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 "core/frame/FrameHost.h" | 5 #include "core/frame/FrameHost.h" |
6 #include "core/frame/FrameView.h" | 6 #include "core/frame/FrameView.h" |
7 #include "core/frame/TopControls.h" | 7 #include "core/frame/TopControls.h" |
8 #include "core/html/HTMLFrameOwnerElement.h" | 8 #include "core/html/HTMLFrameOwnerElement.h" |
9 #include "core/page/Page.h" | 9 #include "core/page/Page.h" |
10 #include "core/page/scrolling/RootScrollerController.h" | 10 #include "core/page/scrolling/RootScrollerController.h" |
| 11 #include "core/paint/PaintLayerScrollableArea.h" |
11 #include "platform/testing/URLTestHelpers.h" | 12 #include "platform/testing/URLTestHelpers.h" |
12 #include "platform/testing/UnitTestHelpers.h" | 13 #include "platform/testing/UnitTestHelpers.h" |
13 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
14 #include "public/platform/WebURLLoaderMockFactory.h" | 15 #include "public/platform/WebURLLoaderMockFactory.h" |
15 #include "public/web/WebCache.h" | 16 #include "public/web/WebCache.h" |
16 #include "public/web/WebConsoleMessage.h" | 17 #include "public/web/WebConsoleMessage.h" |
17 #include "public/web/WebScriptSource.h" | 18 #include "public/web/WebScriptSource.h" |
18 #include "public/web/WebSettings.h" | 19 #include "public/web/WebSettings.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "web/WebLocalFrameImpl.h" | 21 #include "web/WebLocalFrameImpl.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 innerContainer, | 453 innerContainer, |
453 exceptionState); | 454 exceptionState); |
454 mainFrameView()->updateAllLifecyclePhases(); | 455 mainFrameView()->updateAllLifecyclePhases(); |
455 | 456 |
456 ASSERT_EQ(innerContainer, iframe->contentDocument()->rootScroller()); | 457 ASSERT_EQ(innerContainer, iframe->contentDocument()->rootScroller()); |
457 ASSERT_EQ(innerContainer, | 458 ASSERT_EQ(innerContainer, |
458 effectiveRootScroller(iframe->contentDocument())); | 459 effectiveRootScroller(iframe->contentDocument())); |
459 } | 460 } |
460 } | 461 } |
461 | 462 |
| 463 // Tests that setting an iframe as the root scroller makes the iframe the |
| 464 // effective root scroller in the parent frame. |
| 465 TEST_F(RootScrollerTest, SetRootScrollerIframeBecomesEffective) |
| 466 { |
| 467 initialize("root-scroller-iframe.html"); |
| 468 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 469 |
| 470 { |
| 471 NonThrowableExceptionState nonThrow; |
| 472 |
| 473 // Try to set the root scroller in the main frame to be the iframe |
| 474 // element. |
| 475 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 476 mainFrame()->document()->getElementById("iframe")); |
| 477 |
| 478 mainFrame()->document()->setRootScroller(iframe, nonThrow); |
| 479 |
| 480 ASSERT_EQ(iframe, mainFrame()->document()->rootScroller()); |
| 481 ASSERT_EQ(iframe, |
| 482 mainFrame()->document()->rootScrollerController() |
| 483 ->effectiveRootScroller()); |
| 484 |
| 485 Element* container = |
| 486 iframe->contentDocument()->getElementById("container"); |
| 487 |
| 488 iframe->contentDocument()->setRootScroller(container, nonThrow); |
| 489 |
| 490 ASSERT_EQ(container, iframe->contentDocument()->rootScroller()); |
| 491 ASSERT_EQ(container, |
| 492 iframe->contentDocument()->rootScrollerController() |
| 493 ->effectiveRootScroller()); |
| 494 ASSERT_EQ(iframe, mainFrame()->document()->rootScroller()); |
| 495 ASSERT_EQ(iframe, |
| 496 mainFrame()->document()->rootScrollerController() |
| 497 ->effectiveRootScroller()); |
| 498 } |
| 499 } |
| 500 |
| 501 // Tests that the global root scroller is correctly calculated when getting the |
| 502 // root scroller layer and that the viewport apply scroll is set on it. |
| 503 TEST_F(RootScrollerTest, SetRootScrollerIframeUsesCorrectLayerAndCallback) |
| 504 { |
| 505 initialize("root-scroller-iframe.html"); |
| 506 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 507 |
| 508 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 509 mainFrame()->document()->getElementById("iframe")); |
| 510 Element* container = |
| 511 iframe->contentDocument()->getElementById("container"); |
| 512 |
| 513 RootScrollerController* mainController = |
| 514 mainFrame()->document()->rootScrollerController(); |
| 515 |
| 516 NonThrowableExceptionState nonThrow; |
| 517 |
| 518 // No root scroller set, the documentElement should be the effective root |
| 519 // and the main FrameView's scroll layer should be the layer to use. |
| 520 { |
| 521 ASSERT_EQ( |
| 522 mainController->rootScrollerLayer(), |
| 523 mainFrameView()->layerForScrolling()); |
| 524 ASSERT_TRUE(mainController->isViewportScrollCallback( |
| 525 mainFrame()->document()->documentElement()->getApplyScroll())); |
| 526 } |
| 527 |
| 528 // Set a root scroller in the iframe. Since the main document didn't set a |
| 529 // root scroller, the global root scroller shouldn't change. |
| 530 { |
| 531 |
| 532 iframe->contentDocument()->setRootScroller(container, nonThrow); |
| 533 |
| 534 ASSERT_EQ( |
| 535 mainController->rootScrollerLayer(), |
| 536 mainFrameView()->layerForScrolling()); |
| 537 ASSERT_TRUE(mainController->isViewportScrollCallback( |
| 538 mainFrame()->document()->documentElement()->getApplyScroll())); |
| 539 } |
| 540 |
| 541 // Setting the iframe as the root scroller in the main frame should now |
| 542 // link the root scrollers so the container should now be the global root |
| 543 // scroller. |
| 544 { |
| 545 mainFrame()->document()->setRootScroller(iframe, nonThrow); |
| 546 |
| 547 ScrollableArea* containerScroller = |
| 548 static_cast<PaintInvalidationCapableScrollableArea*>( |
| 549 toLayoutBox(container->layoutObject())->getScrollableArea()); |
| 550 |
| 551 ASSERT_EQ( |
| 552 mainController->rootScrollerLayer(), |
| 553 containerScroller->layerForScrolling()); |
| 554 ASSERT_FALSE(mainController->isViewportScrollCallback( |
| 555 mainFrame()->document()->documentElement()->getApplyScroll())); |
| 556 ASSERT_TRUE(mainController->isViewportScrollCallback( |
| 557 container->getApplyScroll())); |
| 558 } |
| 559 |
| 560 // Unsetting the root scroller in the iframe should reset its effective |
| 561 // root scroller to the iframe's documentElement and thus the iframe's |
| 562 // documentElement becomes the global root scroller. |
| 563 { |
| 564 iframe->contentDocument()->setRootScroller(nullptr, nonThrow); |
| 565 ASSERT_EQ( |
| 566 mainController->rootScrollerLayer(), |
| 567 iframe->contentDocument()->view()->layerForScrolling()); |
| 568 ASSERT_FALSE(mainController->isViewportScrollCallback( |
| 569 container->getApplyScroll())); |
| 570 ASSERT_FALSE(mainController->isViewportScrollCallback( |
| 571 mainFrame()->document()->documentElement()->getApplyScroll())); |
| 572 ASSERT_TRUE(mainController->isViewportScrollCallback( |
| 573 iframe->contentDocument()->documentElement()->getApplyScroll())); |
| 574 } |
| 575 |
| 576 // Finally, unsetting the main frame's root scroller should reset it to the |
| 577 // documentElement and corresponding layer. |
| 578 { |
| 579 mainFrame()->document()->setRootScroller(nullptr, nonThrow); |
| 580 ASSERT_EQ( |
| 581 mainController->rootScrollerLayer(), |
| 582 mainFrameView()->layerForScrolling()); |
| 583 ASSERT_TRUE(mainController->isViewportScrollCallback( |
| 584 mainFrame()->document()->documentElement()->getApplyScroll())); |
| 585 ASSERT_FALSE(mainController->isViewportScrollCallback( |
| 586 container->getApplyScroll())); |
| 587 ASSERT_FALSE(mainController->isViewportScrollCallback( |
| 588 iframe->contentDocument()->documentElement()->getApplyScroll())); |
| 589 } |
| 590 } |
| 591 |
| 592 TEST_F(RootScrollerTest, TestSetRootScrollerCausesViewportLayerChange) |
| 593 { |
| 594 // TODO(bokan): Need a test that changing root scrollers actually sets the |
| 595 // outer viewport layer on the compositor, even in the absence of other |
| 596 // compositing changes. crbug.com/505516 |
| 597 } |
| 598 |
| 599 |
462 // Tests that trying to set an element as the root scroller of a document inside | 600 // Tests that trying to set an element as the root scroller of a document inside |
463 // an iframe fails when that element belongs to the parent document. | 601 // an iframe fails when that element belongs to the parent document. |
464 // TODO(bokan): Recent changes mean this is now possible but should be fixed. | 602 // TODO(bokan): Recent changes mean this is now possible but should be fixed. |
465 TEST_F(RootScrollerTest, DISABLED_TestSetRootScrollerOnElementFromOutsideIframe) | 603 TEST_F(RootScrollerTest, DISABLED_TestSetRootScrollerOnElementFromOutsideIframe) |
466 { | 604 { |
467 initialize("root-scroller-iframe.html"); | 605 initialize("root-scroller-iframe.html"); |
468 | 606 |
469 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 607 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
470 { | 608 { |
471 // Try to set the the root scroller of the child document to be the | 609 // Try to set the the root scroller of the child document to be the |
(...skipping 19 matching lines...) Expand all Loading... |
491 body, | 629 body, |
492 exceptionState); | 630 exceptionState); |
493 | 631 |
494 ASSERT_EQ(body, iframe->contentDocument()->rootScroller()); | 632 ASSERT_EQ(body, iframe->contentDocument()->rootScroller()); |
495 } | 633 } |
496 } | 634 } |
497 | 635 |
498 } // namespace | 636 } // namespace |
499 | 637 |
500 } // namespace blink | 638 } // namespace blink |
OLD | NEW |