diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 60a936cc280f..1067e7449eff 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -333529,6 +333529,12 @@ {} ] ], + "html/dom/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js": [ + [ + "/html/dom/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.html", + {} + ] + ], "html/dom/dynamic-markup-insertion/opening-the-input-stream/mutation-events.window.js": [ [ "/html/dom/dynamic-markup-insertion/opening-the-input-stream/mutation-events.window.html", @@ -564404,6 +564410,10 @@ "a2a5acc9dfe53c7482eeaa4be3a4819238f8e120", "testharness" ], + "html/dom/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js": [ + "ccf357a8081b99de1d85e05196145e83b3de2ab5", + "testharness" + ], "html/dom/dynamic-markup-insertion/opening-the-input-stream/mutation-events.window.js": [ "1e1c656e1d19c9c459faf16327e099a4c9e13872", "testharness" diff --git a/testing/web-platform/tests/html/dom/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js b/testing/web-platform/tests/html/dom/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js new file mode 100644 index 000000000000..97334ce1bab8 --- /dev/null +++ b/testing/web-platform/tests/html/dom/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js @@ -0,0 +1,42 @@ +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")), + body = frame.contentDocument.body; + t.add_cleanup(() => frame.remove()); + frame.contentDocument.addEventListener("x", t.unreached_func("document event listener not removed")); + body.addEventListener("x", t.unreached_func("body event listener not removed")); + frame.contentDocument.open(); + frame.contentDocument.dispatchEvent(new Event("x")); + body.dispatchEvent(new Event("x")); + frame.contentDocument.close(); +}, "Event listeners are to be removed"); + +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")); + t.add_cleanup(() => frame.remove()); + let once = false; + frame.contentDocument.addEventListener("x", () => { + frame.contentDocument.open(); + once = true; + }); + frame.contentDocument.addEventListener("x", t.unreached_func("second event listener not removed")); + frame.contentDocument.dispatchEvent(new Event("x")); + assert_true(once); + frame.contentDocument.close(); +}, "Event listeners are to be removed with immediate effect"); + +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")), + shadow = frame.contentDocument.body.attachShadow({ mode: "closed" }), + shadowChild = shadow.appendChild(document.createElement("div")), + shadowShadow = shadowChild.attachShadow({ mode: "open" }), + nodes = [shadow, shadowChild, shadowShadow]; + t.add_cleanup(() => frame.remove()); + nodes.forEach(node => { + node.addEventListener("x", t.unreached_func(node + "'s event listener not removed")); + }); + frame.contentDocument.open(); + nodes.forEach(node => { + node.dispatchEvent(new Event("x")); + }); + frame.contentDocument.close(); +}, "Event listeners are to be removed from shadow trees as well");