| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "chrome/browser/extensions/unpacked_installer.h" | 55 #include "chrome/browser/extensions/unpacked_installer.h" |
| 56 #include "chrome/browser/extensions/updater/extension_updater.h" | 56 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 57 #include "chrome/browser/prefs/browser_prefs.h" | 57 #include "chrome/browser/prefs/browser_prefs.h" |
| 58 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 58 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 59 #include "chrome/browser/prefs/pref_service_syncable.h" | 59 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 60 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 60 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 61 #include "chrome/common/chrome_constants.h" | 61 #include "chrome/common/chrome_constants.h" |
| 62 #include "chrome/common/chrome_notification_types.h" | 62 #include "chrome/common/chrome_notification_types.h" |
| 63 #include "chrome/common/chrome_paths.h" | 63 #include "chrome/common/chrome_paths.h" |
| 64 #include "chrome/common/chrome_switches.h" | 64 #include "chrome/common/chrome_switches.h" |
| 65 #include "chrome/common/extensions/api/content_scripts/content_scripts_handler.h
" |
| 65 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 66 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
| 66 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 67 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
| 67 #include "chrome/common/extensions/background_info.h" | 68 #include "chrome/common/extensions/background_info.h" |
| 68 #include "chrome/common/extensions/extension.h" | 69 #include "chrome/common/extensions/extension.h" |
| 69 #include "chrome/common/extensions/extension_l10n_util.h" | 70 #include "chrome/common/extensions/extension_l10n_util.h" |
| 70 #include "chrome/common/extensions/extension_manifest_constants.h" | 71 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 71 #include "chrome/common/extensions/extension_resource.h" | 72 #include "chrome/common/extensions/extension_resource.h" |
| 72 #include "chrome/common/extensions/manifest_handler.h" | 73 #include "chrome/common/extensions/manifest_handler.h" |
| 73 #include "chrome/common/extensions/manifest_url_handler.h" | 74 #include "chrome/common/extensions/manifest_url_handler.h" |
| 74 #include "chrome/common/extensions/permissions/permission_set.h" | 75 #include "chrome/common/extensions/permissions/permission_set.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 541 |
| 541 // static | 542 // static |
| 542 void ExtensionServiceTestBase::SetUpTestCase() { | 543 void ExtensionServiceTestBase::SetUpTestCase() { |
| 543 ExtensionErrorReporter::Init(false); // no noisy errors | 544 ExtensionErrorReporter::Init(false); // no noisy errors |
| 544 } | 545 } |
| 545 | 546 |
| 546 void ExtensionServiceTestBase::SetUp() { | 547 void ExtensionServiceTestBase::SetUp() { |
| 547 testing::Test::SetUp(); | 548 testing::Test::SetUp(); |
| 548 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 549 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 549 (new extensions::BackgroundManifestHandler)->Register(); | 550 (new extensions::BackgroundManifestHandler)->Register(); |
| 551 (new extensions::ContentScriptsHandler)->Register(); |
| 550 (new extensions::DefaultLocaleHandler)->Register(); | 552 (new extensions::DefaultLocaleHandler)->Register(); |
| 551 (new extensions::PluginsHandler)->Register(); | 553 (new extensions::PluginsHandler)->Register(); |
| 552 } | 554 } |
| 553 | 555 |
| 554 void ExtensionServiceTestBase::TearDown() { | 556 void ExtensionServiceTestBase::TearDown() { |
| 555 extensions::ManifestHandler::ClearRegistryForTesting(); | 557 extensions::ManifestHandler::ClearRegistryForTesting(); |
| 556 } | 558 } |
| 557 | 559 |
| 558 class ExtensionServiceTest | 560 class ExtensionServiceTest |
| 559 : public ExtensionServiceTestBase, public content::NotificationObserver { | 561 : public ExtensionServiceTestBase, public content::NotificationObserver { |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 ValidateIntegerPref(good1, "state", Extension::ENABLED); | 1149 ValidateIntegerPref(good1, "state", Extension::ENABLED); |
| 1148 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); | 1150 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); |
| 1149 ValidateIntegerPref(good2, "state", Extension::ENABLED); | 1151 ValidateIntegerPref(good2, "state", Extension::ENABLED); |
| 1150 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); | 1152 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
| 1151 | 1153 |
| 1152 URLPatternSet expected_patterns; | 1154 URLPatternSet expected_patterns; |
| 1153 AddPattern(&expected_patterns, "file:///*"); | 1155 AddPattern(&expected_patterns, "file:///*"); |
| 1154 AddPattern(&expected_patterns, "http://*.google.com/*"); | 1156 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1155 AddPattern(&expected_patterns, "https://*.google.com/*"); | 1157 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 1156 const Extension* extension = loaded_[0]; | 1158 const Extension* extension = loaded_[0]; |
| 1157 const extensions::UserScriptList& scripts = extension->content_scripts(); | 1159 const extensions::UserScriptList& scripts = |
| 1160 extensions::ContentScriptsInfo::GetContentScripts(extension); |
| 1158 ASSERT_EQ(2u, scripts.size()); | 1161 ASSERT_EQ(2u, scripts.size()); |
| 1159 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); | 1162 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); |
| 1160 EXPECT_EQ(2u, scripts[0].js_scripts().size()); | 1163 EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
| 1161 ExtensionResource resource00(extension->id(), | 1164 ExtensionResource resource00(extension->id(), |
| 1162 scripts[0].js_scripts()[0].extension_root(), | 1165 scripts[0].js_scripts()[0].extension_root(), |
| 1163 scripts[0].js_scripts()[0].relative_path()); | 1166 scripts[0].js_scripts()[0].relative_path()); |
| 1164 base::FilePath expected_path(extension->path().AppendASCII("script1.js")); | 1167 base::FilePath expected_path(extension->path().AppendASCII("script1.js")); |
| 1165 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); | 1168 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
| 1166 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); | 1169 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
| 1167 ExtensionResource resource01(extension->id(), | 1170 ExtensionResource resource01(extension->id(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1186 AddPattern(&expected_patterns, "http://*.google.com/*"); | 1189 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1187 AddPattern(&expected_patterns, "https://*.google.com/*"); | 1190 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 1188 EXPECT_EQ(expected_patterns, | 1191 EXPECT_EQ(expected_patterns, |
| 1189 extension->GetActivePermissions()->explicit_hosts()); | 1192 extension->GetActivePermissions()->explicit_hosts()); |
| 1190 | 1193 |
| 1191 EXPECT_EQ(std::string(good1), loaded_[1]->id()); | 1194 EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
| 1192 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); | 1195 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
| 1193 EXPECT_EQ(std::string(""), loaded_[1]->description()); | 1196 EXPECT_EQ(std::string(""), loaded_[1]->description()); |
| 1194 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), | 1197 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
| 1195 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1])); | 1198 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1])); |
| 1196 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); | 1199 EXPECT_EQ( |
| 1200 0u, extensions::ContentScriptsInfo::GetContentScripts(loaded_[1]).size()); |
| 1197 | 1201 |
| 1198 // We don't parse the plugins section on Chrome OS. | 1202 // We don't parse the plugins section on Chrome OS. |
| 1199 #if defined(OS_CHROMEOS) | 1203 #if defined(OS_CHROMEOS) |
| 1200 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1])); | 1204 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1])); |
| 1201 #else | 1205 #else |
| 1202 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1])); | 1206 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1])); |
| 1203 const std::vector<extensions::PluginInfo>* plugins = | 1207 const std::vector<extensions::PluginInfo>* plugins = |
| 1204 extensions::PluginInfo::GetPlugins(loaded_[1]); | 1208 extensions::PluginInfo::GetPlugins(loaded_[1]); |
| 1205 ASSERT_TRUE(plugins); | 1209 ASSERT_TRUE(plugins); |
| 1206 ASSERT_EQ(2u, plugins->size()); | 1210 ASSERT_EQ(2u, plugins->size()); |
| 1207 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), | 1211 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
| 1208 plugins->at(0).path.value()); | 1212 plugins->at(0).path.value()); |
| 1209 EXPECT_TRUE(plugins->at(0).is_public); | 1213 EXPECT_TRUE(plugins->at(0).is_public); |
| 1210 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), | 1214 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
| 1211 plugins->at(1).path.value()); | 1215 plugins->at(1).path.value()); |
| 1212 EXPECT_FALSE(plugins->at(1).is_public); | 1216 EXPECT_FALSE(plugins->at(1).is_public); |
| 1213 #endif | 1217 #endif |
| 1214 | 1218 |
| 1215 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); | 1219 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
| 1216 | 1220 |
| 1217 int index = expected_num_extensions - 1; | 1221 int index = expected_num_extensions - 1; |
| 1218 EXPECT_EQ(std::string(good2), loaded_[index]->id()); | 1222 EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 1219 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); | 1223 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
| 1220 EXPECT_EQ(std::string(""), loaded_[index]->description()); | 1224 EXPECT_EQ(std::string(""), loaded_[index]->description()); |
| 1221 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); | 1225 EXPECT_EQ( |
| 1226 0u, |
| 1227 extensions::ContentScriptsInfo::GetContentScripts(loaded_[index]).size()); |
| 1222 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); | 1228 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
| 1223 }; | 1229 }; |
| 1224 | 1230 |
| 1225 // Test loading bad extensions from the profile directory. | 1231 // Test loading bad extensions from the profile directory. |
| 1226 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { | 1232 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
| 1227 // Initialize the test dir with a bad Preferences/extensions. | 1233 // Initialize the test dir with a bad Preferences/extensions. |
| 1228 base::FilePath source_install_dir = data_dir_ | 1234 base::FilePath source_install_dir = data_dir_ |
| 1229 .AppendASCII("bad") | 1235 .AppendASCII("bad") |
| 1230 .AppendASCII("Extensions"); | 1236 .AppendASCII("Extensions"); |
| 1231 base::FilePath pref_path = source_install_dir | 1237 base::FilePath pref_path = source_install_dir |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2098 | 2104 |
| 2099 // A theme with extension elements. Themes cannot have extension elements, | 2105 // A theme with extension elements. Themes cannot have extension elements, |
| 2100 // so any such elements (like content scripts) should be ignored. | 2106 // so any such elements (like content scripts) should be ignored. |
| 2101 set_extensions_enabled(true); | 2107 set_extensions_enabled(true); |
| 2102 { | 2108 { |
| 2103 path = data_dir_.AppendASCII("theme_with_extension.crx"); | 2109 path = data_dir_.AppendASCII("theme_with_extension.crx"); |
| 2104 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2110 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2105 ValidatePrefKeyCount(++pref_count); | 2111 ValidatePrefKeyCount(++pref_count); |
| 2106 ASSERT_TRUE(extension); | 2112 ASSERT_TRUE(extension); |
| 2107 EXPECT_TRUE(extension->is_theme()); | 2113 EXPECT_TRUE(extension->is_theme()); |
| 2108 EXPECT_EQ(0u, extension->content_scripts().size()); | 2114 EXPECT_EQ( |
| 2115 0u, |
| 2116 extensions::ContentScriptsInfo::GetContentScripts(extension).size()); |
| 2109 } | 2117 } |
| 2110 | 2118 |
| 2111 // A theme with image resources missing (misspelt path). | 2119 // A theme with image resources missing (misspelt path). |
| 2112 path = data_dir_.AppendASCII("theme_missing_image.crx"); | 2120 path = data_dir_.AppendASCII("theme_missing_image.crx"); |
| 2113 InstallCRX(path, INSTALL_FAILED); | 2121 InstallCRX(path, INSTALL_FAILED); |
| 2114 ValidatePrefKeyCount(pref_count); | 2122 ValidatePrefKeyCount(pref_count); |
| 2115 } | 2123 } |
| 2116 | 2124 |
| 2117 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { | 2125 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
| 2118 // Load. | 2126 // Load. |
| (...skipping 3774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5893 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5901 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5894 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5902 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5895 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5903 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5896 | 5904 |
| 5897 ExtensionPrefs* prefs = service_->extension_prefs(); | 5905 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 5898 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 5906 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
| 5899 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5907 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5900 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 5908 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
| 5901 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5909 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5902 } | 5910 } |
| OLD | NEW |