Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 7175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7186 // The extension should still be there and enabled. | 7186 // The extension should still be there and enabled. |
| 7187 extension = registry()->enabled_extensions().GetByID(id); | 7187 extension = registry()->enabled_extensions().GetByID(id); |
| 7188 ASSERT_TRUE(extension); | 7188 ASSERT_TRUE(extension); |
| 7189 // The version should have changed. | 7189 // The version should have changed. |
| 7190 EXPECT_NE(extension->VersionString(), old_version); | 7190 EXPECT_NE(extension->VersionString(), old_version); |
| 7191 } | 7191 } |
| 7192 | 7192 |
| 7193 // Helper class that allows us to parameterize the UpdateWithPermissionIncrease | 7193 // Helper class that allows us to parameterize the UpdateWithPermissionIncrease |
| 7194 // test over |bool need_custodian_approval|. | 7194 // test over |bool need_custodian_approval|. |
| 7195 class ExtensionServiceTestSupervisedUserPermissionIncrease : | 7195 class ExtensionServiceTestSupervisedUserPermissionIncrease : |
| 7196 public ExtensionServiceTest, public testing::WithParamInterface<bool> {}; | 7196 public ExtensionServiceTest, public testing::WithParamInterface<bool> {}; |
|
Devlin
2015/10/16 02:40:24
Parameterized tests?!?!? What is this black magic
Marc Treib
2015/10/16 09:22:20
In this case, it's arguably more trouble than it's
| |
| 7197 | 7197 |
| 7198 TEST_P(ExtensionServiceTestSupervisedUserPermissionIncrease, | 7198 TEST_P(ExtensionServiceTestSupervisedUserPermissionIncrease, |
| 7199 UpdateWithPermissionIncrease) { | 7199 UpdateWithPermissionIncrease) { |
| 7200 // This is the update URL specified in the test extension. Setting it here is | |
| 7201 // necessary to make the extension considered syncable. | |
| 7202 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 7203 switches::kAppsGalleryUpdateURL, | |
| 7204 "http://localhost/autoupdate/updates.xml"); | |
| 7205 | |
| 7200 bool need_custodian_approval = GetParam(); | 7206 bool need_custodian_approval = GetParam(); |
| 7201 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 7207 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 7202 base::FieldTrialList::CreateFieldTrial( | 7208 base::FieldTrialList::CreateFieldTrial( |
| 7203 "SupervisedUserExtensionPermissionIncrease", | 7209 "SupervisedUserExtensionPermissionIncrease", |
| 7204 need_custodian_approval ? "NeedCustodianApproval" : ""); | 7210 need_custodian_approval ? "NeedCustodianApproval" : ""); |
| 7205 | 7211 |
| 7206 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 7212 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 7207 params.profile_is_supervised = true; | 7213 params.profile_is_supervised = true; |
| 7208 InitializeExtensionService(params); | 7214 InitializeExtensionService(params); |
| 7209 | 7215 |
| 7210 SupervisedUserService* supervised_user_service = | 7216 SupervisedUserService* supervised_user_service = |
| 7211 SupervisedUserServiceFactory::GetForProfile(profile()); | 7217 SupervisedUserServiceFactory::GetForProfile(profile()); |
| 7212 ScopedSupervisedUserServiceDelegate delegate(supervised_user_service); | 7218 ScopedSupervisedUserServiceDelegate delegate(supervised_user_service); |
| 7213 supervised_user_service->Init(); | 7219 supervised_user_service->Init(); |
| 7214 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 7220 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 7215 supervised_user_service->AddPermissionRequestCreator( | 7221 supervised_user_service->AddPermissionRequestCreator( |
| 7216 make_scoped_ptr(creator)); | 7222 make_scoped_ptr(creator)); |
| 7217 | 7223 |
| 7224 const std::string version1("1"); | |
| 7225 const std::string version2("2"); | |
| 7226 const std::string version3("3"); | |
| 7227 | |
| 7218 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); | 7228 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); |
| 7219 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); | 7229 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); |
| 7220 | 7230 |
| 7221 base::FilePath path = base_path.AppendASCII("v1"); | 7231 base::FilePath path = base_path.AppendASCII("v1"); |
| 7222 const Extension* extension = | 7232 const Extension* extension = |
| 7223 PackAndInstallCRX(path, pem_path, INSTALL_NEW, | 7233 PackAndInstallCRX(path, pem_path, INSTALL_NEW, |
| 7224 Extension::WAS_INSTALLED_BY_CUSTODIAN); | 7234 Extension::WAS_INSTALLED_BY_CUSTODIAN); |
| 7225 // The extension must now be installed and enabled. | 7235 // The extension must now be installed and enabled. |
| 7226 ASSERT_TRUE(extension); | 7236 ASSERT_TRUE(extension); |
| 7227 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | 7237 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 7238 ASSERT_EQ(version1, extension->VersionString()); | |
| 7228 | 7239 |
| 7229 // Save the id, as the extension object will be destroyed during updating. | 7240 // Save the id, as the extension object will be destroyed during updating. |
| 7230 std::string id = extension->id(); | 7241 std::string id = extension->id(); |
| 7231 | 7242 |
| 7232 std::string old_version = extension->VersionString(); | |
| 7233 | |
| 7234 // Update to a new version with increased permissions. | 7243 // Update to a new version with increased permissions. |
| 7235 EXPECT_CALL(*creator, | 7244 EXPECT_CALL(*creator, |
| 7236 CreateExtensionUpdateRequest(id + ":2", testing::_)) | 7245 CreateExtensionUpdateRequest(id + ":" + version2, testing::_)) |
| 7237 .Times(need_custodian_approval ? 1 : 0); | 7246 .Times(need_custodian_approval ? 1 : 0); |
| 7238 path = base_path.AppendASCII("v2"); | 7247 path = base_path.AppendASCII("v2"); |
| 7239 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); | 7248 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); |
| 7240 | 7249 |
| 7241 // The extension should still be there, but disabled. | 7250 // The extension should still be there, but disabled. |
| 7242 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 7251 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 7243 extension = registry()->disabled_extensions().GetByID(id); | 7252 extension = registry()->disabled_extensions().GetByID(id); |
| 7244 ASSERT_TRUE(extension); | 7253 ASSERT_TRUE(extension); |
| 7245 // The version should have changed. | 7254 // The version should have changed. |
| 7246 EXPECT_NE(extension->VersionString(), old_version); | 7255 EXPECT_EQ(version2, extension->VersionString()); |
| 7256 | |
| 7257 if (!need_custodian_approval) | |
|
Devlin
2015/10/16 02:40:24
What has this succeeded in testing in this case?
Marc Treib
2015/10/16 09:22:20
The extension was updated but disabled, and (in pa
| |
| 7258 return; | |
| 7259 | |
| 7260 // Now, simulate custodian approvals for re-enabling the extension coming in | |
| 7261 // through Sync. | |
| 7262 | |
| 7263 // Create a sync update to re-enable the extension, but set the old version. | |
| 7264 // This can happen when there already was a pending request for an earlier | |
| 7265 // version of the extension. | |
| 7266 sync_pb::EntitySpecifics specifics; | |
| 7267 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | |
| 7268 ext_specifics->set_id(id); | |
| 7269 ext_specifics->set_enabled(true); | |
| 7270 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | |
| 7271 ext_specifics->set_installed_by_custodian(true); | |
| 7272 ext_specifics->set_version(version1); | |
| 7273 { | |
| 7274 // Attempting to re-enable an old version should result in a permission | |
| 7275 // request for the current version. | |
| 7276 EXPECT_CALL(*creator, | |
| 7277 CreateExtensionUpdateRequest(id + ":" + version2, testing::_)); | |
| 7278 | |
| 7279 syncer::SyncData sync_data = | |
| 7280 syncer::SyncData::CreateLocalData(id, "Name", specifics); | |
| 7281 syncer::SyncChange sync_change(FROM_HERE, | |
| 7282 syncer::SyncChange::ACTION_UPDATE, | |
| 7283 sync_data); | |
| 7284 syncer::SyncChangeList change_list(1, sync_change); | |
| 7285 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); | |
| 7286 // The re-enable should be ignored, since the version doesn't match. | |
| 7287 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
| 7288 } | |
| 7289 | |
| 7290 // Again, but now set a newer version than what is installed. | |
| 7291 ext_specifics->set_version(version3); | |
| 7292 { | |
| 7293 // This should *not* result in a new permission request. | |
| 7294 EXPECT_CALL(*creator, | |
| 7295 CreateExtensionUpdateRequest(id + ":" + version3, testing::_)) | |
| 7296 .Times(0); | |
| 7297 | |
| 7298 syncer::SyncData sync_data = | |
| 7299 syncer::SyncData::CreateLocalData(id, "Name", specifics); | |
| 7300 syncer::SyncChange sync_change(FROM_HERE, | |
| 7301 syncer::SyncChange::ACTION_UPDATE, | |
| 7302 sync_data); | |
| 7303 syncer::SyncChangeList change_list(1, sync_change); | |
| 7304 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); | |
| 7305 // The re-enable should be delayed until the extension is updated to the | |
|
Devlin
2015/10/16 02:40:24
Do we have a test for it being enabled when the ve
Marc Treib
2015/10/16 09:22:20
Good point, we don't :D
I'll add one and ping you
| |
| 7306 // matching version. | |
| 7307 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | |
| 7308 } | |
| 7309 | |
| 7310 // Update to the matching version. Now the extension should get enabled. | |
| 7311 path = base_path.AppendASCII("v3"); | |
|
Devlin
2015/10/16 02:40:24
nit: inline path (everywhere)
Marc Treib
2015/10/16 09:22:20
Done.
| |
| 7312 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); | |
| 7247 } | 7313 } |
| 7248 INSTANTIATE_TEST_CASE_P(NeedCustodianApproval, | 7314 INSTANTIATE_TEST_CASE_P(NeedCustodianApproval, |
| 7249 ExtensionServiceTestSupervisedUserPermissionIncrease, | 7315 ExtensionServiceTestSupervisedUserPermissionIncrease, |
| 7250 testing::Bool()); | 7316 testing::Bool()); |
| 7251 | 7317 |
| 7252 TEST_F(ExtensionServiceTest, | 7318 TEST_F(ExtensionServiceTest, |
| 7253 SupervisedUserSyncUninstallByCustodianSkipsPolicy) { | 7319 SupervisedUserSyncUninstallByCustodianSkipsPolicy) { |
| 7254 InitializeEmptyExtensionService(); | 7320 InitializeEmptyExtensionService(); |
| 7255 extension_sync_service()->MergeDataAndStartSyncing( | 7321 extension_sync_service()->MergeDataAndStartSyncing( |
| 7256 syncer::EXTENSIONS, | 7322 syncer::EXTENSIONS, |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8224 | 8290 |
| 8225 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 8291 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 8226 content::Source<Profile>(profile()), | 8292 content::Source<Profile>(profile()), |
| 8227 content::NotificationService::NoDetails()); | 8293 content::NotificationService::NoDetails()); |
| 8228 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 8294 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 8229 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 8295 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 8230 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 8296 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 8231 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 8297 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 8232 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 8298 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 8233 } | 8299 } |
| OLD | NEW |