OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chrome/browser/extensions/pack_extension_job.cc" | 42 #include "chrome/browser/extensions/pack_extension_job.cc" |
43 #include "chrome/browser/extensions/pending_extension_info.h" | 43 #include "chrome/browser/extensions/pending_extension_info.h" |
44 #include "chrome/browser/extensions/pending_extension_manager.h" | 44 #include "chrome/browser/extensions/pending_extension_manager.h" |
45 #include "chrome/browser/extensions/unpacked_installer.h" | 45 #include "chrome/browser/extensions/unpacked_installer.h" |
46 #include "chrome/browser/plugin_prefs_factory.h" | 46 #include "chrome/browser/plugin_prefs_factory.h" |
47 #include "chrome/browser/prefs/browser_prefs.h" | 47 #include "chrome/browser/prefs/browser_prefs.h" |
48 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 48 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
49 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 49 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
50 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 50 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
51 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 51 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 52 #include "chrome/browser/sync/protocol/sync.pb.h" |
52 #include "chrome/common/chrome_notification_types.h" | 53 #include "chrome/common/chrome_notification_types.h" |
53 #include "chrome/common/chrome_paths.h" | 54 #include "chrome/common/chrome_paths.h" |
54 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
55 #include "chrome/common/extensions/extension.h" | 56 #include "chrome/common/extensions/extension.h" |
56 #include "chrome/common/extensions/extension_constants.h" | 57 #include "chrome/common/extensions/extension_constants.h" |
57 #include "chrome/common/extensions/extension_resource.h" | 58 #include "chrome/common/extensions/extension_resource.h" |
58 #include "chrome/common/extensions/url_pattern.h" | 59 #include "chrome/common/extensions/url_pattern.h" |
59 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
60 #include "chrome/common/string_ordinal.h" | 61 #include "chrome/common/string_ordinal.h" |
61 #include "chrome/common/url_constants.h" | 62 #include "chrome/common/url_constants.h" |
(...skipping 4096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4158 EXPECT_EQ(2u, service_->GetAllSyncData(syncable::EXTENSIONS).size()); | 4159 EXPECT_EQ(2u, service_->GetAllSyncData(syncable::EXTENSIONS).size()); |
4159 } | 4160 } |
4160 | 4161 |
4161 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { | 4162 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { |
4162 InitializeEmptyExtensionService(); | 4163 InitializeEmptyExtensionService(); |
4163 TestSyncProcessorStub processor; | 4164 TestSyncProcessorStub processor; |
4164 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4165 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
4165 &processor); | 4166 &processor); |
4166 | 4167 |
4167 sync_pb::EntitySpecifics specifics; | 4168 sync_pb::EntitySpecifics specifics; |
4168 sync_pb::ExtensionSpecifics* ext_specifics = | 4169 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
4169 specifics.MutableExtension(sync_pb::extension); | |
4170 ext_specifics->set_id(good_crx); | 4170 ext_specifics->set_id(good_crx); |
4171 ext_specifics->set_version("1.0"); | 4171 ext_specifics->set_version("1.0"); |
4172 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 4172 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); |
4173 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); | 4173 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); |
4174 SyncChangeList list(1); | 4174 SyncChangeList list(1); |
4175 list[0] = sync_change; | 4175 list[0] = sync_change; |
4176 | 4176 |
4177 // Should do nothing. | 4177 // Should do nothing. |
4178 service_->ProcessSyncChanges(FROM_HERE, list); | 4178 service_->ProcessSyncChanges(FROM_HERE, list); |
4179 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | 4179 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
(...skipping 14 matching lines...) Expand all Loading... |
4194 | 4194 |
4195 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { | 4195 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { |
4196 InitializeEmptyExtensionService(); | 4196 InitializeEmptyExtensionService(); |
4197 | 4197 |
4198 // Install the extension. | 4198 // Install the extension. |
4199 FilePath extension_path = data_dir_.AppendASCII("good.crx"); | 4199 FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
4200 InstallCRX(extension_path, INSTALL_NEW); | 4200 InstallCRX(extension_path, INSTALL_NEW); |
4201 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); | 4201 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
4202 | 4202 |
4203 sync_pb::EntitySpecifics specifics; | 4203 sync_pb::EntitySpecifics specifics; |
4204 sync_pb::AppSpecifics* app_specifics = | 4204 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
4205 specifics.MutableExtension(sync_pb::app); | |
4206 sync_pb::ExtensionSpecifics* extension_specifics = | 4205 sync_pb::ExtensionSpecifics* extension_specifics = |
4207 app_specifics->mutable_extension(); | 4206 app_specifics->mutable_extension(); |
4208 extension_specifics->set_id(good_crx); | 4207 extension_specifics->set_id(good_crx); |
4209 extension_specifics->set_version( | 4208 extension_specifics->set_version( |
4210 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 4209 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
4211 | 4210 |
4212 { | 4211 { |
4213 extension_specifics->set_enabled(true); | 4212 extension_specifics->set_enabled(true); |
4214 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 4213 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); |
4215 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); | 4214 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); |
(...skipping 23 matching lines...) Expand all Loading... |
4239 InitializeExtensionProcessManager(); | 4238 InitializeExtensionProcessManager(); |
4240 TestSyncProcessorStub processor; | 4239 TestSyncProcessorStub processor; |
4241 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4240 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
4242 &processor); | 4241 &processor); |
4243 | 4242 |
4244 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 4243 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
4245 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4244 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
4246 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4245 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
4247 | 4246 |
4248 sync_pb::EntitySpecifics specifics; | 4247 sync_pb::EntitySpecifics specifics; |
4249 sync_pb::ExtensionSpecifics* ext_specifics = | 4248 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
4250 specifics.MutableExtension(sync_pb::extension); | |
4251 ext_specifics->set_id(good_crx); | 4249 ext_specifics->set_id(good_crx); |
4252 ext_specifics->set_version( | 4250 ext_specifics->set_version( |
4253 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 4251 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
4254 ext_specifics->set_enabled(false); | 4252 ext_specifics->set_enabled(false); |
4255 | 4253 |
4256 { | 4254 { |
4257 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 4255 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); |
4258 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 4256 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); |
4259 SyncChangeList list(1); | 4257 SyncChangeList list(1); |
4260 list[0] = sync_change; | 4258 list[0] = sync_change; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4295 TestSyncProcessorStub processor; | 4293 TestSyncProcessorStub processor; |
4296 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4294 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
4297 &processor); | 4295 &processor); |
4298 | 4296 |
4299 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 4297 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
4300 TerminateExtension(good_crx); | 4298 TerminateExtension(good_crx); |
4301 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4299 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
4302 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4300 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
4303 | 4301 |
4304 sync_pb::EntitySpecifics specifics; | 4302 sync_pb::EntitySpecifics specifics; |
4305 sync_pb::ExtensionSpecifics* ext_specifics = | 4303 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
4306 specifics.MutableExtension(sync_pb::extension); | |
4307 ext_specifics->set_id(good_crx); | 4304 ext_specifics->set_id(good_crx); |
4308 ext_specifics->set_version( | 4305 ext_specifics->set_version( |
4309 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 4306 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
4310 ext_specifics->set_enabled(false); | 4307 ext_specifics->set_enabled(false); |
4311 ext_specifics->set_incognito_enabled(true); | 4308 ext_specifics->set_incognito_enabled(true); |
4312 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 4309 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); |
4313 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 4310 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); |
4314 SyncChangeList list(1); | 4311 SyncChangeList list(1); |
4315 list[0] = sync_change; | 4312 list[0] = sync_change; |
4316 | 4313 |
4317 service_->ProcessSyncChanges(FROM_HERE, list); | 4314 service_->ProcessSyncChanges(FROM_HERE, list); |
4318 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 4315 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
4319 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 4316 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
4320 | 4317 |
4321 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 4318 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
4322 } | 4319 } |
4323 | 4320 |
4324 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { | 4321 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
4325 InitializeExtensionServiceWithUpdater(); | 4322 InitializeExtensionServiceWithUpdater(); |
4326 InitializeRequestContext(); | 4323 InitializeRequestContext(); |
4327 TestSyncProcessorStub processor; | 4324 TestSyncProcessorStub processor; |
4328 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4325 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
4329 &processor); | 4326 &processor); |
4330 | 4327 |
4331 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 4328 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
4332 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4329 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
4333 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4330 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
4334 | 4331 |
4335 sync_pb::EntitySpecifics specifics; | 4332 sync_pb::EntitySpecifics specifics; |
4336 sync_pb::ExtensionSpecifics* ext_specifics = | 4333 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
4337 specifics.MutableExtension(sync_pb::extension); | |
4338 ext_specifics->set_id(good_crx); | 4334 ext_specifics->set_id(good_crx); |
4339 ext_specifics->set_enabled(true); | 4335 ext_specifics->set_enabled(true); |
4340 | 4336 |
4341 { | 4337 { |
4342 ext_specifics->set_version( | 4338 ext_specifics->set_version( |
4343 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 4339 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
4344 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 4340 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); |
4345 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 4341 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); |
4346 SyncChangeList list(1); | 4342 SyncChangeList list(1); |
4347 list[0] = sync_change; | 4343 list[0] = sync_change; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4380 } | 4376 } |
4381 | 4377 |
4382 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { | 4378 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
4383 InitializeExtensionServiceWithUpdater(); | 4379 InitializeExtensionServiceWithUpdater(); |
4384 InitializeRequestContext(); | 4380 InitializeRequestContext(); |
4385 TestSyncProcessorStub processor; | 4381 TestSyncProcessorStub processor; |
4386 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4382 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
4387 &processor); | 4383 &processor); |
4388 | 4384 |
4389 sync_pb::EntitySpecifics specifics; | 4385 sync_pb::EntitySpecifics specifics; |
4390 sync_pb::ExtensionSpecifics* ext_specifics = | 4386 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
4391 specifics.MutableExtension(sync_pb::extension); | |
4392 ext_specifics->set_id(good_crx); | 4387 ext_specifics->set_id(good_crx); |
4393 ext_specifics->set_enabled(false); | 4388 ext_specifics->set_enabled(false); |
4394 ext_specifics->set_incognito_enabled(true); | 4389 ext_specifics->set_incognito_enabled(true); |
4395 ext_specifics->set_update_url("http://www.google.com/"); | 4390 ext_specifics->set_update_url("http://www.google.com/"); |
4396 ext_specifics->set_version("1.2.3.4"); | 4391 ext_specifics->set_version("1.2.3.4"); |
4397 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 4392 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); |
4398 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 4393 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); |
4399 SyncChangeList list(1); | 4394 SyncChangeList list(1); |
4400 list[0] = sync_change; | 4395 list[0] = sync_change; |
4401 | 4396 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4784 ASSERT_FALSE(AddPendingSyncInstall()); | 4779 ASSERT_FALSE(AddPendingSyncInstall()); |
4785 | 4780 |
4786 // Wait for the external source to install. | 4781 // Wait for the external source to install. |
4787 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 4782 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
4788 ASSERT_TRUE(IsCrxInstalled()); | 4783 ASSERT_TRUE(IsCrxInstalled()); |
4789 | 4784 |
4790 // Now that the extension is installed, sync request should fail | 4785 // Now that the extension is installed, sync request should fail |
4791 // because the extension is already installed. | 4786 // because the extension is already installed. |
4792 ASSERT_FALSE(AddPendingSyncInstall()); | 4787 ASSERT_FALSE(AddPendingSyncInstall()); |
4793 } | 4788 } |
OLD | NEW |