Skip to content

Commit 63ab5f3

Browse files
committed
Strengthen mid-stream registry, streamed importmap, and chained template marker tests
1 parent 67ba40b commit 63ab5f3

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎domparsing/stream-html-custom-element.html‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,30 @@
483483
document.body.appendChild(iframe);
484484
});
485485
const { name, log } = createCustomElementClass();
486+
const iframeLog = [];
487+
class IframeCustomElement extends iframe.contentWindow.HTMLElement {
488+
constructor() {
489+
super();
490+
iframeLog.push("constructed");
491+
}
492+
connectedCallback() {
493+
iframeLog.push("connected");
494+
}
495+
}
496+
iframe.contentWindow.customElements.define(name, IframeCustomElement);
486497
const target = document.getElementById("container").appendChild(document.createElement("div"));
498+
t.add_cleanup(() => target.remove());
487499
const writer = target.streamHTMLUnsafe(options).getWriter();
488500
await writer.write(first_chunk);
489501
iframe.contentDocument.body.appendChild(target);
490502
await writer.write(`<${name}></${name}>`);
491503
await writer.close();
492504

493-
assert_not_equals(target.querySelector(name), null);
505+
const el = target.querySelector(name);
506+
assert_not_equals(el, null);
494507
assert_array_equals(log, [], "the original document's definition must not be used");
508+
assert_array_equals(iframeLog, ["constructed", "connected"], "the new document's definition must be used");
509+
assert_true(el instanceof IframeCustomElement);
495510
}, `streamHTMLUnsafe uses the new document's registry after the target is adopted mid-stream${description}`);
496511
}
497512
</script>

‎domparsing/stream-html-defer-async-script.html‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@
122122
await writer.close();
123123
}, `element.${method}: inline defer, importmap, and speculationrules scripts`);
124124

125+
promise_test(async (t) => {
126+
const iframe = document.createElement("iframe");
127+
t.add_cleanup(() => iframe.remove());
128+
iframe.srcdoc = "<!doctype html><body><div id='target'></div></body>";
129+
await new Promise((resolve) => {
130+
iframe.addEventListener("load", resolve, { once: true });
131+
document.body.appendChild(iframe);
132+
});
133+
134+
const done = Promise.withResolvers();
135+
iframe.contentWindow.done = done;
136+
const target = iframe.contentDocument.getElementById("target");
137+
const writer = target[method]({ runScripts: true }).getWriter();
138+
const moduleUrl = "data:text/javascript,export const value = 'from-importmap';";
139+
140+
await writer.write(
141+
`<script type="importmap">{"imports":{"#streamed-dep":"${moduleUrl}"}}<` + `/script>` +
142+
`<script type="module">import { value } from "#streamed-dep"; window.mapped = value; window.done.resolve();<` + `/script>`
143+
);
144+
await writer.close();
145+
await failOnTimeout(done.promise);
146+
147+
assert_equals(iframe.contentWindow.mapped, "from-importmap", "Streamed importmap resolves bare/hash specifier in subsequent streamed module");
148+
}, `element.${method}: streamed importmap registers and resolves specifiers for streamed module scripts`);
149+
125150
promise_test(async (t) => {
126151
window.events = [];
127152
window.slow_async = Promise.withResolvers();

‎html/semantics/scripting-1/the-template-element/template-for/chained-streaming-templates-with-custom-element.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
77
<body>
8-
<div id="target"><?marker name="target"?>Original Target<?end></div>
8+
<div id="target"><?start name="target"?>Original Target<?end?></div>
99

1010
<script>
1111
class CustomElement extends HTMLElement {
@@ -45,6 +45,7 @@
4545

4646
const streamed = document.getElementById('streamed');
4747
assert_not_equals(streamed, null, "Span should be in the document");
48+
assert_false(target.textContent.includes("Original Target"), "Original range content should be replaced");
4849
}, "Chained streaming templates and OwnerDocument");
4950
</script>
5051
</body>

0 commit comments

Comments
 (0)