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

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

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