OLD | NEW |
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 using content::BrowserContext; | 94 using content::BrowserContext; |
95 using content::BrowserThread; | 95 using content::BrowserThread; |
96 using content::DOMStorageContext; | 96 using content::DOMStorageContext; |
97 using content::IndexedDBContext; | 97 using content::IndexedDBContext; |
98 using content::PluginService; | 98 using content::PluginService; |
99 using extensions::APIPermission; | 99 using extensions::APIPermission; |
100 using extensions::APIPermissionSet; | 100 using extensions::APIPermissionSet; |
101 using extensions::Extension; | 101 using extensions::Extension; |
102 using extensions::ExtensionCreator; | 102 using extensions::ExtensionCreator; |
103 using extensions::ExtensionPrefs; | 103 using extensions::ExtensionPrefs; |
| 104 using extensions::ExtensionSystem; |
104 using extensions::PermissionSet; | 105 using extensions::PermissionSet; |
105 | 106 |
106 namespace keys = extension_manifest_keys; | 107 namespace keys = extension_manifest_keys; |
107 | 108 |
108 namespace { | 109 namespace { |
109 | 110 |
110 // Extension ids used during testing. | 111 // Extension ids used during testing. |
111 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 112 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
112 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; | 113 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
113 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 114 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 chrome::RegisterUserPrefs(prefs); | 416 chrome::RegisterUserPrefs(prefs); |
416 profile->SetPrefService(prefs); | 417 profile->SetPrefService(prefs); |
417 | 418 |
418 #if defined(ENABLE_THEMES) | 419 #if defined(ENABLE_THEMES) |
419 ThemeServiceFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); | 420 ThemeServiceFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); |
420 #endif | 421 #endif |
421 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); | 422 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); |
422 | 423 |
423 profile_.reset(profile); | 424 profile_.reset(profile); |
424 | 425 |
425 service_ = static_cast<TestExtensionSystem*>( | 426 service_ = static_cast<extensions::TestExtensionSystem*>( |
426 ExtensionSystem::Get(profile))->CreateExtensionService( | 427 ExtensionSystem::Get(profile))->CreateExtensionService( |
427 CommandLine::ForCurrentProcess(), | 428 CommandLine::ForCurrentProcess(), |
428 extensions_install_dir, | 429 extensions_install_dir, |
429 autoupdate_enabled); | 430 autoupdate_enabled); |
430 service_->set_extensions_enabled(true); | 431 service_->set_extensions_enabled(true); |
431 service_->set_show_extensions_prompts(false); | 432 service_->set_show_extensions_prompts(false); |
432 | 433 |
433 management_policy_ = static_cast<TestExtensionSystem*>( | 434 management_policy_ = static_cast<extensions::TestExtensionSystem*>( |
434 ExtensionSystem::Get(profile))->CreateManagementPolicy(); | 435 ExtensionSystem::Get(profile))->CreateManagementPolicy(); |
435 | 436 |
436 // When we start up, we want to make sure there is no external provider, | 437 // When we start up, we want to make sure there is no external provider, |
437 // since the ExtensionService on Windows will use the Registry as a default | 438 // since the ExtensionService on Windows will use the Registry as a default |
438 // provider and if there is something already registered there then it will | 439 // provider and if there is something already registered there then it will |
439 // interfere with the tests. Those tests that need an external provider | 440 // interfere with the tests. Those tests that need an external provider |
440 // will register one specifically. | 441 // will register one specifically. |
441 service_->ClearProvidersForTesting(); | 442 service_->ClearProvidersForTesting(); |
442 | 443 |
443 expected_extensions_count_ = 0; | 444 expected_extensions_count_ = 0; |
(...skipping 14 matching lines...) Expand all Loading... |
458 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 459 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
459 | 460 |
460 InitializeExtensionService(temp_prefs, extensions_install_dir_, false); | 461 InitializeExtensionService(temp_prefs, extensions_install_dir_, false); |
461 } | 462 } |
462 | 463 |
463 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { | 464 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
464 InitializeExtensionServiceHelper(false); | 465 InitializeExtensionServiceHelper(false); |
465 } | 466 } |
466 | 467 |
467 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { | 468 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
468 static_cast<TestExtensionSystem*>( | 469 static_cast<extensions::TestExtensionSystem*>( |
469 ExtensionSystem::Get(profile_.get()))-> | 470 ExtensionSystem::Get(profile_.get()))-> |
470 CreateExtensionProcessManager(); | 471 CreateExtensionProcessManager(); |
471 } | 472 } |
472 | 473 |
473 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { | 474 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
474 InitializeExtensionServiceHelper(true); | 475 InitializeExtensionServiceHelper(true); |
475 service_->updater()->Start(); | 476 service_->updater()->Start(); |
476 } | 477 } |
477 | 478 |
478 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( | 479 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( |
(...skipping 3596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4075 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); | 4076 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); |
4076 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); | 4077 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); |
4077 scoped_ptr<CommandLine> command_line; | 4078 scoped_ptr<CommandLine> command_line; |
4078 FilePath install_dir = profile->GetPath() | 4079 FilePath install_dir = profile->GetPath() |
4079 .AppendASCII(ExtensionService::kInstallDirectoryName); | 4080 .AppendASCII(ExtensionService::kInstallDirectoryName); |
4080 webkit::npapi::MockPluginList plugin_list(NULL, 0); | 4081 webkit::npapi::MockPluginList plugin_list(NULL, 0); |
4081 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); | 4082 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); |
4082 | 4083 |
4083 // By default, we are enabled. | 4084 // By default, we are enabled. |
4084 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 4085 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
4085 ExtensionService* service = static_cast<TestExtensionSystem*>( | 4086 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
4086 ExtensionSystem::Get(profile.get()))-> | 4087 ExtensionSystem::Get(profile.get()))-> |
4087 CreateExtensionService( | 4088 CreateExtensionService( |
4088 command_line.get(), | 4089 command_line.get(), |
4089 install_dir, | 4090 install_dir, |
4090 false); | 4091 false); |
4091 EXPECT_TRUE(service->extensions_enabled()); | 4092 EXPECT_TRUE(service->extensions_enabled()); |
4092 service->Init(); | 4093 service->Init(); |
4093 loop.RunAllPending(); | 4094 loop.RunAllPending(); |
4094 EXPECT_TRUE(recorder.ready()); | 4095 EXPECT_TRUE(recorder.ready()); |
4095 | 4096 |
4096 // If either the command line or pref is set, we are disabled. | 4097 // If either the command line or pref is set, we are disabled. |
4097 recorder.set_ready(false); | 4098 recorder.set_ready(false); |
4098 profile.reset(new TestingProfile()); | 4099 profile.reset(new TestingProfile()); |
4099 command_line->AppendSwitch(switches::kDisableExtensions); | 4100 command_line->AppendSwitch(switches::kDisableExtensions); |
4100 service = static_cast<TestExtensionSystem*>( | 4101 service = static_cast<extensions::TestExtensionSystem*>( |
4101 ExtensionSystem::Get(profile.get()))-> | 4102 ExtensionSystem::Get(profile.get()))-> |
4102 CreateExtensionService( | 4103 CreateExtensionService( |
4103 command_line.get(), | 4104 command_line.get(), |
4104 install_dir, | 4105 install_dir, |
4105 false); | 4106 false); |
4106 EXPECT_FALSE(service->extensions_enabled()); | 4107 EXPECT_FALSE(service->extensions_enabled()); |
4107 service->Init(); | 4108 service->Init(); |
4108 loop.RunAllPending(); | 4109 loop.RunAllPending(); |
4109 EXPECT_TRUE(recorder.ready()); | 4110 EXPECT_TRUE(recorder.ready()); |
4110 | 4111 |
4111 recorder.set_ready(false); | 4112 recorder.set_ready(false); |
4112 profile.reset(new TestingProfile()); | 4113 profile.reset(new TestingProfile()); |
4113 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 4114 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
4114 service = static_cast<TestExtensionSystem*>( | 4115 service = static_cast<extensions::TestExtensionSystem*>( |
4115 ExtensionSystem::Get(profile.get()))-> | 4116 ExtensionSystem::Get(profile.get()))-> |
4116 CreateExtensionService( | 4117 CreateExtensionService( |
4117 command_line.get(), | 4118 command_line.get(), |
4118 install_dir, | 4119 install_dir, |
4119 false); | 4120 false); |
4120 EXPECT_FALSE(service->extensions_enabled()); | 4121 EXPECT_FALSE(service->extensions_enabled()); |
4121 service->Init(); | 4122 service->Init(); |
4122 loop.RunAllPending(); | 4123 loop.RunAllPending(); |
4123 EXPECT_TRUE(recorder.ready()); | 4124 EXPECT_TRUE(recorder.ready()); |
4124 | 4125 |
4125 recorder.set_ready(false); | 4126 recorder.set_ready(false); |
4126 profile.reset(new TestingProfile()); | 4127 profile.reset(new TestingProfile()); |
4127 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 4128 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
4128 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 4129 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
4129 service = static_cast<TestExtensionSystem*>( | 4130 service = static_cast<extensions::TestExtensionSystem*>( |
4130 ExtensionSystem::Get(profile.get()))-> | 4131 ExtensionSystem::Get(profile.get()))-> |
4131 CreateExtensionService( | 4132 CreateExtensionService( |
4132 command_line.get(), | 4133 command_line.get(), |
4133 install_dir, | 4134 install_dir, |
4134 false); | 4135 false); |
4135 EXPECT_FALSE(service->extensions_enabled()); | 4136 EXPECT_FALSE(service->extensions_enabled()); |
4136 service->Init(); | 4137 service->Init(); |
4137 loop.RunAllPending(); | 4138 loop.RunAllPending(); |
4138 EXPECT_TRUE(recorder.ready()); | 4139 EXPECT_TRUE(recorder.ready()); |
4139 | 4140 |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5246 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5247 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
5247 data_dir_.AppendASCII("hosted_app.crx")); | 5248 data_dir_.AppendASCII("hosted_app.crx")); |
5248 | 5249 |
5249 service_->CheckForExternalUpdates(); | 5250 service_->CheckForExternalUpdates(); |
5250 loop_.RunAllPending(); | 5251 loop_.RunAllPending(); |
5251 | 5252 |
5252 ASSERT_TRUE(service_->PopulateExtensionGlobalError( | 5253 ASSERT_TRUE(service_->PopulateExtensionGlobalError( |
5253 extension_global_error.get())); | 5254 extension_global_error.get())); |
5254 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); | 5255 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); |
5255 } | 5256 } |
OLD | NEW |