Skip to content

Commit

Permalink
Bug 1445934 [wpt PR 9919] - DOM: reset target/relatedTarget, a=testonly
Browse files Browse the repository at this point in the history
Automatic update from web-platform-testsDOM: reset target/relatedTarget

For whatwg/dom#585.

wpt-commits: 2f758ac5c16e44915f270ceec31a84eed8f85769
wpt-pr: 9919
wpt-commits: 2f758ac5c16e44915f270ceec31a84eed8f85769
wpt-pr: 9919
  • Loading branch information
annevk authored and jgraham committed Apr 15, 2018
1 parent 7c3967f commit cce74c2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
10 changes: 10 additions & 0 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -321178,6 +321178,12 @@
{}
]
],
"dom/events/relatedTarget.window.js": [
[
"/dom/events/relatedTarget.window.html",
{}
]
],
"dom/historical.html": [
[
"/dom/historical.html",
Expand Down Expand Up @@ -546791,6 +546797,10 @@
"40ab5636653dfd105738ab38e7d22316132eb630",
"testharness"
],
"dom/events/relatedTarget.window.js": [
"0426d2ecae3f3562be175e4364353d979365ed1c",
"testharness"
],
"dom/historical.html": [
"ccf3d9d2d8eb3e7353ecedd8a4d8ba232f9374ec",
"testharness"
Expand Down
85 changes: 85 additions & 0 deletions testing/web-platform/tests/dom/events/relatedTarget.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// https://dom.spec.whatwg.org/#concept-event-dispatch

const host = document.createElement("div"),
child = host.appendChild(document.createElement("p")),
shadow = host.attachShadow({ mode: "closed" }),
slot = shadow.appendChild(document.createElement("slot"));

test(() => {
for (target of [shadow, slot]) {
for (relatedTarget of [new XMLHttpRequest(), self, host]) {
const event = new FocusEvent("demo", { relatedTarget: relatedTarget });
target.dispatchEvent(event);
assert_equals(event.target, null);
assert_equals(event.relatedTarget, null);
}
}
}, "Reset if target pointed to a shadow tree");

test(() => {
for (relatedTarget of [shadow, slot]) {
for (target of [new XMLHttpRequest(), self, host]) {
const event = new FocusEvent("demo", { relatedTarget: relatedTarget });
target.dispatchEvent(event);
assert_equals(event.target, null);
assert_equals(event.relatedTarget, null);
}
}
}, "Reset if relatedTarget pointed to a shadow tree");

async_test(t => {
const shadowChild = shadow.appendChild(document.createElement("div"));
shadowChild.addEventListener("demo", t.step_func(() => document.body.appendChild(shadowChild)));
const event = new FocusEvent("demo", { relatedTarget: new XMLHttpRequest() });
shadowChild.dispatchEvent(event);
assert_equals(shadowChild.parentNode, document.body);
assert_equals(event.target, null);
assert_equals(event.relatedTarget, null);
shadowChild.remove();
t.done();
}, "Reset if target pointed to a shadow tree pre-dispatch");

async_test(t => {
const shadowChild = shadow.appendChild(document.createElement("div"));
shadowChild.addEventListener("demo", t.step_func(() => document.body.appendChild(shadowChild)));
const event = new FocusEvent("demo", { relatedTarget: shadowChild });
document.body.dispatchEvent(event);
assert_equals(shadowChild.parentNode, document.body);
assert_equals(event.target, null);
assert_equals(event.relatedTarget, null);
shadowChild.remove();
t.done();
}, "Reset if relatedTarget pointed to a shadow tree pre-dispatch");

async_test(t => {
const event = new FocusEvent("heya", { relatedTarget: shadow, cancelable: true }),
callback = t.unreached_func();
host.addEventListener("heya", callback);
t.add_cleanup(() => host.removeEventListener("heya", callback));
event.preventDefault();
assert_true(event.defaultPrevented);
assert_false(host.dispatchEvent(event));
assert_equals(event.target, null);
assert_equals(event.relatedTarget, null);
// Check that the dispatch flag is cleared
event.initEvent("x");
assert_equals(event.type, "x");
t.done();
}, "Reset targets on early return");

async_test(t => {
const input = document.body.appendChild(document.createElement("input")),
event = new MouseEvent("click", { relatedTarget: shadow });
let seen = false;
t.add_cleanup(() => input.remove());
input.type = "checkbox";
input.oninput = t.step_func(() => {
assert_equals(event.target, null);
assert_equals(event.relatedTarget, null);
assert_equals(event.composedPath().length, 0);
seen = true;
});
assert_true(input.dispatchEvent(event));
assert_true(seen);
t.done();
}, "Reset targets before activation behavior");

0 comments on commit cce74c2

Please sign in to comment.