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

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: Fixing the build again! Created 4 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_test_with_install.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 autoupdate[] = "ogjcoiohnmldgjemafoockdghcjciccf"; 77 const char autoupdate[] = "ogjcoiohnmldgjemafoockdghcjciccf";
72 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 78 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj";
73 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; 79 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa";
74 const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; 80 const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh";
75 const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 81 const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
76 const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; 82 const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln";
77 const char permissions_increase[] = "pgdpcfcocojkjfbgpiianjngphoopgmo"; 83 const char permissions_increase[] = "pgdpcfcocojkjfbgpiianjngphoopgmo";
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 // Group name doesn't matter. 1575 // Group name doesn't matter.
1570 base::FieldTrialList::CreateFieldTrial( 1576 base::FieldTrialList::CreateFieldTrial(
1571 "SupervisedUserExtensionPermissionIncrease", "group"); 1577 "SupervisedUserExtensionPermissionIncrease", "group");
1572 std::map<std::string, std::string> params; 1578 std::map<std::string, std::string> params;
1573 params["legacy_supervised_user"] = enabled ? "true" : "false"; 1579 params["legacy_supervised_user"] = enabled ? "true" : "false";
1574 params["child_account"] = enabled ? "true" : "false"; 1580 params["child_account"] = enabled ? "true" : "false";
1575 variations::AssociateVariationParams( 1581 variations::AssociateVariationParams(
1576 "SupervisedUserExtensionPermissionIncrease", "group", params); 1582 "SupervisedUserExtensionPermissionIncrease", "group", params);
1577 } 1583 }
1578 1584
1585 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) {
1586 base::FeatureList::ClearInstanceForTesting();
1587 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
1588 if (enabled) {
1589 feature_list->InitializeFromCommandLine(
1590 "SupervisedUserInitiatedExtensionInstall", std::string());
1591 }
1592 base::FeatureList::SetInstance(std::move(feature_list));
1593 }
1594
1579 void InitServices(bool profile_is_supervised) { 1595 void InitServices(bool profile_is_supervised) {
1580 ExtensionServiceInitParams params = CreateDefaultInitParams(); 1596 ExtensionServiceInitParams params = CreateDefaultInitParams();
1581 params.profile_is_supervised = profile_is_supervised; 1597 params.profile_is_supervised = profile_is_supervised;
1598 // If profile is supervised, don't pass a pref file such that the testing
1599 // profile creates a pref service that uses SupervisedUserPrefStore.
1600 if (profile_is_supervised) {
1601 params.pref_file = base::FilePath();
1602 }
1582 InitializeExtensionService(params); 1603 InitializeExtensionService(params);
1583 StartSyncing(syncer::EXTENSIONS); 1604 StartSyncing(syncer::EXTENSIONS);
1584 1605
1585 supervised_user_service()->SetDelegate(this); 1606 supervised_user_service()->SetDelegate(this);
1586 supervised_user_service()->Init(); 1607 supervised_user_service()->Init();
1587 } 1608 }
1588 1609
1589 std::string InstallPermissionsTestExtension() { 1610 std::string InstallPermissionsTestExtension(bool by_custodian) {
1590 const std::string version("1"); 1611 return InstallTestExtension(permissions_increase, dir_path("1"), pem_path(),
1591 1612 by_custodian);
1592 extensions::util::SetWasInstalledByCustodian(permissions_increase,
1593 profile(), true);
1594 const Extension* extension =
1595 PackAndInstallCRX(dir_path(version), pem_path(), INSTALL_NEW);
1596
1597 // The extension must now be installed and enabled.
1598 EXPECT_TRUE(extension);
1599 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
1600 EXPECT_EQ(version, extension->VersionString());
1601
1602 return extension->id();
1603 } 1613 }
1604 1614
1605 void UpdatePermissionsTestExtension(const std::string& id, 1615 void UpdatePermissionsTestExtension(const std::string& id,
1606 const std::string& version, 1616 const std::string& version,
1607 UpdateState expected_state) { 1617 UpdateState expected_state) {
1608 PackCRXAndUpdateExtension(id, dir_path(version), pem_path(), 1618 UpdateTestExtension(dir_path(version), pem_path(), id, version,
1609 expected_state); 1619 expected_state);
1620 }
1621
1622 std::string InstallNoPermissionsTestExtension(bool by_custodian) {
1623 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
1624 base::FilePath pem_path = base_path.AppendASCII("key.pem");
1625 base::FilePath dir_path = base_path.AppendASCII("v1");
1626
1627 return InstallTestExtension(autoupdate, dir_path, pem_path, by_custodian);
1628 }
1629
1630 void UpdateNoPermissionsTestExtension(const std::string& id,
1631 const std::string& version,
1632 UpdateState expected_state) {
1633 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
1634 base::FilePath pem_path = base_path.AppendASCII("key.pem");
1635 base::FilePath dir_path = base_path.AppendASCII("v" + version);
1636
1637 UpdateTestExtension(dir_path, pem_path, id, version, expected_state);
1638 }
1639
1640 std::string InstallTestExtension(const std::string& id,
1641 const base::FilePath& dir_path,
1642 const base::FilePath& pem_path,
1643 bool by_custodian) {
1644 InstallState expected_state = INSTALL_WITHOUT_LOAD;
1645 if (by_custodian) {
1646 extensions::util::SetWasInstalledByCustodian(id, profile(), true);
1647 expected_state = INSTALL_NEW;
1648 }
1649 const Extension* extension =
1650 PackAndInstallCRX(dir_path, pem_path, expected_state);
1651 // The extension must now be installed.
1652 EXPECT_TRUE(extension);
1653 EXPECT_EQ(extension->id(), id);
1654 if (by_custodian) {
1655 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1656 } else {
1657 CheckDisabledForCustodianApproval(id);
1658 }
1659
1660 EXPECT_EQ(*extension->version(), base::Version("1"));
1661
1662 return id;
1663 }
1664
1665 void UpdateTestExtension(const base::FilePath& dir_path,
1666 const base::FilePath& pem_path,
1667 const std::string& id,
1668 const std::string& version,
1669 const UpdateState& expected_state) {
1670 PackCRXAndUpdateExtension(id, dir_path, pem_path, expected_state);
1610 const Extension* extension = registry()->GetInstalledExtension(id); 1671 const Extension* extension = registry()->GetInstalledExtension(id);
1611 ASSERT_TRUE(extension); 1672 ASSERT_TRUE(extension);
1612 // The version should have been updated. 1673 // The version should have been updated.
1613 EXPECT_EQ(version, extension->VersionString()); 1674 EXPECT_EQ(*extension->version(), base::Version(version));
1675 }
1676
1677 // Simulate a custodian approval for enabling the extension coming in
1678 // through Sync by adding the approved version to the map of approved
1679 // extensions. It doesn't simulate a change in the disable reasons.
1680 void SimulateCustodianApprovalChangeViaSync(const std::string& extension_id,
1681 const std::string& version,
1682 SyncChange::SyncChangeType type) {
1683 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
1684 supervised_users::kApprovedExtensions, extension_id);
1685 syncer::SyncData sync_data =
1686 SupervisedUserSettingsService::CreateSyncDataForSetting(
1687 key, base::StringValue(version));
1688
1689 SyncChangeList list(1, SyncChange(FROM_HERE, type, sync_data));
1690
1691 SupervisedUserSettingsService* supervised_user_settings_service =
1692 SupervisedUserSettingsServiceFactory::GetForProfile(profile());
1693 supervised_user_settings_service->ProcessSyncChanges(FROM_HERE, list);
1694 }
1695
1696 void CheckDisabledForCustodianApproval(const std::string& extension_id) {
1697 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id));
1698 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile());
1699 EXPECT_TRUE(extension_prefs->HasDisableReason(
1700 extension_id,
1701 extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED));
1614 } 1702 }
1615 1703
1616 SupervisedUserService* supervised_user_service() { 1704 SupervisedUserService* supervised_user_service() {
1617 return SupervisedUserServiceFactory::GetForProfile(profile()); 1705 return SupervisedUserServiceFactory::GetForProfile(profile());
1618 } 1706 }
1619 1707
1620 static std::string UpdateRequestId(const std::string& extension_id, 1708 static std::string RequestId(const std::string& extension_id,
1621 const std::string& version) { 1709 const std::string& version) {
1622 return SupervisedUserService::GetExtensionUpdateRequestId( 1710 return SupervisedUserService::GetExtensionRequestId(
1623 extension_id, base::Version(version)); 1711 extension_id, base::Version(version));
1624 } 1712 }
1625 1713
1626 private: 1714 private:
1627 // This prevents the legacy supervised user init code from running. 1715 // This prevents the legacy supervised user init code from running.
1628 bool SetActive(bool active) override { return true; } 1716 bool SetActive(bool active) override { return true; }
1629 1717
1630 base::FilePath base_path() const { 1718 base::FilePath base_path() const {
1631 return data_dir().AppendASCII("permissions_increase"); 1719 return data_dir().AppendASCII("permissions_increase");
1632 } 1720 }
(...skipping 12 matching lines...) Expand all
1645 MockPermissionRequestCreator() {} 1733 MockPermissionRequestCreator() {}
1646 ~MockPermissionRequestCreator() override {} 1734 ~MockPermissionRequestCreator() override {}
1647 1735
1648 bool IsEnabled() const override { return true; } 1736 bool IsEnabled() const override { return true; }
1649 1737
1650 void CreateURLAccessRequest(const GURL& url_requested, 1738 void CreateURLAccessRequest(const GURL& url_requested,
1651 const SuccessCallback& callback) override { 1739 const SuccessCallback& callback) override {
1652 FAIL(); 1740 FAIL();
1653 } 1741 }
1654 1742
1743 MOCK_METHOD2(CreateExtensionInstallRequest,
1744 void(const std::string& id,
1745 const SupervisedUserService::SuccessCallback& callback));
1746
1655 MOCK_METHOD2(CreateExtensionUpdateRequest, 1747 MOCK_METHOD2(CreateExtensionUpdateRequest,
1656 void(const std::string& id, 1748 void(const std::string& id,
1657 const SupervisedUserService::SuccessCallback& callback)); 1749 const SupervisedUserService::SuccessCallback& callback));
1658 1750
1659 private: 1751 private:
1660 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); 1752 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator);
1661 }; 1753 };
1662 1754
1663 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { 1755 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) {
1664 InitServices(true /* profile_is_supervised */); 1756 InitServices(true /* profile_is_supervised */);
1757 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1665 1758
1666 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true); 1759 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true);
1667 1760
1668 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 1761 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1669 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 1762 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1670 const Extension* extensions[] = { 1763 const Extension* extensions[] = {
1671 InstallCRX(path1, INSTALL_FAILED), 1764 InstallCRX(path1, INSTALL_FAILED),
1672 InstallCRX(path2, INSTALL_NEW) 1765 InstallCRX(path2, INSTALL_NEW)
1673 }; 1766 };
1674 1767
1675 // Only the extension with the "installed by custodian" flag should have been 1768 // Only the extension with the "installed by custodian" flag should have been
1676 // installed and enabled. 1769 // installed and enabled.
1677 EXPECT_FALSE(extensions[0]); 1770 EXPECT_FALSE(extensions[0]);
1678 ASSERT_TRUE(extensions[1]); 1771 ASSERT_TRUE(extensions[1]);
1679 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); 1772 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1680 } 1773 }
1681 1774
1682 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) {
1683 InitServices(false /* profile_is_supervised */);
1684
1685 // Install an extension.
1686 base::FilePath path = data_dir().AppendASCII("good.crx");
1687 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1688 std::string id = extension->id();
1689
1690 // Now make the profile supervised.
1691 profile()->AsTestingProfile()->SetSupervisedUserId(
1692 supervised_users::kChildAccountSUID);
1693
1694 // The extension should not be enabled anymore.
1695 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1696 }
1697
1698 TEST_F(ExtensionServiceTestSupervised, 1775 TEST_F(ExtensionServiceTestSupervised,
1699 DelegatedAndPreinstalledExtensionIsSUFirst) { 1776 DelegatedAndPreinstalledExtensionIsSUFirst) {
1700 InitServices(false /* profile_is_supervised */); 1777 InitServices(false /* profile_is_supervised */);
1778 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1701 1779
1702 // Install an extension. 1780 // Install an extension.
1703 base::FilePath path = data_dir().AppendASCII("good.crx"); 1781 base::FilePath path = data_dir().AppendASCII("good.crx");
1704 const Extension* extension = InstallCRX(path, INSTALL_NEW); 1782 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1705 std::string id = extension->id(); 1783 std::string id = extension->id();
1706 const std::string version("1.0.0.0"); 1784 const std::string version("1.0.0.0");
1707 // It should be enabled. 1785 // It should be enabled.
1708 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1786 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1709 1787
1710 // Now make the profile supervised. 1788 // Now make the profile supervised.
(...skipping 18 matching lines...) Expand all
1729 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1807 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1730 1808
1731 // The extension should be enabled again. 1809 // The extension should be enabled again.
1732 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1810 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1733 EXPECT_TRUE(extensions::util::WasInstalledByCustodian(id, profile())); 1811 EXPECT_TRUE(extensions::util::WasInstalledByCustodian(id, profile()));
1734 } 1812 }
1735 1813
1736 TEST_F(ExtensionServiceTestSupervised, 1814 TEST_F(ExtensionServiceTestSupervised,
1737 DelegatedAndPreinstalledExtensionSyncFirst) { 1815 DelegatedAndPreinstalledExtensionSyncFirst) {
1738 InitServices(false /* profile_is_supervised */); 1816 InitServices(false /* profile_is_supervised */);
1817 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1739 1818
1740 // Install an extension. 1819 // Install an extension.
1741 base::FilePath path = data_dir().AppendASCII("good.crx"); 1820 base::FilePath path = data_dir().AppendASCII("good.crx");
1742 const Extension* extension = InstallCRX(path, INSTALL_NEW); 1821 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1743 std::string id = extension->id(); 1822 std::string id = extension->id();
1744 const std::string version("1.0.0.0"); 1823 const std::string version("1.0.0.0");
1745 1824
1746 // It should be enabled. 1825 // It should be enabled.
1747 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1826 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1748 1827
1749 // Simulate data sync with the "was_installed_by_custodian" flag set to 1. 1828 // Simulate data sync with the "was_installed_by_custodian" flag set to 1.
1750 sync_pb::EntitySpecifics specifics; 1829 sync_pb::EntitySpecifics specifics;
1751 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1830 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1752 ext_specifics->set_id(id); 1831 ext_specifics->set_id(id);
1753 ext_specifics->set_enabled(true); 1832 ext_specifics->set_enabled(true);
1754 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1833 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1755 ext_specifics->set_installed_by_custodian(true); 1834 ext_specifics->set_installed_by_custodian(true);
1756 ext_specifics->set_version(version); 1835 ext_specifics->set_version(version);
1757 1836
1758 SyncChangeList list = 1837 SyncChangeList list =
1759 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1838 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1760 1839
1761 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1840 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1841 // The extension should be enabled.
1842 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1843 EXPECT_TRUE(extensions::util::WasInstalledByCustodian(id, profile()));
1844 }
1845
1846 TEST_F(ExtensionServiceTestSupervised,
1847 InstallAllowedByCustodianAndSupervisedUser) {
1848 InitServices(true /* profile_is_supervised */);
1849 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1850
1851 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true);
1852
1853 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1854 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1855 const Extension* extensions[] = {
1856 InstallCRX(path1, INSTALL_WITHOUT_LOAD),
1857 InstallCRX(path2, INSTALL_NEW)
1858 };
1859
1860 // Only the extension with the "installed by custodian" flag should have been
1861 // installed and enabled.
1862 // The extension missing the "installed by custodian" flag is a
1863 // supervised user initiated install and hence not enabled.
1864 ASSERT_TRUE(extensions[0]);
1865 ASSERT_TRUE(extensions[1]);
1866 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id()));
1867 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1868 }
1869
1870 TEST_F(ExtensionServiceTestSupervised,
1871 PreinstalledExtensionWithSUInitiatedInstalls) {
1872 InitServices(false /* profile_is_supervised */);
1873 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1874
1875 // Install an extension.
1876 base::FilePath path = data_dir().AppendASCII("good.crx");
1877 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1878 std::string id = extension->id();
1879 // Make sure it's enabled.
1880 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1881
1882 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1883 supervised_user_service()->AddPermissionRequestCreator(
1884 base::WrapUnique(creator));
1885 const std::string version("1.0.0.0");
1886
1887 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1888 RequestId(good_crx, version), testing::_));
1762 1889
1763 // Now make the profile supervised. 1890 // Now make the profile supervised.
1764 profile()->AsTestingProfile()->SetSupervisedUserId( 1891 profile()->AsTestingProfile()->SetSupervisedUserId(
1765 supervised_users::kChildAccountSUID); 1892 supervised_users::kChildAccountSUID);
1766 1893
1767 // The extension should be enabled. 1894 Mock::VerifyAndClearExpectations(creator);
1895
1896 // The extension should not be enabled anymore.
1897 CheckDisabledForCustodianApproval(id);
1898 }
1899
1900 TEST_F(ExtensionServiceTestSupervised,
1901 PreinstalledExtensionWithoutSUInitiatedInstalls) {
1902 InitServices(false /* profile_is_supervised */);
1903 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1904
1905 // Install an extension.
1906 base::FilePath path = data_dir().AppendASCII("good.crx");
1907 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1908 std::string id = extension->id();
1909
1910 // Make sure it's enabled.
1768 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1911 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1769 EXPECT_TRUE(extensions::util::WasInstalledByCustodian(id, profile())); 1912
1913 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1914 supervised_user_service()->AddPermissionRequestCreator(
1915 base::WrapUnique(creator));
1916 const std::string version("1.0.0.0");
1917
1918 // No request should be sent because supervised user initiated installs
1919 // are disabled.
1920 EXPECT_CALL(*creator, CreateExtensionInstallRequest(testing::_, testing::_))
1921 .Times(0);
1922
1923 // Now make the profile supervised.
1924 profile()->AsTestingProfile()->SetSupervisedUserId(
1925 supervised_users::kChildAccountSUID);
1926
1927 // The extension should not be loaded anymore.
1928 EXPECT_FALSE(registry()->GetInstalledExtension(id));
1929 }
1930
1931 TEST_F(ExtensionServiceTestSupervised, ExtensionApprovalBeforeInstallation) {
1932 // This tests the case when the sync entity flagging the extension as approved
1933 // arrives before the extension itself is installed.
1934 InitServices(true /* profile_is_supervised */);
1935 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1936
1937 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1938 supervised_user_service()->AddPermissionRequestCreator(
1939 base::WrapUnique(creator));
1940
1941 std::string id = good_crx;
1942 std::string version("1.0.0.0");
1943
1944 SimulateCustodianApprovalChangeViaSync(id, version, SyncChange::ACTION_ADD);
1945
1946 // Now install an extension.
1947 base::FilePath path = data_dir().AppendASCII("good.crx");
1948 InstallCRX(path, INSTALL_NEW);
1949
1950 // No approval request should be sent.
1951 EXPECT_CALL(*creator, CreateExtensionInstallRequest(testing::_, testing::_))
1952 .Times(0);
1953
1954 // Make sure it's enabled.
1955 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1770 } 1956 }
1771 1957
1772 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { 1958 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) {
1773 InitServices(true /* profile_is_supervised */); 1959 InitServices(true /* profile_is_supervised */);
1774 1960
1775 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
1776 base::FilePath pem_path = base_path.AppendASCII("key.pem");
1777
1778 extensions::util::SetWasInstalledByCustodian(autoupdate, profile(), true);
1779 const Extension* extension =
1780 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW);
1781
1782 // The extension must now be installed and enabled.
1783 ASSERT_TRUE(extension);
1784 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
1785
1786 // Save the id, as the extension object will be destroyed during updating. 1961 // Save the id, as the extension object will be destroyed during updating.
1787 std::string id = extension->id(); 1962 std::string id = InstallNoPermissionsTestExtension(true /* by_custodian */);
1788
1789 std::string old_version = extension->VersionString();
1790 1963
1791 // Update to a new version. 1964 // Update to a new version.
1792 PackCRXAndUpdateExtension(id, base_path.AppendASCII("v2"), pem_path, ENABLED); 1965 std::string version2("2");
1966 UpdateNoPermissionsTestExtension(id, version2, ENABLED);
1793 1967
1794 // The extension should still be there and enabled. 1968 // The extension should still be there and enabled.
1795 extension = registry()->enabled_extensions().GetByID(id); 1969 const Extension* extension = registry()->enabled_extensions().GetByID(id);
1796 ASSERT_TRUE(extension); 1970 ASSERT_TRUE(extension);
1797 // The version should have changed. 1971 // The version should have changed.
1798 EXPECT_NE(extension->VersionString(), old_version); 1972 EXPECT_EQ(*extension->version(), base::Version(version2));
1799 } 1973 }
1800 1974
1801 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { 1975 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) {
1802 InitNeedCustodianApprovalFieldTrial(false); 1976 InitNeedCustodianApprovalFieldTrial(false);
1803 1977
1804 InitServices(true /* profile_is_supervised */); 1978 InitServices(true /* profile_is_supervised */);
1805 1979
1806 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1980 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1807 supervised_user_service()->AddPermissionRequestCreator( 1981 supervised_user_service()->AddPermissionRequestCreator(
1808 base::WrapUnique(creator)); 1982 base::WrapUnique(creator));
1809 1983
1810 std::string id = InstallPermissionsTestExtension(); 1984 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1811 1985
1812 // Update to a new version with increased permissions. 1986 // Update to a new version with increased permissions.
1813 // Since we don't require the custodian's approval, no permission request 1987 // Since we don't require the custodian's approval, no permission request
1814 // should be created. 1988 // should be created.
1815 const std::string version2("2"); 1989 const std::string version2("2");
1816 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1990 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1817 UpdateRequestId(id, version2), testing::_)) 1991 RequestId(id, version2), testing::_))
1818 .Times(0); 1992 .Times(0);
1819 UpdatePermissionsTestExtension(id, version2, DISABLED); 1993 UpdatePermissionsTestExtension(id, version2, DISABLED);
1820 } 1994 }
1821 1995
1822 TEST_F(ExtensionServiceTestSupervised, 1996 TEST_F(ExtensionServiceTestSupervised,
1823 UpdateWithPermissionIncreaseApprovalOldVersion) { 1997 UpdateWithPermissionIncreaseApprovalOldVersion) {
1824 InitNeedCustodianApprovalFieldTrial(true); 1998 InitNeedCustodianApprovalFieldTrial(true);
1825 1999
1826 InitServices(true /* profile_is_supervised */); 2000 InitServices(true /* profile_is_supervised */);
1827 2001
1828 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 2002 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1829 supervised_user_service()->AddPermissionRequestCreator( 2003 supervised_user_service()->AddPermissionRequestCreator(
1830 base::WrapUnique(creator)); 2004 base::WrapUnique(creator));
1831 2005
1832 const std::string version1("1"); 2006 const std::string version1("1");
1833 const std::string version2("2"); 2007 const std::string version2("2");
1834 2008
1835 std::string id = InstallPermissionsTestExtension(); 2009 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1836 2010
1837 // Update to a new version with increased permissions. 2011 // Update to a new version with increased permissions.
1838 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 2012 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1839 UpdateRequestId(id, version2), testing::_)); 2013 RequestId(id, version2), testing::_));
1840 UpdatePermissionsTestExtension(id, version2, DISABLED); 2014 UpdatePermissionsTestExtension(id, version2, DISABLED);
2015 Mock::VerifyAndClearExpectations(creator);
1841 2016
1842 // Simulate a custodian approval for re-enabling the extension coming in 2017 // Simulate a custodian approval for re-enabling the extension coming in
1843 // through Sync, but set the old version. This can happen when there already 2018 // through Sync, but set the old version. This can happen when there already
1844 // was a pending request for an earlier version of the extension. 2019 // was a pending request for an earlier version of the extension.
1845 sync_pb::EntitySpecifics specifics; 2020 sync_pb::EntitySpecifics specifics;
1846 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 2021 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1847 ext_specifics->set_id(id); 2022 ext_specifics->set_id(id);
1848 ext_specifics->set_enabled(true); 2023 ext_specifics->set_enabled(true);
1849 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 2024 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1850 ext_specifics->set_installed_by_custodian(true); 2025 ext_specifics->set_installed_by_custodian(true);
1851 ext_specifics->set_version(version1); 2026 ext_specifics->set_version(version1);
1852 2027
1853 // Attempting to re-enable an old version should result in a permission 2028 // Attempting to re-enable an old version should result in a permission
1854 // request for the current version. 2029 // request for the current version.
1855 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 2030 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1856 UpdateRequestId(id, version2), testing::_)); 2031 RequestId(id, version2), testing::_));
1857 2032
1858 SyncChangeList list = 2033 SyncChangeList list =
1859 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 2034 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1860 2035
1861 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 2036 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1862 // The re-enable should be ignored, since the version doesn't match. 2037 // The re-enable should be ignored, since the version doesn't match.
1863 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 2038 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1864 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 2039 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1865 id, base::Version(version1))); 2040 id, base::Version(version1)));
1866 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 2041 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1867 id, base::Version(version2))); 2042 id, base::Version(version2)));
2043 Mock::VerifyAndClearExpectations(creator);
1868 } 2044 }
1869 2045
1870 TEST_F(ExtensionServiceTestSupervised, 2046 TEST_F(ExtensionServiceTestSupervised,
1871 UpdateWithPermissionIncreaseApprovalMatchingVersion) { 2047 UpdateWithPermissionIncreaseApprovalMatchingVersion) {
1872 InitNeedCustodianApprovalFieldTrial(true); 2048 InitNeedCustodianApprovalFieldTrial(true);
1873 2049
1874 InitServices(true /* profile_is_supervised */); 2050 InitServices(true /* profile_is_supervised */);
1875 2051
1876 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 2052 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1877 supervised_user_service()->AddPermissionRequestCreator( 2053 supervised_user_service()->AddPermissionRequestCreator(
1878 base::WrapUnique(creator)); 2054 base::WrapUnique(creator));
1879 2055
1880 std::string id = InstallPermissionsTestExtension(); 2056 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1881 2057
1882 // Update to a new version with increased permissions. 2058 // Update to a new version with increased permissions.
1883 const std::string version2("2"); 2059 const std::string version2("2");
1884 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 2060 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1885 UpdateRequestId(id, version2), testing::_)); 2061 RequestId(id, version2), testing::_));
1886 UpdatePermissionsTestExtension(id, version2, DISABLED); 2062 UpdatePermissionsTestExtension(id, version2, DISABLED);
2063 Mock::VerifyAndClearExpectations(creator);
1887 2064
1888 // Simulate a custodian approval for re-enabling the extension coming in 2065 // Simulate a custodian approval for re-enabling the extension coming in
1889 // through Sync. 2066 // through Sync.
1890 sync_pb::EntitySpecifics specifics; 2067 sync_pb::EntitySpecifics specifics;
1891 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 2068 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1892 ext_specifics->set_id(id); 2069 ext_specifics->set_id(id);
1893 ext_specifics->set_enabled(true); 2070 ext_specifics->set_enabled(true);
1894 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 2071 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1895 ext_specifics->set_installed_by_custodian(true); 2072 ext_specifics->set_installed_by_custodian(true);
1896 ext_specifics->set_version(version2); 2073 ext_specifics->set_version(version2);
1897 2074
1898 SyncChangeList list = 2075 SyncChangeList list =
1899 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 2076 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1900 2077
1901 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 2078 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1902 // The extension should have gotten re-enabled. 2079 // The extension should have gotten re-enabled.
1903 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 2080 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1904 } 2081 }
1905 2082
1906 TEST_F(ExtensionServiceTestSupervised, 2083 TEST_F(ExtensionServiceTestSupervised,
1907 UpdateWithPermissionIncreaseApprovalNewVersion) { 2084 UpdateWithPermissionIncreaseApprovalNewVersion) {
1908 InitNeedCustodianApprovalFieldTrial(true); 2085 InitNeedCustodianApprovalFieldTrial(true);
1909 2086
1910 InitServices(true /* profile_is_supervised */); 2087 InitServices(true /* profile_is_supervised */);
1911 2088
1912 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 2089 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1913 supervised_user_service()->AddPermissionRequestCreator( 2090 supervised_user_service()->AddPermissionRequestCreator(
1914 base::WrapUnique(creator)); 2091 base::WrapUnique(creator));
1915 2092
1916 std::string id = InstallPermissionsTestExtension(); 2093 std::string id = InstallPermissionsTestExtension(true /* by_custodian */);
1917 2094
1918 // Update to a new version with increased permissions. 2095 // Update to a new version with increased permissions.
1919 const std::string version2("2"); 2096 const std::string version2("2");
1920 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 2097 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1921 UpdateRequestId(id, version2), testing::_)); 2098 RequestId(id, version2), testing::_));
1922 UpdatePermissionsTestExtension(id, version2, DISABLED); 2099 UpdatePermissionsTestExtension(id, version2, DISABLED);
2100 Mock::VerifyAndClearExpectations(creator);
1923 2101
1924 // Simulate a custodian approval for re-enabling the extension coming in 2102 // Simulate a custodian approval for re-enabling the extension coming in
1925 // through Sync. Set a newer version than we have installed. 2103 // through Sync. Set a newer version than we have installed.
1926 const std::string version3("3"); 2104 const std::string version3("3");
1927 sync_pb::EntitySpecifics specifics; 2105 sync_pb::EntitySpecifics specifics;
1928 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 2106 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1929 ext_specifics->set_id(id); 2107 ext_specifics->set_id(id);
1930 ext_specifics->set_enabled(true); 2108 ext_specifics->set_enabled(true);
1931 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 2109 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1932 ext_specifics->set_installed_by_custodian(true); 2110 ext_specifics->set_installed_by_custodian(true);
1933 ext_specifics->set_version(version3); 2111 ext_specifics->set_version(version3);
1934 2112
1935 // This should *not* result in a new permission request. 2113 // This should *not* result in a new permission request.
1936 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 2114 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(
1937 UpdateRequestId(id, version3), testing::_)) 2115 RequestId(id, version3), testing::_))
1938 .Times(0); 2116 .Times(0);
1939 2117
1940 SyncChangeList list = 2118 SyncChangeList list =
1941 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 2119 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1942 2120
1943 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 2121 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1944 // The re-enable should be delayed until the extension is updated to the 2122 // The re-enable should be delayed until the extension is updated to the
1945 // matching version. 2123 // matching version.
1946 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 2124 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1947 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( 2125 EXPECT_TRUE(extension_sync_service()->HasPendingReenable(
1948 id, base::Version(version3))); 2126 id, base::Version(version3)));
1949 2127
1950 // Update to the matching version. Now the extension should get enabled. 2128 // Update to the matching version. Now the extension should get enabled.
1951 UpdatePermissionsTestExtension(id, version3, ENABLED); 2129 UpdatePermissionsTestExtension(id, version3, ENABLED);
1952 } 2130 }
1953 2131
2132 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) {
2133 InitNeedCustodianApprovalFieldTrial(true);
2134 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2135
2136 InitServices(true /* profile_is_supervised */);
2137
2138 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
2139 supervised_user_service()->AddPermissionRequestCreator(
2140 base::WrapUnique(creator));
2141
2142 base::FilePath path = data_dir().AppendASCII("good.crx");
2143 std::string version("1.0.0.0");
2144
2145 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
2146 RequestId(good_crx, version), testing::_));
2147
2148 // Should be installed but disabled, a request for approval should be sent.
2149 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD);
2150 ASSERT_TRUE(extension);
2151 ASSERT_EQ(extension->id(), good_crx);
2152 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx));
2153 Mock::VerifyAndClearExpectations(creator);
2154
2155 SimulateCustodianApprovalChangeViaSync(good_crx, version,
2156 SyncChange::ACTION_ADD);
2157
2158 // The extension should be enabled now.
2159 EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx));
2160
2161 // Simulate approval removal coming via Sync.
2162 SimulateCustodianApprovalChangeViaSync(good_crx, version,
2163 SyncChange::ACTION_DELETE);
2164
2165 // The extension should be disabled now.
2166 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx));
2167 }
2168
2169 TEST_F(ExtensionServiceTestSupervised,
2170 UpdateSUInitiatedInstallWithoutPermissionIncrease) {
2171 InitNeedCustodianApprovalFieldTrial(true);
2172 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2173
2174 InitServices(true /* profile_is_supervised */);
2175
2176 std::string id = InstallNoPermissionsTestExtension(false /* by_custodian */);
2177 std::string version1("1");
2178
2179 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD);
2180
2181 // The extension should be enabled now.
2182 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2183
2184 std::string version2("2");
2185
2186 // Update to a new version.
2187 UpdateNoPermissionsTestExtension(id, version2, ENABLED);
2188
2189 // The extension should still be there and enabled.
2190 const Extension* extension = registry()->enabled_extensions().GetByID(id);
2191 ASSERT_TRUE(extension);
2192 // The version should have increased.
2193 EXPECT_EQ(1, extension->version()->CompareTo(base::Version(version1)));
2194
2195 // Check that the approved version has been updated in the prefs as well.
2196 // Prefs are updated via Sync. If the prefs are updated, then the new
2197 // approved version has been pushed to Sync as well.
2198 std::string approved_version;
2199 PrefService* pref_service = profile()->GetPrefs();
2200 const base::DictionaryValue* approved_extensions =
2201 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions);
2202 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version);
2203
2204 EXPECT_EQ(base::Version(approved_version), *extension->version());
2205 }
2206
2207 TEST_F(ExtensionServiceTestSupervised,
2208 UpdateSUInitiatedInstallWithPermissionIncrease) {
2209 InitNeedCustodianApprovalFieldTrial(true);
2210 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2211
2212 InitServices(true /* profile_is_supervised */);
2213
2214 std::string id = InstallPermissionsTestExtension(false /* by_custodian */);
2215 std::string version1("1");
2216
2217 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD);
2218
2219 // The extension should be enabled now.
2220 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2221
2222 std::string version3("3");
2223
2224 UpdatePermissionsTestExtension(id, version3, DISABLED);
2225
2226 // The extension should be disabled.
2227 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
2228 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason(
2229 id, Extension::DISABLE_PERMISSIONS_INCREASE));
2230
2231 std::string version2("2");
2232 // Approve an older version
2233 SimulateCustodianApprovalChangeViaSync(id, version2,
2234 SyncChange::ACTION_UPDATE);
2235
2236 // The extension should remain disabled.
2237 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
2238 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason(
2239 id, Extension::DISABLE_PERMISSIONS_INCREASE));
2240 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason(
2241 id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED));
2242
2243 // Approve the latest version
2244 SimulateCustodianApprovalChangeViaSync(id, version3,
2245 SyncChange::ACTION_UPDATE);
2246
2247 // The extension should be enabled again.
2248 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2249 }
2250
2251 TEST_F(ExtensionServiceTestSupervised,
2252 UpdateSUInitiatedInstallWithPermissionIncreaseApprovalArrivesFirst) {
2253 InitNeedCustodianApprovalFieldTrial(true);
2254 InitSupervisedUserInitiatedExtensionInstallFeature(true);
2255
2256 InitServices(true /* profile_is_supervised */);
2257
2258 std::string id = InstallPermissionsTestExtension(false /* by_custodian */);
2259
2260 std::string version1("1");
2261 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD);
2262
2263 // The extension should be enabled now.
2264 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2265
2266 std::string version2("2");
2267 // Approve a newer version
2268 SimulateCustodianApprovalChangeViaSync(id, version2,
2269 SyncChange::ACTION_UPDATE);
2270
2271 // The extension should be disabled.
2272 CheckDisabledForCustodianApproval(id);
2273
2274 // Now update the extension to the same version that was approved.
2275 UpdatePermissionsTestExtension(id, version2, ENABLED);
2276 // The extension should be enabled again.
2277 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
2278 }
2279
1954 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { 2280 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) {
1955 InitializeEmptyExtensionService(); 2281 InitializeEmptyExtensionService();
1956 extension_sync_service()->MergeDataAndStartSyncing( 2282 extension_sync_service()->MergeDataAndStartSyncing(
1957 syncer::EXTENSIONS, syncer::SyncDataList(), 2283 syncer::EXTENSIONS, syncer::SyncDataList(),
1958 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), 2284 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1959 base::WrapUnique(new syncer::SyncErrorFactoryMock())); 2285 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1960 2286
1961 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true); 2287 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true);
1962 // Install two extensions. 2288 // Install two extensions.
1963 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 2289 base::FilePath path1 = data_dir().AppendASCII("good.crx");
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 break; 2468 break;
2143 } 2469 }
2144 } 2470 }
2145 } 2471 }
2146 EXPECT_TRUE(found_delete); 2472 EXPECT_TRUE(found_delete);
2147 2473
2148 // Make sure there is one extension, and there are no more apps. 2474 // Make sure there is one extension, and there are no more apps.
2149 EXPECT_EQ(1u, extensions_processor.data().size()); 2475 EXPECT_EQ(1u, extensions_processor.data().size());
2150 EXPECT_TRUE(apps_processor.data().empty()); 2476 EXPECT_TRUE(apps_processor.data().empty());
2151 } 2477 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_test_with_install.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698