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

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

Issue 425303002: Move extension notifications to extensions/browser/notification_types.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (extension-notifications) rebase Created 6 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 | Annotate | Revision Log
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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 public: 463 public:
464 ExtensionServiceTest() 464 ExtensionServiceTest()
465 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED), 465 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED),
466 installed_(NULL), 466 installed_(NULL),
467 was_update_(false), 467 was_update_(false),
468 override_external_install_prompt_( 468 override_external_install_prompt_(
469 FeatureSwitch::prompt_for_external_extensions(), 469 FeatureSwitch::prompt_for_external_extensions(),
470 false), 470 false),
471 expected_extensions_count_(0) { 471 expected_extensions_count_(0) {
472 registrar_.Add(this, 472 registrar_.Add(this,
473 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 473 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
474 content::NotificationService::AllSources());
475 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
476 content::NotificationService::AllSources()); 474 content::NotificationService::AllSources());
477 registrar_.Add(this, 475 registrar_.Add(this,
478 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, 476 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
479 content::NotificationService::AllSources()); 477 content::NotificationService::AllSources());
478 registrar_.Add(
479 this,
480 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
481 content::NotificationService::AllSources());
480 } 482 }
481 483
482 virtual void Observe(int type, 484 virtual void Observe(int type,
483 const content::NotificationSource& source, 485 const content::NotificationSource& source,
484 const content::NotificationDetails& details) OVERRIDE { 486 const content::NotificationDetails& details) OVERRIDE {
485 switch (type) { 487 switch (type) {
486 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { 488 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
487 const Extension* extension = 489 const Extension* extension =
488 content::Details<const Extension>(details).ptr(); 490 content::Details<const Extension>(details).ptr();
489 loaded_.push_back(make_scoped_refptr(extension)); 491 loaded_.push_back(make_scoped_refptr(extension));
490 // The tests rely on the errors being in a certain order, which can vary 492 // The tests rely on the errors being in a certain order, which can vary
491 // depending on how filesystem iteration works. 493 // depending on how filesystem iteration works.
492 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); 494 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder());
493 break; 495 break;
494 } 496 }
495 497
496 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { 498 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
497 UnloadedExtensionInfo* unloaded_info = 499 UnloadedExtensionInfo* unloaded_info =
498 content::Details<UnloadedExtensionInfo>(details).ptr(); 500 content::Details<UnloadedExtensionInfo>(details).ptr();
499 const Extension* e = unloaded_info->extension; 501 const Extension* e = unloaded_info->extension;
500 unloaded_id_ = e->id(); 502 unloaded_id_ = e->id();
501 unloaded_reason_ = unloaded_info->reason; 503 unloaded_reason_ = unloaded_info->reason;
502 extensions::ExtensionList::iterator i = 504 extensions::ExtensionList::iterator i =
503 std::find(loaded_.begin(), loaded_.end(), e); 505 std::find(loaded_.begin(), loaded_.end(), e);
504 // TODO(erikkay) fix so this can be an assert. Right now the tests 506 // TODO(erikkay) fix so this can be an assert. Right now the tests
505 // are manually calling clear() on loaded_, so this isn't doable. 507 // are manually calling clear() on loaded_, so this isn't doable.
506 if (i == loaded_.end()) 508 if (i == loaded_.end())
507 return; 509 return;
508 loaded_.erase(i); 510 loaded_.erase(i);
509 break; 511 break;
510 } 512 }
511 case chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { 513 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
512 const extensions::InstalledExtensionInfo* installed_info = 514 const extensions::InstalledExtensionInfo* installed_info =
513 content::Details<const extensions::InstalledExtensionInfo>(details) 515 content::Details<const extensions::InstalledExtensionInfo>(details)
514 .ptr(); 516 .ptr();
515 installed_ = installed_info->extension; 517 installed_ = installed_info->extension;
516 was_update_ = installed_info->is_update; 518 was_update_ = installed_info->is_update;
517 old_name_ = installed_info->old_name; 519 old_name_ = installed_info->old_name;
518 break; 520 break;
519 } 521 }
520 522
521 default: 523 default:
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 Manifest::Location install_location, 660 Manifest::Location install_location,
659 InstallState install_state) { 661 InstallState install_state) {
660 EXPECT_TRUE(base::PathExists(crx_path)) 662 EXPECT_TRUE(base::PathExists(crx_path))
661 << "Path does not exist: "<< crx_path.value().c_str(); 663 << "Path does not exist: "<< crx_path.value().c_str();
662 // no client (silent install) 664 // no client (silent install)
663 scoped_refptr<CrxInstaller> installer( 665 scoped_refptr<CrxInstaller> installer(
664 CrxInstaller::CreateSilent(service())); 666 CrxInstaller::CreateSilent(service()));
665 installer->set_install_source(install_location); 667 installer->set_install_source(install_location);
666 668
667 content::WindowedNotificationObserver observer( 669 content::WindowedNotificationObserver observer(
668 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 670 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
669 content::NotificationService::AllSources()); 671 content::NotificationService::AllSources());
670 installer->InstallCrx(crx_path); 672 installer->InstallCrx(crx_path);
671 observer.Wait(); 673 observer.Wait();
672 674
673 return VerifyCrxInstall(crx_path, install_state); 675 return VerifyCrxInstall(crx_path, install_state);
674 } 676 }
675 677
676 // Verifies the result of a CRX installation. Used by InstallCRX. Set the 678 // Verifies the result of a CRX installation. Used by InstallCRX. Set the
677 // |install_state| to INSTALL_FAILED if the installation is expected to fail. 679 // |install_state| to INSTALL_FAILED if the installation is expected to fail.
678 // Returns an Extension pointer if the install succeeded, NULL otherwise. 680 // Returns an Extension pointer if the install succeeded, NULL otherwise.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 ASSERT_TRUE(base::CopyFile(in_path, path)); 786 ASSERT_TRUE(base::CopyFile(in_path, path));
785 787
786 int previous_enabled_extension_count = 788 int previous_enabled_extension_count =
787 registry()->enabled_extensions().size(); 789 registry()->enabled_extensions().size();
788 int previous_installed_extension_count = 790 int previous_installed_extension_count =
789 previous_enabled_extension_count + 791 previous_enabled_extension_count +
790 registry()->disabled_extensions().size(); 792 registry()->disabled_extensions().size();
791 793
792 extensions::CrxInstaller* installer = NULL; 794 extensions::CrxInstaller* installer = NULL;
793 content::WindowedNotificationObserver observer( 795 content::WindowedNotificationObserver observer(
794 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 796 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
795 base::Bind(&IsCrxInstallerDone, &installer)); 797 base::Bind(&IsCrxInstallerDone, &installer));
796 service()->UpdateExtension(id, path, true, &installer); 798 service()->UpdateExtension(id, path, true, &installer);
797 799
798 if (installer) 800 if (installer)
799 observer.Wait(); 801 observer.Wait();
800 else 802 else
801 base::RunLoop().RunUntilIdle(); 803 base::RunLoop().RunUntilIdle();
802 804
803 std::vector<base::string16> errors = GetErrors(); 805 std::vector<base::string16> errors = GetErrors();
804 int error_count = errors.size(); 806 int error_count = errors.size();
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) { 1100 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) {
1099 ASSERT_TRUE(base::PathExists(crx_path)) 1101 ASSERT_TRUE(base::PathExists(crx_path))
1100 << "Path does not exist: "<< crx_path.value().c_str(); 1102 << "Path does not exist: "<< crx_path.value().c_str();
1101 scoped_refptr<CrxInstaller> installer( 1103 scoped_refptr<CrxInstaller> installer(
1102 CrxInstaller::CreateSilent(service())); 1104 CrxInstaller::CreateSilent(service()));
1103 installer->set_creation_flags(creation_flags); 1105 installer->set_creation_flags(creation_flags);
1104 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) 1106 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT))
1105 installer->set_allow_silent_install(true); 1107 installer->set_allow_silent_install(true);
1106 1108
1107 content::WindowedNotificationObserver observer( 1109 content::WindowedNotificationObserver observer(
1108 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1110 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1109 content::Source<extensions::CrxInstaller>(installer)); 1111 content::Source<extensions::CrxInstaller>(installer));
1110 1112
1111 installer->InstallCrx(crx_path); 1113 installer->InstallCrx(crx_path);
1112 1114
1113 observer.Wait(); 1115 observer.Wait();
1114 } 1116 }
1115 1117
1116 size_t expected_extensions_count_; 1118 size_t expected_extensions_count_;
1117 content::NotificationRegistrar registrar_; 1119 content::NotificationRegistrar registrar_;
1118 }; 1120 };
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 const char kPrefFromBookmark[] = "from_bookmark"; 1482 const char kPrefFromBookmark[] = "from_bookmark";
1481 1483
1482 InitializeEmptyExtensionService(); 1484 InitializeEmptyExtensionService();
1483 1485
1484 base::FilePath path = data_dir().AppendASCII("good.crx"); 1486 base::FilePath path = data_dir().AppendASCII("good.crx");
1485 service()->set_extensions_enabled(true); 1487 service()->set_extensions_enabled(true);
1486 1488
1487 // Register and install an external extension. 1489 // Register and install an external extension.
1488 Version version("1.0.0.0"); 1490 Version version("1.0.0.0");
1489 content::WindowedNotificationObserver observer( 1491 content::WindowedNotificationObserver observer(
1490 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1492 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1491 content::NotificationService::AllSources()); 1493 content::NotificationService::AllSources());
1492 if (service()->OnExternalExtensionFileFound(good_crx, 1494 if (service()->OnExternalExtensionFileFound(good_crx,
1493 &version, 1495 &version,
1494 path, 1496 path,
1495 Manifest::EXTERNAL_PREF, 1497 Manifest::EXTERNAL_PREF,
1496 Extension::FROM_BOOKMARK, 1498 Extension::FROM_BOOKMARK,
1497 false /* mark_acknowledged */)) { 1499 false /* mark_acknowledged */)) {
1498 observer.Wait(); 1500 observer.Wait();
1499 } 1501 }
1500 1502
(...skipping 14 matching lines...) Expand all
1515 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED 1517 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED
1516 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1518 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1517 InitializeEmptyExtensionService(); 1519 InitializeEmptyExtensionService();
1518 1520
1519 base::FilePath path = data_dir().AppendASCII("good.crx"); 1521 base::FilePath path = data_dir().AppendASCII("good.crx");
1520 service()->set_extensions_enabled(true); 1522 service()->set_extensions_enabled(true);
1521 1523
1522 // Install an external extension. 1524 // Install an external extension.
1523 Version version("1.0.0.0"); 1525 Version version("1.0.0.0");
1524 content::WindowedNotificationObserver observer( 1526 content::WindowedNotificationObserver observer(
1525 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1527 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1526 content::NotificationService::AllSources()); 1528 content::NotificationService::AllSources());
1527 if (service()->OnExternalExtensionFileFound(good_crx, 1529 if (service()->OnExternalExtensionFileFound(good_crx,
1528 &version, 1530 &version,
1529 path, 1531 path,
1530 Manifest::EXTERNAL_PREF, 1532 Manifest::EXTERNAL_PREF,
1531 Extension::NO_FLAGS, 1533 Extension::NO_FLAGS,
1532 false)) { 1534 false)) {
1533 observer.Wait(); 1535 observer.Wait();
1534 } 1536 }
1535 1537
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 1615
1614 Version version("1.0.0.0"); 1616 Version version("1.0.0.0");
1615 1617
1616 const std::string wrong_id = all_zero; 1618 const std::string wrong_id = all_zero;
1617 const std::string correct_id = good_crx; 1619 const std::string correct_id = good_crx;
1618 ASSERT_NE(correct_id, wrong_id); 1620 ASSERT_NE(correct_id, wrong_id);
1619 1621
1620 // Install an external extension with an ID from the external 1622 // Install an external extension with an ID from the external
1621 // source that is not equal to the ID in the extension manifest. 1623 // source that is not equal to the ID in the extension manifest.
1622 content::WindowedNotificationObserver observer( 1624 content::WindowedNotificationObserver observer(
1623 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1625 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1624 content::NotificationService::AllSources()); 1626 content::NotificationService::AllSources());
1625 service()->OnExternalExtensionFileFound(wrong_id, 1627 service()->OnExternalExtensionFileFound(wrong_id,
1626 &version, 1628 &version,
1627 path, 1629 path,
1628 Manifest::EXTERNAL_PREF, 1630 Manifest::EXTERNAL_PREF,
1629 Extension::NO_FLAGS, 1631 Extension::NO_FLAGS,
1630 false); 1632 false);
1631 1633
1632 observer.Wait(); 1634 observer.Wait();
1633 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1635 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1634 1636
1635 // Try again with the right ID. Expect success. 1637 // Try again with the right ID. Expect success.
1636 content::WindowedNotificationObserver observer2( 1638 content::WindowedNotificationObserver observer2(
1637 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1639 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1638 content::NotificationService::AllSources()); 1640 content::NotificationService::AllSources());
1639 if (service()->OnExternalExtensionFileFound(correct_id, 1641 if (service()->OnExternalExtensionFileFound(correct_id,
1640 &version, 1642 &version,
1641 path, 1643 path,
1642 Manifest::EXTERNAL_PREF, 1644 Manifest::EXTERNAL_PREF,
1643 Extension::NO_FLAGS, 1645 Extension::NO_FLAGS,
1644 false)) { 1646 false)) {
1645 observer2.Wait(); 1647 observer2.Wait();
1646 } 1648 }
1647 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1649 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1648 } 1650 }
1649 1651
1650 // Test that external extensions with incorrect versions are not installed. 1652 // Test that external extensions with incorrect versions are not installed.
1651 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1653 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1652 InitializeEmptyExtensionService(); 1654 InitializeEmptyExtensionService();
1653 base::FilePath path = data_dir().AppendASCII("good.crx"); 1655 base::FilePath path = data_dir().AppendASCII("good.crx");
1654 service()->set_extensions_enabled(true); 1656 service()->set_extensions_enabled(true);
1655 1657
1656 // Install an external extension with a version from the external 1658 // Install an external extension with a version from the external
1657 // source that is not equal to the version in the extension manifest. 1659 // source that is not equal to the version in the extension manifest.
1658 Version wrong_version("1.2.3.4"); 1660 Version wrong_version("1.2.3.4");
1659 content::WindowedNotificationObserver observer( 1661 content::WindowedNotificationObserver observer(
1660 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1662 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1661 content::NotificationService::AllSources()); 1663 content::NotificationService::AllSources());
1662 service()->OnExternalExtensionFileFound(good_crx, 1664 service()->OnExternalExtensionFileFound(good_crx,
1663 &wrong_version, 1665 &wrong_version,
1664 path, 1666 path,
1665 Manifest::EXTERNAL_PREF, 1667 Manifest::EXTERNAL_PREF,
1666 Extension::NO_FLAGS, 1668 Extension::NO_FLAGS,
1667 false); 1669 false);
1668 1670
1669 observer.Wait(); 1671 observer.Wait();
1670 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1672 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1671 1673
1672 // Try again with the right version. Expect success. 1674 // Try again with the right version. Expect success.
1673 service()->pending_extension_manager()->Remove(good_crx); 1675 service()->pending_extension_manager()->Remove(good_crx);
1674 Version correct_version("1.0.0.0"); 1676 Version correct_version("1.0.0.0");
1675 content::WindowedNotificationObserver observer2( 1677 content::WindowedNotificationObserver observer2(
1676 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 1678 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1677 content::NotificationService::AllSources()); 1679 content::NotificationService::AllSources());
1678 if (service()->OnExternalExtensionFileFound(good_crx, 1680 if (service()->OnExternalExtensionFileFound(good_crx,
1679 &correct_version, 1681 &correct_version,
1680 path, 1682 path,
1681 Manifest::EXTERNAL_PREF, 1683 Manifest::EXTERNAL_PREF,
1682 Extension::NO_FLAGS, 1684 Extension::NO_FLAGS,
1683 false)) { 1685 false)) {
1684 observer2.Wait(); 1686 observer2.Wait();
1685 } 1687 }
1686 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1688 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after
3675 // Have policy force-install an extension. 3677 // Have policy force-install an extension.
3676 MockExtensionProvider* provider = 3678 MockExtensionProvider* provider =
3677 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD); 3679 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
3678 AddMockExternalProvider(provider); 3680 AddMockExternalProvider(provider);
3679 provider->UpdateOrAddExtension( 3681 provider->UpdateOrAddExtension(
3680 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); 3682 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
3681 3683
3682 // Reloading extensions should find our externally registered extension 3684 // Reloading extensions should find our externally registered extension
3683 // and install it. 3685 // and install it.
3684 content::WindowedNotificationObserver observer( 3686 content::WindowedNotificationObserver observer(
3685 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3687 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
3686 content::NotificationService::AllSources()); 3688 content::NotificationService::AllSources());
3687 service()->CheckForExternalUpdates(); 3689 service()->CheckForExternalUpdates();
3688 observer.Wait(); 3690 observer.Wait();
3689 3691
3690 // Extension should be installed despite blacklist. 3692 // Extension should be installed despite blacklist.
3691 ASSERT_EQ(1u, registry()->enabled_extensions().size()); 3693 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3692 EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); 3694 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3693 3695
3694 // Blacklist update should not uninstall the extension. 3696 // Blacklist update should not uninstall the extension.
3695 { 3697 {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 MockExtensionProvider* provider = new MockExtensionProvider( 3873 MockExtensionProvider* provider = new MockExtensionProvider(
3872 service(), Manifest::EXTERNAL_POLICY_DOWNLOAD); 3874 service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
3873 AddMockExternalProvider(provider); 3875 AddMockExternalProvider(provider);
3874 provider->UpdateOrAddExtension( 3876 provider->UpdateOrAddExtension(
3875 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); 3877 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
3876 } 3878 }
3877 3879
3878 // Providers are set up. Let them run. 3880 // Providers are set up. Let them run.
3879 int count = 2; 3881 int count = 2;
3880 content::WindowedNotificationObserver observer( 3882 content::WindowedNotificationObserver observer(
3881 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3883 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
3882 base::Bind(&WaitForCountNotificationsCallback, &count)); 3884 base::Bind(&WaitForCountNotificationsCallback, &count));
3883 service()->CheckForExternalUpdates(); 3885 service()->CheckForExternalUpdates();
3884 3886
3885 observer.Wait(); 3887 observer.Wait();
3886 3888
3887 ASSERT_EQ(2u, registry()->enabled_extensions().size()); 3889 ASSERT_EQ(2u, registry()->enabled_extensions().size());
3888 EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); 3890 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3889 EXPECT_TRUE(service()->GetExtensionById(page_action, false)); 3891 EXPECT_TRUE(service()->GetExtensionById(page_action, false));
3890 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); 3892 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
3891 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); 3893 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
(...skipping 21 matching lines...) Expand all
3913 new extensions::ExternalTestingLoader(json_data, data_dir()), 3915 new extensions::ExternalTestingLoader(json_data, data_dir()),
3914 Manifest::INTERNAL, 3916 Manifest::INTERNAL,
3915 Manifest::INVALID_LOCATION, 3917 Manifest::INVALID_LOCATION,
3916 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); 3918 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
3917 3919
3918 AddMockExternalProvider(provider); 3920 AddMockExternalProvider(provider);
3919 } 3921 }
3920 3922
3921 ASSERT_EQ(0u, registry()->enabled_extensions().size()); 3923 ASSERT_EQ(0u, registry()->enabled_extensions().size());
3922 content::WindowedNotificationObserver observer( 3924 content::WindowedNotificationObserver observer(
3923 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 3925 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
3924 content::NotificationService::AllSources()); 3926 content::NotificationService::AllSources());
3925 service()->CheckForExternalUpdates(); 3927 service()->CheckForExternalUpdates();
3926 observer.Wait(); 3928 observer.Wait();
3927 3929
3928 ASSERT_EQ(1u, registry()->enabled_extensions().size()); 3930 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3929 EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); 3931 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3930 const Extension* extension = service()->GetExtensionById(good_crx, false); 3932 const Extension* extension = service()->GetExtensionById(good_crx, false);
3931 EXPECT_TRUE(extension->from_webstore()); 3933 EXPECT_TRUE(extension->from_webstore());
3932 EXPECT_TRUE(extension->was_installed_by_default()); 3934 EXPECT_TRUE(extension->was_installed_by_default());
3933 } 3935 }
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
4601 4603
4602 // Register a test extension externally using the mock registry provider. 4604 // Register a test extension externally using the mock registry provider.
4603 base::FilePath source_path = data_dir().AppendASCII("good.crx"); 4605 base::FilePath source_path = data_dir().AppendASCII("good.crx");
4604 4606
4605 // Add the extension. 4607 // Add the extension.
4606 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4608 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4607 4609
4608 // Reloading extensions should find our externally registered extension 4610 // Reloading extensions should find our externally registered extension
4609 // and install it. 4611 // and install it.
4610 content::WindowedNotificationObserver observer( 4612 content::WindowedNotificationObserver observer(
4611 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4613 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
4612 content::NotificationService::AllSources()); 4614 content::NotificationService::AllSources());
4613 service()->CheckForExternalUpdates(); 4615 service()->CheckForExternalUpdates();
4614 observer.Wait(); 4616 observer.Wait();
4615 4617
4616 ASSERT_EQ(0u, GetErrors().size()); 4618 ASSERT_EQ(0u, GetErrors().size());
4617 ASSERT_EQ(1u, loaded_.size()); 4619 ASSERT_EQ(1u, loaded_.size());
4618 ASSERT_EQ(location, loaded_[0]->location()); 4620 ASSERT_EQ(location, loaded_[0]->location());
4619 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4621 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4620 ValidatePrefKeyCount(1); 4622 ValidatePrefKeyCount(1);
4621 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4623 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4622 ValidateIntegerPref(good_crx, "location", location); 4624 ValidateIntegerPref(good_crx, "location", location);
4623 4625
4624 // Reload extensions without changing anything. The extension should be 4626 // Reload extensions without changing anything. The extension should be
4625 // loaded again. 4627 // loaded again.
4626 loaded_.clear(); 4628 loaded_.clear();
4627 service()->ReloadExtensionsForTest(); 4629 service()->ReloadExtensionsForTest();
4628 base::RunLoop().RunUntilIdle(); 4630 base::RunLoop().RunUntilIdle();
4629 ASSERT_EQ(0u, GetErrors().size()); 4631 ASSERT_EQ(0u, GetErrors().size());
4630 ASSERT_EQ(1u, loaded_.size()); 4632 ASSERT_EQ(1u, loaded_.size());
4631 ValidatePrefKeyCount(1); 4633 ValidatePrefKeyCount(1);
4632 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4634 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4633 ValidateIntegerPref(good_crx, "location", location); 4635 ValidateIntegerPref(good_crx, "location", location);
4634 4636
4635 // Now update the extension with a new version. We should get upgraded. 4637 // Now update the extension with a new version. We should get upgraded.
4636 source_path = source_path.DirName().AppendASCII("good2.crx"); 4638 source_path = source_path.DirName().AppendASCII("good2.crx");
4637 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4639 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4638 4640
4639 loaded_.clear(); 4641 loaded_.clear();
4640 content::WindowedNotificationObserver observer_2( 4642 content::WindowedNotificationObserver observer_2(
4641 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4643 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
4642 content::NotificationService::AllSources()); 4644 content::NotificationService::AllSources());
4643 service()->CheckForExternalUpdates(); 4645 service()->CheckForExternalUpdates();
4644 observer_2.Wait(); 4646 observer_2.Wait();
4645 ASSERT_EQ(0u, GetErrors().size()); 4647 ASSERT_EQ(0u, GetErrors().size());
4646 ASSERT_EQ(1u, loaded_.size()); 4648 ASSERT_EQ(1u, loaded_.size());
4647 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4649 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4648 ValidatePrefKeyCount(1); 4650 ValidatePrefKeyCount(1);
4649 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4651 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4650 ValidateIntegerPref(good_crx, "location", location); 4652 ValidateIntegerPref(good_crx, "location", location);
4651 4653
(...skipping 22 matching lines...) Expand all
4674 ValidatePrefKeyCount(1); 4676 ValidatePrefKeyCount(1);
4675 ValidateIntegerPref(good_crx, "state", 4677 ValidateIntegerPref(good_crx, "state",
4676 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4678 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4677 ValidateIntegerPref(good_crx, "location", location); 4679 ValidateIntegerPref(good_crx, "location", location);
4678 4680
4679 // Now clear the preference and reinstall. 4681 // Now clear the preference and reinstall.
4680 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4682 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4681 4683
4682 loaded_.clear(); 4684 loaded_.clear();
4683 content::WindowedNotificationObserver observer( 4685 content::WindowedNotificationObserver observer(
4684 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4686 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
4685 content::NotificationService::AllSources()); 4687 content::NotificationService::AllSources());
4686 service()->CheckForExternalUpdates(); 4688 service()->CheckForExternalUpdates();
4687 observer.Wait(); 4689 observer.Wait();
4688 ASSERT_EQ(1u, loaded_.size()); 4690 ASSERT_EQ(1u, loaded_.size());
4689 } 4691 }
4690 ValidatePrefKeyCount(1); 4692 ValidatePrefKeyCount(1);
4691 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4693 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4692 ValidateIntegerPref(good_crx, "location", location); 4694 ValidateIntegerPref(good_crx, "location", location);
4693 4695
4694 if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) { 4696 if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) {
4695 EXPECT_EQ(2, provider->visit_count()); 4697 EXPECT_EQ(2, provider->visit_count());
4696 } else { 4698 } else {
4697 // Now test an externally triggered uninstall (deleting the registry key or 4699 // Now test an externally triggered uninstall (deleting the registry key or
4698 // the pref entry). 4700 // the pref entry).
4699 provider->RemoveExtension(good_crx); 4701 provider->RemoveExtension(good_crx);
4700 4702
4701 loaded_.clear(); 4703 loaded_.clear();
4702 service()->OnExternalProviderReady(provider); 4704 service()->OnExternalProviderReady(provider);
4703 base::RunLoop().RunUntilIdle(); 4705 base::RunLoop().RunUntilIdle();
4704 ASSERT_EQ(0u, loaded_.size()); 4706 ASSERT_EQ(0u, loaded_.size());
4705 ValidatePrefKeyCount(0); 4707 ValidatePrefKeyCount(0);
4706 4708
4707 // The extension should also be gone from the install directory. 4709 // The extension should also be gone from the install directory.
4708 ASSERT_FALSE(base::PathExists(install_path)); 4710 ASSERT_FALSE(base::PathExists(install_path));
4709 4711
4710 // Now test the case where user uninstalls and then the extension is removed 4712 // Now test the case where user uninstalls and then the extension is removed
4711 // from the external provider. 4713 // from the external provider.
4712 content::WindowedNotificationObserver observer( 4714 content::WindowedNotificationObserver observer(
4713 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4715 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
4714 content::NotificationService::AllSources()); 4716 content::NotificationService::AllSources());
4715 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4717 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4716 service()->CheckForExternalUpdates(); 4718 service()->CheckForExternalUpdates();
4717 observer.Wait(); 4719 observer.Wait();
4718 4720
4719 ASSERT_EQ(1u, loaded_.size()); 4721 ASSERT_EQ(1u, loaded_.size());
4720 ASSERT_EQ(0u, GetErrors().size()); 4722 ASSERT_EQ(0u, GetErrors().size());
4721 4723
4722 // User uninstalls. 4724 // User uninstalls.
4723 loaded_.clear(); 4725 loaded_.clear();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4856 EXPECT_EQ(0u, GetErrors().size()); 4858 EXPECT_EQ(0u, GetErrors().size());
4857 EXPECT_EQ(0u, loaded_.size()); 4859 EXPECT_EQ(0u, loaded_.size());
4858 4860
4859 // Register a test extension externally using the mock registry provider. 4861 // Register a test extension externally using the mock registry provider.
4860 base::FilePath source_path = data_dir().AppendASCII("good.crx"); 4862 base::FilePath source_path = data_dir().AppendASCII("good.crx");
4861 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4863 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4862 4864
4863 // Two checks for external updates should find the extension, and install it 4865 // Two checks for external updates should find the extension, and install it
4864 // once. 4866 // once.
4865 content::WindowedNotificationObserver observer( 4867 content::WindowedNotificationObserver observer(
4866 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 4868 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
4867 content::NotificationService::AllSources()); 4869 content::NotificationService::AllSources());
4868 provider->set_visit_count(0); 4870 provider->set_visit_count(0);
4869 service()->CheckForExternalUpdates(); 4871 service()->CheckForExternalUpdates();
4870 service()->CheckForExternalUpdates(); 4872 service()->CheckForExternalUpdates();
4871 observer.Wait(); 4873 observer.Wait();
4872 EXPECT_EQ(2, provider->visit_count()); 4874 EXPECT_EQ(2, provider->visit_count());
4873 ASSERT_EQ(0u, GetErrors().size()); 4875 ASSERT_EQ(0u, GetErrors().size());
4874 ASSERT_EQ(1u, loaded_.size()); 4876 ASSERT_EQ(1u, loaded_.size());
4875 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); 4877 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
4876 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4878 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
5104 EXPECT_EQ("My name is simple.", loaded_[0]->name()); 5106 EXPECT_EQ("My name is simple.", loaded_[0]->name());
5105 5107
5106 // These are untouched by re-localization. 5108 // These are untouched by re-localization.
5107 EXPECT_EQ("My name is simple.", loaded_[1]->name()); 5109 EXPECT_EQ("My name is simple.", loaded_[1]->name());
5108 EXPECT_EQ("no l10n", loaded_[2]->name()); 5110 EXPECT_EQ("no l10n", loaded_[2]->name());
5109 } 5111 }
5110 5112
5111 class ExtensionsReadyRecorder : public content::NotificationObserver { 5113 class ExtensionsReadyRecorder : public content::NotificationObserver {
5112 public: 5114 public:
5113 ExtensionsReadyRecorder() : ready_(false) { 5115 ExtensionsReadyRecorder() : ready_(false) {
5114 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 5116 registrar_.Add(this,
5117 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
5115 content::NotificationService::AllSources()); 5118 content::NotificationService::AllSources());
5116 } 5119 }
5117 5120
5118 void set_ready(bool value) { ready_ = value; } 5121 void set_ready(bool value) { ready_ = value; }
5119 bool ready() { return ready_; } 5122 bool ready() { return ready_; }
5120 5123
5121 private: 5124 private:
5122 virtual void Observe(int type, 5125 virtual void Observe(int type,
5123 const content::NotificationSource& source, 5126 const content::NotificationSource& source,
5124 const content::NotificationDetails& details) OVERRIDE { 5127 const content::NotificationDetails& details) OVERRIDE {
5125 switch (type) { 5128 switch (type) {
5126 case chrome::NOTIFICATION_EXTENSIONS_READY: 5129 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
5127 ready_ = true; 5130 ready_ = true;
5128 break; 5131 break;
5129 default: 5132 default:
5130 NOTREACHED(); 5133 NOTREACHED();
5131 } 5134 }
5132 } 5135 }
5133 5136
5134 content::NotificationRegistrar registrar_; 5137 content::NotificationRegistrar registrar_;
5135 bool ready_; 5138 bool ready_;
5136 }; 5139 };
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
6246 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, 6249 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
6247 Manifest::INTERNAL)); 6250 Manifest::INTERNAL));
6248 6251
6249 extensions::PendingExtensionManager* pending = 6252 extensions::PendingExtensionManager* pending =
6250 service()->pending_extension_manager(); 6253 service()->pending_extension_manager();
6251 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6254 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6252 6255
6253 { 6256 {
6254 // Simulate an external source adding the extension as INTERNAL. 6257 // Simulate an external source adding the extension as INTERNAL.
6255 content::WindowedNotificationObserver observer( 6258 content::WindowedNotificationObserver observer(
6256 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6259 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6257 content::NotificationService::AllSources()); 6260 content::NotificationService::AllSources());
6258 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 6261 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6259 &older_version, 6262 &older_version,
6260 kInvalidPathToCrx, 6263 kInvalidPathToCrx,
6261 Manifest::INTERNAL, 6264 Manifest::INTERNAL,
6262 kCreationFlags, 6265 kCreationFlags,
6263 kDontMarkAcknowledged)); 6266 kDontMarkAcknowledged));
6264 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6267 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6265 observer.Wait(); 6268 observer.Wait();
6266 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6269 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6267 } 6270 }
6268 6271
6269 { 6272 {
6270 // Simulate an external source adding the extension as EXTERNAL_PREF. 6273 // Simulate an external source adding the extension as EXTERNAL_PREF.
6271 content::WindowedNotificationObserver observer( 6274 content::WindowedNotificationObserver observer(
6272 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6275 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6273 content::NotificationService::AllSources()); 6276 content::NotificationService::AllSources());
6274 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 6277 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6275 &older_version, 6278 &older_version,
6276 kInvalidPathToCrx, 6279 kInvalidPathToCrx,
6277 Manifest::EXTERNAL_PREF, 6280 Manifest::EXTERNAL_PREF,
6278 kCreationFlags, 6281 kCreationFlags,
6279 kDontMarkAcknowledged)); 6282 kDontMarkAcknowledged));
6280 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6283 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6281 observer.Wait(); 6284 observer.Wait();
6282 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6285 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
(...skipping 15 matching lines...) Expand all
6298 &older_version, 6301 &older_version,
6299 kInvalidPathToCrx, 6302 kInvalidPathToCrx,
6300 Manifest::INTERNAL, 6303 Manifest::INTERNAL,
6301 kCreationFlags, 6304 kCreationFlags,
6302 kDontMarkAcknowledged)); 6305 kDontMarkAcknowledged));
6303 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6306 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6304 6307
6305 { 6308 {
6306 // Now the registry adds the extension. 6309 // Now the registry adds the extension.
6307 content::WindowedNotificationObserver observer( 6310 content::WindowedNotificationObserver observer(
6308 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6311 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6309 content::NotificationService::AllSources()); 6312 content::NotificationService::AllSources());
6310 EXPECT_TRUE( 6313 EXPECT_TRUE(
6311 service()->OnExternalExtensionFileFound(kGoodId, 6314 service()->OnExternalExtensionFileFound(kGoodId,
6312 &older_version, 6315 &older_version,
6313 kInvalidPathToCrx, 6316 kInvalidPathToCrx,
6314 Manifest::EXTERNAL_REGISTRY, 6317 Manifest::EXTERNAL_REGISTRY,
6315 kCreationFlags, 6318 kCreationFlags,
6316 kDontMarkAcknowledged)); 6319 kDontMarkAcknowledged));
6317 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6320 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6318 observer.Wait(); 6321 observer.Wait();
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
6615 // Test that a pending request for installation of an external CRX from 6618 // Test that a pending request for installation of an external CRX from
6616 // an update URL overrides a pending request to install the same extension 6619 // an update URL overrides a pending request to install the same extension
6617 // from sync. 6620 // from sync.
6618 TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { 6621 TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) {
6619 InitializeEmptyExtensionService(); 6622 InitializeEmptyExtensionService();
6620 6623
6621 ASSERT_FALSE(IsCrxInstalled()); 6624 ASSERT_FALSE(IsCrxInstalled());
6622 6625
6623 // Install pending extension from sync. 6626 // Install pending extension from sync.
6624 content::WindowedNotificationObserver observer( 6627 content::WindowedNotificationObserver observer(
6625 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6628 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6626 content::NotificationService::AllSources()); 6629 content::NotificationService::AllSources());
6627 EXPECT_TRUE(AddPendingSyncInstall()); 6630 EXPECT_TRUE(AddPendingSyncInstall());
6628 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); 6631 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation());
6629 EXPECT_TRUE(GetPendingIsFromSync()); 6632 EXPECT_TRUE(GetPendingIsFromSync());
6630 ASSERT_FALSE(IsCrxInstalled()); 6633 ASSERT_FALSE(IsCrxInstalled());
6631 6634
6632 // Install pending as external prefs json would. 6635 // Install pending as external prefs json would.
6633 AddPendingExternalPrefFileInstall(); 6636 AddPendingExternalPrefFileInstall();
6634 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); 6637 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
6635 ASSERT_FALSE(IsCrxInstalled()); 6638 ASSERT_FALSE(IsCrxInstalled());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6674 6677
6675 // External prefs starts an install. 6678 // External prefs starts an install.
6676 AddPendingExternalPrefFileInstall(); 6679 AddPendingExternalPrefFileInstall();
6677 6680
6678 // Crx installer was made, but has not yet run. 6681 // Crx installer was made, but has not yet run.
6679 ASSERT_FALSE(IsCrxInstalled()); 6682 ASSERT_FALSE(IsCrxInstalled());
6680 6683
6681 // Before the CRX installer runs, Sync requests that the same extension 6684 // Before the CRX installer runs, Sync requests that the same extension
6682 // be installed. Should fail, because an external source is pending. 6685 // be installed. Should fail, because an external source is pending.
6683 content::WindowedNotificationObserver observer( 6686 content::WindowedNotificationObserver observer(
6684 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6687 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6685 content::NotificationService::AllSources()); 6688 content::NotificationService::AllSources());
6686 ASSERT_FALSE(AddPendingSyncInstall()); 6689 ASSERT_FALSE(AddPendingSyncInstall());
6687 6690
6688 // Wait for the external source to install. 6691 // Wait for the external source to install.
6689 observer.Wait(); 6692 observer.Wait();
6690 VerifyCrxInstall(crx_path_, INSTALL_NEW); 6693 VerifyCrxInstall(crx_path_, INSTALL_NEW);
6691 ASSERT_TRUE(IsCrxInstalled()); 6694 ASSERT_TRUE(IsCrxInstalled());
6692 6695
6693 // Now that the extension is installed, sync request should fail 6696 // Now that the extension is installed, sync request should fail
6694 // because the extension is already installed. 6697 // because the extension is already installed.
(...skipping 26 matching lines...) Expand all
6721 base::RunLoop().RunUntilIdle(); 6724 base::RunLoop().RunUntilIdle();
6722 EXPECT_FALSE( 6725 EXPECT_FALSE(
6723 service()->external_install_manager()->HasExternalInstallError()); 6726 service()->external_install_manager()->HasExternalInstallError());
6724 6727
6725 // A hosted app, installed externally. 6728 // A hosted app, installed externally.
6726 // This should NOT trigger an alert. 6729 // This should NOT trigger an alert.
6727 provider->UpdateOrAddExtension( 6730 provider->UpdateOrAddExtension(
6728 hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx")); 6731 hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx"));
6729 6732
6730 content::WindowedNotificationObserver observer( 6733 content::WindowedNotificationObserver observer(
6731 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6734 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6732 content::NotificationService::AllSources()); 6735 content::NotificationService::AllSources());
6733 service()->CheckForExternalUpdates(); 6736 service()->CheckForExternalUpdates();
6734 observer.Wait(); 6737 observer.Wait();
6735 EXPECT_FALSE( 6738 EXPECT_FALSE(
6736 service()->external_install_manager()->HasExternalInstallError()); 6739 service()->external_install_manager()->HasExternalInstallError());
6737 6740
6738 // Another normal extension, but installed externally. 6741 // Another normal extension, but installed externally.
6739 // This SHOULD trigger an alert. 6742 // This SHOULD trigger an alert.
6740 provider->UpdateOrAddExtension( 6743 provider->UpdateOrAddExtension(
6741 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); 6744 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6742 6745
6743 content::WindowedNotificationObserver observer2( 6746 content::WindowedNotificationObserver observer2(
6744 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6747 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6745 content::NotificationService::AllSources()); 6748 content::NotificationService::AllSources());
6746 service()->CheckForExternalUpdates(); 6749 service()->CheckForExternalUpdates();
6747 observer2.Wait(); 6750 observer2.Wait();
6748 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); 6751 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
6749 } 6752 }
6750 6753
6751 // Test that external extensions are initially disabled, and that enabling 6754 // Test that external extensions are initially disabled, and that enabling
6752 // them clears the prompt. 6755 // them clears the prompt.
6753 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 6756 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
6754 FeatureSwitch::ScopedOverride prompt( 6757 FeatureSwitch::ScopedOverride prompt(
6755 FeatureSwitch::prompt_for_external_extensions(), true); 6758 FeatureSwitch::prompt_for_external_extensions(), true);
6756 6759
6757 InitializeEmptyExtensionService(); 6760 InitializeEmptyExtensionService();
6758 MockExtensionProvider* provider = 6761 MockExtensionProvider* provider =
6759 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); 6762 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6760 AddMockExternalProvider(provider); 6763 AddMockExternalProvider(provider);
6761 6764
6762 provider->UpdateOrAddExtension( 6765 provider->UpdateOrAddExtension(
6763 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); 6766 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6764 6767
6765 content::WindowedNotificationObserver observer( 6768 content::WindowedNotificationObserver observer(
6766 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6769 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6767 content::NotificationService::AllSources()); 6770 content::NotificationService::AllSources());
6768 service()->CheckForExternalUpdates(); 6771 service()->CheckForExternalUpdates();
6769 observer.Wait(); 6772 observer.Wait();
6770 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); 6773 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
6771 EXPECT_FALSE(service()->IsExtensionEnabled(page_action)); 6774 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6772 6775
6773 const Extension* extension = 6776 const Extension* extension =
6774 registry()->disabled_extensions().GetByID(page_action); 6777 registry()->disabled_extensions().GetByID(page_action);
6775 EXPECT_TRUE(extension); 6778 EXPECT_TRUE(extension);
6776 EXPECT_EQ(page_action, extension->id()); 6779 EXPECT_EQ(page_action, extension->id());
(...skipping 22 matching lines...) Expand all
6799 6802
6800 provider->UpdateOrAddExtension( 6803 provider->UpdateOrAddExtension(
6801 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); 6804 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6802 provider->UpdateOrAddExtension( 6805 provider->UpdateOrAddExtension(
6803 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); 6806 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
6804 provider->UpdateOrAddExtension( 6807 provider->UpdateOrAddExtension(
6805 theme_crx, "2.0", data_dir().AppendASCII("theme.crx")); 6808 theme_crx, "2.0", data_dir().AppendASCII("theme.crx"));
6806 6809
6807 int count = 3; 6810 int count = 3;
6808 content::WindowedNotificationObserver observer( 6811 content::WindowedNotificationObserver observer(
6809 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6812 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6810 base::Bind(&WaitForCountNotificationsCallback, &count)); 6813 base::Bind(&WaitForCountNotificationsCallback, &count));
6811 service()->CheckForExternalUpdates(); 6814 service()->CheckForExternalUpdates();
6812 observer.Wait(); 6815 observer.Wait();
6813 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); 6816 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
6814 EXPECT_FALSE(service()->IsExtensionEnabled(page_action)); 6817 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6815 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); 6818 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6816 EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx)); 6819 EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx));
6817 6820
6818 service()->EnableExtension(page_action); 6821 service()->EnableExtension(page_action);
6819 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); 6822 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6851 PackCRX(data_dir().AppendASCII("update_from_webstore"), 6854 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6852 data_dir().AppendASCII("update_from_webstore.pem"), 6855 data_dir().AppendASCII("update_from_webstore.pem"),
6853 crx_path); 6856 crx_path);
6854 6857
6855 MockExtensionProvider* provider = 6858 MockExtensionProvider* provider =
6856 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); 6859 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6857 AddMockExternalProvider(provider); 6860 AddMockExternalProvider(provider);
6858 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6861 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6859 6862
6860 content::WindowedNotificationObserver observer( 6863 content::WindowedNotificationObserver observer(
6861 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6864 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6862 content::NotificationService::AllSources()); 6865 content::NotificationService::AllSources());
6863 service()->CheckForExternalUpdates(); 6866 service()->CheckForExternalUpdates();
6864 observer.Wait(); 6867 observer.Wait();
6865 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); 6868 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
6866 EXPECT_TRUE(service() 6869 EXPECT_TRUE(service()
6867 ->external_install_manager() 6870 ->external_install_manager()
6868 ->HasExternalInstallBubbleForTesting()); 6871 ->HasExternalInstallBubbleForTesting());
6869 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore)); 6872 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
6870 } 6873 }
6871 6874
6872 // Test that there is no bubble for external extensions if the profile is new. 6875 // Test that there is no bubble for external extensions if the profile is new.
6873 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { 6876 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) {
6874 FeatureSwitch::ScopedOverride prompt( 6877 FeatureSwitch::ScopedOverride prompt(
6875 FeatureSwitch::prompt_for_external_extensions(), true); 6878 FeatureSwitch::prompt_for_external_extensions(), true);
6876 6879
6877 InitializeEmptyExtensionService(); 6880 InitializeEmptyExtensionService();
6878 6881
6879 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx"); 6882 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6880 PackCRX(data_dir().AppendASCII("update_from_webstore"), 6883 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6881 data_dir().AppendASCII("update_from_webstore.pem"), 6884 data_dir().AppendASCII("update_from_webstore.pem"),
6882 crx_path); 6885 crx_path);
6883 6886
6884 MockExtensionProvider* provider = 6887 MockExtensionProvider* provider =
6885 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); 6888 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
6886 AddMockExternalProvider(provider); 6889 AddMockExternalProvider(provider);
6887 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6890 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6888 6891
6889 content::WindowedNotificationObserver observer( 6892 content::WindowedNotificationObserver observer(
6890 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6893 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6891 content::NotificationService::AllSources()); 6894 content::NotificationService::AllSources());
6892 service()->CheckForExternalUpdates(); 6895 service()->CheckForExternalUpdates();
6893 observer.Wait(); 6896 observer.Wait();
6894 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); 6897 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
6895 EXPECT_FALSE(service() 6898 EXPECT_FALSE(service()
6896 ->external_install_manager() 6899 ->external_install_manager()
6897 ->HasExternalInstallBubbleForTesting()); 6900 ->HasExternalInstallBubbleForTesting());
6898 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore)); 6901 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
6899 } 6902 }
6900 6903
(...skipping 11 matching lines...) Expand all
6912 PackCRX(data_dir().AppendASCII("update_from_webstore"), 6915 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6913 data_dir().AppendASCII("update_from_webstore.pem"), 6916 data_dir().AppendASCII("update_from_webstore.pem"),
6914 crx_path); 6917 crx_path);
6915 6918
6916 MockExtensionProvider* provider = 6919 MockExtensionProvider* provider =
6917 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6920 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6918 AddMockExternalProvider(provider); 6921 AddMockExternalProvider(provider);
6919 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6922 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6920 6923
6921 content::WindowedNotificationObserver observer( 6924 content::WindowedNotificationObserver observer(
6922 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6925 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6923 content::NotificationService::AllSources()); 6926 content::NotificationService::AllSources());
6924 service_->CheckForExternalUpdates(); 6927 service_->CheckForExternalUpdates();
6925 observer.Wait(); 6928 observer.Wait();
6926 EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError()); 6929 EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError());
6927 6930
6928 // We check both enabled and disabled, since these are "eventually exclusive" 6931 // We check both enabled and disabled, since these are "eventually exclusive"
6929 // sets. 6932 // sets.
6930 EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore)); 6933 EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore));
6931 EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore)); 6934 EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore));
6932 6935
(...skipping 21 matching lines...) Expand all
6954 PackCRX(data_dir().AppendASCII("update_from_webstore"), 6957 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6955 data_dir().AppendASCII("update_from_webstore.pem"), 6958 data_dir().AppendASCII("update_from_webstore.pem"),
6956 crx_path); 6959 crx_path);
6957 6960
6958 MockExtensionProvider* provider = 6961 MockExtensionProvider* provider =
6959 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6962 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6960 AddMockExternalProvider(provider); 6963 AddMockExternalProvider(provider);
6961 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6964 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6962 6965
6963 content::WindowedNotificationObserver observer( 6966 content::WindowedNotificationObserver observer(
6964 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 6967 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6965 content::NotificationService::AllSources()); 6968 content::NotificationService::AllSources());
6966 service_->CheckForExternalUpdates(); 6969 service_->CheckForExternalUpdates();
6967 observer.Wait(); 6970 observer.Wait();
6968 EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError()); 6971 EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError());
6969 6972
6970 // We check both enabled and disabled, since these are "eventually exclusive" 6973 // We check both enabled and disabled, since these are "eventually exclusive"
6971 // sets. 6974 // sets.
6972 EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore)); 6975 EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore));
6973 EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore)); 6976 EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore));
6974 6977
(...skipping 30 matching lines...) Expand all
7005 // loaded and it should be blacklisted in prefs. 7008 // loaded and it should be blacklisted in prefs.
7006 service()->OnExtensionInstalled( 7009 service()->OnExtensionInstalled(
7007 extension.get(), 7010 extension.get(),
7008 syncer::StringOrdinal(), 7011 syncer::StringOrdinal(),
7009 (extensions::kInstallFlagIsBlacklistedForMalware | 7012 (extensions::kInstallFlagIsBlacklistedForMalware |
7010 extensions::kInstallFlagInstallImmediately)); 7013 extensions::kInstallFlagInstallImmediately));
7011 base::RunLoop().RunUntilIdle(); 7014 base::RunLoop().RunUntilIdle();
7012 7015
7013 // Extension was installed but not loaded. 7016 // Extension was installed but not loaded.
7014 EXPECT_TRUE(notifications.CheckNotifications( 7017 EXPECT_TRUE(notifications.CheckNotifications(
7015 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED)); 7018 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED));
7016 EXPECT_TRUE(service()->GetInstalledExtension(id)); 7019 EXPECT_TRUE(service()->GetInstalledExtension(id));
7017 7020
7018 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 7021 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
7019 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id)); 7022 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id));
7020 7023
7021 EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id)); 7024 EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id));
7022 EXPECT_TRUE( 7025 EXPECT_TRUE(
7023 ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id)); 7026 ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id));
7024 } 7027 }
7025 7028
(...skipping 10 matching lines...) Expand all
7036 7039
7037 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 7040 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7038 content::Source<Profile>(profile()), 7041 content::Source<Profile>(profile()),
7039 content::NotificationService::NoDetails()); 7042 content::NotificationService::NoDetails());
7040 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 7043 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7041 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 7044 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7042 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 7045 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7043 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 7046 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7044 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 7047 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7045 } 7048 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_startup_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698