OLD | NEW |
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/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Loading... |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/task.h" | 22 #include "base/task.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "base/version.h" | 24 #include "base/version.h" |
25 #include "chrome/browser/appcache/chrome_appcache_service.h" | 25 #include "chrome/browser/appcache/chrome_appcache_service.h" |
26 #include "chrome/browser/browser_thread.h" | 26 #include "chrome/browser/browser_thread.h" |
27 #include "chrome/browser/extensions/crx_installer.h" | 27 #include "chrome/browser/extensions/crx_installer.h" |
28 #include "chrome/browser/extensions/extension_creator.h" | 28 #include "chrome/browser/extensions/extension_creator.h" |
29 #include "chrome/browser/extensions/extension_error_reporter.h" | 29 #include "chrome/browser/extensions/extension_error_reporter.h" |
30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
31 #include "chrome/browser/extensions/external_extension_provider.h" | 31 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
32 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 32 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
| 33 #include "chrome/browser/extensions/external_pref_extension_loader.h" |
33 #include "chrome/browser/extensions/pack_extension_job.cc" | 34 #include "chrome/browser/extensions/pack_extension_job.cc" |
34 #include "chrome/browser/file_system/browser_file_system_helper.h" | 35 #include "chrome/browser/file_system/browser_file_system_helper.h" |
35 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 36 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
36 #include "chrome/browser/in_process_webkit/webkit_context.h" | 37 #include "chrome/browser/in_process_webkit/webkit_context.h" |
37 #include "chrome/browser/prefs/browser_prefs.h" | 38 #include "chrome/browser/prefs/browser_prefs.h" |
38 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 39 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
39 #include "chrome/browser/prefs/scoped_pref_update.h" | 40 #include "chrome/browser/prefs/scoped_pref_update.h" |
40 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
41 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
42 #include "chrome/common/extensions/extension.h" | 43 #include "chrome/common/extensions/extension.h" |
(...skipping 75 matching lines...) Loading... |
118 | 119 |
119 std::set<std::string> strings2; | 120 std::set<std::string> strings2; |
120 for (size_t i = 0; i < patterns2.size(); ++i) | 121 for (size_t i = 0; i < patterns2.size(); ++i) |
121 strings2.insert(patterns2.at(i).GetAsString()); | 122 strings2.insert(patterns2.at(i).GetAsString()); |
122 | 123 |
123 EXPECT_EQ(strings1, strings2); | 124 EXPECT_EQ(strings1, strings2); |
124 } | 125 } |
125 | 126 |
126 } // namespace | 127 } // namespace |
127 | 128 |
128 class MockExtensionProvider : public ExternalExtensionProvider { | 129 class MockExtensionProvider : public ExternalExtensionProviderInterface { |
129 public: | 130 public: |
130 explicit MockExtensionProvider(Extension::Location location) | 131 explicit MockExtensionProvider( |
131 : location_(location), visit_count_(0) {} | 132 VisitorInterface* visitor, |
| 133 Extension::Location location) |
| 134 : location_(location), visitor_(visitor), visit_count_(0) { |
| 135 } |
132 virtual ~MockExtensionProvider() {} | 136 virtual ~MockExtensionProvider() {} |
133 | 137 |
134 void UpdateOrAddExtension(const std::string& id, | 138 void UpdateOrAddExtension(const std::string& id, |
135 const std::string& version, | 139 const std::string& version, |
136 const FilePath& path) { | 140 const FilePath& path) { |
137 extension_map_[id] = std::make_pair(version, path); | 141 extension_map_[id] = std::make_pair(version, path); |
138 } | 142 } |
139 | 143 |
140 void RemoveExtension(const std::string& id) { | 144 void RemoveExtension(const std::string& id) { |
141 extension_map_.erase(id); | 145 extension_map_.erase(id); |
142 } | 146 } |
143 | 147 |
144 // ExternalExtensionProvider implementation: | 148 // ExternalExtensionProvider implementation: |
145 virtual void VisitRegisteredExtension(Visitor* visitor) const { | 149 virtual void VisitRegisteredExtension() const { |
146 visit_count_++; | 150 visit_count_++; |
147 for (DataMap::const_iterator i = extension_map_.begin(); | 151 for (DataMap::const_iterator i = extension_map_.begin(); |
148 i != extension_map_.end(); ++i) { | 152 i != extension_map_.end(); ++i) { |
149 scoped_ptr<Version> version; | 153 scoped_ptr<Version> version; |
150 version.reset(Version::GetVersionFromString(i->second.first)); | 154 version.reset(Version::GetVersionFromString(i->second.first)); |
151 | 155 |
152 visitor->OnExternalExtensionFileFound( | 156 visitor_->OnExternalExtensionFileFound( |
153 i->first, version.get(), i->second.second, location_); | 157 i->first, version.get(), i->second.second, location_); |
154 } | 158 } |
| 159 visitor_->OnExternalProviderReady(); |
155 } | 160 } |
156 | 161 |
157 virtual bool HasExtension(const std::string& id) const { | 162 virtual bool HasExtension(const std::string& id) const { |
158 return extension_map_.find(id) != extension_map_.end(); | 163 return extension_map_.find(id) != extension_map_.end(); |
159 } | 164 } |
160 | 165 |
161 virtual bool GetExtensionDetails(const std::string& id, | 166 virtual bool GetExtensionDetails(const std::string& id, |
162 Extension::Location* location, | 167 Extension::Location* location, |
163 scoped_ptr<Version>* version) const { | 168 scoped_ptr<Version>* version) const { |
164 DataMap::const_iterator it = extension_map_.find(id); | 169 DataMap::const_iterator it = extension_map_.find(id); |
165 if (it == extension_map_.end()) | 170 if (it == extension_map_.end()) |
166 return false; | 171 return false; |
167 | 172 |
168 if (version) | 173 if (version) |
169 version->reset(Version::GetVersionFromString(it->second.first)); | 174 version->reset(Version::GetVersionFromString(it->second.first)); |
170 | 175 |
171 if (location) | 176 if (location) |
172 *location = location_; | 177 *location = location_; |
173 | 178 |
174 return true; | 179 return true; |
175 } | 180 } |
| 181 |
| 182 virtual bool IsReady() { |
| 183 return true; |
| 184 } |
| 185 |
| 186 virtual void ServiceShutdown() { |
| 187 } |
| 188 |
176 int visit_count() const { return visit_count_; } | 189 int visit_count() const { return visit_count_; } |
177 void set_visit_count(int visit_count) { | 190 void set_visit_count(int visit_count) { |
178 visit_count_ = visit_count; | 191 visit_count_ = visit_count; |
179 } | 192 } |
180 | 193 |
181 private: | 194 private: |
182 typedef std::map< std::string, std::pair<std::string, FilePath> > DataMap; | 195 typedef std::map< std::string, std::pair<std::string, FilePath> > DataMap; |
183 DataMap extension_map_; | 196 DataMap extension_map_; |
184 Extension::Location location_; | 197 Extension::Location location_; |
| 198 VisitorInterface* visitor_; |
185 | 199 |
186 // visit_count_ tracks the number of calls to VisitRegisteredExtension(). | 200 // visit_count_ tracks the number of calls to VisitRegisteredExtension(). |
187 // Mutable because it must be incremented on each call to | 201 // Mutable because it must be incremented on each call to |
188 // VisitRegisteredExtension(), which must be a const method to inherit | 202 // VisitRegisteredExtension(), which must be a const method to inherit |
189 // from the class being mocked. | 203 // from the class being mocked. |
190 mutable int visit_count_; | 204 mutable int visit_count_; |
191 | 205 |
192 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); | 206 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); |
193 }; | 207 }; |
194 | 208 |
195 class MockProviderVisitor : public ExternalExtensionProvider::Visitor { | 209 class MockProviderVisitor |
| 210 : public ExternalExtensionProviderInterface::VisitorInterface { |
196 public: | 211 public: |
197 MockProviderVisitor() : ids_found_(0) { | 212 MockProviderVisitor() : ids_found_(0) { |
198 } | 213 } |
199 | 214 |
200 int Visit(const std::string& json_data) { | 215 int Visit(const std::string& json_data) { |
201 // Give the test json file to the provider for parsing. | 216 // Give the test json file to the provider for parsing. |
202 provider_.reset(new ExternalPrefExtensionProvider()); | 217 provider_.reset(new ExternalExtensionProviderImpl( |
203 provider_->SetPreferencesForTesting(json_data); | 218 this, |
| 219 new ExternalTestingExtensionLoader(json_data), |
| 220 Extension::EXTERNAL_PREF, |
| 221 Extension::EXTERNAL_PREF_DOWNLOAD)); |
204 | 222 |
205 // We also parse the file into a dictionary to compare what we get back | 223 // We also parse the file into a dictionary to compare what we get back |
206 // from the provider. | 224 // from the provider. |
207 JSONStringValueSerializer serializer(json_data); | 225 JSONStringValueSerializer serializer(json_data); |
208 Value* json_value = serializer.Deserialize(NULL, NULL); | 226 Value* json_value = serializer.Deserialize(NULL, NULL); |
209 | 227 |
210 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { | 228 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { |
211 NOTREACHED() << "Unable to deserialize json data"; | 229 NOTREACHED() << "Unable to deserialize json data"; |
212 return -1; | 230 return -1; |
213 } else { | 231 } else { |
214 DictionaryValue* external_extensions = | 232 DictionaryValue* external_extensions = |
215 static_cast<DictionaryValue*>(json_value); | 233 static_cast<DictionaryValue*>(json_value); |
216 prefs_.reset(external_extensions); | 234 prefs_.reset(external_extensions); |
217 } | 235 } |
218 | 236 |
219 // Reset our counter. | 237 // Reset our counter. |
220 ids_found_ = 0; | 238 ids_found_ = 0; |
221 // Ask the provider to look up all extensions and return them. | 239 // Ask the provider to look up all extensions and return them. |
222 provider_->VisitRegisteredExtension(this); | 240 provider_->VisitRegisteredExtension(); |
223 | 241 |
224 return ids_found_; | 242 return ids_found_; |
225 } | 243 } |
226 | 244 |
227 virtual void OnExternalExtensionFileFound(const std::string& id, | 245 virtual void OnExternalExtensionFileFound(const std::string& id, |
228 const Version* version, | 246 const Version* version, |
229 const FilePath& path, | 247 const FilePath& path, |
230 Extension::Location unused) { | 248 Extension::Location unused) { |
231 ++ids_found_; | 249 ++ids_found_; |
232 DictionaryValue* pref; | 250 DictionaryValue* pref; |
(...skipping 45 matching lines...) Loading... |
278 Extension::Location location1 = Extension::INVALID; | 296 Extension::Location location1 = Extension::INVALID; |
279 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); | 297 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
280 EXPECT_FALSE(v1.get()); | 298 EXPECT_FALSE(v1.get()); |
281 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1); | 299 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1); |
282 | 300 |
283 // Remove it so we won't count it again. | 301 // Remove it so we won't count it again. |
284 prefs_->Remove(id, NULL); | 302 prefs_->Remove(id, NULL); |
285 } | 303 } |
286 } | 304 } |
287 | 305 |
| 306 virtual void OnExternalProviderReady() { |
| 307 EXPECT_TRUE(provider_->IsReady()); |
| 308 } |
| 309 |
288 private: | 310 private: |
289 int ids_found_; | 311 int ids_found_; |
290 | 312 |
291 scoped_ptr<ExternalPrefExtensionProvider> provider_; | 313 scoped_ptr<ExternalExtensionProviderImpl> provider_; |
292 scoped_ptr<DictionaryValue> prefs_; | 314 scoped_ptr<DictionaryValue> prefs_; |
293 | 315 |
294 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 316 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
295 }; | 317 }; |
296 | 318 |
297 class ExtensionTestingProfile : public TestingProfile { | 319 class ExtensionTestingProfile : public TestingProfile { |
298 public: | 320 public: |
299 ExtensionTestingProfile() : service_(NULL) { | 321 ExtensionTestingProfile() : service_(NULL) { |
300 } | 322 } |
301 | 323 |
(...skipping 162 matching lines...) Loading... |
464 case NotificationType::EXTENSION_INSTALLED: | 486 case NotificationType::EXTENSION_INSTALLED: |
465 case NotificationType::THEME_INSTALLED: | 487 case NotificationType::THEME_INSTALLED: |
466 installed_ = Details<const Extension>(details).ptr(); | 488 installed_ = Details<const Extension>(details).ptr(); |
467 break; | 489 break; |
468 | 490 |
469 default: | 491 default: |
470 DCHECK(false); | 492 DCHECK(false); |
471 } | 493 } |
472 } | 494 } |
473 | 495 |
474 void AddMockExternalProvider(ExternalExtensionProvider* provider) { | 496 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) { |
475 service_->AddProviderForTesting(provider); | 497 service_->AddProviderForTesting(provider); |
476 } | 498 } |
477 | 499 |
478 protected: | 500 protected: |
479 void TestExternalProvider(MockExtensionProvider* provider, | 501 void TestExternalProvider(MockExtensionProvider* provider, |
480 Extension::Location location); | 502 Extension::Location location); |
481 | 503 |
482 void PackAndInstallExtension(const FilePath& dir_path, | 504 void PackAndInstallExtension(const FilePath& dir_path, |
483 const FilePath& pem_path, | 505 const FilePath& pem_path, |
484 bool should_succeed) { | 506 bool should_succeed) { |
(...skipping 579 matching lines...) Loading... |
1064 // Test the handling of killed extensions. | 1086 // Test the handling of killed extensions. |
1065 TEST_F(ExtensionServiceTest, KilledExtensions) { | 1087 TEST_F(ExtensionServiceTest, KilledExtensions) { |
1066 InitializeEmptyExtensionService(); | 1088 InitializeEmptyExtensionService(); |
1067 | 1089 |
1068 FilePath extensions_path; | 1090 FilePath extensions_path; |
1069 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1091 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
1070 extensions_path = extensions_path.AppendASCII("extensions"); | 1092 extensions_path = extensions_path.AppendASCII("extensions"); |
1071 FilePath path = extensions_path.AppendASCII("good.crx"); | 1093 FilePath path = extensions_path.AppendASCII("good.crx"); |
1072 set_extensions_enabled(true); | 1094 set_extensions_enabled(true); |
1073 | 1095 |
| 1096 scoped_ptr<Version> version; |
| 1097 version.reset(Version::GetVersionFromString("1.0.0.0")); |
1074 // Install an external extension. | 1098 // Install an external extension. |
1075 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", | 1099 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1076 path, Extension::EXTERNAL_PREF); | 1100 path, Extension::EXTERNAL_PREF); |
1077 loop_.RunAllPending(); | 1101 loop_.RunAllPending(); |
1078 ASSERT_TRUE(NULL != service_->GetExtensionById(good_crx, false)); | 1102 ASSERT_TRUE(NULL != service_->GetExtensionById(good_crx, false)); |
1079 | 1103 |
1080 // Uninstall it and check that its killbit gets set. | 1104 // Uninstall it and check that its killbit gets set. |
1081 service_->UninstallExtension(good_crx, false); | 1105 service_->UninstallExtension(good_crx, false); |
1082 loop_.RunAllPending(); | 1106 loop_.RunAllPending(); |
1083 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); | 1107 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); |
1084 | 1108 |
1085 // Try to re-install it externally. This should fail because of the killbit. | 1109 // Try to re-install it externally. This should fail because of the killbit. |
1086 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", | 1110 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1087 path, Extension::EXTERNAL_PREF); | 1111 path, Extension::EXTERNAL_PREF); |
1088 loop_.RunAllPending(); | 1112 loop_.RunAllPending(); |
1089 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1113 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
1090 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); | 1114 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); |
1091 | 1115 |
| 1116 version.reset(Version::GetVersionFromString("1.0.0.1")); |
1092 // Repeat the same thing with a newer version of the extension. | 1117 // Repeat the same thing with a newer version of the extension. |
1093 path = extensions_path.AppendASCII("good2.crx"); | 1118 path = extensions_path.AppendASCII("good2.crx"); |
1094 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.1", | 1119 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1095 path, Extension::EXTERNAL_PREF); | 1120 path, Extension::EXTERNAL_PREF); |
1096 loop_.RunAllPending(); | 1121 loop_.RunAllPending(); |
1097 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1122 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
1098 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); | 1123 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); |
1099 | 1124 |
1100 // Try adding the same extension from an external update URL. | 1125 // Try adding the same extension from an external update URL. |
1101 service_->AddPendingExtensionFromExternalUpdateUrl( | 1126 service_->AddPendingExtensionFromExternalUpdateUrl( |
1102 good_crx, | 1127 good_crx, |
1103 GURL("http:://fake.update/url"), | 1128 GURL("http:://fake.update/url"), |
1104 Extension::EXTERNAL_PREF_DOWNLOAD); | 1129 Extension::EXTERNAL_PREF_DOWNLOAD); |
(...skipping 1750 matching lines...) Loading... |
2855 ASSERT_EQ(1u, loaded_.size()); | 2880 ASSERT_EQ(1u, loaded_.size()); |
2856 ValidatePrefKeyCount(1); | 2881 ValidatePrefKeyCount(1); |
2857 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 2882 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
2858 ValidateIntegerPref(good_crx, "location", location); | 2883 ValidateIntegerPref(good_crx, "location", location); |
2859 | 2884 |
2860 // Now test an externally triggered uninstall (deleting the registry key or | 2885 // Now test an externally triggered uninstall (deleting the registry key or |
2861 // the pref entry). | 2886 // the pref entry). |
2862 provider->RemoveExtension(good_crx); | 2887 provider->RemoveExtension(good_crx); |
2863 | 2888 |
2864 loaded_.clear(); | 2889 loaded_.clear(); |
2865 service_->UnloadAllExtensions(); | 2890 service_->OnExternalProviderReady(); |
2866 service_->LoadAllExtensions(); | |
2867 loop_.RunAllPending(); | 2891 loop_.RunAllPending(); |
2868 ASSERT_EQ(0u, loaded_.size()); | 2892 ASSERT_EQ(0u, loaded_.size()); |
2869 ValidatePrefKeyCount(0); | 2893 ValidatePrefKeyCount(0); |
2870 | 2894 |
2871 // The extension should also be gone from the install directory. | 2895 // The extension should also be gone from the install directory. |
2872 ASSERT_FALSE(file_util::PathExists(install_path)); | 2896 ASSERT_FALSE(file_util::PathExists(install_path)); |
2873 | 2897 |
2874 // Now test the case where user uninstalls and then the extension is removed | 2898 // Now test the case where user uninstalls and then the extension is removed |
2875 // from the external provider. | 2899 // from the external provider. |
2876 | 2900 |
(...skipping 25 matching lines...) Loading... |
2902 | 2926 |
2903 // Tests the external installation feature | 2927 // Tests the external installation feature |
2904 #if defined(OS_WIN) | 2928 #if defined(OS_WIN) |
2905 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { | 2929 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
2906 // This should all work, even when normal extension installation is disabled. | 2930 // This should all work, even when normal extension installation is disabled. |
2907 InitializeEmptyExtensionService(); | 2931 InitializeEmptyExtensionService(); |
2908 set_extensions_enabled(false); | 2932 set_extensions_enabled(false); |
2909 | 2933 |
2910 // Now add providers. Extension system takes ownership of the objects. | 2934 // Now add providers. Extension system takes ownership of the objects. |
2911 MockExtensionProvider* reg_provider = | 2935 MockExtensionProvider* reg_provider = |
2912 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); | 2936 new MockExtensionProvider(service_.get(), Extension::EXTERNAL_REGISTRY); |
2913 AddMockExternalProvider(reg_provider); | 2937 AddMockExternalProvider(reg_provider); |
2914 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY); | 2938 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY); |
2915 } | 2939 } |
2916 #endif | 2940 #endif |
2917 | 2941 |
2918 TEST_F(ExtensionServiceTest, ExternalInstallPref) { | 2942 TEST_F(ExtensionServiceTest, ExternalInstallPref) { |
2919 InitializeEmptyExtensionService(); | 2943 InitializeEmptyExtensionService(); |
2920 | 2944 |
2921 // Now add providers. Extension system takes ownership of the objects. | 2945 // Now add providers. Extension system takes ownership of the objects. |
2922 MockExtensionProvider* pref_provider = | 2946 MockExtensionProvider* pref_provider = |
2923 new MockExtensionProvider(Extension::EXTERNAL_PREF); | 2947 new MockExtensionProvider(service_.get(), Extension::EXTERNAL_PREF); |
2924 | 2948 |
2925 AddMockExternalProvider(pref_provider); | 2949 AddMockExternalProvider(pref_provider); |
2926 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); | 2950 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); |
2927 } | 2951 } |
2928 | 2952 |
2929 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { | 2953 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
2930 // This should all work, even when normal extension installation is disabled. | 2954 // This should all work, even when normal extension installation is disabled. |
2931 InitializeEmptyExtensionService(); | 2955 InitializeEmptyExtensionService(); |
2932 set_extensions_enabled(false); | 2956 set_extensions_enabled(false); |
2933 | 2957 |
2934 // TODO(skerner): The mock provider is not a good model of a provider | 2958 // TODO(skerner): The mock provider is not a good model of a provider |
2935 // that works with update URLs, because it adds file and version info. | 2959 // that works with update URLs, because it adds file and version info. |
2936 // Extend the mock to work with update URLs. This test checks the | 2960 // Extend the mock to work with update URLs. This test checks the |
2937 // behavior that is common to all external extension visitors. The | 2961 // behavior that is common to all external extension visitors. The |
2938 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that | 2962 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
2939 // what the visitor does results in an extension being downloaded and | 2963 // what the visitor does results in an extension being downloaded and |
2940 // installed. | 2964 // installed. |
2941 MockExtensionProvider* pref_provider = | 2965 MockExtensionProvider* pref_provider = |
2942 new MockExtensionProvider(Extension::EXTERNAL_PREF_DOWNLOAD); | 2966 new MockExtensionProvider(service_.get(), |
| 2967 Extension::EXTERNAL_PREF_DOWNLOAD); |
2943 AddMockExternalProvider(pref_provider); | 2968 AddMockExternalProvider(pref_provider); |
2944 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD); | 2969 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD); |
2945 } | 2970 } |
2946 | 2971 |
2947 // Tests that external extensions get uninstalled when the external extension | 2972 // Tests that external extensions get uninstalled when the external extension |
2948 // providers can't account for them. | 2973 // providers can't account for them. |
2949 TEST_F(ExtensionServiceTest, ExternalUninstall) { | 2974 TEST_F(ExtensionServiceTest, ExternalUninstall) { |
2950 // Start the extensions service with one external extension already installed. | 2975 // Start the extensions service with one external extension already installed. |
2951 FilePath source_install_dir; | 2976 FilePath source_install_dir; |
2952 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); | 2977 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); |
(...skipping 159 matching lines...) Loading... |
3112 BrowserThread ui_thread(BrowserThread::UI, &loop); | 3137 BrowserThread ui_thread(BrowserThread::UI, &loop); |
3113 BrowserThread file_thread(BrowserThread::FILE, &loop); | 3138 BrowserThread file_thread(BrowserThread::FILE, &loop); |
3114 scoped_ptr<CommandLine> command_line; | 3139 scoped_ptr<CommandLine> command_line; |
3115 scoped_refptr<ExtensionService> service; | 3140 scoped_refptr<ExtensionService> service; |
3116 FilePath install_dir = profile->GetPath() | 3141 FilePath install_dir = profile->GetPath() |
3117 .AppendASCII(ExtensionService::kInstallDirectoryName); | 3142 .AppendASCII(ExtensionService::kInstallDirectoryName); |
3118 | 3143 |
3119 // By default, we are enabled. | 3144 // By default, we are enabled. |
3120 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 3145 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
3121 service = profile->CreateExtensionService(command_line.get(), | 3146 service = profile->CreateExtensionService(command_line.get(), |
3122 install_dir); | 3147 install_dir); |
3123 EXPECT_TRUE(service->extensions_enabled()); | 3148 EXPECT_TRUE(service->extensions_enabled()); |
3124 service->Init(); | 3149 service->Init(); |
3125 loop.RunAllPending(); | 3150 loop.RunAllPending(); |
3126 EXPECT_TRUE(recorder.ready()); | 3151 EXPECT_TRUE(recorder.ready()); |
3127 | 3152 |
3128 // If either the command line or pref is set, we are disabled. | 3153 // If either the command line or pref is set, we are disabled. |
3129 recorder.set_ready(false); | 3154 recorder.set_ready(false); |
3130 profile.reset(new TestingProfile()); | 3155 profile.reset(new TestingProfile()); |
3131 command_line->AppendSwitch(switches::kDisableExtensions); | 3156 command_line->AppendSwitch(switches::kDisableExtensions); |
3132 service = profile->CreateExtensionService(command_line.get(), | 3157 service = profile->CreateExtensionService(command_line.get(), |
3133 install_dir); | 3158 install_dir); |
3134 EXPECT_FALSE(service->extensions_enabled()); | 3159 EXPECT_FALSE(service->extensions_enabled()); |
3135 service->Init(); | 3160 service->Init(); |
3136 loop.RunAllPending(); | 3161 loop.RunAllPending(); |
3137 EXPECT_TRUE(recorder.ready()); | 3162 EXPECT_TRUE(recorder.ready()); |
3138 | 3163 |
3139 recorder.set_ready(false); | 3164 recorder.set_ready(false); |
3140 profile.reset(new TestingProfile()); | 3165 profile.reset(new TestingProfile()); |
3141 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 3166 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
3142 service = profile->CreateExtensionService(command_line.get(), | 3167 service = profile->CreateExtensionService(command_line.get(), |
3143 install_dir); | 3168 install_dir); |
3144 EXPECT_FALSE(service->extensions_enabled()); | 3169 EXPECT_FALSE(service->extensions_enabled()); |
3145 service->Init(); | 3170 service->Init(); |
3146 loop.RunAllPending(); | 3171 loop.RunAllPending(); |
3147 EXPECT_TRUE(recorder.ready()); | 3172 EXPECT_TRUE(recorder.ready()); |
3148 | 3173 |
3149 recorder.set_ready(false); | 3174 recorder.set_ready(false); |
3150 profile.reset(new TestingProfile()); | 3175 profile.reset(new TestingProfile()); |
3151 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 3176 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
3152 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 3177 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
3153 service = profile->CreateExtensionService(command_line.get(), | 3178 service = profile->CreateExtensionService(command_line.get(), |
(...skipping 102 matching lines...) Loading... |
3256 // Component extensions shouldn't get recourded in the prefs. | 3281 // Component extensions shouldn't get recourded in the prefs. |
3257 ValidatePrefKeyCount(0); | 3282 ValidatePrefKeyCount(0); |
3258 | 3283 |
3259 // Reload all extensions, and make sure it comes back. | 3284 // Reload all extensions, and make sure it comes back. |
3260 std::string extension_id = service_->extensions()->at(0)->id(); | 3285 std::string extension_id = service_->extensions()->at(0)->id(); |
3261 loaded_.clear(); | 3286 loaded_.clear(); |
3262 service_->ReloadExtensions(); | 3287 service_->ReloadExtensions(); |
3263 ASSERT_EQ(1u, service_->extensions()->size()); | 3288 ASSERT_EQ(1u, service_->extensions()->size()); |
3264 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3289 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
3265 } | 3290 } |
OLD | NEW |