Skip to content

Commit

Permalink
document open steps: More event listener tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Jul 21, 2018
1 parent 86ef763 commit 704c063
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 20 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,7 +19,63 @@ 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();
// Pending resolution from https://github.com/whatwg/html/issues/3836.
// 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();
// Pending resolution from https://github.com/whatwg/html/issues/3836.
// 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 removed");

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.setAttribute("onclick", "throw new Error('element event listener not removed')");
assert_not_equals(div.onclick, null);
frame.contentDocument.open();
// Pending resolution from https://github.com/whatwg/html/issues/3836.
// 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 removed");

test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
Expand Down

0 comments on commit 704c063

Please sign in to comment.