Skip to content

Commit

Permalink
HTML: More event listener tests for document open steps
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Aug 9, 2018
1 parent a4700f5 commit a595475
Show file tree
Hide file tree
Showing 2 changed files with 69 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,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"));
Expand Down

0 comments on commit a595475

Please sign in to comment.