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

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

Issue 9369013: Take extensions out of Profile into a profile-keyed service, ExtensionSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 17 matching lines...) Expand all
28 #include "base/version.h" 28 #include "base/version.h"
29 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/extensions/component_loader.h" 30 #include "chrome/browser/extensions/component_loader.h"
31 #include "chrome/browser/extensions/crx_installer.h" 31 #include "chrome/browser/extensions/crx_installer.h"
32 #include "chrome/browser/extensions/extension_creator.h" 32 #include "chrome/browser/extensions/extension_creator.h"
33 #include "chrome/browser/extensions/extension_error_reporter.h" 33 #include "chrome/browser/extensions/extension_error_reporter.h"
34 #include "chrome/browser/extensions/extension_global_error.h" 34 #include "chrome/browser/extensions/extension_global_error.h"
35 #include "chrome/browser/extensions/extension_service.h" 35 #include "chrome/browser/extensions/extension_service.h"
36 #include "chrome/browser/extensions/extension_special_storage_policy.h" 36 #include "chrome/browser/extensions/extension_special_storage_policy.h"
37 #include "chrome/browser/extensions/extension_sync_data.h" 37 #include "chrome/browser/extensions/extension_sync_data.h"
38 #include "chrome/browser/extensions/extension_system.h"
39 #include "chrome/browser/extensions/extension_system_factory.h"
38 #include "chrome/browser/extensions/extension_updater.h" 40 #include "chrome/browser/extensions/extension_updater.h"
39 #include "chrome/browser/extensions/external_extension_provider_impl.h" 41 #include "chrome/browser/extensions/external_extension_provider_impl.h"
40 #include "chrome/browser/extensions/external_extension_provider_interface.h" 42 #include "chrome/browser/extensions/external_extension_provider_interface.h"
41 #include "chrome/browser/extensions/external_pref_extension_loader.h" 43 #include "chrome/browser/extensions/external_pref_extension_loader.h"
42 #include "chrome/browser/extensions/extension_sorting.h" 44 #include "chrome/browser/extensions/extension_sorting.h"
43 #include "chrome/browser/extensions/installed_loader.h" 45 #include "chrome/browser/extensions/installed_loader.h"
44 #include "chrome/browser/extensions/pack_extension_job.cc" 46 #include "chrome/browser/extensions/pack_extension_job.cc"
45 #include "chrome/browser/extensions/pending_extension_info.h" 47 #include "chrome/browser/extensions/pending_extension_info.h"
46 #include "chrome/browser/extensions/pending_extension_manager.h" 48 #include "chrome/browser/extensions/pending_extension_manager.h"
49 #include "chrome/browser/extensions/test_extension_system.h"
47 #include "chrome/browser/extensions/unpacked_installer.h" 50 #include "chrome/browser/extensions/unpacked_installer.h"
48 #include "chrome/browser/plugin_prefs_factory.h" 51 #include "chrome/browser/plugin_prefs_factory.h"
49 #include "chrome/browser/prefs/browser_prefs.h" 52 #include "chrome/browser/prefs/browser_prefs.h"
50 #include "chrome/browser/prefs/pref_service_mock_builder.h" 53 #include "chrome/browser/prefs/pref_service_mock_builder.h"
51 #include "chrome/browser/prefs/scoped_user_pref_update.h" 54 #include "chrome/browser/prefs/scoped_user_pref_update.h"
52 #include "chrome/browser/sync/protocol/app_specifics.pb.h" 55 #include "chrome/browser/sync/protocol/app_specifics.pb.h"
53 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 56 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
57 #include "chrome/common/chrome_constants.h"
54 #include "chrome/common/chrome_notification_types.h" 58 #include "chrome/common/chrome_notification_types.h"
55 #include "chrome/common/chrome_paths.h" 59 #include "chrome/common/chrome_paths.h"
56 #include "chrome/common/chrome_switches.h" 60 #include "chrome/common/chrome_switches.h"
57 #include "chrome/common/extensions/extension.h" 61 #include "chrome/common/extensions/extension.h"
58 #include "chrome/common/extensions/extension_constants.h" 62 #include "chrome/common/extensions/extension_constants.h"
59 #include "chrome/common/extensions/extension_resource.h" 63 #include "chrome/common/extensions/extension_resource.h"
60 #include "chrome/common/extensions/url_pattern.h" 64 #include "chrome/common/extensions/url_pattern.h"
61 #include "chrome/common/pref_names.h" 65 #include "chrome/common/pref_names.h"
62 #include "chrome/common/string_ordinal.h" 66 #include "chrome/common/string_ordinal.h"
63 #include "chrome/common/url_constants.h" 67 #include "chrome/common/url_constants.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 367
364 private: 368 private:
365 int ids_found_; 369 int ids_found_;
366 FilePath fake_base_path_; 370 FilePath fake_base_path_;
367 scoped_ptr<ExternalExtensionProviderImpl> provider_; 371 scoped_ptr<ExternalExtensionProviderImpl> provider_;
368 scoped_ptr<DictionaryValue> prefs_; 372 scoped_ptr<DictionaryValue> prefs_;
369 373
370 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 374 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
371 }; 375 };
372 376
373 class ExtensionTestingProfile : public TestingProfile {
374 public:
375 ExtensionTestingProfile() : service_(NULL) {
376 }
377
378 void set_extensions_service(ExtensionService* service) {
379 service_ = service;
380 }
381 virtual ExtensionService* GetExtensionService() { return service_; }
382
383 private:
384 ExtensionService* service_;
385 };
386
387 // Our message loop may be used in tests which require it to be an IO loop. 377 // Our message loop may be used in tests which require it to be an IO loop.
388 ExtensionServiceTestBase::ExtensionServiceTestBase() 378 ExtensionServiceTestBase::ExtensionServiceTestBase()
389 : loop_(MessageLoop::TYPE_IO), 379 : loop_(MessageLoop::TYPE_IO),
390 service_(NULL), 380 service_(NULL),
391 expected_extensions_count_(0), 381 expected_extensions_count_(0),
392 ui_thread_(BrowserThread::UI, &loop_), 382 ui_thread_(BrowserThread::UI, &loop_),
393 db_thread_(BrowserThread::DB, &loop_), 383 db_thread_(BrowserThread::DB, &loop_),
394 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), 384 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_),
395 file_thread_(BrowserThread::FILE, &loop_), 385 file_thread_(BrowserThread::FILE, &loop_),
396 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), 386 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_),
(...skipping 12 matching lines...) Expand all
409 // (they are used in the destruction process). 399 // (they are used in the destruction process).
410 service_ = NULL; 400 service_ = NULL;
411 MessageLoop::current()->RunAllPending(); 401 MessageLoop::current()->RunAllPending();
412 profile_.reset(NULL); 402 profile_.reset(NULL);
413 MessageLoop::current()->RunAllPending(); 403 MessageLoop::current()->RunAllPending();
414 } 404 }
415 405
416 void ExtensionServiceTestBase::InitializeExtensionService( 406 void ExtensionServiceTestBase::InitializeExtensionService(
417 const FilePath& pref_file, const FilePath& extensions_install_dir, 407 const FilePath& pref_file, const FilePath& extensions_install_dir,
418 bool autoupdate_enabled) { 408 bool autoupdate_enabled) {
419 ExtensionTestingProfile* profile = new ExtensionTestingProfile(); 409 TestingProfile* profile = new TestingProfile();
420 // Create a PrefService that only contains user defined preference values. 410 // Create a PrefService that only contains user defined preference values.
421 PrefService* prefs = 411 PrefService* prefs =
422 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create(); 412 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create();
423 Profile::RegisterUserPrefs(prefs); 413 Profile::RegisterUserPrefs(prefs);
424 browser::RegisterUserPrefs(prefs); 414 browser::RegisterUserPrefs(prefs);
425 profile->SetPrefService(prefs); 415 profile->SetPrefService(prefs);
426 416
427 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); 417 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs);
428 418
429 profile_.reset(profile); 419 profile_.reset(profile);
430 420
431 service_ = profile->CreateExtensionService( 421 service_ = static_cast<TestExtensionSystem*>(
432 CommandLine::ForCurrentProcess(), 422 ExtensionSystemFactory::GetForProfile(profile))->CreateExtensionService(
433 extensions_install_dir, 423 CommandLine::ForCurrentProcess(),
434 autoupdate_enabled); 424 extensions_install_dir,
425 autoupdate_enabled);
435 service_->set_extensions_enabled(true); 426 service_->set_extensions_enabled(true);
436 service_->set_show_extensions_prompts(false); 427 service_->set_show_extensions_prompts(false);
437 profile->set_extensions_service(service_);
438 428
439 // When we start up, we want to make sure there is no external provider, 429 // When we start up, we want to make sure there is no external provider,
440 // since the ExtensionService on Windows will use the Registry as a default 430 // since the ExtensionService on Windows will use the Registry as a default
441 // provider and if there is something already registered there then it will 431 // provider and if there is something already registered there then it will
442 // interfere with the tests. Those tests that need an external provider 432 // interfere with the tests. Those tests that need an external provider
443 // will register one specifically. 433 // will register one specifically.
444 service_->ClearProvidersForTesting(); 434 service_->ClearProvidersForTesting();
445 435
446 expected_extensions_count_ = 0; 436 expected_extensions_count_ = 0;
447 } 437 }
(...skipping 13 matching lines...) Expand all
461 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); 451 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true);
462 452
463 InitializeExtensionService(temp_prefs, extensions_install_dir_, false); 453 InitializeExtensionService(temp_prefs, extensions_install_dir_, false);
464 } 454 }
465 455
466 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { 456 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
467 InitializeExtensionServiceHelper(false); 457 InitializeExtensionServiceHelper(false);
468 } 458 }
469 459
470 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { 460 void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
471 profile_->CreateExtensionProcessManager(); 461 static_cast<TestExtensionSystem*>(
462 ExtensionSystemFactory::GetForProfile(profile_.get()))->
463 CreateExtensionProcessManager();
472 } 464 }
473 465
474 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 466 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
475 InitializeExtensionServiceHelper(true); 467 InitializeExtensionServiceHelper(true);
476 service_->updater()->Start(); 468 service_->updater()->Start();
477 } 469 }
478 470
479 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( 471 void ExtensionServiceTestBase::InitializeExtensionServiceHelper(
480 bool autoupdate_enabled) { 472 bool autoupdate_enabled) {
481 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 473 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
482 FilePath path_ = temp_dir_.path(); 474 FilePath path_ = temp_dir_.path();
483 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 475 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
484 file_util::Delete(path_, true); 476 file_util::Delete(path_, true);
485 file_util::CreateDirectory(path_); 477 file_util::CreateDirectory(path_);
486 FilePath prefs_filename = path_ 478 FilePath prefs_filename = path_
487 .Append(FILE_PATH_LITERAL("TestPreferences")); 479 .Append(FILE_PATH_LITERAL("TestPreferences"));
488 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); 480 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions"));
489 file_util::Delete(extensions_install_dir_, true); 481 file_util::Delete(extensions_install_dir_, true);
490 file_util::CreateDirectory(extensions_install_dir_); 482 file_util::CreateDirectory(extensions_install_dir_);
491 483
492 InitializeExtensionService(prefs_filename, extensions_install_dir_, 484 InitializeExtensionService(prefs_filename, extensions_install_dir_,
493 autoupdate_enabled); 485 autoupdate_enabled);
494 } 486 }
495 487
496 void ExtensionServiceTestBase::InitializeRequestContext() { 488 void ExtensionServiceTestBase::InitializeRequestContext() {
497 ASSERT_TRUE(profile_.get()); 489 ASSERT_TRUE(profile_.get());
498 ExtensionTestingProfile* profile = 490 TestingProfile* profile =
499 static_cast<ExtensionTestingProfile*>(profile_.get()); 491 static_cast<TestingProfile*>(profile_.get());
500 profile->CreateRequestContext(); 492 profile->CreateRequestContext();
501 } 493 }
502 494
503 // static 495 // static
504 void ExtensionServiceTestBase::SetUpTestCase() { 496 void ExtensionServiceTestBase::SetUpTestCase() {
505 ExtensionErrorReporter::Init(false); // no noisy errors 497 ExtensionErrorReporter::Init(false); // no noisy errors
506 } 498 }
507 499
508 void ExtensionServiceTestBase::SetUp() { 500 void ExtensionServiceTestBase::SetUp() {
509 ExtensionErrorReporter::GetInstance()->ClearErrors(); 501 ExtensionErrorReporter::GetInstance()->ClearErrors();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 int expected_installed_extension_count = 728 int expected_installed_extension_count =
737 (expected_state >= INSTALLED) ? 1 : 0; 729 (expected_state >= INSTALLED) ? 1 : 0;
738 int expected_enabled_extension_count = 730 int expected_enabled_extension_count =
739 (expected_state >= ENABLED) ? 1 : 0; 731 (expected_state >= ENABLED) ? 1 : 0;
740 EXPECT_EQ(expected_installed_extension_count, 732 EXPECT_EQ(expected_installed_extension_count,
741 installed_extension_count); 733 installed_extension_count);
742 EXPECT_EQ(expected_enabled_extension_count, 734 EXPECT_EQ(expected_enabled_extension_count,
743 enabled_extension_count); 735 enabled_extension_count);
744 } 736 }
745 737
746 // Update() should delete the temporary input file. 738 // Update() should the temporary input file.
747 EXPECT_FALSE(file_util::PathExists(path)); 739 EXPECT_FALSE(file_util::PathExists(path));
748 } 740 }
749 741
750 void TerminateExtension(const std::string& id) { 742 void TerminateExtension(const std::string& id) {
751 const Extension* extension = service_->GetInstalledExtension(id); 743 const Extension* extension = service_->GetInstalledExtension(id);
752 if (!extension) { 744 if (!extension) {
753 ADD_FAILURE(); 745 ADD_FAILURE();
754 return; 746 return;
755 } 747 }
756 service_->TrackTerminatedExtensionForTest(extension); 748 service_->TrackTerminatedExtensionForTest(extension);
(...skipping 3093 matching lines...) Expand 10 before | Expand all | Expand 10 after
3850 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); 3842 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop);
3851 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); 3843 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop);
3852 scoped_ptr<CommandLine> command_line; 3844 scoped_ptr<CommandLine> command_line;
3853 FilePath install_dir = profile->GetPath() 3845 FilePath install_dir = profile->GetPath()
3854 .AppendASCII(ExtensionService::kInstallDirectoryName); 3846 .AppendASCII(ExtensionService::kInstallDirectoryName);
3855 webkit::npapi::MockPluginList plugin_list(NULL, 0); 3847 webkit::npapi::MockPluginList plugin_list(NULL, 0);
3856 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); 3848 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list);
3857 3849
3858 // By default, we are enabled. 3850 // By default, we are enabled.
3859 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3851 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3860 // Owned by |profile|. 3852 ExtensionService* service = static_cast<TestExtensionSystem*>(
3861 ExtensionService* service = 3853 ExtensionSystemFactory::GetForProfile(profile.get()))->
3862 profile->CreateExtensionService(command_line.get(), 3854 CreateExtensionService(
3863 install_dir, 3855 command_line.get(),
3864 false); 3856 install_dir,
3857 false);
3865 EXPECT_TRUE(service->extensions_enabled()); 3858 EXPECT_TRUE(service->extensions_enabled());
3866 service->Init(); 3859 service->Init();
3867 loop.RunAllPending(); 3860 loop.RunAllPending();
3868 EXPECT_TRUE(recorder.ready()); 3861 EXPECT_TRUE(recorder.ready());
3869 3862
3870 // If either the command line or pref is set, we are disabled. 3863 // If either the command line or pref is set, we are disabled.
3871 recorder.set_ready(false); 3864 recorder.set_ready(false);
3872 profile.reset(new TestingProfile()); 3865 profile.reset(new TestingProfile());
3873 command_line->AppendSwitch(switches::kDisableExtensions); 3866 command_line->AppendSwitch(switches::kDisableExtensions);
3874 service = profile->CreateExtensionService(command_line.get(), 3867 service = static_cast<TestExtensionSystem*>(
3875 install_dir, 3868 ExtensionSystemFactory::GetForProfile(profile.get()))->
3876 false); 3869 CreateExtensionService(
3870 command_line.get(),
3871 install_dir,
3872 false);
3877 EXPECT_FALSE(service->extensions_enabled()); 3873 EXPECT_FALSE(service->extensions_enabled());
3878 service->Init(); 3874 service->Init();
3879 loop.RunAllPending(); 3875 loop.RunAllPending();
3880 EXPECT_TRUE(recorder.ready()); 3876 EXPECT_TRUE(recorder.ready());
3881 3877
3882 recorder.set_ready(false); 3878 recorder.set_ready(false);
3883 profile.reset(new TestingProfile()); 3879 profile.reset(new TestingProfile());
3884 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3880 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3885 service = profile->CreateExtensionService(command_line.get(), 3881 service = static_cast<TestExtensionSystem*>(
3886 install_dir, 3882 ExtensionSystemFactory::GetForProfile(profile.get()))->
3887 false); 3883 CreateExtensionService(
3884 command_line.get(),
3885 install_dir,
3886 false);
3888 EXPECT_FALSE(service->extensions_enabled()); 3887 EXPECT_FALSE(service->extensions_enabled());
3889 service->Init(); 3888 service->Init();
3890 loop.RunAllPending(); 3889 loop.RunAllPending();
3891 EXPECT_TRUE(recorder.ready()); 3890 EXPECT_TRUE(recorder.ready());
3892 3891
3893 recorder.set_ready(false); 3892 recorder.set_ready(false);
3894 profile.reset(new TestingProfile()); 3893 profile.reset(new TestingProfile());
3895 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 3894 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
3896 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 3895 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
3897 service = profile->CreateExtensionService(command_line.get(), 3896 service = static_cast<TestExtensionSystem*>(
3898 install_dir, 3897 ExtensionSystemFactory::GetForProfile(profile.get()))->
3899 false); 3898 CreateExtensionService(
3899 command_line.get(),
3900 install_dir,
3901 false);
3900 EXPECT_FALSE(service->extensions_enabled()); 3902 EXPECT_FALSE(service->extensions_enabled());
3901 service->Init(); 3903 service->Init();
3902 loop.RunAllPending(); 3904 loop.RunAllPending();
3903 EXPECT_TRUE(recorder.ready()); 3905 EXPECT_TRUE(recorder.ready());
3904 3906
3905 // Explicitly delete all the resources used in this test. 3907 // Explicitly delete all the resources used in this test.
3906 profile.reset(); 3908 profile.reset();
3907 service = NULL; 3909 service = NULL;
3908 } 3910 }
3909 3911
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
4860 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 4862 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
4861 data_dir_.AppendASCII("hosted_app.crx")); 4863 data_dir_.AppendASCII("hosted_app.crx"));
4862 4864
4863 service_->CheckForExternalUpdates(); 4865 service_->CheckForExternalUpdates();
4864 loop_.RunAllPending(); 4866 loop_.RunAllPending();
4865 4867
4866 ASSERT_TRUE(service_->PopulateExtensionGlobalError( 4868 ASSERT_TRUE(service_->PopulateExtensionGlobalError(
4867 extension_global_error.get())); 4869 extension_global_error.get()));
4868 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); 4870 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size());
4869 } 4871 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/extensions/extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698