-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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,custom-elements: Add tests for HTMLElement.attachInternals() #15123
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals"> | ||
<div id="container"></div> | ||
<script> | ||
test(() => { | ||
class MyElement1 extends HTMLElement { | ||
} | ||
customElements.define('my-element1', MyElement1); | ||
const container = document.querySelector('#container'); | ||
|
||
let element = new MyElement1(); | ||
assert_true(element.attachInternals() instanceof ElementInternals, | ||
'New - 1st call'); | ||
assert_throws('InvalidStateError', () => { element.attachInternals(); }, | ||
'New - 2nd call'); | ||
|
||
element = document.createElement('my-element1'); | ||
assert_true(element.attachInternals() instanceof ElementInternals, | ||
'createElement - 1st call'); | ||
assert_throws('InvalidStateError', () => { element.attachInternals(); }, | ||
'createElement - 2nd call'); | ||
|
||
container.innerHTML = '<my-element1></my-element1>'; | ||
assert_true(container.firstChild.attachInternals() instanceof ElementInternals, | ||
'Parser - 1st call'); | ||
assert_throws('InvalidStateError', () => { | ||
container.firstChild.attachInternals(); | ||
}, 'Parser - 2nd call'); | ||
}, 'Successful attachInternals() and the second call.'); | ||
|
||
test(() => { | ||
class MyDiv extends HTMLDivElement {} | ||
customElements.define('my-div', MyDiv, { extends: 'div' }); | ||
const customizedBuiltin = document.createElement('div', { is: 'my-div'}); | ||
assert_throws('NotSupportedError', () => { customizedBuiltin.attachInternals() }); | ||
}, 'attachInternals() throws a NotSupportedError if it is called for ' + | ||
'a customized built-in element'); | ||
|
||
test(() => { | ||
const builtin = document.createElement('div'); | ||
assert_throws('InvalidStateError', () => { builtin.attachInternals() }); | ||
|
||
const doc = document.implementation.createDocument('foo', null); | ||
const span = doc.appendChild(doc.createElementNS('http://www.w3.org/1999/xhtml', 'html:span')); | ||
assert_true(span instanceof HTMLElement); | ||
assert_throws('InvalidStateError', () => { span.attachInternals(); }); | ||
|
||
const undefinedCustom = document.createElement('my-element'); | ||
assert_throws('InvalidStateError', () => { undefinedCustom.attachInternals() }); | ||
}, 'If a custom element definition for the local name of the element doesn\'t' + | ||
' exist, throw an InvalidStateError'); | ||
|
||
test(() => { | ||
class MyElement2 extends HTMLElement { | ||
static get disabledFeatures() { return ['internals']; } | ||
} | ||
customElements.define('my-element2', MyElement2); | ||
const container = document.querySelector('#container'); | ||
|
||
assert_throws('NotSupportedError', () => { | ||
(new MyElement2).attachInternals(); | ||
}); | ||
assert_throws('NotSupportedError', () => { | ||
document.createElement('my-element2').attachInternals(); | ||
}); | ||
assert_throws('NotSupportedError', () => { | ||
container.innerHTML = '<my-element2></my-element2>'; | ||
container.firstChild.attachInternals(); | ||
}); | ||
|
||
class MyElement3 extends HTMLElement { | ||
static get disabledFeatures() { return ['INTERNALS']; } | ||
} | ||
customElements.define('my-element3', MyElement3); | ||
assert_true((new MyElement3).attachInternals() instanceof ElementInternals); | ||
}, 'If a custom element definition for the local name of the element has ' + | ||
'disable internals flag, throw a NotSupportedError'); | ||
</script> | ||
</body> |
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.
This may be a bit clearer if you use
undefined-element
instead ofmy-element
. Right now I had to look up to see what names you had defined so far and see that only my-element1 was defined, not my-element.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.
Done