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

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

Issue 2039803002: Unregister Images, Plugins and Mouselock content settings on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@only_register_platform_used_contentsettingtypes
Patch Set: address review comments, minor change Created 4 years, 6 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) 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 "components/content_settings/core/browser/content_settings_pref_provide r.h" 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.h"
6 6
7 #include <memory> 7 #include <memory>
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 content::TestBrowserThreadBundle thread_bundle_; 111 content::TestBrowserThreadBundle thread_bundle_;
112 }; 112 };
113 113
114 TEST_F(PrefProviderTest, Observer) { 114 TEST_F(PrefProviderTest, Observer) {
115 TestingProfile profile; 115 TestingProfile profile;
116 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false); 116 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false);
117 117
118 ContentSettingsPattern pattern = 118 ContentSettingsPattern pattern =
119 ContentSettingsPattern::FromString("[*.]example.com"); 119 ContentSettingsPattern::FromString("[*.]example.com");
120 MockObserver mock_observer; 120 MockObserver mock_observer;
121 EXPECT_CALL(mock_observer, 121 EXPECT_CALL(mock_observer, OnContentSettingChanged(
122 OnContentSettingChanged(pattern, 122 pattern, ContentSettingsPattern::Wildcard(),
123 ContentSettingsPattern::Wildcard(), 123 CONTENT_SETTINGS_TYPE_COOKIES, ""));
124 CONTENT_SETTINGS_TYPE_IMAGES,
125 ""));
126 124
127 pref_content_settings_provider.AddObserver(&mock_observer); 125 pref_content_settings_provider.AddObserver(&mock_observer);
128 126
129 pref_content_settings_provider.SetWebsiteSetting( 127 pref_content_settings_provider.SetWebsiteSetting(
130 pattern, 128 pattern, ContentSettingsPattern::Wildcard(),
131 ContentSettingsPattern::Wildcard(), 129 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
132 CONTENT_SETTINGS_TYPE_IMAGES,
133 std::string(),
134 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 130 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
135 131
136 pref_content_settings_provider.ShutdownOnUIThread(); 132 pref_content_settings_provider.ShutdownOnUIThread();
137 } 133 }
138 134
139 // Test for regression in which the PrefProvider modified the user pref store 135 // Test for regression in which the PrefProvider modified the user pref store
140 // of the OTR unintentionally: http://crbug.com/74466. 136 // of the OTR unintentionally: http://crbug.com/74466.
141 TEST_F(PrefProviderTest, Incognito) { 137 TEST_F(PrefProviderTest, Incognito) {
142 PersistentPrefStore* user_prefs = new TestingPrefStore(); 138 PersistentPrefStore* user_prefs = new TestingPrefStore();
143 OverlayUserPrefStore* otr_user_prefs = 139 OverlayUserPrefStore* otr_user_prefs =
(...skipping 23 matching lines...) Expand all
167 163
168 TestingProfile::Builder otr_profile_builder; 164 TestingProfile::Builder otr_profile_builder;
169 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); 165 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs));
170 otr_profile_builder.BuildIncognito(profile.get()); 166 otr_profile_builder.BuildIncognito(profile.get());
171 167
172 PrefProvider pref_content_settings_provider(regular_prefs, false); 168 PrefProvider pref_content_settings_provider(regular_prefs, false);
173 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); 169 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true);
174 ContentSettingsPattern pattern = 170 ContentSettingsPattern pattern =
175 ContentSettingsPattern::FromString("[*.]example.com"); 171 ContentSettingsPattern::FromString("[*.]example.com");
176 pref_content_settings_provider.SetWebsiteSetting( 172 pref_content_settings_provider.SetWebsiteSetting(
177 pattern, 173 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
178 pattern,
179 CONTENT_SETTINGS_TYPE_IMAGES,
180 std::string(),
181 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 174 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
182 175
183 GURL host("http://example.com/"); 176 GURL host("http://example.com/");
184 // The value should of course be visible in the regular PrefProvider. 177 // The value should of course be visible in the regular PrefProvider.
185 EXPECT_EQ(CONTENT_SETTING_ALLOW, 178 EXPECT_EQ(CONTENT_SETTING_ALLOW,
186 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 179 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
187 host, CONTENT_SETTINGS_TYPE_IMAGES, 180 host, CONTENT_SETTINGS_TYPE_COOKIES,
188 std::string(), false)); 181 std::string(), false));
189 // And also in the OTR version. 182 // And also in the OTR version.
190 EXPECT_EQ(CONTENT_SETTING_ALLOW, 183 EXPECT_EQ(CONTENT_SETTING_ALLOW,
191 TestUtils::GetContentSetting( 184 TestUtils::GetContentSetting(
192 &pref_content_settings_provider_incognito, host, host, 185 &pref_content_settings_provider_incognito, host, host,
193 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false)); 186 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
194 const WebsiteSettingsInfo* info = 187 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
195 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES); 188 CONTENT_SETTINGS_TYPE_COOKIES);
196 // But the value should not be overridden in the OTR user prefs accidentally. 189 // But the value should not be overridden in the OTR user prefs accidentally.
197 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name())); 190 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name()));
198 191
199 pref_content_settings_provider.ShutdownOnUIThread(); 192 pref_content_settings_provider.ShutdownOnUIThread();
200 pref_content_settings_provider_incognito.ShutdownOnUIThread(); 193 pref_content_settings_provider_incognito.ShutdownOnUIThread();
201 } 194 }
202 195
203 TEST_F(PrefProviderTest, GetContentSettingsValue) { 196 TEST_F(PrefProviderTest, GetContentSettingsValue) {
204 TestingProfile testing_profile; 197 TestingProfile testing_profile;
205 PrefProvider provider(testing_profile.GetPrefs(), false); 198 PrefProvider provider(testing_profile.GetPrefs(), false);
206 199
207 GURL primary_url("http://example.com/"); 200 GURL primary_url("http://example.com/");
208 ContentSettingsPattern primary_pattern = 201 ContentSettingsPattern primary_pattern =
209 ContentSettingsPattern::FromString("[*.]example.com"); 202 ContentSettingsPattern::FromString("[*.]example.com");
210 203
211 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 204 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
212 TestUtils::GetContentSetting(&provider, primary_url, primary_url, 205 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
213 CONTENT_SETTINGS_TYPE_IMAGES, 206 CONTENT_SETTINGS_TYPE_COOKIES,
214 std::string(), false)); 207 std::string(), false));
215 208
216 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( 209 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
217 &provider, primary_url, primary_url, 210 &provider, primary_url, primary_url,
218 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false)); 211 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
219 212
220 provider.SetWebsiteSetting(primary_pattern, 213 provider.SetWebsiteSetting(primary_pattern, primary_pattern,
221 primary_pattern, 214 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
222 CONTENT_SETTINGS_TYPE_IMAGES,
223 std::string(),
224 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 215 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
225 EXPECT_EQ(CONTENT_SETTING_BLOCK, 216 EXPECT_EQ(CONTENT_SETTING_BLOCK,
226 TestUtils::GetContentSetting(&provider, primary_url, primary_url, 217 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
227 CONTENT_SETTINGS_TYPE_IMAGES, 218 CONTENT_SETTINGS_TYPE_COOKIES,
228 std::string(), false)); 219 std::string(), false));
229 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( 220 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue(
230 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES, 221 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_COOKIES,
231 std::string(), false)); 222 std::string(), false));
232 int int_value = -1; 223 int int_value = -1;
233 value_ptr->GetAsInteger(&int_value); 224 value_ptr->GetAsInteger(&int_value);
234 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 225 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
235 226
236 provider.SetWebsiteSetting(primary_pattern, 227 provider.SetWebsiteSetting(primary_pattern, primary_pattern,
237 primary_pattern, 228 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
238 CONTENT_SETTINGS_TYPE_IMAGES,
239 std::string(),
240 NULL); 229 NULL);
241 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( 230 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
242 &provider, primary_url, primary_url, 231 &provider, primary_url, primary_url,
243 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false)); 232 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
244 provider.ShutdownOnUIThread(); 233 provider.ShutdownOnUIThread();
245 } 234 }
246 235
247 TEST_F(PrefProviderTest, Patterns) { 236 TEST_F(PrefProviderTest, Patterns) {
248 TestingProfile testing_profile; 237 TestingProfile testing_profile;
249 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 238 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
250 false); 239 false);
251 240
252 GURL host1("http://example.com/"); 241 GURL host1("http://example.com/");
253 GURL host2("http://www.example.com/"); 242 GURL host2("http://www.example.com/");
254 GURL host3("http://example.org/"); 243 GURL host3("http://example.org/");
255 GURL host4("file:///tmp/test.html"); 244 GURL host4("file:///tmp/test.html");
256 ContentSettingsPattern pattern1 = 245 ContentSettingsPattern pattern1 =
257 ContentSettingsPattern::FromString("[*.]example.com"); 246 ContentSettingsPattern::FromString("[*.]example.com");
258 ContentSettingsPattern pattern2 = 247 ContentSettingsPattern pattern2 =
259 ContentSettingsPattern::FromString("example.org"); 248 ContentSettingsPattern::FromString("example.org");
260 ContentSettingsPattern pattern3 = 249 ContentSettingsPattern pattern3 =
261 ContentSettingsPattern::FromString("file:///tmp/test.html"); 250 ContentSettingsPattern::FromString("file:///tmp/test.html");
262 251
263 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 252 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
264 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, 253 TestUtils::GetContentSetting(&pref_content_settings_provider, host1,
265 host1, CONTENT_SETTINGS_TYPE_IMAGES, 254 host1, CONTENT_SETTINGS_TYPE_COOKIES,
266 std::string(), false)); 255 std::string(), false));
267 pref_content_settings_provider.SetWebsiteSetting( 256 pref_content_settings_provider.SetWebsiteSetting(
268 pattern1, 257 pattern1, pattern1, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
269 pattern1,
270 CONTENT_SETTINGS_TYPE_IMAGES,
271 std::string(),
272 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 258 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
273 EXPECT_EQ(CONTENT_SETTING_BLOCK, 259 EXPECT_EQ(CONTENT_SETTING_BLOCK,
274 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, 260 TestUtils::GetContentSetting(&pref_content_settings_provider, host1,
275 host1, CONTENT_SETTINGS_TYPE_IMAGES, 261 host1, CONTENT_SETTINGS_TYPE_COOKIES,
276 std::string(), false)); 262 std::string(), false));
277 EXPECT_EQ(CONTENT_SETTING_BLOCK, 263 EXPECT_EQ(CONTENT_SETTING_BLOCK,
278 TestUtils::GetContentSetting(&pref_content_settings_provider, host2, 264 TestUtils::GetContentSetting(&pref_content_settings_provider, host2,
279 host2, CONTENT_SETTINGS_TYPE_IMAGES, 265 host2, CONTENT_SETTINGS_TYPE_COOKIES,
280 std::string(), false)); 266 std::string(), false));
281 267
282 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 268 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
283 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, 269 TestUtils::GetContentSetting(&pref_content_settings_provider, host3,
284 host3, CONTENT_SETTINGS_TYPE_IMAGES, 270 host3, CONTENT_SETTINGS_TYPE_COOKIES,
285 std::string(), false)); 271 std::string(), false));
286 pref_content_settings_provider.SetWebsiteSetting( 272 pref_content_settings_provider.SetWebsiteSetting(
287 pattern2, 273 pattern2, pattern2, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
288 pattern2,
289 CONTENT_SETTINGS_TYPE_IMAGES,
290 std::string(),
291 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 274 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
292 EXPECT_EQ(CONTENT_SETTING_BLOCK, 275 EXPECT_EQ(CONTENT_SETTING_BLOCK,
293 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, 276 TestUtils::GetContentSetting(&pref_content_settings_provider, host3,
294 host3, CONTENT_SETTINGS_TYPE_IMAGES, 277 host3, CONTENT_SETTINGS_TYPE_COOKIES,
295 std::string(), false)); 278 std::string(), false));
296 279
297 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 280 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
298 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, 281 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
299 host4, CONTENT_SETTINGS_TYPE_IMAGES, 282 host4, CONTENT_SETTINGS_TYPE_COOKIES,
300 std::string(), false)); 283 std::string(), false));
301 pref_content_settings_provider.SetWebsiteSetting( 284 pref_content_settings_provider.SetWebsiteSetting(
302 pattern3, 285 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
303 pattern3,
304 CONTENT_SETTINGS_TYPE_IMAGES,
305 std::string(),
306 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 286 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
307 EXPECT_EQ(CONTENT_SETTING_BLOCK, 287 EXPECT_EQ(CONTENT_SETTING_BLOCK,
308 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, 288 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
309 host4, CONTENT_SETTINGS_TYPE_IMAGES, 289 host4, CONTENT_SETTINGS_TYPE_COOKIES,
310 std::string(), false)); 290 std::string(), false));
311 291
312 pref_content_settings_provider.ShutdownOnUIThread(); 292 pref_content_settings_provider.ShutdownOnUIThread();
313 } 293 }
314 294
295 #if defined(ENABLE_PLUGINS)
315 TEST_F(PrefProviderTest, ResourceIdentifier) { 296 TEST_F(PrefProviderTest, ResourceIdentifier) {
316 TestingProfile testing_profile; 297 TestingProfile testing_profile;
317 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 298 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
318 false); 299 false);
319 300
320 GURL host("http://example.com/"); 301 GURL host("http://example.com/");
321 ContentSettingsPattern pattern = 302 ContentSettingsPattern pattern =
322 ContentSettingsPattern::FromString("[*.]example.com"); 303 ContentSettingsPattern::FromString("[*.]example.com");
323 std::string resource1("someplugin"); 304 std::string resource1("someplugin");
324 std::string resource2("otherplugin"); 305 std::string resource2("otherplugin");
(...skipping 12 matching lines...) Expand all
337 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 318 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
338 host, CONTENT_SETTINGS_TYPE_PLUGINS, 319 host, CONTENT_SETTINGS_TYPE_PLUGINS,
339 resource1, false)); 320 resource1, false));
340 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 321 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
341 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 322 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
342 host, CONTENT_SETTINGS_TYPE_PLUGINS, 323 host, CONTENT_SETTINGS_TYPE_PLUGINS,
343 resource2, false)); 324 resource2, false));
344 325
345 pref_content_settings_provider.ShutdownOnUIThread(); 326 pref_content_settings_provider.ShutdownOnUIThread();
346 } 327 }
328 #endif
347 329
348 // http://crosbug.com/17760 330 // http://crosbug.com/17760
349 TEST_F(PrefProviderTest, Deadlock) { 331 TEST_F(PrefProviderTest, Deadlock) {
350 syncable_prefs::TestingPrefServiceSyncable prefs; 332 syncable_prefs::TestingPrefServiceSyncable prefs;
351 PrefProvider::RegisterProfilePrefs(prefs.registry()); 333 PrefProvider::RegisterProfilePrefs(prefs.registry());
352 334
353 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 335 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
354 // and writes the preference. When the preference is written, a notification 336 // and writes the preference. When the preference is written, a notification
355 // is sent, and this used to happen when |PrefProvider| was still holding its 337 // is sent, and this used to happen when |PrefProvider| was still holding its
356 // lock. 338 // lock.
357 339
358 const WebsiteSettingsInfo* info = 340 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
359 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES); 341 CONTENT_SETTINGS_TYPE_COOKIES);
360 PrefProvider provider(&prefs, false); 342 PrefProvider provider(&prefs, false);
361 DeadlockCheckerObserver observer(&prefs, &provider); 343 DeadlockCheckerObserver observer(&prefs, &provider);
362 { 344 {
363 DictionaryPrefUpdate update(&prefs, info->pref_name()); 345 DictionaryPrefUpdate update(&prefs, info->pref_name());
364 base::DictionaryValue* mutable_settings = update.Get(); 346 base::DictionaryValue* mutable_settings = update.Get();
365 mutable_settings->SetWithoutPathExpansion("www.example.com,*", 347 mutable_settings->SetWithoutPathExpansion("www.example.com,*",
366 new base::DictionaryValue()); 348 new base::DictionaryValue());
367 } 349 }
368 EXPECT_TRUE(observer.notification_received()); 350 EXPECT_TRUE(observer.notification_received());
369 351
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 ContentSettingsPattern::FromString("google.com"); 395 ContentSettingsPattern::FromString("google.com");
414 ContentSettingsPattern pattern_2 = 396 ContentSettingsPattern pattern_2 =
415 ContentSettingsPattern::FromString("www.google.com"); 397 ContentSettingsPattern::FromString("www.google.com");
416 ContentSettingsPattern wildcard = 398 ContentSettingsPattern wildcard =
417 ContentSettingsPattern::FromString("*"); 399 ContentSettingsPattern::FromString("*");
418 std::unique_ptr<base::Value> value( 400 std::unique_ptr<base::Value> value(
419 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 401 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
420 402
421 // Create a normal provider and set a setting. 403 // Create a normal provider and set a setting.
422 PrefProvider normal_provider(&prefs, false); 404 PrefProvider normal_provider(&prefs, false);
423 normal_provider.SetWebsiteSetting(pattern_1, 405 normal_provider.SetWebsiteSetting(pattern_1, wildcard,
424 wildcard, 406 CONTENT_SETTINGS_TYPE_COOKIES,
425 CONTENT_SETTINGS_TYPE_IMAGES, 407 std::string(), value->DeepCopy());
426 std::string(),
427 value->DeepCopy());
428 408
429 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). 409 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1).
430 { 410 {
431 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 411 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
432 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false)); 412 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
433 EXPECT_TRUE(it->HasNext()); 413 EXPECT_TRUE(it->HasNext());
434 EXPECT_EQ(pattern_1, it->Next().primary_pattern); 414 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
435 EXPECT_FALSE(it->HasNext()); 415 EXPECT_FALSE(it->HasNext());
436 } 416 }
437 417
438 // Non-OTR provider, OTR iterator has no settings. 418 // Non-OTR provider, OTR iterator has no settings.
439 { 419 {
440 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 420 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
441 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), true)); 421 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), true));
442 EXPECT_FALSE(it->HasNext()); 422 EXPECT_FALSE(it->HasNext());
443 } 423 }
444 424
445 // Create an incognito provider and set a setting. 425 // Create an incognito provider and set a setting.
446 PrefProvider incognito_provider(&prefs, true); 426 PrefProvider incognito_provider(&prefs, true);
447 incognito_provider.SetWebsiteSetting(pattern_2, 427 incognito_provider.SetWebsiteSetting(pattern_2, wildcard,
448 wildcard, 428 CONTENT_SETTINGS_TYPE_COOKIES,
449 CONTENT_SETTINGS_TYPE_IMAGES, 429 std::string(), value->DeepCopy());
450 std::string(),
451 value->DeepCopy());
452 430
453 // OTR provider, non-OTR iterator has one setting (pattern 1). 431 // OTR provider, non-OTR iterator has one setting (pattern 1).
454 { 432 {
455 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator( 433 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator(
456 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false)); 434 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
457 EXPECT_TRUE(it->HasNext()); 435 EXPECT_TRUE(it->HasNext());
458 EXPECT_EQ(pattern_1, it->Next().primary_pattern); 436 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
459 EXPECT_FALSE(it->HasNext()); 437 EXPECT_FALSE(it->HasNext());
460 } 438 }
461 439
462 // OTR provider, OTR iterator has one setting (pattern 2). 440 // OTR provider, OTR iterator has one setting (pattern 2).
463 { 441 {
464 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator( 442 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator(
465 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), true)); 443 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), true));
466 EXPECT_TRUE(it->HasNext()); 444 EXPECT_TRUE(it->HasNext());
467 EXPECT_EQ(pattern_2, it->Next().primary_pattern); 445 EXPECT_EQ(pattern_2, it->Next().primary_pattern);
468 EXPECT_FALSE(it->HasNext()); 446 EXPECT_FALSE(it->HasNext());
469 } 447 }
470 448
471 incognito_provider.ShutdownOnUIThread(); 449 incognito_provider.ShutdownOnUIThread();
472 normal_provider.ShutdownOnUIThread(); 450 normal_provider.ShutdownOnUIThread();
473 } 451 }
474 452
475 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { 453 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) {
476 syncable_prefs::TestingPrefServiceSyncable prefs; 454 syncable_prefs::TestingPrefServiceSyncable prefs;
477 PrefProvider::RegisterProfilePrefs(prefs.registry()); 455 PrefProvider::RegisterProfilePrefs(prefs.registry());
478 456
479 ContentSettingsPattern pattern = 457 ContentSettingsPattern pattern =
480 ContentSettingsPattern::FromString("google.com"); 458 ContentSettingsPattern::FromString("google.com");
481 ContentSettingsPattern wildcard = 459 ContentSettingsPattern wildcard =
482 ContentSettingsPattern::FromString("*"); 460 ContentSettingsPattern::FromString("*");
483 std::unique_ptr<base::Value> value( 461 std::unique_ptr<base::Value> value(
484 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 462 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
485 ResourceIdentifier res_id("abcde"); 463 ResourceIdentifier res_id("abcde");
486 464
487 PrefProvider provider(&prefs, false); 465 PrefProvider provider(&prefs, false);
488 466
489 // Non-empty pattern, syncable, empty resource identifier. 467 // Non-empty pattern, syncable, empty resource identifier.
490 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_IMAGES, 468 provider.SetWebsiteSetting(pattern, wildcard,
469 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
491 ResourceIdentifier(), value->DeepCopy()); 470 ResourceIdentifier(), value->DeepCopy());
492 471
493 // Non-empty pattern, non-syncable, empty resource identifier. 472 // Non-empty pattern, non-syncable, empty resource identifier.
494 provider.SetWebsiteSetting(pattern, wildcard, 473 provider.SetWebsiteSetting(pattern, wildcard,
495 CONTENT_SETTINGS_TYPE_GEOLOCATION, 474 CONTENT_SETTINGS_TYPE_GEOLOCATION,
496 ResourceIdentifier(), value->DeepCopy()); 475 ResourceIdentifier(), value->DeepCopy());
497 476 #if defined(ENABLE_PLUGINS)
498 // Non-empty pattern, plugins, non-empty resource identifier. 477 // Non-empty pattern, plugins, non-empty resource identifier.
499 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS, 478 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS,
500 res_id, value->DeepCopy()); 479 res_id, value->DeepCopy());
501 480
502 // Empty pattern, plugins, non-empty resource identifier. 481 // Empty pattern, plugins, non-empty resource identifier.
503 provider.SetWebsiteSetting(wildcard, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS, 482 provider.SetWebsiteSetting(wildcard, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS,
504 res_id, value->DeepCopy()); 483 res_id, value->DeepCopy());
505 484 #endif
506 // Non-empty pattern, syncable, empty resource identifier. 485 // Non-empty pattern, syncable, empty resource identifier.
507 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_COOKIES, 486 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_COOKIES,
508 ResourceIdentifier(), value->DeepCopy()); 487 ResourceIdentifier(), value->DeepCopy());
509 488
510 // Non-empty pattern, non-syncable, empty resource identifier. 489 // Non-empty pattern, non-syncable, empty resource identifier.
511 provider.SetWebsiteSetting(pattern, wildcard, 490 provider.SetWebsiteSetting(pattern, wildcard,
512 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 491 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
513 ResourceIdentifier(), value->DeepCopy()); 492 ResourceIdentifier(), value->DeepCopy());
514 493
515 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_IMAGES); 494 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
516 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION); 495 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION);
496 #if defined(ENABLE_PLUGINS)
517 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS); 497 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS);
498 #endif
518 499
519 WebsiteSettingsRegistry* registry = WebsiteSettingsRegistry::GetInstance(); 500 WebsiteSettingsRegistry* registry = WebsiteSettingsRegistry::GetInstance();
520 // Test that the preferences for images, geolocation and plugins are empty. 501 // Test that the preferences for images, geolocation and plugins are empty.
521 const char* empty_prefs[] = { 502 const char* empty_prefs[] = {
522 registry->Get(CONTENT_SETTINGS_TYPE_IMAGES)->pref_name().c_str(), 503 registry->Get(CONTENT_SETTINGS_TYPE_JAVASCRIPT)->pref_name().c_str(),
523 registry->Get(CONTENT_SETTINGS_TYPE_GEOLOCATION)->pref_name().c_str(), 504 registry->Get(CONTENT_SETTINGS_TYPE_GEOLOCATION)->pref_name().c_str(),
524 registry->Get(CONTENT_SETTINGS_TYPE_PLUGINS)->pref_name().c_str(), 505 #if defined(ENABLE_PLUGINS)
506 registry->Get(CONTENT_SETTINGS_TYPE_PLUGINS)->pref_name().c_str(),
507 #endif
525 }; 508 };
526 509
527 for (const char* pref : empty_prefs) { 510 for (const char* pref : empty_prefs) {
528 DictionaryPrefUpdate update(&prefs, pref); 511 DictionaryPrefUpdate update(&prefs, pref);
529 const base::DictionaryValue* dictionary = update.Get(); 512 const base::DictionaryValue* dictionary = update.Get();
530 EXPECT_TRUE(dictionary->empty()); 513 EXPECT_TRUE(dictionary->empty());
531 } 514 }
532 515
533 // Test that the preferences for cookies and notifications are not empty. 516 // Test that the preferences for cookies and notifications are not empty.
534 const char* nonempty_prefs[] = { 517 const char* nonempty_prefs[] = {
535 registry->Get(CONTENT_SETTINGS_TYPE_COOKIES)->pref_name().c_str(), 518 registry->Get(CONTENT_SETTINGS_TYPE_COOKIES)->pref_name().c_str(),
536 registry->Get(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)->pref_name().c_str(), 519 registry->Get(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)->pref_name().c_str(),
537 }; 520 };
538 521
539 for (const char* pref : nonempty_prefs) { 522 for (const char* pref : nonempty_prefs) {
540 DictionaryPrefUpdate update(&prefs, pref); 523 DictionaryPrefUpdate update(&prefs, pref);
541 const base::DictionaryValue* dictionary = update.Get(); 524 const base::DictionaryValue* dictionary = update.Get();
542 EXPECT_EQ(1u, dictionary->size()); 525 EXPECT_EQ(1u, dictionary->size());
543 } 526 }
544 527
545 provider.ShutdownOnUIThread(); 528 provider.ShutdownOnUIThread();
546 } 529 }
547 530
548 } // namespace content_settings 531 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698