OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 void ClearPolicyDefault() { | 75 void ClearPolicyDefault() { |
76 prefs_->RemoveManagedPref(policy_default_setting_); | 76 prefs_->RemoveManagedPref(policy_default_setting_); |
77 } | 77 } |
78 | 78 |
79 void SetPolicyDefault(ContentSetting setting) { | 79 void SetPolicyDefault(ContentSetting setting) { |
80 prefs_->SetManagedPref(policy_default_setting_, | 80 prefs_->SetManagedPref(policy_default_setting_, |
81 new base::FundamentalValue(setting)); | 81 new base::FundamentalValue(setting)); |
82 } | 82 } |
83 | 83 |
84 bool AreUserExceptionsAllowed() { | |
85 return host_content_settings_map_->AreUserExceptionsAllowedForType( | |
86 content_type_); | |
87 } | |
88 | |
89 void AddUserException(std::string exception, | 84 void AddUserException(std::string exception, |
90 ContentSetting content_settings) { | 85 ContentSetting content_settings) { |
91 ContentSettingsPattern pattern = | 86 ContentSettingsPattern pattern = |
92 ContentSettingsPattern::FromString(exception); | 87 ContentSettingsPattern::FromString(exception); |
93 host_content_settings_map_->SetContentSettingCustomScope( | 88 host_content_settings_map_->SetContentSettingCustomScope( |
94 pattern, pattern, content_type_, std::string(), content_settings); | 89 pattern, pattern, content_type_, std::string(), content_settings); |
95 } | 90 } |
96 | 91 |
97 // Wrapper to query GetWebsiteSetting(), and only return the source. | 92 // Wrapper to query GetWebsiteSetting(), and only return the source. |
98 content_settings::SettingSource GetSettingSourceForURL( | 93 content_settings::SettingSource GetSettingSourceForURL( |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 std::unique_ptr<base::Value> stored_value = | 857 std::unique_ptr<base::Value> stored_value = |
863 host_content_settings_map->GetWebsiteSetting( | 858 host_content_settings_map->GetWebsiteSetting( |
864 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, std::string(), | 859 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, std::string(), |
865 nullptr); | 860 nullptr); |
866 EXPECT_TRUE(stored_value && stored_value->Equals(&test_value)); | 861 EXPECT_TRUE(stored_value && stored_value->Equals(&test_value)); |
867 EXPECT_EQ(nullptr, otr_map->GetWebsiteSetting( | 862 EXPECT_EQ(nullptr, otr_map->GetWebsiteSetting( |
868 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, | 863 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, |
869 std::string(), nullptr)); | 864 std::string(), nullptr)); |
870 } | 865 } |
871 | 866 |
872 TEST_F(HostContentSettingsMapTest, AreUserExceptionsAllowedForType) { | |
873 ContentSettingsType kContentTypesToTest[] = { | |
874 CONTENT_SETTINGS_TYPE_COOKIES, | |
875 CONTENT_SETTINGS_TYPE_POPUPS, | |
876 }; | |
877 | |
878 TestingProfile profile; | |
879 | |
880 for (ContentSettingsType type : kContentTypesToTest) { | |
881 TesterForType tester(&profile, type); | |
882 | |
883 // No settings: Yes. | |
884 tester.ClearPolicyDefault(); | |
885 EXPECT_TRUE(tester.AreUserExceptionsAllowed()); | |
886 | |
887 // Policy enforces default value: No. | |
888 tester.SetPolicyDefault(CONTENT_SETTING_ALLOW); | |
889 EXPECT_FALSE(tester.AreUserExceptionsAllowed()); | |
890 tester.SetPolicyDefault(CONTENT_SETTING_BLOCK); | |
891 EXPECT_FALSE(tester.AreUserExceptionsAllowed()); | |
892 | |
893 // Cleanup for next iteration. | |
894 tester.ClearPolicyDefault(); | |
895 } | |
896 } | |
897 | |
898 TEST_F(HostContentSettingsMapTest, PrefExceptionsOperation) { | 867 TEST_F(HostContentSettingsMapTest, PrefExceptionsOperation) { |
899 using content_settings::SETTING_SOURCE_POLICY; | 868 using content_settings::SETTING_SOURCE_POLICY; |
900 using content_settings::SETTING_SOURCE_USER; | 869 using content_settings::SETTING_SOURCE_USER; |
901 | 870 |
902 const char kUrl1[] = "http://user_exception_allow.com"; | 871 const char kUrl1[] = "http://user_exception_allow.com"; |
903 const char kUrl2[] = "http://user_exception_block.com"; | 872 const char kUrl2[] = "http://user_exception_block.com"; |
904 const char kUrl3[] = "http://non_exception.com"; | 873 const char kUrl3[] = "http://non_exception.com"; |
905 | 874 |
906 TestingProfile profile; | 875 TestingProfile profile; |
907 // Arbitrarily using cookies as content type to test. | 876 // Arbitrarily using cookies as content type to test. |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 1310 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
1342 | 1311 |
1343 // After migrating old settings, changes to the setting works. | 1312 // After migrating old settings, changes to the setting works. |
1344 host_content_settings_map->SetContentSettingDefaultScope( | 1313 host_content_settings_map->SetContentSettingDefaultScope( |
1345 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), | 1314 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
1346 CONTENT_SETTING_BLOCK); | 1315 CONTENT_SETTING_BLOCK); |
1347 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1316 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1348 host_content_settings_map->GetContentSetting( | 1317 host_content_settings_map->GetContentSetting( |
1349 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 1318 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
1350 } | 1319 } |
OLD | NEW |