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

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

Issue 77773002: Ensure the ExtensionSystem is ready before initializing an ExtensionAppModelBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: System -> Service Created 7 years, 1 month 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) 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 "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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 471 }
472 data_dir_ = test_data_dir.AppendASCII("extensions"); 472 data_dir_ = test_data_dir.AppendASCII("extensions");
473 } 473 }
474 474
475 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 475 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
476 service_ = NULL; 476 service_ = NULL;
477 } 477 }
478 478
479 void ExtensionServiceTestBase::InitializeExtensionService( 479 void ExtensionServiceTestBase::InitializeExtensionService(
480 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { 480 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
481 profile_ = CreateTestingProfile(params);
482 service_ = InitializeExtensionServiceForProfile(params, profile_.get());
483 management_policy_ =
484 ExtensionSystem::Get(profile_.get())->management_policy();
485 extensions_install_dir_ = params.extensions_install_dir;
486 expected_extensions_count_ = 0;
487 }
488
489 // static
490 scoped_ptr<TestingProfile> ExtensionServiceTestBase::CreateTestingProfile(
491 const ExtensionServiceInitParams& params) {
481 TestingProfile::Builder profile_builder; 492 TestingProfile::Builder profile_builder;
482 // Create a PrefService that only contains user defined preference values. 493 // Create a PrefService that only contains user defined preference values.
483 PrefServiceMockFactory factory; 494 PrefServiceMockFactory factory;
484 // If pref_file is empty, TestingProfile automatically creates 495 // If pref_file is empty, TestingProfile automatically creates
485 // TestingPrefServiceSyncable instance. 496 // TestingPrefServiceSyncable instance.
486 if (!params.pref_file.empty()) { 497 if (!params.pref_file.empty()) {
487 factory.SetUserPrefsFile(params.pref_file, 498 factory.SetUserPrefsFile(params.pref_file,
488 base::MessageLoopProxy::current().get()); 499 base::MessageLoopProxy::current().get());
489 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 500 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
490 new user_prefs::PrefRegistrySyncable); 501 new user_prefs::PrefRegistrySyncable);
491 scoped_ptr<PrefServiceSyncable> prefs( 502 scoped_ptr<PrefServiceSyncable> prefs(
492 factory.CreateSyncable(registry.get())); 503 factory.CreateSyncable(registry.get()));
493 chrome::RegisterUserProfilePrefs(registry.get()); 504 chrome::RegisterUserProfilePrefs(registry.get());
494 profile_builder.SetPrefService(prefs.Pass()); 505 profile_builder.SetPrefService(prefs.Pass());
495 } 506 }
496 507
497 if (params.profile_is_managed) 508 if (params.profile_is_managed)
498 profile_builder.SetManagedUserId("asdf"); 509 profile_builder.SetManagedUserId("asdf");
499 510
500 profile_builder.SetPath(params.profile_path); 511 profile_builder.SetPath(params.profile_path);
501 profile_ = profile_builder.Build(); 512 return profile_builder.Build();
513 }
502 514
515 // static
516 ExtensionService*
517 ExtensionServiceTestBase::InitializeExtensionServiceForProfile(
518 const ExtensionServiceInitParams& params,
519 Profile* profile) {
503 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( 520 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
504 ExtensionSystem::Get(profile_.get())); 521 ExtensionSystem::Get(profile));
505 if (!params.is_first_run) { 522 if (!params.is_first_run) {
506 ExtensionPrefs* prefs = system->CreateExtensionPrefs( 523 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
507 CommandLine::ForCurrentProcess(), 524 CommandLine::ForCurrentProcess(),
508 params.extensions_install_dir); 525 params.extensions_install_dir);
509 prefs->SetAlertSystemFirstRun(); 526 prefs->SetAlertSystemFirstRun();
510 } 527 }
511 528
512 service_ = system->CreateExtensionService( 529 ExtensionService* service = system->CreateExtensionService(
513 CommandLine::ForCurrentProcess(), 530 CommandLine::ForCurrentProcess(),
514 params.extensions_install_dir, 531 params.extensions_install_dir,
515 params.autoupdate_enabled); 532 params.autoupdate_enabled);
516 533
517 service_->SetFileTaskRunnerForTesting( 534 service->SetFileTaskRunnerForTesting(
518 base::MessageLoopProxy::current().get()); 535 base::MessageLoopProxy::current().get());
519 service_->set_extensions_enabled(true); 536 service->set_extensions_enabled(true);
520 service_->set_show_extensions_prompts(false); 537 service->set_show_extensions_prompts(false);
521 service_->set_install_updates_when_idle_for_test(false); 538 service->set_install_updates_when_idle_for_test(false);
522
523 management_policy_ =
524 ExtensionSystem::Get(profile_.get())->management_policy();
525
526 extensions_install_dir_ = params.extensions_install_dir;
527 539
528 // When we start up, we want to make sure there is no external provider, 540 // When we start up, we want to make sure there is no external provider,
529 // since the ExtensionService on Windows will use the Registry as a default 541 // since the ExtensionService on Windows will use the Registry as a default
530 // provider and if there is something already registered there then it will 542 // provider and if there is something already registered there then it will
531 // interfere with the tests. Those tests that need an external provider 543 // interfere with the tests. Those tests that need an external provider
532 // will register one specifically. 544 // will register one specifically.
533 service_->ClearProvidersForTesting(); 545 service->ClearProvidersForTesting();
534 546
535 #if defined(OS_CHROMEOS) 547 #if defined(OS_CHROMEOS)
536 extensions::InstallLimiter::Get(profile_.get())->DisableForTest(); 548 extensions::InstallLimiter::Get(profile)->DisableForTest();
537 #endif 549 #endif
538 550 return service;
539 expected_extensions_count_ = 0;
540 } 551 }
541 552
542 void ExtensionServiceTestBase::InitializeInstalledExtensionService( 553 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
543 const base::FilePath& prefs_file, 554 const base::FilePath& prefs_file,
544 const base::FilePath& source_install_dir) { 555 const base::FilePath& source_install_dir) {
545 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 556 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
546 base::FilePath path = temp_dir_.path(); 557 base::FilePath path = temp_dir_.path();
547 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 558 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
548 EXPECT_TRUE(base::DeleteFile(path, true)); 559 EXPECT_TRUE(base::DeleteFile(path, true));
549 base::PlatformFileError error = base::PLATFORM_FILE_OK; 560 base::PlatformFileError error = base::PLATFORM_FILE_OK;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 ExtensionErrorReporter::GetInstance()->ClearErrors(); 616 ExtensionErrorReporter::GetInstance()->ClearErrors();
606 content::RenderProcessHost::SetRunRendererInProcess(true); 617 content::RenderProcessHost::SetRunRendererInProcess(true);
607 } 618 }
608 619
609 void ExtensionServiceTestBase::TearDown() { 620 void ExtensionServiceTestBase::TearDown() {
610 content::RenderProcessHost::SetRunRendererInProcess(false); 621 content::RenderProcessHost::SetRunRendererInProcess(false);
611 } 622 }
612 623
613 ExtensionServiceTestBase::ExtensionServiceInitParams 624 ExtensionServiceTestBase::ExtensionServiceInitParams
614 ExtensionServiceTestBase::CreateDefaultInitParams() { 625 ExtensionServiceTestBase::CreateDefaultInitParams() {
626 return CreateDefaultInitParamsInTempDir(&temp_dir_);
627 }
628
629 // static
630 ExtensionServiceTestBase::ExtensionServiceInitParams
631 ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir(
632 base::ScopedTempDir* temp_dir) {
615 ExtensionServiceInitParams params; 633 ExtensionServiceInitParams params;
616 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 634 EXPECT_TRUE(temp_dir->CreateUniqueTempDir());
617 base::FilePath path = temp_dir_.path(); 635 base::FilePath path = temp_dir->path();
618 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 636 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
619 EXPECT_TRUE(base::DeleteFile(path, true)); 637 EXPECT_TRUE(base::DeleteFile(path, true));
620 base::PlatformFileError error = base::PLATFORM_FILE_OK; 638 base::PlatformFileError error = base::PLATFORM_FILE_OK;
621 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; 639 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error;
622 base::FilePath prefs_filename = 640 base::FilePath prefs_filename =
623 path.Append(FILE_PATH_LITERAL("TestPreferences")); 641 path.Append(FILE_PATH_LITERAL("TestPreferences"));
624 base::FilePath extensions_install_dir = 642 base::FilePath extensions_install_dir =
625 path.Append(FILE_PATH_LITERAL("Extensions")); 643 path.Append(FILE_PATH_LITERAL("Extensions"));
626 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); 644 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true));
627 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir, 645 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir,
(...skipping 6111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6739 service_->ReconcileKnownDisabled(); 6757 service_->ReconcileKnownDisabled();
6740 expected_extensions.insert(good2); 6758 expected_extensions.insert(good2);
6741 expected_disabled_extensions.erase(good2); 6759 expected_disabled_extensions.erase(good2);
6742 6760
6743 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); 6761 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs());
6744 EXPECT_EQ(expected_disabled_extensions, 6762 EXPECT_EQ(expected_disabled_extensions,
6745 service_->disabled_extensions()->GetIDs()); 6763 service_->disabled_extensions()->GetIDs());
6746 } 6764 }
6747 6765
6748 #endif // #if !(defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)) 6766 #endif // #if !(defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS))
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/ui/app_list/app_list_controller_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698