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

DOM: latest DocumentFragment adoption changes #22504

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion custom-elements/adopted-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

calls = [];
doc.documentElement.appendChild(shadowRoot);
assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);
assert_array_equals(calls, ['adopted', document, doc, 'disconnected', 'connected']);
});
}, 'Moving the shadow host\'s shadow of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');

Expand Down
46 changes: 35 additions & 11 deletions dom/nodes/adoption.window.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Testing DocumentFragment with host separately as it has a different node document by design
test(() => {
function create(doc, localName = "div") {
return doc.createElementNS("http://www.w3.org/1999/xhtml", localName);
}

test(t => {
const df = document.createElement("template").content;
const child = df.appendChild(new Text('hi'));
assert_not_equals(df.ownerDocument, document);
const nodeDocument = df.ownerDocument;
document.body.appendChild(df);
t.add_cleanup(() => child.remove());
assert_equals(df.childNodes.length, 0);
assert_equals(child.ownerDocument, document);
assert_equals(df.ownerDocument, nodeDocument);
Expand All @@ -27,32 +32,51 @@ test(() => {
},
{
"name": "ShadowRoot",
"creator": doc => doc.createElementNS("http://www.w3.org/1999/xhtml", "div").attachShadow({mode: "closed"})
"creator": doc => create(doc).attachShadow({mode: "closed"})
}
].forEach(dfTest => {
test(() => {
].forEach(({ name, creator }) => {
test(t => {
const doc = new Document();
const df = dfTest.creator(doc);
const df = creator(doc);
const child = df.appendChild(new Text('hi'));
assert_equals(df.ownerDocument, doc);

document.body.appendChild(df);
t.add_cleanup(() => child.remove());
assert_equals(df.childNodes.length, 0);
assert_equals(child.ownerDocument, document);
assert_equals(df.ownerDocument, doc);
}, `appendChild() and ${dfTest.name}`);
if (name === "ShadowRoot") {
assert_equals(df.ownerDocument, doc);
} else {
assert_equals(df.ownerDocument, document);
}
}, `appendChild() and ${name}`);

test(() => {
const doc = new Document();
const df = dfTest.creator(doc);
const df = creator(doc);
const child = df.appendChild(new Text('hi'));
if (dfTest.name === "ShadowRoot") {
if (name === "ShadowRoot") {
assert_throws_dom("HierarchyRequestError", () => document.adoptNode(df));
} else {
document.adoptNode(df);
assert_equals(df.childNodes.length, 1);
assert_equals(child.ownerDocument, document);
assert_equals(df.ownerDocument, document);
}
}, `adoptNode() and ${dfTest.name}`);
}, `adoptNode() and ${name}`);
});

test(t => {
const doc = new Document();
const host = create(doc);
const shadow = host.attachShadow({mode: "closed"});
const childHost = shadow.appendChild(create(doc, "body"));
const childShadow = childHost.attachShadow({mode: "closed"});
const descendant = childShadow.appendChild(new Text("hi"));
document.body.appendChild(shadow);
t.add_cleanup(() => childHost.remove());
assert_equals(shadow.childNodes.length, 0);
assert_equals(childHost.ownerDocument, document);
assert_equals(childShadow.ownerDocument, document);
assert_equals(descendant.ownerDocument, document);
}, "Nested ShadowRoots");