<!DOCTYPE html>
<title>Tests mouse interactions.</title>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="../../../../resources/gesture-util.js"></script>
<script src="../../../../resources/blink-coordinates-util.js"></script>
<script src="../../../../resources/scrollbar-util.js"></script>
<script src="../../../../resources/testdriver.js"></script>
<script src="../../../../resources/testdriver-actions.js"></script>
<script src="../../../../resources/testdriver-vendor.js"></script>
<style>
.appearance {
width: 100px;
height: 100px;
overflow: scroll;
border: 1px solid black;
}
.standardLocation {
position: absolute;
top: 100px;
left: 100px;
}
.space {
height: 200px;
width: 200px;
}
</style>
<!-- Standard scroller -->
<div id="standard" class="appearance standardLocation">
<div class="space"></div>
</div>
<script>
if (window.internals)
internals.settings.setScrollAnimatorEnabled(false);
window.onload = () => {
// http://crrev.com/c/1856359 disables mock theme and makes tests use the
// native theme. Hence, values will differ between platforms for both, main
// and compositor thread scrolling.
const onLinuxPlatform = navigator.userAgent.search(/\bLinux\b/) != -1;
const onMacPlatform = navigator.userAgent.search(/\bMac OS X\b/) != -1;
const standardDivFast = document.getElementById("standard");
const standardRectFast = standardDivFast.getBoundingClientRect();
const TRACK_WIDTH = calculateScrollbarThickness();
const BUTTON_WIDTH = TRACK_WIDTH;
const SCROLL_CORNER = TRACK_WIDTH;
const SCROLLBAR_BUTTON_FWD = {
x: standardRectFast.right - BUTTON_WIDTH / 2,
y: standardRectFast.bottom - SCROLL_CORNER - BUTTON_WIDTH / 2
}
const SCROLLBAR_THUMB = {
x: standardRectFast.right - TRACK_WIDTH / 2,
y: standardRectFast.top + BUTTON_WIDTH + 5
}
promise_test (async () => {
await waitForScrollReset(standardDivFast);
// Click on the track part just above the down arrow.
await clickScroll(SCROLLBAR_BUTTON_FWD.x,
SCROLLBAR_BUTTON_FWD.y - 10,
standardDivFast);
assert_approx_equals(standardDivFast.scrollTop, 74,
1/window.devicePixelRatio,
"Pressing the down trackpart didn't scroll.");
}, "Test mouse click on non-custom composited div scrollbar empty " +
"trackparts.");
promise_test (async () => {
await waitForScrollReset(standardDivFast);
// Testing the vertical scrollbar thumb.
const dx = 0;
const dy = 20;
await mouseDragScroll(SCROLLBAR_THUMB.x, SCROLLBAR_THUMB.y, dx, dy,
standardDivFast);
let expected_offset = 0;
// If Fluent is enabled, Linux and Windows behavior should match
if (onLinuxPlatform && !internals.runtimeFlags.fluentScrollbarsEnabled)
expected_offset = 92;
else if (onMacPlatform)
expected_offset = 46.5;
else
expected_offset = window.devicePixelRatio == 1 ? 71 : 73;
assert_approx_equals(
standardDivFast.scrollTop, expected_offset, 1/window.devicePixelRatio,
"Vertical thumb drag downwards did not scroll as expected.");
}, "Test mouse drags on non-custom composited div scrollbar thumb.");
promise_test (async () => {
// Since scrollbars on Mac don't have buttons, this test is irrelevant.
if(onMacPlatform)
return;
await waitForScrollReset(standardDivFast);
// Click on the Down arrow for standardRectFast.
await clickScroll(SCROLLBAR_BUTTON_FWD.x, SCROLLBAR_BUTTON_FWD.y,
standardDivFast);
const EXPECTED_SCROLL = getScrollbarButtonScrollDelta(standardDivFast).y;
assert_approx_equals(
standardDivFast.scrollTop, EXPECTED_SCROLL, 1/window.devicePixelRatio,
"Pressing the down arrow didn't scroll.");
}, "Test mouse click on non-custom composited div scrollbar arrows.");
promise_test (async () => {
await waitForScrollReset(standardDivFast);
// Testing forward scroll on vertical scrollbar. Mac uses "Option" key
// instead of "Shift". The Option key is mapped to "Alt" in GPUbenchmarking.
const modifier = onMacPlatform ? "Alt" : "Shift";
let scrollPromise = waitForScrollendEvent(standardDivFast);
// TODO: Switch to test-driver variant. Unclear from the test-driver
// documentation if pointerDown supports a 'keys' option.
var point = {
x: SCROLLBAR_BUTTON_FWD.x,
y: standardRectFast.top + 50,
left_click: 0,
input_modifier: modifier
}
await mouseClickHelper(point);
await scrollPromise;
let expected_offset = 0;
// If Fluent is enabled, Linux and Windows behavior should match
if (onLinuxPlatform && !internals.runtimeFlags.fluentScrollbarsEnabled)
expected_offset = 87;
else if (onMacPlatform)
expected_offset = 72.5;
else
expected_offset = 82;
assert_approx_equals(
standardDivFast.scrollTop, expected_offset, 1/window.devicePixelRatio,
modifier + " + click forward didn't scroll.");
scrollPromise = waitForScrollendEvent(standardDivFast);
point.x = SCROLLBAR_BUTTON_FWD.x;
point.y = standardRectFast.top + ((onMacPlatform ? 0 : BUTTON_WIDTH) + 2);
point.left_click = 0;
point.input_modifier = modifier;
await mouseClickHelper(point);
await scrollPromise;
assert_equals(standardDivFast.scrollTop, 0, modifier + " + click backward didn't scroll.");
}, "Test non-animated click scroll on non-custom composited scrollbars.");
}
</script>