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

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: 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/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 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 ValidateIntegerPref(good1, "state", Extension::ENABLED); 1114 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1114 ValidateIntegerPref(good1, "location", Extension::INTERNAL); 1115 ValidateIntegerPref(good1, "location", Extension::INTERNAL);
1115 ValidateIntegerPref(good2, "state", Extension::ENABLED); 1116 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1116 ValidateIntegerPref(good2, "location", Extension::INTERNAL); 1117 ValidateIntegerPref(good2, "location", Extension::INTERNAL);
1117 1118
1118 URLPatternSet expected_patterns; 1119 URLPatternSet expected_patterns;
1119 AddPattern(&expected_patterns, "file:///*"); 1120 AddPattern(&expected_patterns, "file:///*");
1120 AddPattern(&expected_patterns, "http://*.google.com/*"); 1121 AddPattern(&expected_patterns, "http://*.google.com/*");
1121 AddPattern(&expected_patterns, "https://*.google.com/*"); 1122 AddPattern(&expected_patterns, "https://*.google.com/*");
1122 const Extension* extension = loaded_[0]; 1123 const Extension* extension = loaded_[0];
1123 const extensions::UserScriptList& scripts = extension->content_scripts(); 1124 const extensions::UserScriptList& scripts =
1125 extensions::ContentScriptsInfo::GetContentScripts(extension);
1124 ASSERT_EQ(2u, scripts.size()); 1126 ASSERT_EQ(2u, scripts.size());
1125 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); 1127 EXPECT_EQ(expected_patterns, scripts[0].url_patterns());
1126 EXPECT_EQ(2u, scripts[0].js_scripts().size()); 1128 EXPECT_EQ(2u, scripts[0].js_scripts().size());
1127 ExtensionResource resource00(extension->id(), 1129 ExtensionResource resource00(extension->id(),
1128 scripts[0].js_scripts()[0].extension_root(), 1130 scripts[0].js_scripts()[0].extension_root(),
1129 scripts[0].js_scripts()[0].relative_path()); 1131 scripts[0].js_scripts()[0].relative_path());
1130 FilePath expected_path(extension->path().AppendASCII("script1.js")); 1132 FilePath expected_path(extension->path().AppendASCII("script1.js"));
1131 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); 1133 ASSERT_TRUE(file_util::AbsolutePath(&expected_path));
1132 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); 1134 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path));
1133 ExtensionResource resource01(extension->id(), 1135 ExtensionResource resource01(extension->id(),
(...skipping 18 matching lines...) Expand all
1152 AddPattern(&expected_patterns, "http://*.google.com/*"); 1154 AddPattern(&expected_patterns, "http://*.google.com/*");
1153 AddPattern(&expected_patterns, "https://*.google.com/*"); 1155 AddPattern(&expected_patterns, "https://*.google.com/*");
1154 EXPECT_EQ(expected_patterns, 1156 EXPECT_EQ(expected_patterns,
1155 extension->GetActivePermissions()->explicit_hosts()); 1157 extension->GetActivePermissions()->explicit_hosts());
1156 1158
1157 EXPECT_EQ(std::string(good1), loaded_[1]->id()); 1159 EXPECT_EQ(std::string(good1), loaded_[1]->id());
1158 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); 1160 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
1159 EXPECT_EQ(std::string(""), loaded_[1]->description()); 1161 EXPECT_EQ(std::string(""), loaded_[1]->description());
1160 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), 1162 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"),
1161 loaded_[1]->GetBackgroundURL()); 1163 loaded_[1]->GetBackgroundURL());
1162 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); 1164 EXPECT_EQ(
1165 0u, extensions::ContentScriptsInfo::GetContentScripts(loaded_[1]).size());
1163 // We don't parse the plugins section on Chrome OS. 1166 // We don't parse the plugins section on Chrome OS.
1164 #if defined(OS_CHROMEOS) 1167 #if defined(OS_CHROMEOS)
1165 EXPECT_EQ(0u, loaded_[1]->plugins().size()); 1168 EXPECT_EQ(0u, loaded_[1]->plugins().size());
1166 #else 1169 #else
1167 ASSERT_EQ(2u, loaded_[1]->plugins().size()); 1170 ASSERT_EQ(2u, loaded_[1]->plugins().size());
1168 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), 1171 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(),
1169 loaded_[1]->plugins()[0].path.value()); 1172 loaded_[1]->plugins()[0].path.value());
1170 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); 1173 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public);
1171 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), 1174 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(),
1172 loaded_[1]->plugins()[1].path.value()); 1175 loaded_[1]->plugins()[1].path.value());
1173 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); 1176 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public);
1174 #endif 1177 #endif
1175 1178
1176 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); 1179 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location());
1177 1180
1178 int index = expected_num_extensions - 1; 1181 int index = expected_num_extensions - 1;
1179 EXPECT_EQ(std::string(good2), loaded_[index]->id()); 1182 EXPECT_EQ(std::string(good2), loaded_[index]->id());
1180 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); 1183 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name());
1181 EXPECT_EQ(std::string(""), loaded_[index]->description()); 1184 EXPECT_EQ(std::string(""), loaded_[index]->description());
1182 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); 1185 EXPECT_EQ(
1186 0u,
1187 extensions::ContentScriptsInfo::GetContentScripts(loaded_[index]).size());
1183 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); 1188 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location());
1184 }; 1189 };
1185 1190
1186 // Test loading bad extensions from the profile directory. 1191 // Test loading bad extensions from the profile directory.
1187 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { 1192 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
1188 // Initialize the test dir with a bad Preferences/extensions. 1193 // Initialize the test dir with a bad Preferences/extensions.
1189 FilePath source_install_dir = data_dir_ 1194 FilePath source_install_dir = data_dir_
1190 .AppendASCII("bad") 1195 .AppendASCII("bad")
1191 .AppendASCII("Extensions"); 1196 .AppendASCII("Extensions");
1192 FilePath pref_path = source_install_dir 1197 FilePath pref_path = source_install_dir
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 2059
2055 // A theme with extension elements. Themes cannot have extension elements, 2060 // A theme with extension elements. Themes cannot have extension elements,
2056 // so any such elements (like content scripts) should be ignored. 2061 // so any such elements (like content scripts) should be ignored.
2057 set_extensions_enabled(true); 2062 set_extensions_enabled(true);
2058 { 2063 {
2059 path = data_dir_.AppendASCII("theme_with_extension.crx"); 2064 path = data_dir_.AppendASCII("theme_with_extension.crx");
2060 const Extension* extension = InstallCRX(path, INSTALL_NEW); 2065 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2061 ValidatePrefKeyCount(++pref_count); 2066 ValidatePrefKeyCount(++pref_count);
2062 ASSERT_TRUE(extension); 2067 ASSERT_TRUE(extension);
2063 EXPECT_TRUE(extension->is_theme()); 2068 EXPECT_TRUE(extension->is_theme());
2064 EXPECT_EQ(0u, extension->content_scripts().size()); 2069 EXPECT_EQ(
2070 0u,
2071 extensions::ContentScriptsInfo::GetContentScripts(extension).size());
2065 } 2072 }
2066 2073
2067 // A theme with image resources missing (misspelt path). 2074 // A theme with image resources missing (misspelt path).
2068 path = data_dir_.AppendASCII("theme_missing_image.crx"); 2075 path = data_dir_.AppendASCII("theme_missing_image.crx");
2069 InstallCRX(path, INSTALL_FAILED); 2076 InstallCRX(path, INSTALL_FAILED);
2070 ValidatePrefKeyCount(pref_count); 2077 ValidatePrefKeyCount(pref_count);
2071 } 2078 }
2072 2079
2073 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 2080 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
2074 // Load. 2081 // Load.
(...skipping 3721 matching lines...) Expand 10 before | Expand all | Expand 10 after
5796 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5803 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5797 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5804 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5798 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5805 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5799 5806
5800 ExtensionPrefs* prefs = service_->extension_prefs(); 5807 ExtensionPrefs* prefs = service_->extension_prefs();
5801 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5808 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5802 Extension::DISABLE_SIDELOAD_WIPEOUT); 5809 Extension::DISABLE_SIDELOAD_WIPEOUT);
5803 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5810 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5804 Extension::DISABLE_SIDELOAD_WIPEOUT); 5811 Extension::DISABLE_SIDELOAD_WIPEOUT);
5805 } 5812 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698