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" | |
57 #endif | 61 #endif |
58 | 62 |
59 using extensions::AppSorting; | 63 using extensions::AppSorting; |
60 using extensions::Extension; | 64 using extensions::Extension; |
61 using extensions::ExtensionPrefs; | 65 using extensions::ExtensionPrefs; |
62 using extensions::ExtensionSyncData; | 66 using extensions::ExtensionSyncData; |
63 using extensions::ExtensionSystem; | 67 using extensions::ExtensionSystem; |
64 using extensions::Manifest; | 68 using extensions::Manifest; |
65 using extensions::PermissionSet; | 69 using extensions::PermissionSet; |
66 using syncer::SyncChange; | 70 using syncer::SyncChange; |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1562 // Group name doesn't matter. | 1566 // Group name doesn't matter. |
1563 base::FieldTrialList::CreateFieldTrial( | 1567 base::FieldTrialList::CreateFieldTrial( |
1564 "SupervisedUserExtensionPermissionIncrease", "group"); | 1568 "SupervisedUserExtensionPermissionIncrease", "group"); |
1565 std::map<std::string, std::string> params; | 1569 std::map<std::string, std::string> params; |
1566 params["legacy_supervised_user"] = enabled ? "true" : "false"; | 1570 params["legacy_supervised_user"] = enabled ? "true" : "false"; |
1567 params["child_account"] = enabled ? "true" : "false"; | 1571 params["child_account"] = enabled ? "true" : "false"; |
1568 variations::AssociateVariationParams( | 1572 variations::AssociateVariationParams( |
1569 "SupervisedUserExtensionPermissionIncrease", "group", params); | 1573 "SupervisedUserExtensionPermissionIncrease", "group", params); |
1570 } | 1574 } |
1571 | 1575 |
1576 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { | |
1577 base::FeatureList::ClearInstanceForTesting(); | |
1578 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
1579 if (enabled) { | |
1580 feature_list->InitializeFromCommandLine( | |
1581 "SupervisedUserInitiatedExtensionInstall", std::string()); | |
1582 } | |
1583 base::FeatureList::SetInstance(std::move(feature_list)); | |
1584 } | |
1585 | |
1572 void InitServices(bool profile_is_supervised) { | 1586 void InitServices(bool profile_is_supervised) { |
1573 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 1587 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
1574 params.profile_is_supervised = profile_is_supervised; | 1588 params.profile_is_supervised = profile_is_supervised; |
1589 // If profile is supervised, don't pass a pref file to force the testing | |
1590 // profile to create a pref service to uses SupervisedUserPrefStore instead. | |
Marc Treib
2016/05/24 09:54:57
some comment nits:
You're not *forcing* the testin
mamir
2016/06/03 09:45:54
Done.
| |
1591 if (profile_is_supervised) { | |
1592 params.pref_file = base::FilePath(); | |
1593 } | |
1575 InitializeExtensionService(params); | 1594 InitializeExtensionService(params); |
1576 StartSyncing(syncer::EXTENSIONS); | 1595 StartSyncing(syncer::EXTENSIONS); |
1577 | 1596 |
1578 supervised_user_service()->SetDelegate(this); | 1597 supervised_user_service()->SetDelegate(this); |
1579 supervised_user_service()->Init(); | 1598 supervised_user_service()->Init(); |
1580 } | 1599 } |
1581 | 1600 |
1582 std::string InstallPermissionsTestExtension() { | 1601 std::string InstallPermissionsTestExtension() { |
1583 const std::string version("1"); | 1602 const std::string version("1"); |
1584 | 1603 |
(...skipping 16 matching lines...) Expand all Loading... | |
1601 const Extension* extension = registry()->GetInstalledExtension(id); | 1620 const Extension* extension = registry()->GetInstalledExtension(id); |
1602 ASSERT_TRUE(extension); | 1621 ASSERT_TRUE(extension); |
1603 // The version should have been updated. | 1622 // The version should have been updated. |
1604 EXPECT_EQ(version, extension->VersionString()); | 1623 EXPECT_EQ(version, extension->VersionString()); |
1605 } | 1624 } |
1606 | 1625 |
1607 SupervisedUserService* supervised_user_service() { | 1626 SupervisedUserService* supervised_user_service() { |
1608 return SupervisedUserServiceFactory::GetForProfile(profile()); | 1627 return SupervisedUserServiceFactory::GetForProfile(profile()); |
1609 } | 1628 } |
1610 | 1629 |
1611 static std::string UpdateRequestId(const std::string& extension_id, | 1630 static std::string RequestId(const std::string& extension_id, |
1612 const std::string& version) { | 1631 const std::string& version) { |
1613 return SupervisedUserService::GetExtensionUpdateRequestId( | 1632 return SupervisedUserService::GetExtensionRequestId( |
1614 extension_id, base::Version(version)); | 1633 extension_id, base::Version(version)); |
1615 } | 1634 } |
1616 | 1635 |
1617 private: | 1636 private: |
1618 // This prevents the legacy supervised user init code from running. | 1637 // This prevents the legacy supervised user init code from running. |
1619 bool SetActive(bool active) override { return true; } | 1638 bool SetActive(bool active) override { return true; } |
1620 | 1639 |
1621 base::FilePath base_path() const { | 1640 base::FilePath base_path() const { |
1622 return data_dir().AppendASCII("permissions_increase"); | 1641 return data_dir().AppendASCII("permissions_increase"); |
1623 } | 1642 } |
(...skipping 12 matching lines...) Expand all Loading... | |
1636 MockPermissionRequestCreator() {} | 1655 MockPermissionRequestCreator() {} |
1637 ~MockPermissionRequestCreator() override {} | 1656 ~MockPermissionRequestCreator() override {} |
1638 | 1657 |
1639 bool IsEnabled() const override { return true; } | 1658 bool IsEnabled() const override { return true; } |
1640 | 1659 |
1641 void CreateURLAccessRequest(const GURL& url_requested, | 1660 void CreateURLAccessRequest(const GURL& url_requested, |
1642 const SuccessCallback& callback) override { | 1661 const SuccessCallback& callback) override { |
1643 FAIL(); | 1662 FAIL(); |
1644 } | 1663 } |
1645 | 1664 |
1665 MOCK_METHOD2(CreateExtensionInstallRequest, | |
1666 void(const std::string& id, | |
1667 const SupervisedUserService::SuccessCallback& callback)); | |
1668 | |
1646 MOCK_METHOD2(CreateExtensionUpdateRequest, | 1669 MOCK_METHOD2(CreateExtensionUpdateRequest, |
1647 void(const std::string& id, | 1670 void(const std::string& id, |
1648 const SupervisedUserService::SuccessCallback& callback)); | 1671 const SupervisedUserService::SuccessCallback& callback)); |
1649 | 1672 |
1650 private: | 1673 private: |
1651 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); | 1674 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); |
1652 }; | 1675 }; |
1653 | 1676 |
1654 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { | 1677 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { |
1655 InitServices(true /* profile_is_supervised */); | 1678 InitServices(true /* profile_is_supervised */); |
1679 InitSupervisedUserInitiatedExtensionInstallFeature(false); | |
1656 | 1680 |
1657 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 1681 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
1658 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | 1682 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
1659 const Extension* extensions[] = { | 1683 const Extension* extensions[] = { |
1660 InstallCRX(path1, INSTALL_FAILED), | 1684 InstallCRX(path1, INSTALL_FAILED), |
1661 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) | 1685 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) |
1662 }; | 1686 }; |
1663 | 1687 |
1664 // Only the extension with the "installed by custodian" flag should have been | 1688 // Only the extension with the "installed by custodian" flag should have been |
1665 // installed and enabled. | 1689 // installed and enabled. |
1690 // While the extension missing the flag is a supervised user initiated install | |
Marc Treib
2016/05/24 09:54:57
not a complete sentence :)
TBH I'd just drop this
mamir
2016/06/03 09:45:54
Done.
| |
1691 // and hence it is not installed. | |
1666 EXPECT_FALSE(extensions[0]); | 1692 EXPECT_FALSE(extensions[0]); |
1667 ASSERT_TRUE(extensions[1]); | 1693 ASSERT_TRUE(extensions[1]); |
1668 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | 1694 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); |
1669 } | 1695 } |
1670 | 1696 |
1671 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) { | 1697 TEST_F(ExtensionServiceTestSupervised, |
1698 InstallAllowedByCustodianAndSupervisedUser) { | |
1699 InitServices(true /* profile_is_supervised */); | |
1700 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
1701 | |
1702 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | |
1703 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | |
1704 const Extension* extensions[] = { | |
1705 InstallCRX(path1, INSTALL_WITHOUT_LOAD), | |
1706 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)}; | |
1707 | |
1708 // Only the extension with the "installed by custodian" flag should have been | |
1709 // installed and enabled. | |
1710 // The extension missing the "installed by custodian" flag is a | |
1711 // supervised user initiated install and hence not allowed. | |
Marc Treib
2016/05/24 09:54:57
"not allowed" isn't really accurate - installing i
mamir
2016/06/03 09:45:54
Done.
| |
1712 ASSERT_TRUE(extensions[0]); | |
1713 ASSERT_TRUE(extensions[1]); | |
1714 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id())); | |
1715 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | |
1716 } | |
1717 | |
1718 TEST_F(ExtensionServiceTestSupervised, | |
1719 PreinstalledExtensionWithSUInitiatedInstallsEnabled) { | |
Marc Treib
2016/05/24 09:54:57
just PreinstalledExtensionWithSUInitiatedInstalls?
mamir
2016/06/03 09:45:54
Done.
| |
1672 InitServices(false /* profile_is_supervised */); | 1720 InitServices(false /* profile_is_supervised */); |
1721 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
1673 | 1722 |
1674 // Install an extension. | 1723 // Install an extension. |
1675 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1724 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1676 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 1725 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
1677 std::string id = extension->id(); | 1726 std::string id = extension->id(); |
1727 // Make sure it's enabled. | |
1728 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
1729 | |
1730 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
1731 supervised_user_service()->AddPermissionRequestCreator( | |
1732 base::WrapUnique(creator)); | |
1733 const std::string version("1.0.0.0"); | |
1734 | |
1735 EXPECT_CALL(*creator, CreateExtensionInstallRequest( | |
1736 RequestId(good_crx, version), testing::_)); | |
1678 | 1737 |
1679 // Now make the profile supervised. | 1738 // Now make the profile supervised. |
1680 profile()->AsTestingProfile()->SetSupervisedUserId( | 1739 profile()->AsTestingProfile()->SetSupervisedUserId( |
1740 supervised_users::kChildAccountSUID); | |
1741 | |
1742 // The extension should not be enabled anymore. | |
1743 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
Marc Treib
2016/05/24 09:54:57
Also check that it has the proper disable reason?
mamir
2016/06/03 09:45:54
Done.
| |
1744 } | |
1745 | |
1746 TEST_F(ExtensionServiceTestSupervised, | |
1747 PreinstalledExtensionWithSUInitiatedInstallsDisabled) { | |
Marc Treib
2016/05/24 09:54:57
PreinstalledExtensionWithoutSUInitiatedInstalls?
mamir
2016/06/03 09:45:54
Done.
| |
1748 InitServices(false /* profile_is_supervised */); | |
1749 InitSupervisedUserInitiatedExtensionInstallFeature(false); | |
1750 | |
1751 // Install an extension. | |
1752 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
1753 const Extension* extension = InstallCRX(path, INSTALL_NEW); | |
1754 std::string id = extension->id(); | |
1755 // Make sure it's enabled. | |
1756 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
1757 | |
1758 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
1759 supervised_user_service()->AddPermissionRequestCreator( | |
1760 base::WrapUnique(creator)); | |
1761 const std::string version("1.0.0.0"); | |
1762 | |
1763 // No request should be sent because supervised user initiated installs | |
1764 // are disabled. | |
1765 EXPECT_CALL(*creator, CreateExtensionInstallRequest( | |
1766 RequestId(good_crx, version), testing::_)) | |
1767 .Times(0); | |
1768 | |
1769 // Now make the profile supervised. | |
1770 profile()->AsTestingProfile()->SetSupervisedUserId( | |
1681 supervised_users::kChildAccountSUID); | 1771 supervised_users::kChildAccountSUID); |
1682 | 1772 |
1683 // The extension should not be enabled anymore. | 1773 // The extension should not be enabled anymore. |
1684 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 1774 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
Marc Treib
2016/05/24 09:54:58
Also here: What should the disable reasons be?
mamir
2016/06/03 09:45:54
It also should have the same reason DISABLE_CUSTOD
| |
1685 } | 1775 } |
1686 | 1776 |
1687 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { | 1777 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { |
1688 InitServices(true /* profile_is_supervised */); | 1778 InitServices(true /* profile_is_supervised */); |
1689 | 1779 |
1690 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); | 1780 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); |
1691 base::FilePath pem_path = base_path.AppendASCII("key.pem"); | 1781 base::FilePath pem_path = base_path.AppendASCII("key.pem"); |
1692 | 1782 |
1693 const Extension* extension = | 1783 const Extension* extension = |
1694 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW, | 1784 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW, |
(...skipping 26 matching lines...) Expand all Loading... | |
1721 supervised_user_service()->AddPermissionRequestCreator( | 1811 supervised_user_service()->AddPermissionRequestCreator( |
1722 base::WrapUnique(creator)); | 1812 base::WrapUnique(creator)); |
1723 | 1813 |
1724 std::string id = InstallPermissionsTestExtension(); | 1814 std::string id = InstallPermissionsTestExtension(); |
1725 | 1815 |
1726 // Update to a new version with increased permissions. | 1816 // Update to a new version with increased permissions. |
1727 // Since we don't require the custodian's approval, no permission request | 1817 // Since we don't require the custodian's approval, no permission request |
1728 // should be created. | 1818 // should be created. |
1729 const std::string version2("2"); | 1819 const std::string version2("2"); |
1730 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1820 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1731 UpdateRequestId(id, version2), testing::_)) | 1821 RequestId(id, version2), testing::_)) |
1732 .Times(0); | 1822 .Times(0); |
1733 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1823 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1734 } | 1824 } |
1735 | 1825 |
1736 TEST_F(ExtensionServiceTestSupervised, | 1826 TEST_F(ExtensionServiceTestSupervised, |
1737 UpdateWithPermissionIncreaseApprovalOldVersion) { | 1827 UpdateWithPermissionIncreaseApprovalOldVersion) { |
1738 InitNeedCustodianApprovalFieldTrial(true); | 1828 InitNeedCustodianApprovalFieldTrial(true); |
1739 | 1829 |
1740 InitServices(true /* profile_is_supervised */); | 1830 InitServices(true /* profile_is_supervised */); |
1741 | 1831 |
1742 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1832 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1743 supervised_user_service()->AddPermissionRequestCreator( | 1833 supervised_user_service()->AddPermissionRequestCreator( |
1744 base::WrapUnique(creator)); | 1834 base::WrapUnique(creator)); |
1745 | 1835 |
1746 const std::string version1("1"); | 1836 const std::string version1("1"); |
1747 const std::string version2("2"); | 1837 const std::string version2("2"); |
1748 | 1838 |
1749 std::string id = InstallPermissionsTestExtension(); | 1839 std::string id = InstallPermissionsTestExtension(); |
1750 | 1840 |
1751 // Update to a new version with increased permissions. | 1841 // Update to a new version with increased permissions. |
1752 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1842 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1753 UpdateRequestId(id, version2), testing::_)); | 1843 RequestId(id, version2), testing::_)); |
1754 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1844 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1755 | 1845 |
1756 // Simulate a custodian approval for re-enabling the extension coming in | 1846 // 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 | 1847 // 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. | 1848 // was a pending request for an earlier version of the extension. |
1759 sync_pb::EntitySpecifics specifics; | 1849 sync_pb::EntitySpecifics specifics; |
1760 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1850 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
1761 ext_specifics->set_id(id); | 1851 ext_specifics->set_id(id); |
1762 ext_specifics->set_enabled(true); | 1852 ext_specifics->set_enabled(true); |
1763 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 1853 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
1764 ext_specifics->set_installed_by_custodian(true); | 1854 ext_specifics->set_installed_by_custodian(true); |
1765 ext_specifics->set_version(version1); | 1855 ext_specifics->set_version(version1); |
1766 | 1856 |
1767 // Attempting to re-enable an old version should result in a permission | 1857 // Attempting to re-enable an old version should result in a permission |
1768 // request for the current version. | 1858 // request for the current version. |
1769 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1859 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1770 UpdateRequestId(id, version2), testing::_)); | 1860 RequestId(id, version2), testing::_)); |
1771 | 1861 |
1772 SyncChangeList list = | 1862 SyncChangeList list = |
1773 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 1863 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
1774 | 1864 |
1775 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 1865 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
1776 // The re-enable should be ignored, since the version doesn't match. | 1866 // The re-enable should be ignored, since the version doesn't match. |
1777 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 1867 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
1778 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 1868 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
1779 id, base::Version(version1))); | 1869 id, base::Version(version1))); |
1780 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 1870 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
1781 id, base::Version(version2))); | 1871 id, base::Version(version2))); |
1782 } | 1872 } |
1783 | 1873 |
1784 TEST_F(ExtensionServiceTestSupervised, | 1874 TEST_F(ExtensionServiceTestSupervised, |
1785 UpdateWithPermissionIncreaseApprovalMatchingVersion) { | 1875 UpdateWithPermissionIncreaseApprovalMatchingVersion) { |
1786 InitNeedCustodianApprovalFieldTrial(true); | 1876 InitNeedCustodianApprovalFieldTrial(true); |
1787 | 1877 |
1788 InitServices(true /* profile_is_supervised */); | 1878 InitServices(true /* profile_is_supervised */); |
1789 | 1879 |
1790 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1880 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1791 supervised_user_service()->AddPermissionRequestCreator( | 1881 supervised_user_service()->AddPermissionRequestCreator( |
1792 base::WrapUnique(creator)); | 1882 base::WrapUnique(creator)); |
1793 | 1883 |
1794 std::string id = InstallPermissionsTestExtension(); | 1884 std::string id = InstallPermissionsTestExtension(); |
1795 | 1885 |
1796 // Update to a new version with increased permissions. | 1886 // Update to a new version with increased permissions. |
1797 const std::string version2("2"); | 1887 const std::string version2("2"); |
1798 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1888 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1799 UpdateRequestId(id, version2), testing::_)); | 1889 RequestId(id, version2), testing::_)); |
1800 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1890 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1801 | 1891 |
1802 // Simulate a custodian approval for re-enabling the extension coming in | 1892 // Simulate a custodian approval for re-enabling the extension coming in |
1803 // through Sync. | 1893 // through Sync. |
1804 sync_pb::EntitySpecifics specifics; | 1894 sync_pb::EntitySpecifics specifics; |
1805 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1895 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
1806 ext_specifics->set_id(id); | 1896 ext_specifics->set_id(id); |
1807 ext_specifics->set_enabled(true); | 1897 ext_specifics->set_enabled(true); |
1808 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 1898 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
1809 ext_specifics->set_installed_by_custodian(true); | 1899 ext_specifics->set_installed_by_custodian(true); |
(...skipping 15 matching lines...) Expand all Loading... | |
1825 | 1915 |
1826 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1916 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
1827 supervised_user_service()->AddPermissionRequestCreator( | 1917 supervised_user_service()->AddPermissionRequestCreator( |
1828 base::WrapUnique(creator)); | 1918 base::WrapUnique(creator)); |
1829 | 1919 |
1830 std::string id = InstallPermissionsTestExtension(); | 1920 std::string id = InstallPermissionsTestExtension(); |
1831 | 1921 |
1832 // Update to a new version with increased permissions. | 1922 // Update to a new version with increased permissions. |
1833 const std::string version2("2"); | 1923 const std::string version2("2"); |
1834 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1924 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1835 UpdateRequestId(id, version2), testing::_)); | 1925 RequestId(id, version2), testing::_)); |
1836 UpdatePermissionsTestExtension(id, version2, DISABLED); | 1926 UpdatePermissionsTestExtension(id, version2, DISABLED); |
1837 | 1927 |
1838 // Simulate a custodian approval for re-enabling the extension coming in | 1928 // Simulate a custodian approval for re-enabling the extension coming in |
1839 // through Sync. Set a newer version than we have installed. | 1929 // through Sync. Set a newer version than we have installed. |
1840 const std::string version3("3"); | 1930 const std::string version3("3"); |
1841 sync_pb::EntitySpecifics specifics; | 1931 sync_pb::EntitySpecifics specifics; |
1842 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1932 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
1843 ext_specifics->set_id(id); | 1933 ext_specifics->set_id(id); |
1844 ext_specifics->set_enabled(true); | 1934 ext_specifics->set_enabled(true); |
1845 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 1935 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
1846 ext_specifics->set_installed_by_custodian(true); | 1936 ext_specifics->set_installed_by_custodian(true); |
1847 ext_specifics->set_version(version3); | 1937 ext_specifics->set_version(version3); |
1848 | 1938 |
1849 // This should *not* result in a new permission request. | 1939 // This should *not* result in a new permission request. |
1850 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 1940 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
1851 UpdateRequestId(id, version3), testing::_)) | 1941 RequestId(id, version3), testing::_)) |
1852 .Times(0); | 1942 .Times(0); |
1853 | 1943 |
1854 SyncChangeList list = | 1944 SyncChangeList list = |
1855 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 1945 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
1856 | 1946 |
1857 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 1947 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
1858 // The re-enable should be delayed until the extension is updated to the | 1948 // The re-enable should be delayed until the extension is updated to the |
1859 // matching version. | 1949 // matching version. |
1860 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 1950 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
1861 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( | 1951 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( |
1862 id, base::Version(version3))); | 1952 id, base::Version(version3))); |
1863 | 1953 |
1864 // Update to the matching version. Now the extension should get enabled. | 1954 // Update to the matching version. Now the extension should get enabled. |
1865 UpdatePermissionsTestExtension(id, version3, ENABLED); | 1955 UpdatePermissionsTestExtension(id, version3, ENABLED); |
1866 } | 1956 } |
1867 | 1957 |
1958 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) { | |
1959 InitNeedCustodianApprovalFieldTrial(true); | |
1960 InitSupervisedUserInitiatedExtensionInstallFeature(true); | |
1961 | |
1962 InitServices(true /* profile_is_supervised */); | |
1963 | |
1964 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
1965 supervised_user_service()->AddPermissionRequestCreator( | |
1966 base::WrapUnique(creator)); | |
1967 | |
1968 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
1969 const std::string version("1.0.0.0"); | |
1970 | |
1971 EXPECT_CALL(*creator, CreateExtensionInstallRequest( | |
1972 RequestId(good_crx, version), testing::_)); | |
1973 | |
1974 // Should be installed but disabled, a request for approval should be sent. | |
1975 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD); | |
1976 ASSERT_EQ(extension->id(), good_crx); | |
1977 ASSERT_TRUE(extension); | |
1978 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); | |
1979 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id())); | |
1980 | |
Marc Treib
2016/05/24 09:54:57
Something I learned recently: You can do
Mock::Ver
mamir
2016/06/03 09:45:54
Done.
| |
1981 // Simulate a custodian approval for enabling the extension coming in | |
1982 // through Sync. | |
1983 sync_pb::EntitySpecifics specifics; | |
1984 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | |
1985 ext_specifics->set_id(extension->id()); | |
1986 ext_specifics->set_enabled(true); | |
1987 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | |
1988 ext_specifics->set_version(version); | |
1989 | |
1990 SyncChangeList list1 = | |
1991 MakeSyncChangeList(extension->id(), specifics, SyncChange::ACTION_UPDATE); | |
1992 | |
1993 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list1); | |
1994 | |
1995 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( | |
1996 supervised_users::kApprovedExtensions, extension->id()); | |
1997 syncer::SyncData sync_data = | |
1998 SupervisedUserSettingsService::CreateSyncDataForSetting( | |
1999 key, base::StringValue(version)); | |
2000 | |
2001 SyncChangeList list2( | |
2002 1, SyncChange(FROM_HERE, SyncChange::ACTION_ADD, sync_data)); | |
2003 | |
2004 SupervisedUserSettingsService* supervised_user_settings_service = | |
2005 SupervisedUserSettingsServiceFactory::GetForProfile(profile()); | |
2006 supervised_user_settings_service->ProcessSyncChanges(FROM_HERE, list2); | |
2007 // The extension should be enabled now. | |
2008 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | |
2009 } | |
2010 | |
1868 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { | 2011 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { |
1869 InitializeEmptyExtensionService(); | 2012 InitializeEmptyExtensionService(); |
1870 extension_sync_service()->MergeDataAndStartSyncing( | 2013 extension_sync_service()->MergeDataAndStartSyncing( |
1871 syncer::EXTENSIONS, syncer::SyncDataList(), | 2014 syncer::EXTENSIONS, syncer::SyncDataList(), |
1872 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), | 2015 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
1873 base::WrapUnique(new syncer::SyncErrorFactoryMock())); | 2016 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
1874 | 2017 |
1875 // Install two extensions. | 2018 // Install two extensions. |
1876 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 2019 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
1877 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | 2020 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2054 break; | 2197 break; |
2055 } | 2198 } |
2056 } | 2199 } |
2057 } | 2200 } |
2058 EXPECT_TRUE(found_delete); | 2201 EXPECT_TRUE(found_delete); |
2059 | 2202 |
2060 // Make sure there is one extension, and there are no more apps. | 2203 // Make sure there is one extension, and there are no more apps. |
2061 EXPECT_EQ(1u, extensions_processor.data().size()); | 2204 EXPECT_EQ(1u, extensions_processor.data().size()); |
2062 EXPECT_TRUE(apps_processor.data().empty()); | 2205 EXPECT_TRUE(apps_processor.data().empty()); |
2063 } | 2206 } |
OLD | NEW |