| 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 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | |
| 339 ContentScriptDuplicateScriptInjection) { | |
| 340 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); | |
| 341 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 342 | |
| 343 GURL url( | |
| 344 base::StringPrintf("http://maps.google.com:%i/extensions/test_file.html", | |
| 345 embedded_test_server()->port())); | |
| 346 | |
| 347 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | |
| 348 "content_scripts/duplicate_script_injection"))); | |
| 349 | |
| 350 ui_test_utils::NavigateToURL(browser(), url); | |
| 351 | |
| 352 // Test that a script that matches two separate, yet overlapping match | |
| 353 // patterns is only injected once. | |
| 354 bool scripts_injected_once = false; | |
| 355 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 356 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 357 "window.domAutomationController.send(" | |
| 358 "document.getElementsByClassName('injected-once')" | |
| 359 ".length == 1)", | |
| 360 &scripts_injected_once)); | |
| 361 ASSERT_TRUE(scripts_injected_once); | |
| 362 | |
| 363 // Test that a script injected at two different load process times, document | |
| 364 // idle and document end, is injected exactly twice. | |
| 365 bool scripts_injected_twice = false; | |
| 366 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 367 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 368 "window.domAutomationController.send(" | |
| 369 "document.getElementsByClassName('injected-twice')" | |
| 370 ".length == 2)", | |
| 371 &scripts_injected_twice)); | |
| 372 ASSERT_TRUE(scripts_injected_twice); | |
| 373 } | |
| 374 | |
| 375 IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest, | 338 IN_PROC_BROWSER_TEST_F(ContentScriptCssInjectionTest, |
| 376 ContentScriptInjectsStyles) { | 339 ContentScriptInjectsStyles) { |
| 377 ASSERT_TRUE(StartEmbeddedTestServer()); | 340 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 378 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); | 341 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); |
| 379 | 342 |
| 380 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") | 343 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") |
| 381 .AppendASCII("css_injection"))); | 344 .AppendASCII("css_injection"))); |
| 382 | 345 |
| 383 // CSS injection should be allowed on an aribitrary web page. | 346 // CSS injection should be allowed on an aribitrary web page. |
| 384 GURL url = | 347 GURL url = |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); | 629 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); |
| 667 ExtensionTestMessageListener content_script_listener("script injected", | 630 ExtensionTestMessageListener content_script_listener("script injected", |
| 668 false); | 631 false); |
| 669 LoadExtension(data_dir.AppendASCII("script_a_com")); | 632 LoadExtension(data_dir.AppendASCII("script_a_com")); |
| 670 LoadExtension(data_dir.AppendASCII("background_page_iframe")); | 633 LoadExtension(data_dir.AppendASCII("background_page_iframe")); |
| 671 iframe_loaded_listener.WaitUntilSatisfied(); | 634 iframe_loaded_listener.WaitUntilSatisfied(); |
| 672 EXPECT_FALSE(content_script_listener.was_satisfied()); | 635 EXPECT_FALSE(content_script_listener.was_satisfied()); |
| 673 } | 636 } |
| 674 | 637 |
| 675 } // namespace extensions | 638 } // namespace extensions |
| OLD | NEW |