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

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

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

Powered by Google App Engine
This is Rietveld 408576698