OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 12 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
16 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 18 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
17 #include "components/guest_view/browser/test_guest_view_manager.h" | 19 #include "components/guest_view/browser/test_guest_view_manager.h" |
18 #include "content/public/browser/interstitial_page.h" | 20 #include "content/public/browser/interstitial_page.h" |
19 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 358 |
357 // Now detach the frame and observe that the guest is destroyed. | 359 // Now detach the frame and observe that the guest is destroyed. |
358 content::WebContentsDestroyedWatcher observer(guest_web_contents); | 360 content::WebContentsDestroyedWatcher observer(guest_web_contents); |
359 EXPECT_TRUE(ExecuteScript( | 361 EXPECT_TRUE(ExecuteScript( |
360 active_web_contents, | 362 active_web_contents, |
361 "document.body.removeChild(document.querySelector('iframe'));")); | 363 "document.body.removeChild(document.querySelector('iframe'));")); |
362 observer.Wait(); | 364 observer.Wait(); |
363 EXPECT_EQ(0U, test_guest_view_manager()->GetNumGuestsActive()); | 365 EXPECT_EQ(0U, test_guest_view_manager()->GetNumGuestsActive()); |
364 } | 366 } |
365 | 367 |
| 368 // A helper class to verify that a "mailto:" external protocol request succeeds. |
| 369 class MailtoExternalProtocolHandlerDelegate |
| 370 : public ExternalProtocolHandler::Delegate { |
| 371 public: |
| 372 bool has_triggered_external_protocol() { |
| 373 return has_triggered_external_protocol_; |
| 374 } |
| 375 |
| 376 const GURL& external_protocol_url() { return external_protocol_url_; } |
| 377 |
| 378 content::WebContents* web_contents() { return web_contents_; } |
| 379 |
| 380 void RunExternalProtocolDialog(const GURL& url, |
| 381 int render_process_host_id, |
| 382 int routing_id, |
| 383 ui::PageTransition page_transition, |
| 384 bool has_user_gesture) override {} |
| 385 |
| 386 scoped_refptr<shell_integration::DefaultProtocolClientWorker> |
| 387 CreateShellWorker( |
| 388 const shell_integration::DefaultWebClientWorkerCallback& callback, |
| 389 const std::string& protocol) override { |
| 390 return new shell_integration::DefaultProtocolClientWorker(callback, |
| 391 protocol); |
| 392 } |
| 393 |
| 394 ExternalProtocolHandler::BlockState GetBlockState( |
| 395 const std::string& scheme) override { |
| 396 return ExternalProtocolHandler::DONT_BLOCK; |
| 397 } |
| 398 |
| 399 void BlockRequest() override {} |
| 400 |
| 401 void LaunchUrlWithoutSecurityCheck( |
| 402 const GURL& url, |
| 403 content::WebContents* web_contents) override { |
| 404 external_protocol_url_ = url; |
| 405 web_contents_ = web_contents; |
| 406 has_triggered_external_protocol_ = true; |
| 407 if (message_loop_runner_) |
| 408 message_loop_runner_->Quit(); |
| 409 } |
| 410 |
| 411 void Wait() { |
| 412 if (!has_triggered_external_protocol_) { |
| 413 message_loop_runner_ = new content::MessageLoopRunner(); |
| 414 message_loop_runner_->Run(); |
| 415 } |
| 416 } |
| 417 |
| 418 void FinishedProcessingCheck() override {} |
| 419 |
| 420 private: |
| 421 bool has_triggered_external_protocol_ = false; |
| 422 GURL external_protocol_url_; |
| 423 content::WebContents* web_contents_ = nullptr; |
| 424 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 425 }; |
| 426 |
| 427 // This test is not run on ChromeOS because it registers a custom handler (see |
| 428 // ProtocolHandlerRegistry::InstallDefaultsForChromeOS), and handles mailto: |
| 429 // navigations before getting to external protocol code. |
| 430 #if defined(OS_CHROMEOS) |
| 431 #define MAYBE_LaunchExternalProtocolFromSubframe \ |
| 432 DISABLED_LaunchExternalProtocolFromSubframe |
| 433 #else |
| 434 #define MAYBE_LaunchExternalProtocolFromSubframe \ |
| 435 LaunchExternalProtocolFromSubframe |
| 436 #endif |
| 437 // This test verifies that external protocol requests succeed when made from an |
| 438 // OOPIF (https://crbug.com/668289). |
| 439 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, |
| 440 MAYBE_LaunchExternalProtocolFromSubframe) { |
| 441 GURL start_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 442 |
| 443 ui_test_utils::NavigateToURL(browser(), start_url); |
| 444 |
| 445 // Navigate to a page with a cross-site iframe that triggers a mailto: |
| 446 // external protocol request. |
| 447 // The test did not start by navigating to this URL because that would mask |
| 448 // the bug. Instead, navigating the main frame to another page will cause a |
| 449 // cross-process transfer, which will avoid a situation where the OOPIF's |
| 450 // swapped-out RenderViewHost and the main frame's active RenderViewHost get |
| 451 // the same routing IDs, causing an accidental success. |
| 452 GURL mailto_main_frame_url( |
| 453 embedded_test_server()->GetURL("b.com", "/iframe.html")); |
| 454 |
| 455 ui_test_utils::NavigateToURL(browser(), mailto_main_frame_url); |
| 456 |
| 457 MailtoExternalProtocolHandlerDelegate delegate; |
| 458 ChromeResourceDispatcherHostDelegate:: |
| 459 SetExternalProtocolHandlerDelegateForTesting(&delegate); |
| 460 |
| 461 GURL mailto_subframe_url( |
| 462 embedded_test_server()->GetURL("c.com", "/page_with_mailto.html")); |
| 463 content::WebContents* active_web_contents = |
| 464 browser()->tab_strip_model()->GetActiveWebContents(); |
| 465 EXPECT_TRUE( |
| 466 NavigateIframeToURL(active_web_contents, "test", mailto_subframe_url)); |
| 467 |
| 468 delegate.Wait(); |
| 469 |
| 470 EXPECT_TRUE(delegate.has_triggered_external_protocol()); |
| 471 EXPECT_EQ(delegate.external_protocol_url(), GURL("mailto:mail@example.org")); |
| 472 EXPECT_EQ(active_web_contents, delegate.web_contents()); |
| 473 ChromeResourceDispatcherHostDelegate:: |
| 474 SetExternalProtocolHandlerDelegateForTesting(nullptr); |
| 475 } |
| 476 |
366 // Verify that a popup can be opened after navigating a remote frame. This has | 477 // Verify that a popup can be opened after navigating a remote frame. This has |
367 // to be a chrome/ test to ensure that the popup blocker doesn't block the | 478 // to be a chrome/ test to ensure that the popup blocker doesn't block the |
368 // popup. See https://crbug.com/670770. | 479 // popup. See https://crbug.com/670770. |
369 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, | 480 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, |
370 NavigateRemoteFrameAndOpenPopup) { | 481 NavigateRemoteFrameAndOpenPopup) { |
371 // Start on a page with an <iframe>. | 482 // Start on a page with an <iframe>. |
372 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | 483 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
373 ui_test_utils::NavigateToURL(browser(), main_url); | 484 ui_test_utils::NavigateToURL(browser(), main_url); |
374 | 485 |
375 // Navigate the iframe cross-site. | 486 // Navigate the iframe cross-site. |
(...skipping 15 matching lines...) Expand all Loading... |
391 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" | 502 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" |
392 "var w = window.open('about:blank');\n" | 503 "var w = window.open('about:blank');\n" |
393 "window.domAutomationController.send(!!w);\n", | 504 "window.domAutomationController.send(!!w);\n", |
394 &popup_handle_is_valid)); | 505 &popup_handle_is_valid)); |
395 popup_observer.Wait(); | 506 popup_observer.Wait(); |
396 | 507 |
397 // The popup shouldn't be blocked. | 508 // The popup shouldn't be blocked. |
398 EXPECT_TRUE(popup_handle_is_valid); | 509 EXPECT_TRUE(popup_handle_is_valid); |
399 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 510 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
400 } | 511 } |
OLD | NEW |