| 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 "chrome/browser/content_settings/content_settings_policy_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // TODO(markusheintz): Check if it's possible to derive the provider class | 40 // TODO(markusheintz): Check if it's possible to derive the provider class |
| 41 // from NonThreadSafe and to use native thread identifiers instead of | 41 // from NonThreadSafe and to use native thread identifiers instead of |
| 42 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread | 42 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread |
| 43 // fields. | 43 // fields. |
| 44 MessageLoop message_loop_; | 44 MessageLoop message_loop_; |
| 45 content::TestBrowserThread ui_thread_; | 45 content::TestBrowserThread ui_thread_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 TEST_F(PolicyProviderTest, DefaultGeolocationContentSetting) { | 48 TEST_F(PolicyProviderTest, DefaultGeolocationContentSetting) { |
| 49 TestingProfile profile; | 49 TestingProfile profile; |
| 50 TestingPrefService* prefs = profile.GetTestingPrefService(); | 50 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 51 PolicyProvider provider(prefs); | 51 PolicyProvider provider(prefs); |
| 52 | 52 |
| 53 Rules rules; | 53 Rules rules; |
| 54 | 54 |
| 55 scoped_ptr<RuleIterator> rule_iterator( | 55 scoped_ptr<RuleIterator> rule_iterator( |
| 56 provider.GetRuleIterator( | 56 provider.GetRuleIterator( |
| 57 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 57 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 58 std::string(), | 58 std::string(), |
| 59 false)); | 59 false)); |
| 60 EXPECT_FALSE(rule_iterator->HasNext()); | 60 EXPECT_FALSE(rule_iterator->HasNext()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 | 74 |
| 75 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); | 75 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); |
| 76 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); | 76 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); |
| 77 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); | 77 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); |
| 78 | 78 |
| 79 provider.ShutdownOnUIThread(); | 79 provider.ShutdownOnUIThread(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { | 82 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { |
| 83 TestingProfile profile; | 83 TestingProfile profile; |
| 84 TestingPrefService* prefs = profile.GetTestingPrefService(); | 84 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 85 PolicyProvider provider(prefs); | 85 PolicyProvider provider(prefs); |
| 86 | 86 |
| 87 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 87 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
| 88 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 88 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 89 | 89 |
| 90 scoped_ptr<RuleIterator> rule_iterator( | 90 scoped_ptr<RuleIterator> rule_iterator( |
| 91 provider.GetRuleIterator( | 91 provider.GetRuleIterator( |
| 92 CONTENT_SETTINGS_TYPE_PLUGINS, | 92 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 93 std::string(), | 93 std::string(), |
| 94 false)); | 94 false)); |
| 95 EXPECT_TRUE(rule_iterator->HasNext()); | 95 EXPECT_TRUE(rule_iterator->HasNext()); |
| 96 Rule rule = rule_iterator->Next(); | 96 Rule rule = rule_iterator->Next(); |
| 97 EXPECT_FALSE(rule_iterator->HasNext()); | 97 EXPECT_FALSE(rule_iterator->HasNext()); |
| 98 | 98 |
| 99 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); | 99 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); |
| 100 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); | 100 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); |
| 101 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); | 101 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); |
| 102 | 102 |
| 103 provider.ShutdownOnUIThread(); | 103 provider.ShutdownOnUIThread(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // When a default-content-setting is set to a managed setting a | 106 // When a default-content-setting is set to a managed setting a |
| 107 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen | 107 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen |
| 108 // if the managed setting is removed. | 108 // if the managed setting is removed. |
| 109 TEST_F(PolicyProviderTest, ObserveManagedSettingsChange) { | 109 TEST_F(PolicyProviderTest, ObserveManagedSettingsChange) { |
| 110 TestingProfile profile; | 110 TestingProfile profile; |
| 111 TestingPrefService* prefs = profile.GetTestingPrefService(); | 111 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 112 PolicyProvider provider(prefs); | 112 PolicyProvider provider(prefs); |
| 113 | 113 |
| 114 MockObserver mock_observer; | 114 MockObserver mock_observer; |
| 115 EXPECT_CALL(mock_observer, | 115 EXPECT_CALL(mock_observer, |
| 116 OnContentSettingChanged(_, | 116 OnContentSettingChanged(_, |
| 117 _, | 117 _, |
| 118 CONTENT_SETTINGS_TYPE_DEFAULT, | 118 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 119 "")); | 119 "")); |
| 120 provider.AddObserver(&mock_observer); | 120 provider.AddObserver(&mock_observer); |
| 121 | 121 |
| 122 // Set the managed default-content-setting. | 122 // Set the managed default-content-setting. |
| 123 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, | 123 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, |
| 124 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 124 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 125 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | 125 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 126 EXPECT_CALL(mock_observer, | 126 EXPECT_CALL(mock_observer, |
| 127 OnContentSettingChanged(_, | 127 OnContentSettingChanged(_, |
| 128 _, | 128 _, |
| 129 CONTENT_SETTINGS_TYPE_DEFAULT, | 129 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 130 "")); | 130 "")); |
| 131 // Remove the managed default-content-setting. | 131 // Remove the managed default-content-setting. |
| 132 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 132 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
| 133 provider.ShutdownOnUIThread(); | 133 provider.ShutdownOnUIThread(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { | 136 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { |
| 137 TestingProfile profile; | 137 TestingProfile profile; |
| 138 TestingPrefService* prefs = profile.GetTestingPrefService(); | 138 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 139 | 139 |
| 140 ListValue* value = new ListValue(); | 140 ListValue* value = new ListValue(); |
| 141 value->Append(Value::CreateStringValue("[*.]google.com")); | 141 value->Append(Value::CreateStringValue("[*.]google.com")); |
| 142 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, | 142 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, |
| 143 value); | 143 value); |
| 144 | 144 |
| 145 PolicyProvider provider(prefs); | 145 PolicyProvider provider(prefs); |
| 146 | 146 |
| 147 ContentSettingsPattern yt_url_pattern = | 147 ContentSettingsPattern yt_url_pattern = |
| 148 ContentSettingsPattern::FromString("www.youtube.com"); | 148 ContentSettingsPattern::FromString("www.youtube.com"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 186 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 187 GetContentSetting( | 187 GetContentSetting( |
| 188 &provider, youtube_url, youtube_url, | 188 &provider, youtube_url, youtube_url, |
| 189 CONTENT_SETTINGS_TYPE_COOKIES, "", false)); | 189 CONTENT_SETTINGS_TYPE_COOKIES, "", false)); |
| 190 | 190 |
| 191 provider.ShutdownOnUIThread(); | 191 provider.ShutdownOnUIThread(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 TEST_F(PolicyProviderTest, ResourceIdentifier) { | 194 TEST_F(PolicyProviderTest, ResourceIdentifier) { |
| 195 TestingProfile profile; | 195 TestingProfile profile; |
| 196 TestingPrefService* prefs = profile.GetTestingPrefService(); | 196 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 197 | 197 |
| 198 ListValue* value = new ListValue(); | 198 ListValue* value = new ListValue(); |
| 199 value->Append(Value::CreateStringValue("[*.]google.com")); | 199 value->Append(Value::CreateStringValue("[*.]google.com")); |
| 200 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, | 200 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, |
| 201 value); | 201 value); |
| 202 | 202 |
| 203 PolicyProvider provider(prefs); | 203 PolicyProvider provider(prefs); |
| 204 | 204 |
| 205 GURL youtube_url("http://www.youtube.com"); | 205 GURL youtube_url("http://www.youtube.com"); |
| 206 GURL google_url("http://mail.google.com"); | 206 GURL google_url("http://mail.google.com"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 220 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 220 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 221 GetContentSetting( | 221 GetContentSetting( |
| 222 &provider, google_url, google_url, | 222 &provider, google_url, google_url, |
| 223 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); | 223 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); |
| 224 | 224 |
| 225 provider.ShutdownOnUIThread(); | 225 provider.ShutdownOnUIThread(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { | 228 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { |
| 229 TestingProfile profile; | 229 TestingProfile profile; |
| 230 TestingPrefService* prefs = profile.GetTestingPrefService(); | 230 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 231 | 231 |
| 232 PolicyProvider provider(prefs); | 232 PolicyProvider provider(prefs); |
| 233 GURL google_url("https://mail.google.com"); | 233 GURL google_url("https://mail.google.com"); |
| 234 // Tests the default setting for auto selecting certificates | 234 // Tests the default setting for auto selecting certificates |
| 235 EXPECT_EQ(NULL, | 235 EXPECT_EQ(NULL, |
| 236 GetContentSettingValue( | 236 GetContentSettingValue( |
| 237 &provider, google_url, google_url, | 237 &provider, google_url, google_url, |
| 238 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "", false)); | 238 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "", false)); |
| 239 | 239 |
| 240 // Set the content settings pattern list for origins to auto select | 240 // Set the content settings pattern list for origins to auto select |
| (...skipping 17 matching lines...) Expand all Loading... |
| 258 ASSERT_EQ(Value::TYPE_DICTIONARY, cert_filter->GetType()); | 258 ASSERT_EQ(Value::TYPE_DICTIONARY, cert_filter->GetType()); |
| 259 DictionaryValue* dict_value = | 259 DictionaryValue* dict_value = |
| 260 static_cast<DictionaryValue*>(cert_filter.get()); | 260 static_cast<DictionaryValue*>(cert_filter.get()); |
| 261 std::string actual_common_name; | 261 std::string actual_common_name; |
| 262 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); | 262 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); |
| 263 EXPECT_EQ("issuer name", actual_common_name); | 263 EXPECT_EQ("issuer name", actual_common_name); |
| 264 provider.ShutdownOnUIThread(); | 264 provider.ShutdownOnUIThread(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace content_settings | 267 } // namespace content_settings |
| OLD | NEW |