-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1950326 [wpt PR 50925] - DOM: createElement and createElementNS w…
…ith scoped registries, a=testonly Automatic update from web-platform-tests DOM: createElement and createElementNS with scoped registries For whatwg/dom#1341. -- wpt-commits: a52f97983743aae5fdd5172c9938b47743dc7146 wpt-pr: 50925
- Loading branch information
1 parent
50c309c
commit 8b9ddb1
Showing
2 changed files
with
116 additions
and
5 deletions.
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
87 changes: 87 additions & 0 deletions
87
...rm/tests/custom-elements/revamped-scoped-registry/Document-createElementNS.tentative.html
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,87 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="help" href="https://github.com/whatwg/html/issues/10854"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
// Keep this ~synchronized with Document-createElement | ||
"use strict"; | ||
|
||
const scopedRegistry = new CustomElementRegistry(); | ||
const otherScopedRegistry = new CustomElementRegistry(); | ||
class GlobalABElement extends HTMLElement {}; | ||
class ScopedABElement extends HTMLElement {}; | ||
customElements.define('a-b', GlobalABElement); | ||
scopedRegistry.define('a-b', ScopedABElement); | ||
|
||
test(() => { | ||
assert_true(document.createElementNS('http://www.w3.org/1999/xhtml', 'a-b') instanceof GlobalABElement); | ||
}, 'createElementNS should use the global registry by default'); | ||
|
||
test(() => { | ||
assert_true(document.createElementNS('http://www.w3.org/1999/xhtml', 'a-b', {customElements: scopedRegistry}) instanceof ScopedABElement); | ||
}, 'createElementNS should use the specified scoped registry'); | ||
|
||
test(() => { | ||
const elements = { | ||
div: HTMLDivElement, | ||
form: HTMLFormElement, | ||
span: HTMLSpanElement, | ||
table: HTMLTableElement, | ||
unknown: HTMLUnknownElement, | ||
}; | ||
for (const localName in elements) { | ||
const scopedElement = document.createElementNS('http://www.w3.org/1999/xhtml', localName, {customElements: scopedRegistry}); | ||
assert_true(scopedElement instanceof elements[localName], localName); | ||
assert_equals(scopedElement.customElements, scopedRegistry); | ||
|
||
const globalExplicitElement = document.createElementNS('http://www.w3.org/1999/xhtml', localName, {customElements: window.customElements}); | ||
assert_true(globalExplicitElement instanceof elements[localName], localName); | ||
assert_equals(globalExplicitElement.customElements, window.customElements); | ||
|
||
const globalImplicitElement = document.createElementNS('http://www.w3.org/1999/xhtml', localName); | ||
assert_true(globalImplicitElement instanceof elements[localName], localName); | ||
assert_equals(globalImplicitElement.customElements, window.customElements); | ||
} | ||
}, 'createElementNS should create a builtin element regardless of a custom element registry specified'); | ||
|
||
test(() => { | ||
assert_true(document.createElementNS('http://www.w3.org/1999/xhtml', 'a-b', {customElements: window.customElements}) instanceof GlobalABElement); | ||
}, 'createElementNS should use the specified global registry'); | ||
|
||
test(() => { | ||
const element = document.createElementNS('http://www.w3.org/1999/xhtml', 'a-b', {customElements: otherScopedRegistry}); | ||
assert_equals(element.__proto__.constructor.name, 'HTMLElement'); | ||
}, 'createElementNS should create an upgrade candidate when there is no matching definition in the specified registry'); | ||
|
||
test(() => { | ||
class CDElement extends HTMLElement { } | ||
const registry = new CustomElementRegistry; | ||
const cdElement = document.createElementNS('http://www.w3.org/1999/xhtml', 'c-d', {customElements: registry}); | ||
assert_false(cdElement instanceof CDElement); | ||
assert_equals(cdElement.__proto__.constructor.name, 'HTMLElement'); | ||
registry.define('c-d', CDElement); | ||
assert_false(cdElement instanceof CDElement); // Not yet upgraded since it's disconnected. | ||
assert_equals(cdElement.__proto__.constructor.name, 'HTMLElement'); | ||
document.body.appendChild(cdElement); | ||
assert_true(cdElement instanceof CDElement); | ||
}, 'createElementNS should create an upgrade candidate and the candidate should be upgraded when the element is defined'); | ||
|
||
test(() => { | ||
const doc = new Document(); | ||
const scopedElement = doc.createElementNS(null, "time", {customElements: scopedRegistry}); | ||
assert_equals(scopedElement.namespaceURI, null); | ||
assert_equals(scopedElement.customElements, scopedRegistry); | ||
|
||
const abElement = doc.createElementNS(null, "a-b", {customElements: scopedRegistry}); | ||
assert_equals(abElement.namespaceURI, null); | ||
assert_equals(abElement.customElements, scopedRegistry); | ||
assert_false(abElement instanceof ScopedABElement); | ||
}, 'createElementNS on a non-HTML document should still handle registries correctly'); | ||
|
||
</script> | ||
</body> | ||
</html> |