Skip to content

Commit

Permalink
[dom] Add tests for "inner invoke" with EventTarget in a detached iframe
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shaseley authored and chromium-wpt-export-bot committed Jun 8, 2022
1 parent 0663e2d commit b4e3e51
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions dom/events/EventTarget-detached-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>EventTarget in Detached iframe</title>
<link rel="help" href="https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
"use strict";

async function addFrameAndWaitForLoad(srcdoc) {
const frame = document.createElement('iframe');
frame.srcdoc = srcdoc;
await new Promise((resolve) => {
frame.addEventListener('load', resolve);
document.body.appendChild(frame);
});
return frame;
}

window.onload = () => {
promise_test(async t => {
for (let eventType of ["inner", "outer"]) {
const frame = await addFrameAndWaitForLoad(`<script>
window.parent.innerEventTarget = new EventTarget();
window.parent.innerEvent = new Event('event');
<\/script>`);

let fireCount = 0;
window.innerEventTarget.addEventListener('event', () => {
++fireCount;
});

const event = eventType == "inner" ? window.innerEvent : new Event('event');
window.innerEventTarget.dispatchEvent(event);
frame.remove();
window.innerEventTarget.dispatchEvent(event);

assert_equals(fireCount, 1, `Expected one listener to run for type "${eventType}"`);
}
}, "Event handlers for EventTargets in detached iframes do not fire");

promise_test(async t => {
const frame = await addFrameAndWaitForLoad(`<script>
window.parent.innerEventTarget = new EventTarget();
<\/script>`);

let fireCount = 0;
window.innerEventTarget.addEventListener('event', () => {
++fireCount;
frame.remove();
});
window.innerEventTarget.addEventListener('event', () => {
++fireCount;
});

window.innerEventTarget.dispatchEvent(new Event('event'));

assert_equals(fireCount, 1);
}, "Event listeners do not run after detaching an EventTarget's frame during event dispatch");
};

</script>

0 comments on commit b4e3e51

Please sign in to comment.