| <!DOCTYPE html> | |
| <style> | |
| ::-webkit-scrollbar { | |
| width: 0px; | |
| height: 0px; | |
| } | |
| body, html { | |
| width: 100%; | |
| height: 100%; | |
| } | |
| body { | |
| margin: 0px; | |
| } | |
| #container { | |
| width: 100%; | |
| height: 100%; | |
| overflow: auto; | |
| } | |
| #parent { | |
| width: 100%; | |
| height: 100%; | |
| overflow: auto; | |
| } | |
| .spacer { | |
| width: 2000px; | |
| height: 2000px; | |
| } | |
| #rootspacer { | |
| width: 1000px; | |
| height: 1000px; | |
| position: absolute; | |
| top: 0px; | |
| left: 0px; | |
| z-index: -1; | |
| } | |
| </style> | |
| <div id="parent"> | |
| <div id="container"> | |
| <div class="spacer"> | |
| <span id="spanner">TEST</span> | |
| </div> | |
| </div> | |
| <div class="spacer"></div> | |
| </div> | |
| <div id="rootspacer"></div> | |
| <script src="../resources/testharness.js"></script> | |
| <script src="../resources/testharnessreport.js"></script> | |
| <script src="../resources/gesture-util.js"></script> | |
| <script> | |
| var parentScroller = document.querySelector('#parent'); | |
| var container = document.querySelector('#container'); | |
| var spanner = document.querySelector('#spanner'); | |
| async function setRootScrollerAndCheckEffective(element, expected_effective) { | |
| document.rootScroller = element; | |
| // Root Scroller selection happens in a lifecycle update. However, rAF is | |
| // executed before the lifecycle in a BeginMainFrame so we need to wait for | |
| // a second rAF before the we can check the effective root scrollers. | |
| await waitForCompositorCommit(); | |
| assert_equals(window.internals.effectiveRootScroller(document), | |
| expected_effective, | |
| "Unexpected effective root scroller"); | |
| } | |
| test(async function() { | |
| assert_false(typeof document.rootScroller === 'undefined'); | |
| }, 'setRootScroller API enabled'); | |
| test(async function() { | |
| // Setting the container object should succeed. | |
| assert_equals(document.rootScroller, null); | |
| document.rootScroller = container; | |
| assert_equals(document.rootScroller, container); | |
| document.rootScroller = null; | |
| assert_equals(document.rootScroller, null); | |
| }, 'Setter and getter on a valid element works'); | |
| test(async function() { | |
| // Trying to set the <span> should succeed even though it's not a valid | |
| // scroller. | |
| setRootScrollerAndCheckEffective(spanner, document); | |
| assert_equals(document.rootScroller, spanner); | |
| }, 'Can set a non-scrolling element as the rootScroller'); | |
| test(async function() { | |
| // Scroll the container <div> past the end. The scrolls should not chain | |
| // past the rootScroller to the parentScroller element. | |
| setRootScrollerAndCheckEffective(container, container); | |
| if (typeof eventSender !== 'undefined') { | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| assert_equals(container.scrollTop, 2000 - 600); | |
| assert_equals(container.scrollLeft, 2000 - 800); | |
| // The container is now fully scrolled. Normally, further scroll | |
| // events would chain up to the parent element but, because the | |
| // container is the root scroller, we shouldn't chain up past it. | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| assert_equals(container.scrollTop, 2000 - 600); | |
| assert_equals(container.scrollLeft, 2000 - 800); | |
| assert_equals(parentScroller.scrollTop, 0); | |
| assert_equals(parentScroller.scrollLeft, 0); | |
| } | |
| }, "Scrolls don't chain past root scroller element"); | |
| test(async function() { | |
| setRootScrollerAndCheckEffective(container, container); | |
| container.scrollTop = 999; | |
| container.scrollLeft = 998; | |
| // Window.scrollX and scrollY should reflect the scroll offset of the | |
| // rootScroller | |
| assert_equals(container.scrollTop, 999); | |
| assert_equals(container.scrollLeft, 998); | |
| // TODO(bokan): These need to be fixed since landing inert-visual-viewport. crbug.com/505516 | |
| // assert_equals(window.scrollY, container.scrollTop, "ScrollY"); | |
| // assert_equals(window.scrollX, container.scrollLeft, "ScrollX"); | |
| // assert_equals(document.scrollingElement.scrollTop, container.scrollTop, "scrollingElement.scrollTop"); | |
| // assert_equals(document.scrollingElement.scrollLeft, container.scrollLeft, "scrollingElement.scrollLeft"); | |
| }, "document.scrollingElement and window scroll API reflect rootScroller offsets"); | |
| test(async function() { | |
| // Making the current rootScroller an invalid scroller (by making it not | |
| // fill the viewport) should fallback to the default element, the | |
| // documentElement, but the rootScroller property should remain the same. | |
| setRootScrollerAndCheckEffective(container, container); | |
| container.style.width = "95%"; | |
| // We need a compositing update since root scroller selection happens as | |
| // part of a full lifecycle update. | |
| window.internals.forceCompositingUpdate(document); | |
| assert_equals(window.internals.effectiveRootScroller(document), document, | |
| "Effective root scroller should be reset after width is modified"); | |
| assert_equals(document.rootScroller, container); | |
| // Reset parentScroller's offsets, make container fully scrolled. | |
| parentScroller.scrollTop = 0; | |
| parentScroller.scrollLeft = 0; | |
| container.scrollTop = 10000; | |
| container.scrollLeft = 10000; | |
| // Now scrolling over the container should bubble the scroll up to the | |
| // scrollingElement since the rootElement is invalid (doesn't fill the | |
| // viewport). | |
| if (typeof eventSender !== 'undefined') { | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| eventSender.gestureScrollBegin(500, 500); | |
| eventSender.gestureScrollUpdate(-300, -300); | |
| eventSender.gestureScrollEnd(0, 0); | |
| assert_equals(parentScroller.scrollTop, 900); | |
| assert_equals(parentScroller.scrollLeft, 900); | |
| } | |
| }, "Setting an invalid rootScroller should reset to using the documentElement."); | |
| </script> |