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

Side by Side Diff: chrome/browser/extensions/content_script_apitest.cc

Issue 2633253002: Split content script injections into multiple tasks (Closed)
Patch Set: Inject document_idle scripts before window.onload Created 3 years, 10 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
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 10 matching lines...) Expand all
21 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
22 #include "components/app_modal/javascript_dialog_extensions_client.h" 22 #include "components/app_modal/javascript_dialog_extensions_client.h"
23 #include "components/app_modal/javascript_dialog_manager.h" 23 #include "components/app_modal/javascript_dialog_manager.h"
24 #include "content/public/browser/javascript_dialog_manager.h" 24 #include "content/public/browser/javascript_dialog_manager.h"
25 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
28 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
29 #include "extensions/browser/notification_types.h" 29 #include "extensions/browser/notification_types.h"
30 #include "extensions/common/extension.h" 30 #include "extensions/common/extension.h"
31 #include "extensions/common/switches.h"
31 #include "extensions/test/extension_test_message_listener.h" 32 #include "extensions/test/extension_test_message_listener.h"
32 #include "extensions/test/result_catcher.h" 33 #include "extensions/test/result_catcher.h"
33 #include "net/dns/mock_host_resolver.h" 34 #include "net/dns/mock_host_resolver.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h" 35 #include "net/test/embedded_test_server/embedded_test_server.h"
35 #include "url/gurl.h" 36 #include "url/gurl.h"
36 37
37 namespace extensions { 38 namespace extensions {
38 39
39 namespace { 40 namespace {
40 41
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 " \"version\": \"0.1\"," 226 " \"version\": \"0.1\","
226 " \"manifest_version\": 2," 227 " \"manifest_version\": 2,"
227 " \"description\": \"Foo!\"," 228 " \"description\": \"Foo!\","
228 " \"chrome_url_overrides\": {\"newtab\": \"newtab.html\"}" 229 " \"chrome_url_overrides\": {\"newtab\": \"newtab.html\"}"
229 "}"; 230 "}";
230 231
231 const char kNewTabHtml[] = "<html>NewTabOverride!</html>"; 232 const char kNewTabHtml[] = "<html>NewTabOverride!</html>";
232 233
233 } // namespace 234 } // namespace
234 235
235 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { 236 enum class TestConfig {
237 kDefault,
238 kYieldBetweenContentScriptRunsEnabled,
239 };
240
241 class ContentScriptApiTest : public ExtensionApiTest,
242 public testing::WithParamInterface<TestConfig> {
243 public:
244 void SetUpCommandLine(base::CommandLine* command_line) override {
245 ExtensionApiTest::SetUpCommandLine(command_line);
246 command_line->AppendSwitchASCII(
247 switches::kYieldBetweenContentScriptRuns,
248 (GetParam() == TestConfig::kYieldBetweenContentScriptRunsEnabled) ?
249 "1" : "0");
250 }
251 };
252
253 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptAllFrames) {
236 ASSERT_TRUE(StartEmbeddedTestServer()); 254 ASSERT_TRUE(StartEmbeddedTestServer());
237 ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; 255 ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_;
238 } 256 }
239 257
240 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAboutBlankIframes) { 258 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptAboutBlankIframes) {
241 ASSERT_TRUE(StartEmbeddedTestServer()); 259 ASSERT_TRUE(StartEmbeddedTestServer());
242 ASSERT_TRUE( 260 ASSERT_TRUE(
243 RunExtensionTest("content_scripts/about_blank_iframes")) << message_; 261 RunExtensionTest("content_scripts/about_blank_iframes")) << message_;
244 } 262 }
245 263
246 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAboutBlankAndSrcdoc) { 264 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptAboutBlankAndSrcdoc) {
247 // The optional "*://*/*" permission is requested after verifying that 265 // The optional "*://*/*" permission is requested after verifying that
248 // content script insertion solely depends on content_scripts[*].matches. 266 // content script insertion solely depends on content_scripts[*].matches.
249 // The permission is needed for chrome.tabs.executeScript tests. 267 // The permission is needed for chrome.tabs.executeScript tests.
250 PermissionsRequestFunction::SetAutoConfirmForTests(true); 268 PermissionsRequestFunction::SetAutoConfirmForTests(true);
251 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 269 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
252 270
253 ASSERT_TRUE(StartEmbeddedTestServer()); 271 ASSERT_TRUE(StartEmbeddedTestServer());
254 ASSERT_TRUE(RunExtensionTest("content_scripts/about_blank_srcdoc")) 272 ASSERT_TRUE(RunExtensionTest("content_scripts/about_blank_srcdoc"))
255 << message_; 273 << message_;
256 } 274 }
257 275
258 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) { 276 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptExtensionIframe) {
259 ASSERT_TRUE(StartEmbeddedTestServer()); 277 ASSERT_TRUE(StartEmbeddedTestServer());
260 ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_; 278 ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_;
261 } 279 }
262 280
263 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) { 281 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptExtensionProcess) {
264 ASSERT_TRUE(StartEmbeddedTestServer()); 282 ASSERT_TRUE(StartEmbeddedTestServer());
265 ASSERT_TRUE( 283 ASSERT_TRUE(
266 RunExtensionTest("content_scripts/extension_process")) << message_; 284 RunExtensionTest("content_scripts/extension_process")) << message_;
267 } 285 }
268 286
269 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) { 287 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptFragmentNavigation) {
270 ASSERT_TRUE(StartEmbeddedTestServer()); 288 ASSERT_TRUE(StartEmbeddedTestServer());
271 const char extension_name[] = "content_scripts/fragment"; 289 const char extension_name[] = "content_scripts/fragment";
272 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; 290 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
273 } 291 }
274 292
275 // Times out on Linux: http://crbug.com/163097 293 // Times out on Linux: http://crbug.com/163097
276 #if defined(OS_LINUX) 294 #if defined(OS_LINUX)
277 #define MAYBE_ContentScriptIsolatedWorlds DISABLED_ContentScriptIsolatedWorlds 295 #define MAYBE_ContentScriptIsolatedWorlds DISABLED_ContentScriptIsolatedWorlds
278 #else 296 #else
279 #define MAYBE_ContentScriptIsolatedWorlds ContentScriptIsolatedWorlds 297 #define MAYBE_ContentScriptIsolatedWorlds ContentScriptIsolatedWorlds
280 #endif 298 #endif
281 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptIsolatedWorlds) { 299 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
300 MAYBE_ContentScriptIsolatedWorlds) {
282 // This extension runs various bits of script and tests that they all run in 301 // This extension runs various bits of script and tests that they all run in
283 // the same isolated world. 302 // the same isolated world.
284 ASSERT_TRUE(StartEmbeddedTestServer()); 303 ASSERT_TRUE(StartEmbeddedTestServer());
285 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_; 304 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_;
286 305
287 // Now load a different extension, inject into same page, verify worlds aren't 306 // Now load a different extension, inject into same page, verify worlds aren't
288 // shared. 307 // shared.
289 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world2")) << message_; 308 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world2")) << message_;
290 } 309 }
291 310
292 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptIgnoreHostPermissions) { 311 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
312 ContentScriptIgnoreHostPermissions) {
293 host_resolver()->AddRule("a.com", "127.0.0.1"); 313 host_resolver()->AddRule("a.com", "127.0.0.1");
294 host_resolver()->AddRule("b.com", "127.0.0.1"); 314 host_resolver()->AddRule("b.com", "127.0.0.1");
295 ASSERT_TRUE(StartEmbeddedTestServer()); 315 ASSERT_TRUE(StartEmbeddedTestServer());
296 ASSERT_TRUE(RunExtensionTest( 316 ASSERT_TRUE(RunExtensionTest(
297 "content_scripts/dont_match_host_permissions")) << message_; 317 "content_scripts/dont_match_host_permissions")) << message_;
298 } 318 }
299 319
300 // crbug.com/39249 -- content scripts js should not run on view source. 320 // crbug.com/39249 -- content scripts js should not run on view source.
301 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptViewSource) { 321 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptViewSource) {
302 ASSERT_TRUE(StartEmbeddedTestServer()); 322 ASSERT_TRUE(StartEmbeddedTestServer());
303 ASSERT_TRUE(RunExtensionTest("content_scripts/view_source")) << message_; 323 ASSERT_TRUE(RunExtensionTest("content_scripts/view_source")) << message_;
304 } 324 }
305 325
306 // crbug.com/126257 -- content scripts should not get injected into other 326 // crbug.com/126257 -- content scripts should not get injected into other
307 // extensions. 327 // extensions.
308 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptOtherExtensions) { 328 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptOtherExtensions) {
309 host_resolver()->AddRule("a.com", "127.0.0.1"); 329 host_resolver()->AddRule("a.com", "127.0.0.1");
310 ASSERT_TRUE(StartEmbeddedTestServer()); 330 ASSERT_TRUE(StartEmbeddedTestServer());
311 // First, load extension that sets up content script. 331 // First, load extension that sets up content script.
312 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/injector")) 332 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/injector"))
313 << message_; 333 << message_;
314 // Then load targeted extension to make sure its content isn't changed. 334 // Then load targeted extension to make sure its content isn't changed.
315 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/victim")) 335 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/victim"))
316 << message_; 336 << message_;
317 } 337 }
318 338
319 class ContentScriptCssInjectionTest : public ExtensionApiTest { 339 class ContentScriptCssInjectionTest : public ExtensionApiTest {
320 protected: 340 protected:
321 // TODO(rdevlin.cronin): Make a testing switch that looks like FeatureSwitch, 341 // TODO(rdevlin.cronin): Make a testing switch that looks like FeatureSwitch,
322 // but takes in an optional value so that we don't have to do this. 342 // but takes in an optional value so that we don't have to do this.
323 void SetUpCommandLine(base::CommandLine* command_line) override { 343 void SetUpCommandLine(base::CommandLine* command_line) override {
324 ExtensionApiTest::SetUpCommandLine(command_line); 344 ExtensionApiTest::SetUpCommandLine(command_line);
325 // We change the Webstore URL to be http://cws.com. We need to do this so 345 // We change the Webstore URL to be http://cws.com. We need to do this so
326 // we can check that css injection is not allowed on the webstore (which 346 // we can check that css injection is not allowed on the webstore (which
327 // could lead to spoofing). Unfortunately, host_resolver seems to have 347 // could lead to spoofing). Unfortunately, host_resolver seems to have
328 // problems with redirecting "chrome.google.com" to the test server, so we 348 // 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 349 // can't use the real Webstore's URL. If this changes, we could clean this
330 // up. 350 // up.
331 command_line->AppendSwitchASCII( 351 command_line->AppendSwitchASCII(
332 switches::kAppsGalleryURL, 352 ::switches::kAppsGalleryURL,
333 base::StringPrintf("http://%s", kWebstoreDomain)); 353 base::StringPrintf("http://%s", kWebstoreDomain));
334 } 354 }
335 }; 355 };
336 356
337 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, 357 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
338 ContentScriptDuplicateScriptInjection) { 358 ContentScriptDuplicateScriptInjection) {
339 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); 359 host_resolver()->AddRule("maps.google.com", "127.0.0.1");
340 ASSERT_TRUE(StartEmbeddedTestServer()); 360 ASSERT_TRUE(StartEmbeddedTestServer());
341 361
342 GURL url( 362 GURL url(
343 base::StringPrintf("http://maps.google.com:%i/extensions/test_file.html", 363 base::StringPrintf("http://maps.google.com:%i/extensions/test_file.html",
344 embedded_test_server()->port())); 364 embedded_test_server()->port()));
345 365
346 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 366 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
347 "content_scripts/duplicate_script_injection"))); 367 "content_scripts/duplicate_script_injection")));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 bool styles_injected; 440 bool styles_injected;
421 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 441 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
422 browser()->tab_strip_model()->GetActiveWebContents(), 442 browser()->tab_strip_model()->GetActiveWebContents(),
423 "window.domAutomationController.send(" 443 "window.domAutomationController.send("
424 " document.defaultView.getComputedStyle(document.body, null)." 444 " document.defaultView.getComputedStyle(document.body, null)."
425 " getPropertyValue('background-color') == 'rgb(255, 0, 0)')", 445 " getPropertyValue('background-color') == 'rgb(255, 0, 0)')",
426 &styles_injected)); 446 &styles_injected));
427 ASSERT_TRUE(styles_injected); 447 ASSERT_TRUE(styles_injected);
428 } 448 }
429 449
430 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, 450 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptCSSLocalization) {
431 ContentScriptCSSLocalization) {
432 ASSERT_TRUE(StartEmbeddedTestServer()); 451 ASSERT_TRUE(StartEmbeddedTestServer());
433 ASSERT_TRUE(RunExtensionTest("content_scripts/css_l10n")) << message_; 452 ASSERT_TRUE(RunExtensionTest("content_scripts/css_l10n")) << message_;
434 } 453 }
435 454
436 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionAPIs) { 455 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptExtensionAPIs) {
437 ASSERT_TRUE(StartEmbeddedTestServer()); 456 ASSERT_TRUE(StartEmbeddedTestServer());
438 457
439 const extensions::Extension* extension = LoadExtension( 458 const extensions::Extension* extension = LoadExtension(
440 test_data_dir_.AppendASCII("content_scripts/extension_api")); 459 test_data_dir_.AppendASCII("content_scripts/extension_api"));
441 460
442 ResultCatcher catcher; 461 ResultCatcher catcher;
443 ui_test_utils::NavigateToURL( 462 ui_test_utils::NavigateToURL(
444 browser(), 463 browser(),
445 embedded_test_server()->GetURL( 464 embedded_test_server()->GetURL(
446 "/extensions/api_test/content_scripts/extension_api/functions.html")); 465 "/extensions/api_test/content_scripts/extension_api/functions.html"));
(...skipping 14 matching lines...) Expand all
461 ui_test_utils::BROWSER_TEST_NONE); 480 ui_test_utils::BROWSER_TEST_NONE);
462 EXPECT_TRUE(catcher.GetNextResult()); 481 EXPECT_TRUE(catcher.GetNextResult());
463 } 482 }
464 483
465 // Flaky on Windows. http://crbug.com/248418 484 // Flaky on Windows. http://crbug.com/248418
466 #if defined(OS_WIN) 485 #if defined(OS_WIN)
467 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi 486 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi
468 #else 487 #else
469 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi 488 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi
470 #endif 489 #endif
471 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) { 490 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
491 MAYBE_ContentScriptPermissionsApi) {
472 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 492 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
473 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true); 493 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true);
474 host_resolver()->AddRule("*.com", "127.0.0.1"); 494 host_resolver()->AddRule("*.com", "127.0.0.1");
475 ASSERT_TRUE(StartEmbeddedTestServer()); 495 ASSERT_TRUE(StartEmbeddedTestServer());
476 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; 496 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_;
477 } 497 }
478 498
479 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { 499 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptBypassPageCSP) {
480 ASSERT_TRUE(StartEmbeddedTestServer()); 500 ASSERT_TRUE(StartEmbeddedTestServer());
481 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; 501 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_;
482 } 502 }
483 503
484 // Test that when injecting a blocking content script, other scripts don't run 504 // Test that when injecting a blocking content script, other scripts don't run
485 // until the blocking script finishes. 505 // until the blocking script finishes.
486 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBlockingScript) { 506 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, ContentScriptBlockingScript) {
487 ASSERT_TRUE(StartEmbeddedTestServer()); 507 ASSERT_TRUE(StartEmbeddedTestServer());
488 508
489 // Load up two extensions. 509 // Load up two extensions.
490 TestExtensionDir ext_dir1; 510 TestExtensionDir ext_dir1;
491 ext_dir1.WriteManifest( 511 ext_dir1.WriteManifest(
492 base::StringPrintf(kManifest, "ext1", "document_start")); 512 base::StringPrintf(kManifest, "ext1", "document_start"));
493 ext_dir1.WriteFile(FILE_PATH_LITERAL("script.js"), kBlockingScript); 513 ext_dir1.WriteFile(FILE_PATH_LITERAL("script.js"), kBlockingScript);
494 const Extension* ext1 = LoadExtension(ext_dir1.UnpackedPath()); 514 const Extension* ext1 = LoadExtension(ext_dir1.UnpackedPath());
495 ASSERT_TRUE(ext1); 515 ASSERT_TRUE(ext1);
496 516
(...skipping 24 matching lines...) Expand all
521 EXPECT_EQ(1u, dialog_helper.dialog_count()); 541 EXPECT_EQ(1u, dialog_helper.dialog_count());
522 dialog_helper.CloseDialogs(); 542 dialog_helper.CloseDialogs();
523 543
524 // After closing the dialog, the rest of the scripts should be able to 544 // After closing the dialog, the rest of the scripts should be able to
525 // inject. 545 // inject.
526 EXPECT_TRUE(listener.WaitUntilSatisfied()); 546 EXPECT_TRUE(listener.WaitUntilSatisfied());
527 } 547 }
528 548
529 // Test that closing a tab with a blocking script results in no further scripts 549 // Test that closing a tab with a blocking script results in no further scripts
530 // running (and we don't crash). 550 // running (and we don't crash).
531 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBlockingScriptTabClosed) { 551 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
552 ContentScriptBlockingScriptTabClosed) {
532 ASSERT_TRUE(StartEmbeddedTestServer()); 553 ASSERT_TRUE(StartEmbeddedTestServer());
533 554
534 // We're going to close a tab in this test, so make a new one (to ensure 555 // We're going to close a tab in this test, so make a new one (to ensure
535 // we don't close the browser). 556 // we don't close the browser).
536 ui_test_utils::NavigateToURLWithDisposition( 557 ui_test_utils::NavigateToURLWithDisposition(
537 browser(), embedded_test_server()->GetURL("/empty.html"), 558 browser(), embedded_test_server()->GetURL("/empty.html"),
538 WindowOpenDisposition::NEW_FOREGROUND_TAB, 559 WindowOpenDisposition::NEW_FOREGROUND_TAB,
539 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 560 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
540 561
541 // Set up the same as the previous test case. 562 // Set up the same as the previous test case.
(...skipping 29 matching lines...) Expand all
571 run_loop.Run(); 592 run_loop.Run();
572 EXPECT_FALSE(listener.was_satisfied()); 593 EXPECT_FALSE(listener.was_satisfied());
573 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( 594 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
574 browser()->tab_strip_model()->active_index(), 0)); 595 browser()->tab_strip_model()->active_index(), 0));
575 EXPECT_FALSE(listener.was_satisfied()); 596 EXPECT_FALSE(listener.was_satisfied());
576 } 597 }
577 598
578 // There was a bug by which content scripts that blocked and ran on 599 // There was a bug by which content scripts that blocked and ran on
579 // document_idle could be injected twice (crbug.com/431263). Test for 600 // document_idle could be injected twice (crbug.com/431263). Test for
580 // regression. 601 // regression.
581 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, 602 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
582 ContentScriptBlockingScriptsDontRunTwice) { 603 ContentScriptBlockingScriptsDontRunTwice) {
583 ASSERT_TRUE(StartEmbeddedTestServer()); 604 ASSERT_TRUE(StartEmbeddedTestServer());
584 605
585 // Load up an extension. 606 // Load up an extension.
586 TestExtensionDir ext_dir1; 607 TestExtensionDir ext_dir1;
587 ext_dir1.WriteManifest( 608 ext_dir1.WriteManifest(
588 base::StringPrintf(kManifest, "ext1", "document_idle")); 609 base::StringPrintf(kManifest, "ext1", "document_idle"));
589 ext_dir1.WriteFile(FILE_PATH_LITERAL("script.js"), kBlockingScript); 610 ext_dir1.WriteFile(FILE_PATH_LITERAL("script.js"), kBlockingScript);
590 const Extension* ext1 = LoadExtension(ext_dir1.UnpackedPath()); 611 const Extension* ext1 = LoadExtension(ext_dir1.UnpackedPath());
591 ASSERT_TRUE(ext1); 612 ASSERT_TRUE(ext1);
(...skipping 12 matching lines...) Expand all
604 run_loop.Run(); 625 run_loop.Run();
605 626
606 // The extension will have injected at idle, but it should only inject once. 627 // The extension will have injected at idle, but it should only inject once.
607 EXPECT_EQ(1u, dialog_helper.dialog_count()); 628 EXPECT_EQ(1u, dialog_helper.dialog_count());
608 dialog_helper.CloseDialogs(); 629 dialog_helper.CloseDialogs();
609 EXPECT_TRUE(RunAllPending(web_contents)); 630 EXPECT_TRUE(RunAllPending(web_contents));
610 EXPECT_EQ(1u, dialog_helper.dialog_count()); 631 EXPECT_EQ(1u, dialog_helper.dialog_count());
611 } 632 }
612 633
613 // Bug fix for crbug.com/507461. 634 // Bug fix for crbug.com/507461.
614 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, 635 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
615 DocumentStartInjectionFromExtensionTabNavigation) { 636 DocumentStartInjectionFromExtensionTabNavigation) {
616 ASSERT_TRUE(StartEmbeddedTestServer()); 637 ASSERT_TRUE(StartEmbeddedTestServer());
617 638
618 TestExtensionDir new_tab_override_dir; 639 TestExtensionDir new_tab_override_dir;
619 new_tab_override_dir.WriteManifest(kNewTabOverrideManifest); 640 new_tab_override_dir.WriteManifest(kNewTabOverrideManifest);
620 new_tab_override_dir.WriteFile(FILE_PATH_LITERAL("newtab.html"), kNewTabHtml); 641 new_tab_override_dir.WriteFile(FILE_PATH_LITERAL("newtab.html"), kNewTabHtml);
621 const Extension* new_tab_override = 642 const Extension* new_tab_override =
622 LoadExtension(new_tab_override_dir.UnpackedPath()); 643 LoadExtension(new_tab_override_dir.UnpackedPath());
623 ASSERT_TRUE(new_tab_override); 644 ASSERT_TRUE(new_tab_override);
624 645
(...skipping 16 matching lines...) Expand all
641 listener.Reset(); 662 listener.Reset();
642 663
643 ui_test_utils::NavigateToURLWithDisposition( 664 ui_test_utils::NavigateToURLWithDisposition(
644 browser(), embedded_test_server()->GetURL("/empty.html"), 665 browser(), embedded_test_server()->GetURL("/empty.html"),
645 WindowOpenDisposition::CURRENT_TAB, 666 WindowOpenDisposition::CURRENT_TAB,
646 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 667 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
647 base::RunLoop().RunUntilIdle(); 668 base::RunLoop().RunUntilIdle();
648 EXPECT_TRUE(listener.was_satisfied()); 669 EXPECT_TRUE(listener.was_satisfied());
649 } 670 }
650 671
651 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, 672 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest,
652 DontInjectContentScriptsInBackgroundPages) { 673 DontInjectContentScriptsInBackgroundPages) {
653 host_resolver()->AddRule("a.com", "127.0.0.1"); 674 host_resolver()->AddRule("a.com", "127.0.0.1");
654 ASSERT_TRUE(StartEmbeddedTestServer()); 675 ASSERT_TRUE(StartEmbeddedTestServer());
655 // Load two extensions, one with an iframe to a.com in its background page, 676 // Load two extensions, one with an iframe to a.com in its background page,
656 // the other, a content script for a.com. The latter should never be able to 677 // the other, a content script for a.com. The latter should never be able to
657 // inject the script, because scripts aren't allowed to run on foreign 678 // inject the script, because scripts aren't allowed to run on foreign
658 // extensions' pages. 679 // extensions' pages.
659 base::FilePath data_dir = test_data_dir_.AppendASCII("content_scripts"); 680 base::FilePath data_dir = test_data_dir_.AppendASCII("content_scripts");
660 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); 681 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false);
661 ExtensionTestMessageListener content_script_listener("script injected", 682 ExtensionTestMessageListener content_script_listener("script injected",
662 false); 683 false);
663 LoadExtension(data_dir.AppendASCII("script_a_com")); 684 LoadExtension(data_dir.AppendASCII("script_a_com"));
664 LoadExtension(data_dir.AppendASCII("background_page_iframe")); 685 LoadExtension(data_dir.AppendASCII("background_page_iframe"));
665 iframe_loaded_listener.WaitUntilSatisfied(); 686 iframe_loaded_listener.WaitUntilSatisfied();
666 EXPECT_FALSE(content_script_listener.was_satisfied()); 687 EXPECT_FALSE(content_script_listener.was_satisfied());
667 } 688 }
668 689
690 INSTANTIATE_TEST_CASE_P(
691 ContentScriptApiTests,
692 ContentScriptApiTest,
693 testing::Values(TestConfig::kDefault,
694 TestConfig::kYieldBetweenContentScriptRunsEnabled));
695
669 } // namespace extensions 696 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698