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