summaryrefslogtreecommitdiff
path: root/packages/webapi/test/offscreencanvas.js
blob: 6223e78e87d455be26a72fcb27451a445b28dafc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { expect } from 'chai'
import { polyfill } from '../mod.js'

describe('OffscreenCanvas', () => {
	const target = {}

	before(() => polyfill(target))

	it('Supports OffscreenCanvas', () => {
		expect(target).to.have.property('OffscreenCanvas').that.is.a('function')
	})

	it('Supports new (width: number, height: number): OffscreenCanvas', () => {
		const w = 640
		const h = 480

		const canvas = new target.OffscreenCanvas(w, h)

		expect(canvas.width).to.equal(w)
		expect(canvas.height).to.equal(h)
	})

	it('Supports OffscreenCanvas#getContext', () => {
		const w = 640
		const h = 480

		const canvas = new target.OffscreenCanvas(w, h)

		const context = canvas.getContext('2d')

		expect(context.canvas).to.equal(canvas)

		const imageData = context.createImageData(w, h)

		expect(imageData.width).to.equal(w)
		expect(imageData.height).to.equal(h)
		expect(imageData.data).to.have.lengthOf(w * h * 4)
	})
})