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

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: fix tests 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 InitializeExtensionServiceForProfile(params, &profile_, &service_);
482 management_policy_ =
483 ExtensionSystem::Get(profile_.get())->management_policy();
484 extensions_install_dir_ = params.extensions_install_dir;
485 expected_extensions_count_ = 0;
486 }
487
488 // static
489 void ExtensionServiceTestBase::InitializeExtensionServiceForProfile(
490 const ExtensionServiceInitParams& params,
491 scoped_ptr<TestingProfile>* profile_ptr,
stevenjb 2013/11/20 19:41:15 This is pretty confusing. Use of scoped_ptr<>& and
benwells 2013/11/21 00:47:47 Yep, seems like you could encapsulate the bits you
tapted 2013/11/21 03:29:56 Done.
492 ExtensionService** service_ptr) {
481 TestingProfile::Builder profile_builder; 493 TestingProfile::Builder profile_builder;
482 // Create a PrefService that only contains user defined preference values. 494 // Create a PrefService that only contains user defined preference values.
483 PrefServiceMockFactory factory; 495 PrefServiceMockFactory factory;
484 // If pref_file is empty, TestingProfile automatically creates 496 // If pref_file is empty, TestingProfile automatically creates
485 // TestingPrefServiceSyncable instance. 497 // TestingPrefServiceSyncable instance.
486 if (!params.pref_file.empty()) { 498 if (!params.pref_file.empty()) {
487 factory.SetUserPrefsFile(params.pref_file, 499 factory.SetUserPrefsFile(params.pref_file,
488 base::MessageLoopProxy::current().get()); 500 base::MessageLoopProxy::current().get());
489 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 501 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
490 new user_prefs::PrefRegistrySyncable); 502 new user_prefs::PrefRegistrySyncable);
491 scoped_ptr<PrefServiceSyncable> prefs( 503 scoped_ptr<PrefServiceSyncable> prefs(
492 factory.CreateSyncable(registry.get())); 504 factory.CreateSyncable(registry.get()));
493 chrome::RegisterUserProfilePrefs(registry.get()); 505 chrome::RegisterUserProfilePrefs(registry.get());
494 profile_builder.SetPrefService(prefs.Pass()); 506 profile_builder.SetPrefService(prefs.Pass());
495 } 507 }
496 508
497 if (params.profile_is_managed) 509 if (params.profile_is_managed)
498 profile_builder.SetManagedUserId("asdf"); 510 profile_builder.SetManagedUserId("asdf");
499 511
500 profile_builder.SetPath(params.profile_path); 512 profile_builder.SetPath(params.profile_path);
501 profile_ = profile_builder.Build(); 513 scoped_ptr<TestingProfile>& profile = *profile_ptr;
514 profile = profile_builder.Build();
502 515
503 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( 516 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
504 ExtensionSystem::Get(profile_.get())); 517 ExtensionSystem::Get(profile.get()));
505 if (!params.is_first_run) { 518 if (!params.is_first_run) {
506 ExtensionPrefs* prefs = system->CreateExtensionPrefs( 519 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
507 CommandLine::ForCurrentProcess(), 520 CommandLine::ForCurrentProcess(),
508 params.extensions_install_dir); 521 params.extensions_install_dir);
509 prefs->SetAlertSystemFirstRun(); 522 prefs->SetAlertSystemFirstRun();
510 } 523 }
511 524
512 service_ = system->CreateExtensionService( 525 ExtensionService*& service = *service_ptr;
526 service = system->CreateExtensionService(
benwells 2013/11/21 00:47:47 huh? Why so many *'s and &'s?? more importantly, w
tapted 2013/11/21 03:29:56 All fixed :) - at this stage I was still aiming on
513 CommandLine::ForCurrentProcess(), 527 CommandLine::ForCurrentProcess(),
514 params.extensions_install_dir, 528 params.extensions_install_dir,
515 params.autoupdate_enabled); 529 params.autoupdate_enabled);
516 530
517 service_->SetFileTaskRunnerForTesting( 531 service->SetFileTaskRunnerForTesting(
518 base::MessageLoopProxy::current().get()); 532 base::MessageLoopProxy::current().get());
519 service_->set_extensions_enabled(true); 533 service->set_extensions_enabled(true);
520 service_->set_show_extensions_prompts(false); 534 service->set_show_extensions_prompts(false);
521 service_->set_install_updates_when_idle_for_test(false); 535 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 536
528 // When we start up, we want to make sure there is no external provider, 537 // 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 538 // 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 539 // provider and if there is something already registered there then it will
531 // interfere with the tests. Those tests that need an external provider 540 // interfere with the tests. Those tests that need an external provider
532 // will register one specifically. 541 // will register one specifically.
533 service_->ClearProvidersForTesting(); 542 service->ClearProvidersForTesting();
534 543
535 #if defined(OS_CHROMEOS) 544 #if defined(OS_CHROMEOS)
536 extensions::InstallLimiter::Get(profile_.get())->DisableForTest(); 545 extensions::InstallLimiter::Get(profile.get())->DisableForTest();
537 #endif 546 #endif
538
539 expected_extensions_count_ = 0;
540 } 547 }
541 548
542 void ExtensionServiceTestBase::InitializeInstalledExtensionService( 549 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
543 const base::FilePath& prefs_file, 550 const base::FilePath& prefs_file,
544 const base::FilePath& source_install_dir) { 551 const base::FilePath& source_install_dir) {
545 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 552 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
546 base::FilePath path = temp_dir_.path(); 553 base::FilePath path = temp_dir_.path();
547 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 554 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
548 EXPECT_TRUE(base::DeleteFile(path, true)); 555 EXPECT_TRUE(base::DeleteFile(path, true));
549 base::PlatformFileError error = base::PLATFORM_FILE_OK; 556 base::PlatformFileError error = base::PLATFORM_FILE_OK;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 ExtensionErrorReporter::GetInstance()->ClearErrors(); 612 ExtensionErrorReporter::GetInstance()->ClearErrors();
606 content::RenderProcessHost::SetRunRendererInProcess(true); 613 content::RenderProcessHost::SetRunRendererInProcess(true);
607 } 614 }
608 615
609 void ExtensionServiceTestBase::TearDown() { 616 void ExtensionServiceTestBase::TearDown() {
610 content::RenderProcessHost::SetRunRendererInProcess(false); 617 content::RenderProcessHost::SetRunRendererInProcess(false);
611 } 618 }
612 619
613 ExtensionServiceTestBase::ExtensionServiceInitParams 620 ExtensionServiceTestBase::ExtensionServiceInitParams
614 ExtensionServiceTestBase::CreateDefaultInitParams() { 621 ExtensionServiceTestBase::CreateDefaultInitParams() {
622 return CreateDefaultInitParamsInTempDir(&temp_dir_);
623 }
624
625 // static
626 ExtensionServiceTestBase::ExtensionServiceInitParams
627 ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir(
628 base::ScopedTempDir* temp_dir_) {
615 ExtensionServiceInitParams params; 629 ExtensionServiceInitParams params;
616 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 630 EXPECT_TRUE(temp_dir_->CreateUniqueTempDir());
617 base::FilePath path = temp_dir_.path(); 631 base::FilePath path = temp_dir_->path();
618 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 632 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
619 EXPECT_TRUE(base::DeleteFile(path, true)); 633 EXPECT_TRUE(base::DeleteFile(path, true));
620 base::PlatformFileError error = base::PLATFORM_FILE_OK; 634 base::PlatformFileError error = base::PLATFORM_FILE_OK;
621 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; 635 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error;
622 base::FilePath prefs_filename = 636 base::FilePath prefs_filename =
623 path.Append(FILE_PATH_LITERAL("TestPreferences")); 637 path.Append(FILE_PATH_LITERAL("TestPreferences"));
624 base::FilePath extensions_install_dir = 638 base::FilePath extensions_install_dir =
625 path.Append(FILE_PATH_LITERAL("Extensions")); 639 path.Append(FILE_PATH_LITERAL("Extensions"));
626 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); 640 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true));
627 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir, 641 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir,
(...skipping 6111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6739 service_->ReconcileKnownDisabled(); 6753 service_->ReconcileKnownDisabled();
6740 expected_extensions.insert(good2); 6754 expected_extensions.insert(good2);
6741 expected_disabled_extensions.erase(good2); 6755 expected_disabled_extensions.erase(good2);
6742 6756
6743 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); 6757 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs());
6744 EXPECT_EQ(expected_disabled_extensions, 6758 EXPECT_EQ(expected_disabled_extensions,
6745 service_->disabled_extensions()->GetIDs()); 6759 service_->disabled_extensions()->GetIDs());
6746 } 6760 }
6747 6761
6748 #endif // #if !(defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)) 6762 #endif // #if !(defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698