Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML: document.open() event listener removal #10686

Merged
merged 2 commits into from
May 2, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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());
body.addEventListener("x", t.unreached_func());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding descriptions to unreached_funcs makes test failures much easier to diagnose.

frame.contentDocument.open();
frame.contentDocument.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "close()" here seems not great since if someone implemented close() as removing the event listeners the test would still pass.

frame.contentDocument.dispatchEvent(new Event("x"));
body.dispatchEvent(new Event("x"));
}, "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();
frame.contentDocument.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern about close()

once = true;
});
frame.contentDocument.addEventListener("x", t.unreached_func());
frame.contentDocument.dispatchEvent(new Event("x"));
assert_true(once);
}, "Event listeners are to be removed with immediate effect");

test(t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth gating this behind an if (document.body.attachShadow) so browsers without shadow DOM don't get failures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's bad practice. It makes it less clear what's going on. And have a varying number of tests between browsers, if that's what you're suggesting, seems even worse for tooling.

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());
});
frame.contentDocument.open();
frame.contentDocument.close();
nodes.forEach(node => {
node.dispatchEvent(new Event("x"));
});
}, "Event listeners are to be removed from shadow trees as well");