OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 using extensions::Extension; | 133 using extensions::Extension; |
134 using extensions::ExtensionCreator; | 134 using extensions::ExtensionCreator; |
135 using extensions::ExtensionPrefs; | 135 using extensions::ExtensionPrefs; |
136 using extensions::ExtensionResource; | 136 using extensions::ExtensionResource; |
137 using extensions::ExtensionSystem; | 137 using extensions::ExtensionSystem; |
138 using extensions::FeatureSwitch; | 138 using extensions::FeatureSwitch; |
139 using extensions::Manifest; | 139 using extensions::Manifest; |
140 using extensions::PermissionSet; | 140 using extensions::PermissionSet; |
141 using extensions::TestExtensionSystem; | 141 using extensions::TestExtensionSystem; |
142 using extensions::URLPatternSet; | 142 using extensions::URLPatternSet; |
| 143 using extensions::filenames::kManifestFilename; |
143 | 144 |
144 namespace keys = extension_manifest_keys; | 145 namespace keys = extension_manifest_keys; |
145 | 146 |
146 namespace { | 147 namespace { |
147 | 148 |
148 // Extension ids used during testing. | 149 // Extension ids used during testing. |
149 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 150 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
150 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; | 151 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
151 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 152 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
152 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; | 153 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; |
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2117 // not a valid extension. | 2118 // not a valid extension. |
2118 base::ScopedTempDir temp_dir2; | 2119 base::ScopedTempDir temp_dir2; |
2119 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 2120 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
2120 creator.reset(new ExtensionCreator()); | 2121 creator.reset(new ExtensionCreator()); |
2121 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, | 2122 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
2122 base::FilePath(), ExtensionCreator::kOverwriteCRX)); | 2123 base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
2123 | 2124 |
2124 // Try packing with an invalid manifest. | 2125 // Try packing with an invalid manifest. |
2125 std::string invalid_manifest_content = "I am not a manifest."; | 2126 std::string invalid_manifest_content = "I am not a manifest."; |
2126 ASSERT_TRUE(file_util::WriteFile( | 2127 ASSERT_TRUE(file_util::WriteFile( |
2127 temp_dir2.path().Append(extensions::kManifestFilename), | 2128 temp_dir2.path().Append(kManifestFilename), |
2128 invalid_manifest_content.c_str(), invalid_manifest_content.size())); | 2129 invalid_manifest_content.c_str(), invalid_manifest_content.size())); |
2129 creator.reset(new ExtensionCreator()); | 2130 creator.reset(new ExtensionCreator()); |
2130 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, | 2131 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
2131 base::FilePath(), ExtensionCreator::kOverwriteCRX)); | 2132 base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
2132 } | 2133 } |
2133 | 2134 |
2134 // Test Packaging and installing an extension whose name contains punctuation. | 2135 // Test Packaging and installing an extension whose name contains punctuation. |
2135 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { | 2136 TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { |
2136 InitializeEmptyExtensionService(); | 2137 InitializeEmptyExtensionService(); |
2137 base::FilePath input_directory = data_dir_ | 2138 base::FilePath input_directory = data_dir_ |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2336 | 2337 |
2337 // Tests that we can change the ID of an unpacked extension by adding a key | 2338 // Tests that we can change the ID of an unpacked extension by adding a key |
2338 // to its manifest. | 2339 // to its manifest. |
2339 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { | 2340 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { |
2340 InitializeEmptyExtensionService(); | 2341 InitializeEmptyExtensionService(); |
2341 | 2342 |
2342 base::ScopedTempDir temp; | 2343 base::ScopedTempDir temp; |
2343 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2344 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
2344 | 2345 |
2345 base::FilePath extension_path = temp.path(); | 2346 base::FilePath extension_path = temp.path(); |
2346 base::FilePath manifest_path = | 2347 base::FilePath manifest_path = extension_path.Append(kManifestFilename); |
2347 extension_path.Append(extensions::kManifestFilename); | |
2348 base::FilePath manifest_no_key = data_dir_. | 2348 base::FilePath manifest_no_key = data_dir_. |
2349 AppendASCII("unpacked"). | 2349 AppendASCII("unpacked"). |
2350 AppendASCII("manifest_no_key.json"); | 2350 AppendASCII("manifest_no_key.json"); |
2351 | 2351 |
2352 base::FilePath manifest_with_key = data_dir_. | 2352 base::FilePath manifest_with_key = data_dir_. |
2353 AppendASCII("unpacked"). | 2353 AppendASCII("unpacked"). |
2354 AppendASCII("manifest_with_key.json"); | 2354 AppendASCII("manifest_with_key.json"); |
2355 | 2355 |
2356 ASSERT_TRUE(base::PathExists(manifest_no_key)); | 2356 ASSERT_TRUE(base::PathExists(manifest_no_key)); |
2357 ASSERT_TRUE(base::PathExists(manifest_with_key)); | 2357 ASSERT_TRUE(base::PathExists(manifest_with_key)); |
(...skipping 30 matching lines...) Expand all Loading... |
2388 // Paths to test data files. | 2388 // Paths to test data files. |
2389 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); | 2389 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); |
2390 ASSERT_TRUE(base::PathExists(source_manifest)); | 2390 ASSERT_TRUE(base::PathExists(source_manifest)); |
2391 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); | 2391 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); |
2392 ASSERT_TRUE(base::PathExists(source_icon)); | 2392 ASSERT_TRUE(base::PathExists(source_icon)); |
2393 | 2393 |
2394 // Set up the temporary extension directory. | 2394 // Set up the temporary extension directory. |
2395 base::ScopedTempDir temp; | 2395 base::ScopedTempDir temp; |
2396 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2396 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
2397 base::FilePath extension_path = temp.path(); | 2397 base::FilePath extension_path = temp.path(); |
2398 base::FilePath manifest = extension_path.Append( | 2398 base::FilePath manifest = extension_path.Append(kManifestFilename); |
2399 extensions::kManifestFilename); | |
2400 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); | 2399 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); |
2401 base::CopyFile(source_manifest, manifest); | 2400 base::CopyFile(source_manifest, manifest); |
2402 file_util::CreateSymbolicLink(source_icon, icon_symlink); | 2401 file_util::CreateSymbolicLink(source_icon, icon_symlink); |
2403 | 2402 |
2404 // Load extension. | 2403 // Load extension. |
2405 InitializeEmptyExtensionService(); | 2404 InitializeEmptyExtensionService(); |
2406 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 2405 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
2407 loop_.RunUntilIdle(); | 2406 loop_.RunUntilIdle(); |
2408 | 2407 |
2409 EXPECT_TRUE(GetErrors().empty()); | 2408 EXPECT_TRUE(GetErrors().empty()); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2833 // Makes sure that LOAD extension types can downgrade. | 2832 // Makes sure that LOAD extension types can downgrade. |
2834 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { | 2833 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
2835 InitializeEmptyExtensionService(); | 2834 InitializeEmptyExtensionService(); |
2836 | 2835 |
2837 base::ScopedTempDir temp; | 2836 base::ScopedTempDir temp; |
2838 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2837 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
2839 | 2838 |
2840 // We'll write the extension manifest dynamically to a temporary path | 2839 // We'll write the extension manifest dynamically to a temporary path |
2841 // to make it easier to change the version number. | 2840 // to make it easier to change the version number. |
2842 base::FilePath extension_path = temp.path(); | 2841 base::FilePath extension_path = temp.path(); |
2843 base::FilePath manifest_path = | 2842 base::FilePath manifest_path = extension_path.Append(kManifestFilename); |
2844 extension_path.Append(extensions::kManifestFilename); | |
2845 ASSERT_FALSE(base::PathExists(manifest_path)); | 2843 ASSERT_FALSE(base::PathExists(manifest_path)); |
2846 | 2844 |
2847 // Start with version 2.0. | 2845 // Start with version 2.0. |
2848 DictionaryValue manifest; | 2846 DictionaryValue manifest; |
2849 manifest.SetString("version", "2.0"); | 2847 manifest.SetString("version", "2.0"); |
2850 manifest.SetString("name", "LOAD Downgrade Test"); | 2848 manifest.SetString("name", "LOAD Downgrade Test"); |
2851 manifest.SetInteger("manifest_version", 2); | 2849 manifest.SetInteger("manifest_version", 2); |
2852 | 2850 |
2853 JSONFileValueSerializer serializer(manifest_path); | 2851 JSONFileValueSerializer serializer(manifest_path); |
2854 ASSERT_TRUE(serializer.Serialize(manifest)); | 2852 ASSERT_TRUE(serializer.Serialize(manifest)); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3402 } | 3400 } |
3403 | 3401 |
3404 // Install a component extension. | 3402 // Install a component extension. |
3405 base::FilePath path = data_dir_ | 3403 base::FilePath path = data_dir_ |
3406 .AppendASCII("good") | 3404 .AppendASCII("good") |
3407 .AppendASCII("Extensions") | 3405 .AppendASCII("Extensions") |
3408 .AppendASCII(good0) | 3406 .AppendASCII(good0) |
3409 .AppendASCII("1.0.0.0"); | 3407 .AppendASCII("1.0.0.0"); |
3410 std::string manifest; | 3408 std::string manifest; |
3411 ASSERT_TRUE(file_util::ReadFileToString( | 3409 ASSERT_TRUE(file_util::ReadFileToString( |
3412 path.Append(extensions::kManifestFilename), &manifest)); | 3410 path.Append(kManifestFilename), &manifest)); |
3413 service_->component_loader()->Add(manifest, path); | 3411 service_->component_loader()->Add(manifest, path); |
3414 service_->Init(); | 3412 service_->Init(); |
3415 | 3413 |
3416 // Extension should be installed despite blacklist. | 3414 // Extension should be installed despite blacklist. |
3417 ASSERT_EQ(1u, service_->extensions()->size()); | 3415 ASSERT_EQ(1u, service_->extensions()->size()); |
3418 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3416 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
3419 | 3417 |
3420 // Poke external providers and make sure the extension is still present. | 3418 // Poke external providers and make sure the extension is still present. |
3421 service_->CheckForExternalUpdates(); | 3419 service_->CheckForExternalUpdates(); |
3422 ASSERT_EQ(1u, service_->extensions()->size()); | 3420 ASSERT_EQ(1u, service_->extensions()->size()); |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4852 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); | 4850 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); |
4853 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); | 4851 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); |
4854 #if defined OS_CHROMEOS | 4852 #if defined OS_CHROMEOS |
4855 chromeos::ScopedTestDeviceSettingsService device_settings_service; | 4853 chromeos::ScopedTestDeviceSettingsService device_settings_service; |
4856 chromeos::ScopedTestCrosSettings cros_settings; | 4854 chromeos::ScopedTestCrosSettings cros_settings; |
4857 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( | 4855 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( |
4858 new chromeos::ScopedTestUserManager); | 4856 new chromeos::ScopedTestUserManager); |
4859 #endif | 4857 #endif |
4860 scoped_ptr<CommandLine> command_line; | 4858 scoped_ptr<CommandLine> command_line; |
4861 base::FilePath install_dir = profile->GetPath() | 4859 base::FilePath install_dir = profile->GetPath() |
4862 .AppendASCII(extensions::kInstallDirectoryName); | 4860 .AppendASCII(extensions::filenames::kInstallDirectoryName); |
4863 | 4861 |
4864 #if defined(ENABLE_PLUGINS) | 4862 #if defined(ENABLE_PLUGINS) |
4865 webkit::npapi::MockPluginList plugin_list; | 4863 webkit::npapi::MockPluginList plugin_list; |
4866 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); | 4864 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); |
4867 #endif | 4865 #endif |
4868 | 4866 |
4869 // By default, we are enabled. | 4867 // By default, we are enabled. |
4870 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 4868 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
4871 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( | 4869 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
4872 ExtensionSystem::Get(profile.get()))-> | 4870 ExtensionSystem::Get(profile.get()))-> |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4983 set_extensions_enabled(false); | 4981 set_extensions_enabled(false); |
4984 | 4982 |
4985 base::FilePath path = data_dir_ | 4983 base::FilePath path = data_dir_ |
4986 .AppendASCII("good") | 4984 .AppendASCII("good") |
4987 .AppendASCII("Extensions") | 4985 .AppendASCII("Extensions") |
4988 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 4986 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
4989 .AppendASCII("1.0.0.0"); | 4987 .AppendASCII("1.0.0.0"); |
4990 | 4988 |
4991 std::string manifest; | 4989 std::string manifest; |
4992 ASSERT_TRUE(file_util::ReadFileToString( | 4990 ASSERT_TRUE(file_util::ReadFileToString( |
4993 path.Append(extensions::kManifestFilename), &manifest)); | 4991 path.Append(kManifestFilename), &manifest)); |
4994 | 4992 |
4995 service_->component_loader()->Add(manifest, path); | 4993 service_->component_loader()->Add(manifest, path); |
4996 service_->Init(); | 4994 service_->Init(); |
4997 | 4995 |
4998 // Note that we do not pump messages -- the extension should be loaded | 4996 // Note that we do not pump messages -- the extension should be loaded |
4999 // immediately. | 4997 // immediately. |
5000 | 4998 |
5001 EXPECT_EQ(0u, GetErrors().size()); | 4999 EXPECT_EQ(0u, GetErrors().size()); |
5002 ASSERT_EQ(1u, loaded_.size()); | 5000 ASSERT_EQ(1u, loaded_.size()); |
5003 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); | 5001 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5037 &triggered_type)); // Safe due to WeakPtrFactory scope. | 5035 &triggered_type)); // Safe due to WeakPtrFactory scope. |
5038 | 5036 |
5039 // Install a component extension. | 5037 // Install a component extension. |
5040 base::FilePath path = data_dir_ | 5038 base::FilePath path = data_dir_ |
5041 .AppendASCII("good") | 5039 .AppendASCII("good") |
5042 .AppendASCII("Extensions") | 5040 .AppendASCII("Extensions") |
5043 .AppendASCII(good0) | 5041 .AppendASCII(good0) |
5044 .AppendASCII("1.0.0.0"); | 5042 .AppendASCII("1.0.0.0"); |
5045 std::string manifest; | 5043 std::string manifest; |
5046 ASSERT_TRUE(file_util::ReadFileToString( | 5044 ASSERT_TRUE(file_util::ReadFileToString( |
5047 path.Append(extensions::kManifestFilename), &manifest)); | 5045 path.Append(kManifestFilename), &manifest)); |
5048 service_->component_loader()->Add(manifest, path); | 5046 service_->component_loader()->Add(manifest, path); |
5049 ASSERT_FALSE(service_->is_ready()); | 5047 ASSERT_FALSE(service_->is_ready()); |
5050 service_->Init(); | 5048 service_->Init(); |
5051 ASSERT_TRUE(service_->is_ready()); | 5049 ASSERT_TRUE(service_->is_ready()); |
5052 | 5050 |
5053 // Extensions added before service is_ready() don't trigger sync startup. | 5051 // Extensions added before service is_ready() don't trigger sync startup. |
5054 EXPECT_FALSE(flare_was_called); | 5052 EXPECT_FALSE(flare_was_called); |
5055 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); | 5053 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
5056 } | 5054 } |
5057 | 5055 |
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6272 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6270 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
6273 | 6271 |
6274 service_->CheckForExternalUpdates(); | 6272 service_->CheckForExternalUpdates(); |
6275 content::WindowedNotificationObserver( | 6273 content::WindowedNotificationObserver( |
6276 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 6274 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
6277 content::NotificationService::AllSources()).Wait(); | 6275 content::NotificationService::AllSources()).Wait(); |
6278 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6276 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
6279 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6277 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
6280 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6278 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
6281 } | 6279 } |
OLD | NEW |