-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
0663e2d
commit b4e3e51
Showing
1 changed file
with
63 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,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> |