Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / drawImage-with-valid-image.html
blobb05a49630f33dc6ef06e600a463da379f5cdf762
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <script>
7 window.jsTestIsAsync = true;
8 description("This test checks behavior of valid arguments to Canvas::drawImage that use a valid source image.");
10 function ExpectedNotEnoughArgumentsMessage(num) {
11 return "\"TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': 3 arguments required, but only " + num + " present.\"";
13 var IndexSizeError = "IndexSizeError: Index or size was negative, or greater than the allowed value.";
15 // Create image
16 var myImage = new Image();
17 var img_src = 'resources/apple.gif';
18 myImage.src = img_src;
19 myImage.onload = draw;
21 var bitmap;
22 var ctx = document.createElement("canvas").getContext('2d');
23 function draw() {
24 // No arguments should get exception
25 shouldThrow("ctx.drawImage()", ExpectedNotEnoughArgumentsMessage(0));
27 // image argument only should get exception
28 shouldThrow("ctx.drawImage(myImage)", ExpectedNotEnoughArgumentsMessage(1));
30 // image argument plus one number should get exception
31 shouldThrow("ctx.drawImage(myImage, 0)", ExpectedNotEnoughArgumentsMessage(2));
33 // image argument plus 2 numbers
34 shouldNotThrow("ctx.drawImage(myImage, 0, 0)");
36 // image argument plus 4 numbers
37 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20)");
39 // image argument plus 8 numbers
40 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 20, 20)");
42 // image argument plus zero size
43 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 0, 0)");
45 // image argument plus 8 numbers, zero size
46 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 0, 0)");
48 // imageRect does not contain sourceRect on the left side
49 shouldNotThrow("ctx.drawImage(myImage, -10, 0, 52, 64, 0, 0, 20, 20)");
51 // imageRect does not contain sourceRect on the right side
52 shouldNotThrow("ctx.drawImage(myImage, 10, 0, 52, 64, 0, 0, 20, 20)");
54 // imageRect does not contain sourceRect on top
55 shouldNotThrow("ctx.drawImage(myImage, 0, -10, 52, 64, 0, 0, 20, 20)");
57 // imageRect does not contain sourceRect on bottom
58 shouldNotThrow("ctx.drawImage(myImage, 0, 10, 52, 64, 0, 0, 20, 20)");
60 // sourceRect is bigger than imageSource on every side
61 shouldNotThrow("ctx.drawImage(myImage, -10, -10, 72, 84, 0, 0, 20, 20)");
63 // negative size of source, imageRect does not contain sourceRect on the left side
64 shouldNotThrow("ctx.drawImage(myImage, 42, 64, -52, -64, 0, 0, 20, 20)");
66 // negative size of source, imageRect does not contain sourceRect on the right side
67 shouldNotThrow("ctx.drawImage(myImage, 62, 64, -52, -64, 0, 0, 20, 20)");
69 // negative size of source, imageRect does not contain sourceRect on top
70 shouldNotThrow("ctx.drawImage(myImage, 52, 54, -52, -64, 0, 0, 20, 20)");
72 // negative size of source, imageRect does not contain sourceRect on bottom
73 shouldNotThrow("ctx.drawImage(myImage, 52, 74, -52, -64, 0, 0, 20, 20)");
75 // negative size of source, imageRect does not contain sourceRect on every side
76 shouldNotThrow("ctx.drawImage(myImage, 62, 74, -72, -84, 0, 0, 20, 20)");
78 // images with no src can be drawn
79 shouldNotThrow("ctx.drawImage(new Image(), 0, 0)");
80 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 20, 20)");
81 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 20, 20, 0, 0, 20, 20)");
83 // images with no src exit early before IndexSizeError is thrown
84 shouldNotThrow("ctx.drawImage(new Image(), 0, 0)");
85 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 0, 20)");
86 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 0, 20, 0, 0, 20, 20)");
88 createImageBitmap(myImage).then(drawBitmap, function() {
89 testFailed("Promise was rejected.");
90 finishJSTest();
91 });
94 function drawBitmap(imageBitmap) {
95 bitmap = imageBitmap;
97 // bitmap argument plus 2 numbers
98 shouldNotThrow("ctx.drawImage(bitmap, 0, 0)");
100 // bitmap argument plus 4 numbers
101 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20)");
103 // bitmap argument plus 8 numbers
104 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 20, 20)");
106 // bitmap argument plus zero size
107 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 0, 0)");
109 // bitmap argument plus 8 numbers, zero size
110 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 0, 0)");
112 // bitmap argument plus 8 numbers, negative size of source, zero size
113 shouldNotThrow("ctx.drawImage(bitmap, 20, 20, -20, 0, 0, 0, 20, 20)");
115 // bitmap argument plus 8 numbers, negative size of destination, zero size
116 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 0, 20, 20, -20, -20)");
118 // bitmap argument plus 8 numbers, negative size of source and destination, zero size
119 shouldNotThrow("ctx.drawImage(bitmap, 20, 20, -20, 0, 20, 20, -20, -20)");
121 // imageRect does not contain sourceRect on the left side
122 shouldNotThrow("ctx.drawImage(bitmap, -10, 0, 52, 64, 0, 0, 20, 20)");
124 // imageRect does not contain sourceRect on the right side
125 shouldNotThrow("ctx.drawImage(bitmap, 10, 0, 52, 64, 0, 0, 20, 20)");
127 // imageRect does not contain sourceRect on top
128 shouldNotThrow("ctx.drawImage(bitmap, 0, -10, 52, 64, 0, 0, 20, 20)");
130 // imageRect does not contain sourceRect on bottom
131 shouldNotThrow("ctx.drawImage(bitmap, 0, 10, 52, 64, 0, 0, 20, 20)");
133 // sourceRect is bigger than imageSource on every side
134 shouldNotThrow("ctx.drawImage(bitmap, -10, -10, 72, 84, 0, 0, 20, 20)");
136 // negative size of source, imageRect does not contain sourceRect on the left side
137 shouldNotThrow("ctx.drawImage(bitmap, 42, 64, -52, -64, 0, 0, 20, 20)");
139 // negative size of source, imageRect does not contain sourceRect on the right side
140 shouldNotThrow("ctx.drawImage(bitmap, 62, 64, -52, -64, 0, 0, 20, 20)");
142 // negative size of source, imageRect does not contain sourceRect on top
143 shouldNotThrow("ctx.drawImage(bitmap, 52, 54, -52, -64, 0, 0, 20, 20)");
145 // negative size of source, imageRect does not contain sourceRect on bottom
146 shouldNotThrow("ctx.drawImage(bitmap, 52, 74, -52, -64, 0, 0, 20, 20)");
148 // negative size of source, imageRect does not contain sourceRect on every side
149 shouldNotThrow("ctx.drawImage(bitmap, 62, 74, -72, -84, 0, 0, 20, 20)");
151 finishJSTest();
153 </script>
154 </body>
155 </html>