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

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

Issue 2004043002: Supervised Users Initiated Installs v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Style fix 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/files/file_util.h" 15 #include "base/files/file_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
19 #include "base/test/mock_entropy_provider.h" 20 #include "base/test/mock_entropy_provider.h"
20 #include "chrome/browser/extensions/component_loader.h" 21 #include "chrome/browser/extensions/component_loader.h"
21 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_service_test_with_install.h" 23 #include "chrome/browser/extensions/extension_service_test_with_install.h"
23 #include "chrome/browser/extensions/extension_sync_data.h" 24 #include "chrome/browser/extensions/extension_sync_data.h"
(...skipping 21 matching lines...) Expand all
45 #include "extensions/common/value_builder.h" 46 #include "extensions/common/value_builder.h"
46 #include "sync/api/fake_sync_change_processor.h" 47 #include "sync/api/fake_sync_change_processor.h"
47 #include "sync/api/sync_change_processor_wrapper_for_test.h" 48 #include "sync/api/sync_change_processor_wrapper_for_test.h"
48 #include "sync/api/sync_data.h" 49 #include "sync/api/sync_data.h"
49 #include "sync/api/sync_error_factory_mock.h" 50 #include "sync/api/sync_error_factory_mock.h"
50 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
51 52
52 #if defined(ENABLE_SUPERVISED_USERS) 53 #if defined(ENABLE_SUPERVISED_USERS)
53 #include "chrome/browser/supervised_user/permission_request_creator.h" 54 #include "chrome/browser/supervised_user/permission_request_creator.h"
54 #include "chrome/browser/supervised_user/supervised_user_constants.h" 55 #include "chrome/browser/supervised_user/supervised_user_constants.h"
56 #include "chrome/browser/supervised_user/supervised_user_features.h"
55 #include "chrome/browser/supervised_user/supervised_user_service.h" 57 #include "chrome/browser/supervised_user/supervised_user_service.h"
56 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 58 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
59 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
60 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
57 #endif 61 #endif
58 62
59 using extensions::AppSorting; 63 using extensions::AppSorting;
60 using extensions::Extension; 64 using extensions::Extension;
61 using extensions::ExtensionPrefs; 65 using extensions::ExtensionPrefs;
62 using extensions::ExtensionSyncData; 66 using extensions::ExtensionSyncData;
63 using extensions::ExtensionSystem; 67 using extensions::ExtensionSystem;
64 using extensions::Manifest; 68 using extensions::Manifest;
65 using extensions::PermissionSet; 69 using extensions::PermissionSet;
66 using syncer::SyncChange; 70 using syncer::SyncChange;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 ASSERT_TRUE(extension); 307 ASSERT_TRUE(extension);
304 ASSERT_TRUE(service()->IsExtensionEnabled(good0)); 308 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
305 309
306 // Sync starts up. 310 // Sync starts up.
307 extension_sync_service()->MergeDataAndStartSyncing( 311 extension_sync_service()->MergeDataAndStartSyncing(
308 syncer::EXTENSIONS, syncer::SyncDataList(), 312 syncer::EXTENSIONS, syncer::SyncDataList(),
309 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), 313 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
310 base::WrapUnique(new syncer::SyncErrorFactoryMock())); 314 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
311 315
312 // Then sync data arrives telling us to disable |good0|. 316 // Then sync data arrives telling us to disable |good0|.
313 ExtensionSyncData disable_good_crx(*extension, false, 317 ExtensionSyncData disable_good_crx(
Marc Treib 2016/05/23 15:32:42 And once more: no unrelated formatting changes ple
mamir 2016/05/23 19:35:14 Sorry! I made sure not to produce those but seems
314 Extension::DISABLE_USER_ACTION, false, 318 *extension, false, Extension::DISABLE_USER_ACTION, false, false,
315 false, ExtensionSyncData::BOOLEAN_UNSET); 319 ExtensionSyncData::BOOLEAN_UNSET);
316 SyncChangeList list( 320 SyncChangeList list(
317 1, disable_good_crx.GetSyncChange(SyncChange::ACTION_UPDATE)); 321 1, disable_good_crx.GetSyncChange(SyncChange::ACTION_UPDATE));
318 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 322 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
319 323
320 ASSERT_FALSE(service()->IsExtensionEnabled(good0)); 324 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
321 } 325 }
322 326
323 TEST_F(ExtensionServiceSyncTest, IgnoreSyncChangesWhenLocalStateIsMoreRecent) { 327 TEST_F(ExtensionServiceSyncTest, IgnoreSyncChangesWhenLocalStateIsMoreRecent) {
324 // Start the extension service with three extensions already installed. 328 // Start the extension service with three extensions already installed.
325 base::FilePath source_install_dir = 329 base::FilePath source_install_dir =
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 439 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
436 440
437 EXPECT_TRUE(processor->changes().empty()); 441 EXPECT_TRUE(processor->changes().empty());
438 } 442 }
439 443
440 { 444 {
441 const Extension* extension = service()->GetExtensionById(good0, true); 445 const Extension* extension = service()->GetExtensionById(good0, true);
442 ASSERT_TRUE(extension); 446 ASSERT_TRUE(extension);
443 447
444 // Add another disable reason. 448 // Add another disable reason.
445 ExtensionSyncData data(*extension, false, 449 ExtensionSyncData data(
446 Extension::DISABLE_USER_ACTION | 450 *extension, false, Extension::DISABLE_USER_ACTION |
447 Extension::DISABLE_PERMISSIONS_INCREASE, 451 Extension::DISABLE_PERMISSIONS_INCREASE,
448 false, false, ExtensionSyncData::BOOLEAN_UNSET); 452 false, false, ExtensionSyncData::BOOLEAN_UNSET);
449 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); 453 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE));
450 454
451 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 455 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
452 456
453 EXPECT_TRUE(processor->changes().empty()); 457 EXPECT_TRUE(processor->changes().empty());
454 } 458 }
455 459
456 { 460 {
457 const Extension* extension = service()->GetExtensionById(good0, true); 461 const Extension* extension = service()->GetExtensionById(good0, true);
458 ASSERT_TRUE(extension); 462 ASSERT_TRUE(extension);
459 463
460 // Uninstall the extension. 464 // Uninstall the extension.
461 ExtensionSyncData data(*extension, false, 465 ExtensionSyncData data(
462 Extension::DISABLE_USER_ACTION | 466 *extension, false, Extension::DISABLE_USER_ACTION |
463 Extension::DISABLE_PERMISSIONS_INCREASE, 467 Extension::DISABLE_PERMISSIONS_INCREASE,
464 false, false, ExtensionSyncData::BOOLEAN_UNSET); 468 false, false, ExtensionSyncData::BOOLEAN_UNSET);
465 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_DELETE)); 469 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_DELETE));
466 470
467 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 471 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
468 472
469 EXPECT_TRUE(processor->changes().empty()); 473 EXPECT_TRUE(processor->changes().empty());
470 } 474 }
471 } 475 }
472 476
473 TEST_F(ExtensionServiceSyncTest, GetSyncData) { 477 TEST_F(ExtensionServiceSyncTest, GetSyncData) {
474 InitializeEmptyExtensionService(); 478 InitializeEmptyExtensionService();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 ASSERT_EQ(list.size(), 1U); 766 ASSERT_EQ(list.size(), 1U);
763 767
764 std::unique_ptr<ExtensionSyncData> app_sync_data = 768 std::unique_ptr<ExtensionSyncData> app_sync_data =
765 ExtensionSyncData::CreateFromSyncData(list[0]); 769 ExtensionSyncData::CreateFromSyncData(list[0]);
766 ASSERT_TRUE(app_sync_data.get()); 770 ASSERT_TRUE(app_sync_data.get());
767 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data->app_launch_ordinal())); 771 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data->app_launch_ordinal()));
768 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data->page_ordinal())); 772 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data->page_ordinal()));
769 } 773 }
770 } 774 }
771 775
772 // TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from 776 // TODO(rdevlin.cronin): The OnExtensionMoved() method has been removed from
773 // ExtensionService, so this test probably needs a new home. Unfortunately, it 777 // ExtensionService, so this test probably needs a new home. Unfortunately, it
774 // relies pretty heavily on things like InitializeExtension[Sync]Service() and 778 // relies pretty heavily on things like InitializeExtension[Sync]Service() and
775 // PackAndInstallCRX(). When we clean up a bit more, this should move out. 779 // PackAndInstallCRX(). When we clean up a bit more, this should move out.
776 TEST_F(ExtensionServiceSyncTest, GetSyncAppDataUserSettingsOnExtensionMoved) { 780 TEST_F(ExtensionServiceSyncTest, GetSyncAppDataUserSettingsOnExtensionMoved) {
777 InitializeEmptyExtensionService(); 781 InitializeEmptyExtensionService();
778 const size_t kAppCount = 3; 782 const size_t kAppCount = 3;
779 const Extension* apps[kAppCount]; 783 const Extension* apps[kAppCount];
780 apps[0] = PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); 784 apps[0] = PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
781 apps[1] = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); 785 apps[1] = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
782 apps[2] = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW); 786 apps[2] = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 // Group name doesn't matter. 1566 // Group name doesn't matter.
1563 base::FieldTrialList::CreateFieldTrial( 1567 base::FieldTrialList::CreateFieldTrial(
1564 "SupervisedUserExtensionPermissionIncrease", "group"); 1568 "SupervisedUserExtensionPermissionIncrease", "group");
1565 std::map<std::string, std::string> params; 1569 std::map<std::string, std::string> params;
1566 params["legacy_supervised_user"] = enabled ? "true" : "false"; 1570 params["legacy_supervised_user"] = enabled ? "true" : "false";
1567 params["child_account"] = enabled ? "true" : "false"; 1571 params["child_account"] = enabled ? "true" : "false";
1568 variations::AssociateVariationParams( 1572 variations::AssociateVariationParams(
1569 "SupervisedUserExtensionPermissionIncrease", "group", params); 1573 "SupervisedUserExtensionPermissionIncrease", "group", params);
1570 } 1574 }
1571 1575
1576 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) {
1577 base::FeatureList::ClearInstanceForTesting();
1578 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
1579 if (enabled) {
1580 feature_list->InitializeFromCommandLine(
1581 "SupervisedUserInitiatedExtensionInstall", std::string());
1582 }
1583 base::FeatureList::SetInstance(std::move(feature_list));
1584 }
1585
1572 void InitServices(bool profile_is_supervised) { 1586 void InitServices(bool profile_is_supervised) {
1573 ExtensionServiceInitParams params = CreateDefaultInitParams(); 1587 ExtensionServiceInitParams params = CreateDefaultInitParams();
1574 params.profile_is_supervised = profile_is_supervised; 1588 params.profile_is_supervised = profile_is_supervised;
1589 // If profile is supervised, don't pass a pref file to force the testing
1590 // profile to create a pref service to uses SupervisedUserPrefStore instead.
1591 if (profile_is_supervised) {
1592 params.pref_file = base::FilePath();
1593 }
1575 InitializeExtensionService(params); 1594 InitializeExtensionService(params);
1576 StartSyncing(syncer::EXTENSIONS); 1595 StartSyncing(syncer::EXTENSIONS);
1577 1596
1578 supervised_user_service()->SetDelegate(this); 1597 supervised_user_service()->SetDelegate(this);
1579 supervised_user_service()->Init(); 1598 supervised_user_service()->Init();
1580 } 1599 }
1581 1600
1582 std::string InstallPermissionsTestExtension() { 1601 std::string InstallPermissionsTestExtension() {
1583 const std::string version("1"); 1602 const std::string version("1");
1584 1603
(...skipping 16 matching lines...) Expand all
1601 const Extension* extension = registry()->GetInstalledExtension(id); 1620 const Extension* extension = registry()->GetInstalledExtension(id);
1602 ASSERT_TRUE(extension); 1621 ASSERT_TRUE(extension);
1603 // The version should have been updated. 1622 // The version should have been updated.
1604 EXPECT_EQ(version, extension->VersionString()); 1623 EXPECT_EQ(version, extension->VersionString());
1605 } 1624 }
1606 1625
1607 SupervisedUserService* supervised_user_service() { 1626 SupervisedUserService* supervised_user_service() {
1608 return SupervisedUserServiceFactory::GetForProfile(profile()); 1627 return SupervisedUserServiceFactory::GetForProfile(profile());
1609 } 1628 }
1610 1629
1611 static std::string UpdateRequestId(const std::string& extension_id, 1630 static std::string RequestId(const std::string& extension_id,
1612 const std::string& version) { 1631 const std::string& version) {
1613 return SupervisedUserService::GetExtensionUpdateRequestId( 1632 return SupervisedUserService::GetExtensionRequestId(extension_id,
1614 extension_id, base::Version(version)); 1633 base::Version(version));
1615 } 1634 }
1616 1635
1617 private: 1636 private:
1618 // This prevents the legacy supervised user init code from running. 1637 // This prevents the legacy supervised user init code from running.
1619 bool SetActive(bool active) override { return true; } 1638 bool SetActive(bool active) override { return true; }
1620 1639
1621 base::FilePath base_path() const { 1640 base::FilePath base_path() const {
1622 return data_dir().AppendASCII("permissions_increase"); 1641 return data_dir().AppendASCII("permissions_increase");
1623 } 1642 }
1624 base::FilePath dir_path(const std::string& version) const { 1643 base::FilePath dir_path(const std::string& version) const {
(...skipping 11 matching lines...) Expand all
1636 MockPermissionRequestCreator() {} 1655 MockPermissionRequestCreator() {}
1637 ~MockPermissionRequestCreator() override {} 1656 ~MockPermissionRequestCreator() override {}
1638 1657
1639 bool IsEnabled() const override { return true; } 1658 bool IsEnabled() const override { return true; }
1640 1659
1641 void CreateURLAccessRequest(const GURL& url_requested, 1660 void CreateURLAccessRequest(const GURL& url_requested,
1642 const SuccessCallback& callback) override { 1661 const SuccessCallback& callback) override {
1643 FAIL(); 1662 FAIL();
1644 } 1663 }
1645 1664
1665 MOCK_METHOD2(CreateExtensionInstallRequest,
1666 void(const std::string& id,
1667 const SupervisedUserService::SuccessCallback& callback));
1668
1646 MOCK_METHOD2(CreateExtensionUpdateRequest, 1669 MOCK_METHOD2(CreateExtensionUpdateRequest,
1647 void(const std::string& id, 1670 void(const std::string& id,
1648 const SupervisedUserService::SuccessCallback& callback)); 1671 const SupervisedUserService::SuccessCallback& callback));
1649 1672
1650 private: 1673 private:
1651 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); 1674 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator);
1652 }; 1675 };
1653 1676
1654 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { 1677 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) {
1655 InitServices(true /* profile_is_supervised */); 1678 InitServices(true /* profile_is_supervised */);
1679 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1656 1680
1657 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 1681 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1658 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 1682 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1659 const Extension* extensions[] = { 1683 const Extension* extensions[] = {
1660 InstallCRX(path1, INSTALL_FAILED), 1684 InstallCRX(path1, INSTALL_FAILED),
1661 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) 1685 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)};
1662 };
1663 1686
1664 // Only the extension with the "installed by custodian" flag should have been 1687 // Only the extension with the "installed by custodian" flag should have been
1665 // installed and enabled. 1688 // installed and enabled.
1689 // While the extension missing the flag is a supervised user initiated install
1690 // and hence it is not installed.
1666 EXPECT_FALSE(extensions[0]); 1691 EXPECT_FALSE(extensions[0]);
1667 ASSERT_TRUE(extensions[1]); 1692 ASSERT_TRUE(extensions[1]);
1668 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); 1693 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1669 } 1694 }
1670 1695
1671 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) { 1696 TEST_F(ExtensionServiceTestSupervised,
1697 InstallAllowedByCustodianAndSupervisedUser) {
1698 InitServices(true /* profile_is_supervised */);
1699 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1700
1701 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1702 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
1703 const Extension* extensions[] = {
1704 InstallCRX(path1, INSTALL_WITHOUT_LOAD),
1705 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)};
1706
1707 // Only the extension with the "installed by custodian" flag should have been
1708 // installed and enabled.
1709 // The extension missing the "installed by custodian" flag is a
1710 // supervised user initiated install and hence not allowed.
1711 ASSERT_TRUE(extensions[0]);
1712 ASSERT_TRUE(extensions[1]);
1713 EXPECT_TRUE(registry()->disabled_extensions().Contains(extensions[0]->id()));
1714 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
1715 }
1716
1717 TEST_F(ExtensionServiceTestSupervised,
1718 PreinstalledExtensionWithSUInitiatedInstallsEnabled) {
1672 InitServices(false /* profile_is_supervised */); 1719 InitServices(false /* profile_is_supervised */);
1720 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1673 1721
1674 // Install an extension. 1722 // Install an extension.
1675 base::FilePath path = data_dir().AppendASCII("good.crx"); 1723 base::FilePath path = data_dir().AppendASCII("good.crx");
1676 const Extension* extension = InstallCRX(path, INSTALL_NEW); 1724 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1677 std::string id = extension->id(); 1725 std::string id = extension->id();
1726 // Make sure it's enabled.
1727 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1728
1729 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1730 supervised_user_service()->AddPermissionRequestCreator(
1731 base::WrapUnique(creator));
1732 const std::string version("1.0.0.0");
1733
1734 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1735 RequestId(good_crx, version), testing::_));
1678 1736
1679 // Now make the profile supervised. 1737 // Now make the profile supervised.
1680 profile()->AsTestingProfile()->SetSupervisedUserId( 1738 profile()->AsTestingProfile()->SetSupervisedUserId(
1739 supervised_users::kChildAccountSUID);
1740
1741 // The extension should not be enabled anymore.
1742 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1743 }
1744
1745 TEST_F(ExtensionServiceTestSupervised,
1746 PreinstalledExtensionWithSUInitiatedInstallsDisabled) {
1747 InitServices(false /* profile_is_supervised */);
1748 InitSupervisedUserInitiatedExtensionInstallFeature(false);
1749
1750 // Install an extension.
1751 base::FilePath path = data_dir().AppendASCII("good.crx");
1752 const Extension* extension = InstallCRX(path, INSTALL_NEW);
1753 std::string id = extension->id();
1754 // Make sure it's enabled.
1755 EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
1756
1757 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1758 supervised_user_service()->AddPermissionRequestCreator(
1759 base::WrapUnique(creator));
1760 const std::string version("1.0.0.0");
1761
1762 // No request should be sent because supervised user initiated installs
1763 // are disabled.
1764 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1765 RequestId(good_crx, version), testing::_))
1766 .Times(0);
1767
1768 // Now make the profile supervised.
1769 profile()->AsTestingProfile()->SetSupervisedUserId(
1681 supervised_users::kChildAccountSUID); 1770 supervised_users::kChildAccountSUID);
1682 1771
1683 // The extension should not be enabled anymore. 1772 // The extension should not be enabled anymore.
1684 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1773 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1685 } 1774 }
1686 1775
1687 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) { 1776 TEST_F(ExtensionServiceTestSupervised, UpdateWithoutPermissionIncrease) {
1688 InitServices(true /* profile_is_supervised */); 1777 InitServices(true /* profile_is_supervised */);
1689 1778
1690 base::FilePath base_path = data_dir().AppendASCII("autoupdate"); 1779 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
(...skipping 29 matching lines...) Expand all
1720 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1809 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1721 supervised_user_service()->AddPermissionRequestCreator( 1810 supervised_user_service()->AddPermissionRequestCreator(
1722 base::WrapUnique(creator)); 1811 base::WrapUnique(creator));
1723 1812
1724 std::string id = InstallPermissionsTestExtension(); 1813 std::string id = InstallPermissionsTestExtension();
1725 1814
1726 // Update to a new version with increased permissions. 1815 // Update to a new version with increased permissions.
1727 // Since we don't require the custodian's approval, no permission request 1816 // Since we don't require the custodian's approval, no permission request
1728 // should be created. 1817 // should be created.
1729 const std::string version2("2"); 1818 const std::string version2("2");
1730 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1819 EXPECT_CALL(*creator,
1731 UpdateRequestId(id, version2), testing::_)) 1820 CreateExtensionUpdateRequest(RequestId(id, version2), testing::_))
1732 .Times(0); 1821 .Times(0);
1733 UpdatePermissionsTestExtension(id, version2, DISABLED); 1822 UpdatePermissionsTestExtension(id, version2, DISABLED);
1734 } 1823 }
1735 1824
1736 TEST_F(ExtensionServiceTestSupervised, 1825 TEST_F(ExtensionServiceTestSupervised,
1737 UpdateWithPermissionIncreaseApprovalOldVersion) { 1826 UpdateWithPermissionIncreaseApprovalOldVersion) {
1738 InitNeedCustodianApprovalFieldTrial(true); 1827 InitNeedCustodianApprovalFieldTrial(true);
1739 1828
1740 InitServices(true /* profile_is_supervised */); 1829 InitServices(true /* profile_is_supervised */);
1741 1830
1742 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1831 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1743 supervised_user_service()->AddPermissionRequestCreator( 1832 supervised_user_service()->AddPermissionRequestCreator(
1744 base::WrapUnique(creator)); 1833 base::WrapUnique(creator));
1745 1834
1746 const std::string version1("1"); 1835 const std::string version1("1");
1747 const std::string version2("2"); 1836 const std::string version2("2");
1748 1837
1749 std::string id = InstallPermissionsTestExtension(); 1838 std::string id = InstallPermissionsTestExtension();
1750 1839
1751 // Update to a new version with increased permissions. 1840 // Update to a new version with increased permissions.
1752 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1841 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1753 UpdateRequestId(id, version2), testing::_)); 1842 testing::_));
1754 UpdatePermissionsTestExtension(id, version2, DISABLED); 1843 UpdatePermissionsTestExtension(id, version2, DISABLED);
1755 1844
1756 // Simulate a custodian approval for re-enabling the extension coming in 1845 // Simulate a custodian approval for re-enabling the extension coming in
1757 // through Sync, but set the old version. This can happen when there already 1846 // through Sync, but set the old version. This can happen when there already
1758 // was a pending request for an earlier version of the extension. 1847 // was a pending request for an earlier version of the extension.
1759 sync_pb::EntitySpecifics specifics; 1848 sync_pb::EntitySpecifics specifics;
1760 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1849 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1761 ext_specifics->set_id(id); 1850 ext_specifics->set_id(id);
1762 ext_specifics->set_enabled(true); 1851 ext_specifics->set_enabled(true);
1763 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1852 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1764 ext_specifics->set_installed_by_custodian(true); 1853 ext_specifics->set_installed_by_custodian(true);
1765 ext_specifics->set_version(version1); 1854 ext_specifics->set_version(version1);
1766 1855
1767 // Attempting to re-enable an old version should result in a permission 1856 // Attempting to re-enable an old version should result in a permission
1768 // request for the current version. 1857 // request for the current version.
1769 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1858 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1770 UpdateRequestId(id, version2), testing::_)); 1859 testing::_));
1771 1860
1772 SyncChangeList list = 1861 SyncChangeList list =
1773 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1862 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1774 1863
1775 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1864 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1776 // The re-enable should be ignored, since the version doesn't match. 1865 // The re-enable should be ignored, since the version doesn't match.
1777 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1866 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1778 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1867 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1779 id, base::Version(version1))); 1868 id, base::Version(version1)));
1780 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( 1869 EXPECT_FALSE(extension_sync_service()->HasPendingReenable(
1781 id, base::Version(version2))); 1870 id, base::Version(version2)));
1782 } 1871 }
1783 1872
1784 TEST_F(ExtensionServiceTestSupervised, 1873 TEST_F(ExtensionServiceTestSupervised,
1785 UpdateWithPermissionIncreaseApprovalMatchingVersion) { 1874 UpdateWithPermissionIncreaseApprovalMatchingVersion) {
1786 InitNeedCustodianApprovalFieldTrial(true); 1875 InitNeedCustodianApprovalFieldTrial(true);
1787 1876
1788 InitServices(true /* profile_is_supervised */); 1877 InitServices(true /* profile_is_supervised */);
1789 1878
1790 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1879 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1791 supervised_user_service()->AddPermissionRequestCreator( 1880 supervised_user_service()->AddPermissionRequestCreator(
1792 base::WrapUnique(creator)); 1881 base::WrapUnique(creator));
1793 1882
1794 std::string id = InstallPermissionsTestExtension(); 1883 std::string id = InstallPermissionsTestExtension();
1795 1884
1796 // Update to a new version with increased permissions. 1885 // Update to a new version with increased permissions.
1797 const std::string version2("2"); 1886 const std::string version2("2");
1798 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1887 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1799 UpdateRequestId(id, version2), testing::_)); 1888 testing::_));
1800 UpdatePermissionsTestExtension(id, version2, DISABLED); 1889 UpdatePermissionsTestExtension(id, version2, DISABLED);
1801 1890
1802 // Simulate a custodian approval for re-enabling the extension coming in 1891 // Simulate a custodian approval for re-enabling the extension coming in
1803 // through Sync. 1892 // through Sync.
1804 sync_pb::EntitySpecifics specifics; 1893 sync_pb::EntitySpecifics specifics;
1805 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1894 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1806 ext_specifics->set_id(id); 1895 ext_specifics->set_id(id);
1807 ext_specifics->set_enabled(true); 1896 ext_specifics->set_enabled(true);
1808 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1897 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1809 ext_specifics->set_installed_by_custodian(true); 1898 ext_specifics->set_installed_by_custodian(true);
(...skipping 14 matching lines...) Expand all
1824 InitServices(true /* profile_is_supervised */); 1913 InitServices(true /* profile_is_supervised */);
1825 1914
1826 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; 1915 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1827 supervised_user_service()->AddPermissionRequestCreator( 1916 supervised_user_service()->AddPermissionRequestCreator(
1828 base::WrapUnique(creator)); 1917 base::WrapUnique(creator));
1829 1918
1830 std::string id = InstallPermissionsTestExtension(); 1919 std::string id = InstallPermissionsTestExtension();
1831 1920
1832 // Update to a new version with increased permissions. 1921 // Update to a new version with increased permissions.
1833 const std::string version2("2"); 1922 const std::string version2("2");
1834 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1923 EXPECT_CALL(*creator, CreateExtensionUpdateRequest(RequestId(id, version2),
1835 UpdateRequestId(id, version2), testing::_)); 1924 testing::_));
1836 UpdatePermissionsTestExtension(id, version2, DISABLED); 1925 UpdatePermissionsTestExtension(id, version2, DISABLED);
1837 1926
1838 // Simulate a custodian approval for re-enabling the extension coming in 1927 // Simulate a custodian approval for re-enabling the extension coming in
1839 // through Sync. Set a newer version than we have installed. 1928 // through Sync. Set a newer version than we have installed.
1840 const std::string version3("3"); 1929 const std::string version3("3");
1841 sync_pb::EntitySpecifics specifics; 1930 sync_pb::EntitySpecifics specifics;
1842 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); 1931 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1843 ext_specifics->set_id(id); 1932 ext_specifics->set_id(id);
1844 ext_specifics->set_enabled(true); 1933 ext_specifics->set_enabled(true);
1845 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); 1934 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1846 ext_specifics->set_installed_by_custodian(true);
Marc Treib 2016/05/23 15:32:42 Don't remove this
mamir 2016/05/23 19:35:14 Done.
1847 ext_specifics->set_version(version3); 1935 ext_specifics->set_version(version3);
1848 1936
1849 // This should *not* result in a new permission request. 1937 // This should *not* result in a new permission request.
1850 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( 1938 EXPECT_CALL(*creator,
1851 UpdateRequestId(id, version3), testing::_)) 1939 CreateExtensionUpdateRequest(RequestId(id, version3), testing::_))
1852 .Times(0); 1940 .Times(0);
1853 1941
1854 SyncChangeList list = 1942 SyncChangeList list =
1855 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); 1943 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE);
1856 1944
1857 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); 1945 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
1858 // The re-enable should be delayed until the extension is updated to the 1946 // The re-enable should be delayed until the extension is updated to the
1859 // matching version. 1947 // matching version.
1860 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); 1948 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
1861 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( 1949 EXPECT_TRUE(extension_sync_service()->HasPendingReenable(
1862 id, base::Version(version3))); 1950 id, base::Version(version3)));
1863 1951
1864 // Update to the matching version. Now the extension should get enabled. 1952 // Update to the matching version. Now the extension should get enabled.
1865 UpdatePermissionsTestExtension(id, version3, ENABLED); 1953 UpdatePermissionsTestExtension(id, version3, ENABLED);
1866 } 1954 }
1867 1955
1956 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) {
1957 InitNeedCustodianApprovalFieldTrial(true);
1958 InitSupervisedUserInitiatedExtensionInstallFeature(true);
1959
1960 InitServices(true /* profile_is_supervised */);
1961
1962 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator;
1963 supervised_user_service()->AddPermissionRequestCreator(
1964 base::WrapUnique(creator));
1965
1966 base::FilePath path = data_dir().AppendASCII("good.crx");
1967 const std::string version("1.0.0.0");
1968
1969 EXPECT_CALL(*creator, CreateExtensionInstallRequest(
1970 RequestId(good_crx, version), testing::_));
1971
1972 // Should be installed but disabled, a request for approval should be sent.
1973 const Extension* extension = InstallCRX(path, INSTALL_WITHOUT_LOAD);
1974 ASSERT_EQ(extension->id(), good_crx);
1975 ASSERT_TRUE(extension);
1976 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
1977 EXPECT_FALSE(registry()->enabled_extensions().Contains(extension->id()));
1978
1979 // Simulate a custodian approval for enabling the extension coming in
1980 // through Sync.
1981 sync_pb::EntitySpecifics specifics;
1982 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
1983 ext_specifics->set_id(extension->id());
1984 ext_specifics->set_enabled(true);
1985 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE);
1986 ext_specifics->set_version(version);
1987
1988 SyncChangeList list1 =
1989 MakeSyncChangeList(extension->id(), specifics, SyncChange::ACTION_UPDATE);
1990
1991 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list1);
Marc Treib 2016/05/23 15:32:42 After this, we should make sure that the extension
mamir 2016/05/23 19:35:14 Yes this Sync change indeed shouldn't matter. But
Marc Treib 2016/05/24 09:54:57 But here, the Sync change will actually be a no-op
mamir 2016/06/03 09:45:54 Yes, it's not Synced. I will remove it then.
1992
1993 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
1994 supervised_users::kContentPackApprovedExtensions, extension->id());
1995 syncer::SyncData sync_data =
1996 SupervisedUserSettingsService::CreateSyncDataForSetting(
1997 key, base::StringValue(version));
1998
1999 SyncChangeList list2(
2000 1, SyncChange(FROM_HERE, SyncChange::ACTION_ADD, sync_data));
2001
2002 SupervisedUserSettingsService* supervised_user_settings_service =
2003 SupervisedUserSettingsServiceFactory::GetForProfile(profile());
2004 supervised_user_settings_service->ProcessSyncChanges(FROM_HERE, list2);
2005 // The extension should be enabled now.
2006 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
2007 }
2008
1868 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { 2009 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) {
1869 InitializeEmptyExtensionService(); 2010 InitializeEmptyExtensionService();
1870 extension_sync_service()->MergeDataAndStartSyncing( 2011 extension_sync_service()->MergeDataAndStartSyncing(
1871 syncer::EXTENSIONS, syncer::SyncDataList(), 2012 syncer::EXTENSIONS, syncer::SyncDataList(),
1872 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), 2013 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1873 base::WrapUnique(new syncer::SyncErrorFactoryMock())); 2014 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1874 2015
1875 // Install two extensions. 2016 // Install two extensions.
1876 base::FilePath path1 = data_dir().AppendASCII("good.crx"); 2017 base::FilePath path1 = data_dir().AppendASCII("good.crx");
1877 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); 2018 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 break; 2195 break;
2055 } 2196 }
2056 } 2197 }
2057 } 2198 }
2058 EXPECT_TRUE(found_delete); 2199 EXPECT_TRUE(found_delete);
2059 2200
2060 // Make sure there is one extension, and there are no more apps. 2201 // Make sure there is one extension, and there are no more apps.
2061 EXPECT_EQ(1u, extensions_processor.data().size()); 2202 EXPECT_EQ(1u, extensions_processor.data().size());
2062 EXPECT_TRUE(apps_processor.data().empty()); 2203 EXPECT_TRUE(apps_processor.data().empty());
2063 } 2204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698