Skip to content

Commit

Permalink
Simulate user inputs in css-scroll-snap/snap-at-user-scroll-end.html
Browse files Browse the repository at this point in the history
Use testdriver Action API to simulate wheel scroll actions in
css/css-scroll-snap/snap-at-user-scroll-end.html.

Bug: 1145677
Change-Id: I56d99d22a325419865fdc18dfa4cf0a3ae55df51
  • Loading branch information
LanWei22 authored and chromium-wpt-export-bot committed Nov 26, 2020
1 parent 7726454 commit c0c4574
Showing 1 changed file with 47 additions and 2 deletions.
Expand Up @@ -3,8 +3,11 @@
<title>Tests that window should snap at user scroll end.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
body {
html {
margin: 0px;
scroll-snap-type: both mandatory;
}
Expand Down Expand Up @@ -55,6 +58,38 @@ <h4>Tests that the window can snap at user scroll end.</h4>
var scrolled_y = false;
var start_x = window.scrollX;
var start_y = window.scrollY;
var actions_promise;

function smoothScrollByXY(xPosition, yPosition, xScrollOffset, yScrollOffset) {
return new test_driver.Actions()
.scroll(xPosition, yPosition, xScrollOffset, yScrollOffset)
.send();
}

function waitForAnimationEnd() {
const MAX_FRAME = 500;
var last_changed_frame = 0;
var last_window_x = window.scrollX;
var last_window_y = window.scrollY;
return new Promise((resolve, reject) => {
function tick(frames) {
// We requestAnimationFrame either for 500 frames or until 15 frames with
// no change have been observed.
if (frames >= MAX_FRAME || frames - last_changed_frame > 15) {
resolve();
} else {
if (window.scrollX != last_window_x ||
window.scrollY != last_window_y) {
last_changed_frame = frames;
last_window_x = window.scrollX;
last_window_y = window.scrollY;
}
requestAnimationFrame(tick.bind(this, frames + 1));
}
}
tick(0);
});
}

window.onscroll = function() {
if (scrolled_x && scrolled_y) {
Expand Down Expand Up @@ -84,7 +119,17 @@ <h4>Tests that the window can snap at user scroll end.</h4>
// To make the test result visible.
var content = document.getElementById("content");
body.removeChild(content);
snap_test.done();
actions_promise.then( () => {
snap_test.done();
});
}

// Inject scroll actions.
actions_promise = new test_driver.Actions()
.scroll(20, 20, 100, 100)
.send().then(() => {
return waitForAnimationEnd();
}).then(() => {
return test_driver.click(button);
});
</script>

0 comments on commit c0c4574

Please sign in to comment.