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

Unified Diff: chrome/browser/extensions/content_script_apitest.cc

Issue 2213603002: Prevent duplicate content script injection defined in manifest.json (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed lgtm nits Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/content_scripts/duplicate_script_injection/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/content_script_apitest.cc
diff --git a/chrome/browser/extensions/content_script_apitest.cc b/chrome/browser/extensions/content_script_apitest.cc
index 4615de0ac247ce6edd891f1b8a49fd136b1bdaa5..a2c897ffd5f1299abfa656186f31c011472875ec 100644
--- a/chrome/browser/extensions/content_script_apitest.cc
+++ b/chrome/browser/extensions/content_script_apitest.cc
@@ -334,6 +334,43 @@ class ContentScriptCssInjectionTest : public ExtensionApiTest {
}
};
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
+ ContentScriptDuplicateScriptInjection) {
+ host_resolver()->AddRule("maps.google.com", "127.0.0.1");
+ ASSERT_TRUE(StartEmbeddedTestServer());
+
+ GURL url(
+ base::StringPrintf("http://maps.google.com:%i/extensions/test_file.html",
+ embedded_test_server()->port()));
+
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
+ "content_scripts/duplicate_script_injection")));
+
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // Test that a script that matches two separate, yet overlapping match
+ // patterns is only injected once.
+ bool scripts_injected_once = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ "window.domAutomationController.send("
+ "document.getElementsByClassName('injected-once')"
+ ".length == 1)",
+ &scripts_injected_once));
+ ASSERT_TRUE(scripts_injected_once);
+
+ // Test that a script injected at two different load process times, document
+ // idle and document end, is injected exactly twice.
+ bool scripts_injected_twice = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ "window.domAutomationController.send("
+ "document.getElementsByClassName('injected-twice')"
+ ".length == 2)",
+ &scripts_injected_twice));
+ ASSERT_TRUE(scripts_injected_twice);
+}
+
IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest,
ContentScriptInjectsStyles) {
ASSERT_TRUE(StartEmbeddedTestServer());
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/content_scripts/duplicate_script_injection/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698