2022-04-10 20:29:46 -05:00
|
|
|
import { expect } from 'chai'
|
2022-03-07 16:36:22 -05:00
|
|
|
import { polyfill } from '../mod.js'
|
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
describe('OffscreenCanvas', () => {
|
|
|
|
const target = {}
|
2022-03-07 16:37:50 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
before(() => polyfill(target))
|
2022-03-07 16:37:50 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
it('Supports OffscreenCanvas', () => {
|
|
|
|
expect(target).to.have.property('OffscreenCanvas').that.is.a('function')
|
|
|
|
})
|
2022-03-07 16:37:50 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
it('Supports new (width: number, height: number): OffscreenCanvas', () => {
|
|
|
|
const w = 640
|
|
|
|
const h = 480
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
const canvas = new target.OffscreenCanvas(w, h)
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
expect(canvas.width).to.equal(w)
|
|
|
|
expect(canvas.height).to.equal(h)
|
|
|
|
})
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
it('Supports OffscreenCanvas#getContext', () => {
|
|
|
|
const w = 640
|
|
|
|
const h = 480
|
2022-03-07 16:37:50 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
const canvas = new target.OffscreenCanvas(w, h)
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
const context = canvas.getContext('2d')
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
expect(context.canvas).to.equal(canvas)
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
const imageData = context.createImageData(w, h)
|
2022-03-07 16:36:22 -05:00
|
|
|
|
2022-04-10 20:29:46 -05:00
|
|
|
expect(imageData.width).to.equal(w)
|
|
|
|
expect(imageData.height).to.equal(h)
|
|
|
|
expect(imageData.data).to.have.lengthOf(w * h * 4)
|
|
|
|
})
|
2022-03-07 16:36:22 -05:00
|
|
|
})
|