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