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