-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Adoption and DocumentFragment #16348
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,38 @@ | |
}); | ||
}, 'Moving the shadow host of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback'); | ||
|
||
promise_test(function () { | ||
return getDocument().then(function (doc) { | ||
var instance = document.createElement('my-custom-element'); | ||
var host = document.createElement('div'); | ||
var shadowRoot = host.attachShadow({mode: 'closed'}); | ||
shadowRoot.appendChild(instance); | ||
document.body.appendChild(host); | ||
|
||
calls = []; | ||
doc.documentElement.appendChild(shadowRoot); | ||
assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']); | ||
}); | ||
}, 'Moving the shadow host\'s shadow of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback'); | ||
|
||
promise_test(function () { | ||
return getDocument().then(function (doc) { | ||
var instance = document.createElement('my-custom-element'); | ||
var host = document.createElement('template'); | ||
var shadowRoot = host.content; | ||
shadowRoot.appendChild(instance); | ||
document.body.appendChild(host); | ||
|
||
calls = []; | ||
doc.documentElement.appendChild(shadowRoot); | ||
if (documentName === "the document of the template elements") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rniwa this seems a little ugly btw, but I wasn't sure how to avoid it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
assert_array_equals(calls, ['connected']); | ||
} else { | ||
assert_array_equals(calls, ['adopted', shadowRoot.ownerDocument, doc, 'connected']); | ||
} | ||
}); | ||
}, 'Moving the <template>\'s content of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback'); | ||
|
||
promise_test(function () { | ||
return getDocument().then(function (doc) { | ||
var instance = document.createElement('my-custom-element'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Testing DocumentFragment with host separately as it has a different node document by design | ||
test(() => { | ||
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); | ||
assert_equals(df.childNodes.length, 0); | ||
assert_equals(child.ownerDocument, document); | ||
assert_equals(df.ownerDocument, nodeDocument); | ||
}, `appendChild() and DocumentFragment with host`); | ||
|
||
test(() => { | ||
const df = document.createElement("template").content; | ||
const child = df.appendChild(new Text('hi')); | ||
const nodeDocument = df.ownerDocument; | ||
document.adoptNode(df); | ||
assert_equals(df.childNodes.length, 1); | ||
assert_equals(child.ownerDocument, nodeDocument); | ||
assert_equals(df.ownerDocument, nodeDocument); | ||
}, `adoptNode() and DocumentFragment with host`); | ||
|
||
[ | ||
{ | ||
"name": "DocumentFragment", | ||
"creator": doc => doc.createDocumentFragment() | ||
}, | ||
{ | ||
"name": "ShadowRoot", | ||
"creator": doc => doc.createElementNS("http://www.w3.org/1999/xhtml", "div").attachShadow({mode: "closed"}) | ||
} | ||
].forEach(dfTest => { | ||
test(() => { | ||
const doc = new Document(); | ||
const df = dfTest.creator(doc); | ||
const child = df.appendChild(new Text('hi')); | ||
assert_equals(df.ownerDocument, doc); | ||
|
||
document.body.appendChild(df); | ||
assert_equals(df.childNodes.length, 0); | ||
assert_equals(child.ownerDocument, document); | ||
assert_equals(df.ownerDocument, doc); | ||
}, `appendChild() and ${dfTest.name}`); | ||
|
||
test(() => { | ||
const doc = new Document(); | ||
const df = dfTest.creator(doc); | ||
const child = df.appendChild(new Text('hi')); | ||
if (dfTest.name === "ShadowRoot") { | ||
assert_throws("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}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name
shadowRoot
is very confusing. It should bedocumentFragment
or something.