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

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 feedback from rdevlin.cronin@ 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.
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 extensions::ExtensionPrefs* extension_prefs =
Devlin 2016/06/13 15:37:22 no extensions:: prefix (anywhere in this file)
mamir 2016/06/13 17:06:26 Done.
1778 extensions::ExtensionPrefs::Get(profile());
1779 EXPECT_TRUE(extension_prefs->HasDisableReason(
1780 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED));
1781 }
1782
1783 TEST_F(ExtensionServiceTestSupervised,
1784 PreinstalledExtensionWithoutSUInitiatedInstalls) {
1785 InitServices(false /* profile_is_supervised */);
1786 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1787
1788 // Install an extension.
1789 base::FilePath path = data_dir().AppendASCII("good.crx");
1790 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1791 std::string id = extension->id();
1792 // Make sure it's enabled.
1793 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1794
1795 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1796 supervised_user_service()->AddPermissionRequestCreator(
1797 base::WrapUnique(creator));
1798 const std::string version("1.0.0.0");
1799
1800 // No request should be sent because supervised user initiated installs
1801 // are disabled.
1802 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1803 RequestId(good_crx, version), testing::_))
1804 .Times(0);
1805
1806 // Now make the profile supervised.
1807 profile()->AsTestingProfile()->SetSupervisedUserId(
1681 supervised_users::kChildAccountSUID); 1808 supervised_users::kChildAccountSUID);
1682 1809
1683 // The extension should not be enabled anymore. 1810 // The extension should not be enabled anymore.
1684 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1811 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1812
1813 extensions::ExtensionPrefs* extension_prefs =
1814 extensions::ExtensionPrefs::Get(profile());
1815 EXPECT_TRUE(extension_prefs->HasDisableReason(
1816 id, extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED));
1685 } 1817 }
1686 1818
1687 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { 1819 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) {
1688 InitServices(true /* profile_is_supervised */); 1820 InitServices(true /* profile_is_supervised */);
1689 1821
1690 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); 1822 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
1691 base::FilePath pem_path = base_path.AppendASCII("key.pem"); 1823 base::FilePath pem_path = base_path.AppendASCII("key.pem");
1692 1824
1693 const Extension* extension = 1825 const Extension* extension =
1694 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW, 1826 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW,
(...skipping 19 matching lines...) Expand all
1714 1846
1715 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { 1847 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) {
1716 InitNeedCustodianApprovalFieldTrial(false); 1848 InitNeedCustodianApprovalFieldTrial(false);
1717 1849
1718 InitServices(true /* profile_is_supervised */); 1850 InitServices(true /* profile_is_supervised */);
1719 1851
1720 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1852 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1721 supervised_user_service()->AddPermissionRequestCreator( 1853 supervised_user_service()->AddPermissionRequestCreator(
1722 base::WrapUnique(creator)); 1854 base::WrapUnique(creator));
1723 1855
1724 std::string id = InstallPermissionsTestExtension(); 1856 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1725 1857
1726 // Update to a new version with increased permissions. 1858 // Update to a new version with increased permissions.
1727 // Since we don't require the custodian's approval, no permission request 1859 // Since we don't require the custodian's approval, no permission request
1728 // should be created. 1860 // should be created.
1729 const std::string version2("2"); 1861 const std::string version2("2");
1730 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1862 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1731 UpdateRequestId(id, version2), testing::_)) 1863 RequestId(id, version2), testing::_))
1732 .Times(0); 1864 .Times(0);
1733 UpdatePermissionsTestExtension(id, version2, DISABLED); 1865 UpdatePermissionsTestExtension(id, version2, DISABLED);
1734 } 1866 }
1735 1867
1736 TEST_F(ExtensionServiceTestSupervised, 1868 TEST_F(ExtensionServiceTestSupervised,
1737 UpdateWithPermissionIncreaseApprovalOldVersion) { 1869 UpdateWithPermissionIncreaseApprovalOldVersion) {
1738 InitNeedCustodianApprovalFieldTrial(true); 1870 InitNeedCustodianApprovalFieldTrial(true);
1739 1871
1740 InitServices(true /* profile_is_supervised */); 1872 InitServices(true /* profile_is_supervised */);
1741 1873
1742 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1874 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1743 supervised_user_service()->AddPermissionRequestCreator( 1875 supervised_user_service()->AddPermissionRequestCreator(
1744 base::WrapUnique(creator)); 1876 base::WrapUnique(creator));
1745 1877
1746 const std::string version1("1"); 1878 const std::string version1("1");
1747 const std::string version2("2"); 1879 const std::string version2("2");
1748 1880
1749 std::string id = InstallPermissionsTestExtension(); 1881 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1750 1882
1751 // Update to a new version with increased permissions. 1883 // Update to a new version with increased permissions.
1752 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1884 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1753 UpdateRequestId(id, version2), testing::_)); 1885 RequestId(id, version2), testing::_));
1754 UpdatePermissionsTestExtension(id, version2, DISABLED); 1886 UpdatePermissionsTestExtension(id, version2, DISABLED);
1887 Mock::VerifyAndClearExpectations(creator);
1755 1888
1756 // Simulate a custodian approval for re-enabling the extension coming in 1889 // 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 1890 // 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. 1891 // was a pending request for an earlier version of the extension.
1759 sync_pb::EntitySpecifics specifics; 1892 sync_pb::EntitySpecifics specifics;
1760 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1893 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1761 ext_specifics->set_id(id); 1894 ext_specifics->set_id(id);
1762 ext_specifics->set_enabled(true); 1895 ext_specifics->set_enabled(true);
1763 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1896 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1764 ext_specifics->set_installed_by_custodian(true); 1897 ext_specifics->set_installed_by_custodian(true);
1765 ext_specifics->set_version(version1); 1898 ext_specifics->set_version(version1);
1766 1899
1767 // Attempting to re-enable an old version should result in a permission 1900 // Attempting to re-enable an old version should result in a permission
1768 // request for the current version. 1901 // request for the current version.
1769 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1902 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1770 UpdateRequestId(id, version2), testing::_)); 1903 RequestId(id, version2), testing::_));
1771 1904
1772 SyncChangeList list = 1905 SyncChangeList list =
1773 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1906 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1774 1907
1775 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1908 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1776 // The re-enable should be ignored, since the version doesn't match. 1909 // The re-enable should be ignored, since the version doesn't match.
1777 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1910 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1778 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1911 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1779 id, base::Version(version1))); 1912 id, base::Version(version1)));
1780 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1913 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1781 id, base::Version(version2))); 1914 id, base::Version(version2)));
1915 Mock::VerifyAndClearExpectations(creator);
1782 } 1916 }
1783 1917
1784 TEST_F(ExtensionServiceTestSupervised, 1918 TEST_F(ExtensionServiceTestSupervised,
1785 UpdateWithPermissionIncreaseApprovalMatchingVersion) { 1919 UpdateWithPermissionIncreaseApprovalMatchingVersion) {
1786 InitNeedCustodianApprovalFieldTrial(true); 1920 InitNeedCustodianApprovalFieldTrial(true);
1787 1921
1788 InitServices(true /* profile_is_supervised */); 1922 InitServices(true /* profile_is_supervised */);
1789 1923
1790 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1924 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1791 supervised_user_service()->AddPermissionRequestCreator( 1925 supervised_user_service()->AddPermissionRequestCreator(
1792 base::WrapUnique(creator)); 1926 base::WrapUnique(creator));
1793 1927
1794 std::string id = InstallPermissionsTestExtension(); 1928 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1795 1929
1796 // Update to a new version with increased permissions. 1930 // Update to a new version with increased permissions.
1797 const std::string version2("2"); 1931 const std::string version2("2");
1798 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1932 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1799 UpdateRequestId(id, version2), testing::_)); 1933 RequestId(id, version2), testing::_));
1800 UpdatePermissionsTestExtension(id, version2, DISABLED); 1934 UpdatePermissionsTestExtension(id, version2, DISABLED);
1935 Mock::VerifyAndClearExpectations(creator);
1801 1936
1802 // Simulate a custodian approval for re-enabling the extension coming in 1937 // Simulate a custodian approval for re-enabling the extension coming in
1803 // through Sync. 1938 // through Sync.
1804 sync_pb::EntitySpecifics specifics; 1939 sync_pb::EntitySpecifics specifics;
1805 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1940 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1806 ext_specifics->set_id(id); 1941 ext_specifics->set_id(id);
1807 ext_specifics->set_enabled(true); 1942 ext_specifics->set_enabled(true);
1808 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1943 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1809 ext_specifics->set_installed_by_custodian(true); 1944 ext_specifics->set_installed_by_custodian(true);
1810 ext_specifics->set_version(version2); 1945 ext_specifics->set_version(version2);
1811 1946
1812 SyncChangeList list = 1947 SyncChangeList list =
1813 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1948 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1814 1949
1815 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1950 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1816 // The extension should have gotten re-enabled. 1951 // The extension should have gotten re-enabled.
1817 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1952 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1818 } 1953 }
1819 1954
1820 TEST_F(ExtensionServiceTestSupervised, 1955 TEST_F(ExtensionServiceTestSupervised,
1821 UpdateWithPermissionIncreaseApprovalNewVersion) { 1956 UpdateWithPermissionIncreaseApprovalNewVersion) {
1822 InitNeedCustodianApprovalFieldTrial(true); 1957 InitNeedCustodianApprovalFieldTrial(true);
1823 1958
1824 InitServices(true /* profile_is_supervised */); 1959 InitServices(true /* profile_is_supervised */);
1825 1960
1826 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1961 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1827 supervised_user_service()->AddPermissionRequestCreator( 1962 supervised_user_service()->AddPermissionRequestCreator(
1828 base::WrapUnique(creator)); 1963 base::WrapUnique(creator));
1829 1964
1830 std::string id = InstallPermissionsTestExtension(); 1965 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1831 1966
1832 // Update to a new version with increased permissions. 1967 // Update to a new version with increased permissions.
1833 const std::string version2("2"); 1968 const std::string version2("2");
1834 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1969 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1835 UpdateRequestId(id, version2), testing::_)); 1970 RequestId(id, version2), testing::_));
1836 UpdatePermissionsTestExtension(id, version2, DISABLED); 1971 UpdatePermissionsTestExtension(id, version2, DISABLED);
1972 Mock::VerifyAndClearExpectations(creator);
1837 1973
1838 // Simulate a custodian approval for re-enabling the extension coming in 1974 // Simulate a custodian approval for re-enabling the extension coming in
1839 // through Sync. Set a newer version than we have installed. 1975 // through Sync. Set a newer version than we have installed.
1840 const std::string version3("3"); 1976 const std::string version3("3");
1841 sync_pb::EntitySpecifics specifics; 1977 sync_pb::EntitySpecifics specifics;
1842 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1978 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1843 ext_specifics->set_id(id); 1979 ext_specifics->set_id(id);
1844 ext_specifics->set_enabled(true); 1980 ext_specifics->set_enabled(true);
1845 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1981 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1846 ext_specifics->set_installed_by_custodian(true); 1982 ext_specifics->set_installed_by_custodian(true);
1847 ext_specifics->set_version(version3); 1983 ext_specifics->set_version(version3);
1848 1984
1849 // This should *not* result in a new permission request. 1985 // This should *not* result in a new permission request.
1850 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1986 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1851 UpdateRequestId(id, version3), testing::_)) 1987 RequestId(id, version3), testing::_))
1852 .Times(0); 1988 .Times(0);
1853 1989
1854 SyncChangeList list = 1990 SyncChangeList list =
1855 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1991 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1856 1992
1857 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1993 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1858 // The re-enable should be delayed until the extension is updated to the 1994 // The re-enable should be delayed until the extension is updated to the
1859 // matching version. 1995 // matching version.
1860 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1996 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1861 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( 1997 EXPECT_TRUE(extension_sync_service()->HasPendingReenable(
1862 id, base::Version(version3))); 1998 id, base::Version(version3)));
1863 1999
1864 // Update to the matching version. Now the extension should get enabled. 2000 // Update to the matching version. Now the extension should get enabled.
1865 UpdatePermissionsTestExtension(id, version3, ENABLED); 2001 UpdatePermissionsTestExtension(id, version3, ENABLED);
1866 } 2002 }
1867 2003
2004 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) {
2005 InitNeedCustodianApprovalFieldTrial(true);
2006 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2007
2008 InitServices(true /* profile_is_supervised */);
2009
2010 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
2011 supervised_user_service()->AddPermissionRequestCreator(
2012 base::WrapUnique(creator));
2013
2014 base::FilePath path = data_dir().AppendASCII("good.crx");
2015 const std::string version("1.0.0.0");
2016
2017 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
2018 RequestId(good_crx, version), testing::_));
2019
2020 // Should be installed but disabled, a request for approval should be sent.
2021 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD);
2022 ASSERT_EQ(extension->id(), good_crx);
2023 ASSERT_TRUE(extension);
2024 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
2025 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id()));
2026 Mock::VerifyAndClearExpectations(creator);
2027
2028 SimulateCustodianApprovalViaSync(extension->id(), version);
2029
2030 // The extension should be enabled now.
2031 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
2032 }
2033
2034 TEST_F(ExtensionServiceTestSupervised,
2035 UpdateSUInitiatedInstallWithoutPermissionIncrease) {
2036 InitNeedCustodianApprovalFieldTrial(true);
2037 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2038
2039 InitServices(true /* profile_is_supervised */);
2040
2041 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
2042 base::FilePath pem_path = base_path.AppendASCII("key.pem");
2043
2044 const Extension* extension = PackAndInstallCRX(
2045 base_path.AppendASCII("v1"), pem_path, INSTALL_WITHOUT_LOAD);
2046
2047 ASSERT_TRUE(extension);
2048 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id()));
2049
2050 SimulateCustodianApprovalViaSync(extension->id(), extension->VersionString());
2051
2052 // The extension should be enabled now.
2053 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
2054
2055 // Save the id, as the extension object will be destroyed during updating.
2056 std::string id = extension->id();
2057
2058 std::string old_version = extension->VersionString();
2059
2060 // Update to a new version.
2061 PackCRXAndUpdateExtension(id, base_path.AppendASCII("v2"), pem_path, ENABLED);
2062
2063 // The extension should still be there and enabled.
2064 extension = registry()->enabled_extensions().GetByID(id);
2065 ASSERT_TRUE(extension);
2066 // The version should have changed.
2067 EXPECT_NE(extension->VersionString(), old_version);
Devlin 2016/06/13 15:37:22 nit: might be a little bit better to store the bas
mamir 2016/06/13 17:06:26 Done.
2068
2069 // Check that the approved version has been updated in the prefs as well.
2070 // Prefs are updated via Sync. If the prefs are updated, then the new
2071 // approved version has been pushed to Sync as well.
2072 std::string approved_version;
2073 PrefService* pref_service = profile()->GetPrefs();
2074 const base::DictionaryValue* approved_extensions =
2075 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions);
2076 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version);
2077
2078 EXPECT_EQ(extension->VersionString(), approved_version);
2079 }
2080
2081 TEST_F(ExtensionServiceTestSupervised,
2082 UpdateSUInitiatedInstallWithPermissionIncrease) {
2083 InitNeedCustodianApprovalFieldTrial(true);
2084 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2085
2086 InitServices(true /* profile_is_supervised */);
2087
2088 std::string id = InstallPermissionsTestExtension(false /* by_custodian */);
2089 const std::string version("1");
2090
2091 SimulateCustodianApprovalViaSync(id, version);
2092
2093 // The extension should be enabled now.
2094 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2095
2096 const std::string version2("2");
2097
2098 UpdatePermissionsTestExtension(id, version2, DISABLED);
2099
2100 // The extension should be disabled.
2101 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
2102 }
2103
1868 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { 2104 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) {
1869 InitializeEmptyExtensionService(); 2105 InitializeEmptyExtensionService();
1870 extension_sync_service()->MergeDataAndStartSyncing( 2106 extension_sync_service()->MergeDataAndStartSyncing(
1871 syncer::EXTENSIONS, syncer::SyncDataList(), 2107 syncer::EXTENSIONS, syncer::SyncDataList(),
1872 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), 2108 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1873 base::WrapUnique(new syncer::SyncErrorFactoryMock())); 2109 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1874 2110
1875 // Install two extensions. 2111 // Install two extensions.
1876 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 2112 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1877 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 2113 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 break; 2290 break;
2055 } 2291 }
2056 } 2292 }
2057 } 2293 }
2058 EXPECT_TRUE(found_delete); 2294 EXPECT_TRUE(found_delete);
2059 2295
2060 // Make sure there is one extension, and there are no more apps. 2296 // Make sure there is one extension, and there are no more apps.
2061 EXPECT_EQ(1u, extensions_processor.data().size()); 2297 EXPECT_EQ(1u, extensions_processor.data().size());
2062 EXPECT_TRUE(apps_processor.data().empty()); 2298 EXPECT_TRUE(apps_processor.data().empty());
2063 } 2299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698