Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 11724002: Move ContentScripts out of Extension (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Wider net for registration Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/manifest_url_handler.h" 70 #include "chrome/common/extensions/manifest_url_handler.h"
70 #include "chrome/common/extensions/permissions/permission_set.h" 71 #include "chrome/common/extensions/permissions/permission_set.h"
71 #include "chrome/common/pref_names.h" 72 #include "chrome/common/pref_names.h"
72 #include "chrome/common/url_constants.h" 73 #include "chrome/common/url_constants.h"
73 #include "chrome/test/base/testing_profile.h" 74 #include "chrome/test/base/testing_profile.h"
74 #include "content/public/browser/dom_storage_context.h" 75 #include "content/public/browser/dom_storage_context.h"
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 ValidateIntegerPref(good1, "state", Extension::ENABLED); 1129 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1129 ValidateIntegerPref(good1, "location", Extension::INTERNAL); 1130 ValidateIntegerPref(good1, "location", Extension::INTERNAL);
1130 ValidateIntegerPref(good2, "state", Extension::ENABLED); 1131 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1131 ValidateIntegerPref(good2, "location", Extension::INTERNAL); 1132 ValidateIntegerPref(good2, "location", Extension::INTERNAL);
1132 1133
1133 URLPatternSet expected_patterns; 1134 URLPatternSet expected_patterns;
1134 AddPattern(&expected_patterns, "file:///*"); 1135 AddPattern(&expected_patterns, "file:///*");
1135 AddPattern(&expected_patterns, "http://*.google.com/*"); 1136 AddPattern(&expected_patterns, "http://*.google.com/*");
1136 AddPattern(&expected_patterns, "https://*.google.com/*"); 1137 AddPattern(&expected_patterns, "https://*.google.com/*");
1137 const Extension* extension = loaded_[0]; 1138 const Extension* extension = loaded_[0];
1138 const extensions::UserScriptList& scripts = extension->content_scripts(); 1139 const extensions::UserScriptList& scripts =
1140 extensions::ContentScriptsInfo::GetContentScripts(extension);
1139 ASSERT_EQ(2u, scripts.size()); 1141 ASSERT_EQ(2u, scripts.size());
1140 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); 1142 EXPECT_EQ(expected_patterns, scripts[0].url_patterns());
1141 EXPECT_EQ(2u, scripts[0].js_scripts().size()); 1143 EXPECT_EQ(2u, scripts[0].js_scripts().size());
1142 ExtensionResource resource00(extension->id(), 1144 ExtensionResource resource00(extension->id(),
1143 scripts[0].js_scripts()[0].extension_root(), 1145 scripts[0].js_scripts()[0].extension_root(),
1144 scripts[0].js_scripts()[0].relative_path()); 1146 scripts[0].js_scripts()[0].relative_path());
1145 FilePath expected_path(extension->path().AppendASCII("script1.js")); 1147 FilePath expected_path(extension->path().AppendASCII("script1.js"));
1146 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); 1148 ASSERT_TRUE(file_util::AbsolutePath(&expected_path));
1147 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); 1149 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path));
1148 ExtensionResource resource01(extension->id(), 1150 ExtensionResource resource01(extension->id(),
(...skipping 18 matching lines...) Expand all
1167 AddPattern(&expected_patterns, "http://*.google.com/*"); 1169 AddPattern(&expected_patterns, "http://*.google.com/*");
1168 AddPattern(&expected_patterns, "https://*.google.com/*"); 1170 AddPattern(&expected_patterns, "https://*.google.com/*");
1169 EXPECT_EQ(expected_patterns, 1171 EXPECT_EQ(expected_patterns,
1170 extension->GetActivePermissions()->explicit_hosts()); 1172 extension->GetActivePermissions()->explicit_hosts());
1171 1173
1172 EXPECT_EQ(std::string(good1), loaded_[1]->id()); 1174 EXPECT_EQ(std::string(good1), loaded_[1]->id());
1173 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); 1175 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
1174 EXPECT_EQ(std::string(""), loaded_[1]->description()); 1176 EXPECT_EQ(std::string(""), loaded_[1]->description());
1175 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), 1177 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"),
1176 loaded_[1]->GetBackgroundURL()); 1178 loaded_[1]->GetBackgroundURL());
1177 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); 1179 EXPECT_EQ(
1180 0u, extensions::ContentScriptsInfo::GetContentScripts(loaded_[1]).size());
1178 // We don't parse the plugins section on Chrome OS. 1181 // We don't parse the plugins section on Chrome OS.
1179 #if defined(OS_CHROMEOS) 1182 #if defined(OS_CHROMEOS)
1180 EXPECT_EQ(0u, loaded_[1]->plugins().size()); 1183 EXPECT_EQ(0u, loaded_[1]->plugins().size());
1181 #else 1184 #else
1182 ASSERT_EQ(2u, loaded_[1]->plugins().size()); 1185 ASSERT_EQ(2u, loaded_[1]->plugins().size());
1183 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), 1186 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(),
1184 loaded_[1]->plugins()[0].path.value()); 1187 loaded_[1]->plugins()[0].path.value());
1185 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); 1188 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public);
1186 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), 1189 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(),
1187 loaded_[1]->plugins()[1].path.value()); 1190 loaded_[1]->plugins()[1].path.value());
1188 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); 1191 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public);
1189 #endif 1192 #endif
1190 1193
1191 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); 1194 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location());
1192 1195
1193 int index = expected_num_extensions - 1; 1196 int index = expected_num_extensions - 1;
1194 EXPECT_EQ(std::string(good2), loaded_[index]->id()); 1197 EXPECT_EQ(std::string(good2), loaded_[index]->id());
1195 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); 1198 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name());
1196 EXPECT_EQ(std::string(""), loaded_[index]->description()); 1199 EXPECT_EQ(std::string(""), loaded_[index]->description());
1197 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); 1200 EXPECT_EQ(
1201 0u,
1202 extensions::ContentScriptsInfo::GetContentScripts(loaded_[index]).size());
1198 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); 1203 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location());
1199 }; 1204 };
1200 1205
1201 // Test loading bad extensions from the profile directory. 1206 // Test loading bad extensions from the profile directory.
1202 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { 1207 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
1203 // Initialize the test dir with a bad Preferences/extensions. 1208 // Initialize the test dir with a bad Preferences/extensions.
1204 FilePath source_install_dir = data_dir_ 1209 FilePath source_install_dir = data_dir_
1205 .AppendASCII("bad") 1210 .AppendASCII("bad")
1206 .AppendASCII("Extensions"); 1211 .AppendASCII("Extensions");
1207 FilePath pref_path = source_install_dir 1212 FilePath pref_path = source_install_dir
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 2074
2070 // A theme with extension elements. Themes cannot have extension elements, 2075 // A theme with extension elements. Themes cannot have extension elements,
2071 // so any such elements (like content scripts) should be ignored. 2076 // so any such elements (like content scripts) should be ignored.
2072 set_extensions_enabled(true); 2077 set_extensions_enabled(true);
2073 { 2078 {
2074 path = data_dir_.AppendASCII("theme_with_extension.crx"); 2079 path = data_dir_.AppendASCII("theme_with_extension.crx");
2075 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2080 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2076 ValidatePrefKeyCount(++pref_count); 2081 ValidatePrefKeyCount(++pref_count);
2077 ASSERT_TRUE(extension); 2082 ASSERT_TRUE(extension);
2078 EXPECT_TRUE(extension->is_theme()); 2083 EXPECT_TRUE(extension->is_theme());
2079 EXPECT_EQ(0u, extension->content_scripts().size()); 2084 EXPECT_EQ(
2085 0u,
2086 extensions::ContentScriptsInfo::GetContentScripts(extension).size());
2080 } 2087 }
2081 2088
2082 // A theme with image resources missing (misspelt path). 2089 // A theme with image resources missing (misspelt path).
2083 path = data_dir_.AppendASCII("theme_missing_image.crx"); 2090 path = data_dir_.AppendASCII("theme_missing_image.crx");
2084 InstallCRX(path, INSTALL_FAILED); 2091 InstallCRX(path, INSTALL_FAILED);
2085 ValidatePrefKeyCount(pref_count); 2092 ValidatePrefKeyCount(pref_count);
2086 } 2093 }
2087 2094
2088 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 2095 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
2089 // Load. 2096 // Load.
(...skipping 3741 matching lines...) Expand 10 before | Expand all | Expand 10 after
5831 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5838 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5832 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5839 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5833 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5840 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5834 5841
5835 ExtensionPrefs* prefs = service_->extension_prefs(); 5842 ExtensionPrefs* prefs = service_->extension_prefs();
5836 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5843 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5837 Extension::DISABLE_SIDELOAD_WIPEOUT); 5844 Extension::DISABLE_SIDELOAD_WIPEOUT);
5838 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5845 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5839 Extension::DISABLE_SIDELOAD_WIPEOUT); 5846 Extension::DISABLE_SIDELOAD_WIPEOUT);
5840 } 5847 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698