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

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix breakage Created 9 years, 11 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) 2010 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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/scoped_ptr.h" 17 #include "base/scoped_ptr.h"
18 #include "base/stl_util-inl.h" 18 #include "base/stl_util-inl.h"
19 #include "base/string16.h" 19 #include "base/string16.h"
20 #include "base/string_number_conversions.h" 20 #include "base/string_number_conversions.h"
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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 case NotificationType::EXTENSION_INSTALLED: 485 case NotificationType::EXTENSION_INSTALLED:
464 case NotificationType::THEME_INSTALLED: 486 case NotificationType::THEME_INSTALLED:
465 installed_ = Details<const Extension>(details).ptr(); 487 installed_ = Details<const Extension>(details).ptr();
466 break; 488 break;
467 489
468 default: 490 default:
469 DCHECK(false); 491 DCHECK(false);
470 } 492 }
471 } 493 }
472 494
473 void AddMockExternalProvider(ExternalExtensionProvider* provider) { 495 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) {
474 service_->AddProviderForTesting(provider); 496 service_->AddProviderForTesting(provider);
475 } 497 }
476 498
477 protected: 499 protected:
478 void TestExternalProvider(MockExtensionProvider* provider, 500 void TestExternalProvider(MockExtensionProvider* provider,
479 Extension::Location location); 501 Extension::Location location);
480 502
481 void PackAndInstallExtension(const FilePath& dir_path, 503 void PackAndInstallExtension(const FilePath& dir_path,
482 const FilePath& pem_path, 504 const FilePath& pem_path,
483 bool should_succeed) { 505 bool should_succeed) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 // Test the handling of killed extensions. 1085 // Test the handling of killed extensions.
1064 TEST_F(ExtensionServiceTest, KilledExtensions) { 1086 TEST_F(ExtensionServiceTest, KilledExtensions) {
1065 InitializeEmptyExtensionService(); 1087 InitializeEmptyExtensionService();
1066 1088
1067 FilePath extensions_path; 1089 FilePath extensions_path;
1068 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1090 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1069 extensions_path = extensions_path.AppendASCII("extensions"); 1091 extensions_path = extensions_path.AppendASCII("extensions");
1070 FilePath path = extensions_path.AppendASCII("good.crx"); 1092 FilePath path = extensions_path.AppendASCII("good.crx");
1071 set_extensions_enabled(true); 1093 set_extensions_enabled(true);
1072 1094
1095 scoped_ptr<Version> version;
1096 version.reset(Version::GetVersionFromString("1.0.0.0"));
1073 // Install an external extension. 1097 // Install an external extension.
1074 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", 1098 service_->OnExternalExtensionFileFound(good_crx, version.get(),
1075 path, Extension::EXTERNAL_PREF); 1099 path, Extension::EXTERNAL_PREF);
1076 loop_.RunAllPending(); 1100 loop_.RunAllPending();
1077 ASSERT_TRUE(NULL != service_->GetExtensionById(good_crx, false)); 1101 ASSERT_TRUE(NULL != service_->GetExtensionById(good_crx, false));
1078 1102
1079 // Uninstall it and check that its killbit gets set. 1103 // Uninstall it and check that its killbit gets set.
1080 service_->UninstallExtension(good_crx, false); 1104 service_->UninstallExtension(good_crx, false);
1081 loop_.RunAllPending(); 1105 loop_.RunAllPending();
1082 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); 1106 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT);
1083 1107
1084 // Try to re-install it externally. This should fail because of the killbit. 1108 // Try to re-install it externally. This should fail because of the killbit.
1085 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", 1109 service_->OnExternalExtensionFileFound(good_crx, version.get(),
1086 path, Extension::EXTERNAL_PREF); 1110 path, Extension::EXTERNAL_PREF);
1087 loop_.RunAllPending(); 1111 loop_.RunAllPending();
1088 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1112 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1089 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); 1113 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT);
1090 1114
1115 version.reset(Version::GetVersionFromString("1.0.0.1"));
1091 // Repeat the same thing with a newer version of the extension. 1116 // Repeat the same thing with a newer version of the extension.
1092 path = extensions_path.AppendASCII("good2.crx"); 1117 path = extensions_path.AppendASCII("good2.crx");
1093 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.1", 1118 service_->OnExternalExtensionFileFound(good_crx, version.get(),
1094 path, Extension::EXTERNAL_PREF); 1119 path, Extension::EXTERNAL_PREF);
1095 loop_.RunAllPending(); 1120 loop_.RunAllPending();
1096 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1121 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1097 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); 1122 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT);
1098 1123
1099 // Try adding the same extension from an external update URL. 1124 // Try adding the same extension from an external update URL.
1100 service_->AddPendingExtensionFromExternalUpdateUrl( 1125 service_->AddPendingExtensionFromExternalUpdateUrl(
1101 good_crx, 1126 good_crx,
1102 GURL("http:://fake.update/url"), 1127 GURL("http:://fake.update/url"),
1103 Extension::EXTERNAL_PREF_DOWNLOAD); 1128 Extension::EXTERNAL_PREF_DOWNLOAD);
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2854 ASSERT_EQ(1u, loaded_.size()); 2879 ASSERT_EQ(1u, loaded_.size());
2855 ValidatePrefKeyCount(1); 2880 ValidatePrefKeyCount(1);
2856 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2881 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2857 ValidateIntegerPref(good_crx, "location", location); 2882 ValidateIntegerPref(good_crx, "location", location);
2858 2883
2859 // Now test an externally triggered uninstall (deleting the registry key or 2884 // Now test an externally triggered uninstall (deleting the registry key or
2860 // the pref entry). 2885 // the pref entry).
2861 provider->RemoveExtension(good_crx); 2886 provider->RemoveExtension(good_crx);
2862 2887
2863 loaded_.clear(); 2888 loaded_.clear();
2864 service_->UnloadAllExtensions(); 2889 service_->OnExternalProviderReady();
2865 service_->LoadAllExtensions();
2866 loop_.RunAllPending(); 2890 loop_.RunAllPending();
2867 ASSERT_EQ(0u, loaded_.size()); 2891 ASSERT_EQ(0u, loaded_.size());
2868 ValidatePrefKeyCount(0); 2892 ValidatePrefKeyCount(0);
2869 2893
2870 // The extension should also be gone from the install directory. 2894 // The extension should also be gone from the install directory.
2871 ASSERT_FALSE(file_util::PathExists(install_path)); 2895 ASSERT_FALSE(file_util::PathExists(install_path));
2872 2896
2873 // Now test the case where user uninstalls and then the extension is removed 2897 // Now test the case where user uninstalls and then the extension is removed
2874 // from the external provider. 2898 // from the external provider.
2875 2899
(...skipping 25 matching lines...) Expand all
2901 2925
2902 // Tests the external installation feature 2926 // Tests the external installation feature
2903 #if defined(OS_WIN) 2927 #if defined(OS_WIN)
2904 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 2928 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
2905 // This should all work, even when normal extension installation is disabled. 2929 // This should all work, even when normal extension installation is disabled.
2906 InitializeEmptyExtensionService(); 2930 InitializeEmptyExtensionService();
2907 set_extensions_enabled(false); 2931 set_extensions_enabled(false);
2908 2932
2909 // Now add providers. Extension system takes ownership of the objects. 2933 // Now add providers. Extension system takes ownership of the objects.
2910 MockExtensionProvider* reg_provider = 2934 MockExtensionProvider* reg_provider =
2911 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); 2935 new MockExtensionProvider(service_.get(), Extension::EXTERNAL_REGISTRY);
2912 AddMockExternalProvider(reg_provider); 2936 AddMockExternalProvider(reg_provider);
2913 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY); 2937 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY);
2914 } 2938 }
2915 #endif 2939 #endif
2916 2940
2917 TEST_F(ExtensionServiceTest, ExternalInstallPref) { 2941 TEST_F(ExtensionServiceTest, ExternalInstallPref) {
2918 InitializeEmptyExtensionService(); 2942 InitializeEmptyExtensionService();
2919 2943
2920 // Now add providers. Extension system takes ownership of the objects. 2944 // Now add providers. Extension system takes ownership of the objects.
2921 MockExtensionProvider* pref_provider = 2945 MockExtensionProvider* pref_provider =
2922 new MockExtensionProvider(Extension::EXTERNAL_PREF); 2946 new MockExtensionProvider(service_.get(), Extension::EXTERNAL_PREF);
2923 2947
2924 AddMockExternalProvider(pref_provider); 2948 AddMockExternalProvider(pref_provider);
2925 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); 2949 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF);
2926 } 2950 }
2927 2951
2928 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { 2952 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) {
2929 // This should all work, even when normal extension installation is disabled. 2953 // This should all work, even when normal extension installation is disabled.
2930 InitializeEmptyExtensionService(); 2954 InitializeEmptyExtensionService();
2931 set_extensions_enabled(false); 2955 set_extensions_enabled(false);
2932 2956
2933 // TODO(skerner): The mock provider is not a good model of a provider 2957 // TODO(skerner): The mock provider is not a good model of a provider
2934 // that works with update URLs, because it adds file and version info. 2958 // that works with update URLs, because it adds file and version info.
2935 // Extend the mock to work with update URLs. This test checks the 2959 // Extend the mock to work with update URLs. This test checks the
2936 // behavior that is common to all external extension visitors. The 2960 // behavior that is common to all external extension visitors. The
2937 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 2961 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
2938 // what the visitor does results in an extension being downloaded and 2962 // what the visitor does results in an extension being downloaded and
2939 // installed. 2963 // installed.
2940 MockExtensionProvider* pref_provider = 2964 MockExtensionProvider* pref_provider =
2941 new MockExtensionProvider(Extension::EXTERNAL_PREF_DOWNLOAD); 2965 new MockExtensionProvider(service_.get(),
2966 Extension::EXTERNAL_PREF_DOWNLOAD);
2942 AddMockExternalProvider(pref_provider); 2967 AddMockExternalProvider(pref_provider);
2943 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD); 2968 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD);
2944 } 2969 }
2945 2970
2946 // Tests that external extensions get uninstalled when the external extension 2971 // Tests that external extensions get uninstalled when the external extension
2947 // providers can't account for them. 2972 // providers can't account for them.
2948 TEST_F(ExtensionServiceTest, ExternalUninstall) { 2973 TEST_F(ExtensionServiceTest, ExternalUninstall) {
2949 // Start the extensions service with one external extension already installed. 2974 // Start the extensions service with one external extension already installed.
2950 FilePath source_install_dir; 2975 FilePath source_install_dir;
2951 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 2976 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
3111 BrowserThread ui_thread(BrowserThread::UI, &loop); 3136 BrowserThread ui_thread(BrowserThread::UI, &loop);
3112 BrowserThread file_thread(BrowserThread::FILE, &loop); 3137 BrowserThread file_thread(BrowserThread::FILE, &loop);
3113 scoped_ptr<CommandLine> command_line; 3138 scoped_ptr<CommandLine> command_line;
3114 scoped_refptr<ExtensionService> service; 3139 scoped_refptr<ExtensionService> service;
3115 FilePath install_dir = profile->GetPath() 3140 FilePath install_dir = profile->GetPath()
3116 .AppendASCII(ExtensionService::kInstallDirectoryName); 3141 .AppendASCII(ExtensionService::kInstallDirectoryName);
3117 3142
3118 // By default, we are enabled. 3143 // By default, we are enabled.
3119 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3144 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3120 service = profile->CreateExtensionService(command_line.get(), 3145 service = profile->CreateExtensionService(command_line.get(),
3121 install_dir); 3146 install_dir);
3122 EXPECT_TRUE(service->extensions_enabled()); 3147 EXPECT_TRUE(service->extensions_enabled());
3123 service->Init(); 3148 service->Init();
3124 loop.RunAllPending(); 3149 loop.RunAllPending();
3125 EXPECT_TRUE(recorder.ready()); 3150 EXPECT_TRUE(recorder.ready());
3126 3151
3127 // If either the command line or pref is set, we are disabled. 3152 // If either the command line or pref is set, we are disabled.
3128 recorder.set_ready(false); 3153 recorder.set_ready(false);
3129 profile.reset(new TestingProfile()); 3154 profile.reset(new TestingProfile());
3130 command_line->AppendSwitch(switches::kDisableExtensions); 3155 command_line->AppendSwitch(switches::kDisableExtensions);
3131 service = profile->CreateExtensionService(command_line.get(), 3156 service = profile->CreateExtensionService(command_line.get(),
3132 install_dir); 3157 install_dir);
3133 EXPECT_FALSE(service->extensions_enabled()); 3158 EXPECT_FALSE(service->extensions_enabled());
3134 service->Init(); 3159 service->Init();
3135 loop.RunAllPending(); 3160 loop.RunAllPending();
3136 EXPECT_TRUE(recorder.ready()); 3161 EXPECT_TRUE(recorder.ready());
3137 3162
3138 recorder.set_ready(false); 3163 recorder.set_ready(false);
3139 profile.reset(new TestingProfile()); 3164 profile.reset(new TestingProfile());
3140 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3165 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3141 service = profile->CreateExtensionService(command_line.get(), 3166 service = profile->CreateExtensionService(command_line.get(),
3142 install_dir); 3167 install_dir);
3143 EXPECT_FALSE(service->extensions_enabled()); 3168 EXPECT_FALSE(service->extensions_enabled());
3144 service->Init(); 3169 service->Init();
3145 loop.RunAllPending(); 3170 loop.RunAllPending();
3146 EXPECT_TRUE(recorder.ready()); 3171 EXPECT_TRUE(recorder.ready());
3147 3172
3148 recorder.set_ready(false); 3173 recorder.set_ready(false);
3149 profile.reset(new TestingProfile()); 3174 profile.reset(new TestingProfile());
3150 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3175 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3151 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3176 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3152 service = profile->CreateExtensionService(command_line.get(), 3177 service = profile->CreateExtensionService(command_line.get(),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 // Component extensions shouldn't get recourded in the prefs. 3280 // Component extensions shouldn't get recourded in the prefs.
3256 ValidatePrefKeyCount(0); 3281 ValidatePrefKeyCount(0);
3257 3282
3258 // Reload all extensions, and make sure it comes back. 3283 // Reload all extensions, and make sure it comes back.
3259 std::string extension_id = service_->extensions()->at(0)->id(); 3284 std::string extension_id = service_->extensions()->at(0)->id();
3260 loaded_.clear(); 3285 loaded_.clear();
3261 service_->ReloadExtensions(); 3286 service_->ReloadExtensions();
3262 ASSERT_EQ(1u, service_->extensions()->size()); 3287 ASSERT_EQ(1u, service_->extensions()->size());
3263 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); 3288 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id());
3264 } 3289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698