Allow users to pass canvas: undefined

PiperOrigin-RevId: 520142520
This commit is contained in:
Sebastian Schmidt 2023-03-28 14:54:16 -07:00 committed by Copybara-Service
parent bda2639376
commit 62d86494b0
3 changed files with 20 additions and 2 deletions

View File

@ -118,9 +118,10 @@ describe('TaskRunner', () => {
let fetchSpy: jasmine.Spy;
let taskRunner: TaskRunnerFake;
let fetchStatus = 200;
let fetchStatus: number;
beforeEach(() => {
fetchStatus = 200;
fetchSpy = jasmine.createSpy().and.callFake(async url => {
return {
arrayBuffer: () => mockBytes.buffer,

View File

@ -185,6 +185,23 @@ describe('VisionTaskRunner', () => {
}).toThrowError(/You must create a new task to reset the canvas./);
});
it('validates that an undefined canvas leaves the graph unmodified',
async () => {
if (typeof OffscreenCanvas === 'undefined') {
console.log('Test is not supported under Node.');
return;
}
const visionTaskRunner = new VisionTaskRunnerFake();
const canvas = new OffscreenCanvas(1, 1);
visionTaskRunner.graphRunner.wasmModule.canvas = canvas;
await visionTaskRunner.setOptions({canvas});
await visionTaskRunner.setOptions({canvas: undefined});
expect(visionTaskRunner.graphRunner.wasmModule.canvas).toBe(canvas);
});
it('sends packets to graph', async () => {
const visionTaskRunner = new VisionTaskRunnerFake();
await visionTaskRunner.setOptions({runningMode: 'VIDEO'});

View File

@ -89,7 +89,7 @@ export abstract class VisionTaskRunner extends TaskRunner {
this.baseOptions.setUseStreamMode(useStreamMode);
}
if ('canvas' in options) {
if (options.canvas !== undefined) {
if (this.graphRunner.wasmModule.canvas !== options.canvas) {
throw new Error('You must create a new task to reset the canvas.');
}