Checkpoint web parity through Chromium input tasks
This commit is contained in:
34
web/tests/e2e/script-sandbox-isolation.spec.ts
Normal file
34
web/tests/e2e/script-sandbox-isolation.spec.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("M13-03D isolates crash, timeout and late sandbox results from Main", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
const result = await page.evaluate(async () => {
|
||||
const receipts = await new Promise<Record<string, any>>((resolve, reject) => {
|
||||
const worker = new Worker("/src/workers/script-sandbox-isolation-test.worker.ts", { type: "module" });
|
||||
worker.onmessage = (event: MessageEvent<Record<string, any>>) => { worker.terminate(); resolve(event.data); };
|
||||
worker.onerror = (event) => { worker.terminate(); reject(new Error(event.message)); };
|
||||
worker.postMessage({ mode: "RECEIPTS" });
|
||||
});
|
||||
const runCrash = await new Promise<boolean>((resolve, reject) => {
|
||||
const worker = new Worker("/src/workers/script-sandbox-isolation-test.worker.ts", { type: "module" });
|
||||
worker.onerror = () => { worker.terminate(); resolve(true); };
|
||||
worker.onmessage = () => { worker.terminate(); reject(new Error("crash worker published a result")); };
|
||||
worker.postMessage({ mode: "CRASH" });
|
||||
});
|
||||
const runTimeout = await new Promise<{ timedOut: boolean; lateMessages: number }>((resolve, reject) => {
|
||||
const worker = new Worker("/src/workers/script-sandbox-isolation-test.worker.ts", { type: "module" });
|
||||
let lateMessages = 0;
|
||||
worker.onmessage = () => { lateMessages += 1; };
|
||||
worker.onerror = (event) => { worker.terminate(); reject(new Error(event.message)); };
|
||||
worker.postMessage({ mode: "TIMEOUT" });
|
||||
setTimeout(() => { worker.terminate(); resolve({ timedOut: true, lateMessages }); }, 10);
|
||||
});
|
||||
return { ...receipts, runCrash, runTimeout };
|
||||
});
|
||||
expect(result.runCrash).toBe(true);
|
||||
expect(result.runTimeout).toEqual({ timedOut: true, lateMessages: 0 });
|
||||
expect(result.crash).toMatchObject({ status: "CRASHED", errorCode: "SCRIPT_SANDBOX_CRASHED", mainRevisionBefore: 9, mainRevisionAfter: 9, temporaryBytes: 0, publishedResults: 0, committed: false });
|
||||
expect(result.timeout).toMatchObject({ status: "TIMED_OUT", errorCode: "SCRIPT_SANDBOX_TIMEOUT", mainRevisionBefore: 9, mainRevisionAfter: 9, temporaryBytes: 0, publishedResults: 0, committed: false });
|
||||
expect(result.cancel).toMatchObject({ status: "CANCELLED", errorCode: "SCRIPT_SANDBOX_CANCELLED", mainRevisionBefore: 9, mainRevisionAfter: 9, temporaryBytes: 0, publishedResults: 0, committed: false });
|
||||
expect(result.lateResult).toBe("SCRIPT_SANDBOX_LATE_RESULT");
|
||||
});
|
||||
Reference in New Issue
Block a user