OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/feature_list.h" | |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
18 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
19 #include "base/test/mock_entropy_provider.h" | 20 #include "base/test/mock_entropy_provider.h" |
20 #include "chrome/browser/extensions/component_loader.h" | 21 #include "chrome/browser/extensions/component_loader.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/extension_service_test_with_install.h" | 23 #include "chrome/browser/extensions/extension_service_test_with_install.h" |
23 #include "chrome/browser/extensions/extension_sync_data.h" | 24 #include "chrome/browser/extensions/extension_sync_data.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
45 #include "extensions/common/value_builder.h" | 46 #include "extensions/common/value_builder.h" |
46 #include "sync/api/fake_sync_change_processor.h" | 47 #include "sync/api/fake_sync_change_processor.h" |
47 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 48 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
48 #include "sync/api/sync_data.h" | 49 #include "sync/api/sync_data.h" |
49 #include "sync/api/sync_error_factory_mock.h" | 50 #include "sync/api/sync_error_factory_mock.h" |
50 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
51 | 52 |
52 #if defined(ENABLE_SUPERVISED_USERS) | 53 #if defined(ENABLE_SUPERVISED_USERS) |
53 #include "chrome/browser/supervised_user/permission_request_creator.h" | 54 #include "chrome/browser/supervised_user/permission_request_creator.h" |
54 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 55 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
56 #include "chrome/browser/supervised_user/supervised_user_features.h" | |
55 #include "chrome/browser/supervised_user/supervised_user_service.h" | 57 #include "chrome/browser/supervised_user/supervised_user_service.h" |
56 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 58 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
59 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | |
60 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" | |
61 #include "chrome/common/pref_names.h" | |
57 #endif | 62 #endif |
58 | 63 |
59 using extensions::AppSorting; | 64 using extensions::AppSorting; |
60 using extensions::Extension; | 65 using extensions::Extension; |
61 using extensions::ExtensionPrefs; | 66 using extensions::ExtensionPrefs; |
62 using extensions::ExtensionSyncData; | 67 using extensions::ExtensionSyncData; |
63 using extensions::ExtensionSystem; | 68 using extensions::ExtensionSystem; |
64 using extensions::Manifest; | 69 using extensions::Manifest; |
65 using extensions::PermissionSet; | 70 using extensions::PermissionSet; |
66 using syncer::SyncChange; | 71 using syncer::SyncChange; |
67 using syncer::SyncChangeList; | 72 using syncer::SyncChangeList; |
73 using testing::Mock; | |
68 | 74 |
69 namespace { | 75 namespace { |
70 | 76 |
71 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 77 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
72 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; | 78 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
73 const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 79 const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
74 const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; | 80 const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; |
75 const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 81 const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
76 | 82 |
77 SyncChangeList MakeSyncChangeList(const std::string& id, | 83 SyncChangeList MakeSyncChangeList(const std::string& id, |
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1562 // Group name doesn't matter. | 1568 // Group name doesn't matter. |
1563 base::FieldTrialList::CreateFieldTrial( | 1569 base::FieldTrialList::CreateFieldTrial( |
1564 "SupervisedUserExtensionPermissionIncrease", "group"); | 1570 "SupervisedUserExtensionPermissionIncrease", "group"); |
1565 std::map<std::string, std::string> params; | 1571 std::map<std::string, std::string> params; |
1566 params["legacy_supervised_user"] = enabled ? "true" : "false"; | 1572 params["legacy_supervised_user"] = enabled ? "true" : "false"; |
1567 params["child_account"] = enabled ? "true" : "false"; | 1573 params["child_account"] = enabled ? "true" : "false"; |
1568 variations::AssociateVariationParams( | 1574 variations::AssociateVariationParams( |
1569 "SupervisedUserExtensionPermissionIncrease", "group", params); | 1575 "SupervisedUserExtensionPermissionIncrease", "group", params); |
1570 } | 1576 } |
1571 | 1577 |
1578 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { | |
1579 base::FeatureList::ClearInstanceForTesting(); | |
1580 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
1581 if (enabled) { | |
1582 feature_list->InitializeFromCommandLine( | |
1583 "SupervisedUserInitiatedExtensionInstall", std::string()); | |
1584 } | |
1585 base::FeatureList::SetInstance(std::move(feature_list)); | |
1586 } | |
1587 | |
1572 void InitServices(bool profile_is_supervised) { | 1588 void InitServices(bool profile_is_supervised) { |
1573 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 1589 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
1574 params.profile_is_supervised = profile_is_supervised; | 1590 params.profile_is_supervised = profile_is_supervised; |
1591 // If profile is supervised, don't pass a pref file such that the testing | |
1592 // profile creates a pref service that uses SupervisedUserPrefStore. | |
1593 if (profile_is_supervised) { | |
1594 params.pref_file = base::FilePath(); | |
1595 } | |
1575 InitializeExtensionService(params); | 1596 InitializeExtensionService(params); |
1576 StartSyncing(syncer::EXTENSIONS); | 1597 StartSyncing(syncer::EXTENSIONS); |
1577 | 1598 |
1578 supervised_user_service()->SetDelegate(this); | 1599 supervised_user_service()->SetDelegate(this); |
1579 supervised_user_service()->Init(); | 1600 supervised_user_service()->Init(); |
1580 } | 1601 } |
1581 | 1602 |
1582 std::string InstallPermissionsTestExtension() { | 1603 std::string InstallPermissionsTestExtension(bool by_custodian) { |
1583 const std::string version("1"); | 1604 return InstallTestExtension(dir_path("1"), pem_path(), by_custodian); |
1584 | |
1585 const Extension* extension = | |
1586 PackAndInstallCRX(dir_path(version), pem_path(), INSTALL_NEW, | |
1587 Extension::WAS_INSTALLED_BY_CUSTODIAN); | |
1588 // The extension must now be installed and enabled. | |
1589 EXPECT_TRUE(extension); | |
1590 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | |
1591 EXPECT_EQ(version, extension->VersionString()); | |
1592 | |
1593 return extension->id(); | |
1594 } | 1605 } |
1595 | 1606 |
1596 void UpdatePermissionsTestExtension(const std::string& id, | 1607 void UpdatePermissionsTestExtension(const std::string& id, |
1597 const std::string& version, | 1608 const std::string& version, |
1598 UpdateState expected_state) { | 1609 UpdateState expected_state) { |
1599 PackCRXAndUpdateExtension(id, dir_path(version), pem_path(), | 1610 UpdateTestExtension(dir_path(version), pem_path(), id, version, |
1600 expected_state); | 1611 expected_state); |
1612 } | |
1613 | |
1614 std::string InstallNoPermissionsTestExtension(bool by_custodian) { | |
1615 const base::FilePath& base_path = data_dir().AppendASCII("autoupdate"); | |
Devlin
2016/06/21 16:54:37
nit: these shouldn't be const&, since they are cto
mamir
2016/06/23 11:43:20
Done.
| |
1616 const base::FilePath& pem_path = base_path.AppendASCII("key.pem"); | |
1617 const base::FilePath& dir_path = base_path.AppendASCII("v1"); | |
1618 | |
1619 return InstallTestExtension(dir_path, pem_path, by_custodian); | |
1620 } | |
1621 | |
1622 void UpdateNoPermissionsTestExtension(const std::string& id, | |
1623 const std::string& version, | |
1624 UpdateState expected_state) { | |
1625 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); | |
1626 base::FilePath pem_path = base_path.AppendASCII("key.pem"); | |
1627 base::FilePath dir_path = base_path.AppendASCII("v" + version); | |
1628 | |
1629 UpdateTestExtension(dir_path, pem_path, id, version, expected_state); | |
1630 } | |
1631 | |
1632 std::string InstallTestExtension(const base::FilePath& dir_path, | |
1633 const base::FilePath& pem_path, | |
1634 bool by_custodian) { | |
1635 const base::Version version("1"); | |
1636 int creation_flags = 0; | |
1637 InstallState expected_state = INSTALL_WITHOUT_LOAD; | |
1638 if (by_custodian) { | |
1639 creation_flags = Extension::WAS_INSTALLED_BY_CUSTODIAN; | |
1640 expected_state = INSTALL_NEW; | |
1641 } | |
1642 const Extension* extension = | |
1643 PackAndInstallCRX(dir_path, pem_path, expected_state, creation_flags); | |
1644 // The extension must now be installed. | |
1645 EXPECT_TRUE(extension); | |
1646 const std::string& id = extension->id(); | |
1647 if (by_custodian) { | |
1648 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
1649 } else { | |
1650 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile()); | |
1651 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | |
1652 EXPECT_TRUE(extension_prefs->HasDisableReason( | |
1653 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); | |
1654 } | |
1655 | |
1656 EXPECT_EQ(*extension->version(), version); | |
1657 | |
1658 return id; | |
1659 } | |
1660 | |
1661 void UpdateTestExtension(const base::FilePath& dir_path, | |
1662 const base::FilePath& pem_path, | |
1663 const std::string& id, | |
1664 const std::string& version, | |
1665 const UpdateState& expected_state) { | |
1666 PackCRXAndUpdateExtension(id, dir_path, pem_path, expected_state); | |
1601 const Extension* extension = registry()->GetInstalledExtension(id); | 1667 const Extension* extension = registry()->GetInstalledExtension(id); |
1602 ASSERT_TRUE(extension); | 1668 ASSERT_TRUE(extension); |
1603 // The version should have been updated. | 1669 // The version should have been updated. |
1604 EXPECT_EQ(version, extension->VersionString()); | 1670 EXPECT_EQ(*extension->version(), base::Version(version)); |
1671 } | |
1672 | |
1673 // Simulate a custodian approval for enabling the extension coming in | |
1674 // through Sync by adding the approved version to the map of approved | |
1675 // extensions. It doesn't simulate a change in the disable reasons. | |
1676 void SimulateCustodianApprovalViaSync(const std::string& extension_id, | |
1677 const std::string& version, | |
1678 SyncChange::SyncChangeType type) { | |
1679 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( | |
1680 supervised_users::kApprovedExtensions, extension_id); | |
1681 syncer::SyncData sync_data = | |
1682 SupervisedUserSettingsService::CreateSyncDataForSetting( | |
1683 key, base::StringValue(version)); | |
1684 | |
1685 SyncChangeList list(1, SyncChange(FROM_HERE, type, sync_data)); | |
1686 | |
1687 SupervisedUserSettingsService* supervised_user_settings_service = | |
1688 SupervisedUserSettingsServiceFactory::GetForProfile(profile()); | |
1689 supervised_user_settings_service->ProcessSyncChanges(FROM_HERE, list); | |
1605 } | 1690 } |
1606 | 1691 |
1607 SupervisedUserService* supervised_user_service() { | 1692 SupervisedUserService* supervised_user_service() { |
1608 return SupervisedUserServiceFactory::GetForProfile(profile()); | 1693 return SupervisedUserServiceFactory::GetForProfile(profile()); |
1609 } | 1694 } |
1610 | 1695 |
1611 static std::string UpdateRequestId(const std::string& extension_id, | 1696 static std::string RequestId(const std::string& extension_id, |
1612 const std::string& version) { | 1697 const std::string& version) { |
1613 return SupervisedUserService::GetExtensionUpdateRequestId( | 1698 return SupervisedUserService::GetExtensionRequestId( |
1614 extension_id, base::Version(version)); | 1699 extension_id, base::Version(version)); |
1615 } | 1700 } |
1616 | 1701 |
1617 private: | 1702 private: |
1618 // This prevents the legacy supervised user init code from running. | 1703 // This prevents the legacy supervised user init code from running. |
1619 bool SetActive(bool active) override { return true; } | 1704 bool SetActive(bool active) override { return true; } |
1620 | 1705 |
1621 base::FilePath base_path() const { | 1706 base::FilePath base_path() const { |
1622 return data_dir().AppendASCII("permissions_increase"); | 1707 return data_dir().AppendASCII("permissions_increase"); |
1623 } | 1708 } |
(...skipping 12 matching lines...) Expand all Loading... | |
1636 MockPermissionRequestCreator() {} | 1721 MockPermissionRequestCreator() {} |
1637 ~MockPermissionRequestCreator() override {} | 1722 ~MockPermissionRequestCreator() override {} |
1638 | 1723 |
1639 bool IsEnabled() const override { return true; } | 1724 bool IsEnabled() const override { return true; } |
1640 | 1725 |
1641 void CreateURLAccessRequest(const GURL& url_requested, | 1726 void CreateURLAccessRequest(const GURL& url_requested, |
1642 const SuccessCallback& callback) override { | 1727 const SuccessCallback& callback) override { |
1643 FAIL(); | 1728 FAIL(); |
1644 } | 1729 } |
1645 | 1730 |
1731 MOCK_METHOD2(CreateExtensionInstallRequest, | |
1732 void(const std::string& id, | |
1733 const SupervisedUserService::SuccessCallback& callback)); | |
1734 | |
1646 MOCK_METHOD2(CreateExtensionUpdateRequest, | 1735 MOCK_METHOD2(CreateExtensionUpdateRequest, |
1647 void(const std::string& id, | 1736 void(const std::string& id, |
1648 const SupervisedUserService::SuccessCallback& callback)); | 1737 const SupervisedUserService::SuccessCallback& callback)); |
1649 | 1738 |
1650 private: | 1739 private: |
1651 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); | 1740 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); |
1652 }; | 1741 }; |
1653 | 1742 |
1654 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { | 1743 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { |
1655 InitServices(true /* profile_is_supervised */); | 1744 InitServices(true /* profile_is_supervised */); |
1745 InitSupervisedUserInitiatedExtensionInstallFeature(false); | |
1656 | 1746 |
1657 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 1747 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
1658 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | 1748 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
1659 const Extension* extensions[] = { | 1749 const Extension* extensions[] = { |
1660 InstallCRX(path1, INSTALL_FAILED), | 1750 InstallCRX(path1, INSTALL_FAILED), |
1661 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) | 1751 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) |
1662 }; | 1752 }; |
1663 | 1753 |
1664 // Only the extension with the "installed by custodian" flag should have been | 1754 // Only the extension with the "installed by custodian" flag should have been |
1665 // installed and enabled. | 1755 // installed and enabled. |
1666 EXPECT_FALSE(extensions[0]); | 1756 EXPECT_FALSE(extensions[0]); |
1667 ASSERT_TRUE(extensions[1]); | 1757 ASSERT_TRUE(extensions[1]); |
1668 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | 1758 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); |
1669 } | 1759 } |
1670 | 1760 |
1671 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) { | 1761 TEST_F(ExtensionServiceTestSupervised, |
1762 InstallAllowedByCustodianAndSupervisedUser) { | |
1763 InitServices(true /* profile_is_supervised */); | |
1764 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
1765 | |
1766 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | |
1767 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | |
1768 const Extension* extensions[] = { | |
1769 InstallCRX(path1, INSTALL_WITHOUT_LOAD), | |
1770 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) | |
1771 }; | |
1772 | |
1773 // Only the extension with the "installed by custodian" flag should have been | |
1774 // installed and enabled. | |
1775 // The extension missing the "installed by custodian" flag is a | |
1776 // supervised user initiated install and hence not enabled. | |
1777 ASSERT_TRUE(extensions[0]); | |
1778 ASSERT_TRUE(extensions[1]); | |
1779 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id())); | |
1780 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | |
1781 } | |
1782 | |
1783 TEST_F(ExtensionServiceTestSupervised, | |
1784 PreinstalledExtensionWithSUInitiatedInstalls) { | |
1672 InitServices(false /* profile_is_supervised */); | 1785 InitServices(false /* profile_is_supervised */); |
1786 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
1673 | 1787 |
1674 // Install an extension. | 1788 // Install an extension. |
1675 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1789 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1676 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 1790 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
1677 std::string id = extension->id(); | 1791 std::string id = extension->id(); |
1792 // Make sure it's enabled. | |
1793 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
1794 | |
1795 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
1796 supervised_user_service()->AddPermissionRequestCreator( | |
1797 base::WrapUnique(creator)); | |
1798 const std::string version("1.0.0.0"); | |
1799 | |
1800 EXPECT_CALL(*creator, CreateExtensionInstallRequest( | |
1801 RequestId(good_crx, version), testing::_)); | |
1802 | |
1803 // Now make the profile supervised. | |
1804 profile()->AsTestingProfile()->SetSupervisedUserId( | |
1805 supervised_users::kChildAccountSUID); | |
1806 | |
1807 Mock::VerifyAndClearExpectations(creator); | |
1808 | |
1809 // The extension should not be enabled anymore. | |
1810 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
1811 | |
1812 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile()); | |
1813 EXPECT_TRUE(extension_prefs->HasDisableReason( | |
1814 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); | |
1815 } | |
1816 | |
1817 TEST_F(ExtensionServiceTestSupervised, | |
1818 PreinstalledExtensionWithoutSUInitiatedInstalls) { | |
1819 InitServices(false /* profile_is_supervised */); | |
1820 InitSupervisedUserInitiatedExtensionInstallFeature(false); | |
1821 | |
1822 // Install an extension. | |
1823 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
1824 const Extension* extension = InstallCRX(path, INSTALL_NEW); | |
1825 std::string id = extension->id(); | |
1826 // Make sure it's enabled. | |
1827 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
1828 | |
1829 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
1830 supervised_user_service()->AddPermissionRequestCreator( | |
1831 base::WrapUnique(creator)); | |
1832 const std::string version("1.0.0.0"); | |
1833 | |
1834 // No request should be sent because supervised user initiated installs | |
1835 // are disabled. | |
1836 EXPECT_CALL(*creator, CreateExtensionInstallRequest(testing::_, testing::_)) | |
1837 .Times(0); | |
1678 | 1838 |
1679 // Now make the profile supervised. | 1839 // Now make the profile supervised. |
1680 profile()->AsTestingProfile()->SetSupervisedUserId( | 1840 profile()->AsTestingProfile()->SetSupervisedUserId( |
1681 supervised_users::kChildAccountSUID); | 1841 supervised_users::kChildAccountSUID); |
1682 | 1842 |
1683 // The extension should not be enabled anymore. | 1843 // The extension should not be enabled anymore. |
1684 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 1844 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
1845 | |
1846 extensions::ExtensionPrefs* extension_prefs = | |
1847 extensions::ExtensionPrefs::Get(profile()); | |
1848 EXPECT_TRUE(extension_prefs->HasDisableReason( | |
1849 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); | |
1850 } | |
1851 | |
1852 TEST_F(ExtensionServiceTestSupervised, ExtensionApprovalBeforeInstallation) { | |
1853 // This tests the case when the sync entity flagging the extension as approved | |
1854 // arrives before the extension itself is installed. | |
1855 InitServices(true /* profile_is_supervised */); | |
1856 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
1857 | |
1858 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
1859 supervised_user_service()->AddPermissionRequestCreator( | |
1860 base::WrapUnique(creator)); | |
1861 | |
1862 std::string id = good_crx; | |
1863 std::string version("1.0.0.0"); | |
1864 | |
1865 SimulateCustodianApprovalViaSync(id, version, SyncChange::ACTION_ADD); | |
1866 | |
1867 // Now install an extension. | |
1868 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
1869 InstallCRX(path, INSTALL_NEW); | |
1870 | |
1871 // No approval request should be sent. | |
1872 EXPECT_CALL(*creator, CreateExtensionInstallRequest(testing::_, testing::_)) | |
1873 .Times(0); | |
1874 | |
1875 // Make sure it's enabled. | |
1876 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
1685 } | 1877 } |
1686 | 1878 |
1687 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { | 1879 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { |
1688 InitServices(true /* profile_is_supervised */); | 1880 InitServices(true /* profile_is_supervised */); |
1689 | 1881 |
1690 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); | |
1691 base::FilePath pem_path = base_path.AppendASCII("key.pem"); | |
1692 | |
1693 const Extension* extension = | |
1694 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW, | |
1695 Extension::WAS_INSTALLED_BY_CUSTODIAN); | |
1696 // The extension must now be installed and enabled. | |
1697 ASSERT_TRUE(extension); | |
1698 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | |
1699 | |
1700 // Save the id, as the extension object will be destroyed during updating. | 1882 // Save the id, as the extension object will be destroyed during updating. |
1701 std::string id = extension->id(); | 1883 std::string id = InstallNoPermissionsTestExtension(true /* by_custodian */); |
1702 | |
1703 std::string old_version = extension->VersionString(); | |
1704 | 1884 |
1705 // Update to a new version. | 1885 // Update to a new version. |
1706 PackCRXAndUpdateExtension(id, base_path.AppendASCII("v2"), pem_path, ENABLED); | 1886 std::string version2("2"); |
1887 UpdateNoPermissionsTestExtension(id, version2, ENABLED); | |
1707 | 1888 |
1708 // The extension should still be there and enabled. | 1889 // The extension should still be there and enabled. |
1709 extension = registry()->enabled_extensions().GetByID(id); | 1890 const Extension* extension = registry()->enabled_extensions().GetByID(id); |
1710 ASSERT_TRUE(extension); | 1891 ASSERT_TRUE(extension); |
1711 // The version should have changed. | 1892 // The version should have changed. |
1712 EXPECT_NE(extension->VersionString(), old_version); | 1893 EXPECT_EQ(*extension->version(), base::Version(version2)); |
1713 } | 1894 } |
1714 | 1895 |
1715 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { | 1896 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { |
1716 InitNeedCustodianApprovalFieldTrial(false); | 1897 InitNeedCustodianApprovalFieldTrial(false); |
1717 | 1898 |
1718 InitServices(true /* profile_is_supervised */); | 1899 InitServices(true /* profile_is_supervised */); |
1719 | 1900 |
1720 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1901 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1721 supervised_user_service()->AddPermissionRequestCreator( | 1902 supervised_user_service()->AddPermissionRequestCreator( |
1722 base::WrapUnique(creator)); | 1903 base::WrapUnique(creator)); |
1723 | 1904 |
1724 std::string id = InstallPermissionsTestExtension(); | 1905 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
1725 | 1906 |
1726 // Update to a new version with increased permissions. | 1907 // Update to a new version with increased permissions. |
1727 // Since we don't require the custodian's approval, no permission request | 1908 // Since we don't require the custodian's approval, no permission request |
1728 // should be created. | 1909 // should be created. |
1729 const std::string version2("2"); | 1910 const std::string version2("2"); |
1730 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1911 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1731 UpdateRequestId(id, version2), testing::_)) | 1912 RequestId(id, version2), testing::_)) |
1732 .Times(0); | 1913 .Times(0); |
1733 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1914 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1734 } | 1915 } |
1735 | 1916 |
1736 TEST_F(ExtensionServiceTestSupervised, | 1917 TEST_F(ExtensionServiceTestSupervised, |
1737 UpdateWithPermissionIncreaseApprovalOldVersion) { | 1918 UpdateWithPermissionIncreaseApprovalOldVersion) { |
1738 InitNeedCustodianApprovalFieldTrial(true); | 1919 InitNeedCustodianApprovalFieldTrial(true); |
1739 | 1920 |
1740 InitServices(true /* profile_is_supervised */); | 1921 InitServices(true /* profile_is_supervised */); |
1741 | 1922 |
1742 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1923 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1743 supervised_user_service()->AddPermissionRequestCreator( | 1924 supervised_user_service()->AddPermissionRequestCreator( |
1744 base::WrapUnique(creator)); | 1925 base::WrapUnique(creator)); |
1745 | 1926 |
1746 const std::string version1("1"); | 1927 const std::string version1("1"); |
1747 const std::string version2("2"); | 1928 const std::string version2("2"); |
1748 | 1929 |
1749 std::string id = InstallPermissionsTestExtension(); | 1930 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
1750 | 1931 |
1751 // Update to a new version with increased permissions. | 1932 // Update to a new version with increased permissions. |
1752 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1933 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1753 UpdateRequestId(id, version2), testing::_)); | 1934 RequestId(id, version2), testing::_)); |
1754 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1935 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1936 Mock::VerifyAndClearExpectations(creator); | |
1755 | 1937 |
1756 // Simulate a custodian approval for re-enabling the extension coming in | 1938 // Simulate a custodian approval for re-enabling the extension coming in |
1757 // through Sync, but set the old version. This can happen when there already | 1939 // through Sync, but set the old version. This can happen when there already |
1758 // was a pending request for an earlier version of the extension. | 1940 // was a pending request for an earlier version of the extension. |
1759 sync_pb::EntitySpecifics specifics; | 1941 sync_pb::EntitySpecifics specifics; |
1760 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1942 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
1761 ext_specifics->set_id(id); | 1943 ext_specifics->set_id(id); |
1762 ext_specifics->set_enabled(true); | 1944 ext_specifics->set_enabled(true); |
1763 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 1945 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
1764 ext_specifics->set_installed_by_custodian(true); | 1946 ext_specifics->set_installed_by_custodian(true); |
1765 ext_specifics->set_version(version1); | 1947 ext_specifics->set_version(version1); |
1766 | 1948 |
1767 // Attempting to re-enable an old version should result in a permission | 1949 // Attempting to re-enable an old version should result in a permission |
1768 // request for the current version. | 1950 // request for the current version. |
1769 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1951 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1770 UpdateRequestId(id, version2), testing::_)); | 1952 RequestId(id, version2), testing::_)); |
1771 | 1953 |
1772 SyncChangeList list = | 1954 SyncChangeList list = |
1773 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 1955 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
1774 | 1956 |
1775 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 1957 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
1776 // The re-enable should be ignored, since the version doesn't match. | 1958 // The re-enable should be ignored, since the version doesn't match. |
1777 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 1959 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
1778 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 1960 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
1779 id, base::Version(version1))); | 1961 id, base::Version(version1))); |
1780 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 1962 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
1781 id, base::Version(version2))); | 1963 id, base::Version(version2))); |
1964 Mock::VerifyAndClearExpectations(creator); | |
1782 } | 1965 } |
1783 | 1966 |
1784 TEST_F(ExtensionServiceTestSupervised, | 1967 TEST_F(ExtensionServiceTestSupervised, |
1785 UpdateWithPermissionIncreaseApprovalMatchingVersion) { | 1968 UpdateWithPermissionIncreaseApprovalMatchingVersion) { |
1786 InitNeedCustodianApprovalFieldTrial(true); | 1969 InitNeedCustodianApprovalFieldTrial(true); |
1787 | 1970 |
1788 InitServices(true /* profile_is_supervised */); | 1971 InitServices(true /* profile_is_supervised */); |
1789 | 1972 |
1790 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1973 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1791 supervised_user_service()->AddPermissionRequestCreator( | 1974 supervised_user_service()->AddPermissionRequestCreator( |
1792 base::WrapUnique(creator)); | 1975 base::WrapUnique(creator)); |
1793 | 1976 |
1794 std::string id = InstallPermissionsTestExtension(); | 1977 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
1795 | 1978 |
1796 // Update to a new version with increased permissions. | 1979 // Update to a new version with increased permissions. |
1797 const std::string version2("2"); | 1980 const std::string version2("2"); |
1798 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1981 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1799 UpdateRequestId(id, version2), testing::_)); | 1982 RequestId(id, version2), testing::_)); |
1800 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1983 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1984 Mock::VerifyAndClearExpectations(creator); | |
1801 | 1985 |
1802 // Simulate a custodian approval for re-enabling the extension coming in | 1986 // Simulate a custodian approval for re-enabling the extension coming in |
1803 // through Sync. | 1987 // through Sync. |
1804 sync_pb::EntitySpecifics specifics; | 1988 sync_pb::EntitySpecifics specifics; |
1805 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1989 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
1806 ext_specifics->set_id(id); | 1990 ext_specifics->set_id(id); |
1807 ext_specifics->set_enabled(true); | 1991 ext_specifics->set_enabled(true); |
1808 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 1992 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
1809 ext_specifics->set_installed_by_custodian(true); | 1993 ext_specifics->set_installed_by_custodian(true); |
1810 ext_specifics->set_version(version2); | 1994 ext_specifics->set_version(version2); |
1811 | 1995 |
1812 SyncChangeList list = | 1996 SyncChangeList list = |
1813 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 1997 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
1814 | 1998 |
1815 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 1999 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
1816 // The extension should have gotten re-enabled. | 2000 // The extension should have gotten re-enabled. |
1817 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2001 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
1818 } | 2002 } |
1819 | 2003 |
1820 TEST_F(ExtensionServiceTestSupervised, | 2004 TEST_F(ExtensionServiceTestSupervised, |
1821 UpdateWithPermissionIncreaseApprovalNewVersion) { | 2005 UpdateWithPermissionIncreaseApprovalNewVersion) { |
1822 InitNeedCustodianApprovalFieldTrial(true); | 2006 InitNeedCustodianApprovalFieldTrial(true); |
1823 | 2007 |
1824 InitServices(true /* profile_is_supervised */); | 2008 InitServices(true /* profile_is_supervised */); |
1825 | 2009 |
1826 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2010 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1827 supervised_user_service()->AddPermissionRequestCreator( | 2011 supervised_user_service()->AddPermissionRequestCreator( |
1828 base::WrapUnique(creator)); | 2012 base::WrapUnique(creator)); |
1829 | 2013 |
1830 std::string id = InstallPermissionsTestExtension(); | 2014 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
1831 | 2015 |
1832 // Update to a new version with increased permissions. | 2016 // Update to a new version with increased permissions. |
1833 const std::string version2("2"); | 2017 const std::string version2("2"); |
1834 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 2018 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1835 UpdateRequestId(id, version2), testing::_)); | 2019 RequestId(id, version2), testing::_)); |
1836 UpdatePermissionsTestExtension(id, version2, DISABLED); | 2020 UpdatePermissionsTestExtension(id, version2, DISABLED); |
2021 Mock::VerifyAndClearExpectations(creator); | |
1837 | 2022 |
1838 // Simulate a custodian approval for re-enabling the extension coming in | 2023 // Simulate a custodian approval for re-enabling the extension coming in |
1839 // through Sync. Set a newer version than we have installed. | 2024 // through Sync. Set a newer version than we have installed. |
1840 const std::string version3("3"); | 2025 const std::string version3("3"); |
1841 sync_pb::EntitySpecifics specifics; | 2026 sync_pb::EntitySpecifics specifics; |
1842 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 2027 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
1843 ext_specifics->set_id(id); | 2028 ext_specifics->set_id(id); |
1844 ext_specifics->set_enabled(true); | 2029 ext_specifics->set_enabled(true); |
1845 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 2030 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
1846 ext_specifics->set_installed_by_custodian(true); | 2031 ext_specifics->set_installed_by_custodian(true); |
1847 ext_specifics->set_version(version3); | 2032 ext_specifics->set_version(version3); |
1848 | 2033 |
1849 // This should *not* result in a new permission request. | 2034 // This should *not* result in a new permission request. |
1850 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 2035 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1851 UpdateRequestId(id, version3), testing::_)) | 2036 RequestId(id, version3), testing::_)) |
1852 .Times(0); | 2037 .Times(0); |
1853 | 2038 |
1854 SyncChangeList list = | 2039 SyncChangeList list = |
1855 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 2040 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
1856 | 2041 |
1857 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 2042 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
1858 // The re-enable should be delayed until the extension is updated to the | 2043 // The re-enable should be delayed until the extension is updated to the |
1859 // matching version. | 2044 // matching version. |
1860 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 2045 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
1861 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( | 2046 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( |
1862 id, base::Version(version3))); | 2047 id, base::Version(version3))); |
1863 | 2048 |
1864 // Update to the matching version. Now the extension should get enabled. | 2049 // Update to the matching version. Now the extension should get enabled. |
1865 UpdatePermissionsTestExtension(id, version3, ENABLED); | 2050 UpdatePermissionsTestExtension(id, version3, ENABLED); |
1866 } | 2051 } |
1867 | 2052 |
2053 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) { | |
2054 InitNeedCustodianApprovalFieldTrial(true); | |
2055 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
2056 | |
2057 InitServices(true /* profile_is_supervised */); | |
2058 | |
2059 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
2060 supervised_user_service()->AddPermissionRequestCreator( | |
2061 base::WrapUnique(creator)); | |
2062 | |
2063 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
2064 std::string version("1.0.0.0"); | |
2065 | |
2066 EXPECT_CALL(*creator, CreateExtensionInstallRequest( | |
2067 RequestId(good_crx, version), testing::_)); | |
2068 | |
2069 // Should be installed but disabled, a request for approval should be sent. | |
2070 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD); | |
2071 ASSERT_TRUE(extension); | |
2072 ASSERT_EQ(extension->id(), good_crx); | |
2073 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); | |
2074 Mock::VerifyAndClearExpectations(creator); | |
2075 | |
2076 SimulateCustodianApprovalViaSync(good_crx, version, SyncChange::ACTION_ADD); | |
2077 | |
2078 // The extension should be enabled now. | |
2079 EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx)); | |
2080 } | |
2081 | |
2082 TEST_F(ExtensionServiceTestSupervised, | |
2083 UpdateSUInitiatedInstallWithoutPermissionIncrease) { | |
2084 InitNeedCustodianApprovalFieldTrial(true); | |
2085 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
2086 | |
2087 InitServices(true /* profile_is_supervised */); | |
2088 | |
2089 std::string id = InstallNoPermissionsTestExtension(false /* by_custodian */); | |
2090 std::string version1("1"); | |
2091 | |
2092 SimulateCustodianApprovalViaSync(id, version1, SyncChange::ACTION_ADD); | |
2093 | |
2094 // The extension should be enabled now. | |
2095 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
2096 | |
2097 std::string version2("2"); | |
2098 | |
2099 // Update to a new version. | |
2100 UpdateNoPermissionsTestExtension(id, version2, ENABLED); | |
2101 | |
2102 // The extension should still be there and enabled. | |
2103 const Extension* extension = registry()->enabled_extensions().GetByID(id); | |
2104 ASSERT_TRUE(extension); | |
2105 // The version should have increased. | |
2106 EXPECT_EQ(1, extension->version()->CompareTo(base::Version(version1))); | |
2107 | |
2108 // Check that the approved version has been updated in the prefs as well. | |
2109 // Prefs are updated via Sync. If the prefs are updated, then the new | |
2110 // approved version has been pushed to Sync as well. | |
2111 std::string approved_version; | |
2112 PrefService* pref_service = profile()->GetPrefs(); | |
2113 const base::DictionaryValue* approved_extensions = | |
2114 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions); | |
2115 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version); | |
2116 | |
2117 EXPECT_EQ(0, | |
2118 extension->version()->CompareTo(base::Version(approved_version))); | |
2119 } | |
2120 | |
2121 TEST_F(ExtensionServiceTestSupervised, | |
2122 UpdateSUInitiatedInstallWithPermissionIncrease) { | |
2123 InitNeedCustodianApprovalFieldTrial(true); | |
2124 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
2125 | |
2126 InitServices(true /* profile_is_supervised */); | |
2127 | |
2128 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); | |
2129 std::string version1("1"); | |
2130 | |
2131 SimulateCustodianApprovalViaSync(id, version1, SyncChange::ACTION_ADD); | |
2132 | |
2133 // The extension should be enabled now. | |
2134 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
2135 | |
2136 std::string version3("3"); | |
2137 | |
2138 UpdatePermissionsTestExtension(id, version3, DISABLED); | |
2139 | |
2140 // The extension should be disabled. | |
2141 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
2142 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( | |
2143 id, Extension::DISABLE_PERMISSIONS_INCREASE)); | |
2144 | |
2145 std::string version2("2"); | |
2146 // Approve an older version | |
2147 SimulateCustodianApprovalViaSync(id, version2, SyncChange::ACTION_UPDATE); | |
2148 | |
2149 // The extension should remain disabled. | |
2150 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
2151 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( | |
2152 id, Extension::DISABLE_PERMISSIONS_INCREASE)); | |
2153 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( | |
2154 id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); | |
2155 | |
2156 // Approve the latest version | |
2157 SimulateCustodianApprovalViaSync(id, version3, SyncChange::ACTION_UPDATE); | |
2158 | |
2159 // The extension should be enabled again. | |
2160 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
2161 } | |
2162 | |
2163 TEST_F(ExtensionServiceTestSupervised, | |
2164 UpdateSUInitiatedInstallWithPermissionIncreaseApprovalArrivesFirst) { | |
2165 InitNeedCustodianApprovalFieldTrial(true); | |
2166 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
2167 | |
2168 InitServices(true /* profile_is_supervised */); | |
2169 | |
2170 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); | |
2171 | |
2172 std::string version1("1"); | |
2173 SimulateCustodianApprovalViaSync(id, version1, SyncChange::ACTION_ADD); | |
2174 | |
2175 // The extension should be enabled now. | |
2176 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
2177 | |
2178 std::string version2("2"); | |
2179 // Approve a newer version | |
2180 SimulateCustodianApprovalViaSync(id, version2, SyncChange::ACTION_UPDATE); | |
2181 | |
2182 // The extension should be disabled. | |
2183 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | |
2184 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( | |
2185 id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); | |
2186 | |
2187 // Now update the extension to the same version that was approved. | |
2188 UpdatePermissionsTestExtension(id, version2, ENABLED); | |
2189 // The extension should be enabled again. | |
2190 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
2191 } | |
2192 | |
1868 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { | 2193 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { |
1869 InitializeEmptyExtensionService(); | 2194 InitializeEmptyExtensionService(); |
1870 extension_sync_service()->MergeDataAndStartSyncing( | 2195 extension_sync_service()->MergeDataAndStartSyncing( |
1871 syncer::EXTENSIONS, syncer::SyncDataList(), | 2196 syncer::EXTENSIONS, syncer::SyncDataList(), |
1872 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), | 2197 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
1873 base::WrapUnique(new syncer::SyncErrorFactoryMock())); | 2198 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
1874 | 2199 |
1875 // Install two extensions. | 2200 // Install two extensions. |
1876 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 2201 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
1877 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | 2202 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2054 break; | 2379 break; |
2055 } | 2380 } |
2056 } | 2381 } |
2057 } | 2382 } |
2058 EXPECT_TRUE(found_delete); | 2383 EXPECT_TRUE(found_delete); |
2059 | 2384 |
2060 // Make sure there is one extension, and there are no more apps. | 2385 // Make sure there is one extension, and there are no more apps. |
2061 EXPECT_EQ(1u, extensions_processor.data().size()); | 2386 EXPECT_EQ(1u, extensions_processor.data().size()); |
2062 EXPECT_TRUE(apps_processor.data().empty()); | 2387 EXPECT_TRUE(apps_processor.data().empty()); |
2063 } | 2388 } |
OLD | NEW |