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