From 6943f68dbb6f98e2980e0f9416a2829776c60dcc Mon Sep 17 00:00:00 2001 From: Jean-Philippe Gravel Date: Sun, 19 Apr 2026 15:51:56 -0700 Subject: [PATCH] Split 2d-invalid-size-context-lost.html into test variants With this change, each canvas types (HTMLCanvasElement, OffscreenCanvas, offscreen + placeholder, etc.) run into different test instances. This makes each of these instances run faster (potentially avoiding timeouts). This will also be useful in a follow-up CL (https://crrev.com/c/7770807), where tests will be added to validate GPU process loss. Tests are normally running one after the other, so an individual test can kill and restore the GPU process without impacting the others. But this is not true for worker tests because workers run in a parallel thread. Killing the GPU process in the main thread would break the test running in the worker. The solution to this is to run the workers in a different variant, which will either run with a different test runner, or before/after other variants. Change-Id: I95ec34c070d0908e687b5d7c8d207c2e012f585e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7770727 Commit-Queue: Jean-Philippe Gravel Reviewed-by: Vasiliy Telezhnikov Cr-Commit-Position: refs/heads/main@{#1617255} --- .../resources/canvas-promise-test-worker.js | 3 +- html/canvas/resources/canvas-promise-test.js | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/html/canvas/resources/canvas-promise-test-worker.js b/html/canvas/resources/canvas-promise-test-worker.js index 2cb50c322f7978..53091cb5141f8a 100644 --- a/html/canvas/resources/canvas-promise-test-worker.js +++ b/html/canvas/resources/canvas-promise-test-worker.js @@ -8,7 +8,8 @@ function canvasPromiseTest( testBody, description, {testTypes = Object.values(CanvasTestType)} = {}) { - if (testTypes.includes(CanvasTestType.WORKER)) { + if (testTypes.includes(CanvasTestType.WORKER) && + isTestTypeEnabled(CanvasTestType.WORKER)) { promise_test(() => testBody(new OffscreenCanvas(300, 150), {canvasType: CanvasTestType.WORKER}), 'Worker: ' + description); diff --git a/html/canvas/resources/canvas-promise-test.js b/html/canvas/resources/canvas-promise-test.js index 63aaa11f563693..4e45a7d5993186 100644 --- a/html/canvas/resources/canvas-promise-test.js +++ b/html/canvas/resources/canvas-promise-test.js @@ -51,6 +51,21 @@ WORKER_CANVAS_TEST_TYPES = [ CanvasTestType.WORKER, ]; +var enabledTestTypeVariant = null; +setup(() => { + const urlParams = new URLSearchParams(self.location.search); + const testTypeVariant = urlParams.get('testType'); + if (testTypeVariant) { + enabledTestTypeVariant = CanvasTestType[testTypeVariant.toUpperCase()]; + assert_true(!!enabledTestTypeVariant, + `Unrecognized test type variant: ${testTypeVariant}`); + } +}); + +function isTestTypeEnabled(testType) { + return enabledTestTypeVariant === null || enabledTestTypeVariant === testType; +} + /** * Run `testBody` in a `promise_test` against multiple types of canvases. By * default, the test is executed against an HTMLCanvasElement, a main thread @@ -66,7 +81,8 @@ WORKER_CANVAS_TEST_TYPES = [ function canvasPromiseTest( testBody, description, {testTypes = DEFAULT_CANVAS_TEST_TYPES} = {}) { - if (testTypes.includes(CanvasTestType.WORKER)) { + if (testTypes.includes(CanvasTestType.WORKER) && + isTestTypeEnabled(CanvasTestType.WORKER)) { setup(() => { const currentScript = document.currentScript; assert_true( @@ -79,7 +95,8 @@ function canvasPromiseTest( }); } - if (testTypes.includes(CanvasTestType.HTML)) { + if (testTypes.includes(CanvasTestType.HTML) && + isTestTypeEnabled(CanvasTestType.HTML)) { promise_test(async () => { if (!document.body) { document.documentElement.appendChild(document.createElement("body")); @@ -91,19 +108,22 @@ function canvasPromiseTest( }, 'HTMLCanvasElement: ' + description); } - if (testTypes.includes(CanvasTestType.DETACHED_HTML)) { + if (testTypes.includes(CanvasTestType.DETACHED_HTML) && + isTestTypeEnabled(CanvasTestType.DETACHED_HTML)) { promise_test(() => testBody(document.createElement('canvas'), {canvasType: CanvasTestType.DETACHED_HTML}), 'Detached HTMLCanvasElement: ' + description); } - if (testTypes.includes(CanvasTestType.OFFSCREEN)) { + if (testTypes.includes(CanvasTestType.OFFSCREEN) && + isTestTypeEnabled(CanvasTestType.OFFSCREEN)) { promise_test(() => testBody(new OffscreenCanvas(300, 150), {canvasType: CanvasTestType.OFFSCREEN}), 'OffscreenCanvas: ' + description); } - if (testTypes.includes(CanvasTestType.PLACEHOLDER)) { + if (testTypes.includes(CanvasTestType.PLACEHOLDER) && + isTestTypeEnabled(CanvasTestType.PLACEHOLDER)) { promise_test(async () => { if (!document.body) { document.documentElement.appendChild(document.createElement("body")); @@ -122,6 +142,10 @@ function canvasPromiseTest( * via the `dependencies` parameter so that the worker could load them. */ function runCanvasTestsInWorker({dependencies = []} = {}) { + if (!isTestTypeEnabled(CanvasTestType.WORKER)) { + return; + } + const currentScript = document.currentScript; // Keep track of whether runCanvasTestsInWorker was invoked on the current // script. `canvasPromiseTest` will fail if `runCanvasTestsInWorker` hasn't