<!DOCTYPE html>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="../../../../resources/gesture-util.js"></script>
<body style="margin:0">
<div id="container" style="height: 500px; overflow-x: scroll; overflow-y: scroll">
<select id="box" style="width=200px" size="5">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
<option>Option 6</option>
<option>Option 7</option>
<option>Option 8</option>
<option>Option 9</option>
<option>Option 10</option>
<option>Option 11</option>
</select>
<div style="background: green; height: 1000px; width: 1000px"></div>
</div>
</body>
<script type="text/javascript">
var box = document.getElementById("box");
var gestureX = box.getBoundingClientRect().left + (box.clientWidth / 2);
var gestureY = box.getBoundingClientRect().top + (box.clientHeight / 2);
var container = document.getElementById("container");
var itemHeight = box.clientHeight / box.size;
var fullyScrolled = box.scrollHeight - box.clientHeight;
function resetScroll() {
container.scrollTop = 0;
box.scrollTop = 0;
container.scrollLeft = 0;
box.scrollLeft = 0;
}
promise_test (async () => {
resetScroll();
assert_equals(box.scrollTop, 0);
assert_equals(container.scrollTop, 0);
let scrollEndPromise = waitForScrollendEvent(box);
await swipe(2 * itemHeight + 10, gestureX, gestureY, "up", SPEED_INSTANT);
await scrollEndPromise;
assert_greater_than(box.scrollTop, 2 * itemHeight + 10);
assert_equals(container.scrollTop, 0);
resetScroll();
assert_equals(box.scrollTop, 0);
scrollEndPromise = waitForScrollendEvent(box);
await swipe(fullyScrolled + 500, gestureX, gestureY, "up", SPEED_INSTANT);
await scrollEndPromise;
assert_equals(box.scrollTop, fullyScrolled, "box should fully scroll");
// Wait for 100 RAFs to make sure the scroll does not propagate to the
// container.
await conditionHolds(() => { return container.scrollTop == 0; });
// Flinging list past the end should scroll container div when starting at
// scroll extent.
scrollEndPromise = waitForScrollendEvent(container);
await swipe(60, gestureX, gestureY, "up", SPEED_INSTANT);
await scrollEndPromise;
assert_greater_than(container.scrollTop, 60);
assert_equals(box.scrollTop, fullyScrolled);
}, "fling gestures on a list box");
promise_test (async () => {
resetScroll();
assert_equals(box.scrollTop, 0);
assert_equals(container.scrollTop, 0);
let scrollEndPromise = waitForScrollendEvent(box);
await smoothScroll(3 * itemHeight + 6, gestureX, gestureY,
GestureSourceType.TOUCH_INPUT, "down");
await scrollEndPromise;
assert_equals(container.scrollTop, 0);
resetScroll();
assert_equals(box.scrollTop, 0);
scrollEndPromise = waitForScrollendEvent(box);
await smoothScroll(fullyScrolled + 50, gestureX, gestureY,
GestureSourceType.TOUCH_INPUT, "down");
await scrollEndPromise;
assert_equals(box.scrollTop, fullyScrolled, "box should fully scroll");
await conditionHolds(() => { return container.scrollTop == 0; });
// Gesture scrolling list past the end should scroll container div when
// starting at scroll extent.
scrollEndPromise = waitForScrollendEvent(container);
await smoothScroll(fullyScrolled + 50, gestureX, gestureY,
GestureSourceType.TOUCH_INPUT, "down");
await scrollEndPromise;
assert_approx_equals(container.scrollTop, fullyScrolled + 50, 2,
"container should scroll to approx. " + (fullyScrolled + 50));
}, "gesture scroll on a list box");
promise_test (async () => {
resetScroll();
assert_equals(box.scrollTop, 0);
assert_equals(container.scrollTop, 0);
let scrollEndPromise = waitForScrollendEvent(container);
await smoothScroll(60, gestureX, gestureY,
GestureSourceType.TOUCH_INPUT, "right");
await scrollEndPromise;
assert_equals(box.scrollLeft, 0,
"Horizontal scrolls should not affect listbox");
}, "Horizontal scroll on a list box");
</script>