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

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

Issue 10908088: Cleanup: Constify some ProfileKeyedBaseFactory methods and all overrides. Remove ProfileKeyedBaseFa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // VisitRegisteredExtension(), which must be a const method to inherit 238 // VisitRegisteredExtension(), which must be a const method to inherit
239 // from the class being mocked. 239 // from the class being mocked.
240 mutable int visit_count_; 240 mutable int visit_count_;
241 241
242 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); 242 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider);
243 }; 243 };
244 244
245 class MockProviderVisitor 245 class MockProviderVisitor
246 : public extensions::ExternalProviderInterface::VisitorInterface { 246 : public extensions::ExternalProviderInterface::VisitorInterface {
247 public: 247 public:
248
249 // The provider will return |fake_base_path| from 248 // The provider will return |fake_base_path| from
250 // GetBaseCrxFilePath(). User can test the behavior with 249 // GetBaseCrxFilePath(). User can test the behavior with
251 // and without an empty path using this parameter. 250 // and without an empty path using this parameter.
252 explicit MockProviderVisitor(FilePath fake_base_path) 251 explicit MockProviderVisitor(FilePath fake_base_path)
253 : ids_found_(0), 252 : ids_found_(0),
254 fake_base_path_(fake_base_path), 253 fake_base_path_(fake_base_path),
255 expected_creation_flags_(Extension::NO_FLAGS) { 254 expected_creation_flags_(Extension::NO_FLAGS) {
256 } 255 }
257 256
258 MockProviderVisitor(FilePath fake_base_path, int expected_creation_flags) 257 MockProviderVisitor(FilePath fake_base_path, int expected_creation_flags)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // Drop our reference to ExtensionService and TestingProfile, so that they 402 // Drop our reference to ExtensionService and TestingProfile, so that they
404 // can be destroyed while BrowserThreads and MessageLoop are still around 403 // can be destroyed while BrowserThreads and MessageLoop are still around
405 // (they are used in the destruction process). 404 // (they are used in the destruction process).
406 service_ = NULL; 405 service_ = NULL;
407 MessageLoop::current()->RunAllPending(); 406 MessageLoop::current()->RunAllPending();
408 profile_.reset(NULL); 407 profile_.reset(NULL);
409 MessageLoop::current()->RunAllPending(); 408 MessageLoop::current()->RunAllPending();
410 } 409 }
411 410
412 void ExtensionServiceTestBase::InitializeExtensionService( 411 void ExtensionServiceTestBase::InitializeExtensionService(
413 const FilePath& pref_file, const FilePath& extensions_install_dir, 412 const FilePath& profile_path,
413 const FilePath& pref_file,
414 const FilePath& extensions_install_dir,
414 bool autoupdate_enabled) { 415 bool autoupdate_enabled) {
415 TestingProfile* profile = new TestingProfile(); 416 TestingProfile::Builder profile_builder;
416 // Create a PrefService that only contains user defined preference values. 417 // Create a PrefService that only contains user defined preference values.
417 PrefService* prefs = 418 scoped_ptr<PrefService> prefs(
418 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create(); 419 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create());
419 Profile::RegisterUserPrefs(prefs); 420 Profile::RegisterUserPrefs(prefs.get());
420 chrome::RegisterUserPrefs(prefs); 421 chrome::RegisterUserPrefs(prefs.get());
421 profile->SetPrefService(prefs); 422 profile_builder.SetPrefService(prefs.Pass());
423 profile_builder.SetPath(profile_path);
424 profile_ = profile_builder.Build();
422 425
423 #if defined(ENABLE_THEMES) 426 #if defined(ENABLE_THEMES)
424 ThemeServiceFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); 427 ThemeServiceFactory::GetInstance()->RegisterUserPrefsOnProfile(
Lei Zhang 2012/09/05 19:16:26 It also occurred to me, we probably don't need the
Elliot Glaysher 2012/09/05 19:35:39 Are you sure? I think this is a different prefserv
428 profile_.get());
425 #endif 429 #endif
426 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); 430 PluginPrefsFactory::GetInstance()->RegisterUserPrefsOnProfile(profile_.get());
427
428 profile_.reset(profile);
429 431
430 service_ = static_cast<extensions::TestExtensionSystem*>( 432 service_ = static_cast<extensions::TestExtensionSystem*>(
431 ExtensionSystem::Get(profile))->CreateExtensionService( 433 ExtensionSystem::Get(profile_.get()))->CreateExtensionService(
432 CommandLine::ForCurrentProcess(), 434 CommandLine::ForCurrentProcess(),
433 extensions_install_dir, 435 extensions_install_dir,
434 autoupdate_enabled); 436 autoupdate_enabled);
435 service_->set_extensions_enabled(true); 437 service_->set_extensions_enabled(true);
436 service_->set_show_extensions_prompts(false); 438 service_->set_show_extensions_prompts(false);
437 439
438 management_policy_ = static_cast<extensions::TestExtensionSystem*>( 440 management_policy_ = static_cast<extensions::TestExtensionSystem*>(
439 ExtensionSystem::Get(profile))->CreateManagementPolicy(); 441 ExtensionSystem::Get(profile_.get()))->CreateManagementPolicy();
440 442
441 // When we start up, we want to make sure there is no external provider, 443 // When we start up, we want to make sure there is no external provider,
442 // since the ExtensionService on Windows will use the Registry as a default 444 // since the ExtensionService on Windows will use the Registry as a default
443 // provider and if there is something already registered there then it will 445 // provider and if there is something already registered there then it will
444 // interfere with the tests. Those tests that need an external provider 446 // interfere with the tests. Those tests that need an external provider
445 // will register one specifically. 447 // will register one specifically.
446 service_->ClearProvidersForTesting(); 448 service_->ClearProvidersForTesting();
447 449
448 expected_extensions_count_ = 0; 450 expected_extensions_count_ = 0;
449 } 451 }
450 452
451 void ExtensionServiceTestBase::InitializeInstalledExtensionService( 453 void ExtensionServiceTestBase::InitializeInstalledExtensionService(
452 const FilePath& prefs_file, const FilePath& source_install_dir) { 454 const FilePath& prefs_file, const FilePath& source_install_dir) {
453 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 455 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
454 FilePath path_ = temp_dir_.path(); 456 FilePath path = temp_dir_.path();
455 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 457 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
456 file_util::Delete(path_, true); 458 file_util::Delete(path, true);
457 file_util::CreateDirectory(path_); 459 file_util::CreateDirectory(path);
458 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); 460 FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences"));
459 file_util::CopyFile(prefs_file, temp_prefs); 461 file_util::CopyFile(prefs_file, temp_prefs);
460 462
461 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); 463 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions"));
462 file_util::Delete(extensions_install_dir_, true); 464 file_util::Delete(extensions_install_dir_, true);
463 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); 465 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true);
464 466
465 InitializeExtensionService(temp_prefs, extensions_install_dir_, false); 467 InitializeExtensionService(path, temp_prefs, extensions_install_dir_, false);
466 } 468 }
467 469
468 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { 470 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
469 InitializeExtensionServiceHelper(false); 471 InitializeExtensionServiceHelper(false);
470 } 472 }
471 473
472 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { 474 void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
473 static_cast<extensions::TestExtensionSystem*>( 475 static_cast<extensions::TestExtensionSystem*>(
474 ExtensionSystem::Get(profile_.get()))-> 476 ExtensionSystem::Get(profile_.get()))->
475 CreateExtensionProcessManager(); 477 CreateExtensionProcessManager();
476 } 478 }
477 479
478 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 480 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
479 InitializeExtensionServiceHelper(true); 481 InitializeExtensionServiceHelper(true);
480 service_->updater()->Start(); 482 service_->updater()->Start();
481 } 483 }
482 484
483 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( 485 void ExtensionServiceTestBase::InitializeExtensionServiceHelper(
484 bool autoupdate_enabled) { 486 bool autoupdate_enabled) {
485 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 487 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
486 FilePath path_ = temp_dir_.path(); 488 FilePath path = temp_dir_.path();
487 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 489 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
488 file_util::Delete(path_, true); 490 file_util::Delete(path, true);
489 file_util::CreateDirectory(path_); 491 file_util::CreateDirectory(path);
490 FilePath prefs_filename = path_ 492 FilePath prefs_filename = path.Append(FILE_PATH_LITERAL("TestPreferences"));
491 .Append(FILE_PATH_LITERAL("TestPreferences")); 493 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions"));
492 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions"));
493 file_util::Delete(extensions_install_dir_, true); 494 file_util::Delete(extensions_install_dir_, true);
494 file_util::CreateDirectory(extensions_install_dir_); 495 file_util::CreateDirectory(extensions_install_dir_);
495 496
496 InitializeExtensionService(prefs_filename, extensions_install_dir_, 497 InitializeExtensionService(path, prefs_filename, extensions_install_dir_,
497 autoupdate_enabled); 498 autoupdate_enabled);
498 } 499 }
499 500
500 void ExtensionServiceTestBase::InitializeRequestContext() { 501 void ExtensionServiceTestBase::InitializeRequestContext() {
501 ASSERT_TRUE(profile_.get()); 502 ASSERT_TRUE(profile_.get());
502 TestingProfile* profile = 503 TestingProfile* profile =
503 static_cast<TestingProfile*>(profile_.get()); 504 static_cast<TestingProfile*>(profile_.get());
504 profile->CreateRequestContext(); 505 profile->CreateRequestContext();
505 } 506 }
506 507
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 ASSERT_TRUE(file_util::PathExists(private_key_path)); 1031 ASSERT_TRUE(file_util::PathExists(private_key_path));
1031 } 1032 }
1032 1033
1033 // The tests are designed so that we never expect to see a packing error. 1034 // The tests are designed so that we never expect to see a packing error.
1034 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, 1035 void PackExtensionTestClient::OnPackFailure(const std::string& error_message,
1035 ExtensionCreator::ErrorType type) { 1036 ExtensionCreator::ErrorType type) {
1036 if (type == ExtensionCreator::kCRXExists) 1037 if (type == ExtensionCreator::kCRXExists)
1037 FAIL() << "Packing should not fail."; 1038 FAIL() << "Packing should not fail.";
1038 else 1039 else
1039 FAIL() << "Existing CRX should have been overwritten."; 1040 FAIL() << "Existing CRX should have been overwritten.";
1040
1041 } 1041 }
1042 1042
1043 // Test loading good extensions from the profile directory. 1043 // Test loading good extensions from the profile directory.
1044 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { 1044 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
1045 PluginService::GetInstance()->Init(); 1045 PluginService::GetInstance()->Init();
1046 1046
1047 // Initialize the test dir with a good Preferences/extensions. 1047 // Initialize the test dir with a good Preferences/extensions.
1048 FilePath source_install_dir = data_dir_ 1048 FilePath source_install_dir = data_dir_
1049 .AppendASCII("good") 1049 .AppendASCII("good")
1050 .AppendASCII("Extensions"); 1050 .AppendASCII("Extensions");
(...skipping 3567 matching lines...) Expand 10 before | Expand all | Expand 10 after
4618 service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), 4618 service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(),
4619 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), 4619 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub),
4620 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 4620 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
4621 4621
4622 service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); 4622 service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id());
4623 { 4623 {
4624 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); 4624 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS);
4625 ASSERT_EQ(list.size(), 3U); 4625 ASSERT_EQ(list.size(), 3U);
4626 4626
4627 extensions::AppSyncData data[kAppCount]; 4627 extensions::AppSyncData data[kAppCount];
4628 for (size_t i = 0; i < kAppCount; ++i) 4628 for (size_t i = 0; i < kAppCount; ++i) {
4629 {
4630 data[i] = extensions::AppSyncData(list[i]); 4629 data[i] = extensions::AppSyncData(list[i]);
4631 } 4630 }
4632 4631
4633 // The sync data is not always in the same order our apps were installed in, 4632 // The sync data is not always in the same order our apps were installed in,
4634 // so we do that sorting here so we can make sure the values are changed as 4633 // so we do that sorting here so we can make sure the values are changed as
4635 // expected. 4634 // expected.
4636 StringOrdinal app_launch_ordinals[kAppCount]; 4635 StringOrdinal app_launch_ordinals[kAppCount];
4637 for (size_t i = 0; i < kAppCount; ++i) { 4636 for (size_t i = 0; i < kAppCount; ++i) {
4638 for (size_t j = 0; j < kAppCount; ++j) { 4637 for (size_t j = 0; j < kAppCount; ++j) {
4639 if (apps[i]->id() == data[j].id()) 4638 if (apps[i]->id() == data[j].id())
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
5425 // This should NOT trigger an alert. 5424 // This should NOT trigger an alert.
5426 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5425 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5427 data_dir_.AppendASCII("hosted_app.crx")); 5426 data_dir_.AppendASCII("hosted_app.crx"));
5428 5427
5429 service_->CheckForExternalUpdates(); 5428 service_->CheckForExternalUpdates();
5430 loop_.RunAllPending(); 5429 loop_.RunAllPending();
5431 5430
5432 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5431 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get()));
5433 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); 5432 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size());
5434 } 5433 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/extensions/extension_system_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698