Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "chrome/browser/extensions/pending_extension_info.h" | 51 #include "chrome/browser/extensions/pending_extension_info.h" |
| 52 #include "chrome/browser/extensions/pending_extension_manager.h" | 52 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 53 #include "chrome/browser/extensions/test_extension_system.h" | 53 #include "chrome/browser/extensions/test_extension_system.h" |
| 54 #include "chrome/browser/extensions/test_management_policy.h" | 54 #include "chrome/browser/extensions/test_management_policy.h" |
| 55 #include "chrome/browser/extensions/unpacked_installer.h" | 55 #include "chrome/browser/extensions/unpacked_installer.h" |
| 56 #include "chrome/browser/extensions/updater/extension_updater.h" | 56 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 57 #include "chrome/browser/prefs/browser_prefs.h" | 57 #include "chrome/browser/prefs/browser_prefs.h" |
| 58 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 58 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 59 #include "chrome/browser/prefs/pref_service_syncable.h" | 59 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 60 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 60 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 61 #include "chrome/browser/profiles/profile_manager.h" | |
| 61 #include "chrome/common/chrome_constants.h" | 62 #include "chrome/common/chrome_constants.h" |
| 62 #include "chrome/common/chrome_notification_types.h" | 63 #include "chrome/common/chrome_notification_types.h" |
| 63 #include "chrome/common/chrome_paths.h" | 64 #include "chrome/common/chrome_paths.h" |
| 64 #include "chrome/common/chrome_switches.h" | 65 #include "chrome/common/chrome_switches.h" |
| 65 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 66 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
| 66 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 67 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
| 67 #include "chrome/common/extensions/background_info.h" | 68 #include "chrome/common/extensions/background_info.h" |
| 68 #include "chrome/common/extensions/extension.h" | 69 #include "chrome/common/extensions/extension.h" |
| 69 #include "chrome/common/extensions/extension_l10n_util.h" | 70 #include "chrome/common/extensions/extension_l10n_util.h" |
| 70 #include "chrome/common/extensions/extension_manifest_constants.h" | 71 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 72 #include "chrome/common/extensions/extension_messages.h" | |
| 71 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | 73 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
| 72 #include "chrome/common/extensions/manifest_handlers/requirements_handler.h" | 74 #include "chrome/common/extensions/manifest_handlers/requirements_handler.h" |
| 73 #include "chrome/common/extensions/manifest_url_handler.h" | 75 #include "chrome/common/extensions/manifest_url_handler.h" |
| 74 #include "chrome/common/extensions/permissions/permission_set.h" | 76 #include "chrome/common/extensions/permissions/permission_set.h" |
| 75 #include "chrome/common/pref_names.h" | 77 #include "chrome/common/pref_names.h" |
| 76 #include "chrome/common/url_constants.h" | 78 #include "chrome/common/url_constants.h" |
| 79 #include "chrome/test/base/testing_browser_process.h" | |
| 77 #include "chrome/test/base/testing_profile.h" | 80 #include "chrome/test/base/testing_profile.h" |
| 78 #include "components/user_prefs/pref_registry_syncable.h" | 81 #include "components/user_prefs/pref_registry_syncable.h" |
| 79 #include "content/public/browser/dom_storage_context.h" | 82 #include "content/public/browser/dom_storage_context.h" |
| 80 #include "content/public/browser/gpu_data_manager.h" | 83 #include "content/public/browser/gpu_data_manager.h" |
| 81 #include "content/public/browser/indexed_db_context.h" | 84 #include "content/public/browser/indexed_db_context.h" |
| 82 #include "content/public/browser/notification_registrar.h" | 85 #include "content/public/browser/notification_registrar.h" |
| 83 #include "content/public/browser/notification_service.h" | 86 #include "content/public/browser/notification_service.h" |
| 84 #include "content/public/browser/plugin_service.h" | 87 #include "content/public/browser/plugin_service.h" |
| 88 #include "content/public/browser/site_instance.h" | |
| 85 #include "content/public/browser/storage_partition.h" | 89 #include "content/public/browser/storage_partition.h" |
| 86 #include "content/public/common/content_constants.h" | 90 #include "content/public/common/content_constants.h" |
| 87 #include "content/public/common/gpu_info.h" | 91 #include "content/public/common/gpu_info.h" |
| 88 #include "content/public/test/test_browser_thread.h" | 92 #include "content/public/test/test_browser_thread.h" |
| 93 #include "content/public/test/test_notification_tracker.h" | |
| 89 #include "extensions/common/constants.h" | 94 #include "extensions/common/constants.h" |
| 90 #include "extensions/common/extension_resource.h" | 95 #include "extensions/common/extension_resource.h" |
| 91 #include "extensions/common/url_pattern.h" | 96 #include "extensions/common/url_pattern.h" |
| 92 #include "googleurl/src/gurl.h" | 97 #include "googleurl/src/gurl.h" |
| 93 #include "grit/browser_resources.h" | 98 #include "grit/browser_resources.h" |
| 94 #include "net/cookies/canonical_cookie.h" | 99 #include "net/cookies/canonical_cookie.h" |
| 95 #include "net/cookies/cookie_monster.h" | 100 #include "net/cookies/cookie_monster.h" |
| 96 #include "net/cookies/cookie_options.h" | 101 #include "net/cookies/cookie_options.h" |
| 97 #include "net/url_request/url_request_context.h" | 102 #include "net/url_request/url_request_context.h" |
| 98 #include "net/url_request/url_request_context_getter.h" | 103 #include "net/url_request/url_request_context_getter.h" |
| 99 #include "sync/api/string_ordinal.h" | 104 #include "sync/api/string_ordinal.h" |
| 100 #include "sync/api/sync_error_factory.h" | 105 #include "sync/api/sync_error_factory.h" |
| 101 #include "sync/api/sync_error_factory_mock.h" | 106 #include "sync/api/sync_error_factory_mock.h" |
| 102 #include "sync/protocol/app_specifics.pb.h" | 107 #include "sync/protocol/app_specifics.pb.h" |
| 103 #include "sync/protocol/extension_specifics.pb.h" | 108 #include "sync/protocol/extension_specifics.pb.h" |
| 104 #include "sync/protocol/sync.pb.h" | 109 #include "sync/protocol/sync.pb.h" |
| 110 #include "testing/gmock/include/gmock/gmock.h" | |
| 105 #include "testing/gtest/include/gtest/gtest.h" | 111 #include "testing/gtest/include/gtest/gtest.h" |
| 106 #include "testing/platform_test.h" | 112 #include "testing/platform_test.h" |
| 107 #include "webkit/database/database_tracker.h" | 113 #include "webkit/database/database_tracker.h" |
| 108 #include "webkit/database/database_util.h" | 114 #include "webkit/database/database_util.h" |
| 109 #include "webkit/plugins/npapi/mock_plugin_list.h" | 115 #include "webkit/plugins/npapi/mock_plugin_list.h" |
| 110 #include "webkit/quota/quota_manager.h" | 116 #include "webkit/quota/quota_manager.h" |
| 111 | 117 |
| 112 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
| 113 #include "chrome/browser/chromeos/extensions/install_limiter.h" | 119 #include "chrome/browser/chromeos/extensions/install_limiter.h" |
| 114 #endif | 120 #endif |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 base::FilePath fake_base_path_; | 409 base::FilePath fake_base_path_; |
| 404 int expected_creation_flags_; | 410 int expected_creation_flags_; |
| 405 scoped_ptr<extensions::ExternalProviderImpl> provider_; | 411 scoped_ptr<extensions::ExternalProviderImpl> provider_; |
| 406 scoped_ptr<DictionaryValue> prefs_; | 412 scoped_ptr<DictionaryValue> prefs_; |
| 407 | 413 |
| 408 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 414 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
| 409 }; | 415 }; |
| 410 | 416 |
| 411 // Our message loop may be used in tests which require it to be an IO loop. | 417 // Our message loop may be used in tests which require it to be an IO loop. |
| 412 ExtensionServiceTestBase::ExtensionServiceTestBase() | 418 ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 413 : loop_(MessageLoop::TYPE_IO), | 419 : loop_(MessageLoop::TYPE_UI), |
| 420 local_state_(TestingBrowserProcess::GetGlobal()), | |
| 414 service_(NULL), | 421 service_(NULL), |
| 415 management_policy_(NULL), | 422 management_policy_(NULL), |
| 416 expected_extensions_count_(0), | 423 expected_extensions_count_(0), |
| 417 ui_thread_(BrowserThread::UI, &loop_), | 424 ui_thread_(BrowserThread::UI, &loop_), |
| 418 db_thread_(BrowserThread::DB, &loop_), | 425 db_thread_(BrowserThread::DB, &loop_), |
| 419 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), | 426 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), |
| 420 file_thread_(BrowserThread::FILE, &loop_), | 427 file_thread_(BrowserThread::FILE, &loop_), |
| 421 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), | 428 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), |
| 422 io_thread_(BrowserThread::IO, &loop_), | 429 io_thread_(BrowserThread::IO), |
| 423 override_sideload_wipeout_( | 430 override_sideload_wipeout_( |
| 424 FeatureSwitch::sideload_wipeout(), false) { | 431 FeatureSwitch::sideload_wipeout(), false) { |
| 432 io_thread_.StartIOThread(); | |
| 425 base::FilePath test_data_dir; | 433 base::FilePath test_data_dir; |
| 426 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 434 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 427 ADD_FAILURE(); | 435 ADD_FAILURE(); |
| 428 return; | 436 return; |
| 429 } | 437 } |
| 430 data_dir_ = test_data_dir.AppendASCII("extensions"); | 438 data_dir_ = test_data_dir.AppendASCII("extensions"); |
| 431 } | 439 } |
| 432 | 440 |
| 433 ExtensionServiceTestBase::~ExtensionServiceTestBase() { | 441 ExtensionServiceTestBase::~ExtensionServiceTestBase() { |
| 434 // Drop our reference to ExtensionService and TestingProfile, so that they | 442 // Drop our reference to ExtensionService and TestingProfile, so that they |
| 435 // can be destroyed while BrowserThreads and MessageLoop are still around | 443 // can be destroyed while BrowserThreads and MessageLoop are still around |
| 436 // (they are used in the destruction process). | 444 // (they are used in the destruction process). |
| 437 service_ = NULL; | 445 service_ = NULL; |
| 438 MessageLoop::current()->RunUntilIdle(); | 446 MessageLoop::current()->RunUntilIdle(); |
| 439 profile_.reset(NULL); | 447 profile_.reset(NULL); |
| 440 MessageLoop::current()->RunUntilIdle(); | 448 MessageLoop::current()->RunUntilIdle(); |
| 449 | |
| 450 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | |
| 441 } | 451 } |
| 442 | 452 |
| 443 void ExtensionServiceTestBase::InitializeExtensionService( | 453 void ExtensionServiceTestBase::InitializeExtensionService( |
| 444 const base::FilePath& profile_path, | 454 const base::FilePath& profile_path, |
| 445 const base::FilePath& pref_file, | 455 const base::FilePath& pref_file, |
| 446 const base::FilePath& extensions_install_dir, | 456 const base::FilePath& extensions_install_dir, |
| 447 bool autoupdate_enabled) { | 457 bool autoupdate_enabled) { |
| 448 TestingProfile::Builder profile_builder; | 458 TestingProfile::Builder profile_builder; |
| 449 // Create a PrefService that only contains user defined preference values. | 459 // Create a PrefService that only contains user defined preference values. |
| 450 PrefServiceMockBuilder builder; | 460 PrefServiceMockBuilder builder; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 510 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
| 501 | 511 |
| 502 InitializeExtensionService(path, temp_prefs, extensions_install_dir_, false); | 512 InitializeExtensionService(path, temp_prefs, extensions_install_dir_, false); |
| 503 } | 513 } |
| 504 | 514 |
| 505 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { | 515 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
| 506 InitializeExtensionServiceHelper(false); | 516 InitializeExtensionServiceHelper(false); |
| 507 } | 517 } |
| 508 | 518 |
| 509 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { | 519 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
| 520 // Needed in order to look up RenderProcessHosts. | |
| 521 TestingBrowserProcess::GetGlobal()->SetProfileManager( | |
| 522 new ProfileManagerWithoutInit(temp_dir_.path())); | |
| 523 | |
| 510 static_cast<extensions::TestExtensionSystem*>( | 524 static_cast<extensions::TestExtensionSystem*>( |
| 511 ExtensionSystem::Get(profile_.get()))-> | 525 ExtensionSystem::Get(profile_.get()))-> |
| 512 CreateExtensionProcessManager(); | 526 CreateExtensionProcessManager(); |
| 513 } | 527 } |
| 514 | 528 |
| 515 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { | 529 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
| 516 InitializeExtensionServiceHelper(true); | 530 InitializeExtensionServiceHelper(true); |
| 517 service_->updater()->Start(); | 531 service_->updater()->Start(); |
| 518 } | 532 } |
| 519 | 533 |
| (...skipping 3080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3600 // EnableExtension() call above inserted into it and | 3614 // EnableExtension() call above inserted into it and |
| 3601 // UnloadAllExtensions() doesn't send out notifications. | 3615 // UnloadAllExtensions() doesn't send out notifications. |
| 3602 loaded_.clear(); | 3616 loaded_.clear(); |
| 3603 service_->ReloadExtensions(); | 3617 service_->ReloadExtensions(); |
| 3604 | 3618 |
| 3605 // Extension counts shouldn't change. | 3619 // Extension counts shouldn't change. |
| 3606 EXPECT_EQ(1u, service_->extensions()->size()); | 3620 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3607 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3621 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3608 } | 3622 } |
| 3609 | 3623 |
| 3624 namespace { | |
| 3625 std::vector<uint32> ExtensionMessageTypes(const IPC::TestSink& sink) { | |
| 3626 std::vector<uint32> message_types; | |
| 3627 for (size_t i = 0; i < sink.message_count(); ++i) { | |
| 3628 uint32 type = sink.GetMessageAt(i)->type(); | |
| 3629 if (IPC_MESSAGE_ID_CLASS(type) == ExtensionMsgStart) | |
| 3630 message_types.push_back(type); | |
| 3631 } | |
| 3632 return message_types; | |
| 3633 } | |
| 3634 | |
| 3635 struct ProcessObserver | |
| 3636 : public content::MockRenderProcessHostFactory::Observer { | |
| 3637 explicit ProcessObserver(content::MockRenderProcessHostFactory* factory) | |
| 3638 : Observer(factory) {} | |
| 3639 | |
| 3640 ~ProcessObserver() { | |
| 3641 for (size_t i = 0; i < hosts.size(); ++i) { | |
| 3642 if (destroyed_processes.count(process_ids[i]) == 0) | |
| 3643 hosts[i]->sink().RemoveFilter(process_messages[i]); | |
| 3644 delete process_messages[i]; | |
| 3645 } | |
| 3646 } | |
| 3647 | |
| 3648 virtual void OnRenderProcessHostCreated( | |
| 3649 content::MockRenderProcessHost* host) { | |
| 3650 IPC::TestSink* sink = new IPC::TestSink; | |
| 3651 hosts.push_back(host); | |
| 3652 process_ids.push_back(host->GetID()); | |
| 3653 process_messages.push_back(sink); | |
| 3654 host->sink().AddFilter(sink); | |
| 3655 } | |
| 3656 virtual void OnRenderProcessHostDestroyed( | |
| 3657 content::MockRenderProcessHost* host) { | |
| 3658 destroyed_processes.insert(host->GetID()); | |
| 3659 } | |
| 3660 | |
| 3661 std::vector<content::MockRenderProcessHost*> hosts; | |
| 3662 std::vector<int> process_ids; | |
| 3663 std::vector<IPC::TestSink*> process_messages; | |
| 3664 std::set<int> destroyed_processes; | |
| 3665 }; | |
| 3666 } // namespace | |
| 3667 | |
| 3610 // Tests reloading an extension. | 3668 // Tests reloading an extension. |
| 3611 TEST_F(ExtensionServiceTest, ReloadExtension) { | 3669 TEST_F(ExtensionServiceTest, ReloadExtension) { |
| 3670 ProcessObserver observer(rvh_enabler_.rph_factory()); | |
| 3671 | |
| 3672 content::TestNotificationTracker notifications; | |
| 3673 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSIONS_READY); | |
| 3674 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED); | |
| 3675 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_LOADED); | |
| 3676 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_UNLOADED); | |
| 3677 notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_CLOSING); | |
| 3678 notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_CREATED); | |
| 3679 notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); | |
| 3680 notifications.ListenForAll( | |
| 3681 content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW); | |
| 3682 | |
| 3612 InitializeEmptyExtensionService(); | 3683 InitializeEmptyExtensionService(); |
| 3613 InitializeExtensionProcessManager(); | 3684 InitializeExtensionProcessManager(); |
| 3685 service_->Init(); | |
| 3686 EXPECT_THAT(notifications.GetTypesAndReset(), | |
| 3687 testing::ElementsAre(chrome::NOTIFICATION_EXTENSIONS_READY)); | |
| 3614 | 3688 |
| 3615 // Simple extension that should install without error. | 3689 // Simple extension that should install without error. |
| 3616 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 3690 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 3617 base::FilePath ext = data_dir_ | 3691 base::FilePath ext = data_dir_ |
| 3618 .AppendASCII("good") | 3692 .AppendASCII("good") |
| 3619 .AppendASCII("Extensions") | 3693 .AppendASCII("Extensions") |
| 3620 .AppendASCII(extension_id) | 3694 .AppendASCII(extension_id) |
| 3621 .AppendASCII("1.0.0.0"); | 3695 .AppendASCII("1.0.0.0"); |
| 3622 extensions::UnpackedInstaller::Create(service_)->Load(ext); | 3696 extensions::UnpackedInstaller::Create(service_)->Load(ext); |
| 3623 loop_.RunUntilIdle(); | 3697 loop_.RunUntilIdle(); |
| 3624 | 3698 |
| 3699 EXPECT_THAT(notifications.GetTypesAndReset(), | |
| 3700 testing::ElementsAre(chrome::NOTIFICATION_EXTENSION_LOADED)); | |
| 3701 ASSERT_EQ(1u, observer.process_messages.size()); | |
| 3702 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]), | |
| 3703 testing::ElementsAre(ExtensionMsg_Loaded::ID, | |
| 3704 ExtensionMsg_ActivateExtension::ID, | |
| 3705 ExtensionMsg_Loaded::ID, | |
| 3706 ExtensionMsg_ActivateExtension::ID)); | |
| 3707 observer.process_messages[0]->ClearMessages(); | |
| 3708 | |
| 3625 EXPECT_EQ(1u, service_->extensions()->size()); | 3709 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3626 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3710 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3627 | 3711 |
| 3628 service_->ReloadExtension(extension_id); | 3712 service_->ReloadExtension(extension_id); |
| 3629 | 3713 |
| 3714 EXPECT_THAT(notifications.GetTypesAndReset(), | |
| 3715 testing::ElementsAre( | |
| 3716 chrome::NOTIFICATION_EXTENSION_UNLOADED, | |
| 3717 content::NOTIFICATION_RENDERER_PROCESS_CLOSING, | |
| 3718 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | |
| 3719 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED)); | |
| 3720 | |
| 3721 ASSERT_EQ(1u, observer.process_messages.size()); | |
| 3722 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]), | |
| 3723 testing::ElementsAre()); | |
| 3724 observer.process_messages[0]->ClearMessages(); | |
| 3725 | |
| 3630 // Extension should be disabled now, waiting to be reloaded. | 3726 // Extension should be disabled now, waiting to be reloaded. |
| 3631 EXPECT_EQ(0u, service_->extensions()->size()); | 3727 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3632 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 3728 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 3633 EXPECT_EQ(Extension::DISABLE_RELOAD, | 3729 EXPECT_EQ(Extension::DISABLE_RELOAD, |
| 3634 service_->extension_prefs()->GetDisableReasons(extension_id)); | 3730 service_->extension_prefs()->GetDisableReasons(extension_id)); |
| 3635 | 3731 |
| 3636 // Reloading again should not crash. | 3732 // Reloading again before iterating the MessageLoop should not crash and |
| 3733 // shouldn't cause an extra reload. | |
| 3637 service_->ReloadExtension(extension_id); | 3734 service_->ReloadExtension(extension_id); |
| 3735 EXPECT_THAT(notifications.GetTypesAndReset(), | |
| 3736 testing::ElementsAre()); | |
| 3737 ASSERT_EQ(1u, observer.process_messages.size()); | |
| 3738 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]), | |
| 3739 testing::ElementsAre()); | |
| 3740 observer.process_messages[0]->ClearMessages(); | |
| 3638 | 3741 |
| 3639 // Finish reloading | 3742 // Finish reloading |
| 3640 loop_.RunUntilIdle(); | 3743 loop_.RunUntilIdle(); |
| 3641 | 3744 |
| 3745 EXPECT_THAT(notifications.GetTypesAndReset(), | |
| 3746 testing::ElementsAre( | |
| 3747 chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 3748 chrome::NOTIFICATION_EXTENSION_UNLOADED, | |
| 3749 content::NOTIFICATION_RENDERER_PROCESS_CLOSING, | |
| 3750 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | |
| 3751 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 3752 chrome::NOTIFICATION_EXTENSION_LOADED)); | |
| 3753 | |
| 3754 ASSERT_EQ(3u, observer.process_messages.size()); | |
| 3755 EXPECT_THAT(observer.destroyed_processes, | |
| 3756 testing::ElementsAre(observer.process_ids[0], | |
| 3757 observer.process_ids[1])); | |
| 3758 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]), | |
| 3759 testing::ElementsAre()); | |
| 3760 observer.process_messages[0]->ClearMessages(); | |
| 3761 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[1]), | |
| 3762 testing::ElementsAre(ExtensionMsg_Loaded::ID, | |
| 3763 ExtensionMsg_ActivateExtension::ID, | |
| 3764 ExtensionMsg_Loaded::ID, | |
| 3765 ExtensionMsg_ActivateExtension::ID)); | |
| 3766 observer.process_messages[1]->ClearMessages(); | |
| 3767 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[2]), | |
| 3768 testing::ElementsAre(ExtensionMsg_Loaded::ID, | |
| 3769 ExtensionMsg_ActivateExtension::ID, | |
| 3770 ExtensionMsg_Loaded::ID, | |
| 3771 ExtensionMsg_ActivateExtension::ID)); | |
| 3772 observer.process_messages[2]->ClearMessages(); | |
| 3773 | |
| 3642 // Extension should be enabled again. | 3774 // Extension should be enabled again. |
| 3643 EXPECT_EQ(1u, service_->extensions()->size()); | 3775 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3644 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3776 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3645 } | 3777 } |
| 3646 | 3778 |
| 3647 TEST_F(ExtensionServiceTest, UninstallExtension) { | 3779 TEST_F(ExtensionServiceTest, UninstallExtension) { |
| 3648 InitializeEmptyExtensionService(); | 3780 InitializeEmptyExtensionService(); |
| 3649 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3781 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3650 EXPECT_EQ(1u, service_->extensions()->size()); | 3782 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3651 UninstallExtension(good_crx, false); | 3783 UninstallExtension(good_crx, false); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3776 .AppendASCII("v2_bad_requirements"); | 3908 .AppendASCII("v2_bad_requirements"); |
| 3777 extensions::UnpackedInstaller::Create(service_)->Load(path); | 3909 extensions::UnpackedInstaller::Create(service_)->Load(path); |
| 3778 loop_.RunUntilIdle(); | 3910 loop_.RunUntilIdle(); |
| 3779 EXPECT_EQ(1u, GetErrors().size()); | 3911 EXPECT_EQ(1u, GetErrors().size()); |
| 3780 EXPECT_EQ(0u, service_->extensions()->size()); | 3912 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3781 } | 3913 } |
| 3782 | 3914 |
| 3783 class ExtensionCookieCallback { | 3915 class ExtensionCookieCallback { |
| 3784 public: | 3916 public: |
| 3785 ExtensionCookieCallback() | 3917 ExtensionCookieCallback() |
| 3786 : result_(false), | 3918 : result_(false), |
| 3787 weak_factory_(MessageLoop::current()) {} | 3919 cookie_monster_(NULL), |
| 3920 weak_factory_(MessageLoop::current()) {} | |
| 3788 | 3921 |
| 3789 void SetCookieCallback(bool result) { | 3922 void SetCookieCallback(bool result) { |
| 3790 MessageLoop::current()->PostTask( | 3923 MessageLoop::current()->PostTask( |
| 3791 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); | 3924 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
| 3792 result_ = result; | 3925 result_ = result; |
| 3793 } | 3926 } |
| 3794 | 3927 |
| 3795 void GetAllCookiesCallback(const net::CookieList& list) { | 3928 void GetAllCookiesCallback(const net::CookieList& list) { |
| 3796 MessageLoop::current()->PostTask( | 3929 MessageLoop::current()->PostTask( |
| 3797 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); | 3930 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
| 3798 list_ = list; | 3931 list_ = list; |
| 3799 } | 3932 } |
| 3933 | |
| 3934 // Must run on IO thread to set up ThreadCheckers correctly. | |
| 3935 void GetCookieMonsterFromIOThread(net::URLRequestContextGetter* getter) { | |
| 3936 cookie_monster_ = getter->GetURLRequestContext()-> | |
| 3937 cookie_store()->GetCookieMonster(); | |
| 3938 } | |
| 3800 net::CookieList list_; | 3939 net::CookieList list_; |
| 3801 bool result_; | 3940 bool result_; |
| 3941 net::CookieMonster* cookie_monster_; | |
| 3802 base::WeakPtrFactory<MessageLoop> weak_factory_; | 3942 base::WeakPtrFactory<MessageLoop> weak_factory_; |
| 3803 }; | 3943 }; |
| 3804 | 3944 |
| 3805 // Verifies extension state is removed upon uninstall. | 3945 // Verifies extension state is removed upon uninstall. |
| 3806 TEST_F(ExtensionServiceTest, ClearExtensionData) { | 3946 TEST_F(ExtensionServiceTest, ClearExtensionData) { |
| 3807 InitializeEmptyExtensionService(); | 3947 InitializeEmptyExtensionService(); |
| 3808 ExtensionCookieCallback callback; | 3948 ExtensionCookieCallback callback; |
| 3809 | 3949 |
| 3810 // Load a test extension. | 3950 // Load a test extension. |
| 3811 base::FilePath path = data_dir_; | 3951 base::FilePath path = data_dir_; |
| 3812 path = path.AppendASCII("good.crx"); | 3952 path = path.AppendASCII("good.crx"); |
| 3813 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 3953 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 3814 ASSERT_TRUE(extension); | 3954 ASSERT_TRUE(extension); |
| 3815 GURL ext_url(extension->url()); | 3955 GURL ext_url(extension->url()); |
| 3816 string16 origin_id = | 3956 string16 origin_id = |
| 3817 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); | 3957 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); |
| 3818 | 3958 |
| 3819 // Set a cookie for the extension. | 3959 // Set a cookie for the extension. |
| 3820 net::CookieMonster* cookie_monster = | 3960 BrowserThread::PostTaskAndReply( |
| 3821 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> | 3961 BrowserThread::IO, |
| 3822 cookie_store()->GetCookieMonster(); | 3962 FROM_HERE, |
| 3823 ASSERT_TRUE(cookie_monster); | 3963 base::Bind(&ExtensionCookieCallback::GetCookieMonsterFromIOThread, |
| 3964 base::Unretained(&callback), | |
| 3965 make_scoped_refptr( | |
| 3966 profile_->GetRequestContextForExtensions())), | |
| 3967 base::Bind(&MessageLoop::Quit, base::Unretained(MessageLoop::current()))); | |
| 3968 loop_.Run(); | |
|
Matt Perry
2013/04/09 20:20:03
nit: could you move this to a global helper functi
Jeffrey Yasskin
2013/04/10 16:18:57
Done. That helper could probably stand to move to
| |
| 3969 ASSERT_TRUE(callback.cookie_monster_); | |
| 3970 | |
| 3824 net::CookieOptions options; | 3971 net::CookieOptions options; |
| 3825 cookie_monster->SetCookieWithOptionsAsync( | 3972 callback.cookie_monster_->SetCookieWithOptionsAsync( |
| 3826 ext_url, "dummy=value", options, | 3973 ext_url, "dummy=value", options, |
| 3827 base::Bind(&ExtensionCookieCallback::SetCookieCallback, | 3974 base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 3828 base::Unretained(&callback))); | 3975 base::Unretained(&callback))); |
| 3829 loop_.RunUntilIdle(); | 3976 MessageLoop::current()->RunUntilIdle(); |
| 3830 EXPECT_TRUE(callback.result_); | 3977 EXPECT_TRUE(callback.result_); |
| 3831 | 3978 |
| 3832 cookie_monster->GetAllCookiesForURLAsync( | 3979 callback.cookie_monster_->GetAllCookiesForURLAsync( |
| 3833 ext_url, | 3980 ext_url, |
| 3834 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 3981 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3835 base::Unretained(&callback))); | 3982 base::Unretained(&callback))); |
| 3836 loop_.RunUntilIdle(); | 3983 MessageLoop::current()->RunUntilIdle(); |
| 3837 EXPECT_EQ(1U, callback.list_.size()); | 3984 EXPECT_EQ(1U, callback.list_.size()); |
| 3838 | 3985 |
| 3839 // Open a database. | 3986 // Open a database. |
| 3840 webkit_database::DatabaseTracker* db_tracker = | 3987 webkit_database::DatabaseTracker* db_tracker = |
| 3841 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 3988 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 3842 GetDatabaseTracker(); | 3989 GetDatabaseTracker(); |
| 3843 string16 db_name = UTF8ToUTF16("db"); | 3990 string16 db_name = UTF8ToUTF16("db"); |
| 3844 string16 description = UTF8ToUTF16("db_description"); | 3991 string16 description = UTF8ToUTF16("db_description"); |
| 3845 int64 size; | 3992 int64 size; |
| 3846 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 3993 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 3868 GetIndexedDBContext(); | 4015 GetIndexedDBContext(); |
| 3869 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 4016 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
| 3870 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 4017 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 3871 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); | 4018 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 3872 | 4019 |
| 3873 // Uninstall the extension. | 4020 // Uninstall the extension. |
| 3874 service_->UninstallExtension(good_crx, false, NULL); | 4021 service_->UninstallExtension(good_crx, false, NULL); |
| 3875 loop_.RunUntilIdle(); | 4022 loop_.RunUntilIdle(); |
| 3876 | 4023 |
| 3877 // Check that the cookie is gone. | 4024 // Check that the cookie is gone. |
| 3878 cookie_monster->GetAllCookiesForURLAsync( | 4025 callback.cookie_monster_->GetAllCookiesForURLAsync( |
| 3879 ext_url, | 4026 ext_url, |
| 3880 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4027 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3881 base::Unretained(&callback))); | 4028 base::Unretained(&callback))); |
| 3882 loop_.RunUntilIdle(); | 4029 loop_.RunUntilIdle(); |
| 3883 EXPECT_EQ(0U, callback.list_.size()); | 4030 EXPECT_EQ(0U, callback.list_.size()); |
| 3884 | 4031 |
| 3885 // The database should have vanished as well. | 4032 // The database should have vanished as well. |
| 3886 origins.clear(); | 4033 origins.clear(); |
| 3887 db_tracker->GetAllOriginsInfo(&origins); | 4034 db_tracker->GetAllOriginsInfo(&origins); |
| 3888 EXPECT_EQ(0U, origins.size()); | 4035 EXPECT_EQ(0U, origins.size()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3924 EXPECT_TRUE(extension->HasAPIPermission( | 4071 EXPECT_TRUE(extension->HasAPIPermission( |
| 3925 APIPermission::kUnlimitedStorage)); | 4072 APIPermission::kUnlimitedStorage)); |
| 3926 EXPECT_TRUE(extension->web_extent().MatchesURL( | 4073 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 3927 extension->GetFullLaunchURL())); | 4074 extension->GetFullLaunchURL())); |
| 3928 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 4075 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 3929 EXPECT_EQ(origin1, origin2); | 4076 EXPECT_EQ(origin1, origin2); |
| 3930 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 4077 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3931 IsStorageUnlimited(origin2)); | 4078 IsStorageUnlimited(origin2)); |
| 3932 | 4079 |
| 3933 // Set a cookie for the extension. | 4080 // Set a cookie for the extension. |
| 3934 net::CookieMonster* cookie_monster = | 4081 BrowserThread::PostTaskAndReply( |
| 3935 profile_->GetRequestContext()->GetURLRequestContext()-> | 4082 BrowserThread::IO, |
| 3936 cookie_store()->GetCookieMonster(); | 4083 FROM_HERE, |
| 3937 ASSERT_TRUE(cookie_monster); | 4084 base::Bind(&ExtensionCookieCallback::GetCookieMonsterFromIOThread, |
| 4085 base::Unretained(&callback), | |
| 4086 make_scoped_refptr(profile_->GetRequestContext())), | |
| 4087 base::Bind(&MessageLoop::Quit, base::Unretained(MessageLoop::current()))); | |
| 4088 loop_.Run(); | |
| 4089 ASSERT_TRUE(callback.cookie_monster_); | |
| 3938 net::CookieOptions options; | 4090 net::CookieOptions options; |
| 3939 cookie_monster->SetCookieWithOptionsAsync( | 4091 callback.cookie_monster_->SetCookieWithOptionsAsync( |
| 3940 origin1, "dummy=value", options, | 4092 origin1, "dummy=value", options, |
| 3941 base::Bind(&ExtensionCookieCallback::SetCookieCallback, | 4093 base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 3942 base::Unretained(&callback))); | 4094 base::Unretained(&callback))); |
| 3943 loop_.RunUntilIdle(); | 4095 loop_.RunUntilIdle(); |
| 3944 EXPECT_TRUE(callback.result_); | 4096 EXPECT_TRUE(callback.result_); |
| 3945 | 4097 |
| 3946 cookie_monster->GetAllCookiesForURLAsync( | 4098 callback.cookie_monster_->GetAllCookiesForURLAsync( |
| 3947 origin1, | 4099 origin1, |
| 3948 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4100 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3949 base::Unretained(&callback))); | 4101 base::Unretained(&callback))); |
| 3950 loop_.RunUntilIdle(); | 4102 loop_.RunUntilIdle(); |
| 3951 EXPECT_EQ(1U, callback.list_.size()); | 4103 EXPECT_EQ(1U, callback.list_.size()); |
| 3952 | 4104 |
| 3953 // Open a database. | 4105 // Open a database. |
| 3954 webkit_database::DatabaseTracker* db_tracker = | 4106 webkit_database::DatabaseTracker* db_tracker = |
| 3955 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 4107 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 3956 GetDatabaseTracker(); | 4108 GetDatabaseTracker(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 3985 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); | 4137 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 3986 | 4138 |
| 3987 // Uninstall one of them, unlimited storage should still be granted | 4139 // Uninstall one of them, unlimited storage should still be granted |
| 3988 // to the origin. | 4140 // to the origin. |
| 3989 UninstallExtension(id1, false); | 4141 UninstallExtension(id1, false); |
| 3990 EXPECT_EQ(1u, service_->extensions()->size()); | 4142 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3991 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 4143 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3992 IsStorageUnlimited(origin1)); | 4144 IsStorageUnlimited(origin1)); |
| 3993 | 4145 |
| 3994 // Check that the cookie is still there. | 4146 // Check that the cookie is still there. |
| 3995 cookie_monster->GetAllCookiesForURLAsync( | 4147 callback.cookie_monster_->GetAllCookiesForURLAsync( |
| 3996 origin1, | 4148 origin1, |
| 3997 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4149 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3998 base::Unretained(&callback))); | 4150 base::Unretained(&callback))); |
| 3999 loop_.RunUntilIdle(); | 4151 loop_.RunUntilIdle(); |
| 4000 EXPECT_EQ(1U, callback.list_.size()); | 4152 EXPECT_EQ(1U, callback.list_.size()); |
| 4001 | 4153 |
| 4002 // Now uninstall the other. Storage should be cleared for the apps. | 4154 // Now uninstall the other. Storage should be cleared for the apps. |
| 4003 UninstallExtension(id2, false); | 4155 UninstallExtension(id2, false); |
| 4004 EXPECT_EQ(0u, service_->extensions()->size()); | 4156 EXPECT_EQ(0u, service_->extensions()->size()); |
| 4005 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 4157 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4006 IsStorageUnlimited(origin1)); | 4158 IsStorageUnlimited(origin1)); |
| 4007 | 4159 |
| 4008 // Check that the cookie is gone. | 4160 // Check that the cookie is gone. |
| 4009 cookie_monster->GetAllCookiesForURLAsync( | 4161 callback.cookie_monster_->GetAllCookiesForURLAsync( |
| 4010 origin1, | 4162 origin1, |
| 4011 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4163 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4012 base::Unretained(&callback))); | 4164 base::Unretained(&callback))); |
| 4013 loop_.RunUntilIdle(); | 4165 loop_.RunUntilIdle(); |
| 4014 EXPECT_EQ(0U, callback.list_.size()); | 4166 EXPECT_EQ(0U, callback.list_.size()); |
| 4015 | 4167 |
| 4016 // The database should have vanished as well. | 4168 // The database should have vanished as well. |
| 4017 origins.clear(); | 4169 origins.clear(); |
| 4018 db_tracker->GetAllOriginsInfo(&origins); | 4170 db_tracker->GetAllOriginsInfo(&origins); |
| 4019 EXPECT_EQ(0U, origins.size()); | 4171 EXPECT_EQ(0U, origins.size()); |
| (...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5901 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 6053 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5902 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 6054 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5903 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 6055 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5904 | 6056 |
| 5905 ExtensionPrefs* prefs = service_->extension_prefs(); | 6057 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 5906 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 6058 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
| 5907 Extension::DISABLE_SIDELOAD_WIPEOUT); | 6059 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5908 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 6060 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
| 5909 Extension::DISABLE_SIDELOAD_WIPEOUT); | 6061 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5910 } | 6062 } |
| OLD | NEW |