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

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

Issue 2004043002: Supervised Users Initiated Installs v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Response to code review from Marc Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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
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
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()));
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 // Simulate a custodian approval for enabling the extension coming in
1639 // through Sync by adding the approved version to the map of approved
1640 // extensions. It doesn't change the disable reasons.
Marc Treib 2016/06/15 12:31:07 Is it particularly relevant that this doesn't chan
mamir 2016/06/15 17:30:03 The idea is: this method is responsible only for g
Marc Treib 2016/06/16 08:26:54 Acknowledged.
1641 void SimulateCustodianApprovalViaSync(const std::string& extension_id,
1642 const std::string& version) {
1643 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
1644 supervised_users::kApprovedExtensions, extension_id);
1645 syncer::SyncData sync_data =
1646 SupervisedUserSettingsService::CreateSyncDataForSetting(
1647 key, base::StringValue(version));
1648
1649 SyncChangeList list(
1650 1, SyncChange(FROM_HERE, SyncChange::ACTION_ADD, sync_data));
1651
1652 SupervisedUserSettingsService* supervised_user_settings_service =
1653 SupervisedUserSettingsServiceFactory::GetForProfile(profile());
1654 supervised_user_settings_service->ProcessSyncChanges(FROM_HERE, list);
1655 }
1656
1607 SupervisedUserService* supervised_user_service() { 1657 SupervisedUserService* supervised_user_service() {
1608 return SupervisedUserServiceFactory::GetForProfile(profile()); 1658 return SupervisedUserServiceFactory::GetForProfile(profile());
1609 } 1659 }
1610 1660
1611 static std::string UpdateRequestId(const std::string& extension_id, 1661 static std::string RequestId(const std::string& extension_id,
1612 const std::string& version) { 1662 const std::string& version) {
1613 return SupervisedUserService::GetExtensionUpdateRequestId( 1663 return SupervisedUserService::GetExtensionRequestId(
1614 extension_id, base::Version(version)); 1664 extension_id, base::Version(version));
1615 } 1665 }
1616 1666
1617 private: 1667 private:
1618 // This prevents the legacy supervised user init code from running. 1668 // This prevents the legacy supervised user init code from running.
1619 bool SetActive(bool active) override { return true; } 1669 bool SetActive(bool active) override { return true; }
1620 1670
1621 base::FilePath base_path() const { 1671 base::FilePath base_path() const {
1622 return data_dir().AppendASCII("permissions_increase"); 1672 return data_dir().AppendASCII("permissions_increase");
1623 } 1673 }
(...skipping 12 matching lines...) Expand all
1636 MockPermissionRequestCreator() {} 1686 MockPermissionRequestCreator() {}
1637 ~MockPermissionRequestCreator() override {} 1687 ~MockPermissionRequestCreator() override {}
1638 1688
1639 bool IsEnabled() const override { return true; } 1689 bool IsEnabled() const override { return true; }
1640 1690
1641 void CreateURLAccessRequest(const GURL& url_requested, 1691 void CreateURLAccessRequest(const GURL& url_requested,
1642 const SuccessCallback& callback) override { 1692 const SuccessCallback& callback) override {
1643 FAIL(); 1693 FAIL();
1644 } 1694 }
1645 1695
1696 MOCK_METHOD2(CreateExtensionInstallRequest,
1697 void(const std::string& id,
1698 const SupervisedUserService::SuccessCallback& callback));
1699
1646 MOCK_METHOD2(CreateExtensionUpdateRequest, 1700 MOCK_METHOD2(CreateExtensionUpdateRequest,
1647 void(const std::string& id, 1701 void(const std::string& id,
1648 const SupervisedUserService::SuccessCallback& callback)); 1702 const SupervisedUserService::SuccessCallback& callback));
1649 1703
1650 private: 1704 private:
1651 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); 1705 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator);
1652 }; 1706 };
1653 1707
1654 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { 1708 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) {
1655 InitServices(true /* profile_is_supervised */); 1709 InitServices(true /* profile_is_supervised */);
1710 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1656 1711
1657 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 1712 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1658 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 1713 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1659 const Extension* extensions[] = { 1714 const Extension* extensions[] = {
1660 InstallCRX(path1, INSTALL_FAILED), 1715 InstallCRX(path1, INSTALL_FAILED),
1661 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) 1716 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
1662 }; 1717 };
1663 1718
1664 // Only the extension with the "installed by custodian" flag should have been 1719 // Only the extension with the "installed by custodian" flag should have been
1665 // installed and enabled. 1720 // installed and enabled.
1666 EXPECT_FALSE(extensions[0]); 1721 EXPECT_FALSE(extensions[0]);
1667 ASSERT_TRUE(extensions[1]); 1722 ASSERT_TRUE(extensions[1]);
1668 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); 1723 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1669 } 1724 }
1670 1725
1671 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) { 1726 TEST_F(ExtensionServiceTestSupervised,
1727 InstallAllowedByCustodianAndSupervisedUser) {
1728 InitServices(true /* profile_is_supervised */);
1729 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1730
1731 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1732 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1733 const Extension* extensions[] = {
1734 InstallCRX(path1, INSTALL_WITHOUT_LOAD),
1735 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
1736 };
1737
1738 // Only the extension with the "installed by custodian" flag should have been
1739 // installed and enabled.
1740 // The extension missing the "installed by custodian" flag is a
1741 // supervised user initiated install and hence not enabled.
1742 ASSERT_TRUE(extensions[0]);
1743 ASSERT_TRUE(extensions[1]);
1744 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id()));
1745 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1746 }
1747
1748 TEST_F(ExtensionServiceTestSupervised,
1749 PreinstalledExtensionWithSUInitiatedInstalls) {
1672 InitServices(false /* profile_is_supervised */); 1750 InitServices(false /* profile_is_supervised */);
1751 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1673 1752
1674 // Install an extension. 1753 // Install an extension.
1675 base::FilePath path = data_dir().AppendASCII("good.crx"); 1754 base::FilePath path = data_dir().AppendASCII("good.crx");
1676 const Extension* extension = InstallCRX(path, INSTALL_NEW); 1755 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1677 std::string id = extension->id(); 1756 std::string id = extension->id();
1757 // Make sure it's enabled.
1758 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1759
1760 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1761 supervised_user_service()->AddPermissionRequestCreator(
1762 base::WrapUnique(creator));
1763 const std::string version("1.0.0.0");
1764
1765 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1766 RequestId(good_crx, version), testing::_));
1678 1767
1679 // Now make the profile supervised. 1768 // Now make the profile supervised.
1680 profile()->AsTestingProfile()->SetSupervisedUserId( 1769 profile()->AsTestingProfile()->SetSupervisedUserId(
1770 supervised_users::kChildAccountSUID);
1771
1772 Mock::VerifyAndClearExpectations(creator);
1773
1774 // The extension should not be enabled anymore.
1775 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1776
1777 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile());
1778 EXPECT_TRUE(extension_prefs->HasDisableReason(
1779 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED));
1780 }
1781
1782 TEST_F(ExtensionServiceTestSupervised,
1783 PreinstalledExtensionWithoutSUInitiatedInstalls) {
1784 InitServices(false /* profile_is_supervised */);
1785 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1786
1787 // Install an extension.
1788 base::FilePath path = data_dir().AppendASCII("good.crx");
1789 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1790 std::string id = extension->id();
1791 // Make sure it's enabled.
1792 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1793
1794 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1795 supervised_user_service()->AddPermissionRequestCreator(
1796 base::WrapUnique(creator));
1797 const std::string version("1.0.0.0");
1798
1799 // No request should be sent because supervised user initiated installs
1800 // are disabled.
1801 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1802 RequestId(good_crx, version), testing::_))
Marc Treib 2016/06/15 12:31:07 I'd just use testing::_ instead of an explicit req
mamir 2016/06/15 17:30:03 Done.
1803 .Times(0);
1804
1805 // Now make the profile supervised.
1806 profile()->AsTestingProfile()->SetSupervisedUserId(
1681 supervised_users::kChildAccountSUID); 1807 supervised_users::kChildAccountSUID);
1682 1808
1683 // The extension should not be enabled anymore. 1809 // The extension should not be enabled anymore.
1684 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1810 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1811
1812 extensions::ExtensionPrefs* extension_prefs =
1813 extensions::ExtensionPrefs::Get(profile());
1814 EXPECT_TRUE(extension_prefs->HasDisableReason(
1815 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED));
1816 }
1817
1818 TEST_F(ExtensionServiceTestSupervised,
1819 ExtensionApprovalBeforeInstallation) {
Marc Treib 2016/06/15 12:31:07 nit: fits on the previous line I think
mamir 2016/06/15 17:30:03 Done.
1820 // This tests the case when the sync entity flagging the extension as approved
1821 // arrives before the extension itself is installed.
1822 InitServices(true /* profile_is_supervised */);
1823 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1824
1825 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1826 supervised_user_service()->AddPermissionRequestCreator(
1827 base::WrapUnique(creator));
1828
1829 std::string id = good_crx;
1830 const std::string version("1.0.0.0");
Marc Treib 2016/06/15 12:31:07 nit: Why is one const and the other isn't? (Don't
mamir 2016/06/15 17:30:03 Done.
1831
1832 SimulateCustodianApprovalViaSync(id, version);
1833
1834 // Now install an extension.
1835 base::FilePath path = data_dir().AppendASCII("good.crx");
1836 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1837
1838 // No approval request should be sent.
1839 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1840 RequestId(extension->id(), version), testing::_))
1841 .Times(0);
1842
1843 // Make sure it's enabled.
1844 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1685 } 1845 }
1686 1846
1687 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { 1847 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) {
1688 InitServices(true /* profile_is_supervised */); 1848 InitServices(true /* profile_is_supervised */);
1689 1849
1690 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); 1850 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
1691 base::FilePath pem_path = base_path.AppendASCII("key.pem"); 1851 base::FilePath pem_path = base_path.AppendASCII("key.pem");
1692 1852
1693 const Extension* extension = 1853 const Extension* extension =
1694 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW, 1854 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW,
(...skipping 19 matching lines...) Expand all
1714 1874
1715 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { 1875 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) {
1716 InitNeedCustodianApprovalFieldTrial(false); 1876 InitNeedCustodianApprovalFieldTrial(false);
1717 1877
1718 InitServices(true /* profile_is_supervised */); 1878 InitServices(true /* profile_is_supervised */);
1719 1879
1720 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1880 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1721 supervised_user_service()->AddPermissionRequestCreator( 1881 supervised_user_service()->AddPermissionRequestCreator(
1722 base::WrapUnique(creator)); 1882 base::WrapUnique(creator));
1723 1883
1724 std::string id = InstallPermissionsTestExtension(); 1884 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1725 1885
1726 // Update to a new version with increased permissions. 1886 // Update to a new version with increased permissions.
1727 // Since we don't require the custodian's approval, no permission request 1887 // Since we don't require the custodian's approval, no permission request
1728 // should be created. 1888 // should be created.
1729 const std::string version2("2"); 1889 const std::string version2("2");
1730 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1890 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1731 UpdateRequestId(id, version2), testing::_)) 1891 RequestId(id, version2), testing::_))
1732 .Times(0); 1892 .Times(0);
1733 UpdatePermissionsTestExtension(id, version2, DISABLED); 1893 UpdatePermissionsTestExtension(id, version2, DISABLED);
1734 } 1894 }
1735 1895
1736 TEST_F(ExtensionServiceTestSupervised, 1896 TEST_F(ExtensionServiceTestSupervised,
1737 UpdateWithPermissionIncreaseApprovalOldVersion) { 1897 UpdateWithPermissionIncreaseApprovalOldVersion) {
1738 InitNeedCustodianApprovalFieldTrial(true); 1898 InitNeedCustodianApprovalFieldTrial(true);
1739 1899
1740 InitServices(true /* profile_is_supervised */); 1900 InitServices(true /* profile_is_supervised */);
1741 1901
1742 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1902 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1743 supervised_user_service()->AddPermissionRequestCreator( 1903 supervised_user_service()->AddPermissionRequestCreator(
1744 base::WrapUnique(creator)); 1904 base::WrapUnique(creator));
1745 1905
1746 const std::string version1("1"); 1906 const std::string version1("1");
1747 const std::string version2("2"); 1907 const std::string version2("2");
1748 1908
1749 std::string id = InstallPermissionsTestExtension(); 1909 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1750 1910
1751 // Update to a new version with increased permissions. 1911 // Update to a new version with increased permissions.
1752 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1912 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1753 UpdateRequestId(id, version2), testing::_)); 1913 RequestId(id, version2), testing::_));
1754 UpdatePermissionsTestExtension(id, version2, DISABLED); 1914 UpdatePermissionsTestExtension(id, version2, DISABLED);
1915 Mock::VerifyAndClearExpectations(creator);
1755 1916
1756 // Simulate a custodian approval for re-enabling the extension coming in 1917 // 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 1918 // 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. 1919 // was a pending request for an earlier version of the extension.
1759 sync_pb::EntitySpecifics specifics; 1920 sync_pb::EntitySpecifics specifics;
1760 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1921 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1761 ext_specifics->set_id(id); 1922 ext_specifics->set_id(id);
1762 ext_specifics->set_enabled(true); 1923 ext_specifics->set_enabled(true);
1763 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1924 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1764 ext_specifics->set_installed_by_custodian(true); 1925 ext_specifics->set_installed_by_custodian(true);
1765 ext_specifics->set_version(version1); 1926 ext_specifics->set_version(version1);
1766 1927
1767 // Attempting to re-enable an old version should result in a permission 1928 // Attempting to re-enable an old version should result in a permission
1768 // request for the current version. 1929 // request for the current version.
1769 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1930 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1770 UpdateRequestId(id, version2), testing::_)); 1931 RequestId(id, version2), testing::_));
1771 1932
1772 SyncChangeList list = 1933 SyncChangeList list =
1773 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1934 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1774 1935
1775 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1936 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1776 // The re-enable should be ignored, since the version doesn't match. 1937 // The re-enable should be ignored, since the version doesn't match.
1777 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1938 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1778 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1939 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1779 id, base::Version(version1))); 1940 id, base::Version(version1)));
1780 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1941 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1781 id, base::Version(version2))); 1942 id, base::Version(version2)));
1943 Mock::VerifyAndClearExpectations(creator);
1782 } 1944 }
1783 1945
1784 TEST_F(ExtensionServiceTestSupervised, 1946 TEST_F(ExtensionServiceTestSupervised,
1785 UpdateWithPermissionIncreaseApprovalMatchingVersion) { 1947 UpdateWithPermissionIncreaseApprovalMatchingVersion) {
1786 InitNeedCustodianApprovalFieldTrial(true); 1948 InitNeedCustodianApprovalFieldTrial(true);
1787 1949
1788 InitServices(true /* profile_is_supervised */); 1950 InitServices(true /* profile_is_supervised */);
1789 1951
1790 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1952 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1791 supervised_user_service()->AddPermissionRequestCreator( 1953 supervised_user_service()->AddPermissionRequestCreator(
1792 base::WrapUnique(creator)); 1954 base::WrapUnique(creator));
1793 1955
1794 std::string id = InstallPermissionsTestExtension(); 1956 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1795 1957
1796 // Update to a new version with increased permissions. 1958 // Update to a new version with increased permissions.
1797 const std::string version2("2"); 1959 const std::string version2("2");
1798 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1960 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1799 UpdateRequestId(id, version2), testing::_)); 1961 RequestId(id, version2), testing::_));
1800 UpdatePermissionsTestExtension(id, version2, DISABLED); 1962 UpdatePermissionsTestExtension(id, version2, DISABLED);
1963 Mock::VerifyAndClearExpectations(creator);
1801 1964
1802 // Simulate a custodian approval for re-enabling the extension coming in 1965 // Simulate a custodian approval for re-enabling the extension coming in
1803 // through Sync. 1966 // through Sync.
1804 sync_pb::EntitySpecifics specifics; 1967 sync_pb::EntitySpecifics specifics;
1805 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1968 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1806 ext_specifics->set_id(id); 1969 ext_specifics->set_id(id);
1807 ext_specifics->set_enabled(true); 1970 ext_specifics->set_enabled(true);
1808 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1971 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1809 ext_specifics->set_installed_by_custodian(true); 1972 ext_specifics->set_installed_by_custodian(true);
1810 ext_specifics->set_version(version2); 1973 ext_specifics->set_version(version2);
1811 1974
1812 SyncChangeList list = 1975 SyncChangeList list =
1813 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1976 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1814 1977
1815 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1978 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1816 // The extension should have gotten re-enabled. 1979 // The extension should have gotten re-enabled.
1817 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1980 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1818 } 1981 }
1819 1982
1820 TEST_F(ExtensionServiceTestSupervised, 1983 TEST_F(ExtensionServiceTestSupervised,
1821 UpdateWithPermissionIncreaseApprovalNewVersion) { 1984 UpdateWithPermissionIncreaseApprovalNewVersion) {
1822 InitNeedCustodianApprovalFieldTrial(true); 1985 InitNeedCustodianApprovalFieldTrial(true);
1823 1986
1824 InitServices(true /* profile_is_supervised */); 1987 InitServices(true /* profile_is_supervised */);
1825 1988
1826 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1989 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1827 supervised_user_service()->AddPermissionRequestCreator( 1990 supervised_user_service()->AddPermissionRequestCreator(
1828 base::WrapUnique(creator)); 1991 base::WrapUnique(creator));
1829 1992
1830 std::string id = InstallPermissionsTestExtension(); 1993 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1831 1994
1832 // Update to a new version with increased permissions. 1995 // Update to a new version with increased permissions.
1833 const std::string version2("2"); 1996 const std::string version2("2");
1834 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1997 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1835 UpdateRequestId(id, version2), testing::_)); 1998 RequestId(id, version2), testing::_));
1836 UpdatePermissionsTestExtension(id, version2, DISABLED); 1999 UpdatePermissionsTestExtension(id, version2, DISABLED);
2000 Mock::VerifyAndClearExpectations(creator);
1837 2001
1838 // Simulate a custodian approval for re-enabling the extension coming in 2002 // Simulate a custodian approval for re-enabling the extension coming in
1839 // through Sync. Set a newer version than we have installed. 2003 // through Sync. Set a newer version than we have installed.
1840 const std::string version3("3"); 2004 const std::string version3("3");
1841 sync_pb::EntitySpecifics specifics; 2005 sync_pb::EntitySpecifics specifics;
1842 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 2006 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1843 ext_specifics->set_id(id); 2007 ext_specifics->set_id(id);
1844 ext_specifics->set_enabled(true); 2008 ext_specifics->set_enabled(true);
1845 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 2009 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1846 ext_specifics->set_installed_by_custodian(true); 2010 ext_specifics->set_installed_by_custodian(true);
1847 ext_specifics->set_version(version3); 2011 ext_specifics->set_version(version3);
1848 2012
1849 // This should *not* result in a new permission request. 2013 // This should *not* result in a new permission request.
1850 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 2014 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1851 UpdateRequestId(id, version3), testing::_)) 2015 RequestId(id, version3), testing::_))
1852 .Times(0); 2016 .Times(0);
1853 2017
1854 SyncChangeList list = 2018 SyncChangeList list =
1855 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 2019 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1856 2020
1857 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 2021 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1858 // The re-enable should be delayed until the extension is updated to the 2022 // The re-enable should be delayed until the extension is updated to the
1859 // matching version. 2023 // matching version.
1860 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 2024 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1861 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( 2025 EXPECT_TRUE(extension_sync_service()->HasPendingReenable(
1862 id, base::Version(version3))); 2026 id, base::Version(version3)));
1863 2027
1864 // Update to the matching version. Now the extension should get enabled. 2028 // Update to the matching version. Now the extension should get enabled.
1865 UpdatePermissionsTestExtension(id, version3, ENABLED); 2029 UpdatePermissionsTestExtension(id, version3, ENABLED);
1866 } 2030 }
1867 2031
2032 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) {
2033 InitNeedCustodianApprovalFieldTrial(true);
2034 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2035
2036 InitServices(true /* profile_is_supervised */);
2037
2038 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
2039 supervised_user_service()->AddPermissionRequestCreator(
2040 base::WrapUnique(creator));
2041
2042 base::FilePath path = data_dir().AppendASCII("good.crx");
2043 const std::string version("1.0.0.0");
2044
2045 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
2046 RequestId(good_crx, version), testing::_));
2047
2048 // Should be installed but disabled, a request for approval should be sent.
2049 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD);
2050 ASSERT_EQ(extension->id(), good_crx);
2051 ASSERT_TRUE(extension);
2052 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
2053 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id()));
2054 Mock::VerifyAndClearExpectations(creator);
2055
2056 SimulateCustodianApprovalViaSync(extension->id(), version);
2057
2058 // The extension should be enabled now.
2059 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
2060 }
2061
2062 TEST_F(ExtensionServiceTestSupervised,
2063 UpdateSUInitiatedInstallWithoutPermissionIncrease) {
2064 InitNeedCustodianApprovalFieldTrial(true);
2065 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2066
2067 InitServices(true /* profile_is_supervised */);
2068
2069 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
2070 base::FilePath pem_path = base_path.AppendASCII("key.pem");
2071
2072 const Extension* extension = PackAndInstallCRX(
2073 base_path.AppendASCII("v1"), pem_path, INSTALL_WITHOUT_LOAD);
2074
2075 ASSERT_TRUE(extension);
2076 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id()));
2077
2078 SimulateCustodianApprovalViaSync(extension->id(), extension->VersionString());
2079
2080 // The extension should be enabled now.
2081 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
2082
2083 // Save the id, as the extension object will be destroyed during updating.
2084 std::string id = extension->id();
2085
2086 const base::Version old_version = *extension->version();
2087
2088 // Update to a new version.
2089 PackCRXAndUpdateExtension(id, base_path.AppendASCII("v2"), pem_path, ENABLED);
2090
2091 // The extension should still be there and enabled.
2092 extension = registry()->enabled_extensions().GetByID(id);
2093 ASSERT_TRUE(extension);
2094 // The version should have increased.
2095 EXPECT_EQ(1, extension->version()->CompareTo(old_version));
2096
2097 // Check that the approved version has been updated in the prefs as well.
2098 // Prefs are updated via Sync. If the prefs are updated, then the new
2099 // approved version has been pushed to Sync as well.
2100 std::string approved_version;
2101 PrefService* pref_service = profile()->GetPrefs();
2102 const base::DictionaryValue* approved_extensions =
2103 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions);
2104 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version);
2105
2106 EXPECT_EQ(0,
2107 extension->version()->CompareTo(base::Version(approved_version)));
2108 }
2109
2110 TEST_F(ExtensionServiceTestSupervised,
2111 UpdateSUInitiatedInstallWithPermissionIncrease) {
Marc Treib 2016/06/15 12:31:07 This test name suggests that it's the counterpart
mamir 2016/06/15 17:30:03 Because they test different flows. The first tests
Marc Treib 2016/06/16 08:26:54 So, steps 1 and 2 are identical, and step 3 is ide
mamir 2016/06/17 15:03:18 As discussed offline, in order to unify both tests
2112 InitNeedCustodianApprovalFieldTrial(true);
2113 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2114
2115 InitServices(true /* profile_is_supervised */);
2116
2117 std::string id = InstallPermissionsTestExtension(false /* by_custodian */);
2118 const std::string version("1");
Marc Treib 2016/06/15 12:31:07 Also here: please try to be consistent with consts
mamir 2016/06/15 17:30:03 Done.
2119
2120 SimulateCustodianApprovalViaSync(id, version);
2121
2122 // The extension should be enabled now.
2123 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2124
2125 const std::string version2("2");
2126
2127 UpdatePermissionsTestExtension(id, version2, DISABLED);
2128
2129 // The extension should be disabled.
2130 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
Marc Treib 2016/06/15 12:31:07 Also check the disable reasons?
mamir 2016/06/15 17:30:03 Done.
2131 }
Marc Treib 2016/06/15 12:31:07 Please extend the test with an incoming approval a
mamir 2016/06/15 17:30:03 But this would be duplicating other tests covering
Marc Treib 2016/06/16 08:26:54 The way that approval and re-enabling work are ver
mamir 2016/06/17 15:03:17 Done.
2132
1868 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { 2133 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) {
1869 InitializeEmptyExtensionService(); 2134 InitializeEmptyExtensionService();
1870 extension_sync_service()->MergeDataAndStartSyncing( 2135 extension_sync_service()->MergeDataAndStartSyncing(
1871 syncer::EXTENSIONS, syncer::SyncDataList(), 2136 syncer::EXTENSIONS, syncer::SyncDataList(),
1872 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), 2137 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1873 base::WrapUnique(new syncer::SyncErrorFactoryMock())); 2138 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1874 2139
1875 // Install two extensions. 2140 // Install two extensions.
1876 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 2141 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1877 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 2142 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 break; 2319 break;
2055 } 2320 }
2056 } 2321 }
2057 } 2322 }
2058 EXPECT_TRUE(found_delete); 2323 EXPECT_TRUE(found_delete);
2059 2324
2060 // Make sure there is one extension, and there are no more apps. 2325 // Make sure there is one extension, and there are no more apps.
2061 EXPECT_EQ(1u, extensions_processor.data().size()); 2326 EXPECT_EQ(1u, extensions_processor.data().size());
2062 EXPECT_TRUE(apps_processor.data().empty()); 2327 EXPECT_TRUE(apps_processor.data().empty());
2063 } 2328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698