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

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

Issue 17038002: Separate the NTP app ordering from the app list app ordering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert lazy initialzation Created 7 years, 3 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_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 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 1232
1233 EXPECT_EQ(std::string(good0), loaded_[0]->id()); 1233 EXPECT_EQ(std::string(good0), loaded_[0]->id());
1234 EXPECT_EQ(std::string("My extension 1"), 1234 EXPECT_EQ(std::string("My extension 1"),
1235 loaded_[0]->name()); 1235 loaded_[0]->name());
1236 EXPECT_EQ(std::string("The first extension that I made."), 1236 EXPECT_EQ(std::string("The first extension that I made."),
1237 loaded_[0]->description()); 1237 loaded_[0]->description());
1238 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); 1238 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location());
1239 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); 1239 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false));
1240 EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); 1240 EXPECT_EQ(expected_num_extensions, service_->extensions()->size());
1241 1241
1242 ValidatePrefKeyCount(3);
1243 ValidateIntegerPref(good0, "state", Extension::ENABLED); 1242 ValidateIntegerPref(good0, "state", Extension::ENABLED);
1244 ValidateIntegerPref(good0, "location", Manifest::INTERNAL); 1243 ValidateIntegerPref(good0, "location", Manifest::INTERNAL);
1245 ValidateIntegerPref(good1, "state", Extension::ENABLED); 1244 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1246 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); 1245 ValidateIntegerPref(good1, "location", Manifest::INTERNAL);
1247 ValidateIntegerPref(good2, "state", Extension::ENABLED); 1246 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1248 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); 1247 ValidateIntegerPref(good2, "location", Manifest::INTERNAL);
1249 1248
1250 URLPatternSet expected_patterns; 1249 URLPatternSet expected_patterns;
1251 AddPattern(&expected_patterns, "file:///*"); 1250 AddPattern(&expected_patterns, "file:///*");
1252 AddPattern(&expected_patterns, "http://*.google.com/*"); 1251 AddPattern(&expected_patterns, "http://*.google.com/*");
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 // Remove it because we are not testing the pending extension manager's 1542 // Remove it because we are not testing the pending extension manager's
1544 // ability to download and install extensions. 1543 // ability to download and install extensions.
1545 EXPECT_TRUE(service_->pending_extension_manager()->Remove(pending_id)); 1544 EXPECT_TRUE(service_->pending_extension_manager()->Remove(pending_id));
1546 } 1545 }
1547 1546
1548 // Test installing extensions. This test tries to install few extensions using 1547 // Test installing extensions. This test tries to install few extensions using
1549 // crx files. If you need to change those crx files, feel free to repackage 1548 // crx files. If you need to change those crx files, feel free to repackage
1550 // them, throw away the key used and change the id's above. 1549 // them, throw away the key used and change the id's above.
1551 TEST_F(ExtensionServiceTest, InstallExtension) { 1550 TEST_F(ExtensionServiceTest, InstallExtension) {
1552 InitializeEmptyExtensionService(); 1551 InitializeEmptyExtensionService();
1552 int pref_count = GetPrefKeyCount();
1553 1553
1554 // Extensions not enabled. 1554 // Extensions not enabled.
1555 set_extensions_enabled(false); 1555 set_extensions_enabled(false);
1556 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1556 base::FilePath path = data_dir_.AppendASCII("good.crx");
1557 InstallCRX(path, INSTALL_FAILED); 1557 InstallCRX(path, INSTALL_FAILED);
1558 set_extensions_enabled(true); 1558 set_extensions_enabled(true);
1559 1559
1560 ValidatePrefKeyCount(0); 1560 ValidatePrefKeyCount(pref_count);
1561 1561
1562 // A simple extension that should install without error. 1562 // A simple extension that should install without error.
1563 path = data_dir_.AppendASCII("good.crx"); 1563 path = data_dir_.AppendASCII("good.crx");
1564 InstallCRX(path, INSTALL_NEW); 1564 InstallCRX(path, INSTALL_NEW);
1565 // TODO(erikkay): verify the contents of the installed extension. 1565 // TODO(erikkay): verify the contents of the installed extension.
1566 1566
1567 int pref_count = 0;
1568 ValidatePrefKeyCount(++pref_count); 1567 ValidatePrefKeyCount(++pref_count);
1569 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 1568 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
1570 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 1569 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
1571 1570
1572 // An extension with page actions. 1571 // An extension with page actions.
1573 path = data_dir_.AppendASCII("page_action.crx"); 1572 path = data_dir_.AppendASCII("page_action.crx");
1574 InstallCRX(path, INSTALL_NEW); 1573 InstallCRX(path, INSTALL_NEW);
1575 ValidatePrefKeyCount(++pref_count); 1574 ValidatePrefKeyCount(++pref_count);
1576 ValidateIntegerPref(page_action, "state", Extension::ENABLED); 1575 ValidateIntegerPref(page_action, "state", Extension::ENABLED);
1577 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); 1576 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 virtual void OnExtensionLoaded(const Extension* extension) OVERRIDE { 1629 virtual void OnExtensionLoaded(const Extension* extension) OVERRIDE {
1631 } 1630 }
1632 1631
1633 virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE { 1632 virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE {
1634 } 1633 }
1635 1634
1636 virtual void OnExtensionUninstalled(const Extension* extension) OVERRIDE { 1635 virtual void OnExtensionUninstalled(const Extension* extension) OVERRIDE {
1637 last_extension_uninstalled = extension->id(); 1636 last_extension_uninstalled = extension->id();
1638 } 1637 }
1639 1638
1640 virtual void OnAppsReordered() OVERRIDE { 1639 virtual void OnAppListReordered() OVERRIDE {
1641 } 1640 }
1642 1641
1643 virtual void OnAppInstalledToAppList( 1642 virtual void OnAppInstalledToAppList(
1644 const std::string& extension_id) OVERRIDE { 1643 const std::string& extension_id) OVERRIDE {
1645 } 1644 }
1646 1645
1647 virtual void OnShutdown() OVERRIDE { 1646 virtual void OnShutdown() OVERRIDE {
1648 } 1647 }
1649 1648
1650 std::string last_extension_installed; 1649 std::string last_extension_installed;
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 2340 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
2342 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, 2341 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
2343 base::FilePath(), ExtensionCreator::kOverwriteCRX)); 2342 base::FilePath(), ExtensionCreator::kOverwriteCRX));
2344 2343
2345 InstallCRX(crx_path, INSTALL_NEW); 2344 InstallCRX(crx_path, INSTALL_NEW);
2346 } 2345 }
2347 2346
2348 TEST_F(ExtensionServiceTest, InstallTheme) { 2347 TEST_F(ExtensionServiceTest, InstallTheme) {
2349 InitializeEmptyExtensionService(); 2348 InitializeEmptyExtensionService();
2350 service_->Init(); 2349 service_->Init();
2350 int pref_count = GetPrefKeyCount();
2351 2351
2352 // A theme. 2352 // A theme.
2353 base::FilePath path = data_dir_.AppendASCII("theme.crx"); 2353 base::FilePath path = data_dir_.AppendASCII("theme.crx");
2354 InstallCRX(path, INSTALL_NEW); 2354 InstallCRX(path, INSTALL_NEW);
2355 int pref_count = 0;
2356 ValidatePrefKeyCount(++pref_count); 2355 ValidatePrefKeyCount(++pref_count);
2357 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); 2356 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
2358 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); 2357 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL);
2359 2358
2360 // A theme when extensions are disabled. Themes can be installed, even when 2359 // A theme when extensions are disabled. Themes can be installed, even when
2361 // extensions are disabled. 2360 // extensions are disabled.
2362 set_extensions_enabled(false); 2361 set_extensions_enabled(false);
2363 path = data_dir_.AppendASCII("theme2.crx"); 2362 path = data_dir_.AppendASCII("theme2.crx");
2364 InstallCRX(path, INSTALL_NEW); 2363 InstallCRX(path, INSTALL_NEW);
2365 ValidatePrefKeyCount(++pref_count); 2364 ValidatePrefKeyCount(++pref_count);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); 2508 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW);
2510 2509
2511 EXPECT_EQ(0u, GetErrors().size()); 2510 EXPECT_EQ(0u, GetErrors().size());
2512 EXPECT_EQ(1u, service_->extensions()->size()); 2511 EXPECT_EQ(1u, service_->extensions()->size());
2513 EXPECT_EQ("name", theme->name()); 2512 EXPECT_EQ("name", theme->name());
2514 EXPECT_EQ("description", theme->description()); 2513 EXPECT_EQ("description", theme->description());
2515 } 2514 }
2516 2515
2517 TEST_F(ExtensionServiceTest, InstallApps) { 2516 TEST_F(ExtensionServiceTest, InstallApps) {
2518 InitializeEmptyExtensionService(); 2517 InitializeEmptyExtensionService();
2518 int pref_count = GetPrefKeyCount();
2519 2519
2520 // An empty app. 2520 // An empty app.
2521 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), 2521 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"),
2522 INSTALL_NEW); 2522 INSTALL_NEW);
2523 int pref_count = 0;
2524 ValidatePrefKeyCount(++pref_count); 2523 ValidatePrefKeyCount(++pref_count);
2525 ASSERT_EQ(1u, service_->extensions()->size()); 2524 ASSERT_EQ(1u, service_->extensions()->size());
2526 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); 2525 ValidateIntegerPref(app->id(), "state", Extension::ENABLED);
2527 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); 2526 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL);
2528 2527
2529 // Another app with non-overlapping extent. Should succeed. 2528 // Another app with non-overlapping extent. Should succeed.
2530 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2529 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
2531 ValidatePrefKeyCount(++pref_count); 2530 ValidatePrefKeyCount(++pref_count);
2532 2531
2533 // A third app whose extent overlaps the first. Should fail. 2532 // A third app whose extent overlaps the first. Should fail.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 EXPECT_TRUE( 2609 EXPECT_TRUE(
2611 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); 2610 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid());
2612 EXPECT_TRUE( 2611 EXPECT_TRUE(
2613 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); 2612 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid());
2614 } 2613 }
2615 2614
2616 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { 2615 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
2617 InitializeEmptyExtensionService(); 2616 InitializeEmptyExtensionService();
2618 EXPECT_TRUE(service_->extensions()->is_empty()); 2617 EXPECT_TRUE(service_->extensions()->is_empty());
2619 2618
2620 int pref_count = 0; 2619 int pref_count = GetPrefKeyCount();
2621 2620
2622 // Install app1 with unlimited storage. 2621 // Install app1 with unlimited storage.
2623 const Extension* extension = 2622 const Extension* extension =
2624 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2623 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
2625 ValidatePrefKeyCount(++pref_count); 2624 ValidatePrefKeyCount(++pref_count);
2626 ASSERT_EQ(1u, service_->extensions()->size()); 2625 ASSERT_EQ(1u, service_->extensions()->size());
2627 const std::string id1 = extension->id(); 2626 const std::string id1 = extension->id();
2628 EXPECT_TRUE(extension->HasAPIPermission( 2627 EXPECT_TRUE(extension->HasAPIPermission(
2629 APIPermission::kUnlimitedStorage)); 2628 APIPermission::kUnlimitedStorage));
2630 EXPECT_TRUE(extension->web_extent().MatchesURL( 2629 EXPECT_TRUE(extension->web_extent().MatchesURL(
(...skipping 30 matching lines...) Expand all
2661 UninstallExtension(id2, false); 2660 UninstallExtension(id2, false);
2662 EXPECT_EQ(0u, service_->extensions()->size()); 2661 EXPECT_EQ(0u, service_->extensions()->size());
2663 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2662 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
2664 IsStorageUnlimited(origin2)); 2663 IsStorageUnlimited(origin2));
2665 } 2664 }
2666 2665
2667 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { 2666 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
2668 InitializeEmptyExtensionService(); 2667 InitializeEmptyExtensionService();
2669 EXPECT_TRUE(service_->extensions()->is_empty()); 2668 EXPECT_TRUE(service_->extensions()->is_empty());
2670 2669
2671 int pref_count = 0; 2670 int pref_count = GetPrefKeyCount();
2672 2671
2673 const Extension* extension = 2672 const Extension* extension =
2674 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2673 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
2675 ValidatePrefKeyCount(++pref_count); 2674 ValidatePrefKeyCount(++pref_count);
2676 ASSERT_EQ(1u, service_->extensions()->size()); 2675 ASSERT_EQ(1u, service_->extensions()->size());
2677 EXPECT_TRUE(extension->is_app()); 2676 EXPECT_TRUE(extension->is_app());
2678 const std::string id1 = extension->id(); 2677 const std::string id1 = extension->id();
2679 const GURL origin1( 2678 const GURL origin1(
2680 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 2679 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2681 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2680 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
(...skipping 18 matching lines...) Expand all
2700 EXPECT_TRUE(service_->extensions()->is_empty()); 2699 EXPECT_TRUE(service_->extensions()->is_empty());
2701 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2700 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
2702 IsStorageProtected(origin1)); 2701 IsStorageProtected(origin1));
2703 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2702 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
2704 IsStorageProtected(origin2)); 2703 IsStorageProtected(origin2));
2705 } 2704 }
2706 2705
2707 // Test that when an extension version is reinstalled, nothing happens. 2706 // Test that when an extension version is reinstalled, nothing happens.
2708 TEST_F(ExtensionServiceTest, Reinstall) { 2707 TEST_F(ExtensionServiceTest, Reinstall) {
2709 InitializeEmptyExtensionService(); 2708 InitializeEmptyExtensionService();
2709 int pref_count = GetPrefKeyCount();
2710 2710
2711 // A simple extension that should install without error. 2711 // A simple extension that should install without error.
2712 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2712 base::FilePath path = data_dir_.AppendASCII("good.crx");
2713 InstallCRX(path, INSTALL_NEW); 2713 InstallCRX(path, INSTALL_NEW);
2714 2714
2715 ValidatePrefKeyCount(1); 2715 ValidatePrefKeyCount(++pref_count);
2716 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2716 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2717 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 2717 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
2718 2718
2719 // Reinstall the same version, it should overwrite the previous one. 2719 // Reinstall the same version, it should overwrite the previous one.
2720 InstallCRX(path, INSTALL_UPDATED); 2720 InstallCRX(path, INSTALL_UPDATED);
2721 2721
2722 ValidatePrefKeyCount(1); 2722 ValidatePrefKeyCount(pref_count);
2723 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 2723 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
2724 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 2724 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
2725 } 2725 }
2726 2726
2727 // Test that we can determine if extensions came from the 2727 // Test that we can determine if extensions came from the
2728 // Chrome web store. 2728 // Chrome web store.
2729 TEST_F(ExtensionServiceTest, FromWebStore) { 2729 TEST_F(ExtensionServiceTest, FromWebStore) {
2730 InitializeEmptyExtensionService(); 2730 InitializeEmptyExtensionService();
2731 int pref_count = GetPrefKeyCount();
2731 2732
2732 // A simple extension that should install without error. 2733 // A simple extension that should install without error.
2733 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2734 base::FilePath path = data_dir_.AppendASCII("good.crx");
2734 // Not from web store. 2735 // Not from web store.
2735 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2736 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2736 std::string id = extension->id(); 2737 std::string id = extension->id();
2737 2738
2738 ValidatePrefKeyCount(1); 2739 ValidatePrefKeyCount(++pref_count);
2739 ValidateBooleanPref(good_crx, "from_webstore", false); 2740 ValidateBooleanPref(good_crx, "from_webstore", false);
2740 ASSERT_FALSE(extension->from_webstore()); 2741 ASSERT_FALSE(extension->from_webstore());
2741 2742
2742 // Test install from web store. 2743 // Test install from web store.
2743 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. 2744 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store.
2744 2745
2745 ValidatePrefKeyCount(1); 2746 ValidatePrefKeyCount(pref_count);
2746 ValidateBooleanPref(good_crx, "from_webstore", true); 2747 ValidateBooleanPref(good_crx, "from_webstore", true);
2747 2748
2748 // Reload so extension gets reinitialized with new value. 2749 // Reload so extension gets reinitialized with new value.
2749 service_->ReloadExtensions(); 2750 service_->ReloadExtensions();
2750 extension = service_->GetExtensionById(id, false); 2751 extension = service_->GetExtensionById(id, false);
2751 ASSERT_TRUE(extension->from_webstore()); 2752 ASSERT_TRUE(extension->from_webstore());
2752 2753
2753 // Upgrade to version 2.0 2754 // Upgrade to version 2.0
2754 path = data_dir_.AppendASCII("good2.crx"); 2755 path = data_dir_.AppendASCII("good2.crx");
2755 UpdateExtension(good_crx, path, ENABLED); 2756 UpdateExtension(good_crx, path, ENABLED);
2756 ValidatePrefKeyCount(1); 2757 ValidatePrefKeyCount(pref_count);
2757 ValidateBooleanPref(good_crx, "from_webstore", true); 2758 ValidateBooleanPref(good_crx, "from_webstore", true);
2758 } 2759 }
2759 2760
2760 // Test upgrading a signed extension. 2761 // Test upgrading a signed extension.
2761 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { 2762 TEST_F(ExtensionServiceTest, UpgradeSignedGood) {
2762 InitializeEmptyExtensionService(); 2763 InitializeEmptyExtensionService();
2763 2764
2764 base::FilePath path = data_dir_.AppendASCII("good.crx"); 2765 base::FilePath path = data_dir_.AppendASCII("good.crx");
2765 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2766 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2766 std::string id = extension->id(); 2767 std::string id = extension->id();
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
4183 // Check that the LSO file has been removed. 4184 // Check that the LSO file has been removed.
4184 EXPECT_FALSE(base::PathExists(lso_file_path)); 4185 EXPECT_FALSE(base::PathExists(lso_file_path));
4185 4186
4186 // Check if the indexed db has disappeared too. 4187 // Check if the indexed db has disappeared too.
4187 EXPECT_FALSE(base::DirectoryExists(idb_path)); 4188 EXPECT_FALSE(base::DirectoryExists(idb_path));
4188 } 4189 }
4189 4190
4190 // Verifies app state is removed upon uninstall. 4191 // Verifies app state is removed upon uninstall.
4191 TEST_F(ExtensionServiceTest, ClearAppData) { 4192 TEST_F(ExtensionServiceTest, ClearAppData) {
4192 InitializeEmptyExtensionService(); 4193 InitializeEmptyExtensionService();
4194 int pref_count = GetPrefKeyCount();
4195
4193 ExtensionCookieCallback callback; 4196 ExtensionCookieCallback callback;
4194 4197
4195 int pref_count = 0;
4196
4197 // Install app1 with unlimited storage. 4198 // Install app1 with unlimited storage.
4198 const Extension* extension = 4199 const Extension* extension =
4199 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 4200 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
4200 ValidatePrefKeyCount(++pref_count); 4201 ValidatePrefKeyCount(++pref_count);
4201 ASSERT_EQ(1u, service_->extensions()->size()); 4202 ASSERT_EQ(1u, service_->extensions()->size());
4202 const std::string id1 = extension->id(); 4203 const std::string id1 = extension->id();
4203 EXPECT_TRUE(extension->HasAPIPermission( 4204 EXPECT_TRUE(extension->HasAPIPermission(
4204 APIPermission::kUnlimitedStorage)); 4205 APIPermission::kUnlimitedStorage));
4205 const GURL origin1( 4206 const GURL origin1(
4206 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); 4207 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
4317 EXPECT_FALSE(base::PathExists(lso_file_path)); 4318 EXPECT_FALSE(base::PathExists(lso_file_path));
4318 4319
4319 // Check if the indexed db has disappeared too. 4320 // Check if the indexed db has disappeared too.
4320 EXPECT_FALSE(base::DirectoryExists(idb_path)); 4321 EXPECT_FALSE(base::DirectoryExists(idb_path));
4321 } 4322 }
4322 4323
4323 // Tests loading single extensions (like --load-extension) 4324 // Tests loading single extensions (like --load-extension)
4324 // Flaky crashes. http://crbug.com/231806 4325 // Flaky crashes. http://crbug.com/231806
4325 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { 4326 TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
4326 InitializeEmptyExtensionService(); 4327 InitializeEmptyExtensionService();
4328 int pref_count = GetPrefKeyCount();
koz (OOO until 15th September) 2013/09/04 00:26:05 nit: here and elsewhere this would be better named
4327 4329
4328 base::FilePath ext1 = data_dir_ 4330 base::FilePath ext1 = data_dir_
4329 .AppendASCII("good") 4331 .AppendASCII("good")
4330 .AppendASCII("Extensions") 4332 .AppendASCII("Extensions")
4331 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 4333 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
4332 .AppendASCII("1.0.0.0"); 4334 .AppendASCII("1.0.0.0");
4333 extensions::UnpackedInstaller::Create(service_)->Load(ext1); 4335 extensions::UnpackedInstaller::Create(service_)->Load(ext1);
4334 base::RunLoop().RunUntilIdle(); 4336 base::RunLoop().RunUntilIdle();
4335 EXPECT_EQ(0u, GetErrors().size()); 4337 EXPECT_EQ(0u, GetErrors().size());
4336 ASSERT_EQ(1u, loaded_.size()); 4338 ASSERT_EQ(1u, loaded_.size());
4337 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); 4339 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
4338 EXPECT_EQ(1u, service_->extensions()->size()); 4340 EXPECT_EQ(1u, service_->extensions()->size());
4339 4341
4340 ValidatePrefKeyCount(1); 4342 ValidatePrefKeyCount(++pref_count);
4341 4343
4342 base::FilePath no_manifest = data_dir_ 4344 base::FilePath no_manifest = data_dir_
4343 .AppendASCII("bad") 4345 .AppendASCII("bad")
4344 // .AppendASCII("Extensions") 4346 // .AppendASCII("Extensions")
4345 .AppendASCII("cccccccccccccccccccccccccccccccc") 4347 .AppendASCII("cccccccccccccccccccccccccccccccc")
4346 .AppendASCII("1"); 4348 .AppendASCII("1");
4347 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); 4349 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest);
4348 base::RunLoop().RunUntilIdle(); 4350 base::RunLoop().RunUntilIdle();
4349 EXPECT_EQ(1u, GetErrors().size()); 4351 EXPECT_EQ(1u, GetErrors().size());
4350 ASSERT_EQ(1u, loaded_.size()); 4352 ASSERT_EQ(1u, loaded_.size());
4351 EXPECT_EQ(1u, service_->extensions()->size()); 4353 EXPECT_EQ(1u, service_->extensions()->size());
4352 4354
4353 // Test uninstall. 4355 // Test uninstall.
4354 std::string id = loaded_[0]->id(); 4356 std::string id = loaded_[0]->id();
4355 EXPECT_FALSE(unloaded_id_.length()); 4357 EXPECT_FALSE(unloaded_id_.length());
4356 service_->UninstallExtension(id, false, NULL); 4358 service_->UninstallExtension(id, false, NULL);
4357 base::RunLoop().RunUntilIdle(); 4359 base::RunLoop().RunUntilIdle();
4358 EXPECT_EQ(id, unloaded_id_); 4360 EXPECT_EQ(id, unloaded_id_);
4359 ASSERT_EQ(0u, loaded_.size()); 4361 ASSERT_EQ(0u, loaded_.size());
4360 EXPECT_EQ(0u, service_->extensions()->size()); 4362 EXPECT_EQ(0u, service_->extensions()->size());
4361 } 4363 }
4362 4364
4363 // Tests that we generate IDs when they are not specified in the manifest for 4365 // Tests that we generate IDs when they are not specified in the manifest for
4364 // --load-extension. 4366 // --load-extension.
4365 TEST_F(ExtensionServiceTest, GenerateID) { 4367 TEST_F(ExtensionServiceTest, GenerateID) {
4366 InitializeEmptyExtensionService(); 4368 InitializeEmptyExtensionService();
4369 int pref_count = GetPrefKeyCount();
4367 4370
4368 base::FilePath no_id_ext = data_dir_.AppendASCII("no_id"); 4371 base::FilePath no_id_ext = data_dir_.AppendASCII("no_id");
4369 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4372 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
4370 base::RunLoop().RunUntilIdle(); 4373 base::RunLoop().RunUntilIdle();
4371 EXPECT_EQ(0u, GetErrors().size()); 4374 EXPECT_EQ(0u, GetErrors().size());
4372 ASSERT_EQ(1u, loaded_.size()); 4375 ASSERT_EQ(1u, loaded_.size());
4373 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 4376 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
4374 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); 4377 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
4375 4378
4376 ValidatePrefKeyCount(1); 4379 ValidatePrefKeyCount(++pref_count);
4377 4380
4378 std::string previous_id = loaded_[0]->id(); 4381 std::string previous_id = loaded_[0]->id();
4379 4382
4380 // If we reload the same path, we should get the same extension ID. 4383 // If we reload the same path, we should get the same extension ID.
4381 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4384 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
4382 base::RunLoop().RunUntilIdle(); 4385 base::RunLoop().RunUntilIdle();
4383 ASSERT_EQ(1u, loaded_.size()); 4386 ASSERT_EQ(1u, loaded_.size());
4384 ASSERT_EQ(previous_id, loaded_[0]->id()); 4387 ASSERT_EQ(previous_id, loaded_[0]->id());
4385 } 4388 }
4386 4389
4387 void ExtensionServiceTest::TestExternalProvider( 4390 void ExtensionServiceTest::TestExternalProvider(
4388 MockExtensionProvider* provider, Manifest::Location location) { 4391 MockExtensionProvider* provider, Manifest::Location location) {
4389 // Verify that starting with no providers loads no extensions. 4392 // Verify that starting with no providers loads no extensions.
4390 service_->Init(); 4393 service_->Init();
4391 ASSERT_EQ(0u, loaded_.size()); 4394 ASSERT_EQ(0u, loaded_.size());
4392 4395
4396 int pref_count = GetPrefKeyCount();
4397
4393 provider->set_visit_count(0); 4398 provider->set_visit_count(0);
4394 4399
4395 // Register a test extension externally using the mock registry provider. 4400 // Register a test extension externally using the mock registry provider.
4396 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4401 base::FilePath source_path = data_dir_.AppendASCII("good.crx");
4397 4402
4398 // Add the extension. 4403 // Add the extension.
4399 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4404 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4400 4405
4401 // Reloading extensions should find our externally registered extension 4406 // Reloading extensions should find our externally registered extension
4402 // and install it. 4407 // and install it.
4403 service_->CheckForExternalUpdates(); 4408 service_->CheckForExternalUpdates();
4404 content::WindowedNotificationObserver( 4409 content::WindowedNotificationObserver(
4405 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4410 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4406 content::NotificationService::AllSources()).Wait(); 4411 content::NotificationService::AllSources()).Wait();
4407 4412
4408 ASSERT_EQ(0u, GetErrors().size()); 4413 ASSERT_EQ(0u, GetErrors().size());
4409 ASSERT_EQ(1u, loaded_.size()); 4414 ASSERT_EQ(1u, loaded_.size());
4410 ASSERT_EQ(location, loaded_[0]->location()); 4415 ASSERT_EQ(location, loaded_[0]->location());
4411 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4416 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4412 ValidatePrefKeyCount(1); 4417 ValidatePrefKeyCount(++pref_count);
4413 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4418 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4414 ValidateIntegerPref(good_crx, "location", location); 4419 ValidateIntegerPref(good_crx, "location", location);
4415 4420
4416 // Reload extensions without changing anything. The extension should be 4421 // Reload extensions without changing anything. The extension should be
4417 // loaded again. 4422 // loaded again.
4418 loaded_.clear(); 4423 loaded_.clear();
4419 service_->ReloadExtensions(); 4424 service_->ReloadExtensions();
4420 base::RunLoop().RunUntilIdle(); 4425 base::RunLoop().RunUntilIdle();
4421 ASSERT_EQ(0u, GetErrors().size()); 4426 ASSERT_EQ(0u, GetErrors().size());
4422 ASSERT_EQ(1u, loaded_.size()); 4427 ASSERT_EQ(1u, loaded_.size());
4423 ValidatePrefKeyCount(1); 4428 ValidatePrefKeyCount(pref_count);
4424 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4429 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4425 ValidateIntegerPref(good_crx, "location", location); 4430 ValidateIntegerPref(good_crx, "location", location);
4426 4431
4427 // Now update the extension with a new version. We should get upgraded. 4432 // Now update the extension with a new version. We should get upgraded.
4428 source_path = source_path.DirName().AppendASCII("good2.crx"); 4433 source_path = source_path.DirName().AppendASCII("good2.crx");
4429 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4434 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4430 4435
4431 loaded_.clear(); 4436 loaded_.clear();
4432 service_->CheckForExternalUpdates(); 4437 service_->CheckForExternalUpdates();
4433 content::WindowedNotificationObserver( 4438 content::WindowedNotificationObserver(
4434 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4439 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4435 content::NotificationService::AllSources()).Wait(); 4440 content::NotificationService::AllSources()).Wait();
4436 ASSERT_EQ(0u, GetErrors().size()); 4441 ASSERT_EQ(0u, GetErrors().size());
4437 ASSERT_EQ(1u, loaded_.size()); 4442 ASSERT_EQ(1u, loaded_.size());
4438 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4443 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4439 ValidatePrefKeyCount(1); 4444 ValidatePrefKeyCount(pref_count);
4440 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4445 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4441 ValidateIntegerPref(good_crx, "location", location); 4446 ValidateIntegerPref(good_crx, "location", location);
4442 4447
4443 // Uninstall the extension and reload. Nothing should happen because the 4448 // Uninstall the extension and reload. Nothing should happen because the
4444 // preference should prevent us from reinstalling. 4449 // preference should prevent us from reinstalling.
4445 std::string id = loaded_[0]->id(); 4450 std::string id = loaded_[0]->id();
4446 bool no_uninstall = 4451 bool no_uninstall =
4447 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); 4452 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL);
4448 service_->UninstallExtension(id, false, NULL); 4453 service_->UninstallExtension(id, false, NULL);
4449 base::RunLoop().RunUntilIdle(); 4454 base::RunLoop().RunUntilIdle();
4450 4455
4451 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); 4456 base::FilePath install_path = extensions_install_dir_.AppendASCII(id);
4452 if (no_uninstall) { 4457 if (no_uninstall) {
4453 // Policy controlled extensions should not have been touched by uninstall. 4458 // Policy controlled extensions should not have been touched by uninstall.
4454 ASSERT_TRUE(base::PathExists(install_path)); 4459 ASSERT_TRUE(base::PathExists(install_path));
4455 } else { 4460 } else {
4456 // The extension should also be gone from the install directory. 4461 // The extension should also be gone from the install directory.
4457 ASSERT_FALSE(base::PathExists(install_path)); 4462 ASSERT_FALSE(base::PathExists(install_path));
4458 loaded_.clear(); 4463 loaded_.clear();
4459 service_->CheckForExternalUpdates(); 4464 service_->CheckForExternalUpdates();
4460 base::RunLoop().RunUntilIdle(); 4465 base::RunLoop().RunUntilIdle();
4461 ASSERT_EQ(0u, loaded_.size()); 4466 ASSERT_EQ(0u, loaded_.size());
4462 ValidatePrefKeyCount(1); 4467 ValidatePrefKeyCount(pref_count);
4463 ValidateIntegerPref(good_crx, "state", 4468 ValidateIntegerPref(good_crx, "state",
4464 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4469 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4465 ValidateIntegerPref(good_crx, "location", location); 4470 ValidateIntegerPref(good_crx, "location", location);
4466 4471
4467 // Now clear the preference and reinstall. 4472 // Now clear the preference and reinstall.
4468 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4473 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4469 4474
4470 loaded_.clear(); 4475 loaded_.clear();
4471 service_->CheckForExternalUpdates(); 4476 service_->CheckForExternalUpdates();
4472 content::WindowedNotificationObserver( 4477 content::WindowedNotificationObserver(
4473 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4478 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4474 content::NotificationService::AllSources()).Wait(); 4479 content::NotificationService::AllSources()).Wait();
4475 ASSERT_EQ(1u, loaded_.size()); 4480 ASSERT_EQ(1u, loaded_.size());
4476 } 4481 }
4477 ValidatePrefKeyCount(1); 4482 ValidatePrefKeyCount(pref_count);
4478 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4483 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4479 ValidateIntegerPref(good_crx, "location", location); 4484 ValidateIntegerPref(good_crx, "location", location);
4480 4485
4481 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { 4486 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) {
4482 EXPECT_EQ(2, provider->visit_count()); 4487 EXPECT_EQ(2, provider->visit_count());
4483 } else { 4488 } else {
4484 // Now test an externally triggered uninstall (deleting the registry key or 4489 // Now test an externally triggered uninstall (deleting the registry key or
4485 // the pref entry). 4490 // the pref entry).
4486 provider->RemoveExtension(good_crx); 4491 provider->RemoveExtension(good_crx);
4487 4492
4488 loaded_.clear(); 4493 loaded_.clear();
4489 service_->OnExternalProviderReady(provider); 4494 service_->OnExternalProviderReady(provider);
4490 base::RunLoop().RunUntilIdle(); 4495 base::RunLoop().RunUntilIdle();
4491 ASSERT_EQ(0u, loaded_.size()); 4496 ASSERT_EQ(0u, loaded_.size());
4492 ValidatePrefKeyCount(0); 4497 ValidatePrefKeyCount(--pref_count);
4493 4498
4494 // The extension should also be gone from the install directory. 4499 // The extension should also be gone from the install directory.
4495 ASSERT_FALSE(base::PathExists(install_path)); 4500 ASSERT_FALSE(base::PathExists(install_path));
4496 4501
4497 // Now test the case where user uninstalls and then the extension is removed 4502 // Now test the case where user uninstalls and then the extension is removed
4498 // from the external provider. 4503 // from the external provider.
4499 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4504 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4500 service_->CheckForExternalUpdates(); 4505 service_->CheckForExternalUpdates();
4501 content::WindowedNotificationObserver( 4506 content::WindowedNotificationObserver(
4502 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4507 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4503 content::NotificationService::AllSources()).Wait(); 4508 content::NotificationService::AllSources()).Wait();
4504 4509
4505 ASSERT_EQ(1u, loaded_.size()); 4510 ASSERT_EQ(1u, loaded_.size());
4506 ASSERT_EQ(0u, GetErrors().size()); 4511 ASSERT_EQ(0u, GetErrors().size());
4507 4512
4508 // User uninstalls. 4513 // User uninstalls.
4509 loaded_.clear(); 4514 loaded_.clear();
4510 service_->UninstallExtension(id, false, NULL); 4515 service_->UninstallExtension(id, false, NULL);
4511 base::RunLoop().RunUntilIdle(); 4516 base::RunLoop().RunUntilIdle();
4512 ASSERT_EQ(0u, loaded_.size()); 4517 ASSERT_EQ(0u, loaded_.size());
4513 4518
4514 // Then remove the extension from the extension provider. 4519 // Then remove the extension from the extension provider.
4515 provider->RemoveExtension(good_crx); 4520 provider->RemoveExtension(good_crx);
4516 4521
4517 // Should still be at 0. 4522 // Should still be at 0.
4518 loaded_.clear(); 4523 loaded_.clear();
4519 extensions::InstalledLoader(service_).LoadAllExtensions(); 4524 extensions::InstalledLoader(service_).LoadAllExtensions();
4520 base::RunLoop().RunUntilIdle(); 4525 base::RunLoop().RunUntilIdle();
4521 ASSERT_EQ(0u, loaded_.size()); 4526 ASSERT_EQ(0u, loaded_.size());
4522 ValidatePrefKeyCount(1); 4527 ValidatePrefKeyCount(++pref_count);
4523 4528
4524 EXPECT_EQ(5, provider->visit_count()); 4529 EXPECT_EQ(5, provider->visit_count());
4525 } 4530 }
4526 } 4531 }
4527 4532
4528 // Tests the external installation feature 4533 // Tests the external installation feature
4529 #if defined(OS_WIN) 4534 #if defined(OS_WIN)
4530 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 4535 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
4531 // This should all work, even when normal extension installation is disabled. 4536 // This should all work, even when normal extension installation is disabled.
4532 InitializeEmptyExtensionService(); 4537 InitializeEmptyExtensionService();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4615 base::RunLoop().RunUntilIdle(); 4620 base::RunLoop().RunUntilIdle();
4616 4621
4617 ASSERT_EQ(0u, GetErrors().size()); 4622 ASSERT_EQ(0u, GetErrors().size());
4618 ASSERT_EQ(0u, loaded_.size()); 4623 ASSERT_EQ(0u, loaded_.size());
4619 } 4624 }
4620 4625
4621 // Test that running multiple update checks simultaneously does not 4626 // Test that running multiple update checks simultaneously does not
4622 // keep the update from succeeding. 4627 // keep the update from succeeding.
4623 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { 4628 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
4624 InitializeEmptyExtensionService(); 4629 InitializeEmptyExtensionService();
4630 int pref_count = GetPrefKeyCount();
4625 4631
4626 MockExtensionProvider* provider = 4632 MockExtensionProvider* provider =
4627 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 4633 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
4628 AddMockExternalProvider(provider); 4634 AddMockExternalProvider(provider);
4629 4635
4630 // Verify that starting with no providers loads no extensions. 4636 // Verify that starting with no providers loads no extensions.
4631 service_->Init(); 4637 service_->Init();
4632 ASSERT_EQ(0u, loaded_.size()); 4638 ASSERT_EQ(0u, loaded_.size());
4633 4639
4634 // Start two checks for updates. 4640 // Start two checks for updates.
(...skipping 17 matching lines...) Expand all
4652 service_->CheckForExternalUpdates(); 4658 service_->CheckForExternalUpdates();
4653 service_->CheckForExternalUpdates(); 4659 service_->CheckForExternalUpdates();
4654 content::WindowedNotificationObserver( 4660 content::WindowedNotificationObserver(
4655 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4661 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4656 content::NotificationService::AllSources()).Wait(); 4662 content::NotificationService::AllSources()).Wait();
4657 EXPECT_EQ(2, provider->visit_count()); 4663 EXPECT_EQ(2, provider->visit_count());
4658 ASSERT_EQ(0u, GetErrors().size()); 4664 ASSERT_EQ(0u, GetErrors().size());
4659 ASSERT_EQ(1u, loaded_.size()); 4665 ASSERT_EQ(1u, loaded_.size());
4660 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); 4666 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
4661 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4667 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4662 ValidatePrefKeyCount(1); 4668 ValidatePrefKeyCount(++pref_count);
4663 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4669 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4664 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); 4670 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
4665 4671
4666 provider->RemoveExtension(good_crx); 4672 provider->RemoveExtension(good_crx);
4667 provider->set_visit_count(0); 4673 provider->set_visit_count(0);
4668 service_->CheckForExternalUpdates(); 4674 service_->CheckForExternalUpdates();
4669 service_->CheckForExternalUpdates(); 4675 service_->CheckForExternalUpdates();
4670 base::RunLoop().RunUntilIdle(); 4676 base::RunLoop().RunUntilIdle();
4671 4677
4672 // Two calls should cause two checks for external extensions. 4678 // Two calls should cause two checks for external extensions.
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
5032 loaded_[0]->url())); 5038 loaded_[0]->url()));
5033 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5039 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5034 loaded_[1]->url())); 5040 loaded_[1]->url()));
5035 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 5041 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5036 loaded_[2]->url())); 5042 loaded_[2]->url()));
5037 } 5043 }
5038 5044
5039 // Tests ComponentLoader::Add(). 5045 // Tests ComponentLoader::Add().
5040 TEST_F(ExtensionServiceTest, ComponentExtensions) { 5046 TEST_F(ExtensionServiceTest, ComponentExtensions) {
5041 InitializeEmptyExtensionService(); 5047 InitializeEmptyExtensionService();
5048 int pref_count = GetPrefKeyCount();
5042 5049
5043 // Component extensions should work even when extensions are disabled. 5050 // Component extensions should work even when extensions are disabled.
5044 set_extensions_enabled(false); 5051 set_extensions_enabled(false);
5045 5052
5046 base::FilePath path = data_dir_ 5053 base::FilePath path = data_dir_
5047 .AppendASCII("good") 5054 .AppendASCII("good")
5048 .AppendASCII("Extensions") 5055 .AppendASCII("Extensions")
5049 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 5056 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
5050 .AppendASCII("1.0.0.0"); 5057 .AppendASCII("1.0.0.0");
5051 5058
5052 std::string manifest; 5059 std::string manifest;
5053 ASSERT_TRUE(file_util::ReadFileToString( 5060 ASSERT_TRUE(file_util::ReadFileToString(
5054 path.Append(extensions::kManifestFilename), &manifest)); 5061 path.Append(extensions::kManifestFilename), &manifest));
5055 5062
5056 service_->component_loader()->Add(manifest, path); 5063 service_->component_loader()->Add(manifest, path);
5057 service_->Init(); 5064 service_->Init();
5058 5065
5059 // Note that we do not pump messages -- the extension should be loaded 5066 // Note that we do not pump messages -- the extension should be loaded
5060 // immediately. 5067 // immediately.
5061 5068
5062 EXPECT_EQ(0u, GetErrors().size()); 5069 EXPECT_EQ(0u, GetErrors().size());
5063 ASSERT_EQ(1u, loaded_.size()); 5070 ASSERT_EQ(1u, loaded_.size());
5064 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); 5071 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location());
5065 EXPECT_EQ(1u, service_->extensions()->size()); 5072 EXPECT_EQ(1u, service_->extensions()->size());
5066 5073
5067 // Component extensions get a prefs entry on first install. 5074 // Component extensions get a prefs entry on first install.
5068 ValidatePrefKeyCount(1); 5075 ValidatePrefKeyCount(++pref_count);
5069 5076
5070 // Reload all extensions, and make sure it comes back. 5077 // Reload all extensions, and make sure it comes back.
5071 std::string extension_id = (*service_->extensions()->begin())->id(); 5078 std::string extension_id = (*service_->extensions()->begin())->id();
5072 loaded_.clear(); 5079 loaded_.clear();
5073 service_->ReloadExtensions(); 5080 service_->ReloadExtensions();
5074 ASSERT_EQ(1u, service_->extensions()->size()); 5081 ASSERT_EQ(1u, service_->extensions()->size());
5075 EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id()); 5082 EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id());
5076 } 5083 }
5077 5084
5078 namespace { 5085 namespace {
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
5728 GetById(good_crx))); 5735 GetById(good_crx)));
5729 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); 5736 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec());
5730 EXPECT_TRUE(info->is_from_sync()); 5737 EXPECT_TRUE(info->is_from_sync());
5731 EXPECT_TRUE(info->install_silently()); 5738 EXPECT_TRUE(info->install_silently());
5732 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); 5739 EXPECT_EQ(Manifest::INTERNAL, info->install_source());
5733 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. 5740 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
5734 } 5741 }
5735 5742
5736 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { 5743 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
5737 InitializeEmptyExtensionService(); 5744 InitializeEmptyExtensionService();
5745 int pref_count = GetPrefKeyCount();
5738 5746
5739 base::FilePath path = data_dir_.AppendASCII("good.crx"); 5747 base::FilePath path = data_dir_.AppendASCII("good.crx");
5740 InstallCRX(path, INSTALL_NEW); 5748 InstallCRX(path, INSTALL_NEW);
5741 ValidatePrefKeyCount(1u); 5749 ValidatePrefKeyCount(++pref_count);
5742 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 5750 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
5743 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 5751 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
5744 5752
5745 extensions::PendingExtensionManager* pending = 5753 extensions::PendingExtensionManager* pending =
5746 service_->pending_extension_manager(); 5754 service_->pending_extension_manager();
5747 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5755 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5748 5756
5749 // Skip install when the location is the same. 5757 // Skip install when the location is the same.
5750 EXPECT_FALSE( 5758 EXPECT_FALSE(
5751 service_->OnExternalExtensionUpdateUrlFound( 5759 service_->OnExternalExtensionUpdateUrlFound(
(...skipping 29 matching lines...) Expand all
5781 Version newer_version("2.0.0.0"); 5789 Version newer_version("2.0.0.0");
5782 5790
5783 // We don't want the extension to be installed. A path that doesn't 5791 // We don't want the extension to be installed. A path that doesn't
5784 // point to a valid CRX ensures this. 5792 // point to a valid CRX ensures this.
5785 const base::FilePath kInvalidPathToCrx = base::FilePath(); 5793 const base::FilePath kInvalidPathToCrx = base::FilePath();
5786 5794
5787 const int kCreationFlags = 0; 5795 const int kCreationFlags = 0;
5788 const bool kDontMarkAcknowledged = false; 5796 const bool kDontMarkAcknowledged = false;
5789 5797
5790 InitializeEmptyExtensionService(); 5798 InitializeEmptyExtensionService();
5799 int pref_count = GetPrefKeyCount();
5791 5800
5792 // The test below uses install source constants to test that 5801 // The test below uses install source constants to test that
5793 // priority is enforced. It assumes a specific ranking of install 5802 // priority is enforced. It assumes a specific ranking of install
5794 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref 5803 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref
5795 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). 5804 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL).
5796 // The following assertions verify these assumptions: 5805 // The following assertions verify these assumptions:
5797 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, 5806 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
5798 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 5807 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
5799 Manifest::EXTERNAL_PREF)); 5808 Manifest::EXTERNAL_PREF));
5800 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, 5809 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
5859 service_->OnExternalExtensionFileFound( 5868 service_->OnExternalExtensionFileFound(
5860 kGoodId, &older_version, kInvalidPathToCrx, 5869 kGoodId, &older_version, kInvalidPathToCrx,
5861 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); 5870 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged));
5862 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5871 EXPECT_TRUE(pending->IsIdPending(kGoodId));
5863 5872
5864 pending->Remove(kGoodId); 5873 pending->Remove(kGoodId);
5865 5874
5866 // Install the extension. 5875 // Install the extension.
5867 base::FilePath path = data_dir_.AppendASCII("good.crx"); 5876 base::FilePath path = data_dir_.AppendASCII("good.crx");
5868 const Extension* ext = InstallCRX(path, INSTALL_NEW); 5877 const Extension* ext = InstallCRX(path, INSTALL_NEW);
5869 ValidatePrefKeyCount(1u); 5878 ValidatePrefKeyCount(++pref_count);
5870 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 5879 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
5871 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 5880 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
5872 5881
5873 // Now test the logic of OnExternalExtensionFileFound() when the extension 5882 // Now test the logic of OnExternalExtensionFileFound() when the extension
5874 // being added is already installed. 5883 // being added is already installed.
5875 5884
5876 // Tests assume |older_version| is less than the installed version, and 5885 // Tests assume |older_version| is less than the installed version, and
5877 // |newer_version| is greater. Verify this: 5886 // |newer_version| is greater. Verify this:
5878 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); 5887 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString()));
5879 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); 5888 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString()));
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
6370 EXPECT_TRUE(notifications.CheckNotifications( 6379 EXPECT_TRUE(notifications.CheckNotifications(
6371 chrome::NOTIFICATION_EXTENSION_INSTALLED)); 6380 chrome::NOTIFICATION_EXTENSION_INSTALLED));
6372 6381
6373 EXPECT_TRUE(service_->GetInstalledExtension(id)); 6382 EXPECT_TRUE(service_->GetInstalledExtension(id));
6374 EXPECT_FALSE(service_->extensions()->Contains(id)); 6383 EXPECT_FALSE(service_->extensions()->Contains(id));
6375 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); 6384 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id));
6376 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); 6385 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id));
6377 EXPECT_TRUE( 6386 EXPECT_TRUE(
6378 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); 6387 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id));
6379 } 6388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698