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

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

Issue 7655019: Migrate Obsolete NotificationsSettings and remove content_settings::NotificationsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove include of deleted notifications_prefs_cache.h Created 9 years, 3 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 | Annotate | Revision Log
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_pref_provider.h" 5 #include "chrome/browser/content_settings/content_settings_pref_provider.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 "chrome/browser/content_settings/content_settings_mock_observer.h" 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 11 #include "chrome/browser/prefs/browser_prefs.h"
11 #include "chrome/browser/prefs/default_pref_store.h" 12 #include "chrome/browser/prefs/default_pref_store.h"
12 #include "chrome/browser/prefs/incognito_user_pref_store.h" 13 #include "chrome/browser/prefs/incognito_user_pref_store.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/pref_service_mock_builder.h" 15 #include "chrome/browser/prefs/pref_service_mock_builder.h"
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" 16 #include "chrome/browser/prefs/scoped_user_pref_update.h"
16 #include "chrome/browser/prefs/testing_pref_store.h" 17 #include "chrome/browser/prefs/testing_pref_store.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 DictionaryPrefUpdate update(prefs, 671 DictionaryPrefUpdate update(prefs,
671 prefs::kContentSettingsPatternPairs); 672 prefs::kContentSettingsPatternPairs);
672 DictionaryValue* all_settings_dictionary = update.Get(); 673 DictionaryValue* all_settings_dictionary = update.Get();
673 std::string key( 674 std::string key(
674 primary_pattern.ToString()+ "," + 675 primary_pattern.ToString()+ "," +
675 secondary_pattern.ToString()); 676 secondary_pattern.ToString());
676 all_settings_dictionary->SetWithoutPathExpansion( 677 all_settings_dictionary->SetWithoutPathExpansion(
677 key, settings_dictionary->DeepCopy()); 678 key, settings_dictionary->DeepCopy());
678 679
679 key = std::string( 680 key = std::string(
680 primary_pattern_2.ToString()+ "," + 681 primary_pattern_2.ToString() + "," +
681 secondary_pattern.ToString()); 682 secondary_pattern.ToString());
682 all_settings_dictionary->SetWithoutPathExpansion( 683 all_settings_dictionary->SetWithoutPathExpansion(
683 key, settings_dictionary->DeepCopy()); 684 key, settings_dictionary->DeepCopy());
684 } 685 }
685 686
686 // Test if the obsolete geolocation preference is kept in sync if the new 687 // Test if the obsolete geolocation preference is kept in sync if the new
687 // preference is changed by a sync. 688 // preference is changed by a sync.
688 GURL primary_url("http://www.bar.com"); 689 GURL primary_url("http://www.bar.com");
689 GURL primary_url_2("http://www.example.com"); 690 GURL primary_url_2("http://www.example.com");
690 GURL secondary_url("http://www.foo.com"); 691 GURL secondary_url("http://www.foo.com");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 CONTENT_SETTING_ALLOW); 728 CONTENT_SETTING_ALLOW);
728 EXPECT_EQ(CONTENT_SETTING_ALLOW, 729 EXPECT_EQ(CONTENT_SETTING_ALLOW,
729 provider.GetContentSetting( 730 provider.GetContentSetting(
730 primary_url, 731 primary_url,
731 secondary_url, 732 secondary_url,
732 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, 733 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
733 std::string())); 734 std::string()));
734 provider.ShutdownOnUIThread(); 735 provider.ShutdownOnUIThread();
735 } 736 }
736 737
738 TEST_F(PrefProviderTest, MigrateObsoleteNotificationsPref) {
739 TestingProfile profile;
740 PrefService* prefs = profile.GetPrefs();
741 GURL allowed_url("http://www.foo.com");
742 GURL allowed_url2("http://www.example.com");
743 GURL denied_url("http://www.bar.com");
744
745 // Set obsolete preference.
746 scoped_ptr<ListValue> allowed_origin_list(new ListValue());
747 allowed_origin_list->AppendIfNotPresent(
748 Value::CreateStringValue(allowed_url.spec()));
749 prefs->Set(prefs::kDesktopNotificationAllowedOrigins,
750 *allowed_origin_list);
751
752 scoped_ptr<ListValue> denied_origin_list(new ListValue());
753 denied_origin_list->AppendIfNotPresent(
754 Value::CreateStringValue(denied_url.spec()));
755 prefs->Set(prefs::kDesktopNotificationDeniedOrigins,
756 *denied_origin_list);
757
758 content_settings::PrefProvider provider(prefs, false);
759
760 // Test if the migrated settings are loaded and available.
761 EXPECT_EQ(CONTENT_SETTING_ALLOW, provider.GetContentSetting(
762 allowed_url,
763 allowed_url,
764 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
765 ""));
766 EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting(
767 denied_url,
768 denied_url,
769 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
770 ""));
771 EXPECT_EQ(CONTENT_SETTING_DEFAULT, provider.GetContentSetting(
772 allowed_url2,
773 allowed_url2,
774 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
775 ""));
776 // Check if the settings where migrated correctly.
777 const DictionaryValue* const_all_settings_dictionary =
778 prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
779 EXPECT_EQ(2U, const_all_settings_dictionary->size());
780 EXPECT_TRUE(const_all_settings_dictionary->HasKey(
781 ContentSettingsPattern::FromURLNoWildcard(allowed_url).ToString() + "," +
782 ContentSettingsPattern::Wildcard().ToString()));
783 EXPECT_TRUE(const_all_settings_dictionary->HasKey(
784 ContentSettingsPattern::FromURLNoWildcard(denied_url).ToString() + "," +
785 ContentSettingsPattern::Wildcard().ToString()));
786
787 // Check that notifications settings were not synced to the obsolete content
788 // settings pattern preference.
789 const DictionaryValue* const_obsolete_patterns_dictionary =
790 prefs->GetDictionary(prefs::kContentSettingsPatterns);
791 EXPECT_TRUE(const_obsolete_patterns_dictionary->empty());
792
793 // Change obsolete preference. This could be triggered by sync if sync is used
794 // with an old version of chrome.
795 allowed_origin_list.reset(new ListValue());
796 allowed_origin_list->AppendIfNotPresent(
797 Value::CreateStringValue(allowed_url2.spec()));
798 prefs->Set(prefs::kDesktopNotificationAllowedOrigins,
799 *allowed_origin_list);
800
801 // Test if the changed obsolete preference was migrated correctly.
802 EXPECT_EQ(CONTENT_SETTING_ALLOW, provider.GetContentSetting(
803 allowed_url2,
804 allowed_url2,
805 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
806 ""));
807 EXPECT_EQ(CONTENT_SETTING_DEFAULT, provider.GetContentSetting(
808 allowed_url,
809 allowed_url,
810 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
811 ""));
812 EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting(
813 denied_url,
814 denied_url,
815 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
816 ""));
817 // Check that geolocation settings were not synced to the obsolete content
818 // settings pattern preference.
819 const_obsolete_patterns_dictionary =
820 prefs->GetDictionary(prefs::kContentSettingsPatterns);
821 EXPECT_TRUE(const_obsolete_patterns_dictionary->empty());
822
823 provider.ShutdownOnUIThread();
824 }
825
826 TEST_F(PrefProviderTest, SyncObsoleteNotificationsPref) {
827 TestingProfile profile;
828 PrefService* prefs = profile.GetPrefs();
829
830 content_settings::PrefProvider provider(prefs, false);
831
832 // Changing the preferences prefs::kContentSettingsPatternPairs.
833 ContentSettingsPattern primary_pattern=
834 ContentSettingsPattern::FromString("http://www.bar.com");
835 ContentSettingsPattern primary_pattern_2 =
836 ContentSettingsPattern::FromString("http://www.example.com");
837 ContentSettingsPattern secondary_pattern =
838 ContentSettingsPattern::Wildcard();
839 GURL primary_url("http://www.bar.com");
840 GURL primary_url_2("http://www.example.com");
841
842 {
843 DictionaryPrefUpdate update(prefs,
844 prefs::kContentSettingsPatternPairs);
845 DictionaryValue* all_settings_dictionary = update.Get();
846
847 scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue());
848 settings_dictionary->SetInteger("notifications", CONTENT_SETTING_BLOCK);
849 std::string key(
850 primary_pattern.ToString() + "," +
851 secondary_pattern.ToString());
852 all_settings_dictionary->SetWithoutPathExpansion(
853 key, settings_dictionary->DeepCopy());
854
855 settings_dictionary.reset(new DictionaryValue());
856 settings_dictionary->SetInteger("notifications", CONTENT_SETTING_ALLOW);
857 key = primary_pattern_2.ToString() + "," + secondary_pattern.ToString();
858 all_settings_dictionary->SetWithoutPathExpansion(
859 key, settings_dictionary->DeepCopy());
860 }
861
862 // Test if the obsolete notifications preference is kept in sync if the new
863 // preference is changed by a sync.
864 const ListValue* denied_origin_list =
865 prefs->GetList(prefs::kDesktopNotificationAllowedOrigins);
866 EXPECT_EQ(1U, denied_origin_list->GetSize());
867 const ListValue* allowed_origin_list =
868 prefs->GetList(prefs::kDesktopNotificationDeniedOrigins);
869 EXPECT_EQ(1U, allowed_origin_list->GetSize());
870
871 provider.ShutdownOnUIThread();
872 }
873
737 } // namespace content_settings 874 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698