Index: chrome/browser/extensions/extension_service_unittest.cc |
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc |
index e213e77a7bdbc879db003ed88484bcdba16f257d..2928d036fbb66f1d2bc01eca1d5c4d872f1e976f 100644 |
--- a/chrome/browser/extensions/extension_service_unittest.cc |
+++ b/chrome/browser/extensions/extension_service_unittest.cc |
@@ -7057,9 +7057,22 @@ TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) { |
} |
TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
+ // This is the update URL specified in the test extension. Setting it here is |
+ // necessary to make the extension considered syncable. |
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
+ switches::kAppsGalleryUpdateURL, |
+ "http://localhost/autoupdate/updates.xml"); |
+ |
ExtensionServiceInitParams params = CreateDefaultInitParams(); |
params.profile_is_supervised = true; |
InitializeExtensionService(params); |
+ InitializeExtensionSyncService(); |
+ extension_sync_service()->MergeDataAndStartSyncing( |
+ syncer::EXTENSIONS, |
+ syncer::SyncDataList(), |
+ scoped_ptr<syncer::SyncChangeProcessor>( |
+ new syncer::FakeSyncChangeProcessor), |
+ scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
SupervisedUserService* supervised_user_service = |
SupervisedUserServiceFactory::GetForProfile(profile()); |
@@ -7069,6 +7082,10 @@ TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
supervised_user_service->AddPermissionRequestCreator( |
make_scoped_ptr(creator)); |
+ const std::string version1("1"); |
+ const std::string version2("2"); |
+ const std::string version3("3"); |
+ |
base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); |
base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); |
@@ -7079,15 +7096,14 @@ TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
// The extension must now be installed and enabled. |
ASSERT_TRUE(extension); |
ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
+ ASSERT_EQ(version1, extension->VersionString()); |
// Save the id, as the extension object will be destroyed during updating. |
std::string id = extension->id(); |
- std::string old_version = extension->VersionString(); |
- |
// Update to a new version with increased permissions. |
EXPECT_CALL(*creator, |
- CreateExtensionUpdateRequest(id + ":2", testing::_)); |
+ CreateExtensionUpdateRequest(id + ":" + version2, testing::_)); |
path = base_path.AppendASCII("v2"); |
PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); |
@@ -7096,7 +7112,51 @@ TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
extension = registry()->disabled_extensions().GetByID(id); |
ASSERT_TRUE(extension); |
// The version should have changed. |
- EXPECT_NE(extension->VersionString(), old_version); |
+ EXPECT_EQ(version2, extension->VersionString()); |
+ |
+ // Create a sync update to re-enable the extension, but set the old version. |
+ sync_pb::EntitySpecifics specifics; |
+ sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
+ ext_specifics->set_id(id); |
+ ext_specifics->set_enabled(true); |
+ ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
+ ext_specifics->set_installed_by_custodian(true); |
+ ext_specifics->set_version(version1); |
+ { |
+ // Attempting to re-enable an old version should result in a permission |
+ // request for the current version. |
+ EXPECT_CALL(*creator, |
+ CreateExtensionUpdateRequest(id + ":" + version2, testing::_)); |
+ |
+ syncer::SyncData sync_data = |
+ syncer::SyncData::CreateLocalData(id, "Name", specifics); |
+ syncer::SyncChange sync_change(FROM_HERE, |
+ syncer::SyncChange::ACTION_UPDATE, |
+ sync_data); |
+ syncer::SyncChangeList change_list(1, sync_change); |
+ extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); |
+ // The re-enable should be ignored, since the version doesn't match. |
+ EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
+ } |
+ |
+ // Again, but now set a newer version than what is installed. |
+ ext_specifics->set_version(version3); |
+ { |
+ syncer::SyncData sync_data = |
+ syncer::SyncData::CreateLocalData(id, "Name", specifics); |
+ syncer::SyncChange sync_change(FROM_HERE, |
+ syncer::SyncChange::ACTION_UPDATE, |
+ sync_data); |
+ syncer::SyncChangeList change_list(1, sync_change); |
+ extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); |
+ // The re-enable should be delayed until the extension is updated to the |
+ // matching version. |
+ EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
+ } |
+ |
+ // Update to the matching version. Now the extension should get enabled. |
+ path = base_path.AppendASCII("v3"); |
+ PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); |
} |
TEST_F(ExtensionServiceTest, |