Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 using extensions::ExtensionPrefs; | 61 using extensions::ExtensionPrefs; |
| 62 using extensions::ExtensionSyncData; | 62 using extensions::ExtensionSyncData; |
| 63 using extensions::ExtensionSystem; | 63 using extensions::ExtensionSystem; |
| 64 using extensions::Manifest; | 64 using extensions::Manifest; |
| 65 using extensions::PermissionSet; | 65 using extensions::PermissionSet; |
| 66 using syncer::SyncChange; | 66 using syncer::SyncChange; |
| 67 using syncer::SyncChangeList; | 67 using syncer::SyncChangeList; |
| 68 | 68 |
| 69 namespace { | 69 namespace { |
| 70 | 70 |
| 71 const char autoupdate[] = "ogjcoiohnmldgjemafoockdghcjciccf"; | |
| 71 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 72 const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 72 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; | 73 const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
| 74 const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; | |
| 73 const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 75 const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 74 const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; | 76 const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; |
| 77 const char permissions_increase[] = "pgdpcfcocojkjfbgpiianjngphoopgmo"; | |
| 75 const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 78 const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 76 | 79 |
| 77 SyncChangeList MakeSyncChangeList(const std::string& id, | 80 SyncChangeList MakeSyncChangeList(const std::string& id, |
| 78 const sync_pb::EntitySpecifics& specifics, | 81 const sync_pb::EntitySpecifics& specifics, |
| 79 SyncChange::SyncChangeType change_type) { | 82 SyncChange::SyncChangeType change_type) { |
| 80 syncer::SyncData sync_data = | 83 syncer::SyncData sync_data = |
| 81 syncer::SyncData::CreateLocalData(id, "Name", specifics); | 84 syncer::SyncData::CreateLocalData(id, "Name", specifics); |
| 82 return SyncChangeList(1, SyncChange(FROM_HERE, change_type, sync_data)); | 85 return SyncChangeList(1, SyncChange(FROM_HERE, change_type, sync_data)); |
| 83 } | 86 } |
| 84 | 87 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 | 308 |
| 306 // Sync starts up. | 309 // Sync starts up. |
| 307 extension_sync_service()->MergeDataAndStartSyncing( | 310 extension_sync_service()->MergeDataAndStartSyncing( |
| 308 syncer::EXTENSIONS, syncer::SyncDataList(), | 311 syncer::EXTENSIONS, syncer::SyncDataList(), |
| 309 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), | 312 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
| 310 base::WrapUnique(new syncer::SyncErrorFactoryMock())); | 313 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
| 311 | 314 |
| 312 // Then sync data arrives telling us to disable |good0|. | 315 // Then sync data arrives telling us to disable |good0|. |
| 313 ExtensionSyncData disable_good_crx(*extension, false, | 316 ExtensionSyncData disable_good_crx(*extension, false, |
| 314 Extension::DISABLE_USER_ACTION, false, | 317 Extension::DISABLE_USER_ACTION, false, |
| 315 false, ExtensionSyncData::BOOLEAN_UNSET); | 318 false, ExtensionSyncData::BOOLEAN_UNSET, |
| 319 false); | |
| 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 28 matching lines...) Expand all Loading... | |
| 354 ASSERT_FALSE(service()->IsExtensionEnabled(good2)); | 358 ASSERT_FALSE(service()->IsExtensionEnabled(good2)); |
| 355 | 359 |
| 356 const Extension* extension0 = service()->GetExtensionById(good0, true); | 360 const Extension* extension0 = service()->GetExtensionById(good0, true); |
| 357 const Extension* extension2 = service()->GetExtensionById(good2, true); | 361 const Extension* extension2 = service()->GetExtensionById(good2, true); |
| 358 ASSERT_TRUE(extensions::sync_helper::IsSyncable(extension0)); | 362 ASSERT_TRUE(extensions::sync_helper::IsSyncable(extension0)); |
| 359 ASSERT_TRUE(extensions::sync_helper::IsSyncable(extension2)); | 363 ASSERT_TRUE(extensions::sync_helper::IsSyncable(extension2)); |
| 360 | 364 |
| 361 // Now sync data comes in that says to disable good0 and enable good2. | 365 // Now sync data comes in that says to disable good0 and enable good2. |
| 362 ExtensionSyncData disable_good0(*extension0, false, | 366 ExtensionSyncData disable_good0(*extension0, false, |
| 363 Extension::DISABLE_USER_ACTION, false, false, | 367 Extension::DISABLE_USER_ACTION, false, false, |
| 364 ExtensionSyncData::BOOLEAN_UNSET); | 368 ExtensionSyncData::BOOLEAN_UNSET, false); |
| 365 ExtensionSyncData enable_good2(*extension2, true, Extension::DISABLE_NONE, | 369 ExtensionSyncData enable_good2(*extension2, true, Extension::DISABLE_NONE, |
| 366 false, false, | 370 false, false, |
| 367 ExtensionSyncData::BOOLEAN_UNSET); | 371 ExtensionSyncData::BOOLEAN_UNSET, false); |
| 368 syncer::SyncDataList sync_data; | 372 syncer::SyncDataList sync_data; |
| 369 sync_data.push_back(disable_good0.GetSyncData()); | 373 sync_data.push_back(disable_good0.GetSyncData()); |
| 370 sync_data.push_back(enable_good2.GetSyncData()); | 374 sync_data.push_back(enable_good2.GetSyncData()); |
| 371 extension_sync_service()->MergeDataAndStartSyncing( | 375 extension_sync_service()->MergeDataAndStartSyncing( |
| 372 syncer::EXTENSIONS, sync_data, | 376 syncer::EXTENSIONS, sync_data, |
| 373 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), | 377 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
| 374 base::WrapUnique(new syncer::SyncErrorFactoryMock())); | 378 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
| 375 | 379 |
| 376 // Both sync changes should be ignored, since the local state was changed | 380 // Both sync changes should be ignored, since the local state was changed |
| 377 // before sync started, and so the local state is considered more recent. | 381 // before sync started, and so the local state is considered more recent. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 408 | 412 |
| 409 // Simulate various incoming sync changes, and make sure they don't result in | 413 // Simulate various incoming sync changes, and make sure they don't result in |
| 410 // any outgoing changes. | 414 // any outgoing changes. |
| 411 | 415 |
| 412 { | 416 { |
| 413 const Extension* extension = service()->GetExtensionById(good0, true); | 417 const Extension* extension = service()->GetExtensionById(good0, true); |
| 414 ASSERT_TRUE(extension); | 418 ASSERT_TRUE(extension); |
| 415 | 419 |
| 416 // Disable the extension. | 420 // Disable the extension. |
| 417 ExtensionSyncData data(*extension, false, Extension::DISABLE_USER_ACTION, | 421 ExtensionSyncData data(*extension, false, Extension::DISABLE_USER_ACTION, |
| 418 false, false, ExtensionSyncData::BOOLEAN_UNSET); | 422 false, false, ExtensionSyncData::BOOLEAN_UNSET, |
| 423 false); | |
| 419 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); | 424 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); |
| 420 | 425 |
| 421 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 426 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 422 | 427 |
| 423 EXPECT_TRUE(processor->changes().empty()); | 428 EXPECT_TRUE(processor->changes().empty()); |
| 424 } | 429 } |
| 425 | 430 |
| 426 { | 431 { |
| 427 const Extension* extension = service()->GetExtensionById(good0, true); | 432 const Extension* extension = service()->GetExtensionById(good0, true); |
| 428 ASSERT_TRUE(extension); | 433 ASSERT_TRUE(extension); |
| 429 | 434 |
| 430 // Set incognito enabled to true. | 435 // Set incognito enabled to true. |
| 431 ExtensionSyncData data(*extension, false, Extension::DISABLE_NONE, true, | 436 ExtensionSyncData data(*extension, false, Extension::DISABLE_NONE, true, |
| 432 false, ExtensionSyncData::BOOLEAN_UNSET); | 437 false, ExtensionSyncData::BOOLEAN_UNSET, false); |
| 433 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); | 438 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); |
| 434 | 439 |
| 435 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 440 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 436 | 441 |
| 437 EXPECT_TRUE(processor->changes().empty()); | 442 EXPECT_TRUE(processor->changes().empty()); |
| 438 } | 443 } |
| 439 | 444 |
| 440 { | 445 { |
| 441 const Extension* extension = service()->GetExtensionById(good0, true); | 446 const Extension* extension = service()->GetExtensionById(good0, true); |
| 442 ASSERT_TRUE(extension); | 447 ASSERT_TRUE(extension); |
| 443 | 448 |
| 444 // Add another disable reason. | 449 // Add another disable reason. |
| 445 ExtensionSyncData data(*extension, false, | 450 ExtensionSyncData data(*extension, false, |
| 446 Extension::DISABLE_USER_ACTION | | 451 Extension::DISABLE_USER_ACTION | |
| 447 Extension::DISABLE_PERMISSIONS_INCREASE, | 452 Extension::DISABLE_PERMISSIONS_INCREASE, |
| 448 false, false, ExtensionSyncData::BOOLEAN_UNSET); | 453 false, false, ExtensionSyncData::BOOLEAN_UNSET, |
| 454 false); | |
| 449 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); | 455 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_UPDATE)); |
| 450 | 456 |
| 451 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 457 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 452 | 458 |
| 453 EXPECT_TRUE(processor->changes().empty()); | 459 EXPECT_TRUE(processor->changes().empty()); |
| 454 } | 460 } |
| 455 | 461 |
| 456 { | 462 { |
| 457 const Extension* extension = service()->GetExtensionById(good0, true); | 463 const Extension* extension = service()->GetExtensionById(good0, true); |
| 458 ASSERT_TRUE(extension); | 464 ASSERT_TRUE(extension); |
| 459 | 465 |
| 460 // Uninstall the extension. | 466 // Uninstall the extension. |
| 461 ExtensionSyncData data(*extension, false, | 467 ExtensionSyncData data(*extension, false, |
| 462 Extension::DISABLE_USER_ACTION | | 468 Extension::DISABLE_USER_ACTION | |
| 463 Extension::DISABLE_PERMISSIONS_INCREASE, | 469 Extension::DISABLE_PERMISSIONS_INCREASE, |
| 464 false, false, ExtensionSyncData::BOOLEAN_UNSET); | 470 false, false, ExtensionSyncData::BOOLEAN_UNSET, |
| 471 false); | |
| 465 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_DELETE)); | 472 SyncChangeList list(1, data.GetSyncChange(SyncChange::ACTION_DELETE)); |
| 466 | 473 |
| 467 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 474 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 468 | 475 |
| 469 EXPECT_TRUE(processor->changes().empty()); | 476 EXPECT_TRUE(processor->changes().empty()); |
| 470 } | 477 } |
| 471 } | 478 } |
| 472 | 479 |
| 473 TEST_F(ExtensionServiceSyncTest, GetSyncData) { | 480 TEST_F(ExtensionServiceSyncTest, GetSyncData) { |
| 474 InitializeEmptyExtensionService(); | 481 InitializeEmptyExtensionService(); |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1575 InitializeExtensionService(params); | 1582 InitializeExtensionService(params); |
| 1576 StartSyncing(syncer::EXTENSIONS); | 1583 StartSyncing(syncer::EXTENSIONS); |
| 1577 | 1584 |
| 1578 supervised_user_service()->SetDelegate(this); | 1585 supervised_user_service()->SetDelegate(this); |
| 1579 supervised_user_service()->Init(); | 1586 supervised_user_service()->Init(); |
| 1580 } | 1587 } |
| 1581 | 1588 |
| 1582 std::string InstallPermissionsTestExtension() { | 1589 std::string InstallPermissionsTestExtension() { |
| 1583 const std::string version("1"); | 1590 const std::string version("1"); |
| 1584 | 1591 |
| 1592 extensions::util::SetWasInstalledByCustodian(permissions_increase, | |
| 1593 profile()); | |
| 1585 const Extension* extension = | 1594 const Extension* extension = |
| 1586 PackAndInstallCRX(dir_path(version), pem_path(), INSTALL_NEW, | 1595 PackAndInstallCRX(dir_path(version), pem_path(), INSTALL_NEW); |
| 1587 Extension::WAS_INSTALLED_BY_CUSTODIAN); | 1596 |
| 1588 // The extension must now be installed and enabled. | 1597 // The extension must now be installed and enabled. |
| 1589 EXPECT_TRUE(extension); | 1598 EXPECT_TRUE(extension); |
| 1590 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | 1599 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 1591 EXPECT_EQ(version, extension->VersionString()); | 1600 EXPECT_EQ(version, extension->VersionString()); |
| 1592 | 1601 |
| 1593 return extension->id(); | 1602 return extension->id(); |
| 1594 } | 1603 } |
| 1595 | 1604 |
| 1596 void UpdatePermissionsTestExtension(const std::string& id, | 1605 void UpdatePermissionsTestExtension(const std::string& id, |
| 1597 const std::string& version, | 1606 const std::string& version, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1647 void(const std::string& id, | 1656 void(const std::string& id, |
| 1648 const SupervisedUserService::SuccessCallback& callback)); | 1657 const SupervisedUserService::SuccessCallback& callback)); |
| 1649 | 1658 |
| 1650 private: | 1659 private: |
| 1651 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); | 1660 DISALLOW_COPY_AND_ASSIGN(MockPermissionRequestCreator); |
| 1652 }; | 1661 }; |
| 1653 | 1662 |
| 1654 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { | 1663 TEST_F(ExtensionServiceTestSupervised, InstallOnlyAllowedByCustodian) { |
| 1655 InitServices(true /* profile_is_supervised */); | 1664 InitServices(true /* profile_is_supervised */); |
| 1656 | 1665 |
| 1666 extensions::util::SetWasInstalledByCustodian(good2048, profile()); | |
| 1667 | |
| 1657 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 1668 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
| 1658 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | 1669 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
| 1659 const Extension* extensions[] = { | 1670 const Extension* extensions[] = { |
| 1660 InstallCRX(path1, INSTALL_FAILED), | 1671 InstallCRX(path1, INSTALL_FAILED), |
| 1661 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) | 1672 InstallCRX(path2, INSTALL_NEW) |
| 1662 }; | 1673 }; |
| 1663 | 1674 |
| 1664 // Only the extension with the "installed by custodian" flag should have been | 1675 // Only the extension with the "installed by custodian" flag should have been |
| 1665 // installed and enabled. | 1676 // installed and enabled. |
| 1666 EXPECT_FALSE(extensions[0]); | 1677 EXPECT_FALSE(extensions[0]); |
| 1667 ASSERT_TRUE(extensions[1]); | 1678 ASSERT_TRUE(extensions[1]); |
| 1668 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); | 1679 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); |
| 1669 } | 1680 } |
| 1670 | 1681 |
| 1671 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) { | 1682 TEST_F(ExtensionServiceTestSupervised, PreinstalledExtension) { |
| 1672 InitServices(false /* profile_is_supervised */); | 1683 InitServices(false /* profile_is_supervised */); |
| 1673 | 1684 |
| 1674 // Install an extension. | 1685 // Install an extension. |
| 1675 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1686 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1676 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 1687 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 1677 std::string id = extension->id(); | 1688 std::string id = extension->id(); |
| 1678 | 1689 |
| 1679 // Now make the profile supervised. | 1690 // Now make the profile supervised. |
| 1680 profile()->AsTestingProfile()->SetSupervisedUserId( | 1691 profile()->AsTestingProfile()->SetSupervisedUserId( |
| 1681 supervised_users::kChildAccountSUID); | 1692 supervised_users::kChildAccountSUID); |
| 1682 | 1693 |
| 1683 // The extension should not be enabled anymore. | 1694 // The extension should not be enabled anymore. |
| 1684 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 1695 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 1685 } | 1696 } |
| 1686 | 1697 |
| 1698 TEST_F(ExtensionServiceTestSupervised, | |
| 1699 DelegatedAndPreinstalledExtensionIsSUFirst) { | |
| 1700 InitServices(false /* profile_is_supervised */); | |
| 1701 | |
| 1702 // Install an extension. | |
| 1703 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
| 1704 const Extension* extension = InstallCRX(path, INSTALL_NEW); | |
| 1705 std::string id = extension->id(); | |
| 1706 const std::string version("1.0.0.0"); | |
| 1707 // It should be enabled. | |
| 1708 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
| 1709 | |
| 1710 // Now make the profile supervised. | |
| 1711 profile()->AsTestingProfile()->SetSupervisedUserId( | |
| 1712 supervised_users::kChildAccountSUID); | |
| 1713 | |
| 1714 // It should not be enabled now (it is not loaded at all actually). | |
| 1715 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
| 1716 | |
| 1717 // Simulate data sync with the "was_installed_by_custodian" flag set to 1. | |
| 1718 sync_pb::EntitySpecifics specifics; | |
| 1719 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | |
| 1720 ext_specifics->set_id(id); | |
| 1721 ext_specifics->set_enabled(true); | |
| 1722 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | |
| 1723 ext_specifics->set_installed_by_custodian(true); | |
| 1724 ext_specifics->set_version(version); | |
| 1725 | |
| 1726 SyncChangeList list = | |
| 1727 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | |
| 1728 | |
| 1729 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | |
| 1730 | |
| 1731 // The extension should be enabled again. | |
| 1732 const Extension* installed_extension = | |
| 1733 registry()->enabled_extensions().GetByID(id); | |
| 1734 ASSERT_TRUE(installed_extension); | |
|
Marc Treib
2016/06/17 08:56:54
Since you don't need |installed_extension| afterwa
mamir
2016/06/17 16:12:54
Done.
| |
| 1735 EXPECT_TRUE(extensions::util::WasInstalledByCustodian(id, profile())); | |
| 1736 } | |
| 1737 | |
| 1738 TEST_F(ExtensionServiceTestSupervised, | |
| 1739 DelegatedAndPreinstalledExtensionSyncFirst) { | |
| 1740 InitServices(false /* profile_is_supervised */); | |
| 1741 | |
| 1742 // Install an extension. | |
| 1743 base::FilePath path = data_dir().AppendASCII("good.crx"); | |
| 1744 const Extension* extension = InstallCRX(path, INSTALL_NEW); | |
| 1745 std::string id = extension->id(); | |
| 1746 const std::string version("1.0.0.0"); | |
| 1747 | |
| 1748 // It should be enabled. | |
| 1749 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
| 1750 | |
| 1751 // Simulate data sync with the "was_installed_by_custodian" flag set to 1. | |
| 1752 sync_pb::EntitySpecifics specifics; | |
| 1753 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | |
| 1754 ext_specifics->set_id(id); | |
| 1755 ext_specifics->set_enabled(true); | |
| 1756 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | |
| 1757 ext_specifics->set_installed_by_custodian(true); | |
| 1758 ext_specifics->set_version(version); | |
| 1759 | |
| 1760 SyncChangeList list = | |
| 1761 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | |
| 1762 | |
| 1763 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | |
| 1764 | |
| 1765 // Now make the profile supervised. | |
| 1766 profile()->AsTestingProfile()->SetSupervisedUserId( | |
| 1767 supervised_users::kChildAccountSUID); | |
| 1768 | |
| 1769 // The extension should be enabled. | |
| 1770 const Extension* installed_extension = | |
| 1771 registry()->enabled_extensions().GetByID(id); | |
| 1772 ASSERT_TRUE(installed_extension); | |
|
Marc Treib
2016/06/17 08:56:54
Same here.
mamir
2016/06/17 16:12:54
Done.
| |
| 1773 EXPECT_TRUE(extensions::util::WasInstalledByCustodian(id, profile())); | |
| 1774 } | |
| 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"); |
| 1691 base::FilePath pem_path = base_path.AppendASCII("key.pem"); | 1780 base::FilePath pem_path = base_path.AppendASCII("key.pem"); |
| 1692 | 1781 |
| 1782 extensions::util::SetWasInstalledByCustodian(autoupdate, profile()); | |
| 1693 const Extension* extension = | 1783 const Extension* extension = |
| 1694 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW, | 1784 PackAndInstallCRX(base_path.AppendASCII("v1"), pem_path, INSTALL_NEW); |
| 1695 Extension::WAS_INSTALLED_BY_CUSTODIAN); | 1785 |
| 1696 // The extension must now be installed and enabled. | 1786 // The extension must now be installed and enabled. |
| 1697 ASSERT_TRUE(extension); | 1787 ASSERT_TRUE(extension); |
| 1698 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | 1788 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 1699 | 1789 |
| 1700 // Save the id, as the extension object will be destroyed during updating. | 1790 // Save the id, as the extension object will be destroyed during updating. |
| 1701 std::string id = extension->id(); | 1791 std::string id = extension->id(); |
| 1702 | 1792 |
| 1703 std::string old_version = extension->VersionString(); | 1793 std::string old_version = extension->VersionString(); |
| 1704 | 1794 |
| 1705 // Update to a new version. | 1795 // Update to a new version. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1865 UpdatePermissionsTestExtension(id, version3, ENABLED); | 1955 UpdatePermissionsTestExtension(id, version3, ENABLED); |
| 1866 } | 1956 } |
| 1867 | 1957 |
| 1868 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { | 1958 TEST_F(ExtensionServiceSyncTest, SyncUninstallByCustodianSkipsPolicy) { |
| 1869 InitializeEmptyExtensionService(); | 1959 InitializeEmptyExtensionService(); |
| 1870 extension_sync_service()->MergeDataAndStartSyncing( | 1960 extension_sync_service()->MergeDataAndStartSyncing( |
| 1871 syncer::EXTENSIONS, syncer::SyncDataList(), | 1961 syncer::EXTENSIONS, syncer::SyncDataList(), |
| 1872 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), | 1962 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
| 1873 base::WrapUnique(new syncer::SyncErrorFactoryMock())); | 1963 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
| 1874 | 1964 |
| 1965 extensions::util::SetWasInstalledByCustodian(good2048, profile()); | |
| 1875 // Install two extensions. | 1966 // Install two extensions. |
| 1876 base::FilePath path1 = data_dir().AppendASCII("good.crx"); | 1967 base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
| 1877 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); | 1968 base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
| 1878 const Extension* extensions[] = { | 1969 const Extension* extensions[] = { |
| 1879 InstallCRX(path1, INSTALL_NEW), | 1970 InstallCRX(path1, INSTALL_NEW), |
| 1880 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) | 1971 InstallCRX(path2, INSTALL_NEW) |
| 1881 }; | 1972 }; |
| 1882 | 1973 |
| 1883 // Add a policy provider that will disallow any changes. | 1974 // Add a policy provider that will disallow any changes. |
| 1884 extensions::TestManagementPolicyProvider provider( | 1975 extensions::TestManagementPolicyProvider provider( |
| 1885 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 1976 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 1886 ExtensionSystem::Get( | 1977 ExtensionSystem::Get( |
| 1887 browser_context())->management_policy()->RegisterProvider(&provider); | 1978 browser_context())->management_policy()->RegisterProvider(&provider); |
| 1888 | 1979 |
| 1889 // Create a sync deletion for each extension. | 1980 // Create a sync deletion for each extension. |
| 1890 SyncChangeList list; | 1981 SyncChangeList list; |
| 1891 for (size_t i = 0; i < arraysize(extensions); i++) { | 1982 for (size_t i = 0; i < arraysize(extensions); i++) { |
| 1892 const std::string& id = extensions[i]->id(); | 1983 const std::string& id = extensions[i]->id(); |
| 1893 sync_pb::EntitySpecifics specifics; | 1984 sync_pb::EntitySpecifics specifics; |
| 1894 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1985 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
| 1895 ext_specifics->set_id(id); | 1986 ext_specifics->set_id(id); |
| 1896 ext_specifics->set_version("1.0"); | 1987 ext_specifics->set_version("1.0"); |
| 1897 ext_specifics->set_installed_by_custodian( | 1988 ext_specifics->set_installed_by_custodian( |
| 1898 extensions[i]->was_installed_by_custodian()); | 1989 extensions::util::WasInstalledByCustodian(id, profile())); |
| 1990 | |
| 1899 syncer::SyncData sync_data = | 1991 syncer::SyncData sync_data = |
| 1900 syncer::SyncData::CreateLocalData(id, "Name", specifics); | 1992 syncer::SyncData::CreateLocalData(id, "Name", specifics); |
| 1901 list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_DELETE, sync_data)); | 1993 list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_DELETE, sync_data)); |
| 1902 } | 1994 } |
| 1903 | 1995 |
| 1904 // Save the extension ids, as uninstalling destroys the Extension instance. | 1996 // Save the extension ids, as uninstalling destroys the Extension instance. |
| 1905 std::string extension_ids[] = { | 1997 std::string extension_ids[] = { |
| 1906 extensions[0]->id(), | 1998 extensions[0]->id(), |
| 1907 extensions[1]->id() | 1999 extensions[1]->id() |
| 1908 }; | 2000 }; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2054 break; | 2146 break; |
| 2055 } | 2147 } |
| 2056 } | 2148 } |
| 2057 } | 2149 } |
| 2058 EXPECT_TRUE(found_delete); | 2150 EXPECT_TRUE(found_delete); |
| 2059 | 2151 |
| 2060 // Make sure there is one extension, and there are no more apps. | 2152 // Make sure there is one extension, and there are no more apps. |
| 2061 EXPECT_EQ(1u, extensions_processor.data().size()); | 2153 EXPECT_EQ(1u, extensions_processor.data().size()); |
| 2062 EXPECT_TRUE(apps_processor.data().empty()); | 2154 EXPECT_TRUE(apps_processor.data().empty()); |
| 2063 } | 2155 } |
| OLD | NEW |