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