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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<script>
window.jsTestIsAsync = true;
description("This test checks behavior of valid arguments to Canvas::drawImage that use a valid source image.");
function ExpectedNotEnoughArgumentsMessage(num) {
return "\"TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': 3 arguments required, but only " + num + " present.\"";
}
var IndexSizeError = "IndexSizeError: Index or size was negative, or greater than the allowed value.";
// Create image
var myImage = new Image();
var img_src = 'resources/apple.gif';
myImage.src = img_src;
myImage.onload = draw;
var bitmap;
var ctx = document.createElement("canvas").getContext('2d');
function draw() {
// No arguments should get exception
shouldThrow("ctx.drawImage()", ExpectedNotEnoughArgumentsMessage(0));
// image argument only should get exception
shouldThrow("ctx.drawImage(myImage)", ExpectedNotEnoughArgumentsMessage(1));
// image argument plus one number should get exception
shouldThrow("ctx.drawImage(myImage, 0)", ExpectedNotEnoughArgumentsMessage(2));
// image argument plus 2 numbers
shouldNotThrow("ctx.drawImage(myImage, 0, 0)");
// image argument plus 4 numbers
shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20)");
// image argument plus 8 numbers
shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 20, 20)");
// image argument plus zero size
shouldNotThrow("ctx.drawImage(myImage, 0, 0, 0, 0)");
// image argument plus 8 numbers, zero size
shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 0, 0)");
// imageRect does not contain sourceRect on the left side
shouldNotThrow("ctx.drawImage(myImage, -10, 0, 52, 64, 0, 0, 20, 20)");
// imageRect does not contain sourceRect on the right side
shouldNotThrow("ctx.drawImage(myImage, 10, 0, 52, 64, 0, 0, 20, 20)");
// imageRect does not contain sourceRect on top
shouldNotThrow("ctx.drawImage(myImage, 0, -10, 52, 64, 0, 0, 20, 20)");
// imageRect does not contain sourceRect on bottom
shouldNotThrow("ctx.drawImage(myImage, 0, 10, 52, 64, 0, 0, 20, 20)");
// sourceRect is bigger than imageSource on every side
shouldNotThrow("ctx.drawImage(myImage, -10, -10, 72, 84, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on the left side
shouldNotThrow("ctx.drawImage(myImage, 42, 64, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on the right side
shouldNotThrow("ctx.drawImage(myImage, 62, 64, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on top
shouldNotThrow("ctx.drawImage(myImage, 52, 54, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on bottom
shouldNotThrow("ctx.drawImage(myImage, 52, 74, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on every side
shouldNotThrow("ctx.drawImage(myImage, 62, 74, -72, -84, 0, 0, 20, 20)");
// images with no src can be drawn
shouldNotThrow("ctx.drawImage(new Image(), 0, 0)");
shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 20, 20)");
shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 20, 20, 0, 0, 20, 20)");
// images with no src exit early before IndexSizeError is thrown
shouldNotThrow("ctx.drawImage(new Image(), 0, 0)");
shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 0, 20)");
shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 0, 20, 0, 0, 20, 20)");
createImageBitmap(myImage).then(drawBitmap, function() {
testFailed("Promise was rejected.");
finishJSTest();
});
}
function drawBitmap(imageBitmap) {
bitmap = imageBitmap;
// bitmap argument plus 2 numbers
shouldNotThrow("ctx.drawImage(bitmap, 0, 0)");
// bitmap argument plus 4 numbers
shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20)");
// bitmap argument plus 8 numbers
shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 20, 20)");
// bitmap argument plus zero size
shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 0, 0)");
// bitmap argument plus 8 numbers, zero size
shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 0, 0)");
// bitmap argument plus 8 numbers, negative size of source, zero size
shouldNotThrow("ctx.drawImage(bitmap, 20, 20, -20, 0, 0, 0, 20, 20)");
// bitmap argument plus 8 numbers, negative size of destination, zero size
shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 0, 20, 20, -20, -20)");
// bitmap argument plus 8 numbers, negative size of source and destination, zero size
shouldNotThrow("ctx.drawImage(bitmap, 20, 20, -20, 0, 20, 20, -20, -20)");
// imageRect does not contain sourceRect on the left side
shouldNotThrow("ctx.drawImage(bitmap, -10, 0, 52, 64, 0, 0, 20, 20)");
// imageRect does not contain sourceRect on the right side
shouldNotThrow("ctx.drawImage(bitmap, 10, 0, 52, 64, 0, 0, 20, 20)");
// imageRect does not contain sourceRect on top
shouldNotThrow("ctx.drawImage(bitmap, 0, -10, 52, 64, 0, 0, 20, 20)");
// imageRect does not contain sourceRect on bottom
shouldNotThrow("ctx.drawImage(bitmap, 0, 10, 52, 64, 0, 0, 20, 20)");
// sourceRect is bigger than imageSource on every side
shouldNotThrow("ctx.drawImage(bitmap, -10, -10, 72, 84, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on the left side
shouldNotThrow("ctx.drawImage(bitmap, 42, 64, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on the right side
shouldNotThrow("ctx.drawImage(bitmap, 62, 64, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on top
shouldNotThrow("ctx.drawImage(bitmap, 52, 54, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on bottom
shouldNotThrow("ctx.drawImage(bitmap, 52, 74, -52, -64, 0, 0, 20, 20)");
// negative size of source, imageRect does not contain sourceRect on every side
shouldNotThrow("ctx.drawImage(bitmap, 62, 74, -72, -84, 0, 0, 20, 20)");
finishJSTest();
}
</script>
</body>
</html>
|