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 "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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 int expected_creation_flags_; | 442 int expected_creation_flags_; |
443 scoped_ptr<extensions::ExternalProviderImpl> provider_; | 443 scoped_ptr<extensions::ExternalProviderImpl> provider_; |
444 scoped_ptr<DictionaryValue> prefs_; | 444 scoped_ptr<DictionaryValue> prefs_; |
445 scoped_ptr<TestingProfile> profile_; | 445 scoped_ptr<TestingProfile> profile_; |
446 | 446 |
447 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 447 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
448 }; | 448 }; |
449 | 449 |
450 ExtensionServiceTestBase::ExtensionServiceInitParams:: | 450 ExtensionServiceTestBase::ExtensionServiceInitParams:: |
451 ExtensionServiceInitParams() | 451 ExtensionServiceInitParams() |
452 : autoupdate_enabled(false), is_first_run(true) { | 452 : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) { |
453 } | 453 } |
454 | 454 |
455 // Our message loop may be used in tests which require it to be an IO loop. | 455 // Our message loop may be used in tests which require it to be an IO loop. |
456 ExtensionServiceTestBase::ExtensionServiceTestBase() | 456 ExtensionServiceTestBase::ExtensionServiceTestBase() |
457 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 457 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
458 service_(NULL), | 458 service_(NULL), |
459 management_policy_(NULL), | 459 management_policy_(NULL), |
460 expected_extensions_count_(0) { | 460 expected_extensions_count_(0) { |
461 base::FilePath test_data_dir; | 461 base::FilePath test_data_dir; |
462 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 462 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
(...skipping 17 matching lines...) Expand all Loading... |
480 if (!params.pref_file.empty()) { | 480 if (!params.pref_file.empty()) { |
481 builder.WithUserFilePrefs(params.pref_file, | 481 builder.WithUserFilePrefs(params.pref_file, |
482 base::MessageLoopProxy::current().get()); | 482 base::MessageLoopProxy::current().get()); |
483 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | 483 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
484 new user_prefs::PrefRegistrySyncable); | 484 new user_prefs::PrefRegistrySyncable); |
485 scoped_ptr<PrefServiceSyncable> prefs( | 485 scoped_ptr<PrefServiceSyncable> prefs( |
486 builder.CreateSyncable(registry.get())); | 486 builder.CreateSyncable(registry.get())); |
487 chrome::RegisterUserProfilePrefs(registry.get()); | 487 chrome::RegisterUserProfilePrefs(registry.get()); |
488 profile_builder.SetPrefService(prefs.Pass()); | 488 profile_builder.SetPrefService(prefs.Pass()); |
489 } | 489 } |
| 490 |
| 491 if (params.profile_is_managed) |
| 492 profile_builder.SetManagedUserId("asdf"); |
| 493 |
490 profile_builder.SetPath(params.profile_path); | 494 profile_builder.SetPath(params.profile_path); |
491 profile_ = profile_builder.Build(); | 495 profile_ = profile_builder.Build(); |
492 | 496 |
493 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( | 497 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( |
494 ExtensionSystem::Get(profile_.get())); | 498 ExtensionSystem::Get(profile_.get())); |
495 if (!params.is_first_run) { | 499 if (!params.is_first_run) { |
496 ExtensionPrefs* prefs = system->CreateExtensionPrefs( | 500 ExtensionPrefs* prefs = system->CreateExtensionPrefs( |
497 CommandLine::ForCurrentProcess(), | 501 CommandLine::ForCurrentProcess(), |
498 params.extensions_install_dir); | 502 params.extensions_install_dir); |
499 prefs->SetAlertSystemFirstRun(); | 503 prefs->SetAlertSystemFirstRun(); |
500 } | 504 } |
501 | 505 |
502 service_ = system->CreateExtensionService( | 506 service_ = system->CreateExtensionService( |
503 CommandLine::ForCurrentProcess(), | 507 CommandLine::ForCurrentProcess(), |
504 params.extensions_install_dir, | 508 params.extensions_install_dir, |
505 params.autoupdate_enabled); | 509 params.autoupdate_enabled); |
506 service_->SetFileTaskRunnerForTesting( | 510 service_->SetFileTaskRunnerForTesting( |
507 base::MessageLoopProxy::current().get()); | 511 base::MessageLoopProxy::current().get()); |
508 service_->set_extensions_enabled(true); | 512 service_->set_extensions_enabled(true); |
509 service_->set_show_extensions_prompts(false); | 513 service_->set_show_extensions_prompts(false); |
510 service_->set_install_updates_when_idle_for_test(false); | 514 service_->set_install_updates_when_idle_for_test(false); |
511 | 515 |
512 management_policy_ = | 516 management_policy_ = |
513 ExtensionSystem::Get(profile_.get())->management_policy(); | 517 ExtensionSystem::Get(profile_.get())->management_policy(); |
514 | 518 |
| 519 extensions_install_dir_ = params.extensions_install_dir; |
| 520 |
515 // When we start up, we want to make sure there is no external provider, | 521 // When we start up, we want to make sure there is no external provider, |
516 // since the ExtensionService on Windows will use the Registry as a default | 522 // since the ExtensionService on Windows will use the Registry as a default |
517 // provider and if there is something already registered there then it will | 523 // provider and if there is something already registered there then it will |
518 // interfere with the tests. Those tests that need an external provider | 524 // interfere with the tests. Those tests that need an external provider |
519 // will register one specifically. | 525 // will register one specifically. |
520 service_->ClearProvidersForTesting(); | 526 service_->ClearProvidersForTesting(); |
521 | 527 |
522 #if defined(OS_CHROMEOS) | 528 #if defined(OS_CHROMEOS) |
523 extensions::InstallLimiter::Get(profile_.get())->DisableForTest(); | 529 extensions::InstallLimiter::Get(profile_.get())->DisableForTest(); |
524 #endif | 530 #endif |
525 | 531 |
526 expected_extensions_count_ = 0; | 532 expected_extensions_count_ = 0; |
527 } | 533 } |
528 | 534 |
529 void ExtensionServiceTestBase::InitializeInstalledExtensionService( | 535 void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
530 const base::FilePath& prefs_file, | 536 const base::FilePath& prefs_file, |
531 const base::FilePath& source_install_dir) { | 537 const base::FilePath& source_install_dir) { |
532 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 538 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
533 base::FilePath path = temp_dir_.path(); | 539 base::FilePath path = temp_dir_.path(); |
534 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 540 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
535 base::DeleteFile(path, true); | 541 EXPECT_TRUE(base::DeleteFile(path, true)); |
536 file_util::CreateDirectory(path); | 542 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 543 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; |
537 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); | 544 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); |
538 base::CopyFile(prefs_file, temp_prefs); | 545 EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs)); |
539 | 546 |
540 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); | 547 base::FilePath extensions_install_dir = |
541 base::DeleteFile(extensions_install_dir_, true); | 548 path.Append(FILE_PATH_LITERAL("Extensions")); |
542 base::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 549 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); |
| 550 EXPECT_TRUE( |
| 551 base::CopyDirectory(source_install_dir, extensions_install_dir, true)); |
543 | 552 |
544 ExtensionServiceInitParams params; | 553 ExtensionServiceInitParams params; |
545 params.profile_path = path; | 554 params.profile_path = path; |
546 params.pref_file = temp_prefs; | 555 params.pref_file = temp_prefs; |
547 params.extensions_install_dir = extensions_install_dir_; | 556 params.extensions_install_dir = extensions_install_dir; |
548 InitializeExtensionService(params); | 557 InitializeExtensionService(params); |
549 } | 558 } |
550 | 559 |
551 void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() { | 560 void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() { |
552 base::FilePath source_install_dir = data_dir_ | 561 base::FilePath source_install_dir = data_dir_ |
553 .AppendASCII("good") | 562 .AppendASCII("good") |
554 .AppendASCII("Extensions"); | 563 .AppendASCII("Extensions"); |
555 base::FilePath pref_path = source_install_dir | 564 base::FilePath pref_path = source_install_dir |
556 .DirName() | 565 .DirName() |
557 .AppendASCII("Preferences"); | 566 .AppendASCII("Preferences"); |
558 InitializeInstalledExtensionService(pref_path, source_install_dir); | 567 InitializeInstalledExtensionService(pref_path, source_install_dir); |
559 } | 568 } |
560 | 569 |
561 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { | 570 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
562 InitializeExtensionServiceHelper(false, true); | 571 InitializeExtensionService(CreateDefaultInitParams()); |
563 } | 572 } |
564 | 573 |
565 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { | 574 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
566 static_cast<extensions::TestExtensionSystem*>( | 575 static_cast<extensions::TestExtensionSystem*>( |
567 ExtensionSystem::Get(profile_.get()))-> | 576 ExtensionSystem::Get(profile_.get()))-> |
568 CreateExtensionProcessManager(); | 577 CreateExtensionProcessManager(); |
569 } | 578 } |
570 | 579 |
571 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { | 580 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
572 InitializeExtensionServiceHelper(true, true); | 581 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 582 params.autoupdate_enabled = true; |
| 583 InitializeExtensionService(params); |
573 service_->updater()->Start(); | 584 service_->updater()->Start(); |
574 } | 585 } |
575 | 586 |
576 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( | 587 ExtensionServiceTestBase::ExtensionServiceInitParams |
577 bool autoupdate_enabled, bool is_first_run) { | 588 ExtensionServiceTestBase::CreateDefaultInitParams() { |
578 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 589 ExtensionServiceInitParams params; |
| 590 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
579 base::FilePath path = temp_dir_.path(); | 591 base::FilePath path = temp_dir_.path(); |
580 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 592 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
581 base::DeleteFile(path, true); | 593 EXPECT_TRUE(base::DeleteFile(path, true)); |
582 file_util::CreateDirectory(path); | 594 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 595 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; |
583 base::FilePath prefs_filename = | 596 base::FilePath prefs_filename = |
584 path.Append(FILE_PATH_LITERAL("TestPreferences")); | 597 path.Append(FILE_PATH_LITERAL("TestPreferences")); |
585 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); | 598 base::FilePath extensions_install_dir = |
586 base::DeleteFile(extensions_install_dir_, true); | 599 path.Append(FILE_PATH_LITERAL("Extensions")); |
587 file_util::CreateDirectory(extensions_install_dir_); | 600 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); |
| 601 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir, |
| 602 &error)) << error; |
588 | 603 |
589 ExtensionServiceInitParams params; | |
590 params.profile_path = path; | 604 params.profile_path = path; |
591 params.pref_file = prefs_filename; | 605 params.pref_file = prefs_filename; |
592 params.extensions_install_dir = extensions_install_dir_; | 606 params.extensions_install_dir = extensions_install_dir; |
593 params.autoupdate_enabled = autoupdate_enabled; | 607 return params; |
594 params.is_first_run = is_first_run; | |
595 InitializeExtensionService(params); | |
596 } | 608 } |
597 | 609 |
598 // static | 610 // static |
599 void ExtensionServiceTestBase::SetUpTestCase() { | 611 void ExtensionServiceTestBase::SetUpTestCase() { |
600 ExtensionErrorReporter::Init(false); // no noisy errors | 612 ExtensionErrorReporter::Init(false); // no noisy errors |
601 } | 613 } |
602 | 614 |
603 void ExtensionServiceTestBase::SetUp() { | 615 void ExtensionServiceTestBase::SetUp() { |
604 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 616 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
605 content::RenderProcessHost::SetRunRendererInProcess(true); | 617 content::RenderProcessHost::SetRunRendererInProcess(true); |
(...skipping 5862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6468 } | 6480 } |
6469 | 6481 |
6470 // Test that there is a bubble for external extensions that update | 6482 // Test that there is a bubble for external extensions that update |
6471 // from the webstore if the profile is not new. | 6483 // from the webstore if the profile is not new. |
6472 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { | 6484 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { |
6473 FeatureSwitch::ScopedOverride prompt( | 6485 FeatureSwitch::ScopedOverride prompt( |
6474 FeatureSwitch::prompt_for_external_extensions(), true); | 6486 FeatureSwitch::prompt_for_external_extensions(), true); |
6475 | 6487 |
6476 // This sets up the ExtensionPrefs used by our ExtensionService to be | 6488 // This sets up the ExtensionPrefs used by our ExtensionService to be |
6477 // post-first run. | 6489 // post-first run. |
6478 InitializeExtensionServiceHelper(false, false); | 6490 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6491 params.is_first_run = false; |
| 6492 InitializeExtensionService(params); |
6479 | 6493 |
6480 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); | 6494 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); |
6481 PackCRX(data_dir_.AppendASCII("update_from_webstore"), | 6495 PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
6482 data_dir_.AppendASCII("update_from_webstore.pem"), | 6496 data_dir_.AppendASCII("update_from_webstore.pem"), |
6483 crx_path); | 6497 crx_path); |
6484 | 6498 |
6485 MockExtensionProvider* provider = | 6499 MockExtensionProvider* provider = |
6486 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 6500 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
6487 AddMockExternalProvider(provider); | 6501 AddMockExternalProvider(provider); |
6488 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6502 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6616 // ReconcileKnownDisabled(). | 6630 // ReconcileKnownDisabled(). |
6617 service_->EnableExtension(good2); | 6631 service_->EnableExtension(good2); |
6618 service_->ReconcileKnownDisabled(); | 6632 service_->ReconcileKnownDisabled(); |
6619 expected_extensions.insert(good2); | 6633 expected_extensions.insert(good2); |
6620 expected_disabled_extensions.erase(good2); | 6634 expected_disabled_extensions.erase(good2); |
6621 | 6635 |
6622 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); | 6636 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
6623 EXPECT_EQ(expected_disabled_extensions, | 6637 EXPECT_EQ(expected_disabled_extensions, |
6624 service_->disabled_extensions()->GetIDs()); | 6638 service_->disabled_extensions()->GetIDs()); |
6625 } | 6639 } |
OLD | NEW |