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

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

Powered by Google App Engine
This is Rietveld 408576698