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 7039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7050 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); | 7050 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); |
7051 | 7051 |
7052 // The extension should still be there and enabled. | 7052 // The extension should still be there and enabled. |
7053 extension = registry()->enabled_extensions().GetByID(id); | 7053 extension = registry()->enabled_extensions().GetByID(id); |
7054 ASSERT_TRUE(extension); | 7054 ASSERT_TRUE(extension); |
7055 // The version should have changed. | 7055 // The version should have changed. |
7056 EXPECT_NE(extension->VersionString(), old_version); | 7056 EXPECT_NE(extension->VersionString(), old_version); |
7057 } | 7057 } |
7058 | 7058 |
7059 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { | 7059 TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
| 7060 // This is the update URL specified in the test extension. Setting it here is |
| 7061 // necessary to make the extension considered syncable. |
| 7062 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 7063 switches::kAppsGalleryUpdateURL, |
| 7064 "http://localhost/autoupdate/updates.xml"); |
| 7065 |
7060 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 7066 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
7061 params.profile_is_supervised = true; | 7067 params.profile_is_supervised = true; |
7062 InitializeExtensionService(params); | 7068 InitializeExtensionService(params); |
| 7069 InitializeExtensionSyncService(); |
| 7070 extension_sync_service()->MergeDataAndStartSyncing( |
| 7071 syncer::EXTENSIONS, |
| 7072 syncer::SyncDataList(), |
| 7073 scoped_ptr<syncer::SyncChangeProcessor>( |
| 7074 new syncer::FakeSyncChangeProcessor), |
| 7075 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
7063 | 7076 |
7064 SupervisedUserService* supervised_user_service = | 7077 SupervisedUserService* supervised_user_service = |
7065 SupervisedUserServiceFactory::GetForProfile(profile()); | 7078 SupervisedUserServiceFactory::GetForProfile(profile()); |
7066 ScopedSupervisedUserServiceDelegate delegate(supervised_user_service); | 7079 ScopedSupervisedUserServiceDelegate delegate(supervised_user_service); |
7067 supervised_user_service->Init(); | 7080 supervised_user_service->Init(); |
7068 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 7081 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
7069 supervised_user_service->AddPermissionRequestCreator( | 7082 supervised_user_service->AddPermissionRequestCreator( |
7070 make_scoped_ptr(creator)); | 7083 make_scoped_ptr(creator)); |
7071 | 7084 |
| 7085 const std::string version1("1"); |
| 7086 const std::string version2("2"); |
| 7087 const std::string version3("3"); |
| 7088 |
7072 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); | 7089 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); |
7073 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); | 7090 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); |
7074 | 7091 |
7075 base::FilePath path = base_path.AppendASCII("v1"); | 7092 base::FilePath path = base_path.AppendASCII("v1"); |
7076 const Extension* extension = | 7093 const Extension* extension = |
7077 PackAndInstallCRX(path, pem_path, INSTALL_NEW, | 7094 PackAndInstallCRX(path, pem_path, INSTALL_NEW, |
7078 Extension::WAS_INSTALLED_BY_CUSTODIAN); | 7095 Extension::WAS_INSTALLED_BY_CUSTODIAN); |
7079 // The extension must now be installed and enabled. | 7096 // The extension must now be installed and enabled. |
7080 ASSERT_TRUE(extension); | 7097 ASSERT_TRUE(extension); |
7081 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | 7098 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 7099 ASSERT_EQ(version1, extension->VersionString()); |
7082 | 7100 |
7083 // Save the id, as the extension object will be destroyed during updating. | 7101 // Save the id, as the extension object will be destroyed during updating. |
7084 std::string id = extension->id(); | 7102 std::string id = extension->id(); |
7085 | 7103 |
7086 std::string old_version = extension->VersionString(); | |
7087 | |
7088 // Update to a new version with increased permissions. | 7104 // Update to a new version with increased permissions. |
7089 EXPECT_CALL(*creator, | 7105 EXPECT_CALL(*creator, |
7090 CreateExtensionUpdateRequest(id + ":2", testing::_)); | 7106 CreateExtensionUpdateRequest(id + ":" + version2, testing::_)); |
7091 path = base_path.AppendASCII("v2"); | 7107 path = base_path.AppendASCII("v2"); |
7092 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); | 7108 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); |
7093 | 7109 |
7094 // The extension should still be there, but disabled. | 7110 // The extension should still be there, but disabled. |
7095 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 7111 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
7096 extension = registry()->disabled_extensions().GetByID(id); | 7112 extension = registry()->disabled_extensions().GetByID(id); |
7097 ASSERT_TRUE(extension); | 7113 ASSERT_TRUE(extension); |
7098 // The version should have changed. | 7114 // The version should have changed. |
7099 EXPECT_NE(extension->VersionString(), old_version); | 7115 EXPECT_EQ(version2, extension->VersionString()); |
| 7116 |
| 7117 // Create a sync update to re-enable the extension, but set the old version. |
| 7118 sync_pb::EntitySpecifics specifics; |
| 7119 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
| 7120 ext_specifics->set_id(id); |
| 7121 ext_specifics->set_enabled(true); |
| 7122 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
| 7123 ext_specifics->set_installed_by_custodian(true); |
| 7124 ext_specifics->set_version(version1); |
| 7125 { |
| 7126 // Attempting to re-enable an old version should result in a permission |
| 7127 // request for the current version. |
| 7128 EXPECT_CALL(*creator, |
| 7129 CreateExtensionUpdateRequest(id + ":" + version2, testing::_)); |
| 7130 |
| 7131 syncer::SyncData sync_data = |
| 7132 syncer::SyncData::CreateLocalData(id, "Name", specifics); |
| 7133 syncer::SyncChange sync_change(FROM_HERE, |
| 7134 syncer::SyncChange::ACTION_UPDATE, |
| 7135 sync_data); |
| 7136 syncer::SyncChangeList change_list(1, sync_change); |
| 7137 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); |
| 7138 // The re-enable should be ignored, since the version doesn't match. |
| 7139 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 7140 } |
| 7141 |
| 7142 // Again, but now set a newer version than what is installed. |
| 7143 ext_specifics->set_version(version3); |
| 7144 { |
| 7145 syncer::SyncData sync_data = |
| 7146 syncer::SyncData::CreateLocalData(id, "Name", specifics); |
| 7147 syncer::SyncChange sync_change(FROM_HERE, |
| 7148 syncer::SyncChange::ACTION_UPDATE, |
| 7149 sync_data); |
| 7150 syncer::SyncChangeList change_list(1, sync_change); |
| 7151 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); |
| 7152 // The re-enable should be delayed until the extension is updated to the |
| 7153 // matching version. |
| 7154 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 7155 } |
| 7156 |
| 7157 // Update to the matching version. Now the extension should get enabled. |
| 7158 path = base_path.AppendASCII("v3"); |
| 7159 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); |
7100 } | 7160 } |
7101 | 7161 |
7102 TEST_F(ExtensionServiceTest, | 7162 TEST_F(ExtensionServiceTest, |
7103 SupervisedUser_SyncUninstallByCustodianSkipsPolicy) { | 7163 SupervisedUser_SyncUninstallByCustodianSkipsPolicy) { |
7104 InitializeEmptyExtensionService(); | 7164 InitializeEmptyExtensionService(); |
7105 InitializeExtensionSyncService(); | 7165 InitializeExtensionSyncService(); |
7106 extension_sync_service()->MergeDataAndStartSyncing( | 7166 extension_sync_service()->MergeDataAndStartSyncing( |
7107 syncer::EXTENSIONS, | 7167 syncer::EXTENSIONS, |
7108 syncer::SyncDataList(), | 7168 syncer::SyncDataList(), |
7109 scoped_ptr<syncer::SyncChangeProcessor>( | 7169 scoped_ptr<syncer::SyncChangeProcessor>( |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8072 | 8132 |
8073 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 8133 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
8074 content::Source<Profile>(profile()), | 8134 content::Source<Profile>(profile()), |
8075 content::NotificationService::NoDetails()); | 8135 content::NotificationService::NoDetails()); |
8076 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 8136 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
8077 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 8137 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
8078 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 8138 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
8079 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 8139 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
8080 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 8140 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
8081 } | 8141 } |
OLD | NEW |