зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1438330 [wpt PR 4790] - Add tests for window.event, a=testonly
Automatic update from web-platform-testsAdd tests for window.event For https://github.com/whatwg/dom/issues/334 and https://github.com/whatwg/dom/pull/407. -- wpt-commits: 659fe6eb4dea2550f4fb5dc14c2916aa1eaef1cc wpt-pr: 4790
This commit is contained in:
Родитель
96a3ddbe7a
Коммит
cbf581ecc7
|
@ -326378,6 +326378,12 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"dom/events/event-global.html": [
|
||||
[
|
||||
"/dom/events/event-global.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/events/event-global.worker.js": [
|
||||
[
|
||||
"/dom/events/event-global.worker.html",
|
||||
|
@ -561343,6 +561349,10 @@
|
|||
"40ab5636653dfd105738ab38e7d22316132eb630",
|
||||
"testharness"
|
||||
],
|
||||
"dom/events/event-global.html": [
|
||||
"10a189637c05eafd6ffe74e21edde501d2f7da9c",
|
||||
"testharness"
|
||||
],
|
||||
"dom/events/event-global.worker.js": [
|
||||
"084a6f752edee6578113035fece6d0eb85a2fdf7",
|
||||
"testharness"
|
||||
|
@ -588324,7 +588334,7 @@
|
|||
"support"
|
||||
],
|
||||
"interfaces/dom.idl": [
|
||||
"86ea69e6432ac3e4172129591f4aeac69e336a82",
|
||||
"9621186ac979a5860d5c909b7505900a48c2c810",
|
||||
"support"
|
||||
],
|
||||
"interfaces/encoding.idl": [
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
<!DOCTYPE html>
|
||||
<title>window.event tests</title>
|
||||
<link rel="author" title="Mike Taylor" href="mailto:miketaylr@gmail.com">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
test(t => {
|
||||
assert_own_property(window, "event");
|
||||
assert_equals(window.event, undefined);
|
||||
}, "event exists on window, which is initially set to undefined");
|
||||
|
||||
async_test(t => {
|
||||
let target = document.createElement("div");
|
||||
assert_equals(window.event, undefined, "undefined before dispatch");
|
||||
|
||||
let clickEvent = new Event("click");
|
||||
target.addEventListener("click", t.step_func_done(e => {
|
||||
assert_equals(window.event, clickEvent, "window.event set to current event during dispatch");
|
||||
}));
|
||||
|
||||
target.dispatchEvent(clickEvent);
|
||||
assert_equals(window.event, undefined, "undefined after dispatch");
|
||||
}, "window.event is only defined during dispatch");
|
||||
|
||||
async_test(t => {
|
||||
let parent = document.createElement("div");
|
||||
let root = parent.attachShadow({mode: "closed"});
|
||||
let span = document.createElement("span");
|
||||
root.appendChild(span);
|
||||
|
||||
span.addEventListener("test", t.step_func(e => {
|
||||
assert_equals(window.event, undefined);
|
||||
assert_not_equals(window.event, e);
|
||||
}));
|
||||
|
||||
parent.addEventListener("test", t.step_func_done(e => {
|
||||
assert_equals(window.event, e);
|
||||
assert_not_equals(window.event, undefined);
|
||||
}));
|
||||
|
||||
parent.dispatchEvent(new Event("test", {composed: true}));
|
||||
}, "window.event is undefined if the target is in a shadow tree (event dispatched outside shadow tree)");
|
||||
|
||||
async_test(t => {
|
||||
let parent = document.createElement("div");
|
||||
let root = parent.attachShadow({mode: "closed"});
|
||||
let span = document.createElement("span");
|
||||
root.appendChild(span);
|
||||
let shadowNode = root.firstElementChild;
|
||||
|
||||
shadowNode.addEventListener("test", t.step_func((e) => {
|
||||
assert_not_equals(window.event, e);
|
||||
assert_equals(window.event, undefined);
|
||||
}));
|
||||
|
||||
parent.addEventListener("test", t.step_func_done(e => {
|
||||
assert_equals(window.event, e);
|
||||
assert_not_equals(window.event, undefined);
|
||||
}));
|
||||
|
||||
shadowNode.dispatchEvent(new Event("test", {composed: true, bubbles: true}));
|
||||
}, "window.event is undefined if the target is in a shadow tree (event dispatched inside shadow tree)");
|
||||
|
||||
async_test(t => {
|
||||
let target1 = document.createElement("div");
|
||||
let target2 = document.createElement("div");
|
||||
|
||||
target2.addEventListener("dude", t.step_func(() => {
|
||||
assert_equals(window.event.type, "dude");
|
||||
}));
|
||||
|
||||
target1.addEventListener("cool", t.step_func_done(() => {
|
||||
assert_equals(window.event.type, "cool", "got expected event from global event during dispatch");
|
||||
target2.dispatchEvent(new Event("dude"));
|
||||
assert_equals(window.event.type, "cool", "got expected event from global event after handling a different event handler callback");
|
||||
}));
|
||||
|
||||
target1.dispatchEvent(new Event("cool"));
|
||||
}, "window.event is set to the current event during dispatch");
|
||||
|
||||
async_test(t => {
|
||||
let target = document.createElement("div");
|
||||
|
||||
target.addEventListener("click", t.step_func_done(e => {
|
||||
assert_equals(e, window.event);
|
||||
}));
|
||||
|
||||
target.dispatchEvent(new Event("click"));
|
||||
}, "window.event is set to the current event, which is the event passed to dispatch");
|
||||
</script>
|
|
@ -35,6 +35,11 @@ dictionary EventInit {
|
|||
};
|
||||
|
||||
|
||||
partial interface Window {
|
||||
[Replaceable] readonly attribute any event;
|
||||
};
|
||||
|
||||
|
||||
[Constructor(DOMString type, optional CustomEventInit eventInitDict),
|
||||
Exposed=(Window,Worker)]
|
||||
interface CustomEvent : Event {
|
||||
|
|
Загрузка…
Ссылка в новой задаче