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

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

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