| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/content_settings/core/browser/content_settings_policy_provi
der.h" | 5 #include "components/content_settings/core/browser/content_settings_policy_provi
der.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 provider.ShutdownOnUIThread(); | 65 provider.ShutdownOnUIThread(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { | 68 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { |
| 69 TestingProfile profile; | 69 TestingProfile profile; |
| 70 sync_preferences::TestingPrefServiceSyncable* prefs = | 70 sync_preferences::TestingPrefServiceSyncable* prefs = |
| 71 profile.GetTestingPrefService(); | 71 profile.GetTestingPrefService(); |
| 72 PolicyProvider provider(prefs); | 72 PolicyProvider provider(prefs); |
| 73 | 73 |
| 74 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 74 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
| 75 base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK)); | 75 base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK)); |
| 76 | 76 |
| 77 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator( | 77 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator( |
| 78 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), false)); | 78 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); |
| 79 EXPECT_TRUE(rule_iterator->HasNext()); | 79 EXPECT_TRUE(rule_iterator->HasNext()); |
| 80 Rule rule = rule_iterator->Next(); | 80 Rule rule = rule_iterator->Next(); |
| 81 EXPECT_FALSE(rule_iterator->HasNext()); | 81 EXPECT_FALSE(rule_iterator->HasNext()); |
| 82 | 82 |
| 83 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); | 83 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); |
| 84 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); | 84 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); |
| 85 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); | 85 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); |
| 86 | 86 |
| 87 provider.ShutdownOnUIThread(); | 87 provider.ShutdownOnUIThread(); |
| 88 } | 88 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 MockObserver mock_observer; | 134 MockObserver mock_observer; |
| 135 EXPECT_CALL(mock_observer, | 135 EXPECT_CALL(mock_observer, |
| 136 OnContentSettingChanged(_, | 136 OnContentSettingChanged(_, |
| 137 _, | 137 _, |
| 138 CONTENT_SETTINGS_TYPE_DEFAULT, | 138 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 139 "")); | 139 "")); |
| 140 provider.AddObserver(&mock_observer); | 140 provider.AddObserver(&mock_observer); |
| 141 | 141 |
| 142 // Set the managed default-content-setting. | 142 // Set the managed default-content-setting. |
| 143 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, | 143 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
| 144 base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK)); | 144 base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK)); |
| 145 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | 145 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 146 EXPECT_CALL(mock_observer, | 146 EXPECT_CALL(mock_observer, |
| 147 OnContentSettingChanged(_, | 147 OnContentSettingChanged(_, |
| 148 _, | 148 _, |
| 149 CONTENT_SETTINGS_TYPE_DEFAULT, | 149 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 150 "")); | 150 "")); |
| 151 // Remove the managed default-content-setting. | 151 // Remove the managed default-content-setting. |
| 152 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 152 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
| 153 provider.ShutdownOnUIThread(); | 153 provider.ShutdownOnUIThread(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { | 156 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { |
| 157 TestingProfile profile; | 157 TestingProfile profile; |
| 158 sync_preferences::TestingPrefServiceSyncable* prefs = | 158 sync_preferences::TestingPrefServiceSyncable* prefs = |
| 159 profile.GetTestingPrefService(); | 159 profile.GetTestingPrefService(); |
| 160 | 160 |
| 161 auto value = base::MakeUnique<base::ListValue>(); | 161 auto value = base::MakeUnique<base::ListValue>(); |
| 162 value->AppendString("[*.]google.com"); | 162 value->AppendString("[*.]google.com"); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 ASSERT_EQ(base::Value::Type::DICTIONARY, cert_filter->GetType()); | 275 ASSERT_EQ(base::Value::Type::DICTIONARY, cert_filter->GetType()); |
| 276 base::DictionaryValue* dict_value = | 276 base::DictionaryValue* dict_value = |
| 277 static_cast<base::DictionaryValue*>(cert_filter.get()); | 277 static_cast<base::DictionaryValue*>(cert_filter.get()); |
| 278 std::string actual_common_name; | 278 std::string actual_common_name; |
| 279 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); | 279 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); |
| 280 EXPECT_EQ("issuer name", actual_common_name); | 280 EXPECT_EQ("issuer name", actual_common_name); |
| 281 provider.ShutdownOnUIThread(); | 281 provider.ShutdownOnUIThread(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(PolicyProviderTest, InvalidManagedDefaultContentSetting) { |
| 285 TestingProfile profile; |
| 286 sync_preferences::TestingPrefServiceSyncable* prefs = |
| 287 profile.GetTestingPrefService(); |
| 288 PolicyProvider provider(prefs); |
| 289 |
| 290 prefs->SetManagedPref( |
| 291 prefs::kManagedDefaultCookiesSetting, |
| 292 base::MakeUnique<base::Value>(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT)); |
| 293 |
| 294 // The setting provided in the cookies pref is not valid for cookies. It |
| 295 // should be ignored. |
| 296 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator( |
| 297 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); |
| 298 EXPECT_FALSE(rule_iterator); |
| 299 |
| 300 provider.ShutdownOnUIThread(); |
| 301 } |
| 302 |
| 284 } // namespace content_settings | 303 } // namespace content_settings |
| OLD | NEW |