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

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

Issue 2116613002: Prevent duplicate content script injection defined in manifest.json (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed code review comments Created 4 years, 5 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
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 c8d442885dff659576a6f2f6fc95385d298d0f84..2455dbe020d087b5371845171c6191ff85d95b66 100644
--- a/chrome/browser/extensions/content_script_apitest.cc
+++ b/chrome/browser/extensions/content_script_apitest.cc
@@ -335,6 +335,32 @@ class ContentScriptCssInjectionTest : public ExtensionApiTest {
}
};
+// Test that a script that matches two separate match patterns is only
+// injected once.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
+ ContentScriptDuplicateScriptInjection) {
+ host_resolver()->AddRule("maps.google.com", "127.0.0.1");
+ ASSERT_TRUE(StartEmbeddedTestServer());
+
+ GURL url = GURL(
+ 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);
+
+ bool scripts_injected_once = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ "window.domAutomationController.send("
+ "document.getElementsByClassName('test-duplicate-script-injection')"
Devlin 2016/07/12 23:32:36 hmm... git cl format seemed to miss this. I'll ta
catmullings 2016/07/13 17:25:33 As discussed, this is the format chosen by git cl
+ ".length == 1)",
+ &scripts_injected_once));
+ ASSERT_TRUE(scripts_injected_once);
+}
+
IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest,
ContentScriptInjectsStyles) {
ASSERT_TRUE(StartEmbeddedTestServer());

Powered by Google App Engine
This is Rietveld 408576698