| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="../resources/gesture-util.js"></script> |
| <style> |
| ::-webkit-scrollbar { |
| width: 0px; |
| height: 0px; |
| } |
| |
| body, html { |
| width: 100%; |
| height: 100%; |
| margin: 0; |
| } |
| |
| #rootscroller { |
| width: 100%; |
| height: 100%; |
| overflow: auto; |
| position: absolute; |
| left: 0; |
| top: 0; |
| z-index: -1; |
| background-color: red; |
| } |
| |
| .spacer { |
| width: 200%; |
| height: 200%; |
| } |
| |
| #inflow { |
| width: 200%; |
| height: 200%; |
| background-color: lightgreen; |
| z-index: 1; |
| } |
| </style> |
| |
| <div id="rootscroller"> |
| <div class="spacer"> |
| </div> |
| </div> |
| |
| <!--This element overflows the viewport and appears over the root scroller. |
| Therefore, gesture scrolls will target it and should scroll the document rather |
| than the root scroller --> |
| <div id="inflow"> |
| This test ensures that when the document is not the root scroller, i.e. |
| another element has been set as document.rootScroller, it can still be |
| scrolled via gesture scrolls. |
| </div> |
| |
| <script> |
| if (window.internals) |
| internals.settings.setScrollAnimatorEnabled(false); |
| |
| function scrollDown(pixels_to_scroll, start_x, start_y, |
| gesture_source_type, speed_in_pixels_s) { |
| return new Promise((resolve, reject) => { |
| chrome.gpuBenchmarking.smoothScrollBy(pixels_to_scroll, |
| resolve, |
| start_x, |
| start_y, |
| gesture_source_type, |
| 'down', |
| speed_in_pixels_s); |
| }); |
| } |
| |
| function waitForScroll() { |
| const MAX_FRAME = 500; |
| return new Promise((resolve, reject) => { |
| function tick(frames) { |
| // We requestAnimationFrame either for 500 frames or until scrollable |
| // scrolls. |
| if (frames >= MAX_FRAME || document.scrollingElement.scrollTop > 0) |
| resolve(); |
| else |
| requestAnimationFrame(tick.bind(this, frames + 1)); |
| } |
| tick(0); |
| }); |
| } |
| |
| window.onload = async () => { |
| var rootscroller = document.querySelector('#rootscroller'); |
| document.rootScroller = rootscroller; |
| |
| // 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(); |
| |
| promise_test( t => { |
| if (window.internals) { |
| assert_equals(window.internals.effectiveRootScroller(document), |
| rootscroller, |
| "#rootscroller must be the effective root scroller"); |
| } |
| const GESTURE_SOURCE_TYPE = 2; // MOUSE_INPUT from synthetic_gesture_params.h |
| return scrollDown(500, 100, 100, GESTURE_SOURCE_TYPE, 1000) |
| .then(waitForScroll) |
| .then(() => { |
| assert_greater_than(document.scrollingElement.scrollTop, |
| 0, |
| "Document must be scrolled"); |
| assert_equals(rootscroller.scrollTop, |
| 0, |
| "RootScroller must not be scrolled"); |
| }); |
| }, "Gesture scrolling should scroll document."); |
| } |
| </script> |