Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion html/canvas/resources/canvas-promise-test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 29 additions & 5 deletions html/canvas/resources/canvas-promise-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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
Expand Down
Loading