Skip to content

Commit

Permalink
test: update Web Events WPT
Browse files Browse the repository at this point in the history
This updates the tests and the status file via running
`git node wpt dom/events`.

PR-URL: #46051
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
deokjinkim authored and juanarbol committed Jan 31, 2023
1 parent 3f4c0c0 commit 7e1462d
Show file tree
Hide file tree
Showing 66 changed files with 1,883 additions and 106 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Expand Up @@ -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
Expand Down
123 changes: 123 additions & 0 deletions test/fixtures/wpt/dom/events/Body-FrameSet-Event-Handlers.html
@@ -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>
6 changes: 6 additions & 0 deletions test/fixtures/wpt/dom/events/Event-constructors.any.js
@@ -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()
Expand Down
@@ -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 changes: 26 additions & 0 deletions test/fixtures/wpt/dom/events/mouse-event-retarget.html
@@ -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 comments on commit 7e1462d

Please sign in to comment.