<!DOCTYPE html>
<html>
<head>
<link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-WheelEvent">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../../resources/percent-based-util.js"></script>
</head>
<body>
<span id="parent">
<div id="target" style="border:solid 1px green; width:220px; height:70px; overflow:scroll; white-space:nowrap;">
TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP<br/>
Scroll mouse wheel over here<br/>
Scroll mouse wheel over here<br/>
Scroll mouse wheel over here<br/>
Scroll mouse wheel over here<br/>
Scroll mouse wheel over here<br/>
Scroll mouse wheel over here<br/>
END END END END END END END END END END END END END END<br/>
</div>
</span>
<div id="console"></div>
</body>
<script>
let deltaX = 0;
let deltaY = 0;
promise_test(async () => {
// Basic checks.
assert_equals(WheelEvent.__proto__, MouseEvent);
assert_equals(WheelEvent.prototype.__proto__, MouseEvent.prototype);
assert_equals(WheelEvent.DOM_DELTA_PIXEL, 0x00);
assert_equals(WheelEvent.DOM_DELTA_LINE, 0x01);
assert_equals(WheelEvent.DOM_DELTA_PAGE, 0x02);
const testDiv = document.getElementById('target');
assert_equals(window.onwheel, null);
assert_equals(document.onwheel, null);
assert_equals(testDiv.onwheel, null);
testDiv.addEventListener('wheel', wheelHandler);
const x = testDiv.offsetLeft + 5;
const y = testDiv.offsetTop + 5;
await mouseMoveTo(x, y);
const pixelsToScroll = 40;
await gestureScroll(() => {
return smoothScroll(
pixelsToScroll, x, y, GestureSourceType.MOUSE_INPUT, 'downright', SPEED_INSTANT, !isPercentBasedScrollingEnabled()
);
}, testDiv);
if (isPercentBasedScrollingEnabled()) {
const {
x: expectedScrollLeft,
y: expectedScrollTop,
} = calculateExpectedScroll(testDiv, pixelsToScroll, pixelsToScroll);
// Windows and Linux values appear to be slightly different
assert_approx_equals(testDiv.scrollTop, expectedScrollTop, 0.05);
assert_approx_equals(testDiv.scrollLeft, expectedScrollLeft, 0.1);
} else {
assert_true(!!deltaX);
assert_true(!!deltaY);
assert_equals(testDiv.scrollLeft, deltaX);
assert_equals(testDiv.scrollTop, deltaY);
}
}, "Tests the basic functionality of the standard wheel event");
let testEvent;
function wheelHandler(e) {
testEvent = e;
assert_equals(testEvent.__proto__, WheelEvent.prototype);
assert_equals(testEvent.__proto__.__proto__, MouseEvent.prototype);
if (e.deltaX)
deltaX = e.deltaX;
if (e.deltaY)
deltaY = e.deltaY;
assert_equals(testEvent.deltaZ, 0);
assert_equals(testEvent.deltaMode, WheelEvent.DOM_DELTA_PIXEL);
}
</script>
</html>