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

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

Issue 2812113004: Write last_modified date to Content Settings in the PrefProvider (Closed)
Patch Set: fix ios Created 3 years, 8 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Ensure all content settings are initialized. 107 // Ensure all content settings are initialized.
108 ContentSettingsRegistry::GetInstance(); 108 ContentSettingsRegistry::GetInstance();
109 } 109 }
110 110
111 private: 111 private:
112 content::TestBrowserThreadBundle thread_bundle_; 112 content::TestBrowserThreadBundle thread_bundle_;
113 }; 113 };
114 114
115 TEST_F(PrefProviderTest, Observer) { 115 TEST_F(PrefProviderTest, Observer) {
116 TestingProfile profile; 116 TestingProfile profile;
117 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false); 117 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false, true);
raymes 2017/04/24 03:20:22 nit (here and below): please document these boolea
dullweber 2017/04/25 10:50:44 Done.
118 118
119 ContentSettingsPattern pattern = 119 ContentSettingsPattern pattern =
120 ContentSettingsPattern::FromString("[*.]example.com"); 120 ContentSettingsPattern::FromString("[*.]example.com");
121 MockObserver mock_observer; 121 MockObserver mock_observer;
122 EXPECT_CALL(mock_observer, OnContentSettingChanged( 122 EXPECT_CALL(mock_observer, OnContentSettingChanged(
123 pattern, ContentSettingsPattern::Wildcard(), 123 pattern, ContentSettingsPattern::Wildcard(),
124 CONTENT_SETTINGS_TYPE_COOKIES, "")); 124 CONTENT_SETTINGS_TYPE_COOKIES, ""));
125 125
126 pref_content_settings_provider.AddObserver(&mock_observer); 126 pref_content_settings_provider.AddObserver(&mock_observer);
127 127
(...skipping 27 matching lines...) Expand all
155 data_for_pattern->SetInteger("setting", CONTENT_SETTING_ALLOW); 155 data_for_pattern->SetInteger("setting", CONTENT_SETTING_ALLOW);
156 pref_data.SetWithoutPathExpansion(kPattern, std::move(data_for_pattern)); 156 pref_data.SetWithoutPathExpansion(kPattern, std::move(data_for_pattern));
157 prefs->Set(kFullscreenPrefPath, pref_data); 157 prefs->Set(kFullscreenPrefPath, pref_data);
158 #if !defined(OS_ANDROID) 158 #if !defined(OS_ANDROID)
159 prefs->Set(kMouselockPrefPath, pref_data); 159 prefs->Set(kMouselockPrefPath, pref_data);
160 #endif 160 #endif
161 prefs->Set(kGeolocationPrefPath, pref_data); 161 prefs->Set(kGeolocationPrefPath, pref_data);
162 162
163 // Instantiate a new PrefProvider here, because we want to test the 163 // Instantiate a new PrefProvider here, because we want to test the
164 // constructor's behavior after setting the above. 164 // constructor's behavior after setting the above.
165 PrefProvider provider(prefs, false); 165 PrefProvider provider(prefs, false, true);
166 provider.ShutdownOnUIThread(); 166 provider.ShutdownOnUIThread();
167 167
168 // Check that fullscreen and mouselock have been deleted. 168 // Check that fullscreen and mouselock have been deleted.
169 EXPECT_FALSE(prefs->HasPrefPath(kFullscreenPrefPath)); 169 EXPECT_FALSE(prefs->HasPrefPath(kFullscreenPrefPath));
170 #if !defined(OS_ANDROID) 170 #if !defined(OS_ANDROID)
171 EXPECT_FALSE(prefs->HasPrefPath(kMouselockPrefPath)); 171 EXPECT_FALSE(prefs->HasPrefPath(kMouselockPrefPath));
172 #endif 172 #endif
173 EXPECT_TRUE(prefs->HasPrefPath(kGeolocationPrefPath)); 173 EXPECT_TRUE(prefs->HasPrefPath(kGeolocationPrefPath));
174 GURL primary_url("http://example.com/"); 174 GURL primary_url("http://example.com/");
175 EXPECT_EQ(CONTENT_SETTING_ALLOW, 175 EXPECT_EQ(CONTENT_SETTING_ALLOW,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 auto mic_pattern_data = base::MakeUnique<base::DictionaryValue>(); 214 auto mic_pattern_data = base::MakeUnique<base::DictionaryValue>();
215 mic_pattern_data->SetInteger("setting", CONTENT_SETTING_ALLOW); 215 mic_pattern_data->SetInteger("setting", CONTENT_SETTING_ALLOW);
216 mic_pattern_data->SetDouble(kObsoleteLastUsed, 1480000000.0); 216 mic_pattern_data->SetDouble(kObsoleteLastUsed, 1480000000.0);
217 base::DictionaryValue mic_pref_data; 217 base::DictionaryValue mic_pref_data;
218 mic_pref_data.SetWithoutPathExpansion(kPattern, std::move(mic_pattern_data)); 218 mic_pref_data.SetWithoutPathExpansion(kPattern, std::move(mic_pattern_data));
219 prefs->Set(kMicPrefPath, mic_pref_data); 219 prefs->Set(kMicPrefPath, mic_pref_data);
220 220
221 // Instantiate a new PrefProvider here, because we want to test the 221 // Instantiate a new PrefProvider here, because we want to test the
222 // constructor's behavior after setting the above. 222 // constructor's behavior after setting the above.
223 PrefProvider provider(prefs, false); 223 PrefProvider provider(prefs, false, true);
224 224
225 // Check that last_used data has been deleted. 225 // Check that last_used data has been deleted.
226 EXPECT_TRUE(prefs->GetDictionary(kGeolocationPrefPath)->empty()); 226 EXPECT_TRUE(prefs->GetDictionary(kGeolocationPrefPath)->empty());
227 auto* mic_prefs = prefs->GetDictionary(kMicPrefPath); 227 auto* mic_prefs = prefs->GetDictionary(kMicPrefPath);
228 const base::DictionaryValue* mic_result_pattern_data; 228 const base::DictionaryValue* mic_result_pattern_data;
229 ASSERT_TRUE(mic_prefs->GetDictionaryWithoutPathExpansion( 229 ASSERT_TRUE(mic_prefs->GetDictionaryWithoutPathExpansion(
230 kPattern, &mic_result_pattern_data)); 230 kPattern, &mic_result_pattern_data));
231 EXPECT_EQ(static_cast<size_t>(1), mic_result_pattern_data->size()); 231 EXPECT_EQ(static_cast<size_t>(1), mic_result_pattern_data->size());
232 int mic_result_setting; 232 int mic_result_setting;
233 EXPECT_TRUE( 233 EXPECT_TRUE(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 chrome::RegisterUserProfilePrefs(otr_registry.get()); 266 chrome::RegisterUserProfilePrefs(otr_registry.get());
267 267
268 TestingProfile::Builder profile_builder; 268 TestingProfile::Builder profile_builder;
269 profile_builder.SetPrefService(base::WrapUnique(regular_prefs)); 269 profile_builder.SetPrefService(base::WrapUnique(regular_prefs));
270 std::unique_ptr<TestingProfile> profile = profile_builder.Build(); 270 std::unique_ptr<TestingProfile> profile = profile_builder.Build();
271 271
272 TestingProfile::Builder otr_profile_builder; 272 TestingProfile::Builder otr_profile_builder;
273 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); 273 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs));
274 otr_profile_builder.BuildIncognito(profile.get()); 274 otr_profile_builder.BuildIncognito(profile.get());
275 275
276 PrefProvider pref_content_settings_provider(regular_prefs, false); 276 PrefProvider pref_content_settings_provider(regular_prefs, false, true);
277 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); 277 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true, true);
278 ContentSettingsPattern pattern = 278 ContentSettingsPattern pattern =
279 ContentSettingsPattern::FromString("[*.]example.com"); 279 ContentSettingsPattern::FromString("[*.]example.com");
280 pref_content_settings_provider.SetWebsiteSetting( 280 pref_content_settings_provider.SetWebsiteSetting(
281 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 281 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
282 new base::Value(CONTENT_SETTING_ALLOW)); 282 new base::Value(CONTENT_SETTING_ALLOW));
283 283
284 GURL host("http://example.com/"); 284 GURL host("http://example.com/");
285 // The value should of course be visible in the regular PrefProvider. 285 // The value should of course be visible in the regular PrefProvider.
286 EXPECT_EQ(CONTENT_SETTING_ALLOW, 286 EXPECT_EQ(CONTENT_SETTING_ALLOW,
287 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 287 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
288 host, CONTENT_SETTINGS_TYPE_COOKIES, 288 host, CONTENT_SETTINGS_TYPE_COOKIES,
289 std::string(), false)); 289 std::string(), false));
290 // And also in the OTR version. 290 // And also in the OTR version.
291 EXPECT_EQ(CONTENT_SETTING_ALLOW, 291 EXPECT_EQ(CONTENT_SETTING_ALLOW,
292 TestUtils::GetContentSetting( 292 TestUtils::GetContentSetting(
293 &pref_content_settings_provider_incognito, host, host, 293 &pref_content_settings_provider_incognito, host, host,
294 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 294 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
295 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( 295 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
296 CONTENT_SETTINGS_TYPE_COOKIES); 296 CONTENT_SETTINGS_TYPE_COOKIES);
297 // But the value should not be overridden in the OTR user prefs accidentally. 297 // But the value should not be overridden in the OTR user prefs accidentally.
298 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name())); 298 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name()));
299 299
300 pref_content_settings_provider.ShutdownOnUIThread(); 300 pref_content_settings_provider.ShutdownOnUIThread();
301 pref_content_settings_provider_incognito.ShutdownOnUIThread(); 301 pref_content_settings_provider_incognito.ShutdownOnUIThread();
302 } 302 }
303 303
304 TEST_F(PrefProviderTest, GetContentSettingsValue) { 304 TEST_F(PrefProviderTest, GetContentSettingsValue) {
305 TestingProfile testing_profile; 305 TestingProfile testing_profile;
306 PrefProvider provider(testing_profile.GetPrefs(), false); 306 PrefProvider provider(testing_profile.GetPrefs(), false, true);
307 307
308 GURL primary_url("http://example.com/"); 308 GURL primary_url("http://example.com/");
309 ContentSettingsPattern primary_pattern = 309 ContentSettingsPattern primary_pattern =
310 ContentSettingsPattern::FromString("[*.]example.com"); 310 ContentSettingsPattern::FromString("[*.]example.com");
311 311
312 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 312 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
313 TestUtils::GetContentSetting(&provider, primary_url, primary_url, 313 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
314 CONTENT_SETTINGS_TYPE_COOKIES, 314 CONTENT_SETTINGS_TYPE_COOKIES,
315 std::string(), false)); 315 std::string(), false));
316 316
(...skipping 19 matching lines...) Expand all
336 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 336 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
337 NULL); 337 NULL);
338 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( 338 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
339 &provider, primary_url, primary_url, 339 &provider, primary_url, primary_url,
340 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 340 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
341 provider.ShutdownOnUIThread(); 341 provider.ShutdownOnUIThread();
342 } 342 }
343 343
344 TEST_F(PrefProviderTest, Patterns) { 344 TEST_F(PrefProviderTest, Patterns) {
345 TestingProfile testing_profile; 345 TestingProfile testing_profile;
346 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 346 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), false,
347 false); 347 true);
348 348
349 GURL host1("http://example.com/"); 349 GURL host1("http://example.com/");
350 GURL host2("http://www.example.com/"); 350 GURL host2("http://www.example.com/");
351 GURL host3("http://example.org/"); 351 GURL host3("http://example.org/");
352 GURL host4("file:///tmp/test.html"); 352 GURL host4("file:///tmp/test.html");
353 ContentSettingsPattern pattern1 = 353 ContentSettingsPattern pattern1 =
354 ContentSettingsPattern::FromString("[*.]example.com"); 354 ContentSettingsPattern::FromString("[*.]example.com");
355 ContentSettingsPattern pattern2 = 355 ContentSettingsPattern pattern2 =
356 ContentSettingsPattern::FromString("example.org"); 356 ContentSettingsPattern::FromString("example.org");
357 ContentSettingsPattern pattern3 = 357 ContentSettingsPattern pattern3 =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, 396 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
397 host4, CONTENT_SETTINGS_TYPE_COOKIES, 397 host4, CONTENT_SETTINGS_TYPE_COOKIES,
398 std::string(), false)); 398 std::string(), false));
399 399
400 pref_content_settings_provider.ShutdownOnUIThread(); 400 pref_content_settings_provider.ShutdownOnUIThread();
401 } 401 }
402 402
403 #if BUILDFLAG(ENABLE_PLUGINS) 403 #if BUILDFLAG(ENABLE_PLUGINS)
404 TEST_F(PrefProviderTest, ResourceIdentifier) { 404 TEST_F(PrefProviderTest, ResourceIdentifier) {
405 TestingProfile testing_profile; 405 TestingProfile testing_profile;
406 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 406 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), false,
407 false); 407 true);
408 408
409 GURL host("http://example.com/"); 409 GURL host("http://example.com/");
410 ContentSettingsPattern pattern = 410 ContentSettingsPattern pattern =
411 ContentSettingsPattern::FromString("[*.]example.com"); 411 ContentSettingsPattern::FromString("[*.]example.com");
412 std::string resource1("someplugin"); 412 std::string resource1("someplugin");
413 std::string resource2("otherplugin"); 413 std::string resource2("otherplugin");
414 414
415 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 415 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
416 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 416 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
417 host, CONTENT_SETTINGS_TYPE_PLUGINS, 417 host, CONTENT_SETTINGS_TYPE_PLUGINS,
(...skipping 19 matching lines...) Expand all
437 sync_preferences::TestingPrefServiceSyncable prefs; 437 sync_preferences::TestingPrefServiceSyncable prefs;
438 PrefProvider::RegisterProfilePrefs(prefs.registry()); 438 PrefProvider::RegisterProfilePrefs(prefs.registry());
439 439
440 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 440 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
441 // and writes the preference. When the preference is written, a notification 441 // and writes the preference. When the preference is written, a notification
442 // is sent, and this used to happen when |PrefProvider| was still holding its 442 // is sent, and this used to happen when |PrefProvider| was still holding its
443 // lock. 443 // lock.
444 444
445 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( 445 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
446 CONTENT_SETTINGS_TYPE_COOKIES); 446 CONTENT_SETTINGS_TYPE_COOKIES);
447 PrefProvider provider(&prefs, false); 447 PrefProvider provider(&prefs, false, true);
448 DeadlockCheckerObserver observer(&prefs, &provider); 448 DeadlockCheckerObserver observer(&prefs, &provider);
449 { 449 {
450 DictionaryPrefUpdate update(&prefs, info->pref_name()); 450 DictionaryPrefUpdate update(&prefs, info->pref_name());
451 base::DictionaryValue* mutable_settings = update.Get(); 451 base::DictionaryValue* mutable_settings = update.Get();
452 mutable_settings->SetWithoutPathExpansion( 452 mutable_settings->SetWithoutPathExpansion(
453 "www.example.com,*", base::MakeUnique<base::DictionaryValue>()); 453 "www.example.com,*", base::MakeUnique<base::DictionaryValue>());
454 } 454 }
455 EXPECT_TRUE(observer.notification_received()); 455 EXPECT_TRUE(observer.notification_received());
456 456
457 provider.ShutdownOnUIThread(); 457 provider.ShutdownOnUIThread();
458 } 458 }
459 459
460 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) { 460 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
461 sync_preferences::TestingPrefServiceSyncable prefs; 461 sync_preferences::TestingPrefServiceSyncable prefs;
462 PrefProvider::RegisterProfilePrefs(prefs.registry()); 462 PrefProvider::RegisterProfilePrefs(prefs.registry());
463 463
464 ContentSettingsPattern pattern_1 = 464 ContentSettingsPattern pattern_1 =
465 ContentSettingsPattern::FromString("google.com"); 465 ContentSettingsPattern::FromString("google.com");
466 ContentSettingsPattern pattern_2 = 466 ContentSettingsPattern pattern_2 =
467 ContentSettingsPattern::FromString("www.google.com"); 467 ContentSettingsPattern::FromString("www.google.com");
468 ContentSettingsPattern wildcard = 468 ContentSettingsPattern wildcard =
469 ContentSettingsPattern::FromString("*"); 469 ContentSettingsPattern::FromString("*");
470 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW)); 470 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
471 471
472 // Create a normal provider and set a setting. 472 // Create a normal provider and set a setting.
473 PrefProvider normal_provider(&prefs, false); 473 PrefProvider normal_provider(&prefs, false, true);
474 normal_provider.SetWebsiteSetting(pattern_1, wildcard, 474 normal_provider.SetWebsiteSetting(pattern_1, wildcard,
475 CONTENT_SETTINGS_TYPE_COOKIES, 475 CONTENT_SETTINGS_TYPE_COOKIES,
476 std::string(), value->DeepCopy()); 476 std::string(), value->DeepCopy());
477 477
478 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). 478 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1).
479 { 479 {
480 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 480 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
481 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 481 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
482 EXPECT_TRUE(it->HasNext()); 482 EXPECT_TRUE(it->HasNext());
483 EXPECT_EQ(pattern_1, it->Next().primary_pattern); 483 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
484 EXPECT_FALSE(it->HasNext()); 484 EXPECT_FALSE(it->HasNext());
485 } 485 }
486 486
487 // Non-OTR provider, OTR iterator has no settings. 487 // Non-OTR provider, OTR iterator has no settings.
488 { 488 {
489 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 489 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
490 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), true)); 490 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), true));
491 EXPECT_FALSE(it); 491 EXPECT_FALSE(it);
492 } 492 }
493 493
494 // Create an incognito provider and set a setting. 494 // Create an incognito provider and set a setting.
495 PrefProvider incognito_provider(&prefs, true); 495 PrefProvider incognito_provider(&prefs, true, true);
496 incognito_provider.SetWebsiteSetting(pattern_2, wildcard, 496 incognito_provider.SetWebsiteSetting(pattern_2, wildcard,
497 CONTENT_SETTINGS_TYPE_COOKIES, 497 CONTENT_SETTINGS_TYPE_COOKIES,
498 std::string(), value->DeepCopy()); 498 std::string(), value->DeepCopy());
499 499
500 // OTR provider, non-OTR iterator has one setting (pattern 1). 500 // OTR provider, non-OTR iterator has one setting (pattern 1).
501 { 501 {
502 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator( 502 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator(
503 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 503 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
504 EXPECT_TRUE(it->HasNext()); 504 EXPECT_TRUE(it->HasNext());
505 EXPECT_EQ(pattern_1, it->Next().primary_pattern); 505 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
(...skipping 17 matching lines...) Expand all
523 sync_preferences::TestingPrefServiceSyncable prefs; 523 sync_preferences::TestingPrefServiceSyncable prefs;
524 PrefProvider::RegisterProfilePrefs(prefs.registry()); 524 PrefProvider::RegisterProfilePrefs(prefs.registry());
525 525
526 ContentSettingsPattern pattern = 526 ContentSettingsPattern pattern =
527 ContentSettingsPattern::FromString("google.com"); 527 ContentSettingsPattern::FromString("google.com");
528 ContentSettingsPattern wildcard = 528 ContentSettingsPattern wildcard =
529 ContentSettingsPattern::FromString("*"); 529 ContentSettingsPattern::FromString("*");
530 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW)); 530 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
531 ResourceIdentifier res_id("abcde"); 531 ResourceIdentifier res_id("abcde");
532 532
533 PrefProvider provider(&prefs, false); 533 PrefProvider provider(&prefs, false, true);
534 534
535 // Non-empty pattern, syncable, empty resource identifier. 535 // Non-empty pattern, syncable, empty resource identifier.
536 provider.SetWebsiteSetting(pattern, wildcard, 536 provider.SetWebsiteSetting(pattern, wildcard,
537 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 537 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
538 ResourceIdentifier(), value->DeepCopy()); 538 ResourceIdentifier(), value->DeepCopy());
539 539
540 // Non-empty pattern, non-syncable, empty resource identifier. 540 // Non-empty pattern, non-syncable, empty resource identifier.
541 provider.SetWebsiteSetting(pattern, wildcard, 541 provider.SetWebsiteSetting(pattern, wildcard,
542 CONTENT_SETTINGS_TYPE_GEOLOCATION, 542 CONTENT_SETTINGS_TYPE_GEOLOCATION,
543 ResourceIdentifier(), value->DeepCopy()); 543 ResourceIdentifier(), value->DeepCopy());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 589
590 for (const char* pref : nonempty_prefs) { 590 for (const char* pref : nonempty_prefs) {
591 DictionaryPrefUpdate update(&prefs, pref); 591 DictionaryPrefUpdate update(&prefs, pref);
592 const base::DictionaryValue* dictionary = update.Get(); 592 const base::DictionaryValue* dictionary = update.Get();
593 EXPECT_EQ(1u, dictionary->size()); 593 EXPECT_EQ(1u, dictionary->size());
594 } 594 }
595 595
596 provider.ShutdownOnUIThread(); 596 provider.ShutdownOnUIThread();
597 } 597 }
598 598
599 TEST_F(PrefProviderTest, DeleteWebsiteSetting) {
600 sync_preferences::TestingPrefServiceSyncable prefs;
601 PrefProvider::RegisterProfilePrefs(prefs.registry());
602
603 ContentSettingsPattern pattern_1 =
604 ContentSettingsPattern::FromString("google.com");
605 ContentSettingsPattern pattern_2 =
606 ContentSettingsPattern::FromString("www.google.com");
607 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
608
609 // Create a provider and set a setting.
610 PrefProvider provider(&prefs, false, /*store_last_modified=*/true);
raymes 2017/04/24 03:20:22 The usual way to do this is: true /* store_last_mo
dullweber 2017/04/25 10:50:44 I changed it but do you know if this style is docu
raymes 2017/04/26 01:54:17 Ah I actually just found out today that the style
611 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
612 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
613 value->DeepCopy());
614 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(),
615 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
616 value->DeepCopy());
617 base::Time t = base::Time::Now();
618 // These clear calls shouldn't do anything because both rules were created
619 // before |t|.
620 provider.DeleteWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
621 CONTENT_SETTINGS_TYPE_COOKIES, t);
622 provider.DeleteWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(),
623 CONTENT_SETTINGS_TYPE_COOKIES, t);
624 {
625 std::unique_ptr<RuleIterator> it(provider.GetRuleIterator(
626 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
627 EXPECT_TRUE(it->HasNext());
628 Rule rule = it->Next();
629 EXPECT_EQ(pattern_1, rule.primary_pattern);
630 EXPECT_TRUE(it->HasNext());
631 rule = it->Next();
632 EXPECT_EQ(pattern_2, rule.primary_pattern);
633 EXPECT_FALSE(it->HasNext());
634 }
635
636 // Update pattern_1 and check that the timestamp changes.
637 std::unique_ptr<base::Value> value2(new base::Value(CONTENT_SETTING_BLOCK));
638 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
639 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
640 value2->DeepCopy());
641 // This time pattern_1 should be deleted because it was edited after |t|.
642 provider.DeleteWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
643 CONTENT_SETTINGS_TYPE_COOKIES, t);
644 provider.DeleteWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(),
645 CONTENT_SETTINGS_TYPE_COOKIES, t);
646 {
647 std::unique_ptr<RuleIterator> it(provider.GetRuleIterator(
648 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
649 EXPECT_TRUE(it->HasNext());
650 Rule rule = it->Next();
651 EXPECT_EQ(pattern_2, rule.primary_pattern);
652 EXPECT_FALSE(it->HasNext());
653 }
654
655 provider.ShutdownOnUIThread();
656 }
657
599 } // namespace content_settings 658 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698