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

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: " 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) 2010 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 11 matching lines...) Expand all
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.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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ExternalExtensionProvider {
129 public: 130 public:
130 explicit MockExtensionProvider(Extension::Location location) 131 explicit MockExtensionProvider(
131 : location_(location), visit_count_(0) {} 132 Visitor* 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 Visitor* 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 : public ExternalExtensionProvider::Visitor {
196 public: 210 public:
197 MockProviderVisitor() : ids_found_(0) { 211 MockProviderVisitor() : ids_found_(0) {
198 } 212 }
199 213
200 int Visit(const std::string& json_data) { 214 int Visit(const std::string& json_data) {
201 // Give the test json file to the provider for parsing. 215 // Give the test json file to the provider for parsing.
202 provider_.reset(new ExternalPrefExtensionProvider()); 216 provider_.reset(new ExternalExtensionProviderImpl(
203 provider_->SetPreferencesForTesting(json_data); 217 this,
218 new ExternalTestingExtensionLoader(json_data),
219 Extension::EXTERNAL_PREF,
220 Extension::EXTERNAL_PREF_DOWNLOAD));
204 221
205 // We also parse the file into a dictionary to compare what we get back 222 // We also parse the file into a dictionary to compare what we get back
206 // from the provider. 223 // from the provider.
207 JSONStringValueSerializer serializer(json_data); 224 JSONStringValueSerializer serializer(json_data);
208 Value* json_value = serializer.Deserialize(NULL, NULL); 225 Value* json_value = serializer.Deserialize(NULL, NULL);
209 226
210 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { 227 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) {
211 NOTREACHED() << "Unable to deserialize json data"; 228 NOTREACHED() << "Unable to deserialize json data";
212 return -1; 229 return -1;
213 } else { 230 } else {
214 DictionaryValue* external_extensions = 231 DictionaryValue* external_extensions =
215 static_cast<DictionaryValue*>(json_value); 232 static_cast<DictionaryValue*>(json_value);
216 prefs_.reset(external_extensions); 233 prefs_.reset(external_extensions);
217 } 234 }
218 235
219 // Reset our counter. 236 // Reset our counter.
220 ids_found_ = 0; 237 ids_found_ = 0;
221 // Ask the provider to look up all extensions and return them. 238 // Ask the provider to look up all extensions and return them.
222 provider_->VisitRegisteredExtension(this); 239 provider_->VisitRegisteredExtension();
223 240
224 return ids_found_; 241 return ids_found_;
225 } 242 }
226 243
227 virtual void OnExternalExtensionFileFound(const std::string& id, 244 virtual void OnExternalExtensionFileFound(const std::string& id,
228 const Version* version, 245 const Version* version,
229 const FilePath& path, 246 const FilePath& path,
230 Extension::Location unused) { 247 Extension::Location unused) {
231 ++ids_found_; 248 ++ids_found_;
232 DictionaryValue* pref; 249 DictionaryValue* pref;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 Extension::Location location1 = Extension::INVALID; 295 Extension::Location location1 = Extension::INVALID;
279 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); 296 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1));
280 EXPECT_FALSE(v1.get()); 297 EXPECT_FALSE(v1.get());
281 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1); 298 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1);
282 299
283 // Remove it so we won't count it again. 300 // Remove it so we won't count it again.
284 prefs_->Remove(id, NULL); 301 prefs_->Remove(id, NULL);
285 } 302 }
286 } 303 }
287 304
305 virtual void OnExternalProviderReady() {
306 EXPECT_TRUE(provider_->IsReady());
307 }
308
288 private: 309 private:
289 int ids_found_; 310 int ids_found_;
290 311
291 scoped_ptr<ExternalPrefExtensionProvider> provider_; 312 scoped_ptr<ExternalExtensionProviderImpl> provider_;
292 scoped_ptr<DictionaryValue> prefs_; 313 scoped_ptr<DictionaryValue> prefs_;
293 314
294 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 315 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
295 }; 316 };
296 317
297 class ExtensionTestingProfile : public TestingProfile { 318 class ExtensionTestingProfile : public TestingProfile {
298 public: 319 public:
299 ExtensionTestingProfile() : service_(NULL) { 320 ExtensionTestingProfile() : service_(NULL) {
300 } 321 }
301 322
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 // Test the handling of killed extensions. 1084 // Test the handling of killed extensions.
1064 TEST_F(ExtensionServiceTest, KilledExtensions) { 1085 TEST_F(ExtensionServiceTest, KilledExtensions) {
1065 InitializeEmptyExtensionService(); 1086 InitializeEmptyExtensionService();
1066 1087
1067 FilePath extensions_path; 1088 FilePath extensions_path;
1068 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1089 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1069 extensions_path = extensions_path.AppendASCII("extensions"); 1090 extensions_path = extensions_path.AppendASCII("extensions");
1070 FilePath path = extensions_path.AppendASCII("good.crx"); 1091 FilePath path = extensions_path.AppendASCII("good.crx");
1071 set_extensions_enabled(true); 1092 set_extensions_enabled(true);
1072 1093
1094 scoped_ptr<Version> version;
1095 version.reset(Version::GetVersionFromString("1.0.0.0"));
1073 // Install an external extension. 1096 // Install an external extension.
1074 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", 1097 service_->OnExternalExtensionFileFound(good_crx, version.get(),
1075 path, Extension::EXTERNAL_PREF); 1098 path, Extension::EXTERNAL_PREF);
1076 loop_.RunAllPending(); 1099 loop_.RunAllPending();
1077 ASSERT_TRUE(NULL != service_->GetExtensionById(good_crx, false)); 1100 ASSERT_TRUE(NULL != service_->GetExtensionById(good_crx, false));
1078 1101
1079 // Uninstall it and check that its killbit gets set. 1102 // Uninstall it and check that its killbit gets set.
1080 service_->UninstallExtension(good_crx, false); 1103 service_->UninstallExtension(good_crx, false);
1081 loop_.RunAllPending(); 1104 loop_.RunAllPending();
1082 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); 1105 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT);
1083 1106
1084 // Try to re-install it externally. This should fail because of the killbit. 1107 // Try to re-install it externally. This should fail because of the killbit.
1085 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.0", 1108 service_->OnExternalExtensionFileFound(good_crx, version.get(),
1086 path, Extension::EXTERNAL_PREF); 1109 path, Extension::EXTERNAL_PREF);
1087 loop_.RunAllPending(); 1110 loop_.RunAllPending();
1088 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1111 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1089 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); 1112 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT);
1090 1113
1114 version.reset(Version::GetVersionFromString("1.0.0.1"));
1091 // Repeat the same thing with a newer version of the extension. 1115 // Repeat the same thing with a newer version of the extension.
1092 path = extensions_path.AppendASCII("good2.crx"); 1116 path = extensions_path.AppendASCII("good2.crx");
1093 service_->OnExternalExtensionFileFound(good_crx, "1.0.0.1", 1117 service_->OnExternalExtensionFileFound(good_crx, version.get(),
1094 path, Extension::EXTERNAL_PREF); 1118 path, Extension::EXTERNAL_PREF);
1095 loop_.RunAllPending(); 1119 loop_.RunAllPending();
1096 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1120 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1097 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT); 1121 ValidateIntegerPref(good_crx, "location", Extension::KILLBIT);
1098 1122
1099 // Try adding the same extension from an external update URL. 1123 // Try adding the same extension from an external update URL.
1100 service_->AddPendingExtensionFromExternalUpdateUrl( 1124 service_->AddPendingExtensionFromExternalUpdateUrl(
1101 good_crx, 1125 good_crx,
1102 GURL("http:://fake.update/url"), 1126 GURL("http:://fake.update/url"),
1103 Extension::EXTERNAL_PREF_DOWNLOAD); 1127 Extension::EXTERNAL_PREF_DOWNLOAD);
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2854 ASSERT_EQ(1u, loaded_.size()); 2878 ASSERT_EQ(1u, loaded_.size());
2855 ValidatePrefKeyCount(1); 2879 ValidatePrefKeyCount(1);
2856 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2880 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2857 ValidateIntegerPref(good_crx, "location", location); 2881 ValidateIntegerPref(good_crx, "location", location);
2858 2882
2859 // Now test an externally triggered uninstall (deleting the registry key or 2883 // Now test an externally triggered uninstall (deleting the registry key or
2860 // the pref entry). 2884 // the pref entry).
2861 provider->RemoveExtension(good_crx); 2885 provider->RemoveExtension(good_crx);
2862 2886
2863 loaded_.clear(); 2887 loaded_.clear();
2864 service_->UnloadAllExtensions(); 2888 service_->OnExternalProviderReady();
2865 service_->LoadAllExtensions();
2866 loop_.RunAllPending(); 2889 loop_.RunAllPending();
2867 ASSERT_EQ(0u, loaded_.size()); 2890 ASSERT_EQ(0u, loaded_.size());
2868 ValidatePrefKeyCount(0); 2891 ValidatePrefKeyCount(0);
2869 2892
2870 // The extension should also be gone from the install directory. 2893 // The extension should also be gone from the install directory.
2871 ASSERT_FALSE(file_util::PathExists(install_path)); 2894 ASSERT_FALSE(file_util::PathExists(install_path));
2872 2895
2873 // Now test the case where user uninstalls and then the extension is removed 2896 // Now test the case where user uninstalls and then the extension is removed
2874 // from the external provider. 2897 // from the external provider.
2875 2898
(...skipping 25 matching lines...) Expand all
2901 2924
2902 // Tests the external installation feature 2925 // Tests the external installation feature
2903 #if defined(OS_WIN) 2926 #if defined(OS_WIN)
2904 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 2927 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
2905 // This should all work, even when normal extension installation is disabled. 2928 // This should all work, even when normal extension installation is disabled.
2906 InitializeEmptyExtensionService(); 2929 InitializeEmptyExtensionService();
2907 set_extensions_enabled(false); 2930 set_extensions_enabled(false);
2908 2931
2909 // Now add providers. Extension system takes ownership of the objects. 2932 // Now add providers. Extension system takes ownership of the objects.
2910 MockExtensionProvider* reg_provider = 2933 MockExtensionProvider* reg_provider =
2911 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); 2934 new MockExtensionProvider(service_.get(), Extension::EXTERNAL_REGISTRY);
2912 AddMockExternalProvider(reg_provider); 2935 AddMockExternalProvider(reg_provider);
2913 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY); 2936 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY);
2914 } 2937 }
2915 #endif 2938 #endif
2916 2939
2917 TEST_F(ExtensionServiceTest, ExternalInstallPref) { 2940 TEST_F(ExtensionServiceTest, ExternalInstallPref) {
2918 InitializeEmptyExtensionService(); 2941 InitializeEmptyExtensionService();
2919 2942
2920 // Now add providers. Extension system takes ownership of the objects. 2943 // Now add providers. Extension system takes ownership of the objects.
2921 MockExtensionProvider* pref_provider = 2944 MockExtensionProvider* pref_provider =
2922 new MockExtensionProvider(Extension::EXTERNAL_PREF); 2945 new MockExtensionProvider(service_.get(), Extension::EXTERNAL_PREF);
2923 2946
2924 AddMockExternalProvider(pref_provider); 2947 AddMockExternalProvider(pref_provider);
2925 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); 2948 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF);
2926 } 2949 }
2927 2950
2928 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { 2951 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) {
2929 // This should all work, even when normal extension installation is disabled. 2952 // This should all work, even when normal extension installation is disabled.
2930 InitializeEmptyExtensionService(); 2953 InitializeEmptyExtensionService();
2931 set_extensions_enabled(false); 2954 set_extensions_enabled(false);
2932 2955
2933 // TODO(skerner): The mock provider is not a good model of a provider 2956 // 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. 2957 // 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 2958 // Extend the mock to work with update URLs. This test checks the
2936 // behavior that is common to all external extension visitors. The 2959 // behavior that is common to all external extension visitors. The
2937 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that 2960 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
2938 // what the visitor does results in an extension being downloaded and 2961 // what the visitor does results in an extension being downloaded and
2939 // installed. 2962 // installed.
2940 MockExtensionProvider* pref_provider = 2963 MockExtensionProvider* pref_provider =
2941 new MockExtensionProvider(Extension::EXTERNAL_PREF_DOWNLOAD); 2964 new MockExtensionProvider(service_.get(),
2965 Extension::EXTERNAL_PREF_DOWNLOAD);
2942 AddMockExternalProvider(pref_provider); 2966 AddMockExternalProvider(pref_provider);
2943 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD); 2967 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD);
2944 } 2968 }
2945 2969
2946 // Tests that external extensions get uninstalled when the external extension 2970 // Tests that external extensions get uninstalled when the external extension
2947 // providers can't account for them. 2971 // providers can't account for them.
2948 TEST_F(ExtensionServiceTest, ExternalUninstall) { 2972 TEST_F(ExtensionServiceTest, ExternalUninstall) {
2949 // Start the extensions service with one external extension already installed. 2973 // Start the extensions service with one external extension already installed.
2950 FilePath source_install_dir; 2974 FilePath source_install_dir;
2951 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); 2975 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); 3135 BrowserThread ui_thread(BrowserThread::UI, &loop);
3112 BrowserThread file_thread(BrowserThread::FILE, &loop); 3136 BrowserThread file_thread(BrowserThread::FILE, &loop);
3113 scoped_ptr<CommandLine> command_line; 3137 scoped_ptr<CommandLine> command_line;
3114 scoped_refptr<ExtensionService> service; 3138 scoped_refptr<ExtensionService> service;
3115 FilePath install_dir = profile->GetPath() 3139 FilePath install_dir = profile->GetPath()
3116 .AppendASCII(ExtensionService::kInstallDirectoryName); 3140 .AppendASCII(ExtensionService::kInstallDirectoryName);
3117 3141
3118 // By default, we are enabled. 3142 // By default, we are enabled.
3119 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3143 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3120 service = profile->CreateExtensionService(command_line.get(), 3144 service = profile->CreateExtensionService(command_line.get(),
3121 install_dir); 3145 install_dir);
3122 EXPECT_TRUE(service->extensions_enabled()); 3146 EXPECT_TRUE(service->extensions_enabled());
3123 service->Init(); 3147 service->Init();
3124 loop.RunAllPending(); 3148 loop.RunAllPending();
3125 EXPECT_TRUE(recorder.ready()); 3149 EXPECT_TRUE(recorder.ready());
3126 3150
3127 // If either the command line or pref is set, we are disabled. 3151 // If either the command line or pref is set, we are disabled.
3128 recorder.set_ready(false); 3152 recorder.set_ready(false);
3129 profile.reset(new TestingProfile()); 3153 profile.reset(new TestingProfile());
3130 command_line->AppendSwitch(switches::kDisableExtensions); 3154 command_line->AppendSwitch(switches::kDisableExtensions);
3131 service = profile->CreateExtensionService(command_line.get(), 3155 service = profile->CreateExtensionService(command_line.get(),
3132 install_dir); 3156 install_dir);
3133 EXPECT_FALSE(service->extensions_enabled()); 3157 EXPECT_FALSE(service->extensions_enabled());
3134 service->Init(); 3158 service->Init();
3135 loop.RunAllPending(); 3159 loop.RunAllPending();
3136 EXPECT_TRUE(recorder.ready()); 3160 EXPECT_TRUE(recorder.ready());
3137 3161
3138 recorder.set_ready(false); 3162 recorder.set_ready(false);
3139 profile.reset(new TestingProfile()); 3163 profile.reset(new TestingProfile());
3140 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3164 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3141 service = profile->CreateExtensionService(command_line.get(), 3165 service = profile->CreateExtensionService(command_line.get(),
3142 install_dir); 3166 install_dir);
3143 EXPECT_FALSE(service->extensions_enabled()); 3167 EXPECT_FALSE(service->extensions_enabled());
3144 service->Init(); 3168 service->Init();
3145 loop.RunAllPending(); 3169 loop.RunAllPending();
3146 EXPECT_TRUE(recorder.ready()); 3170 EXPECT_TRUE(recorder.ready());
3147 3171
3148 recorder.set_ready(false); 3172 recorder.set_ready(false);
3149 profile.reset(new TestingProfile()); 3173 profile.reset(new TestingProfile());
3150 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3174 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3151 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3175 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3152 service = profile->CreateExtensionService(command_line.get(), 3176 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. 3279 // Component extensions shouldn't get recourded in the prefs.
3256 ValidatePrefKeyCount(0); 3280 ValidatePrefKeyCount(0);
3257 3281
3258 // Reload all extensions, and make sure it comes back. 3282 // Reload all extensions, and make sure it comes back.
3259 std::string extension_id = service_->extensions()->at(0)->id(); 3283 std::string extension_id = service_->extensions()->at(0)->id();
3260 loaded_.clear(); 3284 loaded_.clear();
3261 service_->ReloadExtensions(); 3285 service_->ReloadExtensions();
3262 ASSERT_EQ(1u, service_->extensions()->size()); 3286 ASSERT_EQ(1u, service_->extensions()->size());
3263 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); 3287 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id());
3264 } 3288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698