test: consolidate browser API regression fixtures

Combine the fixture changes from #3271, #3272, #3274, #3275, #3276, #3277.
This commit is contained in:
ldm0
2026-11-20 11:33:20 +08:00
committed by Donough Liu
parent d5e1ced4be
commit cbaf7dc3a4
7 changed files with 130 additions and 110 deletions
@@ -5,10 +5,14 @@
window.parserOwnedModuleTlaPayloadOrder = [];
window.addEventListener("error", (event) => {
window.parserOwnedModuleTlaPayloadOrder.push("window-error");
window.parserOwnedModuleTlaPayloadErrorMessageMatches = Boolean(
typeof event.message === "string" && event.message.length > 0,
);
window.parserOwnedModuleTlaPayloadErrorIdentityMatches =
event.error === window.parserOwnedModuleTlaPayloadReason;
window.parserOwnedModuleTlaPayloadErrorMessageMatches =
typeof event.message === "string" && event.message.length > 0;
event.error === window.parserOwnedModuleTlaPayloadReason &&
Object.getPrototypeOf(event.error) === null &&
!Object.hasOwn(event.error, "message") &&
!Object.hasOwn(event.error, "fileName");
window.parserOwnedModuleTlaPayloadFilenameMatches =
typeof event.filename === "string" &&
event.filename.includes(
@@ -20,8 +24,8 @@
type="module"
onerror="window.parserOwnedModuleTlaPayloadOrder.push('script-error');"
>
window.parserOwnedModuleTlaPayloadReason = Object.create(null);
await Promise.reject(window.parserOwnedModuleTlaPayloadReason);
const reason = window.parserOwnedModuleTlaPayloadReason = Object.create(null);
await Promise.reject(reason);
</script>
<script type="module">
window.parserOwnedModuleTlaPayloadOrder.push("later-module");
@@ -5,13 +5,16 @@
let callbackEntries = null;
let callbackMeasureEntries = null;
let callbackNamedEntries = null;
const observer = new PerformanceObserver((list) => {
callbackEntries = list.getEntries();
callbackMeasureEntries = list.getEntriesByType("measure");
callbackNamedEntries = list.getEntriesByName("duration");
observer.disconnect();
const observed = new Promise(resolve => {
const observer = new PerformanceObserver((list) => {
callbackEntries = list.getEntries();
callbackMeasureEntries = list.getEntriesByType("measure");
callbackNamedEntries = list.getEntriesByName("duration");
observer.disconnect();
resolve();
});
observer.observe({ type: "measure" });
});
observer.observe({ type: "measure" });
performance.clearMarks();
performance.clearMeasures();
@@ -38,7 +41,7 @@
const bufferedMarkRecords = bufferedMarkObserver.takeRecords();
bufferedMarkObserver.disconnect();
Promise.resolve().then(() => {
observed.then(() => {
window.performanceMarkInstance = mark instanceof PerformanceMark;
window.performanceMeasureInstance = measure instanceof PerformanceMeasure;
window.performanceGetEntriesCount = allEntries.length;
+77 -73
View File
@@ -3,82 +3,86 @@ async function runPipeDisturbedProbe(scenario) {
const check = (condition, label) => {
if (!condition) errors.push(label);
};
for (const byteStream of [false, true]) {
for (const method of ['pipeTo', 'pipeThrough']) {
const cases = scenario === 'start'
? ['backpressure', 'pre-aborted', 'source-closed', 'source-errored', 'sink-closed', 'sink-errored']
: ['source-locked', 'sink-locked', 'invalid-sink', 'invalid-signal', 'throwing-options'];
for (const state of cases) {
const label = `${byteStream ? 'bytes' : 'default'}/${method}/${state}`;
const reason = new Error(label);
let sourceController, sinkController, pulls = 0, writes = 0;
const source = new ReadableStream({
...(byteStream ? {type: 'bytes'} : {}),
start(controller) { sourceController = controller; },
pull() { ++pulls; }
}, {highWaterMark: 0});
const body = new Response(source);
check(body.body === source, `${label}: body observes the tested source`);
const sink = new WritableStream({
start(controller) { sinkController = controller; },
write() { ++writes; },
abort() { check(body.bodyUsed, `${label}: abort observes disturbed source`); }
}, {highWaterMark: 0});
const output = new ReadableStream({}, {highWaterMark: 0});
const outputBody = new Response(output);
const abort = new AbortController();
let options = {signal: abort.signal, preventCancel: true};
let destination = sink, reader, writer;
if (state === 'source-closed') sourceController.close();
if (state === 'source-errored') sourceController.error(reason);
if (state === 'sink-closed') await sink.close();
if (state === 'sink-errored') sinkController.error(reason);
if (state === 'pre-aborted') abort.abort(reason);
if (state === 'source-locked') reader = source.getReader();
if (state === 'sink-locked') writer = sink.getWriter();
if (state === 'invalid-sink') destination = {};
if (state === 'invalid-signal') options = {signal: {}};
if (state === 'throwing-options') options = {get preventCancel() {throw reason;}};
check(!body.bodyUsed, `${label}: initially undisturbed`);
let completion, thrown;
try {
if (method === 'pipeTo') {
completion = source.pipeTo(destination, options);
completion.catch(() => {});
for (const ownerKind of ['Response', 'Request']) {
for (const byteStream of [false, true]) {
for (const method of ['pipeTo', 'pipeThrough']) {
const cases = scenario === 'start'
? ['backpressure', 'pre-aborted', 'source-closed', 'source-errored', 'sink-closed', 'sink-errored']
: ['source-locked', 'sink-locked', 'invalid-sink', 'invalid-signal', 'throwing-options'];
for (const state of cases) {
const label = `${ownerKind}/${byteStream ? 'bytes' : 'default'}/${method}/${state}`;
const reason = new Error(label);
let sourceController, sinkController, pulls = 0, writes = 0;
const source = new ReadableStream({
...(byteStream ? {type: 'bytes'} : {}),
start(controller) { sourceController = controller; },
pull() { ++pulls; }
}, {highWaterMark: 0});
const body = ownerKind === 'Response'
? new Response(source)
: new Request('https://example.test/', {method: 'POST', body: source, duplex: 'half'});
check(body.body === source, `${label}: body observes the tested source`);
const sink = new WritableStream({
start(controller) { sinkController = controller; },
write() { ++writes; },
abort() { check(body.bodyUsed, `${label}: abort observes disturbed source`); }
}, {highWaterMark: 0});
const output = new ReadableStream({}, {highWaterMark: 0});
const outputBody = new Response(output);
const abort = new AbortController();
let options = {signal: abort.signal, preventCancel: true};
let destination = sink, reader, writer;
if (state === 'source-closed') sourceController.close();
if (state === 'source-errored') sourceController.error(reason);
if (state === 'sink-closed') await sink.close();
if (state === 'sink-errored') sinkController.error(reason);
if (state === 'pre-aborted') abort.abort(reason);
if (state === 'source-locked') reader = source.getReader();
if (state === 'sink-locked') writer = sink.getWriter();
if (state === 'invalid-sink') destination = {};
if (state === 'invalid-signal') options = {signal: {}};
if (state === 'throwing-options') options = {get preventCancel() {throw reason;}};
check(!body.bodyUsed, `${label}: initially undisturbed`);
let completion, thrown;
try {
if (method === 'pipeTo') {
completion = source.pipeTo(destination, options);
completion.catch(() => {});
} else {
const result = source.pipeThrough({readable: output, writable: destination}, options);
check(result === output, `${label}: returns output stream`);
}
} catch (error) {
thrown = error;
}
if (scenario === 'start') {
check(thrown === undefined, `${label}: accepted pipe does not throw`);
check(body.bodyUsed, `${label}: synchronously disturbed without reading`);
check(pulls === 0 && writes === 0, `${label}: no pull or write before return`);
check(!outputBody.bodyUsed, `${label}: output remains undisturbed`);
abort.abort(reason);
if (completion) await completion.catch(() => {});
for (let turn = 0; (source.locked || sink.locked) && turn < 30; ++turn) {
await new Promise(resolve => setTimeout(resolve, 0));
}
check(!source.locked && !sink.locked, `${label}: pipe releases locks`);
check(body.bodyUsed, `${label}: remains disturbed after shutdown`);
} else {
const result = source.pipeThrough({readable: output, writable: destination}, options);
check(result === output, `${label}: returns output stream`);
if (completion) {
check(thrown === undefined, `${label}: pipeTo returns a rejection`);
thrown = await completion.then(() => undefined, error => error);
}
check(state === 'throwing-options' ? thrown === reason : thrown instanceof TypeError,
`${label}: validation rejects with original error`);
reader?.releaseLock();
writer?.releaseLock();
check(!body.bodyUsed, `${label}: rejected pipe leaves source undisturbed`);
check(!source.locked && !sink.locked, `${label}: rejected pipe acquires no locks`);
check(pulls === 0 && writes === 0, `${label}: rejected pipe does not read or write`);
}
} catch (error) {
thrown = error;
// Avoid invoking the observation above during test cleanup.
await Promise.allSettled([source.cancel(), output.cancel()]);
}
if (scenario === 'start') {
check(thrown === undefined, `${label}: accepted pipe does not throw`);
check(body.bodyUsed, `${label}: synchronously disturbed without reading`);
check(pulls === 0 && writes === 0, `${label}: no pull or write before return`);
check(!outputBody.bodyUsed, `${label}: output remains undisturbed`);
abort.abort(reason);
if (completion) await completion.catch(() => {});
for (let turn = 0; (source.locked || sink.locked) && turn < 30; ++turn) {
await new Promise(resolve => setTimeout(resolve, 0));
}
check(!source.locked && !sink.locked, `${label}: pipe releases locks`);
check(body.bodyUsed, `${label}: remains disturbed after shutdown`);
} else {
if (completion) {
check(thrown === undefined, `${label}: pipeTo returns a rejection`);
thrown = await completion.then(() => undefined, error => error);
}
check(state === 'throwing-options' ? thrown === reason : thrown instanceof TypeError,
`${label}: validation rejects with original error`);
reader?.releaseLock();
writer?.releaseLock();
check(!body.bodyUsed, `${label}: rejected pipe leaves source undisturbed`);
check(!source.locked && !sink.locked, `${label}: rejected pipe acquires no locks`);
check(pulls === 0 && writes === 0, `${label}: rejected pipe does not read or write`);
}
// Avoid invoking the observation above during test cleanup.
await Promise.allSettled([source.cancel(), output.cancel()]);
}
}
}
@@ -9,32 +9,26 @@
<script>
const iframe = document.createElement('iframe');
iframe.id = 'child';
iframe.src = 'about:blank';
iframe.src = '/compat/window-child-browsing-context-target-name-a';
let child = null;
iframe.addEventListener('load', () => {
document.body.dataset.windowSame = String(child === iframe.contentWindow);
document.body.dataset.locationUpdated = String(
iframe.contentWindow?.location?.href ?? 'null'
);
document.body.dataset.documentUpdated = String(
iframe.contentWindow?.document?.body?.textContent?.trim() ?? 'null'
);
iframe.contentWindow?.postMessage('kept', '*');
});
document.body.appendChild(iframe);
const child = iframe.contentWindow;
child = iframe.contentWindow;
if (!child) {
document.body.dataset.windowSame = 'no-child';
} else {
let loadCount = 0;
child.addEventListener('message', (event) => {
document.body.dataset.listenerPreserved = String(event.data);
});
iframe.addEventListener('load', () => {
loadCount += 1;
if (loadCount === 1) {
iframe.src = '/compat/window-child-browsing-context-target-name-a';
return;
}
document.body.dataset.windowSame = String(child === iframe.contentWindow);
document.body.dataset.locationUpdated = String(
iframe.contentWindow?.location?.href ?? 'null'
);
document.body.dataset.documentUpdated = String(
iframe.contentWindow?.document?.body?.textContent?.trim() ?? 'null'
);
iframe.contentWindow?.postMessage('kept', '*');
});
}
</script>
</body>
@@ -1,9 +1,10 @@
<!doctype html>
<html>
<body>
<iframe id="child" src="about:blank"></iframe>
<script>
const iframe = document.getElementById("child");
const iframe = document.createElement("iframe");
iframe.id = "child";
iframe.src = "about:blank";
let loadCount = 0;
let initialWindow = null;
let initialDocument = null;
@@ -137,6 +138,7 @@
iframe.contentDocument.body.getAttribute("data-script-ran") ?? "null"
);
});
document.body.insertBefore(iframe, document.currentScript);
</script>
</body>
</html>
@@ -160,8 +160,9 @@
await rejection(name, container, [{publicKey, signal: controller({}).signal}], TypeErrorCtor);
});
}
if (typeof w.SharedArrayBuffer === 'function') {
for (const [index, binary] of [new w.SharedArrayBuffer(2), new Uint8Array(new w.SharedArrayBuffer(2)), new DataView(new w.SharedArrayBuffer(2))].entries()) {
{
const SharedBuffer = new w.WebAssembly.Memory({shared:true,initial:1,maximum:1}).buffer.constructor;
for (const [index, binary] of [new SharedBuffer(2), new Uint8Array(new SharedBuffer(2)), new DataView(new SharedBuffer(2))].entries()) {
await run(name + '/reject shared BufferSource/' + index, async () => {
const publicKey = name === 'create' ? validCreation() : validRequest(); publicKey.challenge = binary;
await rejection(name, container, [{publicKey, signal: controller({}).signal}], TypeErrorCtor);
+14 -2
View File
@@ -53,8 +53,20 @@
Object.defineProperty(promise, 'constructor', {get() {throw Error('must not get constructor');}});
assert(new PromiseRejectionEvent('audit', {promise}).promise === promise, 'native Promise ignores public constructor');
let thenRead = 0;
const resolved = new PromiseRejectionEvent('audit', {promise: {get then() {thenRead++; throw reason;}}}).promise;
assert(thenRead === 1 && await resolved.then(() => false, e => e === reason), 'thenable rejection');
const thenable = {get then() {thenRead++; throw reason;}};
const converted = new PromiseRejectionEvent('audit', {promise: thenable}).promise;
assert(converted instanceof Promise && thenRead === 1, 'thenable resolved once');
let rejection;try {await converted;} catch (e) {rejection=e;}
assert(rejection === reason, 'thenable rejection identity');
for (const value of [null, 7, 'promise', true]) {
const converted = new PromiseRejectionEvent('audit', {promise: value}).promise;
assert(converted instanceof Promise && await converted === value, 'primitive resolution');
}
for (const bad of [undefined]) {
let caught;
try { new PromiseRejectionEvent('audit', {promise: bad}); } catch (e) { caught = e; }
assert(caught instanceof TypeError, 'promise payload requires an object');
}
assert(new TrackEvent('audit').track === null && new SubmitEvent('audit').submitter === null, 'nullable payload defaults');
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
let caught;