Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: chrome/browser/content_settings/content_settings_policy_provider_unittest.cc

Issue 596613002: Remove content dependencies from content settings providers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: browser_tests fix Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 13 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
15 #include "chrome/browser/content_settings/content_settings_utils.h" 14 #include "chrome/browser/content_settings/content_settings_utils.h"
16 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
20 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
21 #include "components/content_settings/core/browser/content_settings_rule.h" 20 #include "components/content_settings/core/browser/content_settings_rule.h"
22 #include "content/public/test/test_browser_thread.h"
23 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
24 #include "url/gurl.h" 22 #include "url/gurl.h"
25 23
26 using ::testing::_; 24 using ::testing::_;
27 using content::BrowserThread;
28 25
29 namespace content_settings { 26 namespace content_settings {
30 27
31 typedef std::vector<Rule> Rules; 28 typedef std::vector<Rule> Rules;
32 29
33 class PolicyProviderTest : public testing::Test { 30 TEST(PolicyProviderTest, DefaultGeolocationContentSetting) {
34 public:
35 PolicyProviderTest()
36 : ui_thread_(BrowserThread::UI, &message_loop_) {
37 }
38
39 protected:
40 // TODO(markusheintz): Check if it's possible to derive the provider class
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
43 // fields.
44 base::MessageLoop message_loop_;
45 content::TestBrowserThread ui_thread_;
46 };
47
48 TEST_F(PolicyProviderTest, DefaultGeolocationContentSetting) {
49 TestingProfile profile; 31 TestingProfile profile;
50 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 32 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
51 PolicyProvider provider(prefs); 33 PolicyProvider provider(prefs);
52 34
53 Rules rules; 35 Rules rules;
54 36
55 scoped_ptr<RuleIterator> rule_iterator( 37 scoped_ptr<RuleIterator> rule_iterator(
56 provider.GetRuleIterator( 38 provider.GetRuleIterator(
57 CONTENT_SETTINGS_TYPE_GEOLOCATION, 39 CONTENT_SETTINGS_TYPE_GEOLOCATION,
58 std::string(), 40 std::string(),
(...skipping 13 matching lines...) Expand all
72 Rule rule = rule_iterator->Next(); 54 Rule rule = rule_iterator->Next();
73 EXPECT_FALSE(rule_iterator->HasNext()); 55 EXPECT_FALSE(rule_iterator->HasNext());
74 56
75 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); 57 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
76 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); 58 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
77 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); 59 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
78 60
79 provider.ShutdownOnUIThread(); 61 provider.ShutdownOnUIThread();
80 } 62 }
81 63
82 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { 64 TEST(PolicyProviderTest, ManagedDefaultContentSettings) {
83 TestingProfile profile; 65 TestingProfile profile;
84 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 66 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
85 PolicyProvider provider(prefs); 67 PolicyProvider provider(prefs);
86 68
87 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 69 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
88 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 70 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
89 71
90 scoped_ptr<RuleIterator> rule_iterator( 72 scoped_ptr<RuleIterator> rule_iterator(
91 provider.GetRuleIterator( 73 provider.GetRuleIterator(
92 CONTENT_SETTINGS_TYPE_PLUGINS, 74 CONTENT_SETTINGS_TYPE_PLUGINS,
93 std::string(), 75 std::string(),
94 false)); 76 false));
95 EXPECT_TRUE(rule_iterator->HasNext()); 77 EXPECT_TRUE(rule_iterator->HasNext());
96 Rule rule = rule_iterator->Next(); 78 Rule rule = rule_iterator->Next();
97 EXPECT_FALSE(rule_iterator->HasNext()); 79 EXPECT_FALSE(rule_iterator->HasNext());
98 80
99 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); 81 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
100 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); 82 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
101 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); 83 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
102 84
103 provider.ShutdownOnUIThread(); 85 provider.ShutdownOnUIThread();
104 } 86 }
105 87
106 // When a default-content-setting is set to a managed setting a 88 // When a default-content-setting is set to a managed setting a
107 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen 89 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen
108 // if the managed setting is removed. 90 // if the managed setting is removed.
109 TEST_F(PolicyProviderTest, ObserveManagedSettingsChange) { 91 TEST(PolicyProviderTest, ObserveManagedSettingsChange) {
110 TestingProfile profile; 92 TestingProfile profile;
111 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 93 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
112 PolicyProvider provider(prefs); 94 PolicyProvider provider(prefs);
113 95
114 MockObserver mock_observer; 96 MockObserver mock_observer;
115 EXPECT_CALL(mock_observer, 97 EXPECT_CALL(mock_observer,
116 OnContentSettingChanged(_, 98 OnContentSettingChanged(_,
117 _, 99 _,
118 CONTENT_SETTINGS_TYPE_DEFAULT, 100 CONTENT_SETTINGS_TYPE_DEFAULT,
119 "")); 101 ""));
120 provider.AddObserver(&mock_observer); 102 provider.AddObserver(&mock_observer);
121 103
122 // Set the managed default-content-setting. 104 // Set the managed default-content-setting.
123 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, 105 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
124 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 106 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
125 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); 107 ::testing::Mock::VerifyAndClearExpectations(&mock_observer);
126 EXPECT_CALL(mock_observer, 108 EXPECT_CALL(mock_observer,
127 OnContentSettingChanged(_, 109 OnContentSettingChanged(_,
128 _, 110 _,
129 CONTENT_SETTINGS_TYPE_DEFAULT, 111 CONTENT_SETTINGS_TYPE_DEFAULT,
130 "")); 112 ""));
131 // Remove the managed default-content-setting. 113 // Remove the managed default-content-setting.
132 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); 114 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
133 provider.ShutdownOnUIThread(); 115 provider.ShutdownOnUIThread();
134 } 116 }
135 117
136 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { 118 TEST(PolicyProviderTest, GettingManagedContentSettings) {
137 TestingProfile profile; 119 TestingProfile profile;
138 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 120 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
139 121
140 base::ListValue* value = new base::ListValue(); 122 base::ListValue* value = new base::ListValue();
141 value->Append(new base::StringValue("[*.]google.com")); 123 value->Append(new base::StringValue("[*.]google.com"));
142 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, 124 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls,
143 value); 125 value);
144 126
145 PolicyProvider provider(prefs); 127 PolicyProvider provider(prefs);
146 128
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 GetContentSetting(&provider, 180 GetContentSetting(&provider,
199 youtube_url, 181 youtube_url,
200 youtube_url, 182 youtube_url,
201 CONTENT_SETTINGS_TYPE_COOKIES, 183 CONTENT_SETTINGS_TYPE_COOKIES,
202 std::string(), 184 std::string(),
203 false)); 185 false));
204 186
205 provider.ShutdownOnUIThread(); 187 provider.ShutdownOnUIThread();
206 } 188 }
207 189
208 TEST_F(PolicyProviderTest, ResourceIdentifier) { 190 TEST(PolicyProviderTest, ResourceIdentifier) {
209 TestingProfile profile; 191 TestingProfile profile;
210 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 192 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
211 193
212 base::ListValue* value = new base::ListValue(); 194 base::ListValue* value = new base::ListValue();
213 value->Append(new base::StringValue("[*.]google.com")); 195 value->Append(new base::StringValue("[*.]google.com"));
214 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, 196 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls,
215 value); 197 value);
216 198
217 PolicyProvider provider(prefs); 199 PolicyProvider provider(prefs);
218 200
(...skipping 16 matching lines...) Expand all
235 false)); 217 false));
236 218
237 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 219 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
238 GetContentSetting( 220 GetContentSetting(
239 &provider, google_url, google_url, 221 &provider, google_url, google_url,
240 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); 222 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false));
241 223
242 provider.ShutdownOnUIThread(); 224 provider.ShutdownOnUIThread();
243 } 225 }
244 226
245 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { 227 TEST(PolicyProviderTest, AutoSelectCertificateList) {
246 TestingProfile profile; 228 TestingProfile profile;
247 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 229 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
248 230
249 PolicyProvider provider(prefs); 231 PolicyProvider provider(prefs);
250 GURL google_url("https://mail.google.com"); 232 GURL google_url("https://mail.google.com");
251 // Tests the default setting for auto selecting certificates 233 // Tests the default setting for auto selecting certificates
252 EXPECT_EQ( 234 EXPECT_EQ(
253 NULL, 235 NULL,
254 GetContentSettingValue(&provider, 236 GetContentSettingValue(&provider,
255 google_url, 237 google_url,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); 269 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType());
288 base::DictionaryValue* dict_value = 270 base::DictionaryValue* dict_value =
289 static_cast<base::DictionaryValue*>(cert_filter.get()); 271 static_cast<base::DictionaryValue*>(cert_filter.get());
290 std::string actual_common_name; 272 std::string actual_common_name;
291 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); 273 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name));
292 EXPECT_EQ("issuer name", actual_common_name); 274 EXPECT_EQ("issuer name", actual_common_name);
293 provider.ShutdownOnUIThread(); 275 provider.ShutdownOnUIThread();
294 } 276 }
295 277
296 } // namespace content_settings 278 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698