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 | |
369 // request succeeds. | |
alexmos
2016/12/13 23:27:28
nit: looks like this will fit on previous line.
davidsac (gone - try alexmos)
2016/12/14 00:01:31
Done.
| |
370 class MailtoExternalProtocolHandlerDelegate | |
371 : public ExternalProtocolHandler::Delegate { | |
372 public: | |
373 bool has_triggered_external_protocol() { | |
374 return has_triggered_external_protocol_; | |
375 } | |
376 | |
377 std::string external_protocol_url() { | |
alexmos
2016/12/13 23:27:28
You can return this as a const GURL&, and just ret
davidsac (gone - try alexmos)
2016/12/14 00:01:31
Done.
| |
378 return external_protocol_url_.scheme() + ":" + | |
379 external_protocol_url_.GetContent(); | |
380 } | |
381 | |
382 content::WebContents* web_contents() { return web_contents_; } | |
383 | |
384 void RunExternalProtocolDialog(const GURL& url, | |
385 int render_process_host_id, | |
386 int routing_id, | |
387 ui::PageTransition page_transition, | |
388 bool has_user_gesture) override {} | |
389 | |
390 scoped_refptr<shell_integration::DefaultProtocolClientWorker> | |
391 CreateShellWorker( | |
392 const shell_integration::DefaultWebClientWorkerCallback& callback, | |
393 const std::string& protocol) override { | |
394 return new shell_integration::DefaultProtocolClientWorker(callback, | |
395 protocol); | |
396 } | |
397 | |
398 ExternalProtocolHandler::BlockState GetBlockState( | |
399 const std::string& scheme) override { | |
400 return ExternalProtocolHandler::DONT_BLOCK; | |
alexmos
2016/12/13 23:27:28
Good call, I agree this is safer than relying on t
davidsac (gone - try alexmos)
2016/12/14 00:01:31
Acknowledged.
| |
401 } | |
402 | |
403 void BlockRequest() override {} | |
404 | |
405 void LaunchUrlWithoutSecurityCheck( | |
406 const GURL& url, | |
407 content::WebContents* web_contents) override { | |
408 external_protocol_url_ = url; | |
409 web_contents_ = web_contents; | |
410 has_triggered_external_protocol_ = true; | |
411 if (message_loop_runner_) | |
412 message_loop_runner_->Quit(); | |
413 } | |
414 | |
415 void Wait() { | |
416 if (!has_triggered_external_protocol_) { | |
417 message_loop_runner_ = new content::MessageLoopRunner(); | |
418 message_loop_runner_->Run(); | |
419 } | |
420 } | |
421 | |
422 void FinishedProcessingCheck() override {} | |
423 | |
424 private: | |
425 bool has_triggered_external_protocol_ = false; | |
426 GURL external_protocol_url_; | |
427 content::WebContents* web_contents_ = nullptr; | |
428 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
429 }; | |
430 | |
431 // This test is not run on ChromeOS because it registers a custom handler (see | |
432 // ProtocolHandlerRegistry::InstallDefaultsForChromeOS), and handles mailto: | |
433 // navigations before getting to external protocol code | |
alexmos
2016/12/13 23:27:28
nit: end with period.
davidsac (gone - try alexmos)
2016/12/14 00:01:30
Done.
| |
434 #if defined(OS_CHROMEOS) | |
435 #define MAYBE_LaunchExternalProtocolFromSubframe \ | |
436 DISABLED_LaunchExternalProtocolFromSubframe | |
437 #else | |
438 #define MAYBE_LaunchExternalProtocolFromSubframe \ | |
439 LaunchExternalProtocolFromSubframe | |
440 #endif | |
441 | |
alexmos
2016/12/13 23:27:28
nit: no blank line
davidsac (gone - try alexmos)
2016/12/14 00:01:30
Done.
| |
442 // This test verifies that external protocol requests succeed when made from an | |
443 // OOPIF (https://crbug.com/668289). | |
444 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, | |
445 MAYBE_LaunchExternalProtocolFromSubframe) { | |
446 GURL start_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
447 | |
448 ui_test_utils::NavigateToURL(browser(), start_url); | |
449 | |
450 // Navigate to a page with a cross-site iframe that triggers a mailto: | |
451 // external protocol request. | |
452 // The test did not start by navigating to this URL because that would mask | |
453 // the bug. Instead, navigating the main frame to another page will cause a | |
454 // cross-process transfer, which will avoid a situation where the OOPIF's | |
455 // swapped-out RenderViewHost and the main frame's active RenderViewHost get | |
456 // the same routing IDs, causing an accidental success. | |
457 GURL mailto_main_frame_url( | |
458 embedded_test_server()->GetURL("b.com", "/iframe.html")); | |
459 | |
460 ui_test_utils::NavigateToURL(browser(), mailto_main_frame_url); | |
461 | |
462 MailtoExternalProtocolHandlerDelegate delegate; | |
463 ChromeResourceDispatcherHostDelegate:: | |
464 SetExternalProtocolHandlerDelegateForTesting(&delegate); | |
465 | |
466 GURL mailto_subframe_url( | |
467 embedded_test_server()->GetURL("c.com", "/page_with_mailto.html")); | |
468 content::WebContents* active_web_contents = | |
469 browser()->tab_strip_model()->GetActiveWebContents(); | |
470 EXPECT_TRUE( | |
471 NavigateIframeToURL(active_web_contents, "test", mailto_subframe_url)); | |
472 | |
473 delegate.Wait(); | |
474 | |
475 EXPECT_TRUE(delegate.has_triggered_external_protocol()); | |
476 EXPECT_EQ(delegate.external_protocol_url(), "mailto:mail@example.org"); | |
477 EXPECT_EQ(active_web_contents, delegate.web_contents()); | |
478 ChromeResourceDispatcherHostDelegate:: | |
479 SetExternalProtocolHandlerDelegateForTesting(nullptr); | |
480 } | |
481 | |
366 // Verify that a popup can be opened after navigating a remote frame. This has | 482 // 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 | 483 // to be a chrome/ test to ensure that the popup blocker doesn't block the |
368 // popup. See https://crbug.com/670770. | 484 // popup. See https://crbug.com/670770. |
369 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, | 485 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, |
370 NavigateRemoteFrameAndOpenPopup) { | 486 NavigateRemoteFrameAndOpenPopup) { |
371 // Start on a page with an <iframe>. | 487 // Start on a page with an <iframe>. |
372 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | 488 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
373 ui_test_utils::NavigateToURL(browser(), main_url); | 489 ui_test_utils::NavigateToURL(browser(), main_url); |
374 | 490 |
375 // Navigate the iframe cross-site. | 491 // Navigate the iframe cross-site. |
(...skipping 15 matching lines...) Expand all Loading... | |
391 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" | 507 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" |
392 "var w = window.open('about:blank');\n" | 508 "var w = window.open('about:blank');\n" |
393 "window.domAutomationController.send(!!w);\n", | 509 "window.domAutomationController.send(!!w);\n", |
394 &popup_handle_is_valid)); | 510 &popup_handle_is_valid)); |
395 popup_observer.Wait(); | 511 popup_observer.Wait(); |
396 | 512 |
397 // The popup shouldn't be blocked. | 513 // The popup shouldn't be blocked. |
398 EXPECT_TRUE(popup_handle_is_valid); | 514 EXPECT_TRUE(popup_handle_is_valid); |
399 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 515 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
400 } | 516 } |
OLD | NEW |