Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 10908088: Cleanup: Constify some ProfileKeyedBaseFactory methods and all overrides. Remove ProfileKeyedBaseFa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase, remove a few more lines of code Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
42 #include "chrome/browser/extensions/external_provider_impl.h" 42 #include "chrome/browser/extensions/external_provider_impl.h"
43 #include "chrome/browser/extensions/external_provider_interface.h" 43 #include "chrome/browser/extensions/external_provider_interface.h"
44 #include "chrome/browser/extensions/installed_loader.h" 44 #include "chrome/browser/extensions/installed_loader.h"
45 #include "chrome/browser/extensions/pack_extension_job.h" 45 #include "chrome/browser/extensions/pack_extension_job.h"
46 #include "chrome/browser/extensions/pending_extension_info.h" 46 #include "chrome/browser/extensions/pending_extension_info.h"
47 #include "chrome/browser/extensions/pending_extension_manager.h" 47 #include "chrome/browser/extensions/pending_extension_manager.h"
48 #include "chrome/browser/extensions/test_extension_system.h" 48 #include "chrome/browser/extensions/test_extension_system.h"
49 #include "chrome/browser/extensions/test_management_policy.h" 49 #include "chrome/browser/extensions/test_management_policy.h"
50 #include "chrome/browser/extensions/unpacked_installer.h" 50 #include "chrome/browser/extensions/unpacked_installer.h"
51 #include "chrome/browser/extensions/updater/extension_updater.h" 51 #include "chrome/browser/extensions/updater/extension_updater.h"
52 #include "chrome/browser/plugin_prefs_factory.h"
53 #include "chrome/browser/prefs/browser_prefs.h" 52 #include "chrome/browser/prefs/browser_prefs.h"
54 #include "chrome/browser/prefs/pref_service_mock_builder.h" 53 #include "chrome/browser/prefs/pref_service_mock_builder.h"
55 #include "chrome/browser/prefs/scoped_user_pref_update.h" 54 #include "chrome/browser/prefs/scoped_user_pref_update.h"
56 #include "chrome/browser/themes/theme_service_factory.h"
57 #include "chrome/common/chrome_constants.h" 55 #include "chrome/common/chrome_constants.h"
58 #include "chrome/common/chrome_notification_types.h" 56 #include "chrome/common/chrome_notification_types.h"
59 #include "chrome/common/chrome_paths.h" 57 #include "chrome/common/chrome_paths.h"
60 #include "chrome/common/chrome_switches.h" 58 #include "chrome/common/chrome_switches.h"
61 #include "chrome/common/extensions/extension.h" 59 #include "chrome/common/extensions/extension.h"
62 #include "chrome/common/extensions/extension_l10n_util.h" 60 #include "chrome/common/extensions/extension_l10n_util.h"
63 #include "chrome/common/extensions/extension_manifest_constants.h" 61 #include "chrome/common/extensions/extension_manifest_constants.h"
64 #include "chrome/common/extensions/extension_resource.h" 62 #include "chrome/common/extensions/extension_resource.h"
65 #include "chrome/common/extensions/permissions/permission_set.h" 63 #include "chrome/common/extensions/permissions/permission_set.h"
66 #include "chrome/common/extensions/url_pattern.h" 64 #include "chrome/common/extensions/url_pattern.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // VisitRegisteredExtension(), which must be a const method to inherit 236 // VisitRegisteredExtension(), which must be a const method to inherit
239 // from the class being mocked. 237 // from the class being mocked.
240 mutable int visit_count_; 238 mutable int visit_count_;
241 239
242 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); 240 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider);
243 }; 241 };
244 242
245 class MockProviderVisitor 243 class MockProviderVisitor
246 : public extensions::ExternalProviderInterface::VisitorInterface { 244 : public extensions::ExternalProviderInterface::VisitorInterface {
247 public: 245 public:
248
249 // The provider will return |fake_base_path| from 246 // The provider will return |fake_base_path| from
250 // GetBaseCrxFilePath(). User can test the behavior with 247 // GetBaseCrxFilePath(). User can test the behavior with
251 // and without an empty path using this parameter. 248 // and without an empty path using this parameter.
252 explicit MockProviderVisitor(FilePath fake_base_path) 249 explicit MockProviderVisitor(FilePath fake_base_path)
253 : ids_found_(0), 250 : ids_found_(0),
254 fake_base_path_(fake_base_path), 251 fake_base_path_(fake_base_path),
255 expected_creation_flags_(Extension::NO_FLAGS) { 252 expected_creation_flags_(Extension::NO_FLAGS) {
256 } 253 }
257 254
258 MockProviderVisitor(FilePath fake_base_path, int expected_creation_flags) 255 MockProviderVisitor(FilePath fake_base_path, int expected_creation_flags)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // Drop our reference to ExtensionService and TestingProfile, so that they 400 // Drop our reference to ExtensionService and TestingProfile, so that they
404 // can be destroyed while BrowserThreads and MessageLoop are still around 401 // can be destroyed while BrowserThreads and MessageLoop are still around
405 // (they are used in the destruction process). 402 // (they are used in the destruction process).
406 service_ = NULL; 403 service_ = NULL;
407 MessageLoop::current()->RunAllPending(); 404 MessageLoop::current()->RunAllPending();
408 profile_.reset(NULL); 405 profile_.reset(NULL);
409 MessageLoop::current()->RunAllPending(); 406 MessageLoop::current()->RunAllPending();
410 } 407 }
411 408
412 void ExtensionServiceTestBase::InitializeExtensionService( 409 void ExtensionServiceTestBase::InitializeExtensionService(
413 const FilePath& pref_file, const FilePath& extensions_install_dir, 410 const FilePath& profile_path,
411 const FilePath& pref_file,
412 const FilePath& extensions_install_dir,
414 bool autoupdate_enabled) { 413 bool autoupdate_enabled) {
415 TestingProfile* profile = new TestingProfile(); 414 TestingProfile::Builder profile_builder;
416 // Create a PrefService that only contains user defined preference values. 415 // Create a PrefService that only contains user defined preference values.
417 PrefService* prefs = 416 scoped_ptr<PrefService> prefs(
418 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create(); 417 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create());
419 Profile::RegisterUserPrefs(prefs); 418 Profile::RegisterUserPrefs(prefs.get());
420 chrome::RegisterUserPrefs(prefs); 419 chrome::RegisterUserPrefs(prefs.get());
421 profile->SetPrefService(prefs); 420 profile_builder.SetPrefService(prefs.Pass());
422 421 profile_builder.SetPath(profile_path);
423 #if defined(ENABLE_THEMES) 422 profile_ = profile_builder.Build();
424 ThemeServiceFactory::GetInstance()->ForceRegisterPrefsForTest(prefs);
425 #endif
426 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs);
427
428 profile_.reset(profile);
429 423
430 service_ = static_cast<extensions::TestExtensionSystem*>( 424 service_ = static_cast<extensions::TestExtensionSystem*>(
431 ExtensionSystem::Get(profile))->CreateExtensionService( 425 ExtensionSystem::Get(profile_.get()))->CreateExtensionService(
432 CommandLine::ForCurrentProcess(), 426 CommandLine::ForCurrentProcess(),
433 extensions_install_dir, 427 extensions_install_dir,
434 autoupdate_enabled); 428 autoupdate_enabled);
435 service_->set_extensions_enabled(true); 429 service_->set_extensions_enabled(true);
436 service_->set_show_extensions_prompts(false); 430 service_->set_show_extensions_prompts(false);
437 431
438 management_policy_ = static_cast<extensions::TestExtensionSystem*>( 432 management_policy_ = static_cast<extensions::TestExtensionSystem*>(
439 ExtensionSystem::Get(profile))->CreateManagementPolicy(); 433 ExtensionSystem::Get(profile_.get()))->CreateManagementPolicy();
440 434
441 // When we start up, we want to make sure there is no external provider, 435 // When we start up, we want to make sure there is no external provider,
442 // since the ExtensionService on Windows will use the Registry as a default 436 // since the ExtensionService on Windows will use the Registry as a default
443 // provider and if there is something already registered there then it will 437 // provider and if there is something already registered there then it will
444 // interfere with the tests. Those tests that need an external provider 438 // interfere with the tests. Those tests that need an external provider
445 // will register one specifically. 439 // will register one specifically.
446 service_->ClearProvidersForTesting(); 440 service_->ClearProvidersForTesting();
447 441
448 expected_extensions_count_ = 0; 442 expected_extensions_count_ = 0;
449 } 443 }
450 444
451 void ExtensionServiceTestBase::InitializeInstalledExtensionService( 445 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
452 const FilePath& prefs_file, const FilePath& source_install_dir) { 446 const FilePath& prefs_file, const FilePath& source_install_dir) {
453 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 447 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
454 FilePath path_ = temp_dir_.path(); 448 FilePath path = temp_dir_.path();
455 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 449 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
456 file_util::Delete(path_, true); 450 file_util::Delete(path, true);
457 file_util::CreateDirectory(path_); 451 file_util::CreateDirectory(path);
458 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); 452 FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences"));
459 file_util::CopyFile(prefs_file, temp_prefs); 453 file_util::CopyFile(prefs_file, temp_prefs);
460 454
461 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); 455 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions"));
462 file_util::Delete(extensions_install_dir_, true); 456 file_util::Delete(extensions_install_dir_, true);
463 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); 457 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true);
464 458
465 InitializeExtensionService(temp_prefs, extensions_install_dir_, false); 459 InitializeExtensionService(path, temp_prefs, extensions_install_dir_, false);
466 } 460 }
467 461
468 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { 462 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
469 InitializeExtensionServiceHelper(false); 463 InitializeExtensionServiceHelper(false);
470 } 464 }
471 465
472 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { 466 void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
473 static_cast<extensions::TestExtensionSystem*>( 467 static_cast<extensions::TestExtensionSystem*>(
474 ExtensionSystem::Get(profile_.get()))-> 468 ExtensionSystem::Get(profile_.get()))->
475 CreateExtensionProcessManager(); 469 CreateExtensionProcessManager();
476 } 470 }
477 471
478 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 472 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
479 InitializeExtensionServiceHelper(true); 473 InitializeExtensionServiceHelper(true);
480 service_->updater()->Start(); 474 service_->updater()->Start();
481 } 475 }
482 476
483 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( 477 void ExtensionServiceTestBase::InitializeExtensionServiceHelper(
484 bool autoupdate_enabled) { 478 bool autoupdate_enabled) {
485 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 479 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
486 FilePath path_ = temp_dir_.path(); 480 FilePath path = temp_dir_.path();
487 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 481 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
488 file_util::Delete(path_, true); 482 file_util::Delete(path, true);
489 file_util::CreateDirectory(path_); 483 file_util::CreateDirectory(path);
490 FilePath prefs_filename = path_ 484 FilePath prefs_filename = path.Append(FILE_PATH_LITERAL("TestPreferences"));
491 .Append(FILE_PATH_LITERAL("TestPreferences")); 485 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions"));
492 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions"));
493 file_util::Delete(extensions_install_dir_, true); 486 file_util::Delete(extensions_install_dir_, true);
494 file_util::CreateDirectory(extensions_install_dir_); 487 file_util::CreateDirectory(extensions_install_dir_);
495 488
496 InitializeExtensionService(prefs_filename, extensions_install_dir_, 489 InitializeExtensionService(path, prefs_filename, extensions_install_dir_,
497 autoupdate_enabled); 490 autoupdate_enabled);
498 } 491 }
499 492
500 void ExtensionServiceTestBase::InitializeRequestContext() { 493 void ExtensionServiceTestBase::InitializeRequestContext() {
501 ASSERT_TRUE(profile_.get()); 494 ASSERT_TRUE(profile_.get());
502 TestingProfile* profile = 495 TestingProfile* profile =
503 static_cast<TestingProfile*>(profile_.get()); 496 static_cast<TestingProfile*>(profile_.get());
504 profile->CreateRequestContext(); 497 profile->CreateRequestContext();
505 } 498 }
506 499
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 ASSERT_TRUE(file_util::PathExists(private_key_path)); 1023 ASSERT_TRUE(file_util::PathExists(private_key_path));
1031 } 1024 }
1032 1025
1033 // The tests are designed so that we never expect to see a packing error. 1026 // The tests are designed so that we never expect to see a packing error.
1034 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, 1027 void PackExtensionTestClient::OnPackFailure(const std::string& error_message,
1035 ExtensionCreator::ErrorType type) { 1028 ExtensionCreator::ErrorType type) {
1036 if (type == ExtensionCreator::kCRXExists) 1029 if (type == ExtensionCreator::kCRXExists)
1037 FAIL() << "Packing should not fail."; 1030 FAIL() << "Packing should not fail.";
1038 else 1031 else
1039 FAIL() << "Existing CRX should have been overwritten."; 1032 FAIL() << "Existing CRX should have been overwritten.";
1040
1041 } 1033 }
1042 1034
1043 // Test loading good extensions from the profile directory. 1035 // Test loading good extensions from the profile directory.
1044 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { 1036 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
1045 PluginService::GetInstance()->Init(); 1037 PluginService::GetInstance()->Init();
1046 1038
1047 // Initialize the test dir with a good Preferences/extensions. 1039 // Initialize the test dir with a good Preferences/extensions.
1048 FilePath source_install_dir = data_dir_ 1040 FilePath source_install_dir = data_dir_
1049 .AppendASCII("good") 1041 .AppendASCII("good")
1050 .AppendASCII("Extensions"); 1042 .AppendASCII("Extensions");
(...skipping 3567 matching lines...) Expand 10 before | Expand all | Expand 10 after
4618 service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), 4610 service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(),
4619 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), 4611 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub),
4620 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 4612 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
4621 4613
4622 service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); 4614 service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id());
4623 { 4615 {
4624 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); 4616 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS);
4625 ASSERT_EQ(list.size(), 3U); 4617 ASSERT_EQ(list.size(), 3U);
4626 4618
4627 extensions::AppSyncData data[kAppCount]; 4619 extensions::AppSyncData data[kAppCount];
4628 for (size_t i = 0; i < kAppCount; ++i) 4620 for (size_t i = 0; i < kAppCount; ++i) {
4629 {
4630 data[i] = extensions::AppSyncData(list[i]); 4621 data[i] = extensions::AppSyncData(list[i]);
4631 } 4622 }
4632 4623
4633 // The sync data is not always in the same order our apps were installed in, 4624 // The sync data is not always in the same order our apps were installed in,
4634 // so we do that sorting here so we can make sure the values are changed as 4625 // so we do that sorting here so we can make sure the values are changed as
4635 // expected. 4626 // expected.
4636 StringOrdinal app_launch_ordinals[kAppCount]; 4627 StringOrdinal app_launch_ordinals[kAppCount];
4637 for (size_t i = 0; i < kAppCount; ++i) { 4628 for (size_t i = 0; i < kAppCount; ++i) {
4638 for (size_t j = 0; j < kAppCount; ++j) { 4629 for (size_t j = 0; j < kAppCount; ++j) {
4639 if (apps[i]->id() == data[j].id()) 4630 if (apps[i]->id() == data[j].id())
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
5425 // This should NOT trigger an alert. 5416 // This should NOT trigger an alert.
5426 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5417 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5427 data_dir_.AppendASCII("hosted_app.crx")); 5418 data_dir_.AppendASCII("hosted_app.crx"));
5428 5419
5429 service_->CheckForExternalUpdates(); 5420 service_->CheckForExternalUpdates();
5430 loop_.RunAllPending(); 5421 loop_.RunAllPending();
5431 5422
5432 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5423 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get()));
5433 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); 5424 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size());
5434 } 5425 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/extensions/extension_system_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698