diff --git a/packages/core/src/htmlInCanvasDefects.test.ts b/packages/core/src/htmlInCanvasDefects.test.ts
index b7965abfdf7..5a6cca81d28 100644
--- a/packages/core/src/htmlInCanvasDefects.test.ts
+++ b/packages/core/src/htmlInCanvasDefects.test.ts
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import {
chromeMajor,
+ createDefectScan,
findCaptureDefect,
scanBackfaceDefect,
type DefectEnv,
@@ -30,6 +31,21 @@ const env = (over: Partial = {}): DefectEnv => ({
const code = (root: HTMLElement, e: DefectEnv) => findCaptureDefect(root, e)?.code ?? null;
+/** Every Chrome the render and preview browsers can be, and an unknown one. */
+const VERSIONS = [152, 155, 156, 157, 158, null] as const;
+
+/** The defect found with the page's user agent set to `major`. */
+function codeOn(major: number | null, root: HTMLElement, e: DefectEnv): string | null {
+ const spy = vi
+ .spyOn(window.navigator, "userAgent", "get")
+ .mockReturnValue(ua(major).navigator.userAgent);
+ try {
+ return code(root, e);
+ } finally {
+ spy.mockRestore();
+ }
+}
+
afterEach(() => {
document.body.innerHTML = document.head.innerHTML = "";
vi.unstubAllGlobals();
@@ -57,9 +73,8 @@ describe("nested-capture-canvas", () => {
it("is found on every version, in either API form", () => {
for (const attr of ["layoutsubtree", 'content="drawable"']) {
const root = mount(``);
- for (const major of [152, 158, null]) {
- expect(code(root, env({ win: ua(major) }))).toBe("nested-capture-canvas");
- }
+ for (const major of VERSIONS)
+ expect(codeOn(major, root, env())).toBe("nested-capture-canvas");
}
});
});
@@ -67,57 +82,174 @@ describe("nested-capture-canvas", () => {
describe("accelerated-canvas", () => {
const gl = (root: HTMLElement) => env({ isAccelerated: (c) => root.contains(c) });
- it("applies below 157 and when the version is unknown, not from 157", () => {
+ it("applies on every version, 157 and 158 included", () => {
const root = mount("");
- for (const major of [152, 155, null]) {
- expect(code(root, { ...gl(root), win: ua(major) })).toBe("accelerated-canvas");
+ for (const major of VERSIONS) {
+ expect(codeOn(major, root, gl(root))).toBe("accelerated-canvas");
+ }
+ });
+
+ it("finds a WebGL canvas outside the root, where a render's shader compositor puts it", () => {
+ const root = mount("");
+ const outside = document.createElement("canvas");
+ document.body.append(outside);
+ for (const major of VERSIONS) {
+ expect(codeOn(major, root, env({ isAccelerated: (c) => c === outside }))).toBe(
+ "accelerated-canvas",
+ );
}
- for (const major of [157, 158]) expect(code(root, { ...gl(root), win: ua(major) })).toBeNull();
});
it("ignores a canvas the page did not give a WebGL context", () => {
- expect(code(mount(""), env({ win: ua(152) }))).toBeNull();
+ expect(code(mount(""), env())).toBeNull();
});
});
describe("iframe-in-root", () => {
it("applies on every version: a reload cannot be undone", () => {
const root = mount('');
- for (const major of [152, 157, 158])
- expect(code(root, env({ win: ua(major) }))).toBe("iframe-in-root");
+ for (const major of VERSIONS) expect(codeOn(major, root, env())).toBe("iframe-in-root");
});
it("is not reported for a composition without an iframe", () => {
expect(code(mount("![]()
"), env())).toBeNull();
});
+
+ it("also covers