| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" | 9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 gfx::Size GetScreenSize() { | 45 gfx::Size GetScreenSize() { |
| 46 content::WebContents* web_contents = | 46 content::WebContents* web_contents = |
| 47 browser()->tab_strip_model()->GetActiveWebContents(); | 47 browser()->tab_strip_model()->GetActiveWebContents(); |
| 48 const display::Display display = | 48 const display::Display display = |
| 49 display::Screen::GetScreen()->GetDisplayNearestWindow( | 49 display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 50 web_contents->GetRenderWidgetHostView()->GetNativeView()); | 50 web_contents->GetRenderWidgetHostView()->GetNativeView()); |
| 51 return display.bounds().size(); | 51 return display.bounds().size(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 enum class FullscreenExitMethod { |
| 55 JS_CALL, |
| 56 ESC_PRESS, |
| 57 }; |
| 58 |
| 59 void FullscreenElementInABA(FullscreenExitMethod exit_method); |
| 60 |
| 54 private: | 61 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(SitePerProcessInteractiveBrowserTest); | 62 DISALLOW_COPY_AND_ASSIGN(SitePerProcessInteractiveBrowserTest); |
| 56 }; | 63 }; |
| 57 | 64 |
| 58 // Check that document.hasFocus() works properly with out-of-process iframes. | 65 // Check that document.hasFocus() works properly with out-of-process iframes. |
| 59 // The test builds a page with four cross-site frames and then focuses them one | 66 // The test builds a page with four cross-site frames and then focuses them one |
| 60 // by one, checking the value of document.hasFocus() in all frames. For any | 67 // by one, checking the value of document.hasFocus() in all frames. For any |
| 61 // given focused frame, document.hasFocus() should return true for that frame | 68 // given focused frame, document.hasFocus() should return true for that frame |
| 62 // and all its ancestor frames. | 69 // and all its ancestor frames. |
| 63 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, DocumentHasFocus) { | 70 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, DocumentHasFocus) { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 EXPECT_FALSE(ElementHasFullscreenStyle(main_frame, "child-0")); | 463 EXPECT_FALSE(ElementHasFullscreenStyle(main_frame, "child-0")); |
| 457 EXPECT_FALSE(ElementHasFullscreenAncestorStyle(main_frame, "child-0")); | 464 EXPECT_FALSE(ElementHasFullscreenAncestorStyle(main_frame, "child-0")); |
| 458 | 465 |
| 459 // Check that both frames cleared their document.webkitFullscreenElement. | 466 // Check that both frames cleared their document.webkitFullscreenElement. |
| 460 EXPECT_EQ("none", GetFullscreenElementId(main_frame)); | 467 EXPECT_EQ("none", GetFullscreenElementId(main_frame)); |
| 461 EXPECT_EQ("none", GetFullscreenElementId(child)); | 468 EXPECT_EQ("none", GetFullscreenElementId(child)); |
| 462 } | 469 } |
| 463 | 470 |
| 464 // Check that on a page with A-embed-B-embed-A frame hierarchy, an element in | 471 // Check that on a page with A-embed-B-embed-A frame hierarchy, an element in |
| 465 // the bottom frame can enter and exit fullscreen. | 472 // the bottom frame can enter and exit fullscreen. |
| 466 // | 473 void SitePerProcessInteractiveBrowserTest::FullscreenElementInABA( |
| 467 // TODO(alexmos): For now, the test will verify sizing and fullscreen CSS | 474 FullscreenExitMethod exit_method) { |
| 468 // styles, but additional refactoring of Blink's Fullscreen class is required | |
| 469 // to fully handle fullscreenchange events and webkitFullscreenElement in the | |
| 470 // main frame. | |
| 471 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, | |
| 472 FullscreenElementInABA) { | |
| 473 GURL main_url(embedded_test_server()->GetURL( | 475 GURL main_url(embedded_test_server()->GetURL( |
| 474 "a.com", "/cross_site_iframe_factory.html?a(b(a))")); | 476 "a.com", "/cross_site_iframe_factory.html?a(b(a))")); |
| 475 ui_test_utils::NavigateToURL(browser(), main_url); | 477 ui_test_utils::NavigateToURL(browser(), main_url); |
| 476 content::WebContents* web_contents = | 478 content::WebContents* web_contents = |
| 477 browser()->tab_strip_model()->GetActiveWebContents(); | 479 browser()->tab_strip_model()->GetActiveWebContents(); |
| 478 | 480 |
| 479 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 481 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 480 content::RenderFrameHost* child = ChildFrameAt(main_frame, 0); | 482 content::RenderFrameHost* child = ChildFrameAt(main_frame, 0); |
| 481 content::RenderFrameHost* grandchild = ChildFrameAt(child, 0); | 483 content::RenderFrameHost* grandchild = ChildFrameAt(child, 0); |
| 482 | 484 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 499 | 501 |
| 500 // Add a resize event handler that will send a message when the grandchild | 502 // Add a resize event handler that will send a message when the grandchild |
| 501 // frame is resized to the screen size. Also save its original size. | 503 // frame is resized to the screen size. Also save its original size. |
| 502 AddResizeListener(grandchild, GetScreenSize()); | 504 AddResizeListener(grandchild, GetScreenSize()); |
| 503 gfx::Size original_grandchild_size = GetFrameSize(grandchild); | 505 gfx::Size original_grandchild_size = GetFrameSize(grandchild); |
| 504 | 506 |
| 505 // Fullscreen a <div> inside the bottom subframe. This will block until | 507 // Fullscreen a <div> inside the bottom subframe. This will block until |
| 506 // (1) the fullscreenchange events in all frames send a response, and | 508 // (1) the fullscreenchange events in all frames send a response, and |
| 507 // (2) the frame is resized to fill the whole screen. | 509 // (2) the frame is resized to fill the whole screen. |
| 508 // (3) the browser has finished the fullscreen transition. | 510 // (3) the browser has finished the fullscreen transition. |
| 509 // | 511 std::set<std::string> expected_events = {"main_frame", "child", "grandchild"}; |
| 510 // TODO(alexmos): Also wait for "main_frame" once | |
| 511 // blink::Fullscreen::requestFullscreen() and exitFullscreen() are fixed to | |
| 512 // process all local ancestors. | |
| 513 std::set<std::string> expected_events = {"child", "grandchild"}; | |
| 514 { | 512 { |
| 515 content::DOMMessageQueue queue; | 513 content::DOMMessageQueue queue; |
| 516 std::unique_ptr<FullscreenNotificationObserver> observer( | 514 std::unique_ptr<FullscreenNotificationObserver> observer( |
| 517 new FullscreenNotificationObserver()); | 515 new FullscreenNotificationObserver()); |
| 518 EXPECT_TRUE(ExecuteScript(grandchild, "activateFullscreen()")); | 516 EXPECT_TRUE(ExecuteScript(grandchild, "activateFullscreen()")); |
| 519 WaitForMultipleFullscreenEvents(expected_events, queue); | 517 WaitForMultipleFullscreenEvents(expected_events, queue); |
| 520 observer->Wait(); | 518 observer->Wait(); |
| 521 } | 519 } |
| 522 | 520 |
| 523 // Verify that the browser has entered fullscreen for the current tab. | 521 // Verify that the browser has entered fullscreen for the current tab. |
| 524 EXPECT_TRUE(browser()->window()->IsFullscreen()); | 522 EXPECT_TRUE(browser()->window()->IsFullscreen()); |
| 525 EXPECT_TRUE(browser()->exclusive_access_manager() | 523 EXPECT_TRUE(browser()->exclusive_access_manager() |
| 526 ->fullscreen_controller() | 524 ->fullscreen_controller() |
| 527 ->IsFullscreenForTabOrPending(web_contents)); | 525 ->IsFullscreenForTabOrPending(web_contents)); |
| 528 | 526 |
| 529 // Verify that the <div> has fullscreen style in the bottom frame, and that | 527 // Verify that the <div> has fullscreen style in the bottom frame, and that |
| 530 // the proper <iframe> elements have fullscreen style in its ancestor frames. | 528 // the proper <iframe> elements have fullscreen style in its ancestor frames. |
| 531 EXPECT_TRUE(ElementHasFullscreenStyle(grandchild, "fullscreen-div")); | 529 EXPECT_TRUE(ElementHasFullscreenStyle(grandchild, "fullscreen-div")); |
| 532 EXPECT_TRUE(ElementHasFullscreenStyle(child, "child-0")); | 530 EXPECT_TRUE(ElementHasFullscreenStyle(child, "child-0")); |
| 533 EXPECT_TRUE(ElementHasFullscreenAncestorStyle(child, "child-0")); | 531 EXPECT_TRUE(ElementHasFullscreenAncestorStyle(child, "child-0")); |
| 534 EXPECT_TRUE(ElementHasFullscreenStyle(main_frame, "child-0")); | 532 EXPECT_TRUE(ElementHasFullscreenStyle(main_frame, "child-0")); |
| 535 EXPECT_TRUE(ElementHasFullscreenAncestorStyle(main_frame, "child-0")); | 533 EXPECT_TRUE(ElementHasFullscreenAncestorStyle(main_frame, "child-0")); |
| 536 | 534 |
| 537 // Check document.webkitFullscreenElement in all frames. | 535 // Check document.webkitFullscreenElement in all frames. |
| 536 EXPECT_EQ("child-0", GetFullscreenElementId(main_frame)); |
| 538 EXPECT_EQ("child-0", GetFullscreenElementId(child)); | 537 EXPECT_EQ("child-0", GetFullscreenElementId(child)); |
| 539 EXPECT_EQ("fullscreen-div", GetFullscreenElementId(grandchild)); | 538 EXPECT_EQ("fullscreen-div", GetFullscreenElementId(grandchild)); |
| 540 // TODO(alexmos): Also check that |main_frame|'s webkitFullscreenElement is | |
| 541 // "child-0" once blink::Fullscreen::requestFullscreen() is fixed to handle | |
| 542 // all local ancestors. | |
| 543 | 539 |
| 544 // Now exit fullscreen from the subframe. | 540 // Now exit fullscreen from the subframe. |
| 545 AddResizeListener(grandchild, original_grandchild_size); | 541 AddResizeListener(grandchild, original_grandchild_size); |
| 546 { | 542 { |
| 547 content::DOMMessageQueue queue; | 543 content::DOMMessageQueue queue; |
| 548 std::unique_ptr<FullscreenNotificationObserver> observer( | 544 std::unique_ptr<FullscreenNotificationObserver> observer( |
| 549 new FullscreenNotificationObserver()); | 545 new FullscreenNotificationObserver()); |
| 550 EXPECT_TRUE(ExecuteScript(grandchild, "exitFullscreen()")); | 546 switch (exit_method) { |
| 547 case FullscreenExitMethod::JS_CALL: |
| 548 EXPECT_TRUE(ExecuteScript(grandchild, "exitFullscreen()")); |
| 549 break; |
| 550 case FullscreenExitMethod::ESC_PRESS: |
| 551 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_ESCAPE, |
| 552 false, false, false, |
| 553 false)); |
| 554 break; |
| 555 default: |
| 556 NOTREACHED(); |
| 557 } |
| 551 WaitForMultipleFullscreenEvents(expected_events, queue); | 558 WaitForMultipleFullscreenEvents(expected_events, queue); |
| 552 observer->Wait(); | 559 observer->Wait(); |
| 553 } | 560 } |
| 554 | 561 |
| 555 EXPECT_FALSE(browser()->window()->IsFullscreen()); | 562 EXPECT_FALSE(browser()->window()->IsFullscreen()); |
| 556 | 563 |
| 557 // Verify that the fullscreen styles were removed from the <div> and its | 564 // Verify that the fullscreen styles were removed from the <div> and its |
| 558 // container <iframe>'s. | 565 // container <iframe>'s. |
| 559 EXPECT_FALSE(ElementHasFullscreenStyle(grandchild, "fullscreen-div")); | 566 EXPECT_FALSE(ElementHasFullscreenStyle(grandchild, "fullscreen-div")); |
| 560 EXPECT_FALSE(ElementHasFullscreenStyle(child, "child-0")); | 567 EXPECT_FALSE(ElementHasFullscreenStyle(child, "child-0")); |
| 561 EXPECT_FALSE(ElementHasFullscreenAncestorStyle(child, "child-0")); | 568 EXPECT_FALSE(ElementHasFullscreenAncestorStyle(child, "child-0")); |
| 562 EXPECT_FALSE(ElementHasFullscreenStyle(main_frame, "child-0")); | 569 EXPECT_FALSE(ElementHasFullscreenStyle(main_frame, "child-0")); |
| 563 EXPECT_FALSE(ElementHasFullscreenAncestorStyle(main_frame, "child-0")); | 570 EXPECT_FALSE(ElementHasFullscreenAncestorStyle(main_frame, "child-0")); |
| 564 | 571 |
| 565 // Check that document.webkitFullscreenElement was cleared in all three | 572 // Check that document.webkitFullscreenElement was cleared in all three |
| 566 // frames. | 573 // frames. |
| 567 EXPECT_EQ("none", GetFullscreenElementId(main_frame)); | 574 EXPECT_EQ("none", GetFullscreenElementId(main_frame)); |
| 568 EXPECT_EQ("none", GetFullscreenElementId(child)); | 575 EXPECT_EQ("none", GetFullscreenElementId(child)); |
| 569 EXPECT_EQ("none", GetFullscreenElementId(grandchild)); | 576 EXPECT_EQ("none", GetFullscreenElementId(grandchild)); |
| 570 } | 577 } |
| 571 | 578 |
| 579 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
| 580 FullscreenElementInABAAndExitViaEscapeKey) { |
| 581 FullscreenElementInABA(FullscreenExitMethod::ESC_PRESS); |
| 582 } |
| 583 |
| 584 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
| 585 FullscreenElementInABAAndExitViaJS) { |
| 586 FullscreenElementInABA(FullscreenExitMethod::JS_CALL); |
| 587 } |
| 588 |
| 572 // Check that fullscreen works on a more complex page hierarchy with multiple | 589 // Check that fullscreen works on a more complex page hierarchy with multiple |
| 573 // local and remote ancestors. The test uses this frame tree: | 590 // local and remote ancestors. The test uses this frame tree: |
| 574 // | 591 // |
| 575 // A (a_top) | 592 // A (a_top) |
| 576 // | | 593 // | |
| 577 // A (a_bottom) | 594 // A (a_bottom) |
| 578 // / \ . | 595 // / \ . |
| 579 // (b_first) B B (b_second) | 596 // (b_first) B B (b_second) |
| 580 // | | 597 // | |
| 581 // C (c_top) | 598 // C (c_top) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 // Verify that all fullscreen styles have been cleared. | 729 // Verify that all fullscreen styles have been cleared. |
| 713 EXPECT_FALSE(ElementHasFullscreenStyle(a_top, "child-0")); | 730 EXPECT_FALSE(ElementHasFullscreenStyle(a_top, "child-0")); |
| 714 EXPECT_FALSE(ElementHasFullscreenStyle(a_bottom, "child-0")); | 731 EXPECT_FALSE(ElementHasFullscreenStyle(a_bottom, "child-0")); |
| 715 EXPECT_FALSE(ElementHasFullscreenStyle(a_bottom, "child-1")); | 732 EXPECT_FALSE(ElementHasFullscreenStyle(a_bottom, "child-1")); |
| 716 EXPECT_FALSE(ElementHasFullscreenStyle(b_second, "child-0")); | 733 EXPECT_FALSE(ElementHasFullscreenStyle(b_second, "child-0")); |
| 717 EXPECT_FALSE(ElementHasFullscreenStyle(c_top, "child-0")); | 734 EXPECT_FALSE(ElementHasFullscreenStyle(c_top, "child-0")); |
| 718 EXPECT_FALSE(ElementHasFullscreenStyle(c_middle, "fullscreen-div")); | 735 EXPECT_FALSE(ElementHasFullscreenStyle(c_middle, "fullscreen-div")); |
| 719 EXPECT_FALSE(ElementHasFullscreenStyle(c_middle, "child-0")); | 736 EXPECT_FALSE(ElementHasFullscreenStyle(c_middle, "child-0")); |
| 720 } | 737 } |
| 721 | 738 |
| OLD | NEW |