| 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/feature_list.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 20 #include "base/test/mock_entropy_provider.h" | 20 #include "base/test/mock_entropy_provider.h" |
| 21 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 21 #include "chrome/browser/extensions/component_loader.h" | 22 #include "chrome/browser/extensions/component_loader.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_service_test_with_install.h" | 24 #include "chrome/browser/extensions/extension_service_test_with_install.h" |
| 24 #include "chrome/browser/extensions/extension_sync_data.h" | 25 #include "chrome/browser/extensions/extension_sync_data.h" |
| 25 #include "chrome/browser/extensions/extension_sync_service.h" | 26 #include "chrome/browser/extensions/extension_sync_service.h" |
| 26 #include "chrome/browser/extensions/extension_util.h" | 27 #include "chrome/browser/extensions/extension_util.h" |
| 27 #include "chrome/browser/extensions/updater/extension_updater.h" | 28 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/extensions/sync_helper.h" | 32 #include "chrome/common/extensions/sync_helper.h" |
| 32 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 33 #include "components/browser_sync/browser/profile_sync_service.h" | 34 #include "components/browser_sync/browser/profile_sync_service.h" |
| 34 #include "components/crx_file/id_util.h" | 35 #include "components/crx_file/id_util.h" |
| 35 #include "components/variations/variations_associated_data.h" | 36 #include "components/variations/variations_associated_data.h" |
| 37 #include "extensions/browser/api_test_utils.h" |
| 36 #include "extensions/browser/app_sorting.h" | 38 #include "extensions/browser/app_sorting.h" |
| 37 #include "extensions/browser/extension_prefs.h" | 39 #include "extensions/browser/extension_prefs.h" |
| 38 #include "extensions/browser/extension_registry.h" | 40 #include "extensions/browser/extension_registry.h" |
| 39 #include "extensions/browser/extension_system.h" | 41 #include "extensions/browser/extension_system.h" |
| 40 #include "extensions/browser/management_policy.h" | 42 #include "extensions/browser/management_policy.h" |
| 41 #include "extensions/browser/test_management_policy.h" | 43 #include "extensions/browser/test_management_policy.h" |
| 42 #include "extensions/common/constants.h" | 44 #include "extensions/common/constants.h" |
| 43 #include "extensions/common/extension_builder.h" | 45 #include "extensions/common/extension_builder.h" |
| 44 #include "extensions/common/manifest_url_handlers.h" | 46 #include "extensions/common/manifest_url_handlers.h" |
| 45 #include "extensions/common/permissions/permission_set.h" | 47 #include "extensions/common/permissions/permission_set.h" |
| 46 #include "extensions/common/value_builder.h" | 48 #include "extensions/common/value_builder.h" |
| 47 #include "sync/api/fake_sync_change_processor.h" | 49 #include "sync/api/fake_sync_change_processor.h" |
| 48 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 50 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
| 49 #include "sync/api/sync_data.h" | 51 #include "sync/api/sync_data.h" |
| 50 #include "sync/api/sync_error_factory_mock.h" | 52 #include "sync/api/sync_error_factory_mock.h" |
| 51 #include "testing/gtest/include/gtest/gtest.h" | 53 #include "testing/gtest/include/gtest/gtest.h" |
| 52 | 54 |
| 53 #if defined(ENABLE_SUPERVISED_USERS) | 55 #if defined(ENABLE_SUPERVISED_USERS) |
| 54 #include "chrome/browser/supervised_user/permission_request_creator.h" | 56 #include "chrome/browser/supervised_user/permission_request_creator.h" |
| 55 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 57 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 56 #include "chrome/browser/supervised_user/supervised_user_features.h" | 58 #include "chrome/browser/supervised_user/supervised_user_features.h" |
| 57 #include "chrome/browser/supervised_user/supervised_user_service.h" | 59 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 58 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 60 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 59 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 61 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 60 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" | 62 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
| 61 #include "chrome/common/pref_names.h" | 63 #include "chrome/common/pref_names.h" |
| 62 #endif | 64 #endif |
| 63 | 65 |
| 66 using extensions::api_test_utils::RunFunctionAndReturnSingleResult; |
| 64 using extensions::AppSorting; | 67 using extensions::AppSorting; |
| 65 using extensions::Extension; | 68 using extensions::Extension; |
| 66 using extensions::ExtensionPrefs; | 69 using extensions::ExtensionPrefs; |
| 67 using extensions::ExtensionSyncData; | 70 using extensions::ExtensionSyncData; |
| 68 using extensions::ExtensionSystem; | 71 using extensions::ExtensionSystem; |
| 69 using extensions::Manifest; | 72 using extensions::Manifest; |
| 70 using extensions::PermissionSet; | 73 using extensions::PermissionSet; |
| 74 using extensions::WebstorePrivateIsPendingCustodianApprovalFunction; |
| 71 using syncer::SyncChange; | 75 using syncer::SyncChange; |
| 72 using syncer::SyncChangeList; | 76 using syncer::SyncChangeList; |
| 73 using testing::Mock; | 77 using testing::Mock; |
| 74 | 78 |
| 75 namespace { | 79 namespace { |
| 76 | 80 |
| 77 const char autoupdate[] = "ogjcoiohnmldgjemafoockdghcjciccf"; | 81 const char autoupdate[] = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 78 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 82 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 79 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; | 83 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
| 80 const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; | 84 const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1585 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { | 1589 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { |
| 1586 base::FeatureList::ClearInstanceForTesting(); | 1590 base::FeatureList::ClearInstanceForTesting(); |
| 1587 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 1591 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 1588 if (enabled) { | 1592 if (enabled) { |
| 1589 feature_list->InitializeFromCommandLine( | 1593 feature_list->InitializeFromCommandLine( |
| 1590 "SupervisedUserInitiatedExtensionInstall", std::string()); | 1594 "SupervisedUserInitiatedExtensionInstall", std::string()); |
| 1591 } | 1595 } |
| 1592 base::FeatureList::SetInstance(std::move(feature_list)); | 1596 base::FeatureList::SetInstance(std::move(feature_list)); |
| 1593 } | 1597 } |
| 1594 | 1598 |
| 1599 bool IsPendingCustodianApproval(const std::string& extension_id) { |
| 1600 auto function = make_scoped_refptr( |
| 1601 new WebstorePrivateIsPendingCustodianApprovalFunction()); |
| 1602 |
| 1603 std::unique_ptr<base::Value> result(RunFunctionAndReturnSingleResult( |
| 1604 function.get(), "[\"" + extension_id + "\"]", browser_context())); |
| 1605 |
| 1606 bool copy_bool_result = false; |
| 1607 EXPECT_TRUE(result->GetAsBoolean(©_bool_result)); |
| 1608 return copy_bool_result; |
| 1609 } |
| 1610 |
| 1595 void InitServices(bool profile_is_supervised) { | 1611 void InitServices(bool profile_is_supervised) { |
| 1596 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 1612 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 1597 params.profile_is_supervised = profile_is_supervised; | 1613 params.profile_is_supervised = profile_is_supervised; |
| 1598 // If profile is supervised, don't pass a pref file such that the testing | 1614 // If profile is supervised, don't pass a pref file such that the testing |
| 1599 // profile creates a pref service that uses SupervisedUserPrefStore. | 1615 // profile creates a pref service that uses SupervisedUserPrefStore. |
| 1600 if (profile_is_supervised) { | 1616 if (profile_is_supervised) { |
| 1601 params.pref_file = base::FilePath(); | 1617 params.pref_file = base::FilePath(); |
| 1602 } | 1618 } |
| 1603 InitializeExtensionService(params); | 1619 InitializeExtensionService(params); |
| 1604 StartSyncing(syncer::EXTENSIONS); | 1620 StartSyncing(syncer::EXTENSIONS); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 const Extension* extensions[] = { | 1779 const Extension* extensions[] = { |
| 1764 InstallCRX(path1, INSTALL_FAILED), | 1780 InstallCRX(path1, INSTALL_FAILED), |
| 1765 InstallCRX(path2, INSTALL_NEW) | 1781 InstallCRX(path2, INSTALL_NEW) |
| 1766 }; | 1782 }; |
| 1767 | 1783 |
| 1768 // Only the extension with the "installed by custodian" flag should have been | 1784 // Only the extension with the "installed by custodian" flag should have been |
| 1769 // installed and enabled. | 1785 // installed and enabled. |
| 1770 EXPECT_FALSE(extensions[0]); | 1786 EXPECT_FALSE(extensions[0]); |
| 1771 ASSERT_TRUE(extensions[1]); | 1787 ASSERT_TRUE(extensions[1]); |
| 1772 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | 1788 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); |
| 1789 EXPECT_FALSE(IsPendingCustodianApproval(extensions[1]->id())); |
| 1773 } | 1790 } |
| 1774 | 1791 |
| 1775 TEST_F(ExtensionServiceTestSupervised, | 1792 TEST_F(ExtensionServiceTestSupervised, |
| 1776 DelegatedAndPreinstalledExtensionIsSUFirst) { | 1793 DelegatedAndPreinstalledExtensionIsSUFirst) { |
| 1777 InitServices(false /* profile_is_supervised */); | 1794 InitServices(false /* profile_is_supervised */); |
| 1778 InitSupervisedUserInitiatedExtensionInstallFeature(false); | 1795 InitSupervisedUserInitiatedExtensionInstallFeature(false); |
| 1779 | 1796 |
| 1780 // Install an extension. | 1797 // Install an extension. |
| 1781 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1798 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1782 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 1799 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1857 InstallCRX(path2, INSTALL_NEW) | 1874 InstallCRX(path2, INSTALL_NEW) |
| 1858 }; | 1875 }; |
| 1859 | 1876 |
| 1860 // Only the extension with the "installed by custodian" flag should have been | 1877 // Only the extension with the "installed by custodian" flag should have been |
| 1861 // installed and enabled. | 1878 // installed and enabled. |
| 1862 // The extension missing the "installed by custodian" flag is a | 1879 // The extension missing the "installed by custodian" flag is a |
| 1863 // supervised user initiated install and hence not enabled. | 1880 // supervised user initiated install and hence not enabled. |
| 1864 ASSERT_TRUE(extensions[0]); | 1881 ASSERT_TRUE(extensions[0]); |
| 1865 ASSERT_TRUE(extensions[1]); | 1882 ASSERT_TRUE(extensions[1]); |
| 1866 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id())); | 1883 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id())); |
| 1884 EXPECT_TRUE(IsPendingCustodianApproval(extensions[0]->id())); |
| 1867 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | 1885 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); |
| 1886 EXPECT_FALSE(IsPendingCustodianApproval(extensions[1]->id())); |
| 1868 } | 1887 } |
| 1869 | 1888 |
| 1870 TEST_F(ExtensionServiceTestSupervised, | 1889 TEST_F(ExtensionServiceTestSupervised, |
| 1871 PreinstalledExtensionWithSUInitiatedInstalls) { | 1890 PreinstalledExtensionWithSUInitiatedInstalls) { |
| 1872 InitServices(false /* profile_is_supervised */); | 1891 InitServices(false /* profile_is_supervised */); |
| 1873 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 1892 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 1874 | 1893 |
| 1875 // Install an extension. | 1894 // Install an extension. |
| 1876 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1895 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1877 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 1896 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1888 RequestId(good_crx, version), testing::_)); | 1907 RequestId(good_crx, version), testing::_)); |
| 1889 | 1908 |
| 1890 // Now make the profile supervised. | 1909 // Now make the profile supervised. |
| 1891 profile()->AsTestingProfile()->SetSupervisedUserId( | 1910 profile()->AsTestingProfile()->SetSupervisedUserId( |
| 1892 supervised_users::kChildAccountSUID); | 1911 supervised_users::kChildAccountSUID); |
| 1893 | 1912 |
| 1894 Mock::VerifyAndClearExpectations(creator); | 1913 Mock::VerifyAndClearExpectations(creator); |
| 1895 | 1914 |
| 1896 // The extension should not be enabled anymore. | 1915 // The extension should not be enabled anymore. |
| 1897 CheckDisabledForCustodianApproval(id); | 1916 CheckDisabledForCustodianApproval(id); |
| 1917 EXPECT_TRUE(IsPendingCustodianApproval(id)); |
| 1898 } | 1918 } |
| 1899 | 1919 |
| 1900 TEST_F(ExtensionServiceTestSupervised, | 1920 TEST_F(ExtensionServiceTestSupervised, |
| 1901 PreinstalledExtensionWithoutSUInitiatedInstalls) { | 1921 PreinstalledExtensionWithoutSUInitiatedInstalls) { |
| 1902 InitServices(false /* profile_is_supervised */); | 1922 InitServices(false /* profile_is_supervised */); |
| 1903 InitSupervisedUserInitiatedExtensionInstallFeature(false); | 1923 InitSupervisedUserInitiatedExtensionInstallFeature(false); |
| 1904 | 1924 |
| 1905 // Install an extension. | 1925 // Install an extension. |
| 1906 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1926 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1907 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 1927 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 // Now install an extension. | 1966 // Now install an extension. |
| 1947 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1967 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1948 InstallCRX(path, INSTALL_NEW); | 1968 InstallCRX(path, INSTALL_NEW); |
| 1949 | 1969 |
| 1950 // No approval request should be sent. | 1970 // No approval request should be sent. |
| 1951 EXPECT_CALL(*creator, CreateExtensionInstallRequest(testing::_, testing::_)) | 1971 EXPECT_CALL(*creator, CreateExtensionInstallRequest(testing::_, testing::_)) |
| 1952 .Times(0); | 1972 .Times(0); |
| 1953 | 1973 |
| 1954 // Make sure it's enabled. | 1974 // Make sure it's enabled. |
| 1955 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 1975 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1976 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 1956 } | 1977 } |
| 1957 | 1978 |
| 1958 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { | 1979 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { |
| 1959 InitServices(true /* profile_is_supervised */); | 1980 InitServices(true /* profile_is_supervised */); |
| 1960 | 1981 |
| 1961 // Save the id, as the extension object will be destroyed during updating. | 1982 // Save the id, as the extension object will be destroyed during updating. |
| 1962 std::string id = InstallNoPermissionsTestExtension(true /* by_custodian */); | 1983 std::string id = InstallNoPermissionsTestExtension(true /* by_custodian */); |
| 1963 | 1984 |
| 1964 // Update to a new version. | 1985 // Update to a new version. |
| 1965 std::string version2("2"); | 1986 std::string version2("2"); |
| 1966 UpdateNoPermissionsTestExtension(id, version2, ENABLED); | 1987 UpdateNoPermissionsTestExtension(id, version2, ENABLED); |
| 1967 | 1988 |
| 1968 // The extension should still be there and enabled. | 1989 // The extension should still be there and enabled. |
| 1969 const Extension* extension = registry()->enabled_extensions().GetByID(id); | 1990 const Extension* extension = registry()->enabled_extensions().GetByID(id); |
| 1970 ASSERT_TRUE(extension); | 1991 ASSERT_TRUE(extension); |
| 1971 // The version should have changed. | 1992 // The version should have changed. |
| 1972 EXPECT_EQ(*extension->version(), base::Version(version2)); | 1993 EXPECT_EQ(*extension->version(), base::Version(version2)); |
| 1994 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 1973 } | 1995 } |
| 1974 | 1996 |
| 1975 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { | 1997 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { |
| 1976 InitNeedCustodianApprovalFieldTrial(false); | 1998 InitNeedCustodianApprovalFieldTrial(false); |
| 1977 | 1999 |
| 1978 InitServices(true /* profile_is_supervised */); | 2000 InitServices(true /* profile_is_supervised */); |
| 1979 | 2001 |
| 1980 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2002 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 1981 supervised_user_service()->AddPermissionRequestCreator( | 2003 supervised_user_service()->AddPermissionRequestCreator( |
| 1982 base::WrapUnique(creator)); | 2004 base::WrapUnique(creator)); |
| 1983 | 2005 |
| 1984 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | 2006 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
| 1985 | 2007 |
| 1986 // Update to a new version with increased permissions. | 2008 // Update to a new version with increased permissions. |
| 1987 // Since we don't require the custodian's approval, no permission request | 2009 // Since we don't require the custodian's approval, no permission request |
| 1988 // should be created. | 2010 // should be created. |
| 1989 const std::string version2("2"); | 2011 const std::string version2("2"); |
| 1990 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 2012 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
| 1991 RequestId(id, version2), testing::_)) | 2013 RequestId(id, version2), testing::_)) |
| 1992 .Times(0); | 2014 .Times(0); |
| 1993 UpdatePermissionsTestExtension(id, version2, DISABLED); | 2015 UpdatePermissionsTestExtension(id, version2, DISABLED); |
| 2016 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 1994 } | 2017 } |
| 1995 | 2018 |
| 1996 TEST_F(ExtensionServiceTestSupervised, | 2019 TEST_F(ExtensionServiceTestSupervised, |
| 1997 UpdateWithPermissionIncreaseApprovalOldVersion) { | 2020 UpdateWithPermissionIncreaseApprovalOldVersion) { |
| 1998 InitNeedCustodianApprovalFieldTrial(true); | 2021 InitNeedCustodianApprovalFieldTrial(true); |
| 1999 | 2022 |
| 2000 InitServices(true /* profile_is_supervised */); | 2023 InitServices(true /* profile_is_supervised */); |
| 2001 | 2024 |
| 2002 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2025 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2003 supervised_user_service()->AddPermissionRequestCreator( | 2026 supervised_user_service()->AddPermissionRequestCreator( |
| 2004 base::WrapUnique(creator)); | 2027 base::WrapUnique(creator)); |
| 2005 | 2028 |
| 2006 const std::string version1("1"); | 2029 const std::string version1("1"); |
| 2007 const std::string version2("2"); | 2030 const std::string version2("2"); |
| 2008 | 2031 |
| 2009 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | 2032 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
| 2010 | 2033 |
| 2011 // Update to a new version with increased permissions. | 2034 // Update to a new version with increased permissions. |
| 2012 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 2035 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
| 2013 RequestId(id, version2), testing::_)); | 2036 RequestId(id, version2), testing::_)); |
| 2014 UpdatePermissionsTestExtension(id, version2, DISABLED); | 2037 UpdatePermissionsTestExtension(id, version2, DISABLED); |
| 2015 Mock::VerifyAndClearExpectations(creator); | 2038 Mock::VerifyAndClearExpectations(creator); |
| 2039 EXPECT_TRUE(IsPendingCustodianApproval(id)); |
| 2016 | 2040 |
| 2017 // Simulate a custodian approval for re-enabling the extension coming in | 2041 // Simulate a custodian approval for re-enabling the extension coming in |
| 2018 // through Sync, but set the old version. This can happen when there already | 2042 // through Sync, but set the old version. This can happen when there already |
| 2019 // was a pending request for an earlier version of the extension. | 2043 // was a pending request for an earlier version of the extension. |
| 2020 sync_pb::EntitySpecifics specifics; | 2044 sync_pb::EntitySpecifics specifics; |
| 2021 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 2045 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
| 2022 ext_specifics->set_id(id); | 2046 ext_specifics->set_id(id); |
| 2023 ext_specifics->set_enabled(true); | 2047 ext_specifics->set_enabled(true); |
| 2024 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 2048 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
| 2025 ext_specifics->set_installed_by_custodian(true); | 2049 ext_specifics->set_installed_by_custodian(true); |
| 2026 ext_specifics->set_version(version1); | 2050 ext_specifics->set_version(version1); |
| 2027 | 2051 |
| 2028 // Attempting to re-enable an old version should result in a permission | 2052 // Attempting to re-enable an old version should result in a permission |
| 2029 // request for the current version. | 2053 // request for the current version. |
| 2030 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 2054 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
| 2031 RequestId(id, version2), testing::_)); | 2055 RequestId(id, version2), testing::_)); |
| 2032 | 2056 |
| 2033 SyncChangeList list = | 2057 SyncChangeList list = |
| 2034 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 2058 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
| 2035 | 2059 |
| 2036 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 2060 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 2037 // The re-enable should be ignored, since the version doesn't match. | 2061 // The re-enable should be ignored, since the version doesn't match. |
| 2038 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 2062 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 2039 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 2063 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
| 2040 id, base::Version(version1))); | 2064 id, base::Version(version1))); |
| 2041 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 2065 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
| 2042 id, base::Version(version2))); | 2066 id, base::Version(version2))); |
| 2043 Mock::VerifyAndClearExpectations(creator); | 2067 Mock::VerifyAndClearExpectations(creator); |
| 2068 EXPECT_TRUE(IsPendingCustodianApproval(id)); |
| 2044 } | 2069 } |
| 2045 | 2070 |
| 2046 TEST_F(ExtensionServiceTestSupervised, | 2071 TEST_F(ExtensionServiceTestSupervised, |
| 2047 UpdateWithPermissionIncreaseApprovalMatchingVersion) { | 2072 UpdateWithPermissionIncreaseApprovalMatchingVersion) { |
| 2048 InitNeedCustodianApprovalFieldTrial(true); | 2073 InitNeedCustodianApprovalFieldTrial(true); |
| 2049 | 2074 |
| 2050 InitServices(true /* profile_is_supervised */); | 2075 InitServices(true /* profile_is_supervised */); |
| 2051 | 2076 |
| 2052 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2077 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2053 supervised_user_service()->AddPermissionRequestCreator( | 2078 supervised_user_service()->AddPermissionRequestCreator( |
| 2054 base::WrapUnique(creator)); | 2079 base::WrapUnique(creator)); |
| 2055 | 2080 |
| 2056 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | 2081 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
| 2057 | 2082 |
| 2058 // Update to a new version with increased permissions. | 2083 // Update to a new version with increased permissions. |
| 2059 const std::string version2("2"); | 2084 const std::string version2("2"); |
| 2060 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | 2085 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( |
| 2061 RequestId(id, version2), testing::_)); | 2086 RequestId(id, version2), testing::_)); |
| 2062 UpdatePermissionsTestExtension(id, version2, DISABLED); | 2087 UpdatePermissionsTestExtension(id, version2, DISABLED); |
| 2063 Mock::VerifyAndClearExpectations(creator); | 2088 Mock::VerifyAndClearExpectations(creator); |
| 2089 EXPECT_TRUE(IsPendingCustodianApproval(id)); |
| 2064 | 2090 |
| 2065 // Simulate a custodian approval for re-enabling the extension coming in | 2091 // Simulate a custodian approval for re-enabling the extension coming in |
| 2066 // through Sync. | 2092 // through Sync. |
| 2067 sync_pb::EntitySpecifics specifics; | 2093 sync_pb::EntitySpecifics specifics; |
| 2068 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 2094 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
| 2069 ext_specifics->set_id(id); | 2095 ext_specifics->set_id(id); |
| 2070 ext_specifics->set_enabled(true); | 2096 ext_specifics->set_enabled(true); |
| 2071 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 2097 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
| 2072 ext_specifics->set_installed_by_custodian(true); | 2098 ext_specifics->set_installed_by_custodian(true); |
| 2073 ext_specifics->set_version(version2); | 2099 ext_specifics->set_version(version2); |
| 2074 | 2100 |
| 2075 SyncChangeList list = | 2101 SyncChangeList list = |
| 2076 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 2102 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
| 2077 | 2103 |
| 2078 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 2104 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 2079 // The extension should have gotten re-enabled. | 2105 // The extension should have gotten re-enabled. |
| 2080 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2106 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 2107 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2081 } | 2108 } |
| 2082 | 2109 |
| 2083 TEST_F(ExtensionServiceTestSupervised, | 2110 TEST_F(ExtensionServiceTestSupervised, |
| 2084 UpdateWithPermissionIncreaseApprovalNewVersion) { | 2111 UpdateWithPermissionIncreaseApprovalNewVersion) { |
| 2085 InitNeedCustodianApprovalFieldTrial(true); | 2112 InitNeedCustodianApprovalFieldTrial(true); |
| 2086 | 2113 |
| 2087 InitServices(true /* profile_is_supervised */); | 2114 InitServices(true /* profile_is_supervised */); |
| 2088 | 2115 |
| 2089 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2116 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2090 supervised_user_service()->AddPermissionRequestCreator( | 2117 supervised_user_service()->AddPermissionRequestCreator( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 | 2171 |
| 2145 EXPECT_CALL(*creator, CreateExtensionInstallRequest( | 2172 EXPECT_CALL(*creator, CreateExtensionInstallRequest( |
| 2146 RequestId(good_crx, version), testing::_)); | 2173 RequestId(good_crx, version), testing::_)); |
| 2147 | 2174 |
| 2148 // Should be installed but disabled, a request for approval should be sent. | 2175 // Should be installed but disabled, a request for approval should be sent. |
| 2149 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD); | 2176 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD); |
| 2150 ASSERT_TRUE(extension); | 2177 ASSERT_TRUE(extension); |
| 2151 ASSERT_EQ(extension->id(), good_crx); | 2178 ASSERT_EQ(extension->id(), good_crx); |
| 2152 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); | 2179 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); |
| 2153 Mock::VerifyAndClearExpectations(creator); | 2180 Mock::VerifyAndClearExpectations(creator); |
| 2181 EXPECT_TRUE(IsPendingCustodianApproval(extension->id())); |
| 2154 | 2182 |
| 2155 SimulateCustodianApprovalChangeViaSync(good_crx, version, | 2183 SimulateCustodianApprovalChangeViaSync(good_crx, version, |
| 2156 SyncChange::ACTION_ADD); | 2184 SyncChange::ACTION_ADD); |
| 2157 | 2185 |
| 2158 // The extension should be enabled now. | 2186 // The extension should be enabled now. |
| 2159 EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx)); | 2187 EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx)); |
| 2188 EXPECT_FALSE(IsPendingCustodianApproval(extension->id())); |
| 2160 | 2189 |
| 2161 // Simulate approval removal coming via Sync. | 2190 // Simulate approval removal coming via Sync. |
| 2162 SimulateCustodianApprovalChangeViaSync(good_crx, version, | 2191 SimulateCustodianApprovalChangeViaSync(good_crx, version, |
| 2163 SyncChange::ACTION_DELETE); | 2192 SyncChange::ACTION_DELETE); |
| 2164 | 2193 |
| 2165 // The extension should be disabled now. | 2194 // The extension should be disabled now. |
| 2166 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); | 2195 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); |
| 2196 EXPECT_TRUE(IsPendingCustodianApproval(extension->id())); |
| 2167 } | 2197 } |
| 2168 | 2198 |
| 2169 TEST_F(ExtensionServiceTestSupervised, | 2199 TEST_F(ExtensionServiceTestSupervised, |
| 2170 UpdateSUInitiatedInstallWithoutPermissionIncrease) { | 2200 UpdateSUInitiatedInstallWithoutPermissionIncrease) { |
| 2171 InitNeedCustodianApprovalFieldTrial(true); | 2201 InitNeedCustodianApprovalFieldTrial(true); |
| 2172 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2202 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2173 | 2203 |
| 2174 InitServices(true /* profile_is_supervised */); | 2204 InitServices(true /* profile_is_supervised */); |
| 2175 | 2205 |
| 2176 std::string id = InstallNoPermissionsTestExtension(false /* by_custodian */); | 2206 std::string id = InstallNoPermissionsTestExtension(false /* by_custodian */); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2195 // Check that the approved version has been updated in the prefs as well. | 2225 // Check that the approved version has been updated in the prefs as well. |
| 2196 // Prefs are updated via Sync. If the prefs are updated, then the new | 2226 // Prefs are updated via Sync. If the prefs are updated, then the new |
| 2197 // approved version has been pushed to Sync as well. | 2227 // approved version has been pushed to Sync as well. |
| 2198 std::string approved_version; | 2228 std::string approved_version; |
| 2199 PrefService* pref_service = profile()->GetPrefs(); | 2229 PrefService* pref_service = profile()->GetPrefs(); |
| 2200 const base::DictionaryValue* approved_extensions = | 2230 const base::DictionaryValue* approved_extensions = |
| 2201 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions); | 2231 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions); |
| 2202 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version); | 2232 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version); |
| 2203 | 2233 |
| 2204 EXPECT_EQ(base::Version(approved_version), *extension->version()); | 2234 EXPECT_EQ(base::Version(approved_version), *extension->version()); |
| 2235 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2205 } | 2236 } |
| 2206 | 2237 |
| 2207 TEST_F(ExtensionServiceTestSupervised, | 2238 TEST_F(ExtensionServiceTestSupervised, |
| 2208 UpdateSUInitiatedInstallWithPermissionIncrease) { | 2239 UpdateSUInitiatedInstallWithPermissionIncrease) { |
| 2209 InitNeedCustodianApprovalFieldTrial(true); | 2240 InitNeedCustodianApprovalFieldTrial(true); |
| 2210 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2241 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2211 | 2242 |
| 2212 InitServices(true /* profile_is_supervised */); | 2243 InitServices(true /* profile_is_supervised */); |
| 2213 | 2244 |
| 2214 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); | 2245 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2233 SimulateCustodianApprovalChangeViaSync(id, version2, | 2264 SimulateCustodianApprovalChangeViaSync(id, version2, |
| 2234 SyncChange::ACTION_UPDATE); | 2265 SyncChange::ACTION_UPDATE); |
| 2235 | 2266 |
| 2236 // The extension should remain disabled. | 2267 // The extension should remain disabled. |
| 2237 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 2268 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 2238 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( | 2269 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( |
| 2239 id, Extension::DISABLE_PERMISSIONS_INCREASE)); | 2270 id, Extension::DISABLE_PERMISSIONS_INCREASE)); |
| 2240 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( | 2271 EXPECT_TRUE(ExtensionPrefs::Get(profile())->HasDisableReason( |
| 2241 id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); | 2272 id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)); |
| 2242 | 2273 |
| 2274 EXPECT_TRUE(IsPendingCustodianApproval(id)); |
| 2243 // Approve the latest version | 2275 // Approve the latest version |
| 2244 SimulateCustodianApprovalChangeViaSync(id, version3, | 2276 SimulateCustodianApprovalChangeViaSync(id, version3, |
| 2245 SyncChange::ACTION_UPDATE); | 2277 SyncChange::ACTION_UPDATE); |
| 2246 | 2278 |
| 2247 // The extension should be enabled again. | 2279 // The extension should be enabled again. |
| 2248 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2280 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 2281 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2249 } | 2282 } |
| 2250 | 2283 |
| 2251 TEST_F(ExtensionServiceTestSupervised, | 2284 TEST_F(ExtensionServiceTestSupervised, |
| 2252 UpdateSUInitiatedInstallWithPermissionIncreaseApprovalArrivesFirst) { | 2285 UpdateSUInitiatedInstallWithPermissionIncreaseApprovalArrivesFirst) { |
| 2253 InitNeedCustodianApprovalFieldTrial(true); | 2286 InitNeedCustodianApprovalFieldTrial(true); |
| 2254 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2287 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2255 | 2288 |
| 2256 InitServices(true /* profile_is_supervised */); | 2289 InitServices(true /* profile_is_supervised */); |
| 2257 | 2290 |
| 2258 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); | 2291 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); |
| 2259 | 2292 |
| 2260 std::string version1("1"); | 2293 std::string version1("1"); |
| 2261 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); | 2294 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); |
| 2262 | 2295 |
| 2263 // The extension should be enabled now. | 2296 // The extension should be enabled now. |
| 2264 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2297 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 2265 | 2298 |
| 2266 std::string version2("2"); | 2299 std::string version2("2"); |
| 2267 // Approve a newer version | 2300 // Approve a newer version |
| 2268 SimulateCustodianApprovalChangeViaSync(id, version2, | 2301 SimulateCustodianApprovalChangeViaSync(id, version2, |
| 2269 SyncChange::ACTION_UPDATE); | 2302 SyncChange::ACTION_UPDATE); |
| 2270 | 2303 |
| 2271 // The extension should be disabled. | 2304 // The extension should be disabled. |
| 2272 CheckDisabledForCustodianApproval(id); | 2305 CheckDisabledForCustodianApproval(id); |
| 2273 | 2306 |
| 2274 // Now update the extension to the same version that was approved. | 2307 // Now update the extension to the same version that was approved. |
| 2275 UpdatePermissionsTestExtension(id, version2, ENABLED); | 2308 UpdatePermissionsTestExtension(id, version2, ENABLED); |
| 2276 // The extension should be enabled again. | 2309 // The extension should be enabled again. |
| 2277 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2310 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 2311 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2278 } | 2312 } |
| 2279 | 2313 |
| 2280 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { | 2314 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { |
| 2281 InitializeEmptyExtensionService(); | 2315 InitializeEmptyExtensionService(); |
| 2282 extension_sync_service()->MergeDataAndStartSyncing( | 2316 extension_sync_service()->MergeDataAndStartSyncing( |
| 2283 syncer::EXTENSIONS, syncer::SyncDataList(), | 2317 syncer::EXTENSIONS, syncer::SyncDataList(), |
| 2284 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), | 2318 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
| 2285 base::WrapUnique(new syncer::SyncErrorFactoryMock())); | 2319 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
| 2286 | 2320 |
| 2287 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true); | 2321 extensions::util::SetWasInstalledByCustodian(good2048, profile(), true); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2468 break; | 2502 break; |
| 2469 } | 2503 } |
| 2470 } | 2504 } |
| 2471 } | 2505 } |
| 2472 EXPECT_TRUE(found_delete); | 2506 EXPECT_TRUE(found_delete); |
| 2473 | 2507 |
| 2474 // Make sure there is one extension, and there are no more apps. | 2508 // Make sure there is one extension, and there are no more apps. |
| 2475 EXPECT_EQ(1u, extensions_processor.data().size()); | 2509 EXPECT_EQ(1u, extensions_processor.data().size()); |
| 2476 EXPECT_TRUE(apps_processor.data().empty()); | 2510 EXPECT_TRUE(apps_processor.data().empty()); |
| 2477 } | 2511 } |
| OLD | NEW |