Skip to content

Commit b4e3e51

Browse files
shaseleychromium-wpt-export-bot
authored andcommitted
[dom] Add tests for "inner invoke" with EventTarget in a detached iframe
This adds tests for dispatching events to an EventTarget created in an iframe that gets detached --- both prior to and during event dispatch. The behavior of engines for this case is to not run event listeners after the EventTarget's associated global is detached, which is what we check for in the tests. Spec: https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke PR: whatwg/dom#1085 Bug: 1323391 Change-Id: I57aac7d444d3532ad0940a228452d206b5c1be07
1 parent 0663e2d commit b4e3e51

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>EventTarget in Detached iframe</title>
4+
<link rel="help" href="https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<script>
9+
"use strict";
10+
11+
async function addFrameAndWaitForLoad(srcdoc) {
12+
const frame = document.createElement('iframe');
13+
frame.srcdoc = srcdoc;
14+
await new Promise((resolve) => {
15+
frame.addEventListener('load', resolve);
16+
document.body.appendChild(frame);
17+
});
18+
return frame;
19+
}
20+
21+
window.onload = () => {
22+
promise_test(async t => {
23+
for (let eventType of ["inner", "outer"]) {
24+
const frame = await addFrameAndWaitForLoad(`<script>
25+
window.parent.innerEventTarget = new EventTarget();
26+
window.parent.innerEvent = new Event('event');
27+
<\/script>`);
28+
29+
let fireCount = 0;
30+
window.innerEventTarget.addEventListener('event', () => {
31+
++fireCount;
32+
});
33+
34+
const event = eventType == "inner" ? window.innerEvent : new Event('event');
35+
window.innerEventTarget.dispatchEvent(event);
36+
frame.remove();
37+
window.innerEventTarget.dispatchEvent(event);
38+
39+
assert_equals(fireCount, 1, `Expected one listener to run for type "${eventType}"`);
40+
}
41+
}, "Event handlers for EventTargets in detached iframes do not fire");
42+
43+
promise_test(async t => {
44+
const frame = await addFrameAndWaitForLoad(`<script>
45+
window.parent.innerEventTarget = new EventTarget();
46+
<\/script>`);
47+
48+
let fireCount = 0;
49+
window.innerEventTarget.addEventListener('event', () => {
50+
++fireCount;
51+
frame.remove();
52+
});
53+
window.innerEventTarget.addEventListener('event', () => {
54+
++fireCount;
55+
});
56+
57+
window.innerEventTarget.dispatchEvent(new Event('event'));
58+
59+
assert_equals(fireCount, 1);
60+
}, "Event listeners do not run after detaching an EventTarget's frame during event dispatch");
61+
};
62+
63+
</script>

0 commit comments

Comments
 (0)