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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // could lead to spoofing). Unfortunately, host_resolver seems to have 327 // could lead to spoofing). Unfortunately, host_resolver seems to have
328 // problems with redirecting "chrome.google.com" to the test server, so we 328 // problems with redirecting "chrome.google.com" to the test server, so we
329 // can't use the real Webstore's URL. If this changes, we could clean this 329 // can't use the real Webstore's URL. If this changes, we could clean this
330 // up. 330 // up.
331 command_line->AppendSwitchASCII( 331 command_line->AppendSwitchASCII(
332 switches::kAppsGalleryURL, 332 switches::kAppsGalleryURL,
333 base::StringPrintf("http://%s", kWebstoreDomain)); 333 base::StringPrintf("http://%s", kWebstoreDomain));
334 } 334 }
335 }; 335 };
336 336
337 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
338 ContentScriptDuplicateScriptInjection) {
339 host_resolver()->AddRule("maps.google.com", "127.0.0.1");
340 ASSERT_TRUE(StartEmbeddedTestServer());
341
342 GURL url(
343 base::StringPrintf("http://maps.google.com:%i/extensions/test_file.html",
344 embedded_test_server()->port()));
345
346 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
347 "content_scripts/duplicate_script_injection")));
348
349 ui_test_utils::NavigateToURL(browser(), url);
350
351 // Test that a script that matches two separate, yet overlapping match
352 // patterns is only injected once.
353 bool scripts_injected_once = false;
354 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
355 browser()->tab_strip_model()->GetActiveWebContents(),
356 "window.domAutomationController.send("
357 "document.getElementsByClassName('injected-once')"
358 ".length == 1)",
359 &scripts_injected_once));
360 ASSERT_TRUE(scripts_injected_once);
361
362 // Test that a script injected at two different load process times, document
363 // idle and document end, is injected exactly twice.
364 bool scripts_injected_twice = false;
365 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
366 browser()->tab_strip_model()->GetActiveWebContents(),
367 "window.domAutomationController.send("
368 "document.getElementsByClassName('injected-twice')"
369 ".length == 2)",
370 &scripts_injected_twice));
371 ASSERT_TRUE(scripts_injected_twice);
372 }
373
337 IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest, 374 IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest,
338 ContentScriptInjectsStyles) { 375 ContentScriptInjectsStyles) {
339 ASSERT_TRUE(StartEmbeddedTestServer()); 376 ASSERT_TRUE(StartEmbeddedTestServer());
340 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); 377 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1");
341 378
342 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") 379 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts")
343 .AppendASCII("css_injection"))); 380 .AppendASCII("css_injection")));
344 381
345 // CSS injection should be allowed on an aribitrary web page. 382 // CSS injection should be allowed on an aribitrary web page.
346 GURL url = 383 GURL url =
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); 660 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false);
624 ExtensionTestMessageListener content_script_listener("script injected", 661 ExtensionTestMessageListener content_script_listener("script injected",
625 false); 662 false);
626 LoadExtension(data_dir.AppendASCII("script_a_com")); 663 LoadExtension(data_dir.AppendASCII("script_a_com"));
627 LoadExtension(data_dir.AppendASCII("background_page_iframe")); 664 LoadExtension(data_dir.AppendASCII("background_page_iframe"));
628 iframe_loaded_listener.WaitUntilSatisfied(); 665 iframe_loaded_listener.WaitUntilSatisfied();
629 EXPECT_FALSE(content_script_listener.was_satisfied()); 666 EXPECT_FALSE(content_script_listener.was_satisfied());
630 } 667 }
631 668
632 } // namespace extensions 669 } // namespace extensions
OLDNEW
« 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