test: update Web Events WPT

This updates the tests and the status file via running
`git node wpt dom/events`.

PR-URL: https://github.com/nodejs/node/pull/46051
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Deokjin Kim authored and GitHub committed 2023-01-10 20:01:49 +00:00
1 parent 2af83ea0f8
commit 2363634076
66 files changed
+1874 -97

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ Last update:
- common: https://github.com/web-platform-tests/wpt/tree/03c5072aff/common
- console: https://github.com/web-platform-tests/wpt/tree/767ae35464/console
- dom/abort: https://github.com/web-platform-tests/wpt/tree/8fadb38120/dom/abort
- dom/events: https://github.com/web-platform-tests/wpt/tree/f8821adb28/dom/events
- dom/events: https://github.com/web-platform-tests/wpt/tree/ab8999891c/dom/events
- encoding: https://github.com/web-platform-tests/wpt/tree/779d175c40/encoding
- fetch/data-urls/resources: https://github.com/web-platform-tests/wpt/tree/7c79d998ff/fetch/data-urls/resources
- FileAPI: https://github.com/web-platform-tests/wpt/tree/3b279420d4/FileAPI
@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html>
<title>HTMLBodyElement and HTMLFrameSetElement Event Handler Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function getObject(interface) {
switch(interface) {
case "Element":
var e = document.createElementNS("http://example.com/", "example");
assert_true(e instanceof Element);
assert_false(e instanceof HTMLElement);
assert_false(e instanceof SVGElement);
return e;
case "HTMLElement":
var e = document.createElement("html");
assert_true(e instanceof HTMLElement);
return e;
case "HTMLBodyElement":
var e = document.createElement("body");
assert_true(e instanceof HTMLBodyElement);
return e;
case "HTMLFormElement":
var e = document.createElement("form");
assert_true(e instanceof HTMLFormElement);
return e;
case "HTMLFrameSetElement":
var e = document.createElement("frameset");
assert_true(e instanceof HTMLFrameSetElement);
return e;
case "SVGElement":
var e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
assert_true(e instanceof SVGElement);
return e;
case "Document":
assert_true(document instanceof Document);
return document;
case "Window":
assert_true(window instanceof Window);
return window;
}
assert_unreached();
}
function testSet(interface, attribute) {
test(function() {
var object = getObject(interface);
function nop() {}
assert_equals(object[attribute], null, "Initially null");
object[attribute] = nop;
assert_equals(object[attribute], nop, "Return same function");
object[attribute] = "";
assert_equals(object[attribute], null, "Return null after setting string");
object[attribute] = null;
assert_equals(object[attribute], null, "Finally null");
}, "Set " + interface + "." + attribute);
}
function testReflect(interface, attribute) {
test(function() {
var element = getObject(interface);
assert_false(element.hasAttribute(attribute), "Initially missing");
element.setAttribute(attribute, "return");
assert_equals(element.getAttribute(attribute), "return", "Return same string");
assert_equals(typeof element[attribute], "function", "Convert to function");
element.removeAttribute(attribute);
}, "Reflect " + interface + "." + attribute);
}
function testForwardToWindow(interface, attribute) {
test(function() {
var element = getObject(interface);
window[attribute] = null;
element.setAttribute(attribute, "return");
assert_equals(typeof window[attribute], "function", "Convert to function");
assert_equals(window[attribute], element[attribute], "Forward content attribute");
function nop() {}
element[attribute] = nop;
assert_equals(window[attribute], nop, "Forward IDL attribute");
window[attribute] = null;
}, "Forward " + interface + "." + attribute + " to Window");
}
// Object.propertyIsEnumerable cannot be used because it doesn't
// work with properties inherited through the prototype chain.
function getEnumerable(interface) {
var enumerable = {};
for (var attribute in getObject(interface)) {
enumerable[attribute] = true;
}
return enumerable;
}
var enumerableCache = {};
function testEnumerate(interface, attribute) {
if (!(interface in enumerableCache)) {
enumerableCache[interface] = getEnumerable(interface);
}
test(function() {
assert_true(enumerableCache[interface][attribute]);
}, "Enumerate " + interface + "." + attribute);
}
[
"onblur",
"onerror",
"onfocus",
"onload",
"onscroll",
"onresize"
].forEach(function(attribute) {
testSet("HTMLBodyElement", attribute);
testEnumerate("HTMLBodyElement", attribute);
testReflect("HTMLBodyElement", attribute);
testForwardToWindow("HTMLBodyElement", attribute);
testSet("HTMLFrameSetElement", attribute);
testEnumerate("HTMLFrameSetElement", attribute);
testReflect("HTMLFrameSetElement", attribute);
testForwardToWindow("HTMLFrameSetElement", attribute);
});
</script>
</html>
@@ -1,5 +1,11 @@
// META: title=Event constructors
test(function() {
assert_throws_js(
TypeError,
() => Event(""),
"Calling Event constructor without 'new' must throw")
})
test(function() {
assert_throws_js(TypeError, function() {
new Event()
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>window.onerror handler restores window.event after it reports an exception</title>
<link rel="help" href="https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<iframe src="resources/empty-document.html"></iframe>
<iframe src="resources/empty-document.html"></iframe>
<script>
setup({ allow_uncaught_exception: true });
async_test(t => {
window.onload = t.step_func_done(onLoadEvent => {
frames[0].onerror = new frames[1].Function(`
top.eventDuringSecondOnError = top.window.event;
top.frames[0].eventDuringSecondOnError = top.frames[0].event;
top.frames[1].eventDuringSecondOnError = top.frames[1].event;
`);
window.onerror = new frames[0].Function(`
top.eventDuringFirstOnError = top.window.event;
top.frames[0].eventDuringFirstOnError = top.frames[0].event;
top.frames[1].eventDuringFirstOnError = top.frames[1].event;
foo; // cause second onerror
`);
const myEvent = new ErrorEvent("error", { error: new Error("myError") });
window.dispatchEvent(myEvent);
assert_equals(top.eventDuringFirstOnError, onLoadEvent);
assert_equals(frames[0].eventDuringFirstOnError, myEvent);
assert_equals(frames[1].eventDuringFirstOnError, undefined);
assert_equals(top.eventDuringSecondOnError, onLoadEvent);
assert_equals(frames[0].eventDuringSecondOnError, myEvent);
assert_equals(frames[1].eventDuringSecondOnError.error.name, "ReferenceError");
});
});
</script>
+26
View File
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<title>Script created MouseEvent properly retargets and adjusts offsetX</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body {
margin: 8px;
padding: 0;
}
</style>
<div id="target">Hello</div>
<script>
async_test(t => {
target.addEventListener('click', ev => {
t.step(() => assert_equals(ev.offsetX, 42));
t.done();
});
const ev = new MouseEvent('click', { clientX: 50 });
target.dispatchEvent(ev);
}, "offsetX is correctly adjusted");
</script>
@@ -0,0 +1,80 @@
<!doctype html>
<html>
<head>
<meta chareset="utf-8">
<title>Clicking editable content in link shouldn't cause redundant focus related events</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>
</head>
<body>
<a href="#"><span contenteditable>Hello</span></a>
<a href="#" contenteditable><span>Hello</span></a>
<script>
function promiseTicks() {
return new Promise(resolve => {
requestAnimationFrame(() => {
requestAnimationFrame(resolve);
});
});
}
async function clickElementAndCollectFocusEvents(x, y, options) {
await promiseTicks();
let events = [];
for (const eventType of ["focus", "blur", "focusin", "focusout"]) {
document.addEventListener(eventType, event => {
events.push(`type: ${event.type}, target: ${event.target.nodeName}`);
}, {capture: true});
}
const waitForClickEvent = new Promise(resolve => {
addEventListener("click", resolve, {capture: true, once: true});
});
await new test_driver
.Actions()
.pointerMove(x, y, options)
.pointerDown()
.pointerUp()
.send();
await waitForClickEvent;
await promiseTicks();
return events;
}
promise_test(async t => {
document.activeElement?.blur();
const editingHost = document.querySelector("span[contenteditable]");
editingHost.blur();
const focusEvents =
await clickElementAndCollectFocusEvents(5, 5, {origin: editingHost});
assert_array_equals(
focusEvents,
[
"type: focus, target: SPAN",
"type: focusin, target: SPAN",
],
"Click event shouldn't cause redundant focus events");
}, "Click editable element in link");
promise_test(async t => {
document.activeElement?.blur();
const editingHost = document.querySelector("a[contenteditable]");
editingHost.blur();
const focusEvents =
await clickElementAndCollectFocusEvents(5, 5, {origin: editingHost});
assert_array_equals(
focusEvents,
[
"type: focus, target: A",
"type: focusin, target: A",
],
"Click event shouldn't cause redundant focus events");
}, "Click editable link");
</script>
</body>
</html>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>non-passive mousewheel event listener on body</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'mousewheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<title>non-passive mousewheel event listener on div</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<style>
html, body {
overflow: hidden;
margin: 0;
}
#div {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: scroll;
}
</style>
<div class=remove-on-cleanup id=div>
<div style="height: 200vh"></div>
</div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('div'),
eventName: 'mousewheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>non-passive mousewheel event listener on document</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'mousewheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>non-passive mousewheel event listener on root</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'mousewheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>non-passive mousewheel event listener on window</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'mousewheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchmove event listener on body</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'touchmove',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchmove event listener on div</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('touchDiv'),
eventName: 'touchmove',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchmove event listener on document</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'touchmove',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchmove event listener on root</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'touchmove',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<link rel="help" href="https://github.com/WICG/interventions/issues/35">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'touchstart',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchstart event listener on body</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'touchstart',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchstart event listener on div</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('touchDiv'),
eventName: 'touchstart',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchstart event listener on document</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'touchstart',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchstart event listener on root</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'touchstart',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>non-passive touchstart event listener on window</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'touchstart',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>non-passive wheel event listener on body</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'wheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<title>non-passive wheel event listener on div</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<style>
html, body {
overflow: hidden;
margin: 0;
}
#div {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: scroll;
}
</style>
<div class=remove-on-cleanup id=div>
<div style="height: 200vh"></div>
</div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('div'),
eventName: 'wheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>non-passive wheel event listener on document</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'wheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>non-passive wheel event listener on root</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'wheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>non-passive wheel event listener on window</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'wheel',
passive: false,
expectCancelable: true,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>passive mousewheel event listener on body</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'mousewheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<title>passive mousewheel event listener on div</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<style>
html, body {
overflow: hidden;
margin: 0;
}
#div {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: scroll;
}
</style>
<div class=remove-on-cleanup id=div>
<div style="height: 200vh"></div>
</div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('div'),
eventName: 'mousewheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>passive mousewheel event listener on document</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'mousewheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>passive mousewheel event listener on root</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'mousewheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>passive mousewheel event listener on window</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<link rel="help" href="https://github.com/w3c/uievents/issues/331">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'mousewheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchmove event listener on body</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'touchmove',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchmove event listener on div</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('touchDiv'),
eventName: 'touchmove',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchmove event listener on document</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'touchmove',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchmove event listener on root</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'touchmove',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchmove event listener on window</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'touchstart',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchstart event listener on body</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'touchstart',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchstart event listener on div</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('touchDiv'),
eventName: 'touchstart',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchstart event listener on document</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'touchstart',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchstart event listener on root</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'touchstart',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>passive touchstart event listener on window</title>
<link rel="help" href="https://w3c.github.io/touch-events/#cancelability">
<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>
<script src="resources/wait-for.js"></script>
<script src="resources/touching.js"></script>
<style>
#touchDiv {
width: 100px;
height: 100px;
}
</style>
<div id="touchDiv"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'touchstart',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>passive wheel event listener on body</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.body,
eventName: 'wheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<title>passive wheel event listener on div</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<style>
html, body {
overflow: hidden;
margin: 0;
}
#div {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: scroll;
}
</style>
<div class=remove-on-cleanup id=div>
<div style="height: 200vh"></div>
</div>
<script>
document.body.onload = () => runTest({
target: document.getElementById('div'),
eventName: 'wheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>passive wheel event listener on document</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document,
eventName: 'wheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>passive wheel event listener on root</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: document.documentElement,
eventName: 'wheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>passive wheel event listener on window</title>
<link rel="help" href="https://w3c.github.io/uievents/#cancelability-of-wheel-events">
<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>
<script src="resources/scrolling.js"></script>
<div class=remove-on-cleanup style="height: 200vh"></div>
<script>
document.body.onload = () => runTest({
target: window,
eventName: 'wheel',
passive: true,
expectCancelable: false,
});
</script>
@@ -0,0 +1,34 @@
function raf() {
return new Promise((resolve) => {
// rAF twice.
window.requestAnimationFrame(() => {
window.requestAnimationFrame(resolve);
});
});
}
async function runTest({target, eventName, passive, expectCancelable}) {
await raf();
let cancelable = null;
let arrived = false;
target.addEventListener(eventName, function (event) {
cancelable = event.cancelable;
arrived = true;
}, {passive:passive, once:true});
promise_test(async (t) => {
t.add_cleanup(() => {
document.querySelector('.remove-on-cleanup')?.remove();
});
const pos_x = Math.floor(window.innerWidth / 2);
const pos_y = Math.floor(window.innerHeight / 2);
const delta_x = 0;
const delta_y = 100;
await new test_driver.Actions()
.scroll(pos_x, pos_y, delta_x, delta_y).send();
await t.step_wait(() => arrived, `Didn't get event ${eventName} on ${target.localName}`);
assert_equals(cancelable, expectCancelable);
});
}
@@ -0,0 +1,34 @@
function waitForCompositorCommit() {
return new Promise((resolve) => {
// rAF twice.
window.requestAnimationFrame(() => {
window.requestAnimationFrame(resolve);
});
});
}
function injectInput(touchDiv) {
return new test_driver.Actions()
.addPointer("touch_pointer", "touch")
.pointerMove(0, 0, {origin: touchDiv})
.pointerDown()
.pointerMove(30, 30)
.pointerUp()
.send();
}
function runTest({target, eventName, passive, expectCancelable}) {
let touchDiv = document.getElementById("touchDiv");
let cancelable = null;
let arrived = false;
target.addEventListener(eventName, function (event) {
cancelable = event.cancelable;
arrived = true;
}, {passive});
promise_test(async () => {
await waitForCompositorCommit();
await injectInput(touchDiv);
await waitFor(() => arrived);
assert_equals(cancelable, expectCancelable);
});
}
@@ -0,0 +1,15 @@
function waitFor(condition, MAX_FRAME = 500) {
return new Promise((resolve, reject) => {
function tick(frames) {
// We requestAnimationFrame either for MAX_FRAME frames or until condition is
// met.
if (frames >= MAX_FRAME)
reject(new Error(`Condition did not become true after ${MAX_FRAME} frames`));
else if (condition())
resolve();
else
requestAnimationFrame(() => tick(frames + 1));
}
tick(0);
});
}
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<title>Synthetic events are always cancelable by default</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dictdef-eventinit">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const eventsMap = {
wheel: 'WheelEvent',
mousewheel: 'WheelEvent',
touchstart: 'TouchEvent',
touchmove: 'TouchEvent',
touchend: 'TouchEvent',
touchcancel: 'TouchEvent',
}
function isCancelable(eventName, interfaceName) {
test(() => {
assert_implements(interfaceName in self, `${interfaceName} should be supported`);
let defaultPrevented = null;
addEventListener(eventName, event => {
event.preventDefault();
defaultPrevented = event.defaultPrevented;
});
const event = new self[interfaceName](eventName);
assert_false(event.cancelable, 'cancelable');
const dispatchEventReturnValue = dispatchEvent(event);
assert_false(defaultPrevented, 'defaultPrevented');
assert_true(dispatchEventReturnValue, 'dispatchEvent() return value');
}, `Synthetic ${eventName} event with interface ${interfaceName} is not cancelable`);
}
for (const eventName in eventsMap) {
isCancelable(eventName, eventsMap[eventName]);
isCancelable(eventName, 'Event');
}
</script>
+50
View File
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<title>Default passive event listeners on window, document, document element, body</title>
<link rel="help" href="https://dom.spec.whatwg.org/#default-passive-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="div"></div>
<script>
function isListenerPassive(eventName, eventTarget, passive, expectPassive) {
test(() => {
let defaultPrevented = null;
let handler = event => {
event.preventDefault();
defaultPrevented = event.defaultPrevented;
eventTarget.removeEventListener(eventName, handler);
};
if (passive === 'omitted') {
eventTarget.addEventListener(eventName, handler);
} else {
eventTarget.addEventListener(eventName, handler, {passive});
}
let dispatchEventReturnValue = eventTarget.dispatchEvent(new Event(eventName, {cancelable: true}));
assert_equals(defaultPrevented, !expectPassive, 'defaultPrevented');
assert_equals(dispatchEventReturnValue, expectPassive, 'dispatchEvent() return value');
}, `${eventName} listener is ${expectPassive ? '' : 'non-'}passive ${passive === 'omitted' ? 'by default' : `with {passive:${passive}}`} for ${eventTarget.constructor.name}`);
}
const eventNames = {
touchstart: true,
touchmove: true,
wheel: true,
mousewheel: true,
touchend: false
};
const passiveEventTargets = [window, document, document.documentElement, document.body];
const div = document.getElementById('div');
for (const eventName in eventNames) {
for (const eventTarget of passiveEventTargets) {
isListenerPassive(eventName, eventTarget, 'omitted', eventNames[eventName]);
isListenerPassive(eventName, eventTarget, undefined, eventNames[eventName]);
isListenerPassive(eventName, eventTarget, false, false);
isListenerPassive(eventName, eventTarget, true, true);
}
isListenerPassive(eventName, div, 'omitted', false);
isListenerPassive(eventName, div, undefined, false);
isListenerPassive(eventName, div, false, false);
isListenerPassive(eventName, div, true, true);
}
</script>
+2 -1
View File
@@ -39,7 +39,8 @@ body { margin: 0; padding: 10px; }
promise_test(async t => {
await new test_driver.Actions().scroll(50, 50, 0, 50).send();
assert_equals(scroller.scrollTop, 50);
// Allow the possibility the scroll is not fully synchronous
await t.step_wait(() => scroller.scrollTop === 50);
}, "Wheel scroll in iframe chains to containing element.");
</script>
+67 -1
View File
@@ -1,8 +1,22 @@
async function waitForScrollendEvent(test, target, timeoutMs = 500) {
return new Promise((resolve, reject) => {
const timeoutCallback = test.step_timeout(() => {
reject(`No Scrollend event received for target ${target}`);
}, timeoutMs);
target.addEventListener('scrollend', (evt) => {
clearTimeout(timeoutCallback);
resolve(evt);
}, { once: true });
});
}
const MAX_FRAME = 700;
const MAX_UNCHANGED_FRAMES = 20;
// Returns a promise that resolves when the given condition is met or rejects
// after MAX_FRAME animation frames.
// TODO(crbug.com/1400399): deprecate. We should not use frame based waits in
// WPT as frame rates may vary greatly in different testing environments.
function waitFor(condition, error_message = 'Reaches the maximum frames.') {
return new Promise((resolve, reject) => {
function tick(frames) {
@@ -19,6 +33,9 @@ function waitFor(condition, error_message = 'Reaches the maximum frames.') {
});
}
// TODO(crbug.com/1400446): Test driver should defer sending events until the
// browser is ready. Also the term compositor-commit is misleading as not all
// user-agents use a compositor process.
function waitForCompositorCommit() {
return new Promise((resolve) => {
// rAF twice.
@@ -28,6 +45,8 @@ function waitForCompositorCommit() {
});
}
// TODO(crbug.com/1400399): Deprecate as frame rates may vary greatly in
// different test environments.
function waitForAnimationEnd(getValue) {
var last_changed_frame = 0;
var last_position = getValue();
@@ -50,6 +69,31 @@ function waitForAnimationEnd(getValue) {
})
}
// Scrolls in target according to move_path with pauses in between
function touchScrollInTargetSequentiallyWithPause(target, move_path, pause_time_in_ms = 100) {
const test_driver_actions = new test_driver.Actions()
.addPointer("pointer1", "touch")
.pointerMove(0, 0, {origin: target})
.pointerDown();
const substeps = 5;
let x = 0;
let y = 0;
// Do each move in 5 steps
for(let move of move_path) {
let step_x = (move.x - x) / substeps;
let step_y = (move.y - y) / substeps;
for(let step = 0; step < substeps; step++) {
x += step_x;
y += step_y;
test_driver_actions.pointerMove(x, y, {origin: target});
}
test_driver_actions.pause(pause_time_in_ms);
}
return test_driver_actions.pointerUp().send();
}
function touchScrollInTarget(pixels_to_scroll, target, direction, pause_time_in_ms = 100) {
var x_delta = 0;
var y_delta = 0;
@@ -61,7 +105,7 @@ function touchScrollInTarget(pixels_to_scroll, target, direction, pause_time_in_
} else if (direction == "right") {
x_delta = -1 * pixels_to_scroll / num_movs;
} else if (direction == "left") {
x_delta = pixels_to_scroll / num_movs;;
x_delta = pixels_to_scroll / num_movs;
} else {
throw("scroll direction '" + direction + "' is not expected, direction should be 'down', 'up', 'left' or 'right'");
}
@@ -95,3 +139,25 @@ function mouseActionsInTarget(target, origin, delta, pause_time_in_ms = 100) {
.pointerUp()
.send();
}
// Returns a promise that resolves when the given condition holds for 10
// animation frames or rejects if the condition changes to false within 10
// animation frames.
// TODO(crbug.com/1400399): Deprecate as frame rates may very greatly in
// different test environments.
function conditionHolds(condition, error_message = 'Condition is not true anymore.') {
const MAX_FRAME = 10;
return new Promise((resolve, reject) => {
function tick(frames) {
// We requestAnimationFrame either for 10 frames or until condition is
// violated.
if (frames >= MAX_FRAME)
resolve();
else if (!condition())
reject(error_message);
else
requestAnimationFrame(tick.bind(this, frames + 1));
}
tick(0);
});
}
@@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<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>
<script src="scroll_support.js"></script>
<style>
#targetDiv {
width: 200px;
height: 200px;
overflow: scroll;
}
#innerDiv {
width: 500px;
height: 4000px;
}
</style>
<body style="margin:0" onload=runTest()>
<div id="targetDiv">
<div id="innerDiv">
</div>
</div>
</body>
<script>
const target_div = document.getElementById('targetDiv');
let scrollend_arrived = false;
let scrollend_event_count = 0;
function onScrollEnd(event) {
assert_false(event.cancelable);
assert_false(event.bubbles);
scrollend_arrived = true;
scrollend_event_count += 1;
}
function runTest() {
promise_test (async (t) => {
// Make sure that no scrollend event is sent to document.
document.addEventListener("scrollend",
t.unreached_func("document got unexpected scrollend event."));
await waitForCompositorCommit();
// Scroll down & up & down on target div and wait for the target_div to get scrollend event.
target_div.addEventListener("scrollend", onScrollEnd);
const move_path = [
{ x: 0, y: -300}, // down
{ x: 0, y: -100}, // up
{ x: 0, y: -400}, // down
{ x: 0, y: -200}, // up
];
await touchScrollInTargetSequentiallyWithPause(target_div, move_path, 150);
await waitFor(() => {return scrollend_arrived;},
'target_div did not receive scrollend event after sequence of scrolls on target.');
assert_equals(scrollend_event_count, 1);
}, "Move down, up and down again, receive scrollend event only once");
}
</script>
@@ -1,4 +1,5 @@
<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -1,5 +1,6 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -1,5 +1,6 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -1,4 +1,5 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -1,4 +1,5 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -80,12 +81,20 @@ function runTest() {
'on target.');
assert_equals(target_div.scrollLeft, 0);
// Scroll up on target div and wait for the element with overscroll-y to get
// scrollend event.
let touchEndPromise = new Promise((resolve) => {
target_div.addEventListener("touchend", resolve);
});
await touchScrollInTarget(300, target_div, 'up');
await waitFor(() => { return vertical_scrollend_arrived; },
'Expected element did not receive scrollend event after scroll up on ' +
'target.');
// The scrollend event should never be fired before the gesture has completed.
await touchEndPromise;
// Ensure we wait at least a tick after the touch end.
await waitForCompositorCommit();
// We should not trigger a scrollend event for a scroll that did not change
// the scroll position.
assert_equals(vertical_scrollend_arrived, false);
assert_equals(target_div.scrollTop, 0);
}, 'Tests that the last element in the cut scroll chain gets scrollend ' +
'event when no element scrolls by touch.');
@@ -1,4 +1,5 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -1,4 +1,5 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
@@ -29,110 +30,170 @@
<script>
var target_div = document.getElementById('targetDiv');
var scrollend_arrived = false;
function onScrollEnd(event) {
assert_false(event.cancelable);
assert_false(event.bubbles);
scrollend_arrived = true;
}
function resetTargetScrollState() {
async function resetTargetScrollState(test) {
if (target_div.scrollTop != 0 || target_div.scrollLeft != 0) {
target_div.scrollTop = 0;
target_div.scrollLeft = 0;
return waitForScrollendEvent(test, target_div);
}
}
function checkFinalPosition(target, position, pause_time_in_ms) {
return new Promise((resolve, reject) => {
step_timeout(() => {
resolve();
assert_equals(position.x, target.scrollLeft);
assert_equals(position.y, target.scrollTop);
}, pause_time_in_ms);
});
async function verifyScrollStopped(test) {
const unscaled_pause_time_in_ms = 100;
const x = target_div.scrollLeft;
const y = target_div.scrollTop;
return new Promise(resolve => {
test.step_timeout(() => {
assert_equals(x, target_div.scrollLeft);
assert_equals(y, target_div.scrollTop);
resolve();
}, unscaled_pause_time_in_ms);
});
}
target_div.addEventListener("scrollend", onScrollEnd);
async function verifyNoScrollendOnDocument(test) {
const callback =
test.unreached_func("window got unexpected scrollend event.");
window.addEventListener('scrollend', callback);
}
async function createScrollendPromise(test) {
return waitForScrollendEvent(test, target_div).then(evt => {
assert_false(evt.cancelable, 'Event is not cancelable');
assert_false(evt.bubbles, 'Event targeting element does not bubble');
});
}
function runTest() {
promise_test(async (t) => {
// Make sure that no scrollend event is sent to window.
window.addEventListener("scrollend",
t.unreached_func("window got unexpected scrollend event."));
await waitForCompositorCommit();
scrollend_arrived = false;
promise_test(async (t) => {
// Skip the test on a Mac as they do not support touch screens.
const isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
if (isMac)
return;
// Perform drag action on target div and wait for target_div to get scrollend event.
var origin = { x: target_div.offsetWidth / 2, y: target_div.offsetHeight - 50 };
var delta = { x: 0, y: 40 };
await mouseActionsInTarget(target_div, origin, delta, 300);
await waitFor(() => { return scrollend_arrived; },
'target_div did not receive scrollend event after dragging scroll on target.');
assert_true(target_div.scrollTop > 0);
await checkFinalPosition(target_div, {x: target_div.scrollLeft, y: target_div.scrollTop}, 300);
}, 'Tests that the target_div gets scrollend event when dragging scroll on target.');
await resetTargetScrollState(t);
await waitForCompositorCommit();
promise_test(async (t) => {
resetTargetScrollState();
// Make sure that no scrollend event is sent to window.
window.addEventListener("scrollend",
t.unreached_func("window got unexpected scrollend event."));
await waitForCompositorCommit();
scrollend_arrived = false;
const targetScrollendPromise = createScrollendPromise(t);
verifyNoScrollendOnDocument(t);
// Hit the scrollbar of target div and wait for target_div to get scrollend event.
var scrollbar_width = target_div.offsetWidth - target_div.clientWidth;
assert_true(scrollbar_width > 0, "This test requires scrollbar.");
var origin = {x: target_div.offsetWidth - scrollbar_width / 2, y: target_div.offsetHeight - 50};
var delta = {x: 0, y: 0};
await mouseActionsInTarget(target_div, origin, delta, 100);
await waitFor(() => { return scrollend_arrived; },
'target_div did not receive scrollend event after clicking scrollbar on target.');
assert_true(target_div.scrollTop > 0);
await checkFinalPosition(target_div, { x: target_div.scrollLeft, y: target_div.scrollTop }, 300);
}, 'Tests that the target_div gets scrollend event when click scrollbar on target.');
// Perform a touch drag on target div and wait for target_div to get
// a scrollend event.
await new test_driver.Actions()
.addPointer('TestPointer', 'touch')
.pointerMove(0, 0, {origin: target_div}) // 0, 0 is center of element.
.pointerDown()
.addTick()
.pointerMove(0, -40, {origin: target_div}) // Drag up to move down.
.addTick()
.pause(200) // Prevent inertial scroll.
.pointerUp()
.send();
promise_test(async (t) => {
resetTargetScrollState();
// Make sure that no scrollend event is sent to window.
window.addEventListener("scrollend",
t.unreached_func("window got unexpected scrollend event."));
await waitForCompositorCommit();
scrollend_arrived = false;
await targetScrollendPromise;
assert_true(target_div.scrollTop > 0);
await verifyScrollStopped(t);
}, 'Tests that the target_div gets scrollend event when touch dragging.');
// Drag the thumb of target div.
var scrollbar_width = target_div.offsetWidth - target_div.clientWidth;
assert_true(scrollbar_width > 0, "This test requires scrollbar.");
var origin = { x: target_div.offsetWidth - scrollbar_width / 2, y: 50 };
var delta = { x: 0, y: 20 };
await mouseActionsInTarget(target_div, origin, delta, 100);
await waitFor(() => { return scrollend_arrived; },
'target_div did not receive scrollend event after dragging the thumb of target.');
assert_true(target_div.scrollTop > 0);
await checkFinalPosition(target_div, { x: target_div.scrollLeft, y: target_div.scrollTop }, 300);
}, 'Tests that the target_div gets scrollend event when drag the thumb of target.');
promise_test(async (t) => {
// Skip test on platforms that do not have a visible scrollbar (e.g.
// overlay scrollbar).
const scrollbar_width = target_div.offsetWidth - target_div.clientWidth;
if (scrollbar_width == 0)
return;
promise_test(async (t) => {
resetTargetScrollState();
// Make sure that no scrollend event is sent to window.
window.addEventListener("scrollend",
t.unreached_func("window got unexpected scrollend event."));
await waitForCompositorCommit();
scrollend_arrived = false;
await resetTargetScrollState(t);
await waitForCompositorCommit();
// Hit and active the target div.
var origin = { x: target_div.offsetWidth / 2, y: target_div.offsetHeight / 2};
var delta = { x: 0, y: 0 };
await mouseActionsInTarget(target_div, origin, delta, 100);
// Send DOWN key to the target div.
window.test_driver.send_keys(target_div, '\ue015');
const targetScrollendPromise = createScrollendPromise(t);
verifyNoScrollendOnDocument(t);
await waitFor(() => { return scrollend_arrived; },
'target_div did not receive scrollend event after sending DOWN key to target.');
assert_true(target_div.scrollTop > 0);
await checkFinalPosition(target_div, { x: target_div.scrollLeft, y: target_div.scrollTop }, 300);
}, 'Tests that the target_div gets scrollend event when send DOWN key to target.');
const bounds = target_div.getBoundingClientRect();
const x = bounds.right - scrollbar_width / 2;
const y = bounds.bottom - 20;
await new test_driver.Actions()
.addPointer('TestPointer', 'mouse')
.pointerMove(x, y, {origin: 'viewport'})
.pointerDown()
.addTick()
.pointerUp()
.send();
await targetScrollendPromise;
assert_true(target_div.scrollTop > 0);
await verifyScrollStopped(t);
}, 'Tests that the target_div gets scrollend event when clicking ' +
'scrollbar.');
// Same issue as previous test.
promise_test(async (t) => {
// Skip test on platforms that do not have a visible scrollbar (e.g.
// overlay scrollbar).
const scrollbar_width = target_div.offsetWidth - target_div.clientWidth;
if (scrollbar_width == 0)
return;
resetTargetScrollState(t);
const targetScrollendPromise = createScrollendPromise(t);
verifyNoScrollendOnDocument(t);
const bounds = target_div.getBoundingClientRect();
const x = bounds.right - scrollbar_width / 2;
const y = bounds.top + 30;
const dy = 30;
await new test_driver.Actions()
.addPointer('TestPointer', 'mouse')
.pointerMove(x, y, { origin: 'viewport' })
.pointerDown()
.pointerMove(x, y + dy, { origin: 'viewport' })
.addTick()
.pointerUp()
.send();
await targetScrollendPromise;
assert_true(target_div.scrollTop > 0);
await verifyScrollStopped(t);
}, 'Tests that the target_div gets scrollend event when dragging the ' +
'scrollbar thumb.');
promise_test(async (t) => {
resetTargetScrollState(t);
const targetScrollendPromise = createScrollendPromise(t);
verifyNoScrollendOnDocument(t);
const x = 0;
const y = 0;
const dx = 0;
const dy = 40;
const duration_ms = 10;
await new test_driver.Actions()
.scroll(x, y, dx, dy, { origin: target_div }, duration_ms)
.send();
await targetScrollendPromise;
assert_true(target_div.scrollTop > 0);
await verifyScrollStopped(t);
}, 'Tests that the target_div gets scrollend event when mouse wheel ' +
'scrolling.');
promise_test(async (t) => {
await resetTargetScrollState(t);
await waitForCompositorCommit();
verifyNoScrollendOnDocument(t);
const targetScrollendPromise = createScrollendPromise(t);
target_div.focus();
window.test_driver.send_keys(target_div, '\ue015');
await targetScrollendPromise;
assert_true(target_div.scrollTop > 0);
await verifyScrollStopped(t);
}, 'Tests that the target_div gets scrollend event when sending DOWN key ' +
'to the target.');
}
</script>
</html>
@@ -0,0 +1,108 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<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>
<script src="scroll_support.js"></script>
<style>
html, body {
margin: 0
}
body {
height: 3000px;
width: 3000px;
}
#targetDiv {
width: 200px;
height: 200px;
overflow: scroll;
}
#innerDiv {
width: 400px;
height: 400px;
}
</style>
<body onload=runTest() onscrollend="failOnScrollEnd(event)">
<div id="targetDiv" onscrollend="onElementScrollEnd(event)">
<div id="innerDiv">
</div>
</div>
</body>
<script>
let element_scrollend_arrived = false;
function onElementScrollEnd(event) {
assert_false(event.cancelable);
assert_false(event.bubbles);
element_scrollend_arrived = true;
}
function failOnScrollEnd(event) {
assert_true(false, "Scrollend should not be called on: " + event.target);
}
function runTest() {
let target_div = document.getElementById("targetDiv");
promise_test (async (t) => {
await waitForCompositorCommit();
target_div.scrollTo({top: 200, left: 200});
await waitFor(() => { return element_scrollend_arrived; },
target_div.tagName + " did not receive scrollend event.");
assert_equals(target_div.scrollLeft, 200, target_div.tagName + " scrollLeft");
assert_equals(target_div.scrollTop, 200, target_div.tagName + " scrollTop");
}, "Tests scrollend event is handled by event handler content attribute.");
promise_test (async (t) => {
await waitForCompositorCommit();
document.scrollingElement.scrollTo({top: 200, left: 200});
// The document body onscrollend event handler content attribute will fail
// here, if it is fired.
await waitForCompositorCommit();
assert_equals(document.scrollingElement.scrollLeft, 200,
"Document scrolled on horizontal axis");
assert_equals(document.scrollingElement.scrollTop, 200,
"Document scrolled on vertical axis");
}, "Tests scrollend event is not fired to document body event handler content attribute.");
promise_test (async (t) => {
await waitForCompositorCommit();
// Reset the scroll position.
document.scrollingElement.scrollTo({top: 0, left: 0});
let scrollend_event = new Promise(resolve => document.onscrollend = resolve);
document.scrollingElement.scrollTo({top: 200, left: 200});
await scrollend_event;
assert_equals(document.scrollingElement.scrollTop, 200,
"Document scrolled on horizontal axis");
assert_equals(document.scrollingElement.scrollLeft, 200,
"Document scrolled on vertical axis");
}, "Tests scrollend event is fired to document event handler property");
promise_test (async (t) => {
await waitForCompositorCommit();
// Reset the scroll position.
target_div.scrollTo({top: 0, left: 0});
let scrollend_event = new Promise(resolve => target_div.onscrollend = resolve);
target_div.scrollTo({top: 200, left: 200});
await scrollend_event;
assert_equals(target_div.scrollLeft, 200,
target_div.tagName + " scrolled on horizontal axis");
assert_equals(target_div.scrollLeft, 200,
target_div.tagName + " scrolled on vertical axis");
}, "Tests scrollend event is fired to element event handler property");
}
</script>
@@ -0,0 +1,84 @@
<!DOCTYPE HTML>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
<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>
<script src="scroll_support.js"></script>
<style>
#rootDiv {
width: 500px;
height: 500px;
}
#targetDiv {
width: 200px;
height: 200px;
overflow: scroll;
}
#innerDiv {
width: 500px;
height: 4000px;
}
</style>
<body style="margin:0" onload=runTest()>
</body>
<script>
let scrollend_arrived = false;
async function setupHtmlAndScrollAndRemoveElement(element_to_remove_id) {
document.body.innerHTML=`
<div id="rootDiv">
<div id="targetDiv">
<div id="innerDiv">
</div>
</div>
</div>
`;
await waitForCompositorCommit();
const target_div = document.getElementById('targetDiv');
const element_to_remove = document.getElementById(element_to_remove_id);
let reached_half_scroll = false;
scrollend_arrived = false;
target_div.addEventListener("scrollend", () => {
scrollend_arrived = true;
});
target_div.onscroll = () => {
// Remove the element after reached half of the scroll offset,
if(target_div.scrollTop >= 1000) {
reached_half_scroll = true;
element_to_remove.remove();
}
};
target_div.scrollTo({top:2000, left:0, behavior:"smooth"});
await waitFor(() => {return reached_half_scroll; },
"target_div never reached scroll offset of 1000");
await waitForCompositorCommit();
}
function runTest() {
promise_test (async (t) => {
await setupHtmlAndScrollAndRemoveElement("rootDiv");
await conditionHolds(() => { return !scrollend_arrived; });
}, "No scrollend is received after removing parent div");
promise_test (async (t) => {
await setupHtmlAndScrollAndRemoveElement("targetDiv");
await conditionHolds(() => { return !scrollend_arrived; });
}, "No scrollend is received after removing scrolling element");
promise_test (async (t) => {
await setupHtmlAndScrollAndRemoveElement("innerDiv");
await waitFor(() => { return scrollend_arrived; },
'target_div did not receive scrollend event after vertical scroll.');
}, "scrollend is received after removing descendant div");
}
</script>
+1 -1
View File
@@ -12,7 +12,7 @@
"path": "dom/abort"
},
"dom/events": {
"commit": "f8821adb281696322f4bd96d412a98ae510f9125",
"commit": "ab8999891c6225bef1741c2960033aad620481a8",
"path": "dom/events"
},
"encoding": {
+2 -2
View File
@@ -11,8 +11,8 @@
"Event-constructors.any.js": {
"fail": {
"expected": [
"Untitled 2",
"Untitled 3"
"Untitled 3",
"Untitled 4"
]
}
},