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

Side by Side Diff: chrome/browser/extensions/extension_service_sync_unittest.cc

Issue 1948133004: CWS Private API - isPendingCustodianApproval (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Fixing nits about coding style. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/feature_list.h" 14 #include "base/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 #endif 61 #endif
60 62
63 using extensions::api_test_utils::RunFunctionAndReturnSingleResult;
61 using extensions::AppSorting; 64 using extensions::AppSorting;
62 using extensions::Extension; 65 using extensions::Extension;
63 using extensions::ExtensionPrefs; 66 using extensions::ExtensionPrefs;
64 using extensions::ExtensionSyncData; 67 using extensions::ExtensionSyncData;
65 using extensions::ExtensionSystem; 68 using extensions::ExtensionSystem;
66 using extensions::Manifest; 69 using extensions::Manifest;
67 using extensions::PermissionSet; 70 using extensions::PermissionSet;
68 using syncer::SyncChange; 71 using syncer::SyncChange;
69 using syncer::SyncChangeList; 72 using syncer::SyncChangeList;
70 73
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { 1578 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) {
1576 base::FeatureList::ClearInstanceForTesting(); 1579 base::FeatureList::ClearInstanceForTesting();
1577 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 1580 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
1578 if (enabled) { 1581 if (enabled) {
1579 feature_list->InitializeFromCommandLine( 1582 feature_list->InitializeFromCommandLine(
1580 "SupervisedUserInitiatedExtensionInstall", std::string()); 1583 "SupervisedUserInitiatedExtensionInstall", std::string());
1581 } 1584 }
1582 base::FeatureList::SetInstance(std::move(feature_list)); 1585 base::FeatureList::SetInstance(std::move(feature_list));
1583 } 1586 }
1584 1587
1588 bool IsExtensionPendingCustodianApproval(const std::string& extension_id) {
1589 std::unique_ptr<base::Value> result(RunFunctionAndReturnSingleResult(
1590 new extensions::
1591 WebstorePrivateIsExtensionPendingCustodianApprovalFunction(),
Marc Treib 2016/05/09 13:44:57 This looks like it'd create a memleak?
mamir 2016/05/09 14:42:19 Done.
1592 "[\"" + extension_id + "\"]", browser_context()));
1593
1594 bool copy_bool_result = false;
1595 EXPECT_TRUE(result->GetAsBoolean(&copy_bool_result));
1596 return copy_bool_result;
1597 }
1598
1585 void InitServices(bool profile_is_supervised) { 1599 void InitServices(bool profile_is_supervised) {
1586 ExtensionServiceInitParams params = CreateDefaultInitParams(); 1600 ExtensionServiceInitParams params = CreateDefaultInitParams();
1587 params.profile_is_supervised = profile_is_supervised; 1601 params.profile_is_supervised = profile_is_supervised;
1588 InitializeExtensionService(params); 1602 InitializeExtensionService(params);
1589 StartSyncing(syncer::EXTENSIONS); 1603 StartSyncing(syncer::EXTENSIONS);
1590 1604
1591 supervised_user_service()->SetDelegate(this); 1605 supervised_user_service()->SetDelegate(this);
1592 supervised_user_service()->Init(); 1606 supervised_user_service()->Init();
1593 } 1607 }
1594 1608
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 InstallCRX(path1, INSTALL_FAILED), 1692 InstallCRX(path1, INSTALL_FAILED),
1679 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)}; 1693 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)};
1680 1694
1681 // Only the extension with the "installed by custodian" flag should have been 1695 // Only the extension with the "installed by custodian" flag should have been
1682 // installed and enabled. 1696 // installed and enabled.
1683 // While the extension missing the flag is a supervised user initiated install 1697 // While the extension missing the flag is a supervised user initiated install
1684 // and hence it is not installed. 1698 // and hence it is not installed.
1685 EXPECT_FALSE(extensions[0]); 1699 EXPECT_FALSE(extensions[0]);
1686 ASSERT_TRUE(extensions[1]); 1700 ASSERT_TRUE(extensions[1]);
1687 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); 1701 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1702 EXPECT_FALSE(IsExtensionPendingCustodianApproval(extensions[1]->id()));
1688 } 1703 }
1689 1704
1690 TEST_F(ExtensionServiceTestSupervised, 1705 TEST_F(ExtensionServiceTestSupervised,
1691 InstallAllowedByCustodianAndSupervisedUser) { 1706 InstallAllowedByCustodianAndSupervisedUser) {
1692 InitServices(true /* profile_is_supervised */); 1707 InitServices(true /* profile_is_supervised */);
1693 InitSupervisedUserInitiatedExtensionInstallFeature(true); 1708 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1694 1709
1695 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 1710 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1696 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 1711 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1697 const Extension* extensions[] = { 1712 const Extension* extensions[] = {
1698 InstallCRX(path1, INSTALL_WITHOUT_LOAD), 1713 InstallCRX(path1, INSTALL_WITHOUT_LOAD),
1699 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)}; 1714 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)};
1700 1715
1701 // Only the extension with the "installed by custodian" flag should have been 1716 // Only the extension with the "installed by custodian" flag should have been
1702 // installed and enabled. 1717 // installed and enabled.
1703 // The extension missing the "installed by custodian" flag is a 1718 // The extension missing the "installed by custodian" flag is a
1704 // supervised user inititaed install and hence not alowed. 1719 // supervised user inititaed install and hence not alowed.
1705 ASSERT_TRUE(extensions[0]); 1720 ASSERT_TRUE(extensions[0]);
1706 ASSERT_TRUE(extensions[1]); 1721 ASSERT_TRUE(extensions[1]);
1707 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id())); 1722 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id()));
1723 EXPECT_TRUE(IsExtensionPendingCustodianApproval(extensions[0]->id()));
1708 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); 1724 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1725 EXPECT_FALSE(IsExtensionPendingCustodianApproval(extensions[1]->id()));
1709 } 1726 }
1710 1727
1711 TEST_F(ExtensionServiceTestSupervised, 1728 TEST_F(ExtensionServiceTestSupervised,
1712 PreinstalledExtensionWithSUInitiatedInstallsEnabled) { 1729 PreinstalledExtensionWithSUInitiatedInstallsEnabled) {
1713 InitServices(false /* profile_is_supervised */); 1730 InitServices(false /* profile_is_supervised */);
1714 InitSupervisedUserInitiatedExtensionInstallFeature(true); 1731 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1715 1732
1716 // Install an extension. 1733 // Install an extension.
1717 base::FilePath path = data_dir().AppendASCII("good.crx"); 1734 base::FilePath path = data_dir().AppendASCII("good.crx");
1718 const Extension* extension = InstallCRX(path, INSTALL_NEW); 1735 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1719 std::string id = extension->id(); 1736 std::string id = extension->id();
1720 // Make sure it's enabled. 1737 // Make sure it's enabled.
1721 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1738 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1722 1739
1723 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1740 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1724 supervised_user_service()->AddPermissionRequestCreator( 1741 supervised_user_service()->AddPermissionRequestCreator(
1725 base::WrapUnique(creator)); 1742 base::WrapUnique(creator));
1726 const std::string version("1.0.0.0"); 1743 const std::string version("1.0.0.0");
1727 1744
1728 EXPECT_CALL(*creator, CreateExtensionInstallRequest( 1745 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1729 RequestId(good_crx, version), testing::_)); 1746 RequestId(good_crx, version), testing::_));
1730 1747
1731 // Now make the profile supervised. 1748 // Now make the profile supervised.
1732 profile()->AsTestingProfile()->SetSupervisedUserId( 1749 profile()->AsTestingProfile()->SetSupervisedUserId(
1733 supervised_users::kChildAccountSUID); 1750 supervised_users::kChildAccountSUID);
1734 1751
1735 // The extension should not be enabled anymore. 1752 // The extension should not be enabled anymore.
1736 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1753 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1754 EXPECT_TRUE(IsExtensionPendingCustodianApproval(id));
1737 } 1755 }
1738 1756
1739 TEST_F(ExtensionServiceTestSupervised, 1757 TEST_F(ExtensionServiceTestSupervised,
1740 PreinstalledExtensionWithSUInitiatedInstallsDisabled) { 1758 PreinstalledExtensionWithSUInitiatedInstallsDisabled) {
1741 InitServices(false /* profile_is_supervised */); 1759 InitServices(false /* profile_is_supervised */);
1742 InitSupervisedUserInitiatedExtensionInstallFeature(false); 1760 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1743 1761
1744 // Install an extension. 1762 // Install an extension.
1745 base::FilePath path = data_dir().AppendASCII("good.crx"); 1763 base::FilePath path = data_dir().AppendASCII("good.crx");
1746 const Extension* extension = InstallCRX(path, INSTALL_NEW); 1764 const Extension* extension = InstallCRX(path, INSTALL_NEW);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 std::string old_version = extension->VersionString(); 1804 std::string old_version = extension->VersionString();
1787 1805
1788 // Update to a new version. 1806 // Update to a new version.
1789 PackCRXAndUpdateExtension(id, base_path.AppendASCII("v2"), pem_path, ENABLED); 1807 PackCRXAndUpdateExtension(id, base_path.AppendASCII("v2"), pem_path, ENABLED);
1790 1808
1791 // The extension should still be there and enabled. 1809 // The extension should still be there and enabled.
1792 extension = registry()->enabled_extensions().GetByID(id); 1810 extension = registry()->enabled_extensions().GetByID(id);
1793 ASSERT_TRUE(extension); 1811 ASSERT_TRUE(extension);
1794 // The version should have changed. 1812 // The version should have changed.
1795 EXPECT_NE(extension->VersionString(), old_version); 1813 EXPECT_NE(extension->VersionString(), old_version);
1814 EXPECT_FALSE(IsExtensionPendingCustodianApproval(id));
1796 } 1815 }
1797 1816
1798 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { 1817 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) {
1799 InitNeedCustodianApprovalFieldTrial(false); 1818 InitNeedCustodianApprovalFieldTrial(false);
1800 1819
1801 InitServices(true /* profile_is_supervised */); 1820 InitServices(true /* profile_is_supervised */);
1802 1821
1803 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1822 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1804 supervised_user_service()->AddPermissionRequestCreator( 1823 supervised_user_service()->AddPermissionRequestCreator(
1805 base::WrapUnique(creator)); 1824 base::WrapUnique(creator));
1806 1825
1807 std::string id = InstallPermissionsTestExtension(); 1826 std::string id = InstallPermissionsTestExtension();
1808 1827
1809 // Update to a new version with increased permissions. 1828 // Update to a new version with increased permissions.
1810 // Since we don't require the custodian's approval, no permission request 1829 // Since we don't require the custodian's approval, no permission request
1811 // should be created. 1830 // should be created.
1812 const std::string version2("2"); 1831 const std::string version2("2");
1813 EXPECT_CALL(*creator, 1832 EXPECT_CALL(*creator,
1814 CreateExtensionUpdateRequest(RequestId(id, version2), testing::_)) 1833 CreateExtensionUpdateRequest(RequestId(id, version2), testing::_))
1815 .Times(0); 1834 .Times(0);
1816 UpdatePermissionsTestExtension(id, version2, DISABLED); 1835 UpdatePermissionsTestExtension(id, version2, DISABLED);
1836 EXPECT_FALSE(IsExtensionPendingCustodianApproval(id));
1817 } 1837 }
1818 1838
1819 TEST_F(ExtensionServiceTestSupervised, 1839 TEST_F(ExtensionServiceTestSupervised,
1820 UpdateWithPermissionIncreaseApprovalOldVersion) { 1840 UpdateWithPermissionIncreaseApprovalOldVersion) {
1821 InitNeedCustodianApprovalFieldTrial(true); 1841 InitNeedCustodianApprovalFieldTrial(true);
1822 1842
1823 InitServices(true /* profile_is_supervised */); 1843 InitServices(true /* profile_is_supervised */);
1824 1844
1825 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1845 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1826 supervised_user_service()->AddPermissionRequestCreator( 1846 supervised_user_service()->AddPermissionRequestCreator(
1827 base::WrapUnique(creator)); 1847 base::WrapUnique(creator));
1828 1848
1829 const std::string version1("1"); 1849 const std::string version1("1");
1830 const std::string version2("2"); 1850 const std::string version2("2");
1831 1851
1832 std::string id = InstallPermissionsTestExtension(); 1852 std::string id = InstallPermissionsTestExtension();
1833 1853
1834 // Update to a new version with increased permissions. 1854 // Update to a new version with increased permissions.
1835 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2), 1855 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1836 testing::_)); 1856 testing::_));
1837 UpdatePermissionsTestExtension(id, version2, DISABLED); 1857 UpdatePermissionsTestExtension(id, version2, DISABLED);
1858 EXPECT_TRUE(IsExtensionPendingCustodianApproval(id));
1838 1859
1839 // Simulate a custodian approval for re-enabling the extension coming in 1860 // Simulate a custodian approval for re-enabling the extension coming in
1840 // through Sync, but set the old version. This can happen when there already 1861 // through Sync, but set the old version. This can happen when there already
1841 // was a pending request for an earlier version of the extension. 1862 // was a pending request for an earlier version of the extension.
1842 sync_pb::EntitySpecifics specifics; 1863 sync_pb::EntitySpecifics specifics;
1843 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1864 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1844 ext_specifics->set_id(id); 1865 ext_specifics->set_id(id);
1845 ext_specifics->set_enabled(true); 1866 ext_specifics->set_enabled(true);
1846 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1867 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1847 ext_specifics->set_installed_by_custodian(true); 1868 ext_specifics->set_installed_by_custodian(true);
1848 ext_specifics->set_version(version1); 1869 ext_specifics->set_version(version1);
1849 1870
1850 // Attempting to re-enable an old version should result in a permission 1871 // Attempting to re-enable an old version should result in a permission
1851 // request for the current version. 1872 // request for the current version.
1852 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2), 1873 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1853 testing::_)); 1874 testing::_));
1854 1875
1855 SyncChangeList list = 1876 SyncChangeList list =
1856 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1877 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1857 1878
1858 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1879 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1859 // The re-enable should be ignored, since the version doesn't match. 1880 // The re-enable should be ignored, since the version doesn't match.
1860 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1881 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1861 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1882 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1862 id, base::Version(version1))); 1883 id, base::Version(version1)));
1863 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1884 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1864 id, base::Version(version2))); 1885 id, base::Version(version2)));
1886 EXPECT_TRUE(IsExtensionPendingCustodianApproval(id));
1865 } 1887 }
1866 1888
1867 TEST_F(ExtensionServiceTestSupervised, 1889 TEST_F(ExtensionServiceTestSupervised,
1868 UpdateWithPermissionIncreaseApprovalMatchingVersion) { 1890 UpdateWithPermissionIncreaseApprovalMatchingVersion) {
1869 InitNeedCustodianApprovalFieldTrial(true); 1891 InitNeedCustodianApprovalFieldTrial(true);
1870 1892
1871 InitServices(true /* profile_is_supervised */); 1893 InitServices(true /* profile_is_supervised */);
1872 1894
1873 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1895 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1874 supervised_user_service()->AddPermissionRequestCreator( 1896 supervised_user_service()->AddPermissionRequestCreator(
1875 base::WrapUnique(creator)); 1897 base::WrapUnique(creator));
1876 1898
1877 std::string id = InstallPermissionsTestExtension(); 1899 std::string id = InstallPermissionsTestExtension();
1878 1900
1879 // Update to a new version with increased permissions. 1901 // Update to a new version with increased permissions.
1880 const std::string version2("2"); 1902 const std::string version2("2");
1881 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2), 1903 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1882 testing::_)); 1904 testing::_));
1883 UpdatePermissionsTestExtension(id, version2, DISABLED); 1905 UpdatePermissionsTestExtension(id, version2, DISABLED);
1906 EXPECT_TRUE(IsExtensionPendingCustodianApproval(id));
1884 1907
1885 // Simulate a custodian approval for re-enabling the extension coming in 1908 // Simulate a custodian approval for re-enabling the extension coming in
1886 // through Sync. 1909 // through Sync.
1887 sync_pb::EntitySpecifics specifics; 1910 sync_pb::EntitySpecifics specifics;
1888 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1911 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1889 ext_specifics->set_id(id); 1912 ext_specifics->set_id(id);
1890 ext_specifics->set_enabled(true); 1913 ext_specifics->set_enabled(true);
1891 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1914 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1892 ext_specifics->set_installed_by_custodian(true); 1915 ext_specifics->set_installed_by_custodian(true);
1893 ext_specifics->set_version(version2); 1916 ext_specifics->set_version(version2);
1894 1917
1895 SyncChangeList list = 1918 SyncChangeList list =
1896 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1919 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1897 1920
1898 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1921 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1899 // The extension should have gotten re-enabled. 1922 // The extension should have gotten re-enabled.
1900 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); 1923 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1924 EXPECT_FALSE(IsExtensionPendingCustodianApproval(id));
1901 } 1925 }
1902 1926
1903 TEST_F(ExtensionServiceTestSupervised, 1927 TEST_F(ExtensionServiceTestSupervised,
1904 UpdateWithPermissionIncreaseApprovalNewVersion) { 1928 UpdateWithPermissionIncreaseApprovalNewVersion) {
1905 InitNeedCustodianApprovalFieldTrial(true); 1929 InitNeedCustodianApprovalFieldTrial(true);
1906 1930
1907 InitServices(true /* profile_is_supervised */); 1931 InitServices(true /* profile_is_supervised */);
1908 1932
1909 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1933 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1910 supervised_user_service()->AddPermissionRequestCreator( 1934 supervised_user_service()->AddPermissionRequestCreator(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 EXPECT_CALL(*creator, CreateExtensionInstallRequest( 1988 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1965 RequestId(good_crx, version), testing::_)); 1989 RequestId(good_crx, version), testing::_));
1966 1990
1967 // Should be installed but disabled, a request for approval should be sent. 1991 // Should be installed but disabled, a request for approval should be sent.
1968 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD); 1992 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD);
1969 ASSERT_EQ(extension->id(), good_crx); 1993 ASSERT_EQ(extension->id(), good_crx);
1970 ASSERT_TRUE(extension); 1994 ASSERT_TRUE(extension);
1971 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); 1995 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
1972 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id())); 1996 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id()));
1973 1997
1998 EXPECT_TRUE(IsExtensionPendingCustodianApproval(extension->id()));
1999
1974 // Simulate a custodian approval for enabling the extension coming in 2000 // Simulate a custodian approval for enabling the extension coming in
1975 // through Sync. 2001 // through Sync.
1976 sync_pb::EntitySpecifics specifics; 2002 sync_pb::EntitySpecifics specifics;
1977 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 2003 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1978 ext_specifics->set_id(extension->id()); 2004 ext_specifics->set_id(extension->id());
1979 ext_specifics->set_enabled(true); 2005 ext_specifics->set_enabled(true);
1980 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 2006 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1981 ext_specifics->set_approved_by_custodian(true); 2007 ext_specifics->set_approved_by_custodian(true);
1982 ext_specifics->set_version(version); 2008 ext_specifics->set_version(version);
1983 2009
1984 SyncChangeList list = 2010 SyncChangeList list =
1985 MakeSyncChangeList(extension->id(), specifics, SyncChange::ACTION_UPDATE); 2011 MakeSyncChangeList(extension->id(), specifics, SyncChange::ACTION_UPDATE);
1986 2012
1987 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 2013 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1988 // The extension should be enabled now. 2014 // The extension should be enabled now.
1989 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); 2015 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
2016 EXPECT_FALSE(IsExtensionPendingCustodianApproval(extension->id()));
1990 } 2017 }
1991 2018
1992 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { 2019 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) {
1993 InitializeEmptyExtensionService(); 2020 InitializeEmptyExtensionService();
1994 extension_sync_service()->MergeDataAndStartSyncing( 2021 extension_sync_service()->MergeDataAndStartSyncing(
1995 syncer::EXTENSIONS, syncer::SyncDataList(), 2022 syncer::EXTENSIONS, syncer::SyncDataList(),
1996 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), 2023 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1997 base::WrapUnique(new syncer::SyncErrorFactoryMock())); 2024 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1998 2025
1999 // Install two extensions. 2026 // Install two extensions.
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 break; 2205 break;
2179 } 2206 }
2180 } 2207 }
2181 } 2208 }
2182 EXPECT_TRUE(found_delete); 2209 EXPECT_TRUE(found_delete);
2183 2210
2184 // Make sure there is one extension, and there are no more apps. 2211 // Make sure there is one extension, and there are no more apps.
2185 EXPECT_EQ(1u, extensions_processor.data().size()); 2212 EXPECT_EQ(1u, extensions_processor.data().size());
2186 EXPECT_TRUE(apps_processor.data().empty()); 2213 EXPECT_TRUE(apps_processor.data().empty());
2187 } 2214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698