Commit 0945d3eb authored by Sandra Sun's avatar Sandra Sun Committed by Commit Bot

Rewrite horizontal-smooth-scroll-in-rtl.html

The original test is written using js-test and is using
shouldBecomeEqual() to verify the scroll offset after the animation,
which makes it flaky.

This patch rewrites the patch using testharness and promise test,
and only checks after the page no longer scrolls or has reached the
specified destination, which would be independent from the platform's
performance, making the test robust.

We separate the waitForWindowScrollEnd into scroll-animation.js so that
other tests can reuse the method. We also change the input-driven scroll
from clicking at scrollbar to keyboard-left so that the test passes
on Mac.

Bug: 664858
Change-Id: I030392484489983453bf7a11b55b05c13fa4a470
Reviewed-on: https://chromium-review.googlesource.com/822988Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Commit-Queue: Sandra Sun <sunyunjia@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523629}
parent 207b7651
......@@ -2724,7 +2724,6 @@ crbug.com/702837 fast/text/aat-morx.html [ Skip ]
crbug.com/688670 media/track/track-cue-rendering-after-controls-removed.html [ Pass Failure ]
crbug.com/664858 virtual/threaded/fast/scroll-behavior/overflow-scroll-animates.html [ Skip ]
crbug.com/664858 virtual/threaded/fast/scroll-behavior/smooth-scroll/horizontal-smooth-scroll-in-rtl.html [ Skip ]
crbug.com/664858 virtual/threaded/fast/scroll-behavior/smooth-scroll/main-thread-scrolling-reason-added.html [ Skip ]
crbug.com/664858 virtual/threaded/fast/scroll-behavior/smooth-scroll/ongoing-smooth-scroll-anchors.html [ Skip ]
crbug.com/664858 virtual/threaded/fast/scroll-behavior/smooth-scroll/ongoing-smooth-scroll-vertical-rl-anchors.html [ Skip ]
......
<!DOCTYPE HTML>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="scroll-animation.js"></script>
<title>The first programmatic smooth scroll runs on compositor</title>
<style>
body {
......@@ -34,35 +35,12 @@ function waitForCompositor() {
});
}
function waitForScrollEnd() {
var last_changed_frame = 0;
var last_x = window.scrollX;
var last_y = window.scrollY;
return new Promise((resolve, reject) => {
function tick(frames) {
// We requestAnimationFrames until 20 frames without observed changes or
// until the window has scolled to the specified destination.
if (frames - last_changed_frame > 20 || window.scrollY == 500) {
resolve();
} else {
if (window.scrollX != last_x || window.scrollY != last_y) {
last_changed_frame = frames;
last_x = window.scrollX;
last_y = window.scrollY;
}
requestAnimationFrame(tick.bind(null, frames + 1));
}
}
tick(0);
});
}
requestAnimationFrame(() => {
promise_test(t => {
document.scrollingElement.scrollTop = 0;
window.scrollBy({top: 500, behavior: "smooth"});
return waitForCompositor()
.then(waitForScrollEnd)
.then(waitForWindowScrollEnd.bind(this, '', 500))
.then(() => {
assert_approx_equals(document.scrollingElement.scrollTop, 500, 1);
});
......
function waitForWindowScrollEnd(end_x, end_y) {
var last_changed_frame = 0;
var last_x = scrollX;
var last_y = scrollY;
return new Promise((resolve, reject) => {
function tick(frames) {
// We requestAnimationFrames until 20 frames without observed changes or
// until the window has scolled to the specified destination.
if (frames - last_changed_frame > 20) {
resolve();
}
if (!(isNaN(end_x) && isNaN(end_y))) {
if ((isNaN(end_x) || scrollX == end_x) &&
(isNaN(end_y) || scrollY == end_y)) {
console.log(scrollY + "==" + end_y);
resolve();
}
}
if (window.scrollX != last_x || window.scrollY != last_y) {
last_changed_frame = frames;
last_x = scrollX;
last_y = scrollY;
}
requestAnimationFrame(tick.bind(null, frames + 1));
}
tick(0);
});
}
\ No newline at end of file
This test verifies that both input-driven and programmatic smooth scrolls serviced by the compositor thread go to the correct scroll position on RTL pages with horizontal overflow.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS scrollX became -80
PASS scrollX became -40
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../../../../../resources/js-test.js"></script>
<!DOCTYPE HTML>
<script src="../../../../../resources/testharness.js"></script>
<script src="../../../../../resources/testharnessreport.js"></script>
<script src="../scroll-animation.js"></script>
<title>The first programmatic smooth scroll runs on compositor</title>
<style>
html {
......@@ -10,31 +13,25 @@ html {
</style>
<script>
var jsTestIsAsync = true;
function inputDrivenScroll() {
return new Promise((resolve, reject) => {
eventSender.keyDown("ArrowLeft");
resolve();
});
}
description("This test verifies that both input-driven and programmatic " +
promise_test(t => {
return inputDrivenScroll()
.then(waitForWindowScrollEnd.bind(this, -40, ''))
.then(() => {
assert_equals(scrollX, -40);
scrollBy({left: 40, behavior: "smooth"});})
.then(waitForWindowScrollEnd.bind(this, 0, ''))
.then(() => {
assert_equals(scrollX, 0);
});
}, "This test verifies that both input-driven and programmatic " +
"smooth scrolls serviced by the compositor thread go to the correct " +
"scroll position on RTL pages with horizontal overflow.");
onload = function() {
if (!window.eventSender) {
debug("This test requires window.eventSender.")
finishJSTest();
return;
}
// Start scrolled due to http://crbug.com/592799.
scrollBy(-120, 0);
// Click scrollbar stepper.
eventSender.mouseMoveTo(795, 595);
eventSender.mouseDown();
eventSender.mouseUp();
shouldBecomeEqual("scrollX", "-80", function() {
scrollBy({left: 40, behavior: "smooth"});
shouldBecomeEqual("scrollX", "-40", finishJSTest);
});
};
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment