-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Helps with issue whatwg/dom#562 and PR whatwg/dom#585.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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"); |