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

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

Issue 974713002: kiosk: Ensure launching latest version. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unittest compile Created 5 years, 9 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 <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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 // ExternalProvider implementation: 264 // ExternalProvider implementation:
265 void VisitRegisteredExtension() override { 265 void VisitRegisteredExtension() override {
266 visit_count_++; 266 visit_count_++;
267 for (DataMap::const_iterator i = extension_map_.begin(); 267 for (DataMap::const_iterator i = extension_map_.begin();
268 i != extension_map_.end(); ++i) { 268 i != extension_map_.end(); ++i) {
269 Version version(i->second.first); 269 Version version(i->second.first);
270 270
271 visitor_->OnExternalExtensionFileFound( 271 visitor_->OnExternalExtensionFileFound(
272 i->first, &version, i->second.second, location_, 272 i->first, &version, i->second.second, location_,
273 Extension::NO_FLAGS, false); 273 Extension::NO_FLAGS, false, false);
274 } 274 }
275 visitor_->OnExternalProviderReady(this); 275 visitor_->OnExternalProviderReady(this);
276 } 276 }
277 277
278 bool HasExtension(const std::string& id) const override { 278 bool HasExtension(const std::string& id) const override {
279 return extension_map_.find(id) != extension_map_.end(); 279 return extension_map_.find(id) != extension_map_.end();
280 } 280 }
281 281
282 bool GetExtensionDetails(const std::string& id, 282 bool GetExtensionDetails(const std::string& id,
283 Manifest::Location* location, 283 Manifest::Location* location,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 provider_->VisitRegisteredExtension(); 370 provider_->VisitRegisteredExtension();
371 371
372 return ids_found_; 372 return ids_found_;
373 } 373 }
374 374
375 bool OnExternalExtensionFileFound(const std::string& id, 375 bool OnExternalExtensionFileFound(const std::string& id,
376 const Version* version, 376 const Version* version,
377 const base::FilePath& path, 377 const base::FilePath& path,
378 Manifest::Location unused, 378 Manifest::Location unused,
379 int creation_flags, 379 int creation_flags,
380 bool mark_acknowledged) override { 380 bool mark_acknowledged,
381 bool install_immediately) override {
381 EXPECT_EQ(expected_creation_flags_, creation_flags); 382 EXPECT_EQ(expected_creation_flags_, creation_flags);
382 383
383 ++ids_found_; 384 ++ids_found_;
384 base::DictionaryValue* pref; 385 base::DictionaryValue* pref;
385 // This tests is to make sure that the provider only notifies us of the 386 // This tests is to make sure that the provider only notifies us of the
386 // values we gave it. So if the id we doesn't exist in our internal 387 // values we gave it. So if the id we doesn't exist in our internal
387 // dictionary then something is wrong. 388 // dictionary then something is wrong.
388 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) 389 EXPECT_TRUE(prefs_->GetDictionary(id, &pref))
389 << "Got back ID (" << id.c_str() << ") we weren't expecting"; 390 << "Got back ID (" << id.c_str() << ") we weren't expecting";
390 391
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 InitializeEmptyExtensionService(); 1558 InitializeEmptyExtensionService();
1558 1559
1559 base::FilePath path = data_dir().AppendASCII("good.crx"); 1560 base::FilePath path = data_dir().AppendASCII("good.crx");
1560 service()->set_extensions_enabled(true); 1561 service()->set_extensions_enabled(true);
1561 1562
1562 // Register and install an external extension. 1563 // Register and install an external extension.
1563 Version version("1.0.0.0"); 1564 Version version("1.0.0.0");
1564 content::WindowedNotificationObserver observer( 1565 content::WindowedNotificationObserver observer(
1565 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1566 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1566 content::NotificationService::AllSources()); 1567 content::NotificationService::AllSources());
1567 if (service()->OnExternalExtensionFileFound(good_crx, 1568 if (service()->OnExternalExtensionFileFound(
1568 &version, 1569 good_crx,
1569 path, 1570 &version,
1570 Manifest::EXTERNAL_PREF, 1571 path,
1571 Extension::FROM_BOOKMARK, 1572 Manifest::EXTERNAL_PREF,
1572 false /* mark_acknowledged */)) { 1573 Extension::FROM_BOOKMARK,
1574 false /* mark_acknowledged */,
1575 false /* install_immediately */)) {
1573 observer.Wait(); 1576 observer.Wait();
1574 } 1577 }
1575 1578
1576 const Extension* extension = service()->GetExtensionById(good_crx, false); 1579 const Extension* extension = service()->GetExtensionById(good_crx, false);
1577 ASSERT_TRUE(extension); 1580 ASSERT_TRUE(extension);
1578 ASSERT_TRUE(extension->from_bookmark()); 1581 ASSERT_TRUE(extension->from_bookmark());
1579 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); 1582 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
1580 1583
1581 // Upgrade to version 2.0, the flag should be preserved. 1584 // Upgrade to version 2.0, the flag should be preserved.
1582 path = data_dir().AppendASCII("good2.crx"); 1585 path = data_dir().AppendASCII("good2.crx");
(...skipping 14 matching lines...) Expand all
1597 // Install an external extension. 1600 // Install an external extension.
1598 Version version("1.0.0.0"); 1601 Version version("1.0.0.0");
1599 content::WindowedNotificationObserver observer( 1602 content::WindowedNotificationObserver observer(
1600 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1603 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1601 content::NotificationService::AllSources()); 1604 content::NotificationService::AllSources());
1602 if (service()->OnExternalExtensionFileFound(good_crx, 1605 if (service()->OnExternalExtensionFileFound(good_crx,
1603 &version, 1606 &version,
1604 path, 1607 path,
1605 Manifest::EXTERNAL_PREF, 1608 Manifest::EXTERNAL_PREF,
1606 Extension::NO_FLAGS, 1609 Extension::NO_FLAGS,
1610 false,
1607 false)) { 1611 false)) {
1608 observer.Wait(); 1612 observer.Wait();
1609 } 1613 }
1610 1614
1611 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1615 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1612 1616
1613 // Uninstall it and check that its killbit gets set. 1617 // Uninstall it and check that its killbit gets set.
1614 UninstallExtension(good_crx, false); 1618 UninstallExtension(good_crx, false);
1615 ValidateIntegerPref(good_crx, "state", 1619 ValidateIntegerPref(good_crx, "state",
1616 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1620 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1617 1621
1618 // Try to re-install it externally. This should fail because of the killbit. 1622 // Try to re-install it externally. This should fail because of the killbit.
1619 service()->OnExternalExtensionFileFound(good_crx, 1623 service()->OnExternalExtensionFileFound(good_crx,
1620 &version, 1624 &version,
1621 path, 1625 path,
1622 Manifest::EXTERNAL_PREF, 1626 Manifest::EXTERNAL_PREF,
1623 Extension::NO_FLAGS, 1627 Extension::NO_FLAGS,
1628 false,
1624 false); 1629 false);
1625 base::RunLoop().RunUntilIdle(); 1630 base::RunLoop().RunUntilIdle();
1626 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); 1631 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1627 ValidateIntegerPref(good_crx, "state", 1632 ValidateIntegerPref(good_crx, "state",
1628 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1633 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1629 1634
1630 version = Version("1.0.0.1"); 1635 version = Version("1.0.0.1");
1631 // Repeat the same thing with a newer version of the extension. 1636 // Repeat the same thing with a newer version of the extension.
1632 path = data_dir().AppendASCII("good2.crx"); 1637 path = data_dir().AppendASCII("good2.crx");
1633 service()->OnExternalExtensionFileFound(good_crx, 1638 service()->OnExternalExtensionFileFound(good_crx,
1634 &version, 1639 &version,
1635 path, 1640 path,
1636 Manifest::EXTERNAL_PREF, 1641 Manifest::EXTERNAL_PREF,
1637 Extension::NO_FLAGS, 1642 Extension::NO_FLAGS,
1643 false,
1638 false); 1644 false);
1639 base::RunLoop().RunUntilIdle(); 1645 base::RunLoop().RunUntilIdle();
1640 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); 1646 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
1641 ValidateIntegerPref(good_crx, "state", 1647 ValidateIntegerPref(good_crx, "state",
1642 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1648 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1643 1649
1644 // Try adding the same extension from an external update URL. 1650 // Try adding the same extension from an external update URL.
1645 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( 1651 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
1646 good_crx, 1652 good_crx,
1647 std::string(), 1653 std::string(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 // Install an external extension with an ID from the external 1701 // Install an external extension with an ID from the external
1696 // source that is not equal to the ID in the extension manifest. 1702 // source that is not equal to the ID in the extension manifest.
1697 content::WindowedNotificationObserver observer( 1703 content::WindowedNotificationObserver observer(
1698 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1704 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1699 content::NotificationService::AllSources()); 1705 content::NotificationService::AllSources());
1700 service()->OnExternalExtensionFileFound(wrong_id, 1706 service()->OnExternalExtensionFileFound(wrong_id,
1701 &version, 1707 &version,
1702 path, 1708 path,
1703 Manifest::EXTERNAL_PREF, 1709 Manifest::EXTERNAL_PREF,
1704 Extension::NO_FLAGS, 1710 Extension::NO_FLAGS,
1711 false,
1705 false); 1712 false);
1706 1713
1707 observer.Wait(); 1714 observer.Wait();
1708 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1715 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1709 1716
1710 // Try again with the right ID. Expect success. 1717 // Try again with the right ID. Expect success.
1711 content::WindowedNotificationObserver observer2( 1718 content::WindowedNotificationObserver observer2(
1712 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1719 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1713 content::NotificationService::AllSources()); 1720 content::NotificationService::AllSources());
1714 if (service()->OnExternalExtensionFileFound(correct_id, 1721 if (service()->OnExternalExtensionFileFound(correct_id,
1715 &version, 1722 &version,
1716 path, 1723 path,
1717 Manifest::EXTERNAL_PREF, 1724 Manifest::EXTERNAL_PREF,
1718 Extension::NO_FLAGS, 1725 Extension::NO_FLAGS,
1726 false,
1719 false)) { 1727 false)) {
1720 observer2.Wait(); 1728 observer2.Wait();
1721 } 1729 }
1722 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1730 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1723 } 1731 }
1724 1732
1725 // Test that external extensions with incorrect versions are not installed. 1733 // Test that external extensions with incorrect versions are not installed.
1726 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1734 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1727 InitializeEmptyExtensionService(); 1735 InitializeEmptyExtensionService();
1728 base::FilePath path = data_dir().AppendASCII("good.crx"); 1736 base::FilePath path = data_dir().AppendASCII("good.crx");
1729 service()->set_extensions_enabled(true); 1737 service()->set_extensions_enabled(true);
1730 1738
1731 // Install an external extension with a version from the external 1739 // Install an external extension with a version from the external
1732 // source that is not equal to the version in the extension manifest. 1740 // source that is not equal to the version in the extension manifest.
1733 Version wrong_version("1.2.3.4"); 1741 Version wrong_version("1.2.3.4");
1734 content::WindowedNotificationObserver observer( 1742 content::WindowedNotificationObserver observer(
1735 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1743 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1736 content::NotificationService::AllSources()); 1744 content::NotificationService::AllSources());
1737 service()->OnExternalExtensionFileFound(good_crx, 1745 service()->OnExternalExtensionFileFound(good_crx,
1738 &wrong_version, 1746 &wrong_version,
1739 path, 1747 path,
1740 Manifest::EXTERNAL_PREF, 1748 Manifest::EXTERNAL_PREF,
1741 Extension::NO_FLAGS, 1749 Extension::NO_FLAGS,
1750 false,
1742 false); 1751 false);
1743 1752
1744 observer.Wait(); 1753 observer.Wait();
1745 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1754 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1746 1755
1747 // Try again with the right version. Expect success. 1756 // Try again with the right version. Expect success.
1748 service()->pending_extension_manager()->Remove(good_crx); 1757 service()->pending_extension_manager()->Remove(good_crx);
1749 Version correct_version("1.0.0.0"); 1758 Version correct_version("1.0.0.0");
1750 content::WindowedNotificationObserver observer2( 1759 content::WindowedNotificationObserver observer2(
1751 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1760 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1752 content::NotificationService::AllSources()); 1761 content::NotificationService::AllSources());
1753 if (service()->OnExternalExtensionFileFound(good_crx, 1762 if (service()->OnExternalExtensionFileFound(good_crx,
1754 &correct_version, 1763 &correct_version,
1755 path, 1764 path,
1756 Manifest::EXTERNAL_PREF, 1765 Manifest::EXTERNAL_PREF,
1757 Extension::NO_FLAGS, 1766 Extension::NO_FLAGS,
1767 false,
1758 false)) { 1768 false)) {
1759 observer2.Wait(); 1769 observer2.Wait();
1760 } 1770 }
1761 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1771 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1762 } 1772 }
1763 1773
1764 // Install a user script (they get converted automatically to an extension) 1774 // Install a user script (they get converted automatically to an extension)
1765 TEST_F(ExtensionServiceTest, InstallUserScript) { 1775 TEST_F(ExtensionServiceTest, InstallUserScript) {
1766 // The details of script conversion are tested elsewhere, this just tests 1776 // The details of script conversion are tested elsewhere, this just tests
1767 // integration with ExtensionService. 1777 // integration with ExtensionService.
(...skipping 5050 matching lines...) Expand 10 before | Expand all | Expand 10 after
6818 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { 6828 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
6819 Version older_version("0.1.0.0"); 6829 Version older_version("0.1.0.0");
6820 Version newer_version("2.0.0.0"); 6830 Version newer_version("2.0.0.0");
6821 6831
6822 // We don't want the extension to be installed. A path that doesn't 6832 // We don't want the extension to be installed. A path that doesn't
6823 // point to a valid CRX ensures this. 6833 // point to a valid CRX ensures this.
6824 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); 6834 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path"));
6825 6835
6826 const int kCreationFlags = 0; 6836 const int kCreationFlags = 0;
6827 const bool kDontMarkAcknowledged = false; 6837 const bool kDontMarkAcknowledged = false;
6838 const bool kDontInstallImmediately = false;
6828 6839
6829 InitializeEmptyExtensionService(); 6840 InitializeEmptyExtensionService();
6830 6841
6831 // The test below uses install source constants to test that 6842 // The test below uses install source constants to test that
6832 // priority is enforced. It assumes a specific ranking of install 6843 // priority is enforced. It assumes a specific ranking of install
6833 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref 6844 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref
6834 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). 6845 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL).
6835 // The following assertions verify these assumptions: 6846 // The following assertions verify these assumptions:
6836 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, 6847 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
6837 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 6848 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6838 Manifest::EXTERNAL_PREF)); 6849 Manifest::EXTERNAL_PREF));
6839 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, 6850 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
6840 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 6851 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6841 Manifest::INTERNAL)); 6852 Manifest::INTERNAL));
6842 ASSERT_EQ(Manifest::EXTERNAL_PREF, 6853 ASSERT_EQ(Manifest::EXTERNAL_PREF,
6843 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, 6854 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
6844 Manifest::INTERNAL)); 6855 Manifest::INTERNAL));
6845 6856
6846 extensions::PendingExtensionManager* pending = 6857 extensions::PendingExtensionManager* pending =
6847 service()->pending_extension_manager(); 6858 service()->pending_extension_manager();
6848 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6859 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6849 6860
6850 { 6861 {
6851 // Simulate an external source adding the extension as INTERNAL. 6862 // Simulate an external source adding the extension as INTERNAL.
6852 content::WindowedNotificationObserver observer( 6863 content::WindowedNotificationObserver observer(
6853 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 6864 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6854 content::NotificationService::AllSources()); 6865 content::NotificationService::AllSources());
6855 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 6866 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
6856 &older_version, 6867 kGoodId,
6857 kInvalidPathToCrx, 6868 &older_version,
6858 Manifest::INTERNAL, 6869 kInvalidPathToCrx,
6859 kCreationFlags, 6870 Manifest::INTERNAL,
6860 kDontMarkAcknowledged)); 6871 kCreationFlags,
6872 kDontMarkAcknowledged,
6873 kDontInstallImmediately));
6861 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6874 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6862 observer.Wait(); 6875 observer.Wait();
6863 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6876 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6864 } 6877 }
6865 6878
6866 { 6879 {
6867 // Simulate an external source adding the extension as EXTERNAL_PREF. 6880 // Simulate an external source adding the extension as EXTERNAL_PREF.
6868 content::WindowedNotificationObserver observer( 6881 content::WindowedNotificationObserver observer(
6869 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 6882 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6870 content::NotificationService::AllSources()); 6883 content::NotificationService::AllSources());
6871 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 6884 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
6872 &older_version, 6885 kGoodId,
6873 kInvalidPathToCrx, 6886 &older_version,
6874 Manifest::EXTERNAL_PREF, 6887 kInvalidPathToCrx,
6875 kCreationFlags, 6888 Manifest::EXTERNAL_PREF,
6876 kDontMarkAcknowledged)); 6889 kCreationFlags,
6890 kDontMarkAcknowledged,
6891 kDontInstallImmediately));
6877 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6892 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6878 observer.Wait(); 6893 observer.Wait();
6879 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6894 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6880 } 6895 }
6881 6896
6882 // Simulate an external source adding as EXTERNAL_PREF again. 6897 // Simulate an external source adding as EXTERNAL_PREF again.
6883 // This is rejected because the version and the location are the same as 6898 // This is rejected because the version and the location are the same as
6884 // the previous installation, which is still pending. 6899 // the previous installation, which is still pending.
6885 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 6900 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6886 &older_version, 6901 kGoodId,
6887 kInvalidPathToCrx, 6902 &older_version,
6888 Manifest::EXTERNAL_PREF, 6903 kInvalidPathToCrx,
6889 kCreationFlags, 6904 Manifest::EXTERNAL_PREF,
6890 kDontMarkAcknowledged)); 6905 kCreationFlags,
6906 kDontMarkAcknowledged,
6907 kDontInstallImmediately));
6891 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6908 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6892 6909
6893 // Try INTERNAL again. Should fail. 6910 // Try INTERNAL again. Should fail.
6894 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 6911 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6895 &older_version, 6912 kGoodId,
6896 kInvalidPathToCrx, 6913 &older_version,
6897 Manifest::INTERNAL, 6914 kInvalidPathToCrx,
6898 kCreationFlags, 6915 Manifest::INTERNAL,
6899 kDontMarkAcknowledged)); 6916 kCreationFlags,
6917 kDontMarkAcknowledged,
6918 kDontInstallImmediately));
6900 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6919 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6901 6920
6902 { 6921 {
6903 // Now the registry adds the extension. 6922 // Now the registry adds the extension.
6904 content::WindowedNotificationObserver observer( 6923 content::WindowedNotificationObserver observer(
6905 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 6924 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
6906 content::NotificationService::AllSources()); 6925 content::NotificationService::AllSources());
6907 EXPECT_TRUE( 6926 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
6908 service()->OnExternalExtensionFileFound(kGoodId, 6927 kGoodId,
6909 &older_version, 6928 &older_version,
6910 kInvalidPathToCrx, 6929 kInvalidPathToCrx,
6911 Manifest::EXTERNAL_REGISTRY, 6930 Manifest::EXTERNAL_REGISTRY,
6912 kCreationFlags, 6931 kCreationFlags,
6913 kDontMarkAcknowledged)); 6932 kDontMarkAcknowledged,
6933 kDontInstallImmediately));
6914 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6934 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6915 observer.Wait(); 6935 observer.Wait();
6916 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); 6936 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6917 } 6937 }
6918 6938
6919 // Registry outranks both external pref and internal, so both fail. 6939 // Registry outranks both external pref and internal, so both fail.
6920 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 6940 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6921 &older_version, 6941 kGoodId,
6922 kInvalidPathToCrx, 6942 &older_version,
6923 Manifest::EXTERNAL_PREF, 6943 kInvalidPathToCrx,
6924 kCreationFlags, 6944 Manifest::EXTERNAL_PREF,
6925 kDontMarkAcknowledged)); 6945 kCreationFlags,
6946 kDontMarkAcknowledged,
6947 kDontInstallImmediately));
6926 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6948 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6927 6949
6928 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 6950 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6929 &older_version, 6951 kGoodId,
6930 kInvalidPathToCrx, 6952 &older_version,
6931 Manifest::INTERNAL, 6953 kInvalidPathToCrx,
6932 kCreationFlags, 6954 Manifest::INTERNAL,
6933 kDontMarkAcknowledged)); 6955 kCreationFlags,
6956 kDontMarkAcknowledged,
6957 kDontInstallImmediately));
6934 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 6958 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6935 6959
6936 pending->Remove(kGoodId); 6960 pending->Remove(kGoodId);
6937 6961
6938 // Install the extension. 6962 // Install the extension.
6939 base::FilePath path = data_dir().AppendASCII("good.crx"); 6963 base::FilePath path = data_dir().AppendASCII("good.crx");
6940 const Extension* ext = InstallCRX(path, INSTALL_NEW); 6964 const Extension* ext = InstallCRX(path, INSTALL_NEW);
6941 ValidatePrefKeyCount(1u); 6965 ValidatePrefKeyCount(1u);
6942 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 6966 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
6943 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 6967 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
6944 6968
6945 // Now test the logic of OnExternalExtensionFileFound() when the extension 6969 // Now test the logic of OnExternalExtensionFileFound() when the extension
6946 // being added is already installed. 6970 // being added is already installed.
6947 6971
6948 // Tests assume |older_version| is less than the installed version, and 6972 // Tests assume |older_version| is less than the installed version, and
6949 // |newer_version| is greater. Verify this: 6973 // |newer_version| is greater. Verify this:
6950 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); 6974 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString()));
6951 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); 6975 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString()));
6952 6976
6953 // An external install for the same location should fail if the version is 6977 // An external install for the same location should fail if the version is
6954 // older, or the same, and succeed if the version is newer. 6978 // older, or the same, and succeed if the version is newer.
6955 6979
6956 // Older than the installed version... 6980 // Older than the installed version...
6957 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 6981 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6958 &older_version, 6982 kGoodId,
6959 kInvalidPathToCrx, 6983 &older_version,
6960 Manifest::INTERNAL, 6984 kInvalidPathToCrx,
6961 kCreationFlags, 6985 Manifest::INTERNAL,
6962 kDontMarkAcknowledged)); 6986 kCreationFlags,
6987 kDontMarkAcknowledged,
6988 kDontInstallImmediately));
6963 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 6989 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6964 6990
6965 // Same version as the installed version... 6991 // Same version as the installed version...
6966 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 6992 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6967 ext->version(), 6993 kGoodId,
6968 kInvalidPathToCrx, 6994 ext->version(),
6969 Manifest::INTERNAL, 6995 kInvalidPathToCrx,
6970 kCreationFlags, 6996 Manifest::INTERNAL,
6971 kDontMarkAcknowledged)); 6997 kCreationFlags,
6998 kDontMarkAcknowledged,
6999 kDontInstallImmediately));
6972 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 7000 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6973 7001
6974 // Newer than the installed version... 7002 // Newer than the installed version...
6975 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 7003 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
6976 &newer_version, 7004 kGoodId,
6977 kInvalidPathToCrx, 7005 &newer_version,
6978 Manifest::INTERNAL, 7006 kInvalidPathToCrx,
6979 kCreationFlags, 7007 Manifest::INTERNAL,
6980 kDontMarkAcknowledged)); 7008 kCreationFlags,
7009 kDontMarkAcknowledged,
7010 kDontInstallImmediately));
6981 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 7011 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6982 7012
6983 // An external install for a higher priority install source should succeed 7013 // An external install for a higher priority install source should succeed
6984 // if the version is greater. |older_version| is not... 7014 // if the version is greater. |older_version| is not...
6985 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 7015 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
6986 &older_version, 7016 kGoodId,
6987 kInvalidPathToCrx, 7017 &older_version,
6988 Manifest::EXTERNAL_PREF, 7018 kInvalidPathToCrx,
6989 kCreationFlags, 7019 Manifest::EXTERNAL_PREF,
6990 kDontMarkAcknowledged)); 7020 kCreationFlags,
7021 kDontMarkAcknowledged,
7022 kDontInstallImmediately));
6991 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 7023 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6992 7024
6993 // |newer_version| is newer. 7025 // |newer_version| is newer.
6994 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 7026 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
6995 &newer_version, 7027 kGoodId,
6996 kInvalidPathToCrx, 7028 &newer_version,
6997 Manifest::EXTERNAL_PREF, 7029 kInvalidPathToCrx,
6998 kCreationFlags, 7030 Manifest::EXTERNAL_PREF,
6999 kDontMarkAcknowledged)); 7031 kCreationFlags,
7032 kDontMarkAcknowledged,
7033 kDontInstallImmediately));
7000 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 7034 EXPECT_TRUE(pending->IsIdPending(kGoodId));
7001 7035
7002 // An external install for an even higher priority install source should 7036 // An external install for an even higher priority install source should
7003 // succeed if the version is greater. 7037 // succeed if the version is greater.
7004 EXPECT_TRUE( 7038 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
7005 service()->OnExternalExtensionFileFound(kGoodId, 7039 kGoodId,
7006 &newer_version, 7040 &newer_version,
7007 kInvalidPathToCrx, 7041 kInvalidPathToCrx,
7008 Manifest::EXTERNAL_REGISTRY, 7042 Manifest::EXTERNAL_REGISTRY,
7009 kCreationFlags, 7043 kCreationFlags,
7010 kDontMarkAcknowledged)); 7044 kDontMarkAcknowledged,
7045 kDontInstallImmediately));
7011 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 7046 EXPECT_TRUE(pending->IsIdPending(kGoodId));
7012 7047
7013 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, 7048 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY,
7014 // adding from external pref will now fail. 7049 // adding from external pref will now fail.
7015 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 7050 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
7016 &newer_version, 7051 kGoodId,
7017 kInvalidPathToCrx, 7052 &newer_version,
7018 Manifest::EXTERNAL_PREF, 7053 kInvalidPathToCrx,
7019 kCreationFlags, 7054 Manifest::EXTERNAL_PREF,
7020 kDontMarkAcknowledged)); 7055 kCreationFlags,
7056 kDontMarkAcknowledged,
7057 kDontInstallImmediately));
7021 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 7058 EXPECT_TRUE(pending->IsIdPending(kGoodId));
7022 } 7059 }
7023 7060
7024 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { 7061 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) {
7025 Version kVersion123("1.2.3"); 7062 Version kVersion123("1.2.3");
7026 Version kVersion124("1.2.4"); 7063 Version kVersion124("1.2.4");
7027 Version kVersion125("1.2.5"); 7064 Version kVersion125("1.2.5");
7028 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); 7065 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path"));
7029 const int kCreationFlags = 0; 7066 const int kCreationFlags = 0;
7030 const bool kDontMarkAcknowledged = false; 7067 const bool kDontMarkAcknowledged = false;
7068 const bool kDontInstallImmediately = false;
7031 7069
7032 InitializeEmptyExtensionService(); 7070 InitializeEmptyExtensionService();
7033 7071
7034 extensions::PendingExtensionManager* pending = 7072 extensions::PendingExtensionManager* pending =
7035 service()->pending_extension_manager(); 7073 service()->pending_extension_manager();
7036 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 7074 EXPECT_FALSE(pending->IsIdPending(kGoodId));
7037 7075
7038 // An external provider starts installing from a local crx. 7076 // An external provider starts installing from a local crx.
7039 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 7077 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
7040 &kVersion123, 7078 kGoodId,
7041 kInvalidPathToCrx, 7079 &kVersion123,
7042 Manifest::EXTERNAL_PREF, 7080 kInvalidPathToCrx,
7043 kCreationFlags, 7081 Manifest::EXTERNAL_PREF,
7044 kDontMarkAcknowledged)); 7082 kCreationFlags,
7083 kDontMarkAcknowledged,
7084 kDontInstallImmediately));
7045 const extensions::PendingExtensionInfo* info; 7085 const extensions::PendingExtensionInfo* info;
7046 EXPECT_TRUE((info = pending->GetById(kGoodId))); 7086 EXPECT_TRUE((info = pending->GetById(kGoodId)));
7047 EXPECT_TRUE(info->version().IsValid()); 7087 EXPECT_TRUE(info->version().IsValid());
7048 EXPECT_TRUE(info->version().Equals(kVersion123)); 7088 EXPECT_TRUE(info->version().Equals(kVersion123));
7049 7089
7050 // Adding a newer version overrides the currently pending version. 7090 // Adding a newer version overrides the currently pending version.
7051 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, 7091 EXPECT_TRUE(service()->OnExternalExtensionFileFound(
7052 &kVersion124, 7092 kGoodId,
7053 kInvalidPathToCrx, 7093 &kVersion124,
7054 Manifest::EXTERNAL_PREF, 7094 kInvalidPathToCrx,
7055 kCreationFlags, 7095 Manifest::EXTERNAL_PREF,
7056 kDontMarkAcknowledged)); 7096 kCreationFlags,
7097 kDontMarkAcknowledged,
7098 kDontInstallImmediately));
7057 EXPECT_TRUE((info = pending->GetById(kGoodId))); 7099 EXPECT_TRUE((info = pending->GetById(kGoodId)));
7058 EXPECT_TRUE(info->version().IsValid()); 7100 EXPECT_TRUE(info->version().IsValid());
7059 EXPECT_TRUE(info->version().Equals(kVersion124)); 7101 EXPECT_TRUE(info->version().Equals(kVersion124));
7060 7102
7061 // Adding an older version fails. 7103 // Adding an older version fails.
7062 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, 7104 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
7063 &kVersion123, 7105 kGoodId,
7064 kInvalidPathToCrx, 7106 &kVersion123,
7065 Manifest::EXTERNAL_PREF, 7107 kInvalidPathToCrx,
7066 kCreationFlags, 7108 Manifest::EXTERNAL_PREF,
7067 kDontMarkAcknowledged)); 7109 kCreationFlags,
7110 kDontMarkAcknowledged,
7111 kDontInstallImmediately));
7068 EXPECT_TRUE((info = pending->GetById(kGoodId))); 7112 EXPECT_TRUE((info = pending->GetById(kGoodId)));
7069 EXPECT_TRUE(info->version().IsValid()); 7113 EXPECT_TRUE(info->version().IsValid());
7070 EXPECT_TRUE(info->version().Equals(kVersion124)); 7114 EXPECT_TRUE(info->version().Equals(kVersion124));
7071 7115
7072 // Adding an older version fails even when coming from a higher-priority 7116 // Adding an older version fails even when coming from a higher-priority
7073 // location. 7117 // location.
7074 EXPECT_FALSE( 7118 EXPECT_FALSE(service()->OnExternalExtensionFileFound(
7075 service()->OnExternalExtensionFileFound(kGoodId, 7119 kGoodId,
7076 &kVersion123, 7120 &kVersion123,
7077 kInvalidPathToCrx, 7121 kInvalidPathToCrx,
7078 Manifest::EXTERNAL_REGISTRY, 7122 Manifest::EXTERNAL_REGISTRY,
7079 kCreationFlags, 7123 kCreationFlags,
7080 kDontMarkAcknowledged)); 7124 kDontMarkAcknowledged,
7125 kDontInstallImmediately));
7081 EXPECT_TRUE((info = pending->GetById(kGoodId))); 7126 EXPECT_TRUE((info = pending->GetById(kGoodId)));
7082 EXPECT_TRUE(info->version().IsValid()); 7127 EXPECT_TRUE(info->version().IsValid());
7083 EXPECT_TRUE(info->version().Equals(kVersion124)); 7128 EXPECT_TRUE(info->version().Equals(kVersion124));
7084 7129
7085 // Adding the latest version from the webstore overrides a specific version. 7130 // Adding the latest version from the webstore overrides a specific version.
7086 GURL kUpdateUrl("http://example.com/update"); 7131 GURL kUpdateUrl("http://example.com/update");
7087 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( 7132 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
7088 kGoodId, 7133 kGoodId,
7089 std::string(), 7134 std::string(),
7090 kUpdateUrl, 7135 kUpdateUrl,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7143 7188
7144 // Fake an external file from external_extensions.json. 7189 // Fake an external file from external_extensions.json.
7145 bool AddPendingExternalPrefFileInstall() { 7190 bool AddPendingExternalPrefFileInstall() {
7146 Version version("1.0.0.0"); 7191 Version version("1.0.0.0");
7147 7192
7148 return service()->OnExternalExtensionFileFound(crx_id_, 7193 return service()->OnExternalExtensionFileFound(crx_id_,
7149 &version, 7194 &version,
7150 crx_path_, 7195 crx_path_,
7151 Manifest::EXTERNAL_PREF, 7196 Manifest::EXTERNAL_PREF,
7152 Extension::NO_FLAGS, 7197 Extension::NO_FLAGS,
7198 false,
7153 false); 7199 false);
7154 } 7200 }
7155 7201
7156 // Fake a request from sync to install an extension. 7202 // Fake a request from sync to install an extension.
7157 bool AddPendingSyncInstall() { 7203 bool AddPendingSyncInstall() {
7158 return service()->pending_extension_manager()->AddFromSync( 7204 return service()->pending_extension_manager()->AddFromSync(
7159 crx_id_, 7205 crx_id_,
7160 GURL(kGoodUpdateURL), 7206 GURL(kGoodUpdateURL),
7161 &IsExtension, 7207 &IsExtension,
7162 kGoodRemoteInstall, 7208 kGoodRemoteInstall,
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
7632 7678
7633 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 7679 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7634 content::Source<Profile>(profile()), 7680 content::Source<Profile>(profile()),
7635 content::NotificationService::NoDetails()); 7681 content::NotificationService::NoDetails());
7636 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 7682 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7637 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 7683 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7638 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 7684 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7639 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 7685 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7640 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 7686 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7641 } 7687 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/external_policy_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698