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

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

Issue 13533007: Test extension reloading behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a ScopedOleInitializer for Windows Created 7 years, 8 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) 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
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/json/json_file_value_serializer.h" 17 #include "base/json/json_file_value_serializer.h"
18 #include "base/json/json_reader.h" 18 #include "base/json/json_reader.h"
19 #include "base/json/json_string_value_serializer.h" 19 #include "base/json/json_string_value_serializer.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "base/message_loop.h" 22 #include "base/message_loop.h"
23 #include "base/path_service.h" 23 #include "base/path_service.h"
24 #include "base/run_loop.h"
24 #include "base/stl_util.h" 25 #include "base/stl_util.h"
25 #include "base/string16.h" 26 #include "base/string16.h"
26 #include "base/string_util.h" 27 #include "base/string_util.h"
27 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
28 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
29 #include "base/version.h" 30 #include "base/version.h"
30 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/extensions/app_sync_data.h" 32 #include "chrome/browser/extensions/app_sync_data.h"
32 #include "chrome/browser/extensions/component_loader.h" 33 #include "chrome/browser/extensions/component_loader.h"
33 #include "chrome/browser/extensions/crx_installer.h" 34 #include "chrome/browser/extensions/crx_installer.h"
(...skipping 17 matching lines...) Expand all
51 #include "chrome/browser/extensions/pending_extension_info.h" 52 #include "chrome/browser/extensions/pending_extension_info.h"
52 #include "chrome/browser/extensions/pending_extension_manager.h" 53 #include "chrome/browser/extensions/pending_extension_manager.h"
53 #include "chrome/browser/extensions/test_extension_system.h" 54 #include "chrome/browser/extensions/test_extension_system.h"
54 #include "chrome/browser/extensions/test_management_policy.h" 55 #include "chrome/browser/extensions/test_management_policy.h"
55 #include "chrome/browser/extensions/unpacked_installer.h" 56 #include "chrome/browser/extensions/unpacked_installer.h"
56 #include "chrome/browser/extensions/updater/extension_updater.h" 57 #include "chrome/browser/extensions/updater/extension_updater.h"
57 #include "chrome/browser/prefs/browser_prefs.h" 58 #include "chrome/browser/prefs/browser_prefs.h"
58 #include "chrome/browser/prefs/pref_service_mock_builder.h" 59 #include "chrome/browser/prefs/pref_service_mock_builder.h"
59 #include "chrome/browser/prefs/pref_service_syncable.h" 60 #include "chrome/browser/prefs/pref_service_syncable.h"
60 #include "chrome/browser/prefs/scoped_user_pref_update.h" 61 #include "chrome/browser/prefs/scoped_user_pref_update.h"
62 #include "chrome/browser/profiles/profile_manager.h"
61 #include "chrome/common/chrome_constants.h" 63 #include "chrome/common/chrome_constants.h"
62 #include "chrome/common/chrome_notification_types.h" 64 #include "chrome/common/chrome_notification_types.h"
63 #include "chrome/common/chrome_paths.h" 65 #include "chrome/common/chrome_paths.h"
64 #include "chrome/common/chrome_switches.h" 66 #include "chrome/common/chrome_switches.h"
65 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 67 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
66 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 68 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
67 #include "chrome/common/extensions/background_info.h" 69 #include "chrome/common/extensions/background_info.h"
68 #include "chrome/common/extensions/extension.h" 70 #include "chrome/common/extensions/extension.h"
69 #include "chrome/common/extensions/extension_l10n_util.h" 71 #include "chrome/common/extensions/extension_l10n_util.h"
70 #include "chrome/common/extensions/extension_manifest_constants.h" 72 #include "chrome/common/extensions/extension_manifest_constants.h"
73 #include "chrome/common/extensions/extension_messages.h"
71 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 74 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
72 #include "chrome/common/extensions/manifest_handlers/requirements_handler.h" 75 #include "chrome/common/extensions/manifest_handlers/requirements_handler.h"
73 #include "chrome/common/extensions/manifest_url_handler.h" 76 #include "chrome/common/extensions/manifest_url_handler.h"
74 #include "chrome/common/extensions/permissions/permission_set.h" 77 #include "chrome/common/extensions/permissions/permission_set.h"
75 #include "chrome/common/pref_names.h" 78 #include "chrome/common/pref_names.h"
76 #include "chrome/common/url_constants.h" 79 #include "chrome/common/url_constants.h"
80 #include "chrome/test/base/testing_browser_process.h"
77 #include "chrome/test/base/testing_profile.h" 81 #include "chrome/test/base/testing_profile.h"
78 #include "components/user_prefs/pref_registry_syncable.h" 82 #include "components/user_prefs/pref_registry_syncable.h"
79 #include "content/public/browser/dom_storage_context.h" 83 #include "content/public/browser/dom_storage_context.h"
80 #include "content/public/browser/gpu_data_manager.h" 84 #include "content/public/browser/gpu_data_manager.h"
81 #include "content/public/browser/indexed_db_context.h" 85 #include "content/public/browser/indexed_db_context.h"
82 #include "content/public/browser/notification_registrar.h" 86 #include "content/public/browser/notification_registrar.h"
83 #include "content/public/browser/notification_service.h" 87 #include "content/public/browser/notification_service.h"
84 #include "content/public/browser/plugin_service.h" 88 #include "content/public/browser/plugin_service.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"
92 #include "content/public/test/mock_render_process_host.h"
88 #include "content/public/test/test_browser_thread.h" 93 #include "content/public/test/test_browser_thread.h"
94 #include "content/public/test/test_notification_tracker.h"
89 #include "extensions/common/constants.h" 95 #include "extensions/common/constants.h"
90 #include "extensions/common/extension_resource.h" 96 #include "extensions/common/extension_resource.h"
91 #include "extensions/common/url_pattern.h" 97 #include "extensions/common/url_pattern.h"
92 #include "googleurl/src/gurl.h" 98 #include "googleurl/src/gurl.h"
93 #include "grit/browser_resources.h" 99 #include "grit/browser_resources.h"
94 #include "net/cookies/canonical_cookie.h" 100 #include "net/cookies/canonical_cookie.h"
95 #include "net/cookies/cookie_monster.h" 101 #include "net/cookies/cookie_monster.h"
96 #include "net/cookies/cookie_options.h" 102 #include "net/cookies/cookie_options.h"
97 #include "net/url_request/url_request_context.h" 103 #include "net/url_request/url_request_context.h"
98 #include "net/url_request/url_request_context_getter.h" 104 #include "net/url_request/url_request_context_getter.h"
99 #include "sync/api/string_ordinal.h" 105 #include "sync/api/string_ordinal.h"
100 #include "sync/api/sync_error_factory.h" 106 #include "sync/api/sync_error_factory.h"
101 #include "sync/api/sync_error_factory_mock.h" 107 #include "sync/api/sync_error_factory_mock.h"
102 #include "sync/protocol/app_specifics.pb.h" 108 #include "sync/protocol/app_specifics.pb.h"
103 #include "sync/protocol/extension_specifics.pb.h" 109 #include "sync/protocol/extension_specifics.pb.h"
104 #include "sync/protocol/sync.pb.h" 110 #include "sync/protocol/sync.pb.h"
111 #include "testing/gmock/include/gmock/gmock.h"
105 #include "testing/gtest/include/gtest/gtest.h" 112 #include "testing/gtest/include/gtest/gtest.h"
106 #include "testing/platform_test.h" 113 #include "testing/platform_test.h"
107 #include "webkit/database/database_tracker.h" 114 #include "webkit/database/database_tracker.h"
108 #include "webkit/database/database_util.h" 115 #include "webkit/database/database_util.h"
109 #include "webkit/plugins/npapi/mock_plugin_list.h" 116 #include "webkit/plugins/npapi/mock_plugin_list.h"
110 #include "webkit/quota/quota_manager.h" 117 #include "webkit/quota/quota_manager.h"
111 118
112 #if defined(OS_CHROMEOS) 119 #if defined(OS_CHROMEOS)
113 #include "chrome/browser/chromeos/extensions/install_limiter.h" 120 #include "chrome/browser/chromeos/extensions/install_limiter.h"
114 #endif 121 #endif
115 122
123 #if defined(OS_WIN)
124 #include "ui/base/win/scoped_ole_initializer.h"
125 #endif
126
116 using content::BrowserContext; 127 using content::BrowserContext;
117 using content::BrowserThread; 128 using content::BrowserThread;
118 using content::DOMStorageContext; 129 using content::DOMStorageContext;
119 using content::IndexedDBContext; 130 using content::IndexedDBContext;
120 using content::PluginService; 131 using content::PluginService;
121 using extensions::APIPermission; 132 using extensions::APIPermission;
122 using extensions::APIPermissionSet; 133 using extensions::APIPermissionSet;
123 using extensions::CrxInstaller; 134 using extensions::CrxInstaller;
124 using extensions::Extension; 135 using extensions::Extension;
125 using extensions::ExtensionCreator; 136 using extensions::ExtensionCreator;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 int ids_found_; 413 int ids_found_;
403 base::FilePath fake_base_path_; 414 base::FilePath fake_base_path_;
404 int expected_creation_flags_; 415 int expected_creation_flags_;
405 scoped_ptr<extensions::ExternalProviderImpl> provider_; 416 scoped_ptr<extensions::ExternalProviderImpl> provider_;
406 scoped_ptr<DictionaryValue> prefs_; 417 scoped_ptr<DictionaryValue> prefs_;
407 418
408 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 419 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
409 }; 420 };
410 421
411 // Our message loop may be used in tests which require it to be an IO loop. 422 // Our message loop may be used in tests which require it to be an IO loop.
412 ExtensionServiceTestBase::ExtensionServiceTestBase() 423 ExtensionServiceTestBase::ExtensionServiceTestBase(
413 : loop_(MessageLoop::TYPE_IO), 424 MessageLoop::Type main_loop_type)
425 : loop_(main_loop_type),
426 local_state_(TestingBrowserProcess::GetGlobal()),
427 #if defined(OS_WIN)
428 ole_initializer_(new ui::ScopedOleInitializer()),
429 #endif
414 service_(NULL), 430 service_(NULL),
415 management_policy_(NULL), 431 management_policy_(NULL),
416 expected_extensions_count_(0), 432 expected_extensions_count_(0),
417 ui_thread_(BrowserThread::UI, &loop_), 433 ui_thread_(BrowserThread::UI, &loop_),
418 db_thread_(BrowserThread::DB, &loop_), 434 db_thread_(BrowserThread::DB, &loop_),
419 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), 435 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_),
420 file_thread_(BrowserThread::FILE, &loop_), 436 file_thread_(BrowserThread::FILE, &loop_),
421 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), 437 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_),
422 io_thread_(BrowserThread::IO, &loop_), 438 io_thread_(main_loop_type == MessageLoop::TYPE_IO
439 ? new content::TestBrowserThread(BrowserThread::IO, &loop_)
440 : new content::TestBrowserThread(BrowserThread::IO)),
423 override_sideload_wipeout_( 441 override_sideload_wipeout_(
424 FeatureSwitch::sideload_wipeout(), false) { 442 FeatureSwitch::sideload_wipeout(), false) {
443 if (main_loop_type != MessageLoop::TYPE_IO)
444 io_thread_->StartIOThread();
425 base::FilePath test_data_dir; 445 base::FilePath test_data_dir;
426 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 446 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
427 ADD_FAILURE(); 447 ADD_FAILURE();
428 return; 448 return;
429 } 449 }
430 data_dir_ = test_data_dir.AppendASCII("extensions"); 450 data_dir_ = test_data_dir.AppendASCII("extensions");
431 } 451 }
432 452
433 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 453 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
434 // Drop our reference to ExtensionService and TestingProfile, so that they 454 // Drop our reference to ExtensionService and TestingProfile, so that they
435 // can be destroyed while BrowserThreads and MessageLoop are still around 455 // can be destroyed while BrowserThreads and MessageLoop are still around
436 // (they are used in the destruction process). 456 // (they are used in the destruction process).
437 service_ = NULL; 457 service_ = NULL;
438 MessageLoop::current()->RunUntilIdle(); 458 MessageLoop::current()->RunUntilIdle();
439 profile_.reset(NULL); 459 profile_.reset(NULL);
440 MessageLoop::current()->RunUntilIdle(); 460 MessageLoop::current()->RunUntilIdle();
461
462 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
441 } 463 }
442 464
443 void ExtensionServiceTestBase::InitializeExtensionService( 465 void ExtensionServiceTestBase::InitializeExtensionService(
444 const base::FilePath& profile_path, 466 const base::FilePath& profile_path,
445 const base::FilePath& pref_file, 467 const base::FilePath& pref_file,
446 const base::FilePath& extensions_install_dir, 468 const base::FilePath& extensions_install_dir,
447 bool autoupdate_enabled) { 469 bool autoupdate_enabled) {
448 TestingProfile::Builder profile_builder; 470 TestingProfile::Builder profile_builder;
449 // Create a PrefService that only contains user defined preference values. 471 // Create a PrefService that only contains user defined preference values.
450 PrefServiceMockBuilder builder; 472 PrefServiceMockBuilder builder;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); 522 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true);
501 523
502 InitializeExtensionService(path, temp_prefs, extensions_install_dir_, false); 524 InitializeExtensionService(path, temp_prefs, extensions_install_dir_, false);
503 } 525 }
504 526
505 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { 527 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
506 InitializeExtensionServiceHelper(false); 528 InitializeExtensionServiceHelper(false);
507 } 529 }
508 530
509 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { 531 void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
532 // Needed in order to look up RenderProcessHosts.
533 TestingBrowserProcess::GetGlobal()->SetProfileManager(
534 new ProfileManagerWithoutInit(temp_dir_.path()));
535
510 static_cast<extensions::TestExtensionSystem*>( 536 static_cast<extensions::TestExtensionSystem*>(
511 ExtensionSystem::Get(profile_.get()))-> 537 ExtensionSystem::Get(profile_.get()))->
512 CreateExtensionProcessManager(); 538 CreateExtensionProcessManager();
513 } 539 }
514 540
515 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 541 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
516 InitializeExtensionServiceHelper(true); 542 InitializeExtensionServiceHelper(true);
517 service_->updater()->Start(); 543 service_->updater()->Start();
518 } 544 }
519 545
(...skipping 29 matching lines...) Expand all
549 void ExtensionServiceTestBase::SetUp() { 575 void ExtensionServiceTestBase::SetUp() {
550 ExtensionTest::SetUp(); 576 ExtensionTest::SetUp();
551 ExtensionErrorReporter::GetInstance()->ClearErrors(); 577 ExtensionErrorReporter::GetInstance()->ClearErrors();
552 (new extensions::BackgroundManifestHandler)->Register(); 578 (new extensions::BackgroundManifestHandler)->Register();
553 (new extensions::ContentScriptsHandler)->Register(); 579 (new extensions::ContentScriptsHandler)->Register();
554 (new extensions::DefaultLocaleHandler)->Register(); 580 (new extensions::DefaultLocaleHandler)->Register();
555 (new extensions::PluginsHandler)->Register(); 581 (new extensions::PluginsHandler)->Register();
556 (new extensions::RequirementsHandler)->Register(); 582 (new extensions::RequirementsHandler)->Register();
557 } 583 }
558 584
585 template<typename Result>
586 static Result PostTaskAndWaitForResult(
587 content::BrowserThread::ID thread,
588 const tracked_objects::Location& from_here,
589 const base::Callback<Result(void)>& task) {
590 struct ResultSaver {
591 static void UpdateResult(base::RunLoop* loop,
592 Result* saved,
593 Result from_task) {
594 using std::swap;
595 swap(*saved, from_task);
596 loop->Quit();
597 }
598 };
599
600 Result result;
601 base::RunLoop loop;
602 content::BrowserThread::PostTaskAndReplyWithResult(
603 thread, from_here, task,
604 base::Bind(&ResultSaver::UpdateResult,
605 base::Unretained(&loop),
606 base::Unretained(&result)));
607 loop.Run();
608 return result;
609 }
610
559 class ExtensionServiceTest 611 class ExtensionServiceTest
560 : public ExtensionServiceTestBase, public content::NotificationObserver { 612 : public ExtensionServiceTestBase, public content::NotificationObserver {
561 public: 613 public:
562 ExtensionServiceTest() 614 ExtensionServiceTest()
563 : installed_(NULL), 615 : installed_(NULL),
564 override_external_install_prompt_( 616 override_external_install_prompt_(
565 FeatureSwitch::prompt_for_external_extensions(), false) { 617 FeatureSwitch::prompt_for_external_extensions(), false) {
566 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 618 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
567 content::NotificationService::AllSources()); 619 content::NotificationService::AllSources());
568 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 620 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
(...skipping 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after
3600 // EnableExtension() call above inserted into it and 3652 // EnableExtension() call above inserted into it and
3601 // UnloadAllExtensions() doesn't send out notifications. 3653 // UnloadAllExtensions() doesn't send out notifications.
3602 loaded_.clear(); 3654 loaded_.clear();
3603 service_->ReloadExtensions(); 3655 service_->ReloadExtensions();
3604 3656
3605 // Extension counts shouldn't change. 3657 // Extension counts shouldn't change.
3606 EXPECT_EQ(1u, service_->extensions()->size()); 3658 EXPECT_EQ(1u, service_->extensions()->size());
3607 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3659 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3608 } 3660 }
3609 3661
3662 namespace {
3663 std::vector<uint32> ExtensionMessageTypes(const IPC::TestSink& sink) {
3664 std::vector<uint32> message_types;
3665 for (size_t i = 0; i < sink.message_count(); ++i) {
3666 uint32 type = sink.GetMessageAt(i)->type();
3667 if (IPC_MESSAGE_ID_CLASS(type) == ExtensionMsgStart)
3668 message_types.push_back(type);
3669 }
3670 return message_types;
3671 }
3672
3673 struct ProcessObserver
3674 : public content::MockRenderProcessHostFactory::Observer {
3675 explicit ProcessObserver(content::MockRenderProcessHostFactory* factory)
3676 : Observer(factory) {}
3677
3678 ~ProcessObserver() {
3679 for (size_t i = 0; i < hosts.size(); ++i) {
3680 if (destroyed_processes.count(process_ids[i]) == 0)
3681 hosts[i]->sink().RemoveFilter(process_messages[i]);
3682 delete process_messages[i];
3683 }
3684 }
3685
3686 virtual void OnRenderProcessHostCreated(
3687 content::MockRenderProcessHost* host) {
3688 IPC::TestSink* sink = new IPC::TestSink;
3689 hosts.push_back(host);
3690 process_ids.push_back(host->GetID());
3691 process_messages.push_back(sink);
3692 host->sink().AddFilter(sink);
3693 }
3694 virtual void OnRenderProcessHostDestroyed(
3695 content::MockRenderProcessHost* host) {
3696 destroyed_processes.insert(host->GetID());
3697 }
3698
3699 std::vector<content::MockRenderProcessHost*> hosts;
3700 std::vector<int> process_ids;
3701 std::vector<IPC::TestSink*> process_messages;
3702 std::set<int> destroyed_processes;
3703 };
3704 } // namespace
3705
3610 // Tests reloading an extension. 3706 // Tests reloading an extension.
3611 TEST_F(ExtensionServiceTest, ReloadExtension) { 3707 TEST_F(ExtensionServiceTest, ReloadExtension) {
3708 ProcessObserver observer(rvh_enabler_.rph_factory());
3709
3710 content::TestNotificationTracker notifications;
3711 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSIONS_READY);
3712 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED);
3713 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_LOADED);
3714 notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_UNLOADED);
3715 notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_CLOSING);
3716 notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_CREATED);
3717 notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
3718 notifications.ListenForAll(
3719 content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW);
3720
3612 InitializeEmptyExtensionService(); 3721 InitializeEmptyExtensionService();
3613 InitializeExtensionProcessManager(); 3722 InitializeExtensionProcessManager();
3723 service_->Init();
3724 EXPECT_THAT(notifications.GetTypesAndReset(),
3725 testing::ElementsAre(chrome::NOTIFICATION_EXTENSIONS_READY));
3614 3726
3615 // Simple extension that should install without error. 3727 // Simple extension that should install without error.
3616 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 3728 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj";
3617 base::FilePath ext = data_dir_ 3729 base::FilePath ext = data_dir_
3618 .AppendASCII("good") 3730 .AppendASCII("good")
3619 .AppendASCII("Extensions") 3731 .AppendASCII("Extensions")
3620 .AppendASCII(extension_id) 3732 .AppendASCII(extension_id)
3621 .AppendASCII("1.0.0.0"); 3733 .AppendASCII("1.0.0.0");
3622 extensions::UnpackedInstaller::Create(service_)->Load(ext); 3734 extensions::UnpackedInstaller::Create(service_)->Load(ext);
3623 loop_.RunUntilIdle(); 3735 loop_.RunUntilIdle();
3624 3736
3737 EXPECT_THAT(notifications.GetTypesAndReset(),
3738 testing::ElementsAre(chrome::NOTIFICATION_EXTENSION_LOADED));
3739 ASSERT_EQ(1u, observer.process_messages.size());
3740 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
3741 testing::ElementsAre(ExtensionMsg_Loaded::ID,
3742 ExtensionMsg_ActivateExtension::ID,
3743 ExtensionMsg_Loaded::ID,
3744 ExtensionMsg_ActivateExtension::ID));
3745 observer.process_messages[0]->ClearMessages();
3746
3625 EXPECT_EQ(1u, service_->extensions()->size()); 3747 EXPECT_EQ(1u, service_->extensions()->size());
3626 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3748 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3627 3749
3628 service_->ReloadExtension(extension_id); 3750 service_->ReloadExtension(extension_id);
3629 3751
3752 EXPECT_THAT(notifications.GetTypesAndReset(),
3753 testing::ElementsAre(
3754 chrome::NOTIFICATION_EXTENSION_UNLOADED,
3755 content::NOTIFICATION_RENDERER_PROCESS_CLOSING,
3756 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
3757 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED));
3758
3759 ASSERT_EQ(1u, observer.process_messages.size());
3760 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
3761 testing::ElementsAre());
3762 observer.process_messages[0]->ClearMessages();
3763
3630 // Extension should be disabled now, waiting to be reloaded. 3764 // Extension should be disabled now, waiting to be reloaded.
3631 EXPECT_EQ(0u, service_->extensions()->size()); 3765 EXPECT_EQ(0u, service_->extensions()->size());
3632 EXPECT_EQ(1u, service_->disabled_extensions()->size()); 3766 EXPECT_EQ(1u, service_->disabled_extensions()->size());
3633 EXPECT_EQ(Extension::DISABLE_RELOAD, 3767 EXPECT_EQ(Extension::DISABLE_RELOAD,
3634 service_->extension_prefs()->GetDisableReasons(extension_id)); 3768 service_->extension_prefs()->GetDisableReasons(extension_id));
3635 3769
3636 // Reloading again should not crash. 3770 // Reloading again before iterating the MessageLoop should not crash and
3771 // shouldn't cause an extra reload.
3637 service_->ReloadExtension(extension_id); 3772 service_->ReloadExtension(extension_id);
3773 EXPECT_THAT(notifications.GetTypesAndReset(),
3774 testing::ElementsAre());
3775 ASSERT_EQ(1u, observer.process_messages.size());
3776 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
3777 testing::ElementsAre());
3778 observer.process_messages[0]->ClearMessages();
3638 3779
3639 // Finish reloading 3780 // Finish reloading
3640 loop_.RunUntilIdle(); 3781 loop_.RunUntilIdle();
3641 3782
3783 EXPECT_THAT(notifications.GetTypesAndReset(),
3784 testing::ElementsAre(
3785 chrome::NOTIFICATION_EXTENSION_LOADED,
3786 chrome::NOTIFICATION_EXTENSION_UNLOADED,
3787 content::NOTIFICATION_RENDERER_PROCESS_CLOSING,
3788 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
3789 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
3790 chrome::NOTIFICATION_EXTENSION_LOADED));
3791
3792 ASSERT_EQ(3u, observer.process_messages.size());
3793 EXPECT_THAT(observer.destroyed_processes,
3794 testing::ElementsAre(observer.process_ids[0],
3795 observer.process_ids[1]));
3796 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
3797 testing::ElementsAre());
3798 observer.process_messages[0]->ClearMessages();
3799 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[1]),
3800 testing::ElementsAre(ExtensionMsg_Loaded::ID,
3801 ExtensionMsg_ActivateExtension::ID,
3802 ExtensionMsg_Loaded::ID,
3803 ExtensionMsg_ActivateExtension::ID));
3804 observer.process_messages[1]->ClearMessages();
3805 EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[2]),
3806 testing::ElementsAre(ExtensionMsg_Loaded::ID,
3807 ExtensionMsg_ActivateExtension::ID,
3808 ExtensionMsg_Loaded::ID,
3809 ExtensionMsg_ActivateExtension::ID));
3810 observer.process_messages[2]->ClearMessages();
3811
3642 // Extension should be enabled again. 3812 // Extension should be enabled again.
3643 EXPECT_EQ(1u, service_->extensions()->size()); 3813 EXPECT_EQ(1u, service_->extensions()->size());
3644 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3814 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3645 } 3815 }
3646 3816
3647 TEST_F(ExtensionServiceTest, UninstallExtension) { 3817 TEST_F(ExtensionServiceTest, UninstallExtension) {
3648 InitializeEmptyExtensionService(); 3818 InitializeEmptyExtensionService();
3649 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3819 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3650 EXPECT_EQ(1u, service_->extensions()->size()); 3820 EXPECT_EQ(1u, service_->extensions()->size());
3651 UninstallExtension(good_crx, false); 3821 UninstallExtension(good_crx, false);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3776 .AppendASCII("v2_bad_requirements"); 3946 .AppendASCII("v2_bad_requirements");
3777 extensions::UnpackedInstaller::Create(service_)->Load(path); 3947 extensions::UnpackedInstaller::Create(service_)->Load(path);
3778 loop_.RunUntilIdle(); 3948 loop_.RunUntilIdle();
3779 EXPECT_EQ(1u, GetErrors().size()); 3949 EXPECT_EQ(1u, GetErrors().size());
3780 EXPECT_EQ(0u, service_->extensions()->size()); 3950 EXPECT_EQ(0u, service_->extensions()->size());
3781 } 3951 }
3782 3952
3783 class ExtensionCookieCallback { 3953 class ExtensionCookieCallback {
3784 public: 3954 public:
3785 ExtensionCookieCallback() 3955 ExtensionCookieCallback()
3786 : result_(false), 3956 : result_(false),
3787 weak_factory_(MessageLoop::current()) {} 3957 weak_factory_(MessageLoop::current()) {}
3788 3958
3789 void SetCookieCallback(bool result) { 3959 void SetCookieCallback(bool result) {
3790 MessageLoop::current()->PostTask( 3960 MessageLoop::current()->PostTask(
3791 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); 3961 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr()));
3792 result_ = result; 3962 result_ = result;
3793 } 3963 }
3794 3964
3795 void GetAllCookiesCallback(const net::CookieList& list) { 3965 void GetAllCookiesCallback(const net::CookieList& list) {
3796 MessageLoop::current()->PostTask( 3966 MessageLoop::current()->PostTask(
3797 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); 3967 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr()));
3798 list_ = list; 3968 list_ = list;
3799 } 3969 }
3970
3800 net::CookieList list_; 3971 net::CookieList list_;
3801 bool result_; 3972 bool result_;
3802 base::WeakPtrFactory<MessageLoop> weak_factory_; 3973 base::WeakPtrFactory<MessageLoop> weak_factory_;
3803 }; 3974 };
3804 3975
3976 // Must run on IO thread to set up ThreadCheckers correctly.
3977 static net::CookieMonster* GetCookieMonsterFromIOThread(
3978 net::URLRequestContextGetter* getter) {
3979 return getter->GetURLRequestContext()->cookie_store()->GetCookieMonster();
3980 }
3981
3805 // Verifies extension state is removed upon uninstall. 3982 // Verifies extension state is removed upon uninstall.
3806 TEST_F(ExtensionServiceTest, ClearExtensionData) { 3983 TEST_F(ExtensionServiceTest, ClearExtensionData) {
3807 InitializeEmptyExtensionService(); 3984 InitializeEmptyExtensionService();
3808 ExtensionCookieCallback callback; 3985 ExtensionCookieCallback callback;
3809 3986
3810 // Load a test extension. 3987 // Load a test extension.
3811 base::FilePath path = data_dir_; 3988 base::FilePath path = data_dir_;
3812 path = path.AppendASCII("good.crx"); 3989 path = path.AppendASCII("good.crx");
3813 const Extension* extension = InstallCRX(path, INSTALL_NEW); 3990 const Extension* extension = InstallCRX(path, INSTALL_NEW);
3814 ASSERT_TRUE(extension); 3991 ASSERT_TRUE(extension);
3815 GURL ext_url(extension->url()); 3992 GURL ext_url(extension->url());
3816 string16 origin_id = 3993 string16 origin_id =
3817 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); 3994 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url);
3818 3995
3819 // Set a cookie for the extension. 3996 // Set a cookie for the extension.
3820 net::CookieMonster* cookie_monster = 3997 net::CookieMonster* cookie_monster = PostTaskAndWaitForResult(
3821 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 3998 BrowserThread::IO, FROM_HERE,
3822 cookie_store()->GetCookieMonster(); 3999 base::Bind(&GetCookieMonsterFromIOThread,
4000 make_scoped_refptr(
4001 profile_->GetRequestContextForExtensions())));
3823 ASSERT_TRUE(cookie_monster); 4002 ASSERT_TRUE(cookie_monster);
4003
3824 net::CookieOptions options; 4004 net::CookieOptions options;
3825 cookie_monster->SetCookieWithOptionsAsync( 4005 cookie_monster->SetCookieWithOptionsAsync(
3826 ext_url, "dummy=value", options, 4006 ext_url, "dummy=value", options,
3827 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4007 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
3828 base::Unretained(&callback))); 4008 base::Unretained(&callback)));
3829 loop_.RunUntilIdle(); 4009 MessageLoop::current()->RunUntilIdle();
3830 EXPECT_TRUE(callback.result_); 4010 EXPECT_TRUE(callback.result_);
3831 4011
3832 cookie_monster->GetAllCookiesForURLAsync( 4012 cookie_monster->GetAllCookiesForURLAsync(
3833 ext_url, 4013 ext_url,
3834 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4014 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
3835 base::Unretained(&callback))); 4015 base::Unretained(&callback)));
3836 loop_.RunUntilIdle(); 4016 MessageLoop::current()->RunUntilIdle();
3837 EXPECT_EQ(1U, callback.list_.size()); 4017 EXPECT_EQ(1U, callback.list_.size());
3838 4018
3839 // Open a database. 4019 // Open a database.
3840 webkit_database::DatabaseTracker* db_tracker = 4020 webkit_database::DatabaseTracker* db_tracker =
3841 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 4021 BrowserContext::GetDefaultStoragePartition(profile_.get())->
3842 GetDatabaseTracker(); 4022 GetDatabaseTracker();
3843 string16 db_name = UTF8ToUTF16("db"); 4023 string16 db_name = UTF8ToUTF16("db");
3844 string16 description = UTF8ToUTF16("db_description"); 4024 string16 description = UTF8ToUTF16("db_description");
3845 int64 size; 4025 int64 size;
3846 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 4026 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 EXPECT_TRUE(extension->HasAPIPermission( 4104 EXPECT_TRUE(extension->HasAPIPermission(
3925 APIPermission::kUnlimitedStorage)); 4105 APIPermission::kUnlimitedStorage));
3926 EXPECT_TRUE(extension->web_extent().MatchesURL( 4106 EXPECT_TRUE(extension->web_extent().MatchesURL(
3927 extension->GetFullLaunchURL())); 4107 extension->GetFullLaunchURL()));
3928 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 4108 const GURL origin2(extension->GetFullLaunchURL().GetOrigin());
3929 EXPECT_EQ(origin1, origin2); 4109 EXPECT_EQ(origin1, origin2);
3930 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 4110 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
3931 IsStorageUnlimited(origin2)); 4111 IsStorageUnlimited(origin2));
3932 4112
3933 // Set a cookie for the extension. 4113 // Set a cookie for the extension.
3934 net::CookieMonster* cookie_monster = 4114 net::CookieMonster* cookie_monster = PostTaskAndWaitForResult(
3935 profile_->GetRequestContext()->GetURLRequestContext()-> 4115 BrowserThread::IO, FROM_HERE,
3936 cookie_store()->GetCookieMonster(); 4116 base::Bind(&GetCookieMonsterFromIOThread,
4117 make_scoped_refptr(profile_->GetRequestContext())));
3937 ASSERT_TRUE(cookie_monster); 4118 ASSERT_TRUE(cookie_monster);
3938 net::CookieOptions options; 4119 net::CookieOptions options;
3939 cookie_monster->SetCookieWithOptionsAsync( 4120 cookie_monster->SetCookieWithOptionsAsync(
3940 origin1, "dummy=value", options, 4121 origin1, "dummy=value", options,
3941 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 4122 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
3942 base::Unretained(&callback))); 4123 base::Unretained(&callback)));
3943 loop_.RunUntilIdle(); 4124 loop_.RunUntilIdle();
3944 EXPECT_TRUE(callback.result_); 4125 EXPECT_TRUE(callback.result_);
3945 4126
3946 cookie_monster->GetAllCookiesForURLAsync( 4127 cookie_monster->GetAllCookiesForURLAsync(
(...skipping 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after
5901 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6082 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5902 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 6083 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5903 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 6084 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5904 6085
5905 ExtensionPrefs* prefs = service_->extension_prefs(); 6086 ExtensionPrefs* prefs = service_->extension_prefs();
5906 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 6087 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5907 Extension::DISABLE_SIDELOAD_WIPEOUT); 6088 Extension::DISABLE_SIDELOAD_WIPEOUT);
5908 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 6089 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5909 Extension::DISABLE_SIDELOAD_WIPEOUT); 6090 Extension::DISABLE_SIDELOAD_WIPEOUT);
5910 } 6091 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/extensions/user_script_listener_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698