summaryrefslogtreecommitdiff
path: root/packages/webapi/test/imagedata.js
blob: 7f35eddd7a1fe0566d4baa1a0f53455d57ca14d7 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { assert, test } from '../run/test.setup.js'
import { polyfill } from '../mod.js'

test(() => {
	return [
		{
			name: 'Supports ImageData',
			test() {
				const target = {}

				polyfill(target)

				assert.equal('ImageData' in target, true)
				assert.equal(typeof target['ImageData'], 'function')
			},
		},
		{
			name: 'Supports new (data: Uint8ClampedArray, width: number, height: number): ImageData',
			test() {
				const target = {}

				polyfill(target)

				const w = 640
				const h = 480
				const d = new Uint8ClampedArray(w * h * 4)

				const id = new target.ImageData(d, w, h)

				assert.equal(id.data, d)
				assert.equal(id.width, w)
				assert.equal(id.height, h)
			},
		},
		{
			name: 'Supports new (data: Uint8ClampedArray, width: number): ImageData',
			test() {
				const target = {}

				polyfill(target)

				const w = 640
				const h = 480
				const d = new Uint8ClampedArray(w * h * 4)

				const id = new target.ImageData(d, w)

				assert.equal(id.data, d)
				assert.equal(id.width, w)
				assert.equal(id.height, h)
			},
		},
		{
			name: 'Supports new (width: number, height: number): ImageData',
			test() {
				const target = {}

				polyfill(target)

				const w = 640
				const h = 480

				const id = new target.ImageData(w, h)

				assert.equal(id.data.length, w * h * 4)
				assert.equal(id.width, w)
				assert.equal(id.height, h)
			},
		},
		{
			name: 'Supports Object.keys(new ImageData(640, 480))',
			test() {
				const target = {}

				polyfill(target)

				const keys = Object.keys(new target.ImageData(640, 480))

				assert.equal(keys.length, 1)
				assert.equal(keys[0], 'data')
			},
		},
	]
})