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 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 msg += extension_id + " " + pref_path; | 1009 msg += extension_id + " " + pref_path; |
1010 | 1010 |
1011 ListValue* list_value = new ListValue(); | 1011 ListValue* list_value = new ListValue(); |
1012 for (std::set<std::string>::const_iterator iter = value.begin(); | 1012 for (std::set<std::string>::const_iterator iter = value.begin(); |
1013 iter != value.end(); ++iter) | 1013 iter != value.end(); ++iter) |
1014 list_value->Append(Value::CreateStringValue(*iter)); | 1014 list_value->Append(Value::CreateStringValue(*iter)); |
1015 | 1015 |
1016 SetPref(extension_id, pref_path, list_value, msg); | 1016 SetPref(extension_id, pref_path, list_value, msg); |
1017 } | 1017 } |
1018 | 1018 |
| 1019 void InitPluginService() { |
| 1020 #if defined(ENABLE_PLUGINS) |
| 1021 PluginService::GetInstance()->Init(); |
| 1022 #endif |
| 1023 } |
| 1024 |
1019 protected: | 1025 protected: |
1020 extensions::ExtensionList loaded_; | 1026 extensions::ExtensionList loaded_; |
1021 std::string unloaded_id_; | 1027 std::string unloaded_id_; |
1022 const Extension* installed_; | 1028 const Extension* installed_; |
1023 FeatureSwitch::ScopedOverride override_external_install_prompt_; | 1029 FeatureSwitch::ScopedOverride override_external_install_prompt_; |
1024 | 1030 |
1025 private: | 1031 private: |
1026 content::NotificationRegistrar registrar_; | 1032 content::NotificationRegistrar registrar_; |
1027 }; | 1033 }; |
1028 | 1034 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, | 1074 void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
1069 ExtensionCreator::ErrorType type) { | 1075 ExtensionCreator::ErrorType type) { |
1070 if (type == ExtensionCreator::kCRXExists) | 1076 if (type == ExtensionCreator::kCRXExists) |
1071 FAIL() << "Packing should not fail."; | 1077 FAIL() << "Packing should not fail."; |
1072 else | 1078 else |
1073 FAIL() << "Existing CRX should have been overwritten."; | 1079 FAIL() << "Existing CRX should have been overwritten."; |
1074 } | 1080 } |
1075 | 1081 |
1076 // Test loading good extensions from the profile directory. | 1082 // Test loading good extensions from the profile directory. |
1077 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { | 1083 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
1078 PluginService::GetInstance()->Init(); | 1084 InitPluginService(); |
1079 | 1085 |
1080 // Initialize the test dir with a good Preferences/extensions. | 1086 // Initialize the test dir with a good Preferences/extensions. |
1081 FilePath source_install_dir = data_dir_ | 1087 FilePath source_install_dir = data_dir_ |
1082 .AppendASCII("good") | 1088 .AppendASCII("good") |
1083 .AppendASCII("Extensions"); | 1089 .AppendASCII("Extensions"); |
1084 FilePath pref_path = source_install_dir | 1090 FilePath pref_path = source_install_dir |
1085 .DirName() | 1091 .DirName() |
1086 .AppendASCII("Preferences"); | 1092 .AppendASCII("Preferences"); |
1087 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1093 InitializeInstalledExtensionService(pref_path, source_install_dir); |
1088 | 1094 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 | 1216 |
1211 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[3]), | 1217 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[3]), |
1212 std::string("Could not load extension from '*'. ") + | 1218 std::string("Could not load extension from '*'. ") + |
1213 extension_manifest_errors::kManifestUnreadable)) << | 1219 extension_manifest_errors::kManifestUnreadable)) << |
1214 UTF16ToUTF8(GetErrors()[3]); | 1220 UTF16ToUTF8(GetErrors()[3]); |
1215 }; | 1221 }; |
1216 | 1222 |
1217 // Test that partially deleted extensions are cleaned up during startup | 1223 // Test that partially deleted extensions are cleaned up during startup |
1218 // Test loading bad extensions from the profile directory. | 1224 // Test loading bad extensions from the profile directory. |
1219 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | 1225 TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
1220 PluginService::GetInstance()->Init(); | 1226 InitPluginService(); |
1221 | 1227 |
1222 FilePath source_install_dir = data_dir_ | 1228 FilePath source_install_dir = data_dir_ |
1223 .AppendASCII("good") | 1229 .AppendASCII("good") |
1224 .AppendASCII("Extensions"); | 1230 .AppendASCII("Extensions"); |
1225 FilePath pref_path = source_install_dir | 1231 FilePath pref_path = source_install_dir |
1226 .DirName() | 1232 .DirName() |
1227 .AppendASCII("Preferences"); | 1233 .AppendASCII("Preferences"); |
1228 | 1234 |
1229 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1235 InitializeInstalledExtensionService(pref_path, source_install_dir); |
1230 | 1236 |
(...skipping 20 matching lines...) Expand all Loading... |
1251 | 1257 |
1252 // And extension1 dir should now be toast. | 1258 // And extension1 dir should now be toast. |
1253 FilePath extension_dir = extensions_install_dir_ | 1259 FilePath extension_dir = extensions_install_dir_ |
1254 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); | 1260 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); |
1255 ASSERT_FALSE(file_util::PathExists(extension_dir)); | 1261 ASSERT_FALSE(file_util::PathExists(extension_dir)); |
1256 } | 1262 } |
1257 | 1263 |
1258 // Test that GarbageCollectExtensions deletes the right versions of an | 1264 // Test that GarbageCollectExtensions deletes the right versions of an |
1259 // extension. | 1265 // extension. |
1260 TEST_F(ExtensionServiceTest, GarbageCollectWithPendingUpdates) { | 1266 TEST_F(ExtensionServiceTest, GarbageCollectWithPendingUpdates) { |
1261 PluginService::GetInstance()->Init(); | 1267 InitPluginService(); |
1262 | 1268 |
1263 FilePath source_install_dir = data_dir_ | 1269 FilePath source_install_dir = data_dir_ |
1264 .AppendASCII("pending_updates") | 1270 .AppendASCII("pending_updates") |
1265 .AppendASCII("Extensions"); | 1271 .AppendASCII("Extensions"); |
1266 FilePath pref_path = source_install_dir | 1272 FilePath pref_path = source_install_dir |
1267 .DirName() | 1273 .DirName() |
1268 .AppendASCII("Preferences"); | 1274 .AppendASCII("Preferences"); |
1269 | 1275 |
1270 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1276 InitializeInstalledExtensionService(pref_path, source_install_dir); |
1271 | 1277 |
(...skipping 13 matching lines...) Expand all Loading... |
1285 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( | 1291 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
1286 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); | 1292 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); |
1287 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( | 1293 EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
1288 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); | 1294 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
1289 EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( | 1295 EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
1290 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); | 1296 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
1291 } | 1297 } |
1292 | 1298 |
1293 // Test that pending updates are properly handled on startup. | 1299 // Test that pending updates are properly handled on startup. |
1294 TEST_F(ExtensionServiceTest, UpdateOnStartup) { | 1300 TEST_F(ExtensionServiceTest, UpdateOnStartup) { |
1295 PluginService::GetInstance()->Init(); | 1301 InitPluginService(); |
1296 | 1302 |
1297 FilePath source_install_dir = data_dir_ | 1303 FilePath source_install_dir = data_dir_ |
1298 .AppendASCII("pending_updates") | 1304 .AppendASCII("pending_updates") |
1299 .AppendASCII("Extensions"); | 1305 .AppendASCII("Extensions"); |
1300 FilePath pref_path = source_install_dir | 1306 FilePath pref_path = source_install_dir |
1301 .DirName() | 1307 .DirName() |
1302 .AppendASCII("Preferences"); | 1308 .AppendASCII("Preferences"); |
1303 | 1309 |
1304 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1310 InitializeInstalledExtensionService(pref_path, source_install_dir); |
1305 | 1311 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1695 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
1690 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1696 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
1691 } | 1697 } |
1692 #endif | 1698 #endif |
1693 | 1699 |
1694 #if !defined(OS_CHROMEOS) | 1700 #if !defined(OS_CHROMEOS) |
1695 // Tests that the granted permissions full_access bit gets set correctly when | 1701 // Tests that the granted permissions full_access bit gets set correctly when |
1696 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 1702 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
1697 // since they don't support plugins. | 1703 // since they don't support plugins. |
1698 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1704 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
1699 PluginService::GetInstance()->Init(); | 1705 InitPluginService(); |
1700 | 1706 |
1701 InitializeEmptyExtensionService(); | 1707 InitializeEmptyExtensionService(); |
1702 | 1708 |
1703 FilePath path = data_dir_ | 1709 FilePath path = data_dir_ |
1704 .AppendASCII("good") | 1710 .AppendASCII("good") |
1705 .AppendASCII("Extensions") | 1711 .AppendASCII("Extensions") |
1706 .AppendASCII(good1) | 1712 .AppendASCII(good1) |
1707 .AppendASCII("2"); | 1713 .AppendASCII("2"); |
1708 | 1714 |
1709 ASSERT_TRUE(file_util::PathExists(path)); | 1715 ASSERT_TRUE(file_util::PathExists(path)); |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2628 .AppendASCII("good") | 2634 .AppendASCII("good") |
2629 .AppendASCII("Extensions") | 2635 .AppendASCII("Extensions") |
2630 .AppendASCII(good1) | 2636 .AppendASCII(good1) |
2631 .AppendASCII("2"); | 2637 .AppendASCII("2"); |
2632 FilePath extension_no_plugin_path = data_dir_ | 2638 FilePath extension_no_plugin_path = data_dir_ |
2633 .AppendASCII("good") | 2639 .AppendASCII("good") |
2634 .AppendASCII("Extensions") | 2640 .AppendASCII("Extensions") |
2635 .AppendASCII(good2) | 2641 .AppendASCII(good2) |
2636 .AppendASCII("1.0"); | 2642 .AppendASCII("1.0"); |
2637 | 2643 |
2638 PluginService::GetInstance()->Init(); | 2644 InitPluginService(); |
2639 InitializeEmptyExtensionService(); | 2645 InitializeEmptyExtensionService(); |
2640 InitializeExtensionProcessManager(); | 2646 InitializeExtensionProcessManager(); |
2641 service_->set_show_extensions_prompts(true); | 2647 service_->set_show_extensions_prompts(true); |
2642 | 2648 |
2643 // Start by canceling any install prompts. | 2649 // Start by canceling any install prompts. |
2644 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 2650 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
2645 switches::kAppsGalleryInstallAutoConfirmForTests, | 2651 switches::kAppsGalleryInstallAutoConfirmForTests, |
2646 "cancel"); | 2652 "cancel"); |
2647 | 2653 |
2648 // The extension that has a plugin should not install. | 2654 // The extension that has a plugin should not install. |
(...skipping 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4504 ExtensionErrorReporter::Init(false); // no noisy errors | 4510 ExtensionErrorReporter::Init(false); // no noisy errors |
4505 ExtensionsReadyRecorder recorder; | 4511 ExtensionsReadyRecorder recorder; |
4506 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 4512 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
4507 MessageLoop loop; | 4513 MessageLoop loop; |
4508 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); | 4514 content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); |
4509 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); | 4515 content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); |
4510 scoped_ptr<CommandLine> command_line; | 4516 scoped_ptr<CommandLine> command_line; |
4511 FilePath install_dir = profile->GetPath() | 4517 FilePath install_dir = profile->GetPath() |
4512 .AppendASCII(ExtensionService::kInstallDirectoryName); | 4518 .AppendASCII(ExtensionService::kInstallDirectoryName); |
4513 | 4519 |
| 4520 #if defined(ENABLE_PLUGINS) |
4514 webkit::npapi::MockPluginList plugin_list; | 4521 webkit::npapi::MockPluginList plugin_list; |
4515 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); | 4522 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); |
| 4523 #endif |
4516 | 4524 |
4517 // By default, we are enabled. | 4525 // By default, we are enabled. |
4518 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 4526 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
4519 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( | 4527 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
4520 ExtensionSystem::Get(profile.get()))-> | 4528 ExtensionSystem::Get(profile.get()))-> |
4521 CreateExtensionService( | 4529 CreateExtensionService( |
4522 command_line.get(), | 4530 command_line.get(), |
4523 install_dir, | 4531 install_dir, |
4524 false); | 4532 false); |
4525 EXPECT_TRUE(service->extensions_enabled()); | 4533 EXPECT_TRUE(service->extensions_enabled()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4570 service->Init(); | 4578 service->Init(); |
4571 loop.RunUntilIdle(); | 4579 loop.RunUntilIdle(); |
4572 EXPECT_TRUE(recorder.ready()); | 4580 EXPECT_TRUE(recorder.ready()); |
4573 | 4581 |
4574 // Explicitly delete all the resources used in this test. | 4582 // Explicitly delete all the resources used in this test. |
4575 profile.reset(); | 4583 profile.reset(); |
4576 service = NULL; | 4584 service = NULL; |
4577 // Execute any pending deletion tasks. | 4585 // Execute any pending deletion tasks. |
4578 loop.RunUntilIdle(); | 4586 loop.RunUntilIdle(); |
4579 | 4587 |
| 4588 #if defined(ENABLE_PLUGINS) |
4580 // Ensure that even if the PluginService is re-used for a later test, it | 4589 // Ensure that even if the PluginService is re-used for a later test, it |
4581 // won't still hold a reference to the stack position of our MockPluginList. | 4590 // won't still hold a reference to the stack position of our MockPluginList. |
4582 // See crbug.com/159754. | 4591 // See crbug.com/159754. |
4583 PluginService::GetInstance()->SetPluginListForTesting(NULL); | 4592 PluginService::GetInstance()->SetPluginListForTesting(NULL); |
| 4593 #endif |
4584 } | 4594 } |
4585 | 4595 |
4586 // Test loading extensions that require limited and unlimited storage quotas. | 4596 // Test loading extensions that require limited and unlimited storage quotas. |
4587 TEST_F(ExtensionServiceTest, StorageQuota) { | 4597 TEST_F(ExtensionServiceTest, StorageQuota) { |
4588 InitializeEmptyExtensionService(); | 4598 InitializeEmptyExtensionService(); |
4589 | 4599 |
4590 FilePath extensions_path = data_dir_ | 4600 FilePath extensions_path = data_dir_ |
4591 .AppendASCII("storage_quota"); | 4601 .AppendASCII("storage_quota"); |
4592 | 4602 |
4593 FilePath limited_quota_ext = | 4603 FilePath limited_quota_ext = |
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5785 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5795 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
5786 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5796 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
5787 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5797 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
5788 | 5798 |
5789 ExtensionPrefs* prefs = service_->extension_prefs(); | 5799 ExtensionPrefs* prefs = service_->extension_prefs(); |
5790 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 5800 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
5791 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5801 Extension::DISABLE_SIDELOAD_WIPEOUT); |
5792 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 5802 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
5793 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5803 Extension::DISABLE_SIDELOAD_WIPEOUT); |
5794 } | 5804 } |
OLD | NEW |