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

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

Issue 1252073002: Move pref names and default value into WebsiteSettingsInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@website-settings-registry-simple
Patch Set: Created 5 years, 4 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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 23 matching lines...) Expand all
34 #include "content/public/test/test_browser_thread_bundle.h" 34 #include "content/public/test/test_browser_thread_bundle.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "url/gurl.h" 36 #include "url/gurl.h"
37 37
38 using ::testing::_; 38 using ::testing::_;
39 39
40 namespace content_settings { 40 namespace content_settings {
41 41
42 class DeadlockCheckerThread : public base::PlatformThread::Delegate { 42 class DeadlockCheckerThread : public base::PlatformThread::Delegate {
43 public: 43 public:
44 explicit DeadlockCheckerThread(PrefProvider* provider) 44 explicit DeadlockCheckerThread(const ContentSettingsPref* pref)
45 : provider_(provider) {} 45 : pref_(pref) {}
46 46
47 void ThreadMain() override { 47 void ThreadMain() override {
48 EXPECT_TRUE(provider_->TestAllLocks()); 48 EXPECT_TRUE(pref_->lock_.Try());
49 pref_->lock_.Release();
Bernhard Bauer 2015/07/30 08:13:00 Why this change?
msramek 2015/07/31 15:27:49 This is apparently rebased over my https://coderev
raymes 2015/08/03 03:18:17 Sorry! I've updated the patch to base it on Martin
49 } 50 }
50 private: 51 private:
51 PrefProvider* provider_; 52 const ContentSettingsPref* pref_;
52 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread); 53 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread);
53 }; 54 };
54 55
55 // A helper for observing an preference changes and testing whether 56 // A helper for observing an preference changes and testing whether
56 // |PrefProvider| holds a lock when the preferences change. 57 // |PrefProvider| holds a lock when the preferences change.
57 class DeadlockCheckerObserver { 58 class DeadlockCheckerObserver {
58 public: 59 public:
59 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or 60 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or
60 // |provider|. 61 // |provider|.
61 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider) 62 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider)
62 : provider_(provider), 63 : provider_(provider),
63 notification_received_(false) { 64 notification_received_(false) {
64 pref_change_registrar_.Init(prefs); 65 pref_change_registrar_.Init(prefs);
65 pref_change_registrar_.Add( 66 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
66 prefs::kContentSettingsPatternPairs, 67 pref_change_registrar_.Add(
67 base::Bind( 68 provider_->content_settings_prefs_[i]->pref_name_,
68 &DeadlockCheckerObserver::OnContentSettingsPatternPairsChanged, 69 base::Bind(
69 base::Unretained(this))); 70 &DeadlockCheckerObserver::OnContentSettingsPatternPairsChanged,
71 base::Unretained(this),
72 base::Unretained(provider_->content_settings_prefs_[i])));
73 }
70 } 74 }
71 virtual ~DeadlockCheckerObserver() {} 75 virtual ~DeadlockCheckerObserver() {}
72 76
73 bool notification_received() const { 77 bool notification_received() const {
74 return notification_received_; 78 return notification_received_;
75 } 79 }
76 80
77 private: 81 private:
78 void OnContentSettingsPatternPairsChanged() { 82 void OnContentSettingsPatternPairsChanged(const ContentSettingsPref* pref) {
79 // Check whether |provider_| holds its lock. For this, we need a 83 // Check whether |provider_| holds its lock. For this, we need a
80 // separate thread. 84 // separate thread.
81 DeadlockCheckerThread thread(provider_); 85 DeadlockCheckerThread thread(pref);
82 base::PlatformThreadHandle handle; 86 base::PlatformThreadHandle handle;
83 ASSERT_TRUE(base::PlatformThread::Create(0, &thread, &handle)); 87 ASSERT_TRUE(base::PlatformThread::Create(0, &thread, &handle));
84 base::PlatformThread::Join(handle); 88 base::PlatformThread::Join(handle);
85 notification_received_ = true; 89 notification_received_ = true;
86 } 90 }
87 91
88 PrefProvider* provider_; 92 PrefProvider* provider_;
89 PrefChangeRegistrar pref_change_registrar_; 93 PrefChangeRegistrar pref_change_registrar_;
90 bool notification_received_; 94 bool notification_received_;
91 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerObserver); 95 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerObserver);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // And also in the OTR version. 180 // And also in the OTR version.
177 EXPECT_EQ(CONTENT_SETTING_ALLOW, 181 EXPECT_EQ(CONTENT_SETTING_ALLOW,
178 GetContentSetting(&pref_content_settings_provider_incognito, 182 GetContentSetting(&pref_content_settings_provider_incognito,
179 host, 183 host,
180 host, 184 host,
181 CONTENT_SETTINGS_TYPE_IMAGES, 185 CONTENT_SETTINGS_TYPE_IMAGES,
182 std::string(), 186 std::string(),
183 false)); 187 false));
184 // But the value should not be overridden in the OTR user prefs accidentally. 188 // But the value should not be overridden in the OTR user prefs accidentally.
185 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay( 189 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(
186 prefs::kContentSettingsPatternPairs)); 190 prefs::kContentSettingsImagesPatternPairs));
187 191
188 pref_content_settings_provider.ShutdownOnUIThread(); 192 pref_content_settings_provider.ShutdownOnUIThread();
189 pref_content_settings_provider_incognito.ShutdownOnUIThread(); 193 pref_content_settings_provider_incognito.ShutdownOnUIThread();
190 } 194 }
191 195
192 TEST_F(PrefProviderTest, GetContentSettingsValue) { 196 TEST_F(PrefProviderTest, GetContentSettingsValue) {
193 TestingProfile testing_profile; 197 TestingProfile testing_profile;
194 PrefProvider provider(testing_profile.GetPrefs(), false); 198 PrefProvider provider(testing_profile.GetPrefs(), false);
195 199
196 GURL primary_url("http://example.com/"); 200 GURL primary_url("http://example.com/");
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 420
417 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 421 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
418 // and writes the preference. When the preference is written, a notification 422 // and writes the preference. When the preference is written, a notification
419 // is sent, and this used to happen when |PrefProvider| was still holding its 423 // is sent, and this used to happen when |PrefProvider| was still holding its
420 // lock. 424 // lock.
421 425
422 PrefProvider provider(&prefs, false); 426 PrefProvider provider(&prefs, false);
423 DeadlockCheckerObserver observer(&prefs, &provider); 427 DeadlockCheckerObserver observer(&prefs, &provider);
424 { 428 {
425 DictionaryPrefUpdate update(&prefs, 429 DictionaryPrefUpdate update(&prefs,
426 prefs::kContentSettingsPatternPairs); 430 prefs::kContentSettingsImagesPatternPairs);
427 base::DictionaryValue* mutable_settings = update.Get(); 431 base::DictionaryValue* mutable_settings = update.Get();
428 mutable_settings->SetWithoutPathExpansion("www.example.com,*", 432 mutable_settings->SetWithoutPathExpansion("www.example.com,*",
429 new base::DictionaryValue()); 433 new base::DictionaryValue());
430 } 434 }
431 EXPECT_TRUE(observer.notification_received()); 435 EXPECT_TRUE(observer.notification_received());
432 436
433 provider.ShutdownOnUIThread(); 437 provider.ShutdownOnUIThread();
434 } 438 }
435 439
436 TEST_F(PrefProviderTest, LastUsage) { 440 TEST_F(PrefProviderTest, LastUsage) {
(...skipping 24 matching lines...) Expand all
461 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); 465 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
462 base::Time second = pref_content_settings_provider.GetLastUsage( 466 base::Time second = pref_content_settings_provider.GetLastUsage(
463 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); 467 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
464 468
465 base::TimeDelta delta = second - first; 469 base::TimeDelta delta = second - first;
466 EXPECT_EQ(delta.InSeconds(), 10); 470 EXPECT_EQ(delta.InSeconds(), 10);
467 471
468 pref_content_settings_provider.ShutdownOnUIThread(); 472 pref_content_settings_provider.ShutdownOnUIThread();
469 } 473 }
470 474
471
472 // TODO(msramek): This tests the correct migration behavior between the old
473 // aggregate dictionary preferences for all content settings types and the new
474 // dictionary preferences for individual types. Remove this when the migration
475 // period is over.
476 TEST_F(PrefProviderTest, SyncingOldToNew) {
477 TestingPrefServiceSyncable prefs;
478 PrefProvider::RegisterProfilePrefs(prefs.registry());
479 PrefProvider provider(&prefs, false);
480
481 const std::string pattern = "google.com,*";
482 const std::string resource_id = "abcde12345";
483 base::DictionaryValue* exceptions = new base::DictionaryValue();
484 base::DictionaryValue* plugin_resources = new base::DictionaryValue();
485
486 // Add exceptions for images and app banner which did not need to be migrated.
487 exceptions->SetIntegerWithoutPathExpansion(
488 GetTypeName(CONTENT_SETTINGS_TYPE_IMAGES), CONTENT_SETTING_ALLOW);
489 exceptions->SetIntegerWithoutPathExpansion(
490 GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW);
491
492 // Add exceptions for new content settings types added after the migration.
493 exceptions->SetIntegerWithoutPathExpansion(
494 GetTypeName(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT),
495 CONTENT_SETTING_ALLOW);
496
497 // Add a regular exception for plugins, then one with a resource identifier.
498 exceptions->SetIntegerWithoutPathExpansion(
499 GetTypeName(CONTENT_SETTINGS_TYPE_PLUGINS), CONTENT_SETTING_ALLOW);
500 plugin_resources->SetIntegerWithoutPathExpansion(
501 resource_id, CONTENT_SETTING_BLOCK);
502 exceptions->SetWithoutPathExpansion(
503 "per_plugin", plugin_resources);
504
505 // Change the old dictionary preference and observe changes
506 // in the new preferences.
507 {
508 DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
509 base::DictionaryValue* old_dictionary = update.Get();
510 old_dictionary->SetWithoutPathExpansion(pattern, exceptions);
511 }
512
513 // The images exception was synced.
514 {
515 DictionaryPrefUpdate update(
516 &prefs, prefs::kContentSettingsImagesPatternPairs);
517 const base::DictionaryValue* images_dictionary = update.Get();
518
519 EXPECT_EQ(1u, images_dictionary->size());
520 const base::DictionaryValue* images_exception;
521 EXPECT_TRUE(images_dictionary->GetDictionaryWithoutPathExpansion(
522 pattern, &images_exception));
523
524 // And it has a correct value.
525 int images_exception_value = CONTENT_SETTING_DEFAULT;
526 EXPECT_TRUE(images_exception->GetIntegerWithoutPathExpansion(
527 "setting", &images_exception_value));
528 EXPECT_EQ(CONTENT_SETTING_ALLOW, images_exception_value);
529 }
530
531 // The app banner exception was not synced.
532 {
533 DictionaryPrefUpdate update(
534 &prefs, prefs::kContentSettingsAppBannerPatternPairs);
535 const base::DictionaryValue* app_banner_dictionary = update.Get();
536 EXPECT_TRUE(app_banner_dictionary->empty());
537 }
538
539 // The plugins exception was synced, together with the resource identifiers.
540 {
541 DictionaryPrefUpdate update(
542 &prefs, prefs::kContentSettingsPluginsPatternPairs);
543 const base::DictionaryValue* plugins_dictionary = update.Get();
544 EXPECT_EQ(1u, plugins_dictionary->size());
545
546 const base::DictionaryValue* plugins_exception;
547 EXPECT_TRUE(plugins_dictionary->GetDictionaryWithoutPathExpansion(
548 pattern, &plugins_exception));
549
550 int plugins_exception_value = CONTENT_SETTING_DEFAULT;
551 EXPECT_TRUE(plugins_exception->GetIntegerWithoutPathExpansion(
552 "setting", &plugins_exception_value));
553 EXPECT_EQ(CONTENT_SETTING_ALLOW, plugins_exception_value);
554
555 int resource_exception_value = CONTENT_SETTING_DEFAULT;
556 const base::DictionaryValue* resource_exception;
557 EXPECT_TRUE(plugins_exception->GetDictionaryWithoutPathExpansion(
558 "per_resource", &resource_exception));
559 EXPECT_TRUE(resource_exception->GetIntegerWithoutPathExpansion(
560 resource_id, &resource_exception_value));
561 EXPECT_EQ(CONTENT_SETTING_BLOCK, resource_exception_value);
562 }
563
564 provider.ShutdownOnUIThread();
565 }
566
567 TEST_F(PrefProviderTest, SyncingNewToOld) {
568 TestingPrefServiceSyncable prefs;
569 PrefProvider::RegisterProfilePrefs(prefs.registry());
570 PrefProvider provider(&prefs, false);
571
572 const std::string pattern = "google.com,*";
573 const std::string resource_id = "abcde12345";
574 base::DictionaryValue block_exception;
575 block_exception.SetIntegerWithoutPathExpansion(
576 "setting", CONTENT_SETTING_BLOCK);
577
578 // Add a mouselock exception.
579 {
580 DictionaryPrefUpdate update(
581 &prefs, prefs::kContentSettingsMouseLockPatternPairs);
582 base::DictionaryValue* mouselock_dictionary = update.Get();
583
584 mouselock_dictionary->SetWithoutPathExpansion(
585 pattern, block_exception.DeepCopy());
586 }
587
588 // Add a microphone exception.
589 {
590 DictionaryPrefUpdate update(
591 &prefs, prefs::kContentSettingsMediaStreamMicPatternPairs);
592 base::DictionaryValue* microphone_dictionary = update.Get();
593
594 microphone_dictionary->SetWithoutPathExpansion(
595 pattern, block_exception.DeepCopy());
596 }
597
598 // Add a plugin exception with resource identifiers.
599 {
600 DictionaryPrefUpdate update(
601 &prefs, prefs::kContentSettingsPluginsPatternPairs);
602 base::DictionaryValue* plugins_dictionary = update.Get();
603
604 base::DictionaryValue* plugin_exception = block_exception.DeepCopy();
605 plugins_dictionary->SetWithoutPathExpansion(
606 pattern, plugin_exception);
607
608 base::DictionaryValue* resource_exception = new base::DictionaryValue();
609 resource_exception->SetIntegerWithoutPathExpansion(
610 resource_id, CONTENT_SETTING_ALLOW);
611
612 plugin_exception->SetWithoutPathExpansion(
613 "per_resource", resource_exception);
614 }
615
616 // Only the notifications and plugin exceptions should appear in the
617 // old dictionary. We should also have a resource identifiers section
618 // for plugins.
619 {
620 DictionaryPrefUpdate update(
621 &prefs, prefs::kContentSettingsPatternPairs);
622 const base::DictionaryValue* old_dictionary = update.Get();
623
624 const base::DictionaryValue* exception;
625 EXPECT_TRUE(old_dictionary->GetDictionaryWithoutPathExpansion(
626 pattern, &exception));
627 EXPECT_EQ(3u, exception->size());
628 EXPECT_FALSE(exception->HasKey(
629 GetTypeName(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)));
630
631 int mouselock_exception_value = CONTENT_SETTING_DEFAULT;
632 exception->GetIntegerWithoutPathExpansion(
633 GetTypeName(CONTENT_SETTINGS_TYPE_MOUSELOCK),
634 &mouselock_exception_value);
635 DCHECK_EQ(CONTENT_SETTING_BLOCK, mouselock_exception_value);
636
637 int plugins_exception_value = CONTENT_SETTING_DEFAULT;
638 exception->GetIntegerWithoutPathExpansion(
639 GetTypeName(CONTENT_SETTINGS_TYPE_PLUGINS),
640 &plugins_exception_value);
641 DCHECK_EQ(CONTENT_SETTING_BLOCK, plugins_exception_value);
642
643 int resource_exception_value = CONTENT_SETTING_DEFAULT;
644 const base::DictionaryValue* resource_values;
645 exception->GetDictionaryWithoutPathExpansion(
646 "per_plugin", &resource_values);
647 resource_values->GetIntegerWithoutPathExpansion(
648 resource_id, &resource_exception_value);
649 DCHECK_EQ(CONTENT_SETTING_ALLOW, resource_exception_value);
650 }
651
652 provider.ShutdownOnUIThread();
653 }
654
655 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
656 TEST_F(PrefProviderTest, PMIMigrateOnlyAllow) {
657 TestingPrefServiceSyncable prefs;
658 PrefProvider::RegisterProfilePrefs(prefs.registry());
659
660 const std::string pattern_1 = "google.com,*";
661 const std::string pattern_2 = "www.google.com,*";
662 base::DictionaryValue* exception_1 = new base::DictionaryValue();
663 base::DictionaryValue* exception_2 = new base::DictionaryValue();
664
665 // Add both an "allow" and "block" exception for PMI.
666 exception_1->SetIntegerWithoutPathExpansion(
667 GetTypeName(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER),
668 CONTENT_SETTING_ALLOW);
669 exception_2->SetIntegerWithoutPathExpansion(
670 GetTypeName(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER),
671 CONTENT_SETTING_BLOCK);
672
673 // Change the old dictionary preference.
674 {
675 DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
676 base::DictionaryValue* old_dictionary = update.Get();
677 old_dictionary->SetWithoutPathExpansion(pattern_1, exception_1);
678 old_dictionary->SetWithoutPathExpansion(pattern_2, exception_2);
679 }
680
681 // Create the PrefProvider. It should migrate the settings.
682 PrefProvider provider(&prefs, false);
683
684 // The "block" exception for PMI was migrated, but "allow" was not.
685 {
686 DictionaryPrefUpdate update(
687 &prefs, prefs::kContentSettingsProtectedMediaIdentifierPatternPairs);
688 const base::DictionaryValue* pmi_dictionary = update.Get();
689 EXPECT_FALSE(pmi_dictionary->HasKey(pattern_1));
690 EXPECT_TRUE(pmi_dictionary->HasKey(pattern_2));
691 }
692
693 provider.ShutdownOnUIThread();
694 }
695 #endif
696
697 TEST_F(PrefProviderTest, PrefsMigrateVerbatim) {
698 TestingPrefServiceSyncable prefs;
699 PrefProvider::RegisterProfilePrefs(prefs.registry());
700
701 const std::string pattern_1 = "google.com,*";
702 const std::string pattern_2 = "www.google.com,*";
703 base::DictionaryValue* exception_1 = new base::DictionaryValue();
704 base::DictionaryValue* exception_2 = new base::DictionaryValue();
705 scoped_ptr<base::DictionaryValue> old_dictionary;
706
707 // Add two exceptions.
708 exception_1->SetIntegerWithoutPathExpansion(
709 GetTypeName(CONTENT_SETTINGS_TYPE_COOKIES),
710 CONTENT_SETTING_ALLOW);
711 exception_2->SetIntegerWithoutPathExpansion(
712 GetTypeName(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS),
713 CONTENT_SETTING_BLOCK);
714
715 // Change the old dictionary preference.
716 {
717 DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
718 base::DictionaryValue* dictionary = update.Get();
719 dictionary->SetWithoutPathExpansion(pattern_1, exception_1);
720 dictionary->SetWithoutPathExpansion(pattern_2, exception_2);
721 old_dictionary.reset(dictionary->DeepCopy());
722 }
723
724 // Create the PrefProvider. It should copy the settings from the old
725 // preference to the new ones.
726 PrefProvider provider(&prefs, false);
727
728 // Force copying back from the new preferences to the old one.
729 {
730 DictionaryPrefUpdate update(
731 &prefs, prefs::kContentSettingsCookiesPatternPairs);
732 }
733 {
734 DictionaryPrefUpdate update(
735 &prefs, prefs::kContentSettingsAutomaticDownloadsPatternPairs);
736 }
737
738 // Test if the value after copying there and back is the same.
739 {
740 DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
741 base::DictionaryValue* new_dictionary = update.Get();
742 EXPECT_TRUE(old_dictionary->Equals(new_dictionary));
743 }
744
745 provider.ShutdownOnUIThread();
746 }
747
748 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) { 475 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
749 TestingPrefServiceSyncable prefs; 476 TestingPrefServiceSyncable prefs;
750 PrefProvider::RegisterProfilePrefs(prefs.registry()); 477 PrefProvider::RegisterProfilePrefs(prefs.registry());
751 478
752 ContentSettingsPattern pattern_1 = 479 ContentSettingsPattern pattern_1 =
753 ContentSettingsPattern::FromString("google.com"); 480 ContentSettingsPattern::FromString("google.com");
754 ContentSettingsPattern pattern_2 = 481 ContentSettingsPattern pattern_2 =
755 ContentSettingsPattern::FromString("www.google.com"); 482 ContentSettingsPattern::FromString("www.google.com");
756 ContentSettingsPattern wildcard = 483 ContentSettingsPattern wildcard =
757 ContentSettingsPattern::FromString("*"); 484 ContentSettingsPattern::FromString("*");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 576
850 // Non-empty pattern, non-syncable, empty resource identifier. 577 // Non-empty pattern, non-syncable, empty resource identifier.
851 provider.SetWebsiteSetting(pattern, wildcard, 578 provider.SetWebsiteSetting(pattern, wildcard,
852 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 579 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
853 ResourceIdentifier(), value->DeepCopy()); 580 ResourceIdentifier(), value->DeepCopy());
854 581
855 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_IMAGES); 582 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_IMAGES);
856 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION); 583 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION);
857 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS); 584 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS);
858 585
859 // Test that the new preferences for images, geolocation and plugins 586 // Test that the preferences for images, geolocation and plugins are empty.
860 // are empty.
861 const char* empty_prefs[] = { 587 const char* empty_prefs[] = {
862 prefs::kContentSettingsImagesPatternPairs, 588 prefs::kContentSettingsImagesPatternPairs,
863 prefs::kContentSettingsGeolocationPatternPairs, 589 prefs::kContentSettingsGeolocationPatternPairs,
864 prefs::kContentSettingsPluginsPatternPairs 590 prefs::kContentSettingsPluginsPatternPairs
865 }; 591 };
866 592
867 for (const char* pref : empty_prefs) { 593 for (const char* pref : empty_prefs) {
868 DictionaryPrefUpdate update(&prefs, pref); 594 DictionaryPrefUpdate update(&prefs, pref);
869 const base::DictionaryValue* dictionary = update.Get(); 595 const base::DictionaryValue* dictionary = update.Get();
870 EXPECT_TRUE(dictionary->empty()); 596 EXPECT_TRUE(dictionary->empty());
871 } 597 }
872 598
873 // Test that the preferences for cookies and notifications are not empty. 599 // Test that the preferences for cookies and notifications are not empty.
874 const char* nonempty_prefs[] = { 600 const char* nonempty_prefs[] = {
875 prefs::kContentSettingsCookiesPatternPairs, 601 prefs::kContentSettingsCookiesPatternPairs,
876 prefs::kContentSettingsNotificationsPatternPairs 602 prefs::kContentSettingsNotificationsPatternPairs
877 }; 603 };
878 604
879 for (const char* pref : nonempty_prefs) { 605 for (const char* pref : nonempty_prefs) {
880 DictionaryPrefUpdate update(&prefs, pref); 606 DictionaryPrefUpdate update(&prefs, pref);
881 const base::DictionaryValue* dictionary = update.Get(); 607 const base::DictionaryValue* dictionary = update.Get();
882 EXPECT_EQ(1u, dictionary->size()); 608 EXPECT_EQ(1u, dictionary->size());
883 } 609 }
884 610
885 // Test that the old preference only contains cookies and notifications.
886 {
887 DictionaryPrefUpdate update(&prefs, prefs::kContentSettingsPatternPairs);
888 const base::DictionaryValue* dictionary = update.Get();
889 const base::DictionaryValue* exception;
890 EXPECT_TRUE(dictionary->GetDictionaryWithoutPathExpansion(
891 CreatePatternString(pattern, wildcard), &exception));
892 EXPECT_EQ(1u, exception->size());
893 EXPECT_TRUE(exception->HasKey(GetTypeName(CONTENT_SETTINGS_TYPE_COOKIES)));
894
895 // The notification setting was not cleared, but it was also never written
896 // to the old preference, as it is unsyncable.
897 }
898
899 provider.ShutdownOnUIThread(); 611 provider.ShutdownOnUIThread();
900 } 612 }
901 613
902 } // namespace content_settings 614 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698