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

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

Issue 2259383002: Consistently use namespaced base::Version in extensions code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 void RemoveExtension(const std::string& id) { 279 void RemoveExtension(const std::string& id) {
280 extension_map_.erase(id); 280 extension_map_.erase(id);
281 } 281 }
282 282
283 // ExternalProvider implementation: 283 // ExternalProvider implementation:
284 void VisitRegisteredExtension() override { 284 void VisitRegisteredExtension() override {
285 visit_count_++; 285 visit_count_++;
286 for (DataMap::const_iterator i = extension_map_.begin(); 286 for (DataMap::const_iterator i = extension_map_.begin();
287 i != extension_map_.end(); ++i) { 287 i != extension_map_.end(); ++i) {
288 std::unique_ptr<Version> version(new Version(i->second.first)); 288 std::unique_ptr<base::Version> version(
289 new base::Version(i->second.first));
289 290
290 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 291 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
291 i->first, std::move(version), i->second.second, location_, 292 i->first, std::move(version), i->second.second, location_,
292 Extension::NO_FLAGS, false, false)); 293 Extension::NO_FLAGS, false, false));
293 visitor_->OnExternalExtensionFileFound(*info); 294 visitor_->OnExternalExtensionFileFound(*info);
294 } 295 }
295 visitor_->OnExternalProviderReady(this); 296 visitor_->OnExternalProviderReady(this);
296 } 297 }
297 298
298 bool HasExtension(const std::string& id) const override { 299 bool HasExtension(const std::string& id) const override {
299 return extension_map_.find(id) != extension_map_.end(); 300 return extension_map_.find(id) != extension_map_.end();
300 } 301 }
301 302
302 bool GetExtensionDetails(const std::string& id, 303 bool GetExtensionDetails(
303 Manifest::Location* location, 304 const std::string& id,
304 std::unique_ptr<Version>* version) const override { 305 Manifest::Location* location,
306 std::unique_ptr<base::Version>* version) const override {
305 DataMap::const_iterator it = extension_map_.find(id); 307 DataMap::const_iterator it = extension_map_.find(id);
306 if (it == extension_map_.end()) 308 if (it == extension_map_.end())
307 return false; 309 return false;
308 310
309 if (version) 311 if (version)
310 version->reset(new Version(it->second.first)); 312 version->reset(new base::Version(it->second.first));
311 313
312 if (location) 314 if (location)
313 *location = location_; 315 *location = location_;
314 316
315 return true; 317 return true;
316 } 318 }
317 319
318 bool IsReady() const override { return true; } 320 bool IsReady() const override { return true; }
319 321
320 void ServiceShutdown() override {} 322 void ServiceShutdown() override {}
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 404
403 EXPECT_TRUE(info.path.IsAbsolute()); 405 EXPECT_TRUE(info.path.IsAbsolute());
404 if (!fake_base_path_.empty()) 406 if (!fake_base_path_.empty())
405 EXPECT_TRUE(fake_base_path_.IsParent(info.path)); 407 EXPECT_TRUE(fake_base_path_.IsParent(info.path));
406 408
407 if (pref) { 409 if (pref) {
408 EXPECT_TRUE(provider_->HasExtension(info.extension_id)); 410 EXPECT_TRUE(provider_->HasExtension(info.extension_id));
409 411
410 // Ask provider if the extension we got back is registered. 412 // Ask provider if the extension we got back is registered.
411 Manifest::Location location = Manifest::INVALID_LOCATION; 413 Manifest::Location location = Manifest::INVALID_LOCATION;
412 std::unique_ptr<Version> v1; 414 std::unique_ptr<base::Version> v1;
413 base::FilePath crx_path; 415 base::FilePath crx_path;
414 416
415 EXPECT_TRUE(provider_->GetExtensionDetails(info.extension_id, NULL, &v1)); 417 EXPECT_TRUE(provider_->GetExtensionDetails(info.extension_id, NULL, &v1));
416 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str()); 418 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str());
417 419
418 std::unique_ptr<Version> v2; 420 std::unique_ptr<base::Version> v2;
419 EXPECT_TRUE( 421 EXPECT_TRUE(
420 provider_->GetExtensionDetails(info.extension_id, &location, &v2)); 422 provider_->GetExtensionDetails(info.extension_id, &location, &v2));
421 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str()); 423 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str());
422 EXPECT_STREQ(info.version->GetString().c_str(), v2->GetString().c_str()); 424 EXPECT_STREQ(info.version->GetString().c_str(), v2->GetString().c_str());
423 EXPECT_EQ(crx_location_, location); 425 EXPECT_EQ(crx_location_, location);
424 426
425 // Remove it so we won't count it ever again. 427 // Remove it so we won't count it ever again.
426 prefs_->Remove(info.extension_id, NULL); 428 prefs_->Remove(info.extension_id, NULL);
427 } 429 }
428 return true; 430 return true;
429 } 431 }
430 432
431 bool OnExternalExtensionUpdateUrlFound( 433 bool OnExternalExtensionUpdateUrlFound(
432 const ExternalInstallInfoUpdateUrl& info, 434 const ExternalInstallInfoUpdateUrl& info,
433 bool is_initial_load) override { 435 bool is_initial_load) override {
434 ++ids_found_; 436 ++ids_found_;
435 base::DictionaryValue* pref; 437 base::DictionaryValue* pref;
436 // This tests is to make sure that the provider only notifies us of the 438 // This tests is to make sure that the provider only notifies us of the
437 // values we gave it. So if the id we doesn't exist in our internal 439 // values we gave it. So if the id we doesn't exist in our internal
438 // dictionary then something is wrong. 440 // dictionary then something is wrong.
439 EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref)) 441 EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref))
440 << L"Got back ID (" << info.extension_id.c_str() 442 << L"Got back ID (" << info.extension_id.c_str()
441 << ") we weren't expecting"; 443 << ") we weren't expecting";
442 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info.download_location); 444 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info.download_location);
443 445
444 if (pref) { 446 if (pref) {
445 EXPECT_TRUE(provider_->HasExtension(info.extension_id)); 447 EXPECT_TRUE(provider_->HasExtension(info.extension_id));
446 448
447 // External extensions with update URLs do not have versions. 449 // External extensions with update URLs do not have versions.
448 std::unique_ptr<Version> v1; 450 std::unique_ptr<base::Version> v1;
449 Manifest::Location location1 = Manifest::INVALID_LOCATION; 451 Manifest::Location location1 = Manifest::INVALID_LOCATION;
450 EXPECT_TRUE( 452 EXPECT_TRUE(
451 provider_->GetExtensionDetails(info.extension_id, &location1, &v1)); 453 provider_->GetExtensionDetails(info.extension_id, &location1, &v1));
452 EXPECT_FALSE(v1.get()); 454 EXPECT_FALSE(v1.get());
453 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); 455 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1);
454 456
455 std::string parsed_install_parameter; 457 std::string parsed_install_parameter;
456 pref->GetString("install_parameter", &parsed_install_parameter); 458 pref->GetString("install_parameter", &parsed_install_parameter);
457 EXPECT_EQ(parsed_install_parameter, info.install_parameter); 459 EXPECT_EQ(parsed_install_parameter, info.install_parameter);
458 460
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 // extension object. 1145 // extension object.
1144 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { 1146 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) {
1145 const char kPrefFromBookmark[] = "from_bookmark"; 1147 const char kPrefFromBookmark[] = "from_bookmark";
1146 1148
1147 InitializeEmptyExtensionService(); 1149 InitializeEmptyExtensionService();
1148 1150
1149 base::FilePath path = data_dir().AppendASCII("good.crx"); 1151 base::FilePath path = data_dir().AppendASCII("good.crx");
1150 service()->set_extensions_enabled(true); 1152 service()->set_extensions_enabled(true);
1151 1153
1152 // Register and install an external extension. 1154 // Register and install an external extension.
1153 std::unique_ptr<Version> version(new Version("1.0.0.0")); 1155 std::unique_ptr<base::Version> version(new base::Version("1.0.0.0"));
1154 content::WindowedNotificationObserver observer( 1156 content::WindowedNotificationObserver observer(
1155 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1157 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1156 content::NotificationService::AllSources()); 1158 content::NotificationService::AllSources());
1157 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1159 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1158 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, 1160 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF,
1159 Extension::FROM_BOOKMARK, false /* mark_acknowledged */, 1161 Extension::FROM_BOOKMARK, false /* mark_acknowledged */,
1160 false /* install_immediately */)); 1162 false /* install_immediately */));
1161 if (service()->OnExternalExtensionFileFound(*info)) 1163 if (service()->OnExternalExtensionFileFound(*info))
1162 observer.Wait(); 1164 observer.Wait();
1163 1165
(...skipping 15 matching lines...) Expand all
1179 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1181 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1180 InitializeEmptyExtensionService(); 1182 InitializeEmptyExtensionService();
1181 1183
1182 base::FilePath path = data_dir().AppendASCII("good.crx"); 1184 base::FilePath path = data_dir().AppendASCII("good.crx");
1183 service()->set_extensions_enabled(true); 1185 service()->set_extensions_enabled(true);
1184 1186
1185 // Install an external extension. 1187 // Install an external extension.
1186 content::WindowedNotificationObserver observer( 1188 content::WindowedNotificationObserver observer(
1187 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1189 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1188 content::NotificationService::AllSources()); 1190 content::NotificationService::AllSources());
1189 std::unique_ptr<Version> version(new Version("1.0.0.0")); 1191 std::unique_ptr<base::Version> version(new base::Version("1.0.0.0"));
1190 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1192 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1191 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, 1193 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF,
1192 Extension::NO_FLAGS, false, false)); 1194 Extension::NO_FLAGS, false, false));
1193 if (service()->OnExternalExtensionFileFound(*info)) 1195 if (service()->OnExternalExtensionFileFound(*info))
1194 observer.Wait(); 1196 observer.Wait();
1195 1197
1196 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1198 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1197 1199
1198 // Uninstall it and check that its killbit gets set. 1200 // Uninstall it and check that its killbit gets set.
1199 UninstallExtension(good_crx, false); 1201 UninstallExtension(good_crx, false);
1200 ValidateIntegerPref(good_crx, "state", 1202 ValidateIntegerPref(good_crx, "state",
1201 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1203 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1202 1204
1203 // Try to re-install it externally. This should fail because of the killbit. 1205 // Try to re-install it externally. This should fail because of the killbit.
1204 service()->OnExternalExtensionFileFound(*info); 1206 service()->OnExternalExtensionFileFound(*info);
1205 base::RunLoop().RunUntilIdle(); 1207 base::RunLoop().RunUntilIdle();
1206 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); 1208 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1207 ValidateIntegerPref(good_crx, "state", 1209 ValidateIntegerPref(good_crx, "state",
1208 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1210 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1209 1211
1210 version.reset(new Version("1.0.0.1")); 1212 version.reset(new base::Version("1.0.0.1"));
1211 // Repeat the same thing with a newer version of the extension. 1213 // Repeat the same thing with a newer version of the extension.
1212 path = data_dir().AppendASCII("good2.crx"); 1214 path = data_dir().AppendASCII("good2.crx");
1213 info.reset(new ExternalInstallInfoFile(good_crx, std::move(version), path, 1215 info.reset(new ExternalInstallInfoFile(good_crx, std::move(version), path,
1214 Manifest::EXTERNAL_PREF, 1216 Manifest::EXTERNAL_PREF,
1215 Extension::NO_FLAGS, false, false)); 1217 Extension::NO_FLAGS, false, false));
1216 service()->OnExternalExtensionFileFound(*info); 1218 service()->OnExternalExtensionFileFound(*info);
1217 base::RunLoop().RunUntilIdle(); 1219 base::RunLoop().RunUntilIdle();
1218 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); 1220 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1219 ValidateIntegerPref(good_crx, "state", 1221 ValidateIntegerPref(good_crx, "state",
1220 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1222 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); 1259 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY);
1258 service()->OnExternalProviderReady(&provider); 1260 service()->OnExternalProviderReady(&provider);
1259 } 1261 }
1260 1262
1261 // Test that external extensions with incorrect IDs are not installed. 1263 // Test that external extensions with incorrect IDs are not installed.
1262 TEST_F(ExtensionServiceTest, FailOnWrongId) { 1264 TEST_F(ExtensionServiceTest, FailOnWrongId) {
1263 InitializeEmptyExtensionService(); 1265 InitializeEmptyExtensionService();
1264 base::FilePath path = data_dir().AppendASCII("good.crx"); 1266 base::FilePath path = data_dir().AppendASCII("good.crx");
1265 service()->set_extensions_enabled(true); 1267 service()->set_extensions_enabled(true);
1266 1268
1267 std::unique_ptr<Version> version(new Version("1.0.0.0")); 1269 std::unique_ptr<base::Version> version(new base::Version("1.0.0.0"));
1268 1270
1269 const std::string wrong_id = all_zero; 1271 const std::string wrong_id = all_zero;
1270 const std::string correct_id = good_crx; 1272 const std::string correct_id = good_crx;
1271 ASSERT_NE(correct_id, wrong_id); 1273 ASSERT_NE(correct_id, wrong_id);
1272 1274
1273 // Install an external extension with an ID from the external 1275 // Install an external extension with an ID from the external
1274 // source that is not equal to the ID in the extension manifest. 1276 // source that is not equal to the ID in the extension manifest.
1275 content::WindowedNotificationObserver observer( 1277 content::WindowedNotificationObserver observer(
1276 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1278 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1277 content::NotificationService::AllSources()); 1279 content::NotificationService::AllSources());
(...skipping 19 matching lines...) Expand all
1297 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1299 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1298 InitializeEmptyExtensionService(); 1300 InitializeEmptyExtensionService();
1299 base::FilePath path = data_dir().AppendASCII("good.crx"); 1301 base::FilePath path = data_dir().AppendASCII("good.crx");
1300 service()->set_extensions_enabled(true); 1302 service()->set_extensions_enabled(true);
1301 1303
1302 // Install an external extension with a version from the external 1304 // Install an external extension with a version from the external
1303 // source that is not equal to the version in the extension manifest. 1305 // source that is not equal to the version in the extension manifest.
1304 content::WindowedNotificationObserver observer( 1306 content::WindowedNotificationObserver observer(
1305 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1307 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1306 content::NotificationService::AllSources()); 1308 content::NotificationService::AllSources());
1307 std::unique_ptr<Version> wrong_version(new Version("1.2.3.4")); 1309 std::unique_ptr<base::Version> wrong_version(new base::Version("1.2.3.4"));
1308 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1310 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1309 good_crx, std::move(wrong_version), path, Manifest::EXTERNAL_PREF, 1311 good_crx, std::move(wrong_version), path, Manifest::EXTERNAL_PREF,
1310 Extension::NO_FLAGS, false, false)); 1312 Extension::NO_FLAGS, false, false));
1311 service()->OnExternalExtensionFileFound(*info); 1313 service()->OnExternalExtensionFileFound(*info);
1312 1314
1313 observer.Wait(); 1315 observer.Wait();
1314 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1316 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1315 1317
1316 // Try again with the right version. Expect success. 1318 // Try again with the right version. Expect success.
1317 service()->pending_extension_manager()->Remove(good_crx); 1319 service()->pending_extension_manager()->Remove(good_crx);
1318 std::unique_ptr<Version> correct_version(new Version("1.0.0.0")); 1320 std::unique_ptr<base::Version> correct_version(new base::Version("1.0.0.0"));
1319 info->version = std::move(correct_version); 1321 info->version = std::move(correct_version);
1320 content::WindowedNotificationObserver observer2( 1322 content::WindowedNotificationObserver observer2(
1321 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1323 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1322 content::NotificationService::AllSources()); 1324 content::NotificationService::AllSources());
1323 if (service()->OnExternalExtensionFileFound(*info)) 1325 if (service()->OnExternalExtensionFileFound(*info))
1324 observer2.Wait(); 1326 observer2.Wait();
1325 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1327 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1326 } 1328 }
1327 1329
1328 // Install a user script (they get converted automatically to an extension) 1330 // Install a user script (they get converted automatically to an extension)
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
3007 const Extension* good = InstallCRX(path, INSTALL_NEW); 3009 const Extension* good = InstallCRX(path, INSTALL_NEW);
3008 ASSERT_EQ(1u, registry()->enabled_extensions().size()); 3010 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3009 3011
3010 EXPECT_FALSE(good->is_theme()); 3012 EXPECT_FALSE(good->is_theme());
3011 3013
3012 // Use AddExtensionImpl() as AddFrom*() would balk. 3014 // Use AddExtensionImpl() as AddFrom*() would balk.
3013 service()->pending_extension_manager()->AddExtensionImpl( 3015 service()->pending_extension_manager()->AddExtensionImpl(
3014 good->id(), 3016 good->id(),
3015 std::string(), 3017 std::string(),
3016 extensions::ManifestURL::GetUpdateURL(good), 3018 extensions::ManifestURL::GetUpdateURL(good),
3017 Version(), 3019 base::Version(),
3018 &IsExtension, 3020 &IsExtension,
3019 kGoodIsFromSync, 3021 kGoodIsFromSync,
3020 Manifest::INTERNAL, 3022 Manifest::INTERNAL,
3021 Extension::NO_FLAGS, 3023 Extension::NO_FLAGS,
3022 false, 3024 false,
3023 kGoodRemoteInstall); 3025 kGoodRemoteInstall);
3024 UpdateExtension(good->id(), path, ENABLED); 3026 UpdateExtension(good->id(), path, ENABLED);
3025 3027
3026 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 3028 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
3027 } 3029 }
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 TEST_F(ExtensionServiceTest, UpdatingPendingExternalExtensionWithFlags) { 4230 TEST_F(ExtensionServiceTest, UpdatingPendingExternalExtensionWithFlags) {
4229 // Regression test for crbug.com/627522 4231 // Regression test for crbug.com/627522
4230 const char kPrefFromBookmark[] = "from_bookmark"; 4232 const char kPrefFromBookmark[] = "from_bookmark";
4231 4233
4232 InitializeEmptyExtensionService(); 4234 InitializeEmptyExtensionService();
4233 4235
4234 base::FilePath path = data_dir().AppendASCII("good.crx"); 4236 base::FilePath path = data_dir().AppendASCII("good.crx");
4235 service()->set_extensions_enabled(true); 4237 service()->set_extensions_enabled(true);
4236 4238
4237 // Register and install an external extension. 4239 // Register and install an external extension.
4238 std::unique_ptr<Version> version(new Version("1.0.0.0")); 4240 std::unique_ptr<base::Version> version(new base::Version("1.0.0.0"));
4239 content::WindowedNotificationObserver observer( 4241 content::WindowedNotificationObserver observer(
4240 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 4242 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
4241 content::NotificationService::AllSources()); 4243 content::NotificationService::AllSources());
4242 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 4244 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
4243 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, 4245 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF,
4244 Extension::FROM_BOOKMARK, false /* mark_acknowledged */, 4246 Extension::FROM_BOOKMARK, false /* mark_acknowledged */,
4245 false /* install_immediately */)); 4247 false /* install_immediately */));
4246 ASSERT_TRUE(service()->OnExternalExtensionFileFound(*info)); 4248 ASSERT_TRUE(service()->OnExternalExtensionFileFound(*info));
4247 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(good_crx)); 4249 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(good_crx));
4248 4250
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
5805 5807
5806 // Skip install when the location has the same priority as the installed 5808 // Skip install when the location has the same priority as the installed
5807 // location. 5809 // location.
5808 info->download_location = Manifest::INTERNAL; 5810 info->download_location = Manifest::INTERNAL;
5809 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); 5811 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true));
5810 5812
5811 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5813 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5812 } 5814 }
5813 5815
5814 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { 5816 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
5815 Version older_version("0.1.0.0"); 5817 base::Version older_version("0.1.0.0");
5816 Version newer_version("2.0.0.0"); 5818 base::Version newer_version("2.0.0.0");
5817 5819
5818 // We don't want the extension to be installed. A path that doesn't 5820 // We don't want the extension to be installed. A path that doesn't
5819 // point to a valid CRX ensures this. 5821 // point to a valid CRX ensures this.
5820 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); 5822 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path"));
5821 5823
5822 const int kCreationFlags = 0; 5824 const int kCreationFlags = 0;
5823 const bool kDontMarkAcknowledged = false; 5825 const bool kDontMarkAcknowledged = false;
5824 const bool kDontInstallImmediately = false; 5826 const bool kDontInstallImmediately = false;
5825 5827
5826 InitializeEmptyExtensionService(); 5828 InitializeEmptyExtensionService();
(...skipping 10 matching lines...) Expand all
5837 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 5839 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
5838 Manifest::INTERNAL)); 5840 Manifest::INTERNAL));
5839 ASSERT_EQ(Manifest::EXTERNAL_PREF, 5841 ASSERT_EQ(Manifest::EXTERNAL_PREF,
5840 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, 5842 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
5841 Manifest::INTERNAL)); 5843 Manifest::INTERNAL));
5842 5844
5843 extensions::PendingExtensionManager* pending = 5845 extensions::PendingExtensionManager* pending =
5844 service()->pending_extension_manager(); 5846 service()->pending_extension_manager();
5845 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5847 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5846 5848
5847 std::unique_ptr<Version> older_version_ptr(new Version(older_version)); 5849 std::unique_ptr<base::Version> older_version_ptr(
5850 new base::Version(older_version));
5848 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 5851 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
5849 kGoodId, std::move(older_version_ptr), kInvalidPathToCrx, 5852 kGoodId, std::move(older_version_ptr), kInvalidPathToCrx,
5850 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged, 5853 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged,
5851 kDontInstallImmediately)); 5854 kDontInstallImmediately));
5852 { 5855 {
5853 // Simulate an external source adding the extension as INTERNAL. 5856 // Simulate an external source adding the extension as INTERNAL.
5854 content::WindowedNotificationObserver observer( 5857 content::WindowedNotificationObserver observer(
5855 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 5858 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
5856 content::NotificationService::AllSources()); 5859 content::NotificationService::AllSources());
5857 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5860 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
5918 5921
5919 // Tests assume |older_version| is less than the installed version, and 5922 // Tests assume |older_version| is less than the installed version, and
5920 // |newer_version| is greater. Verify this: 5923 // |newer_version| is greater. Verify this:
5921 ASSERT_LT(older_version, *ext->version()); 5924 ASSERT_LT(older_version, *ext->version());
5922 ASSERT_GT(newer_version, *ext->version()); 5925 ASSERT_GT(newer_version, *ext->version());
5923 5926
5924 // An external install for the same location should fail if the version is 5927 // An external install for the same location should fail if the version is
5925 // older, or the same, and succeed if the version is newer. 5928 // older, or the same, and succeed if the version is newer.
5926 5929
5927 // Older than the installed version... 5930 // Older than the installed version...
5928 info->version.reset(new Version(older_version)); 5931 info->version.reset(new base::Version(older_version));
5929 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 5932 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
5930 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5933 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5931 5934
5932 // Same version as the installed version... 5935 // Same version as the installed version...
5933 info->version.reset(new Version(ext->VersionString())); 5936 info->version.reset(new base::Version(ext->VersionString()));
5934 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 5937 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
5935 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5938 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5936 5939
5937 // Newer than the installed version... 5940 // Newer than the installed version...
5938 info->version.reset(new Version(newer_version)); 5941 info->version.reset(new base::Version(newer_version));
5939 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5942 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5940 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5943 EXPECT_TRUE(pending->IsIdPending(kGoodId));
5941 5944
5942 // An external install for a higher priority install source should succeed 5945 // An external install for a higher priority install source should succeed
5943 // if the version is greater. |older_version| is not... 5946 // if the version is greater. |older_version| is not...
5944 info->version.reset(new Version(older_version)); 5947 info->version.reset(new base::Version(older_version));
5945 info->crx_location = Manifest::EXTERNAL_PREF; 5948 info->crx_location = Manifest::EXTERNAL_PREF;
5946 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 5949 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
5947 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5950 EXPECT_TRUE(pending->IsIdPending(kGoodId));
5948 5951
5949 // |newer_version| is newer. 5952 // |newer_version| is newer.
5950 info->version.reset(new Version(newer_version)); 5953 info->version.reset(new base::Version(newer_version));
5951 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5954 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5952 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5955 EXPECT_TRUE(pending->IsIdPending(kGoodId));
5953 5956
5954 // An external install for an even higher priority install source should 5957 // An external install for an even higher priority install source should
5955 // succeed if the version is greater. 5958 // succeed if the version is greater.
5956 info->crx_location = Manifest::EXTERNAL_REGISTRY; 5959 info->crx_location = Manifest::EXTERNAL_REGISTRY;
5957 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5960 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5958 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5961 EXPECT_TRUE(pending->IsIdPending(kGoodId));
5959 5962
5960 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, 5963 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY,
5961 // adding from external pref will now fail. 5964 // adding from external pref will now fail.
5962 info->crx_location = Manifest::EXTERNAL_PREF; 5965 info->crx_location = Manifest::EXTERNAL_PREF;
5963 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 5966 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
5964 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5967 EXPECT_TRUE(pending->IsIdPending(kGoodId));
5965 } 5968 }
5966 5969
5967 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { 5970 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) {
5968 Version kVersion123("1.2.3"); 5971 base::Version kVersion123("1.2.3");
5969 Version kVersion124("1.2.4"); 5972 base::Version kVersion124("1.2.4");
5970 Version kVersion125("1.2.5"); 5973 base::Version kVersion125("1.2.5");
5971 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); 5974 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path"));
5972 const int kCreationFlags = 0; 5975 const int kCreationFlags = 0;
5973 const bool kDontMarkAcknowledged = false; 5976 const bool kDontMarkAcknowledged = false;
5974 const bool kDontInstallImmediately = false; 5977 const bool kDontInstallImmediately = false;
5975 5978
5976 InitializeEmptyExtensionService(); 5979 InitializeEmptyExtensionService();
5977 5980
5978 extensions::PendingExtensionManager* pending = 5981 extensions::PendingExtensionManager* pending =
5979 service()->pending_extension_manager(); 5982 service()->pending_extension_manager();
5980 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5983 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5981 5984
5982 // An external provider starts installing from a local crx. 5985 // An external provider starts installing from a local crx.
5983 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 5986 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
5984 kGoodId, base::WrapUnique(new Version(kVersion123)), kInvalidPathToCrx, 5987 kGoodId, base::WrapUnique(new base::Version(kVersion123)),
5985 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged, 5988 kInvalidPathToCrx, Manifest::EXTERNAL_PREF, kCreationFlags,
5986 kDontInstallImmediately)); 5989 kDontMarkAcknowledged, kDontInstallImmediately));
5987 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5990 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5988 5991
5989 const extensions::PendingExtensionInfo* pending_info; 5992 const extensions::PendingExtensionInfo* pending_info;
5990 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 5993 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
5991 EXPECT_TRUE(pending_info->version().IsValid()); 5994 EXPECT_TRUE(pending_info->version().IsValid());
5992 EXPECT_EQ(pending_info->version(), kVersion123); 5995 EXPECT_EQ(pending_info->version(), kVersion123);
5993 5996
5994 // Adding a newer version overrides the currently pending version. 5997 // Adding a newer version overrides the currently pending version.
5995 info->version.reset(new Version(kVersion124)); 5998 info->version.reset(new base::Version(kVersion124));
5996 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5999 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5997 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 6000 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
5998 EXPECT_TRUE(pending_info->version().IsValid()); 6001 EXPECT_TRUE(pending_info->version().IsValid());
5999 EXPECT_EQ(pending_info->version(), kVersion124); 6002 EXPECT_EQ(pending_info->version(), kVersion124);
6000 6003
6001 // Adding an older version fails. 6004 // Adding an older version fails.
6002 info->version.reset(new Version(kVersion123)); 6005 info->version.reset(new base::Version(kVersion123));
6003 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 6006 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
6004 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 6007 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
6005 EXPECT_TRUE(pending_info->version().IsValid()); 6008 EXPECT_TRUE(pending_info->version().IsValid());
6006 EXPECT_EQ(pending_info->version(), kVersion124); 6009 EXPECT_EQ(pending_info->version(), kVersion124);
6007 6010
6008 // Adding an older version fails even when coming from a higher-priority 6011 // Adding an older version fails even when coming from a higher-priority
6009 // location. 6012 // location.
6010 info->crx_location = Manifest::EXTERNAL_REGISTRY; 6013 info->crx_location = Manifest::EXTERNAL_REGISTRY;
6011 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 6014 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
6012 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 6015 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
6065 crx_id_, 6068 crx_id_,
6066 std::string(), 6069 std::string(),
6067 GURL(), 6070 GURL(),
6068 Manifest::EXTERNAL_PREF_DOWNLOAD, 6071 Manifest::EXTERNAL_PREF_DOWNLOAD,
6069 Extension::NO_FLAGS, 6072 Extension::NO_FLAGS,
6070 false); 6073 false);
6071 } 6074 }
6072 6075
6073 // Fake an external file from external_extensions.json. 6076 // Fake an external file from external_extensions.json.
6074 bool AddPendingExternalPrefFileInstall() { 6077 bool AddPendingExternalPrefFileInstall() {
6075 std::unique_ptr<Version> version(new Version("1.0.0.0")); 6078 std::unique_ptr<base::Version> version(new base::Version("1.0.0.0"));
6076 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 6079 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
6077 crx_id_, std::move(version), crx_path_, Manifest::EXTERNAL_PREF, 6080 crx_id_, std::move(version), crx_path_, Manifest::EXTERNAL_PREF,
6078 Extension::NO_FLAGS, false, false)); 6081 Extension::NO_FLAGS, false, false));
6079 return service()->OnExternalExtensionFileFound(*info); 6082 return service()->OnExternalExtensionFileFound(*info);
6080 } 6083 }
6081 6084
6082 // Fake a request from sync to install an extension. 6085 // Fake a request from sync to install an extension.
6083 bool AddPendingSyncInstall() { 6086 bool AddPendingSyncInstall() {
6084 return service()->pending_extension_manager()->AddFromSync( 6087 return service()->pending_extension_manager()->AddFromSync(
6085 crx_id_, 6088 crx_id_,
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
6910 6913
6911 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6914 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6912 content::Source<Profile>(profile()), 6915 content::Source<Profile>(profile()),
6913 content::NotificationService::NoDetails()); 6916 content::NotificationService::NoDetails());
6914 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6917 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6915 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 6918 EXPECT_EQ(0u, registry()->enabled_extensions().size());
6916 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 6919 EXPECT_EQ(0u, registry()->disabled_extensions().size());
6917 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 6920 EXPECT_EQ(0u, registry()->terminated_extensions().size());
6918 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 6921 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
6919 } 6922 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_sync_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698