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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 |
OLD | NEW |