/
canvas-test.js
executable file
·76 lines (73 loc) · 2.58 KB
/
canvas-test.js
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
test("Canvas pixels", function () {
var canvas = document.getElementById('qunit-canvas'), context;
try {
context = canvas.getContext('2d');
} catch(e) {
// propably no canvas support, just exit
return;
}
context.fillStyle = 'rgba(0, 0, 0, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 0)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 255, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 255, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 0, 0, 0, 0, 255, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 0, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 255, 0, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 0, 255, 0, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 0.5)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 2, 2, 0, 0, 255, 127);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 0, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 0, 0, 0, 255);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(255, 0, 0, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 255, 0, 0, 255);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 255, 0, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 0, 255, 0, 255);
context.clearRect(0,0,5,5);
context.fillStyle = 'rgba(0, 0, 255, 1)';
context.fillRect(0, 0, 5, 5);
QUnit.pixelEqual(canvas, 4, 4, 0, 0, 255, 255);
context.clearRect(0,0,5,5);
});