Update web-platform-tests to revision 132d12daea699ce266324e79eecbe59b10e56502

This commit is contained in:
WPT Sync Bot 2018-06-08 21:05:21 -04:00
parent 527d874bc1
commit fe00a63040
1004 changed files with 18598 additions and 92770 deletions

View file

@ -0,0 +1,90 @@
const otherWindow = document.body.appendChild(document.createElement("iframe")).contentWindow;
["EventTarget", "XMLHttpRequest"].forEach(constructorName => {
async_test(t => {
const eventTarget = new otherWindow[constructorName]();
eventTarget.addEventListener("hi", t.step_func_done(e => {
assert_equals(otherWindow.event, undefined);
assert_equals(e, window.event);
}));
eventTarget.dispatchEvent(new Event("hi"));
}, "window.event for constructors from another global: " + constructorName);
});
// XXX: It would be good to test a subclass of EventTarget once we sort out
// https://github.com/heycam/webidl/issues/540
async_test(t => {
const element = document.body.appendChild(otherWindow.document.createElement("meh"));
element.addEventListener("yo", t.step_func_done(e => {
assert_equals(e, window.event);
}));
element.dispatchEvent(new Event("yo"));
}, "window.event and element from another document");
async_test(t => {
const doc = otherWindow.document,
element = doc.body.appendChild(doc.createElement("meh")),
child = element.appendChild(doc.createElement("bleh"));
element.addEventListener("yoyo", t.step_func(e => {
document.body.appendChild(element);
assert_equals(element.ownerDocument, document);
assert_equals(window.event, e);
assert_equals(otherWindow.event, undefined);
}), true);
element.addEventListener("yoyo", t.step_func(e => {
assert_equals(element.ownerDocument, document);
assert_equals(window.event, e);
assert_equals(otherWindow.event, undefined);
}), true);
child.addEventListener("yoyo", t.step_func_done(e => {
assert_equals(child.ownerDocument, document);
assert_equals(window.event, e);
assert_equals(otherWindow.event, undefined);
}));
child.dispatchEvent(new Event("yoyo"));
}, "window.event and moving an element post-dispatch");
test(t => {
const host = document.createElement("div"),
shadow = host.attachShadow({ mode: "open" }),
child = shadow.appendChild(document.createElement("trala")),
furtherChild = child.appendChild(document.createElement("waddup"));
let counter = 0;
host.addEventListener("hi", t.step_func(e => {
assert_equals(window.event, e);
assert_equals(counter++, 3);
}));
child.addEventListener("hi", t.step_func(e => {
assert_equals(window.event, e);
assert_equals(counter++, 2);
}));
furtherChild.addEventListener("hi", t.step_func(e => {
host.appendChild(child);
assert_equals(window.event, e);
assert_equals(counter++, 0);
}));
furtherChild.addEventListener("hi", t.step_func(e => {
assert_equals(window.event, e);
assert_equals(counter++, 1);
}));
furtherChild.dispatchEvent(new Event("hi", { composed: true, bubbles: true }));
assert_equals(counter, 4);
}, "window.event should not be affected by nodes moving post-dispatch");
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
frame.src = "resources/event-global-extra-frame.html";
frame.onload = t.step_func_done(() => {
const event = new Event("hi");
document.addEventListener("hi", frame.contentWindow.listener); // listener intentionally not wrapped in t.step_func
document.addEventListener("hi", t.step_func(e => {
assert_equals(event, e);
assert_equals(window.event, e);
}));
document.dispatchEvent(event);
assert_equals(frameState.event, event);
assert_equals(frameState.windowEvent, event);
assert_equals(frameState.parentEvent, undefined);
});
}, "Listener from a different global");

View file

@ -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>

View file

@ -0,0 +1,9 @@
<script>
function listener(e) {
parent.frameState = {
event: e,
windowEvent: window.event,
parentEvent: parent.event
}
}
</script>