tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2e38ebd936fc51fe8733e84e922acda48e7ab196
parent 0ca802342a001e9b4e0a525d6910c3f1621ad5ed
Author: Ryosuke Niwa <rniwa@webkit.org>
Date:   Sat, 22 Nov 2025 21:10:19 +0000

Bug 2001015 [wpt PR 56108] - Add new tests for customelementregistry content attribute and specifying null to createEleent and attachShadow per, a=testonly

Automatic update from web-platform-tests
Add new tests for customelementregistry content attribute and specifying null to createEleent and attachShadow per (#56108)

- https://github.com/whatwg/dom/pull/1424
- https://github.com/whatwg/dom/pull/1423

Also update the existing tests to account for the behavior differences.`
--

wpt-commits: cc1c056521abd0ff97456455dbebe113617a2bc1
wpt-pr: 56108

Diffstat:
Mtesting/web-platform/tests/custom-elements/registries/Element-customElementRegistry-exceptions.html | 2--
Mtesting/web-platform/tests/custom-elements/registries/Element-customElementRegistry.html | 2+-
Mtesting/web-platform/tests/custom-elements/registries/ShadowRoot-init-customElementRegistry.html | 8++++----
Atesting/web-platform/tests/custom-elements/registries/scoped-custom-element-registry-customelementregistry-attribute-in-xhtml.xhtml | 45+++++++++++++++++++++++++++++++++++++++++++++
Atesting/web-platform/tests/custom-elements/registries/scoped-custom-element-registry-customelementregistry-attribute.html | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atesting/web-platform/tests/custom-elements/registries/scoped-registry-append-does-not-upgrade.html | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtesting/web-platform/tests/custom-elements/registries/scoped-registry-define-upgrade-criteria.html | 3+--
7 files changed, 249 insertions(+), 9 deletions(-)

diff --git a/testing/web-platform/tests/custom-elements/registries/Element-customElementRegistry-exceptions.html b/testing/web-platform/tests/custom-elements/registries/Element-customElementRegistry-exceptions.html @@ -7,8 +7,6 @@ <script src="/resources/testharnessreport.js"></script> </head> <body> -<div id="host-window"><template shadowrootmode="open"><a-b></a-b></template></div> -<div id="host-null"><template shadowrootmode="open" shadowrootcustomelementregistry=""><a-b></a-b></template></div> <script> setup({allow_uncaught_exception : true}); diff --git a/testing/web-platform/tests/custom-elements/registries/Element-customElementRegistry.html b/testing/web-platform/tests/custom-elements/registries/Element-customElementRegistry.html @@ -41,7 +41,7 @@ test((t) => { const clone = document.getElementById('host-null').cloneNode(true); const ab = clone.shadowRoot.querySelector('a-b'); document.body.appendChild(ab); - assert_equals(ab.customElementRegistry, window.customElements); + assert_equals(ab.customElementRegistry, null); const frame = document.createElement('iframe'); t.add_cleanup(() => frame.remove()); diff --git a/testing/web-platform/tests/custom-elements/registries/ShadowRoot-init-customElementRegistry.html b/testing/web-platform/tests/custom-elements/registries/ShadowRoot-init-customElementRegistry.html @@ -36,15 +36,15 @@ test(() => { test(() => { const host = document.body.appendChild(document.createElement('div')); const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null}); - assert_equals(shadowRoot.customElementRegistry, window.customElements); -}, 'attachShadow() should use the global registry when customElementRegistry is null (host uses global registry)'); + assert_equals(shadowRoot.customElementRegistry, null); +}, 'attachShadow() should use null registry when customElementRegistry is null (host uses global registry)'); test(() => { const registry = new CustomElementRegistry; const host = document.body.appendChild(document.createElement('div', {customElementRegistry: registry})); const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null}); - assert_equals(shadowRoot.customElementRegistry, window.customElements); -}, 'attachShadow() should use the global registry when customElementRegistry is null (host uses custom registry)'); + assert_equals(shadowRoot.customElementRegistry, null); +}, 'attachShadow() should use null registry when customElementRegistry is null (host uses custom registry)'); test(() => { const registry = new CustomElementRegistry; diff --git a/testing/web-platform/tests/custom-elements/registries/scoped-custom-element-registry-customelementregistry-attribute-in-xhtml.xhtml b/testing/web-platform/tests/custom-elements/registries/scoped-custom-element-registry-customelementregistry-attribute-in-xhtml.xhtml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"/> +<link rel="help" href="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-initialize"/> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script> +<![CDATA[ + +customElements.define('c-d', class ABElement extends HTMLElement { }); + +]]> +</script> +<div id="container"><a-b customelementregistry=""></a-b><c-d customelementregistry=""></c-d></div> +<script> +<![CDATA[ + +const container = document.getElementById('container'); +test((test) => { + assert_equals(container.querySelector('a-b').customElementRegistry, null); +}, `XHTML parser should create a custom element candidate with null registry if customelementregistry is set`); + +test((test) => { + assert_equals(container.querySelector('c-d').customElementRegistry, null); +}, `XHTML parser should create a defined custom element with null registry if customelementregistry is set`); + +test((test) => { + container.setHTMLUnsafe(`<a-b customelementregistry></a-b>`); + assert_equals(container.querySelector('a-b').customElementRegistry, null); +}, `XHTML fragment parser should create a custom element candidate with null registry if customelementregistry is set`); + +test((test) => { + container.setHTMLUnsafe(`<c-d></c-d>`); + assert_equals(container.querySelector('c-d').customElementRegistry, window.customElements); + container.setHTMLUnsafe(`<c-d customelementregistry></c-d>`); + assert_equals(container.querySelector('c-d').customElementRegistry, null); +}, `XHTML fragment parser should create a defined custom element with null registry if customelementregistry is set`); + +]]> +</script> +</body> +</html> diff --git a/testing/web-platform/tests/custom-elements/registries/scoped-custom-element-registry-customelementregistry-attribute.html b/testing/web-platform/tests/custom-elements/registries/scoped-custom-element-registry-customelementregistry-attribute.html @@ -0,0 +1,106 @@ +<!DOCTYPE html> +<html> +<head> +<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-initialize"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script> + +function makeIframe(test) { + const iframe = document.createElement('iframe'); + document.body.appendChild(iframe); + test.add_cleanup(() => iframe.remove()); + return [iframe.contentDocument, iframe.contentWindow]; +} + +function makeIframeWithABElement(test) { + const [doc, win] = makeIframe(test); + win.customElements.define('a-b', class ABElement extends win.HTMLElement { }); + return [doc, win]; +} + +function runBasicTests(makeIframe, elementName, elementDescription) { + test((test) => { + const [doc, win] = makeIframe(test); + doc.documentElement.setHTMLUnsafe(`<${elementName} customelementregistry></${elementName}>`); + assert_equals(doc.querySelector(elementName).customElementRegistry, null); + }, `HTML parser should create a ${elementDescription} with null registry if customelementregistry is set`); + + test((test) => { + const [doc, win] = makeIframe(test); + assert_equals(doc.createElement(elementName, {customElementRegistry: null}).customElementRegistry, null); + assert_equals(doc.createElementNS('http://www.w3.org/1999/xhtml', 'div', {customElementRegistry: null}).customElementRegistry, null); + }, `document.createElement should create a ${elementDescription} with null registry if customElement is set to null`); + + test((test) => { + const [doc, win] = makeIframe(test); + const host = doc.createElement(elementName); + const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null}) + assert_equals(shadowRoot.customElementRegistry, null); + }, `attchShadow on a ${elementDescription} with null customElementRegistry should create a ShadowRoot with null registry`); + + test((test) => { + const [doc, win] = makeIframe(test); + const element = doc.createElement(elementName); + assert_equals(element.customElementRegistry, win.customElements); + element.setAttribute('customelementregistry', ''); + assert_equals(element.customElementRegistry, win.customElements); + }, `Setting customelementregistry content attribute after a ${elementDescription} had finishsed parsing should not set null registry`); + + test((test) => { + const [doc, win] = makeIframe(test); + const element = doc.createElement(elementName, {customElementRegistry: null}); + assert_equals(element.customElementRegistry, null); + assert_equals(element.cloneNode(false).customElementRegistry, null); + + doc.documentElement.setHTMLUnsafe(`<${elementName} customelementregistry></${elementName}>`); + assert_equals(doc.querySelector(elementName).customElementRegistry, null); + assert_equals(doc.querySelector(elementName).cloneNode(true).customElementRegistry, null); + }, `Cloning a ${elementDescription} with null regsitry should create an element with null registry`); +} + +runBasicTests(makeIframe, 'div', 'builtin element'); +runBasicTests(makeIframe, 'a-b', 'custom element candidate'); +runBasicTests(makeIframeWithABElement, 'a-b', 'custom element'); + +test((test) => { + const [doc, win] = makeIframe(test); + + const upgradeCandidate = doc.createElement('a-b'); + assert_equals(upgradeCandidate.customElementRegistry, win.customElements); + + doc.body.setHTMLUnsafe('<a-b></a-b>'); + assert_equals(doc.querySelector('a-b').customElementRegistry, win.customElements); + + assert_equals(upgradeCandidate.customElementRegistry, win.customElements); + let customElementRegistryDuringConstruction = null; + win.customElements.define('a-b', class ABElement extends win.HTMLElement { + constructor() { + super(); + this.setAttribute('customelementregistry', ''); + customElementRegistryDuringConstruction = this.customElementRegistry; + this.removeAttribute('customelementregistry', ''); + } + }); + assert_equals(customElementRegistryDuringConstruction, win.customElements); + assert_equals(doc.querySelector('a-b').customElementRegistry, win.customElements); + + const element = doc.createElement('a-b'); + assert_equals(customElementRegistryDuringConstruction, win.customElements); + assert_equals(element.customElementRegistry, win.customElements); + + doc.body.setHTMLUnsafe('<a-b></a-b>'); + assert_equals(customElementRegistryDuringConstruction, win.customElements); + assert_equals(element.customElementRegistry, win.customElements); + + win.customElements.upgrade(upgradeCandidate); + assert_equals(customElementRegistryDuringConstruction, win.customElements); + assert_equals(element.customElementRegistry, win.customElements); +}, `Setting customelementregistry content attribute during constructor should not make it use null registry`); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/custom-elements/registries/scoped-registry-append-does-not-upgrade.html b/testing/web-platform/tests/custom-elements/registries/scoped-registry-append-does-not-upgrade.html @@ -0,0 +1,92 @@ +<!DOCTYPE html> +<html> +<head> +<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script> + +test(() => { + assert_equals((new Document).createElement('a-b').customElementRegistry, null); + assert_equals(document.implementation.createHTMLDocument().createElement('a-b').customElementRegistry, null); + assert_equals(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null).createElement('a-b').customElementRegistry, null); +}, 'customElementRegistry of an upgrade candidate created in a document without a browsing context uses null regsitry by default'); + +function makeIframe(test) { + const iframe = document.createElement('iframe'); + document.body.appendChild(iframe); + test.add_cleanup(() => iframe.remove()); + return [iframe.contentDocument, iframe.contentWindow]; +} + +test((test) => { + const [doc, win] = makeIframe(test); + doc.documentElement.setHTMLUnsafe('<div id="host"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>'); + const hostClone = doc.getElementById('host').cloneNode(true); + assert_equals(hostClone.shadowRoot.customElementRegistry, null); + assert_equals(hostClone.shadowRoot.querySelector('a-b').customElementRegistry, null); +}, 'Connecting a custom element candiate in a shadow root with a scoped custom element registry has null registry by default'); + +test((test) => { + const [doc, win] = makeIframe(test); + doc.documentElement.setHTMLUnsafe('<div id="host"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>'); + win.customElements.define('a-b', class ABElement extends win.HTMLElement { }); + const hostClone = doc.getElementById('host').cloneNode(true); + assert_equals(hostClone.shadowRoot.customElementRegistry, null); + const candidate = hostClone.shadowRoot.querySelector('a-b'); + assert_equals(candidate.customElementRegistry, null); + doc.body.appendChild(candidate); + assert_equals(candidate.customElementRegistry, null); +}, 'Connecting a custom element candiate with null registry does not set the registry'); + +test((test) => { + const [doc, win] = makeIframe(test); + doc.documentElement.setHTMLUnsafe('<div id="host"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>'); + win.customElements.define('a-b', class ABElement extends win.HTMLElement { }); + const hostClone = doc.getElementById('host').cloneNode(true); + const candidate = hostClone.shadowRoot.querySelector('a-b'); + const registry = new CustomElementRegistry; + assert_equals(candidate.customElementRegistry, null); + registry.initialize(hostClone.shadowRoot); + assert_equals(candidate.customElementRegistry, registry); + doc.body.appendChild(candidate); + assert_equals(candidate.customElementRegistry, registry); + + const element = doc.createElement('host', {customElementRegistry: registry}); + assert_equals(element.customElementRegistry, registry); + doc.body.appendChild(element); + assert_equals(element.customElementRegistry, registry); +}, 'Connecting a custom element candiate with a scoped custom element registry does not change the registry'); + +test((test) => { + const [doc, win] = makeIframe(test); + doc.documentElement.setHTMLUnsafe('<div id="host1"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>' + + '<div id="host2"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><c-d></c-d></template></div>'); + win.customElements.define('a-b', class ABElement extends win.HTMLElement { }); + const clone1 = doc.getElementById('host1').cloneNode(true); + const clone2 = doc.getElementById('host2').cloneNode(true); + const candidate = clone1.shadowRoot.querySelector('a-b'); + assert_equals(candidate.customElementRegistry, null); + assert_equals(clone2.shadowRoot.querySelector('c-d').customElementRegistry, null); + const registry = new CustomElementRegistry; + registry.initialize(clone2.shadowRoot); + assert_equals(clone2.shadowRoot.querySelector('c-d').customElementRegistry, registry); + clone2.shadowRoot.appendChild(candidate); + assert_equals(candidate.customElementRegistry, null); +}, 'Inserting a custom element candiate with null registry does not change the registry'); + +test((test) => { + const [doc, win] = makeIframe(test); + const registry = new CustomElementRegistry; + const host = doc.createElement('div'); + const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: registry}); + assert_equals(shadowRoot.customElementRegistry, registry); + doc.body.appendChild(host); + assert_equals(shadowRoot.customElementRegistry, registry); +}, 'Inserting the shadow host of a shadow root with a scoped custom element registry does not change the registry'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/custom-elements/registries/scoped-registry-define-upgrade-criteria.html b/testing/web-platform/tests/custom-elements/registries/scoped-registry-define-upgrade-criteria.html @@ -123,9 +123,8 @@ test(t => { test(t => { const name = nextCustomElementName(); - const node = document.body.appendChild(document.createElement(name)); - const registry = new CustomElementRegistry; + const node = document.body.appendChild(document.createElement(name, {customElementRegistry: registry})); const shadow = attachShadowForTest(t, registry); shadow.appendChild(node);