| 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 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/plugins/plugin_prefs_factory.h" | 57 #include "chrome/browser/plugins/plugin_prefs_factory.h" |
| 58 #include "chrome/browser/prefs/browser_prefs.h" | 58 #include "chrome/browser/prefs/browser_prefs.h" |
| 59 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 59 #include "chrome/browser/prefs/pref_service_mock_builder.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/extension.h" | 66 #include "chrome/common/extensions/extension.h" |
| 66 #include "chrome/common/extensions/extension_l10n_util.h" | 67 #include "chrome/common/extensions/extension_l10n_util.h" |
| 67 #include "chrome/common/extensions/extension_manifest_constants.h" | 68 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 68 #include "chrome/common/extensions/extension_resource.h" | 69 #include "chrome/common/extensions/extension_resource.h" |
| 69 #include "chrome/common/extensions/permissions/permission_set.h" | 70 #include "chrome/common/extensions/permissions/permission_set.h" |
| 70 #include "chrome/common/pref_names.h" | 71 #include "chrome/common/pref_names.h" |
| 71 #include "chrome/common/url_constants.h" | 72 #include "chrome/common/url_constants.h" |
| 72 #include "chrome/test/base/testing_profile.h" | 73 #include "chrome/test/base/testing_profile.h" |
| 73 #include "content/public/browser/dom_storage_context.h" | 74 #include "content/public/browser/dom_storage_context.h" |
| 74 #include "content/public/browser/gpu_data_manager.h" | 75 #include "content/public/browser/gpu_data_manager.h" |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 ValidateIntegerPref(good1, "state", Extension::ENABLED); | 1120 ValidateIntegerPref(good1, "state", Extension::ENABLED); |
| 1120 ValidateIntegerPref(good1, "location", Extension::INTERNAL); | 1121 ValidateIntegerPref(good1, "location", Extension::INTERNAL); |
| 1121 ValidateIntegerPref(good2, "state", Extension::ENABLED); | 1122 ValidateIntegerPref(good2, "state", Extension::ENABLED); |
| 1122 ValidateIntegerPref(good2, "location", Extension::INTERNAL); | 1123 ValidateIntegerPref(good2, "location", Extension::INTERNAL); |
| 1123 | 1124 |
| 1124 URLPatternSet expected_patterns; | 1125 URLPatternSet expected_patterns; |
| 1125 AddPattern(&expected_patterns, "file:///*"); | 1126 AddPattern(&expected_patterns, "file:///*"); |
| 1126 AddPattern(&expected_patterns, "http://*.google.com/*"); | 1127 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1127 AddPattern(&expected_patterns, "https://*.google.com/*"); | 1128 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 1128 const Extension* extension = loaded_[0]; | 1129 const Extension* extension = loaded_[0]; |
| 1129 const extensions::UserScriptList& scripts = extension->content_scripts(); | 1130 const extensions::UserScriptList& scripts = |
| 1131 extensions::ContentScriptsInfo::GetContentScripts(extension); |
| 1130 ASSERT_EQ(2u, scripts.size()); | 1132 ASSERT_EQ(2u, scripts.size()); |
| 1131 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); | 1133 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); |
| 1132 EXPECT_EQ(2u, scripts[0].js_scripts().size()); | 1134 EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
| 1133 ExtensionResource resource00(extension->id(), | 1135 ExtensionResource resource00(extension->id(), |
| 1134 scripts[0].js_scripts()[0].extension_root(), | 1136 scripts[0].js_scripts()[0].extension_root(), |
| 1135 scripts[0].js_scripts()[0].relative_path()); | 1137 scripts[0].js_scripts()[0].relative_path()); |
| 1136 FilePath expected_path(extension->path().AppendASCII("script1.js")); | 1138 FilePath expected_path(extension->path().AppendASCII("script1.js")); |
| 1137 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); | 1139 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
| 1138 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); | 1140 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
| 1139 ExtensionResource resource01(extension->id(), | 1141 ExtensionResource resource01(extension->id(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1158 AddPattern(&expected_patterns, "http://*.google.com/*"); | 1160 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1159 AddPattern(&expected_patterns, "https://*.google.com/*"); | 1161 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 1160 EXPECT_EQ(expected_patterns, | 1162 EXPECT_EQ(expected_patterns, |
| 1161 extension->GetActivePermissions()->explicit_hosts()); | 1163 extension->GetActivePermissions()->explicit_hosts()); |
| 1162 | 1164 |
| 1163 EXPECT_EQ(std::string(good1), loaded_[1]->id()); | 1165 EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
| 1164 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); | 1166 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
| 1165 EXPECT_EQ(std::string(""), loaded_[1]->description()); | 1167 EXPECT_EQ(std::string(""), loaded_[1]->description()); |
| 1166 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), | 1168 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
| 1167 loaded_[1]->GetBackgroundURL()); | 1169 loaded_[1]->GetBackgroundURL()); |
| 1168 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); | 1170 EXPECT_EQ( |
| 1171 0u, extensions::ContentScriptsInfo::GetContentScripts(loaded_[1]).size()); |
| 1169 // We don't parse the plugins section on Chrome OS. | 1172 // We don't parse the plugins section on Chrome OS. |
| 1170 #if defined(OS_CHROMEOS) | 1173 #if defined(OS_CHROMEOS) |
| 1171 EXPECT_EQ(0u, loaded_[1]->plugins().size()); | 1174 EXPECT_EQ(0u, loaded_[1]->plugins().size()); |
| 1172 #else | 1175 #else |
| 1173 ASSERT_EQ(2u, loaded_[1]->plugins().size()); | 1176 ASSERT_EQ(2u, loaded_[1]->plugins().size()); |
| 1174 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), | 1177 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
| 1175 loaded_[1]->plugins()[0].path.value()); | 1178 loaded_[1]->plugins()[0].path.value()); |
| 1176 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); | 1179 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); |
| 1177 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), | 1180 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
| 1178 loaded_[1]->plugins()[1].path.value()); | 1181 loaded_[1]->plugins()[1].path.value()); |
| 1179 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); | 1182 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); |
| 1180 #endif | 1183 #endif |
| 1181 | 1184 |
| 1182 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); | 1185 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); |
| 1183 | 1186 |
| 1184 int index = expected_num_extensions - 1; | 1187 int index = expected_num_extensions - 1; |
| 1185 EXPECT_EQ(std::string(good2), loaded_[index]->id()); | 1188 EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 1186 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); | 1189 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
| 1187 EXPECT_EQ(std::string(""), loaded_[index]->description()); | 1190 EXPECT_EQ(std::string(""), loaded_[index]->description()); |
| 1188 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); | 1191 EXPECT_EQ( |
| 1192 0u, |
| 1193 extensions::ContentScriptsInfo::GetContentScripts(loaded_[index]).size()); |
| 1189 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); | 1194 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); |
| 1190 }; | 1195 }; |
| 1191 | 1196 |
| 1192 // Test loading bad extensions from the profile directory. | 1197 // Test loading bad extensions from the profile directory. |
| 1193 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { | 1198 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
| 1194 // Initialize the test dir with a bad Preferences/extensions. | 1199 // Initialize the test dir with a bad Preferences/extensions. |
| 1195 FilePath source_install_dir = data_dir_ | 1200 FilePath source_install_dir = data_dir_ |
| 1196 .AppendASCII("bad") | 1201 .AppendASCII("bad") |
| 1197 .AppendASCII("Extensions"); | 1202 .AppendASCII("Extensions"); |
| 1198 FilePath pref_path = source_install_dir | 1203 FilePath pref_path = source_install_dir |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2060 | 2065 |
| 2061 // A theme with extension elements. Themes cannot have extension elements, | 2066 // A theme with extension elements. Themes cannot have extension elements, |
| 2062 // so any such elements (like content scripts) should be ignored. | 2067 // so any such elements (like content scripts) should be ignored. |
| 2063 set_extensions_enabled(true); | 2068 set_extensions_enabled(true); |
| 2064 { | 2069 { |
| 2065 path = data_dir_.AppendASCII("theme_with_extension.crx"); | 2070 path = data_dir_.AppendASCII("theme_with_extension.crx"); |
| 2066 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2071 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2067 ValidatePrefKeyCount(++pref_count); | 2072 ValidatePrefKeyCount(++pref_count); |
| 2068 ASSERT_TRUE(extension); | 2073 ASSERT_TRUE(extension); |
| 2069 EXPECT_TRUE(extension->is_theme()); | 2074 EXPECT_TRUE(extension->is_theme()); |
| 2070 EXPECT_EQ(0u, extension->content_scripts().size()); | 2075 EXPECT_EQ( |
| 2076 0u, |
| 2077 extensions::ContentScriptsInfo::GetContentScripts(extension).size()); |
| 2071 } | 2078 } |
| 2072 | 2079 |
| 2073 // A theme with image resources missing (misspelt path). | 2080 // A theme with image resources missing (misspelt path). |
| 2074 path = data_dir_.AppendASCII("theme_missing_image.crx"); | 2081 path = data_dir_.AppendASCII("theme_missing_image.crx"); |
| 2075 InstallCRX(path, INSTALL_FAILED); | 2082 InstallCRX(path, INSTALL_FAILED); |
| 2076 ValidatePrefKeyCount(pref_count); | 2083 ValidatePrefKeyCount(pref_count); |
| 2077 } | 2084 } |
| 2078 | 2085 |
| 2079 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { | 2086 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
| 2080 // Load. | 2087 // Load. |
| (...skipping 3740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5821 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5828 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5822 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5829 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5823 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5830 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5824 | 5831 |
| 5825 ExtensionPrefs* prefs = service_->extension_prefs(); | 5832 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 5826 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 5833 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
| 5827 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5834 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5828 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 5835 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
| 5829 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5836 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5830 } | 5837 } |
| OLD | NEW |