mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
Tests: Import WPT custom-elements/registries tests
Includes reimporting the test we already had, which has changed significantly. Most of these fail, but importing them now to track progress.
This commit is contained in:
committed by
Tim Ledbetter
parent
86e1be123f
commit
fe3c6a1f9f
Notes:
github-actions[bot]
2026-03-27 19:51:35 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/fe3c6a1f9f9 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8613 Reviewed-by: https://github.com/tcl3 ✅
@@ -0,0 +1,100 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
|
||||
<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-createElementNS
|
||||
"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.createElement('a-b') instanceof GlobalABElement);
|
||||
}, 'createElement should use the global registry by default');
|
||||
|
||||
test(() => {
|
||||
assert_true(document.createElement('a-b', {customElementRegistry: scopedRegistry}) instanceof ScopedABElement);
|
||||
}, 'createElement 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.createElement(localName, {customElementRegistry: scopedRegistry});
|
||||
assert_true(scopedElement instanceof elements[localName], localName);
|
||||
assert_equals(scopedElement.customElementRegistry, scopedRegistry);
|
||||
|
||||
const globalExplicitElement = document.createElement(localName, {customElementRegistry: window.customElements});
|
||||
assert_true(globalExplicitElement instanceof elements[localName], localName);
|
||||
assert_equals(globalExplicitElement.customElementRegistry, window.customElements);
|
||||
|
||||
const globalImplicitElement = document.createElement(localName);
|
||||
assert_true(globalImplicitElement instanceof elements[localName], localName);
|
||||
assert_equals(globalImplicitElement.customElementRegistry, window.customElements);
|
||||
}
|
||||
}, 'createElement should create a builtin element regardless of a custom element registry specified');
|
||||
|
||||
test(() => {
|
||||
assert_true(document.createElement('a-b', {customElementRegistry: window.customElements}) instanceof GlobalABElement);
|
||||
}, 'createElement should use the specified global registry');
|
||||
|
||||
test(() => {
|
||||
const element = document.createElement('a-b', {customElementRegistry: otherScopedRegistry});
|
||||
assert_equals(element.__proto__.constructor.name, 'HTMLElement');
|
||||
}, 'createElement should create an upgrade candidate when there is no matching definition in the specified registry');
|
||||
|
||||
test((t) => {
|
||||
assert_equals(document.createElement('div', {customElementRegistry: null}).customElementRegistry, null);
|
||||
}, `document.createElement should create a builtin element with null registry if customElementRegistry is set to null`);
|
||||
|
||||
test((t) => {
|
||||
assert_equals(document.createElement('c-d', {customElementRegistry: null}).customElementRegistry, null);
|
||||
}, `document.createElement should create a custom element candidate with null registry if customElementRegistry is set to null`);
|
||||
|
||||
test((t) => {
|
||||
assert_equals(document.createElement('a-b', {customElementRegistry: null}).customElementRegistry, null);
|
||||
}, `document.createElement should create a custom element candidate with null registry if customElementRegistry is set to null even if there is a custom element of the same name in the glboal registry`);
|
||||
|
||||
test(() => {
|
||||
class CDElement extends HTMLElement { }
|
||||
const registry = new CustomElementRegistry;
|
||||
const cdElement = document.createElement('c-d', {customElementRegistry: 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);
|
||||
}, 'createElement should create an upgrade candidate and the candidate should be upgraded when the element is defined');
|
||||
|
||||
test(() => {
|
||||
const doc = new Document();
|
||||
const scopedElement = doc.createElement("time", {customElementRegistry: scopedRegistry});
|
||||
assert_equals(scopedElement.namespaceURI, null);
|
||||
assert_equals(scopedElement.customElementRegistry, scopedRegistry);
|
||||
|
||||
const abElement = doc.createElement("a-b", {customElementRegistry: scopedRegistry});
|
||||
assert_equals(abElement.namespaceURI, null);
|
||||
assert_equals(abElement.customElementRegistry, scopedRegistry);
|
||||
assert_false(abElement instanceof ScopedABElement);
|
||||
}, 'createElement on a non-HTML document should still handle registries correctly');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user