OLD | NEW |
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 "chrome/browser/extensions/extension_prefs_unittest.h" | 5 #include "chrome/browser/extensions/extension_prefs_unittest.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/prefs/mock_pref_change_callback.h" | 10 #include "base/prefs/mock_pref_change_callback.h" |
11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/extensions/extension_pref_value_map.h" | 17 #include "chrome/browser/extensions/extension_pref_value_map.h" |
18 #include "chrome/browser/extensions/extension_prefs.h" | 18 #include "chrome/browser/extensions/extension_prefs.h" |
19 #include "chrome/browser/prefs/pref_service_syncable.h" | 19 #include "chrome/browser/prefs/pref_service_syncable.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
24 #include "content/public/test/mock_notification_observer.h" | 24 #include "content/public/test/mock_notification_observer.h" |
| 25 #include "extensions/common/extension.h" |
25 #include "extensions/common/manifest_constants.h" | 26 #include "extensions/common/manifest_constants.h" |
26 #include "extensions/common/permissions/permission_set.h" | 27 #include "extensions/common/permissions/permission_set.h" |
27 #include "extensions/common/permissions/permissions_info.h" | 28 #include "extensions/common/permissions/permissions_info.h" |
28 #include "sync/api/string_ordinal.h" | 29 #include "sync/api/string_ordinal.h" |
29 | 30 |
30 using base::Time; | 31 using base::Time; |
31 using base::TimeDelta; | 32 using base::TimeDelta; |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 | 34 |
34 namespace extensions { | 35 namespace extensions { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 }; | 96 }; |
96 TEST_F(ExtensionPrefsLastPingDay, LastPingDay) {} | 97 TEST_F(ExtensionPrefsLastPingDay, LastPingDay) {} |
97 | 98 |
98 // Tests the GetToolbarOrder/SetToolbarOrder functions. | 99 // Tests the GetToolbarOrder/SetToolbarOrder functions. |
99 class ExtensionPrefsToolbarOrder : public ExtensionPrefsTest { | 100 class ExtensionPrefsToolbarOrder : public ExtensionPrefsTest { |
100 public: | 101 public: |
101 virtual void Initialize() OVERRIDE { | 102 virtual void Initialize() OVERRIDE { |
102 list_.push_back(prefs_.AddExtensionAndReturnId("1")); | 103 list_.push_back(prefs_.AddExtensionAndReturnId("1")); |
103 list_.push_back(prefs_.AddExtensionAndReturnId("2")); | 104 list_.push_back(prefs_.AddExtensionAndReturnId("2")); |
104 list_.push_back(prefs_.AddExtensionAndReturnId("3")); | 105 list_.push_back(prefs_.AddExtensionAndReturnId("3")); |
105 std::vector<std::string> before_list = prefs()->GetToolbarOrder(); | 106 ExtensionIdList before_list = prefs()->GetToolbarOrder(); |
106 EXPECT_TRUE(before_list.empty()); | 107 EXPECT_TRUE(before_list.empty()); |
107 prefs()->SetToolbarOrder(list_); | 108 prefs()->SetToolbarOrder(list_); |
108 } | 109 } |
109 | 110 |
110 virtual void Verify() OVERRIDE { | 111 virtual void Verify() OVERRIDE { |
111 std::vector<std::string> result = prefs()->GetToolbarOrder(); | 112 ExtensionIdList result = prefs()->GetToolbarOrder(); |
112 ASSERT_EQ(list_, result); | 113 ASSERT_EQ(list_, result); |
113 } | 114 } |
114 | 115 |
115 private: | 116 private: |
116 std::vector<std::string> list_; | 117 ExtensionIdList list_; |
117 }; | 118 }; |
118 TEST_F(ExtensionPrefsToolbarOrder, ToolbarOrder) {} | 119 TEST_F(ExtensionPrefsToolbarOrder, ToolbarOrder) {} |
119 | 120 |
120 // Tests the GetKnownDisabled/SetKnownDisabled functions. | 121 // Tests the GetKnownDisabled/SetKnownDisabled functions. |
121 class ExtensionPrefsKnownDisabled : public ExtensionPrefsTest { | 122 class ExtensionPrefsKnownDisabled : public ExtensionPrefsTest { |
122 public: | 123 public: |
123 virtual void Initialize() OVERRIDE { | 124 virtual void Initialize() OVERRIDE { |
| 125 ExtensionIdSet before_set; |
| 126 EXPECT_FALSE(prefs()->GetKnownDisabled(&before_set)); |
| 127 EXPECT_TRUE(before_set.empty()); |
| 128 |
| 129 // Initialize to an empty list and confirm that GetKnownDisabled() returns |
| 130 // true and an empty list. |
| 131 prefs()->SetKnownDisabled(before_set); |
| 132 EXPECT_TRUE(prefs()->GetKnownDisabled(&before_set)); |
| 133 EXPECT_TRUE(before_set.empty()); |
| 134 |
124 set_.insert(prefs_.AddExtensionAndReturnId("1")); | 135 set_.insert(prefs_.AddExtensionAndReturnId("1")); |
125 set_.insert(prefs_.AddExtensionAndReturnId("2")); | 136 set_.insert(prefs_.AddExtensionAndReturnId("2")); |
126 set_.insert(prefs_.AddExtensionAndReturnId("3")); | 137 set_.insert(prefs_.AddExtensionAndReturnId("3")); |
127 std::set<std::string> before_set = prefs()->GetKnownDisabled(); | |
128 EXPECT_TRUE(before_set.empty()); | |
129 prefs()->SetKnownDisabled(set_); | 138 prefs()->SetKnownDisabled(set_); |
130 } | 139 } |
131 | 140 |
132 virtual void Verify() OVERRIDE { | 141 virtual void Verify() OVERRIDE { |
133 std::set<std::string> result = prefs()->GetKnownDisabled(); | 142 ExtensionIdSet result; |
| 143 EXPECT_TRUE(prefs()->GetKnownDisabled(&result)); |
134 ASSERT_EQ(set_, result); | 144 ASSERT_EQ(set_, result); |
135 } | 145 } |
136 | 146 |
137 private: | 147 private: |
138 std::set<std::string> set_; | 148 ExtensionIdSet set_; |
139 }; | 149 }; |
140 TEST_F(ExtensionPrefsKnownDisabled, KnownDisabled) {} | 150 TEST_F(ExtensionPrefsKnownDisabled, KnownDisabled) {} |
141 | 151 |
142 // Tests the IsExtensionDisabled/SetExtensionState functions. | 152 // Tests the IsExtensionDisabled/SetExtensionState functions. |
143 class ExtensionPrefsExtensionState : public ExtensionPrefsTest { | 153 class ExtensionPrefsExtensionState : public ExtensionPrefsTest { |
144 public: | 154 public: |
145 virtual void Initialize() OVERRIDE { | 155 virtual void Initialize() OVERRIDE { |
146 extension = prefs_.AddExtension("test"); | 156 extension = prefs_.AddExtension("test"); |
147 prefs()->SetExtensionState(extension->id(), Extension::DISABLED); | 157 prefs()->SetExtensionState(extension->id(), Extension::DISABLED); |
148 } | 158 } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 virtual ~ExtensionPrefsBlacklistedExtensions() {} | 779 virtual ~ExtensionPrefsBlacklistedExtensions() {} |
770 | 780 |
771 virtual void Initialize() OVERRIDE { | 781 virtual void Initialize() OVERRIDE { |
772 extension_a_ = prefs_.AddExtension("a"); | 782 extension_a_ = prefs_.AddExtension("a"); |
773 extension_b_ = prefs_.AddExtension("b"); | 783 extension_b_ = prefs_.AddExtension("b"); |
774 extension_c_ = prefs_.AddExtension("c"); | 784 extension_c_ = prefs_.AddExtension("c"); |
775 } | 785 } |
776 | 786 |
777 virtual void Verify() OVERRIDE { | 787 virtual void Verify() OVERRIDE { |
778 { | 788 { |
779 std::set<std::string> ids; | 789 ExtensionIdSet ids; |
780 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 790 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
781 } | 791 } |
782 prefs()->SetExtensionBlacklisted(extension_a_->id(), true); | 792 prefs()->SetExtensionBlacklisted(extension_a_->id(), true); |
783 { | 793 { |
784 std::set<std::string> ids; | 794 ExtensionIdSet ids; |
785 ids.insert(extension_a_->id()); | 795 ids.insert(extension_a_->id()); |
786 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 796 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
787 } | 797 } |
788 prefs()->SetExtensionBlacklisted(extension_b_->id(), true); | 798 prefs()->SetExtensionBlacklisted(extension_b_->id(), true); |
789 prefs()->SetExtensionBlacklisted(extension_c_->id(), true); | 799 prefs()->SetExtensionBlacklisted(extension_c_->id(), true); |
790 { | 800 { |
791 std::set<std::string> ids; | 801 ExtensionIdSet ids; |
792 ids.insert(extension_a_->id()); | 802 ids.insert(extension_a_->id()); |
793 ids.insert(extension_b_->id()); | 803 ids.insert(extension_b_->id()); |
794 ids.insert(extension_c_->id()); | 804 ids.insert(extension_c_->id()); |
795 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 805 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
796 } | 806 } |
797 prefs()->SetExtensionBlacklisted(extension_a_->id(), false); | 807 prefs()->SetExtensionBlacklisted(extension_a_->id(), false); |
798 { | 808 { |
799 std::set<std::string> ids; | 809 ExtensionIdSet ids; |
800 ids.insert(extension_b_->id()); | 810 ids.insert(extension_b_->id()); |
801 ids.insert(extension_c_->id()); | 811 ids.insert(extension_c_->id()); |
802 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 812 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
803 } | 813 } |
804 prefs()->SetExtensionBlacklisted(extension_b_->id(), false); | 814 prefs()->SetExtensionBlacklisted(extension_b_->id(), false); |
805 prefs()->SetExtensionBlacklisted(extension_c_->id(), false); | 815 prefs()->SetExtensionBlacklisted(extension_c_->id(), false); |
806 { | 816 { |
807 std::set<std::string> ids; | 817 ExtensionIdSet ids; |
808 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 818 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
809 } | 819 } |
810 | 820 |
811 // The interesting part: make sure that we're cleaning up after ourselves | 821 // The interesting part: make sure that we're cleaning up after ourselves |
812 // when we're storing *just* the fact that the extension is blacklisted. | 822 // when we're storing *just* the fact that the extension is blacklisted. |
813 std::string arbitrary_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 823 std::string arbitrary_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
814 | 824 |
815 prefs()->SetExtensionBlacklisted(arbitrary_id, true); | 825 prefs()->SetExtensionBlacklisted(arbitrary_id, true); |
816 prefs()->SetExtensionBlacklisted(extension_a_->id(), true); | 826 prefs()->SetExtensionBlacklisted(extension_a_->id(), true); |
817 | 827 |
818 // (And make sure that the acknowledged bit is also cleared). | 828 // (And make sure that the acknowledged bit is also cleared). |
819 prefs()->AcknowledgeBlacklistedExtension(arbitrary_id); | 829 prefs()->AcknowledgeBlacklistedExtension(arbitrary_id); |
820 | 830 |
821 EXPECT_TRUE(prefs()->GetExtensionPref(arbitrary_id)); | 831 EXPECT_TRUE(prefs()->GetExtensionPref(arbitrary_id)); |
822 { | 832 { |
823 std::set<std::string> ids; | 833 ExtensionIdSet ids; |
824 ids.insert(arbitrary_id); | 834 ids.insert(arbitrary_id); |
825 ids.insert(extension_a_->id()); | 835 ids.insert(extension_a_->id()); |
826 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 836 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
827 } | 837 } |
828 prefs()->SetExtensionBlacklisted(arbitrary_id, false); | 838 prefs()->SetExtensionBlacklisted(arbitrary_id, false); |
829 prefs()->SetExtensionBlacklisted(extension_a_->id(), false); | 839 prefs()->SetExtensionBlacklisted(extension_a_->id(), false); |
830 EXPECT_FALSE(prefs()->GetExtensionPref(arbitrary_id)); | 840 EXPECT_FALSE(prefs()->GetExtensionPref(arbitrary_id)); |
831 { | 841 { |
832 std::set<std::string> ids; | 842 ExtensionIdSet ids; |
833 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); | 843 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
834 } | 844 } |
835 } | 845 } |
836 | 846 |
837 private: | 847 private: |
838 scoped_refptr<const Extension> extension_a_; | 848 scoped_refptr<const Extension> extension_a_; |
839 scoped_refptr<const Extension> extension_b_; | 849 scoped_refptr<const Extension> extension_b_; |
840 scoped_refptr<const Extension> extension_c_; | 850 scoped_refptr<const Extension> extension_c_; |
841 }; | 851 }; |
842 TEST_F(ExtensionPrefsBlacklistedExtensions, | 852 TEST_F(ExtensionPrefsBlacklistedExtensions, |
843 ExtensionPrefsBlacklistedExtensions) {} | 853 ExtensionPrefsBlacklistedExtensions) {} |
844 | 854 |
845 } // namespace extensions | 855 } // namespace extensions |
OLD | NEW |