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

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

Issue 10914076: ExtensionService: Delay non-critical IO until after startup has finished. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ResetExternalUpdateCheckGuard() -> ResetExternalUpdateCheckGuardForTests() Created 8 years 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
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_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 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 1223
1224 // Simulate that one of them got partially deleted by clearing its pref. 1224 // Simulate that one of them got partially deleted by clearing its pref.
1225 { 1225 {
1226 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); 1226 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings");
1227 DictionaryValue* dict = update.Get(); 1227 DictionaryValue* dict = update.Get();
1228 ASSERT_TRUE(dict != NULL); 1228 ASSERT_TRUE(dict != NULL);
1229 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); 1229 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL);
1230 } 1230 }
1231 1231
1232 service_->Init(); 1232 service_->Init();
1233 // Wait for GarbageCollectExtensions task to complete. 1233 service_->GarbageCollectExtensions();
1234
1235 // Wait for GarbageCollectExtensions tasks to complete.
1234 loop_.RunUntilIdle(); 1236 loop_.RunUntilIdle();
1235 1237
1236 file_util::FileEnumerator dirs(extensions_install_dir_, false, 1238 file_util::FileEnumerator dirs(extensions_install_dir_, false,
1237 file_util::FileEnumerator::DIRECTORIES); 1239 file_util::FileEnumerator::DIRECTORIES);
1238 size_t count = 0; 1240 size_t count = 0;
1239 while (!dirs.Next().empty()) 1241 while (!dirs.Next().empty())
1240 count++; 1242 count++;
1241 1243
1242 // We should have only gotten two extensions now. 1244 // We should have only gotten two extensions now.
1243 EXPECT_EQ(2u, count); 1245 EXPECT_EQ(2u, count);
(...skipping 17 matching lines...) Expand all
1261 .AppendASCII("Preferences"); 1263 .AppendASCII("Preferences");
1262 1264
1263 InitializeInstalledExtensionService(pref_path, source_install_dir); 1265 InitializeInstalledExtensionService(pref_path, source_install_dir);
1264 1266
1265 // This is the directory that is going to be deleted, so make sure it actually 1267 // This is the directory that is going to be deleted, so make sure it actually
1266 // is there before the garbage collection. 1268 // is there before the garbage collection.
1267 ASSERT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1269 ASSERT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1268 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); 1270 "hpiknbiabeeppbpihjehijgoemciehgk/3")));
1269 1271
1270 service_->GarbageCollectExtensions(); 1272 service_->GarbageCollectExtensions();
1271 // Wait for GarbageCollectExtensions task to complete. 1273
1274 // Wait for GarbageCollectExtensions tasks to complete.
1272 loop_.RunUntilIdle(); 1275 loop_.RunUntilIdle();
1273 1276
1274 // Verify that the pending update for the first extension didn't get 1277 // Verify that the pending update for the first extension didn't get
1275 // deleted. 1278 // deleted.
1276 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1279 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1277 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1280 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1278 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1281 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1279 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); 1282 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0")));
1280 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1283 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1281 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1284 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
(...skipping 13 matching lines...) Expand all
1295 .AppendASCII("Preferences"); 1298 .AppendASCII("Preferences");
1296 1299
1297 InitializeInstalledExtensionService(pref_path, source_install_dir); 1300 InitializeInstalledExtensionService(pref_path, source_install_dir);
1298 1301
1299 // This is the directory that is going to be deleted, so make sure it actually 1302 // This is the directory that is going to be deleted, so make sure it actually
1300 // is there before the garbage collection. 1303 // is there before the garbage collection.
1301 ASSERT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1304 ASSERT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1302 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); 1305 "hpiknbiabeeppbpihjehijgoemciehgk/3")));
1303 1306
1304 service_->Init(); 1307 service_->Init();
1305 // Wait for GarbageCollectExtensions task to complete. 1308
1309 service_->GarbageCollectExtensions();
1310
1311 // Wait for GarbageCollectExtensions tasks to complete.
1306 loop_.RunUntilIdle(); 1312 loop_.RunUntilIdle();
1307 1313
1308 // Verify that the pending update for the first extension got installed. 1314 // Verify that the pending update for the first extension got installed.
1309 EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1315 EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1310 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); 1316 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
1311 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1317 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1312 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); 1318 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0")));
1313 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1319 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII(
1314 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); 1320 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1315 EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( 1321 EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII(
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after
3227 ASSERT_TRUE(file_util::ReadFileToString( 3233 ASSERT_TRUE(file_util::ReadFileToString(
3228 path.Append(Extension::kManifestFilename), &manifest)); 3234 path.Append(Extension::kManifestFilename), &manifest));
3229 service_->component_loader()->Add(manifest, path); 3235 service_->component_loader()->Add(manifest, path);
3230 service_->Init(); 3236 service_->Init();
3231 3237
3232 // Extension should be installed despite blacklist. 3238 // Extension should be installed despite blacklist.
3233 ASSERT_EQ(1u, service_->extensions()->size()); 3239 ASSERT_EQ(1u, service_->extensions()->size());
3234 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3240 EXPECT_TRUE(service_->GetExtensionById(good0, false));
3235 3241
3236 // Poke external providers and make sure the extension is still present. 3242 // Poke external providers and make sure the extension is still present.
3243 service_->ResetExternalUpdateCheckGuardForTests();
3237 service_->CheckForExternalUpdates(); 3244 service_->CheckForExternalUpdates();
3238 ASSERT_EQ(1u, service_->extensions()->size()); 3245 ASSERT_EQ(1u, service_->extensions()->size());
3239 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3246 EXPECT_TRUE(service_->GetExtensionById(good0, false));
3240 3247
3241 // Extension should not be uninstalled on blacklist changes. 3248 // Extension should not be uninstalled on blacklist changes.
3242 { 3249 {
3243 ListPrefUpdate update(profile_->GetPrefs(), 3250 ListPrefUpdate update(profile_->GetPrefs(),
3244 prefs::kExtensionInstallDenyList); 3251 prefs::kExtensionInstallDenyList);
3245 ListValue* blacklist = update.Get(); 3252 ListValue* blacklist = update.Get();
3246 blacklist->Append(Value::CreateStringValue(good0)); 3253 blacklist->Append(Value::CreateStringValue(good0));
(...skipping 18 matching lines...) Expand all
3265 // Have policy force-install an extension. 3272 // Have policy force-install an extension.
3266 MockExtensionProvider* provider = 3273 MockExtensionProvider* provider =
3267 new MockExtensionProvider(service_, 3274 new MockExtensionProvider(service_,
3268 Extension::EXTERNAL_POLICY_DOWNLOAD); 3275 Extension::EXTERNAL_POLICY_DOWNLOAD);
3269 AddMockExternalProvider(provider); 3276 AddMockExternalProvider(provider);
3270 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3277 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
3271 data_dir_.AppendASCII("good.crx")); 3278 data_dir_.AppendASCII("good.crx"));
3272 3279
3273 // Reloading extensions should find our externally registered extension 3280 // Reloading extensions should find our externally registered extension
3274 // and install it. 3281 // and install it.
3282 service_->ResetExternalUpdateCheckGuardForTests();
3275 service_->CheckForExternalUpdates(); 3283 service_->CheckForExternalUpdates();
3276 loop_.RunUntilIdle(); 3284 loop_.RunUntilIdle();
3277 3285
3278 // Extension should be installed despite blacklist. 3286 // Extension should be installed despite blacklist.
3279 ASSERT_EQ(1u, service_->extensions()->size()); 3287 ASSERT_EQ(1u, service_->extensions()->size());
3280 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3288 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3281 3289
3282 // Blacklist update should not uninstall the extension. 3290 // Blacklist update should not uninstall the extension.
3283 { 3291 {
3284 ListPrefUpdate update(profile_->GetPrefs(), 3292 ListPrefUpdate update(profile_->GetPrefs(),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3443 // Have policy force-install an extension. 3451 // Have policy force-install an extension.
3444 MockExtensionProvider* provider = 3452 MockExtensionProvider* provider =
3445 new MockExtensionProvider(service_, 3453 new MockExtensionProvider(service_,
3446 Extension::EXTERNAL_POLICY_DOWNLOAD); 3454 Extension::EXTERNAL_POLICY_DOWNLOAD);
3447 AddMockExternalProvider(provider); 3455 AddMockExternalProvider(provider);
3448 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 3456 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
3449 data_dir_.AppendASCII("page_action.crx")); 3457 data_dir_.AppendASCII("page_action.crx"));
3450 } 3458 }
3451 3459
3452 // Providers are set up. Let them run. 3460 // Providers are set up. Let them run.
3461 service_->ResetExternalUpdateCheckGuardForTests();
3453 service_->CheckForExternalUpdates(); 3462 service_->CheckForExternalUpdates();
3454 loop_.RunUntilIdle(); 3463 loop_.RunUntilIdle();
3455 3464
3456 ASSERT_EQ(2u, service_->extensions()->size()); 3465 ASSERT_EQ(2u, service_->extensions()->size());
3457 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3466 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3458 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); 3467 EXPECT_TRUE(service_->GetExtensionById(page_action, false));
3459 ExtensionPrefs* prefs = service_->extension_prefs(); 3468 ExtensionPrefs* prefs = service_->extension_prefs();
3460 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); 3469 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
3461 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); 3470 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action));
3462 } 3471 }
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
4052 provider->set_visit_count(0); 4061 provider->set_visit_count(0);
4053 4062
4054 // Register a test extension externally using the mock registry provider. 4063 // Register a test extension externally using the mock registry provider.
4055 FilePath source_path = data_dir_.AppendASCII("good.crx"); 4064 FilePath source_path = data_dir_.AppendASCII("good.crx");
4056 4065
4057 // Add the extension. 4066 // Add the extension.
4058 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4067 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4059 4068
4060 // Reloading extensions should find our externally registered extension 4069 // Reloading extensions should find our externally registered extension
4061 // and install it. 4070 // and install it.
4071 service_->ResetExternalUpdateCheckGuardForTests();
4062 service_->CheckForExternalUpdates(); 4072 service_->CheckForExternalUpdates();
4063 loop_.RunUntilIdle(); 4073 loop_.RunUntilIdle();
4064 4074
4065 ASSERT_EQ(0u, GetErrors().size()); 4075 ASSERT_EQ(0u, GetErrors().size());
4066 ASSERT_EQ(1u, loaded_.size()); 4076 ASSERT_EQ(1u, loaded_.size());
4067 ASSERT_EQ(location, loaded_[0]->location()); 4077 ASSERT_EQ(location, loaded_[0]->location());
4068 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4078 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4069 ValidatePrefKeyCount(1); 4079 ValidatePrefKeyCount(1);
4070 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4080 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4071 ValidateIntegerPref(good_crx, "location", location); 4081 ValidateIntegerPref(good_crx, "location", location);
4072 4082
4073 // Reload extensions without changing anything. The extension should be 4083 // Reload extensions without changing anything. The extension should be
4074 // loaded again. 4084 // loaded again.
4075 loaded_.clear(); 4085 loaded_.clear();
4076 service_->ReloadExtensions(); 4086 service_->ReloadExtensions();
4077 loop_.RunUntilIdle(); 4087 loop_.RunUntilIdle();
4078 ASSERT_EQ(0u, GetErrors().size()); 4088 ASSERT_EQ(0u, GetErrors().size());
4079 ASSERT_EQ(1u, loaded_.size()); 4089 ASSERT_EQ(1u, loaded_.size());
4080 ValidatePrefKeyCount(1); 4090 ValidatePrefKeyCount(1);
4081 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4091 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4082 ValidateIntegerPref(good_crx, "location", location); 4092 ValidateIntegerPref(good_crx, "location", location);
4083 4093
4084 // Now update the extension with a new version. We should get upgraded. 4094 // Now update the extension with a new version. We should get upgraded.
4085 source_path = source_path.DirName().AppendASCII("good2.crx"); 4095 source_path = source_path.DirName().AppendASCII("good2.crx");
4086 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4096 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4087 4097
4088 loaded_.clear(); 4098 loaded_.clear();
4099 service_->ResetExternalUpdateCheckGuardForTests();
4089 service_->CheckForExternalUpdates(); 4100 service_->CheckForExternalUpdates();
4090 loop_.RunUntilIdle(); 4101 loop_.RunUntilIdle();
4091 ASSERT_EQ(0u, GetErrors().size()); 4102 ASSERT_EQ(0u, GetErrors().size());
4092 ASSERT_EQ(1u, loaded_.size()); 4103 ASSERT_EQ(1u, loaded_.size());
4093 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4104 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4094 ValidatePrefKeyCount(1); 4105 ValidatePrefKeyCount(1);
4095 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4106 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4096 ValidateIntegerPref(good_crx, "location", location); 4107 ValidateIntegerPref(good_crx, "location", location);
4097 4108
4098 // Uninstall the extension and reload. Nothing should happen because the 4109 // Uninstall the extension and reload. Nothing should happen because the
4099 // preference should prevent us from reinstalling. 4110 // preference should prevent us from reinstalling.
4100 std::string id = loaded_[0]->id(); 4111 std::string id = loaded_[0]->id();
4101 service_->UninstallExtension(id, false, NULL); 4112 service_->UninstallExtension(id, false, NULL);
4102 loop_.RunUntilIdle(); 4113 loop_.RunUntilIdle();
4103 4114
4104 FilePath install_path = extensions_install_dir_.AppendASCII(id); 4115 FilePath install_path = extensions_install_dir_.AppendASCII(id);
4105 if (Extension::IsRequired(location)) { 4116 if (Extension::IsRequired(location)) {
4106 // Policy controlled extensions should not have been touched by uninstall. 4117 // Policy controlled extensions should not have been touched by uninstall.
4107 ASSERT_TRUE(file_util::PathExists(install_path)); 4118 ASSERT_TRUE(file_util::PathExists(install_path));
4108 } else { 4119 } else {
4109 // The extension should also be gone from the install directory. 4120 // The extension should also be gone from the install directory.
4110 ASSERT_FALSE(file_util::PathExists(install_path)); 4121 ASSERT_FALSE(file_util::PathExists(install_path));
4111 loaded_.clear(); 4122 loaded_.clear();
4123 service_->ResetExternalUpdateCheckGuardForTests();
4112 service_->CheckForExternalUpdates(); 4124 service_->CheckForExternalUpdates();
4113 loop_.RunUntilIdle(); 4125 loop_.RunUntilIdle();
4114 ASSERT_EQ(0u, loaded_.size()); 4126 ASSERT_EQ(0u, loaded_.size());
4115 ValidatePrefKeyCount(1); 4127 ValidatePrefKeyCount(1);
4116 ValidateIntegerPref(good_crx, "state", 4128 ValidateIntegerPref(good_crx, "state",
4117 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4129 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4118 ValidateIntegerPref(good_crx, "location", location); 4130 ValidateIntegerPref(good_crx, "location", location);
4119 4131
4120 // Now clear the preference and reinstall. 4132 // Now clear the preference and reinstall.
4121 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4133 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4122 4134
4123 loaded_.clear(); 4135 loaded_.clear();
4136 service_->ResetExternalUpdateCheckGuardForTests();
4124 service_->CheckForExternalUpdates(); 4137 service_->CheckForExternalUpdates();
4125 loop_.RunUntilIdle(); 4138 loop_.RunUntilIdle();
4126 ASSERT_EQ(1u, loaded_.size()); 4139 ASSERT_EQ(1u, loaded_.size());
4127 } 4140 }
4128 ValidatePrefKeyCount(1); 4141 ValidatePrefKeyCount(1);
4129 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4142 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4130 ValidateIntegerPref(good_crx, "location", location); 4143 ValidateIntegerPref(good_crx, "location", location);
4131 4144
4132 if (Extension::IsRequired(location)) { 4145 if (Extension::IsRequired(location)) {
4133 EXPECT_EQ(2, provider->visit_count()); 4146 EXPECT_EQ(2, provider->visit_count());
4134 } else { 4147 } else {
4135 // Now test an externally triggered uninstall (deleting the registry key or 4148 // Now test an externally triggered uninstall (deleting the registry key or
4136 // the pref entry). 4149 // the pref entry).
4137 provider->RemoveExtension(good_crx); 4150 provider->RemoveExtension(good_crx);
4138 4151
4139 loaded_.clear(); 4152 loaded_.clear();
4140 service_->OnExternalProviderReady(provider); 4153 service_->OnExternalProviderReady(provider);
4141 loop_.RunUntilIdle(); 4154 loop_.RunUntilIdle();
4142 ASSERT_EQ(0u, loaded_.size()); 4155 ASSERT_EQ(0u, loaded_.size());
4143 ValidatePrefKeyCount(0); 4156 ValidatePrefKeyCount(0);
4144 4157
4145 // The extension should also be gone from the install directory. 4158 // The extension should also be gone from the install directory.
4146 ASSERT_FALSE(file_util::PathExists(install_path)); 4159 ASSERT_FALSE(file_util::PathExists(install_path));
4147 4160
4148 // Now test the case where user uninstalls and then the extension is removed 4161 // Now test the case where user uninstalls and then the extension is removed
4149 // from the external provider. 4162 // from the external provider.
4150 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4163 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4164 service_->ResetExternalUpdateCheckGuardForTests();
4151 service_->CheckForExternalUpdates(); 4165 service_->CheckForExternalUpdates();
4152 loop_.RunUntilIdle(); 4166 loop_.RunUntilIdle();
4153 4167
4154 ASSERT_EQ(1u, loaded_.size()); 4168 ASSERT_EQ(1u, loaded_.size());
4155 ASSERT_EQ(0u, GetErrors().size()); 4169 ASSERT_EQ(0u, GetErrors().size());
4156 4170
4157 // User uninstalls. 4171 // User uninstalls.
4158 loaded_.clear(); 4172 loaded_.clear();
4159 service_->UninstallExtension(id, false, NULL); 4173 service_->UninstallExtension(id, false, NULL);
4160 loop_.RunUntilIdle(); 4174 loop_.RunUntilIdle();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
4249 .DirName() 4263 .DirName()
4250 .AppendASCII("PreferencesExternal"); 4264 .AppendASCII("PreferencesExternal");
4251 4265
4252 // This initializes the extensions service with no ExternalProviders. 4266 // This initializes the extensions service with no ExternalProviders.
4253 InitializeInstalledExtensionService(pref_path, source_install_dir); 4267 InitializeInstalledExtensionService(pref_path, source_install_dir);
4254 set_extensions_enabled(false); 4268 set_extensions_enabled(false);
4255 4269
4256 service_->Init(); 4270 service_->Init();
4257 4271
4258 ASSERT_EQ(0u, GetErrors().size()); 4272 ASSERT_EQ(0u, GetErrors().size());
4259 ASSERT_EQ(0u, loaded_.size()); 4273
4274 service_->CheckForExternalUpdates();
4275 service_->GarbageCollectExtensions();
4260 4276
4261 // Verify that it's not the disabled extensions flag causing it not to load. 4277 // Verify that it's not the disabled extensions flag causing it not to load.
4262 set_extensions_enabled(true); 4278 set_extensions_enabled(true);
4263 service_->ReloadExtensions(); 4279 service_->ReloadExtensions();
4264 loop_.RunUntilIdle(); 4280 loop_.RunUntilIdle();
4265 4281
4266 ASSERT_EQ(0u, GetErrors().size()); 4282 ASSERT_EQ(0u, GetErrors().size());
4267 ASSERT_EQ(0u, loaded_.size()); 4283 ASSERT_EQ(0u, loaded_.size());
4268 } 4284 }
4269 4285
4270 // Test that running multiple update checks simultaneously does not 4286 // Test that running multiple update checks simultaneously does not
4271 // keep the update from succeeding. 4287 // keep the update from succeeding.
4272 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { 4288 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
4273 InitializeEmptyExtensionService(); 4289 InitializeEmptyExtensionService();
4274 4290
4275 MockExtensionProvider* provider = 4291 MockExtensionProvider* provider =
4276 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 4292 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
4277 AddMockExternalProvider(provider); 4293 AddMockExternalProvider(provider);
4278 4294
4279 // Verify that starting with no providers loads no extensions. 4295 // Verify that starting with no providers loads no extensions.
4280 service_->Init(); 4296 service_->Init();
4281 ASSERT_EQ(0u, loaded_.size()); 4297 ASSERT_EQ(0u, loaded_.size());
4282 4298
4283 // Start two checks for updates. 4299 // Start two checks for updates.
4284 provider->set_visit_count(0); 4300 provider->set_visit_count(0);
4301 service_->ResetExternalUpdateCheckGuardForTests();
4285 service_->CheckForExternalUpdates(); 4302 service_->CheckForExternalUpdates();
4303 service_->ResetExternalUpdateCheckGuardForTests();
4286 service_->CheckForExternalUpdates(); 4304 service_->CheckForExternalUpdates();
4287 loop_.RunUntilIdle(); 4305 loop_.RunUntilIdle();
4288 4306
4289 // Two calls should cause two checks for external extensions. 4307 // Two calls should cause two checks for external extensions.
4290 EXPECT_EQ(2, provider->visit_count()); 4308 EXPECT_EQ(2, provider->visit_count());
4291 EXPECT_EQ(0u, GetErrors().size()); 4309 EXPECT_EQ(0u, GetErrors().size());
4292 EXPECT_EQ(0u, loaded_.size()); 4310 EXPECT_EQ(0u, loaded_.size());
4293 4311
4294 // Register a test extension externally using the mock registry provider. 4312 // Register a test extension externally using the mock registry provider.
4295 FilePath source_path = data_dir_.AppendASCII("good.crx"); 4313 FilePath source_path = data_dir_.AppendASCII("good.crx");
4296 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4314 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4297 4315
4298 // Two checks for external updates should find the extension, and install it 4316 // Two checks for external updates should find the extension, and install it
4299 // once. 4317 // once.
4300 provider->set_visit_count(0); 4318 provider->set_visit_count(0);
4319 service_->ResetExternalUpdateCheckGuardForTests();
4301 service_->CheckForExternalUpdates(); 4320 service_->CheckForExternalUpdates();
4321 service_->ResetExternalUpdateCheckGuardForTests();
4302 service_->CheckForExternalUpdates(); 4322 service_->CheckForExternalUpdates();
4303 loop_.RunUntilIdle(); 4323 loop_.RunUntilIdle();
4304 EXPECT_EQ(2, provider->visit_count()); 4324 EXPECT_EQ(2, provider->visit_count());
4305 ASSERT_EQ(0u, GetErrors().size()); 4325 ASSERT_EQ(0u, GetErrors().size());
4306 ASSERT_EQ(1u, loaded_.size()); 4326 ASSERT_EQ(1u, loaded_.size());
4307 ASSERT_EQ(Extension::EXTERNAL_PREF, loaded_[0]->location()); 4327 ASSERT_EQ(Extension::EXTERNAL_PREF, loaded_[0]->location());
4308 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4328 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4309 ValidatePrefKeyCount(1); 4329 ValidatePrefKeyCount(1);
4310 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4330 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4311 ValidateIntegerPref(good_crx, "location", Extension::EXTERNAL_PREF); 4331 ValidateIntegerPref(good_crx, "location", Extension::EXTERNAL_PREF);
4312 4332
4313 provider->RemoveExtension(good_crx); 4333 provider->RemoveExtension(good_crx);
4314 provider->set_visit_count(0); 4334 provider->set_visit_count(0);
4335 service_->ResetExternalUpdateCheckGuardForTests();
4315 service_->CheckForExternalUpdates(); 4336 service_->CheckForExternalUpdates();
4337 service_->ResetExternalUpdateCheckGuardForTests();
4316 service_->CheckForExternalUpdates(); 4338 service_->CheckForExternalUpdates();
4317 loop_.RunUntilIdle(); 4339 loop_.RunUntilIdle();
4318 4340
4319 // Two calls should cause two checks for external extensions. 4341 // Two calls should cause two checks for external extensions.
4320 // Because the external source no longer includes good_crx, 4342 // Because the external source no longer includes good_crx,
4321 // good_crx will be uninstalled. So, expect that no extensions 4343 // good_crx will be uninstalled. So, expect that no extensions
4322 // are loaded. 4344 // are loaded.
4323 EXPECT_EQ(2, provider->visit_count()); 4345 EXPECT_EQ(2, provider->visit_count());
4324 EXPECT_EQ(0u, GetErrors().size()); 4346 EXPECT_EQ(0u, GetErrors().size());
4325 EXPECT_EQ(0u, loaded_.size()); 4347 EXPECT_EQ(0u, loaded_.size());
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after
5743 5765
5744 service_->CheckForExternalUpdates(); 5766 service_->CheckForExternalUpdates();
5745 loop_.RunUntilIdle(); 5767 loop_.RunUntilIdle();
5746 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5768 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5747 5769
5748 // A hosted app, installed externally. 5770 // A hosted app, installed externally.
5749 // This SHOULD trigger an alert. 5771 // This SHOULD trigger an alert.
5750 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5772 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5751 data_dir_.AppendASCII("hosted_app.crx")); 5773 data_dir_.AppendASCII("hosted_app.crx"));
5752 5774
5775 service_->ResetExternalUpdateCheckGuardForTests();
5753 service_->CheckForExternalUpdates(); 5776 service_->CheckForExternalUpdates();
5777 service_->GarbageCollectExtensions();
5754 loop_.RunUntilIdle(); 5778 loop_.RunUntilIdle();
5755 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5779 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5756 service_->EnableExtension(hosted_app); 5780 service_->EnableExtension(hosted_app);
5757 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5781 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5758 5782
5759 // Another normal extension, but installed externally. 5783 // Another normal extension, but installed externally.
5760 // This SHOULD trigger an alert. 5784 // This SHOULD trigger an alert.
5761 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5785 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5762 data_dir_.AppendASCII("page_action.crx")); 5786 data_dir_.AppendASCII("page_action.crx"));
5763 5787
5788 service_->ResetExternalUpdateCheckGuardForTests();
5764 service_->CheckForExternalUpdates(); 5789 service_->CheckForExternalUpdates();
5765 loop_.RunUntilIdle(); 5790 loop_.RunUntilIdle();
5766 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5791 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5767 } 5792 }
5768 5793
5769 // Test that external extensions are initially disabled, and that enabling 5794 // Test that external extensions are initially disabled, and that enabling
5770 // them clears the prompt. 5795 // them clears the prompt.
5771 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 5796 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
5772 FeatureSwitch::ScopedOverride prompt( 5797 FeatureSwitch::ScopedOverride prompt(
5773 FeatureSwitch::prompt_for_external_extensions(), true); 5798 FeatureSwitch::prompt_for_external_extensions(), true);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5838 AddMockExternalProvider(provider_registry); 5863 AddMockExternalProvider(provider_registry);
5839 MockExtensionProvider* provider_pref = 5864 MockExtensionProvider* provider_pref =
5840 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 5865 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5841 AddMockExternalProvider(provider_pref); 5866 AddMockExternalProvider(provider_pref);
5842 5867
5843 provider_registry->UpdateOrAddExtension(good_crx, "1.0.0.0", 5868 provider_registry->UpdateOrAddExtension(good_crx, "1.0.0.0",
5844 data_dir_.AppendASCII("good.crx")); 5869 data_dir_.AppendASCII("good.crx"));
5845 provider_pref->UpdateOrAddExtension(good_crx, "1.0.0.0", 5870 provider_pref->UpdateOrAddExtension(good_crx, "1.0.0.0",
5846 data_dir_.AppendASCII("good.crx")); 5871 data_dir_.AppendASCII("good.crx"));
5847 5872
5873 service_->ResetExternalUpdateCheckGuardForTests();
5848 service_->CheckForExternalUpdates(); 5874 service_->CheckForExternalUpdates();
5849 loop_.RunUntilIdle(); 5875 loop_.RunUntilIdle();
5850 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5876 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5851 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5877 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5852 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5878 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5853 5879
5854 ExtensionPrefs* prefs = service_->extension_prefs(); 5880 ExtensionPrefs* prefs = service_->extension_prefs();
5855 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5881 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5856 Extension::DISABLE_SIDELOAD_WIPEOUT); 5882 Extension::DISABLE_SIDELOAD_WIPEOUT);
5857 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5883 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5858 Extension::DISABLE_SIDELOAD_WIPEOUT); 5884 Extension::DISABLE_SIDELOAD_WIPEOUT);
5859 } 5885 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698