From a5954754cd687a9e755bbd8692e79c22a9af6ff1 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Fri, 20 Jul 2018 18:36:59 -0400 Subject: [PATCH] HTML: More event listener tests for document open steps --- .../opening-the-input-stream/007.html | 19 ----- .../event-listeners.window.js | 70 ++++++++++++++++++- 2 files changed, 69 insertions(+), 20 deletions(-) delete mode 100644 html/webappapis/dynamic-markup-insertion/opening-the-input-stream/007.html diff --git a/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/007.html b/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/007.html deleted file mode 100644 index e5f0d1561ef6e9..00000000000000 --- a/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/007.html +++ /dev/null @@ -1,19 +0,0 @@ - -Unregistering event handlers after document.open - - -
- - diff --git a/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js b/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js index 97334ce1bab8f1..58ec08f9ff110a 100644 --- a/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js +++ b/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/event-listeners.window.js @@ -1,3 +1,14 @@ +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")), + body = frame.contentDocument.body; + t.add_cleanup(() => frame.remove()); + const div = body.appendChild(frame.contentDocument.createElement("div")); + div.addEventListener("click", t.unreached_func("element event listener not removed")); + frame.contentDocument.open(); + div.click(); + frame.contentDocument.close(); +}, "Standard event listeners are to be removed"); + test(t => { const frame = document.body.appendChild(document.createElement("iframe")), body = frame.contentDocument.body; @@ -8,7 +19,64 @@ test(t => { frame.contentDocument.dispatchEvent(new Event("x")); body.dispatchEvent(new Event("x")); frame.contentDocument.close(); -}, "Event listeners are to be removed"); +}, "Custom event listeners are to be removed"); + +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")), + body = frame.contentDocument.body; + t.add_cleanup(() => frame.remove()); + // Focus on the current window so that the frame's window is blurred. + window.focus(); + assert_false(frame.contentDocument.hasFocus()); + frame.contentWindow.addEventListener("focus", t.unreached_func("window event listener not removed")); + body.onfocus = t.unreached_func("body event listener not removed"); + frame.contentDocument.open(); + assert_equals(body.onfocus, null); + frame.contentWindow.focus(); + frame.contentDocument.close(); +}, "Standard event listeners are to be removed from Window"); + +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")); + t.add_cleanup(() => frame.remove()); + frame.contentWindow.addEventListener("x", t.unreached_func("window event listener not removed")); + frame.contentDocument.open(); + frame.contentWindow.dispatchEvent(new Event("x")); + frame.contentDocument.close(); +}, "Custom event listeners are to be removed from Window"); + +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")), + body = frame.contentDocument.body; + t.add_cleanup(() => frame.remove()); + const div = body.appendChild(frame.contentDocument.createElement("div")); + div.onclick = t.unreached_func("element event listener not removed"); + frame.contentDocument.open(); + assert_equals(div.onclick, null); + const e = frame.contentDocument.createEvent("mouseevents") + e.initEvent("click", false, false); + div.dispatchEvent(e); + frame.contentDocument.close(); +}, "IDL attribute event handlers are to be deactivated"); + +var thrower; + +test(t => { + const frame = document.body.appendChild(document.createElement("iframe")), + body = frame.contentDocument.body; + t.add_cleanup(() => frame.remove()); + const div = body.appendChild(frame.contentDocument.createElement("div")); + thrower = t.step_func(() => { throw new Error('element event listener not removed'); }); + div.setAttribute("onclick", "parent.thrower()"); + assert_not_equals(div.onclick, null); + frame.contentDocument.open(); + assert_equals(div.getAttribute("onclick"), "parent.thrower()"); + assert_equals(div.onclick, null); + const e = frame.contentDocument.createEvent("mouseevents") + e.initEvent("click", false, false); + div.dispatchEvent(e); + frame.contentDocument.close(); +}, "Content attribute event handlers are to be deactivated"); test(t => { const frame = document.body.appendChild(document.createElement("iframe"));