OLD | NEW |
---|---|
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 // could lead to spoofing). Unfortunately, host_resolver seems to have | 328 // could lead to spoofing). Unfortunately, host_resolver seems to have |
329 // problems with redirecting "chrome.google.com" to the test server, so we | 329 // problems with redirecting "chrome.google.com" to the test server, so we |
330 // can't use the real Webstore's URL. If this changes, we could clean this | 330 // can't use the real Webstore's URL. If this changes, we could clean this |
331 // up. | 331 // up. |
332 command_line->AppendSwitchASCII( | 332 command_line->AppendSwitchASCII( |
333 switches::kAppsGalleryURL, | 333 switches::kAppsGalleryURL, |
334 base::StringPrintf("http://%s", kWebstoreDomain)); | 334 base::StringPrintf("http://%s", kWebstoreDomain)); |
335 } | 335 } |
336 }; | 336 }; |
337 | 337 |
338 // Test that a script that matches two separate match patterns is only | |
339 // injected once. | |
340 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | |
341 ContentScriptDuplicateScriptInjection) { | |
342 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); | |
343 ASSERT_TRUE(StartEmbeddedTestServer()); | |
344 | |
345 GURL url = GURL( | |
346 base::StringPrintf("http://maps.google.com:%i/extensions/test_file.html", | |
347 embedded_test_server()->port())); | |
348 | |
349 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | |
350 "content_scripts/duplicate_script_injection"))); | |
351 | |
352 ui_test_utils::NavigateToURL(browser(), url); | |
353 | |
354 bool scripts_injected_once = false; | |
355 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
356 browser()->tab_strip_model()->GetActiveWebContents(), | |
357 "window.domAutomationController.send(" | |
358 "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
| |
359 ".length == 1)", | |
360 &scripts_injected_once)); | |
361 ASSERT_TRUE(scripts_injected_once); | |
362 } | |
363 | |
338 IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest, | 364 IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest, |
339 ContentScriptInjectsStyles) { | 365 ContentScriptInjectsStyles) { |
340 ASSERT_TRUE(StartEmbeddedTestServer()); | 366 ASSERT_TRUE(StartEmbeddedTestServer()); |
341 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); | 367 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); |
342 | 368 |
343 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") | 369 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") |
344 .AppendASCII("css_injection"))); | 370 .AppendASCII("css_injection"))); |
345 | 371 |
346 // CSS injection should be allowed on an aribitrary web page. | 372 // CSS injection should be allowed on an aribitrary web page. |
347 GURL url = | 373 GURL url = |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); | 655 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); |
630 ExtensionTestMessageListener content_script_listener("script injected", | 656 ExtensionTestMessageListener content_script_listener("script injected", |
631 false); | 657 false); |
632 LoadExtension(data_dir.AppendASCII("script_a_com")); | 658 LoadExtension(data_dir.AppendASCII("script_a_com")); |
633 LoadExtension(data_dir.AppendASCII("background_page_iframe")); | 659 LoadExtension(data_dir.AppendASCII("background_page_iframe")); |
634 iframe_loaded_listener.WaitUntilSatisfied(); | 660 iframe_loaded_listener.WaitUntilSatisfied(); |
635 EXPECT_FALSE(content_script_listener.was_satisfied()); | 661 EXPECT_FALSE(content_script_listener.was_satisfied()); |
636 } | 662 } |
637 | 663 |
638 } // namespace extensions | 664 } // namespace extensions |
OLD | NEW |