| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.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> |
| 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); |
| }); |
| } |
| |
| // Do a rAF before actually starting the test to ensure we leave enough time |
| // to commit layers to the compositor before we start scrolling. |
| window.onload = function() { requestAnimationFrame(() => { |
| var rootscroller = document.querySelector('#rootscroller'); |
| document.rootScroller = rootscroller; |
| |
| promise_test( t => { |
| const GESTURE_SOURCE_TYPE = 2; // MOUSE_INPUT from synthetic_gesture_params.h |
| return scrollDown(500, 100, 100, GESTURE_SOURCE_TYPE, 1000) |
| .then(waitForScroll) |
| .then(() => { |
| if (window.internals) { |
| assert_equals(internals.effectiveRootScroller(document), |
| rootscroller, |
| "Failed to set root scroller"); |
| } |
| |
| 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> |