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

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

Powered by Google App Engine
This is Rietveld 408576698