| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <head> | 3 |
| 4 <script src="../../resources/js-test.js"></script> | |
| 5 </head> | |
| 6 <script> | 4 <script> |
| 7 window.jsTestIsAsync = true; | |
| 8 description("This test checks behavior of valid arguments to Canvas::drawIma
ge that use a valid source image."); | |
| 9 | 5 |
| 10 function ExpectedNotEnoughArgumentsMessage(num) { | 6 function ExpectedNotEnoughArgumentsMessage(num) { |
| 11 return "\"TypeError: Failed to execute 'drawImage' on 'CanvasRenderingCo
ntext2D': 3 arguments required, but only " + num + " present.\""; | 7 return "\"TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContex
t2D': 3 arguments required, but only " + num + " present.\""; |
| 12 } | 8 } |
| 13 var IndexSizeError = "IndexSizeError: Index or size was negative, or greater
than the allowed value."; | |
| 14 | 9 |
| 15 // Create image | 10 var IndexSizeError = "IndexSizeError: Index or size was negative, or greater tha
n the allowed value."; |
| 16 var myImage = new Image(); | |
| 17 var img_src = 'resources/apple.gif'; | |
| 18 myImage.src = img_src; | |
| 19 myImage.onload = draw; | |
| 20 | 11 |
| 21 var bitmap; | 12 // Create image |
| 22 var ctx = document.createElement("canvas").getContext('2d'); | 13 var myImage = new Image(); |
| 23 function draw() { | 14 var img_src = 'resources/apple.gif'; |
| 24 // No arguments should get exception | 15 myImage.src = img_src; |
| 25 shouldThrow("ctx.drawImage()", ExpectedNotEnoughArgumentsMessage(0)); | |
| 26 | 16 |
| 27 // image argument only should get exception | 17 var bitmap; |
| 28 shouldThrow("ctx.drawImage(myImage)", ExpectedNotEnoughArgumentsMessage(
1)); | 18 var ctx = document.createElement("canvas").getContext('2d'); |
| 29 | 19 |
| 30 // image argument plus one number should get exception | 20 function draw() { |
| 31 shouldThrow("ctx.drawImage(myImage, 0)", ExpectedNotEnoughArgumentsMessa
ge(2)); | 21 // No arguments should get exception |
| 22 assert_throws(null, function() {ctx.drawImage();}, ExpectedNotEnoughArgument
sMessage(0)); |
| 32 | 23 |
| 33 // image argument plus 2 numbers | 24 // image argument only should get exception |
| 34 shouldNotThrow("ctx.drawImage(myImage, 0, 0)"); | 25 assert_throws(null, function() {ctx.drawImage(myImage);}, ExpectedNotEnoughA
rgumentsMessage(1)); |
| 35 | 26 |
| 36 // image argument plus 4 numbers | 27 // image argument plus one number should get exception |
| 37 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20)"); | 28 assert_throws(null, function() {ctx.drawImage(myImage, 0);}, ExpectedNotEnou
ghArgumentsMessage(2)); |
| 38 | 29 |
| 39 // image argument plus 8 numbers | 30 // image argument plus 2 numbers |
| 40 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 20, 20)"); | 31 ctx.drawImage(myImage, 0, 0); |
| 41 | 32 |
| 42 // image argument plus zero size | 33 // image argument plus 4 numbers |
| 43 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 0, 0)"); | 34 ctx.drawImage(myImage, 0, 0, 20, 20); |
| 44 | 35 |
| 45 // image argument plus 8 numbers, zero size | 36 // image argument plus 8 numbers |
| 46 shouldNotThrow("ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 0, 0)"); | 37 ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 20, 20); |
| 47 | 38 |
| 48 // imageRect does not contain sourceRect on the left side | 39 // image argument plus zero size |
| 49 shouldNotThrow("ctx.drawImage(myImage, -10, 0, 52, 64, 0, 0, 20, 20)"); | 40 ctx.drawImage(myImage, 0, 0, 0, 0); |
| 50 | 41 |
| 51 // imageRect does not contain sourceRect on the right side | 42 // image argument plus 8 numbers, zero size |
| 52 shouldNotThrow("ctx.drawImage(myImage, 10, 0, 52, 64, 0, 0, 20, 20)"); | 43 ctx.drawImage(myImage, 0, 0, 20, 20, 0, 0, 0, 0); |
| 53 | 44 |
| 54 // imageRect does not contain sourceRect on top | 45 // imageRect does not contain sourceRect on the left side |
| 55 shouldNotThrow("ctx.drawImage(myImage, 0, -10, 52, 64, 0, 0, 20, 20)"); | 46 ctx.drawImage(myImage, -10, 0, 52, 64, 0, 0, 20, 20); |
| 56 | 47 |
| 57 // imageRect does not contain sourceRect on bottom | 48 // imageRect does not contain sourceRect on the right side |
| 58 shouldNotThrow("ctx.drawImage(myImage, 0, 10, 52, 64, 0, 0, 20, 20)"); | 49 ctx.drawImage(myImage, 10, 0, 52, 64, 0, 0, 20, 20); |
| 59 | 50 |
| 60 // sourceRect is bigger than imageSource on every side | 51 // imageRect does not contain sourceRect on top |
| 61 shouldNotThrow("ctx.drawImage(myImage, -10, -10, 72, 84, 0, 0, 20, 20)")
; | 52 ctx.drawImage(myImage, 0, -10, 52, 64, 0, 0, 20, 20); |
| 62 | 53 |
| 63 // negative size of source, imageRect does not contain sourceRect on the
left side | 54 // imageRect does not contain sourceRect on bottom |
| 64 shouldNotThrow("ctx.drawImage(myImage, 42, 64, -52, -64, 0, 0, 20, 20)")
; | 55 ctx.drawImage(myImage, 0, 10, 52, 64, 0, 0, 20, 20); |
| 65 | 56 |
| 66 // negative size of source, imageRect does not contain sourceRect on the
right side | 57 // sourceRect is bigger than imageSource on every side |
| 67 shouldNotThrow("ctx.drawImage(myImage, 62, 64, -52, -64, 0, 0, 20, 20)")
; | 58 ctx.drawImage(myImage, -10, -10, 72, 84, 0, 0, 20, 20); |
| 68 | 59 |
| 69 // negative size of source, imageRect does not contain sourceRect on top | 60 // negative size of source, imageRect does not contain sourceRect on the lef
t side |
| 70 shouldNotThrow("ctx.drawImage(myImage, 52, 54, -52, -64, 0, 0, 20, 20)")
; | 61 ctx.drawImage(myImage, 42, 64, -52, -64, 0, 0, 20, 20); |
| 71 | 62 |
| 72 // negative size of source, imageRect does not contain sourceRect on bot
tom | 63 // negative size of source, imageRect does not contain sourceRect on the rig
ht side |
| 73 shouldNotThrow("ctx.drawImage(myImage, 52, 74, -52, -64, 0, 0, 20, 20)")
; | 64 ctx.drawImage(myImage, 62, 64, -52, -64, 0, 0, 20, 20); |
| 74 | 65 |
| 75 // negative size of source, imageRect does not contain sourceRect on eve
ry side | 66 // negative size of source, imageRect does not contain sourceRect on top |
| 76 shouldNotThrow("ctx.drawImage(myImage, 62, 74, -72, -84, 0, 0, 20, 20)")
; | 67 ctx.drawImage(myImage, 52, 54, -52, -64, 0, 0, 20, 20); |
| 77 | 68 |
| 78 // images with no src can be drawn | 69 // negative size of source, imageRect does not contain sourceRect on bottom |
| 79 shouldNotThrow("ctx.drawImage(new Image(), 0, 0)"); | 70 ctx.drawImage(myImage, 52, 74, -52, -64, 0, 0, 20, 20); |
| 80 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 20, 20)"); | |
| 81 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 20, 20, 0, 0, 20, 20)")
; | |
| 82 | 71 |
| 83 // images with no src exit early before IndexSizeError is thrown | 72 // negative size of source, imageRect does not contain sourceRect on every s
ide |
| 84 shouldNotThrow("ctx.drawImage(new Image(), 0, 0)"); | 73 ctx.drawImage(myImage, 62, 74, -72, -84, 0, 0, 20, 20); |
| 85 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 0, 20)"); | |
| 86 shouldNotThrow("ctx.drawImage(new Image(), 0, 0, 0, 20, 0, 0, 20, 20)"); | |
| 87 | 74 |
| 88 createImageBitmap(myImage).then(drawBitmap, function() { | 75 // images with no src can be drawn |
| 89 testFailed("Promise was rejected."); | 76 ctx.drawImage(new Image(), 0, 0); |
| 90 finishJSTest(); | 77 ctx.drawImage(new Image(), 0, 0, 20, 20); |
| 91 }); | 78 ctx.drawImage(new Image(), 0, 0, 20, 20, 0, 0, 20, 20); |
| 92 } | |
| 93 | 79 |
| 94 function drawBitmap(imageBitmap) { | 80 // images with no src exit early before IndexSizeError is thrown |
| 95 bitmap = imageBitmap; | 81 ctx.drawImage(new Image(), 0, 0); |
| 82 ctx.drawImage(new Image(), 0, 0, 0, 20); |
| 83 ctx.drawImage(new Image(), 0, 0, 0, 20, 0, 0, 20, 20); |
| 84 } |
| 96 | 85 |
| 97 // bitmap argument plus 2 numbers | 86 function drawBitmap(imageBitmap) { |
| 98 shouldNotThrow("ctx.drawImage(bitmap, 0, 0)"); | 87 bitmap = imageBitmap; |
| 99 | 88 |
| 100 // bitmap argument plus 4 numbers | 89 // bitmap argument plus 2 numbers |
| 101 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20)"); | 90 ctx.drawImage(bitmap, 0, 0); |
| 102 | 91 |
| 103 // bitmap argument plus 8 numbers | 92 // bitmap argument plus 4 numbers |
| 104 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 20, 20)"); | 93 ctx.drawImage(bitmap, 0, 0, 20, 20); |
| 105 | 94 |
| 106 // bitmap argument plus zero size | 95 // bitmap argument plus 8 numbers |
| 107 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 0, 0)"); | 96 ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 20, 20); |
| 108 | 97 |
| 109 // bitmap argument plus 8 numbers, zero size | 98 // bitmap argument plus zero size |
| 110 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 0, 0)"); | 99 ctx.drawImage(bitmap, 0, 0, 0, 0); |
| 111 | 100 |
| 112 // bitmap argument plus 8 numbers, negative size of source, zero size | 101 // bitmap argument plus 8 numbers, zero size |
| 113 shouldNotThrow("ctx.drawImage(bitmap, 20, 20, -20, 0, 0, 0, 20, 20)"); | 102 ctx.drawImage(bitmap, 0, 0, 20, 20, 0, 0, 0, 0); |
| 114 | 103 |
| 115 // bitmap argument plus 8 numbers, negative size of destination, zero si
ze | 104 // bitmap argument plus 8 numbers, negative size of source, zero size |
| 116 shouldNotThrow("ctx.drawImage(bitmap, 0, 0, 20, 0, 20, 20, -20, -20)"); | 105 ctx.drawImage(bitmap, 20, 20, -20, 0, 0, 0, 20, 20); |
| 117 | 106 |
| 118 // bitmap argument plus 8 numbers, negative size of source and destinati
on, zero size | 107 // bitmap argument plus 8 numbers, negative size of destination, zero size |
| 119 shouldNotThrow("ctx.drawImage(bitmap, 20, 20, -20, 0, 20, 20, -20, -20)"
); | 108 ctx.drawImage(bitmap, 0, 0, 20, 0, 20, 20, -20, -20); |
| 120 | 109 |
| 121 // imageRect does not contain sourceRect on the left side | 110 // bitmap argument plus 8 numbers, negative size of source and destination,
zero size |
| 122 shouldNotThrow("ctx.drawImage(bitmap, -10, 0, 52, 64, 0, 0, 20, 20)"); | 111 ctx.drawImage(bitmap, 20, 20, -20, 0, 20, 20, -20, -20); |
| 123 | 112 |
| 124 // imageRect does not contain sourceRect on the right side | 113 // imageRect does not contain sourceRect on the left side |
| 125 shouldNotThrow("ctx.drawImage(bitmap, 10, 0, 52, 64, 0, 0, 20, 20)"); | 114 ctx.drawImage(bitmap, -10, 0, 52, 64, 0, 0, 20, 20); |
| 126 | 115 |
| 127 // imageRect does not contain sourceRect on top | 116 // imageRect does not contain sourceRect on the right side |
| 128 shouldNotThrow("ctx.drawImage(bitmap, 0, -10, 52, 64, 0, 0, 20, 20)"); | 117 ctx.drawImage(bitmap, 10, 0, 52, 64, 0, 0, 20, 20); |
| 129 | 118 |
| 130 // imageRect does not contain sourceRect on bottom | 119 // imageRect does not contain sourceRect on top |
| 131 shouldNotThrow("ctx.drawImage(bitmap, 0, 10, 52, 64, 0, 0, 20, 20)"); | 120 ctx.drawImage(bitmap, 0, -10, 52, 64, 0, 0, 20, 20); |
| 132 | 121 |
| 133 // sourceRect is bigger than imageSource on every side | 122 // imageRect does not contain sourceRect on bottom |
| 134 shouldNotThrow("ctx.drawImage(bitmap, -10, -10, 72, 84, 0, 0, 20, 20)"); | 123 ctx.drawImage(bitmap, 0, 10, 52, 64, 0, 0, 20, 20); |
| 135 | 124 |
| 136 // negative size of source, imageRect does not contain sourceRect on the
left side | 125 // sourceRect is bigger than imageSource on every side |
| 137 shouldNotThrow("ctx.drawImage(bitmap, 42, 64, -52, -64, 0, 0, 20, 20)"); | 126 ctx.drawImage(bitmap, -10, -10, 72, 84, 0, 0, 20, 20); |
| 138 | 127 |
| 139 // negative size of source, imageRect does not contain sourceRect on the
right side | 128 // negative size of source, imageRect does not contain sourceRect on the lef
t side |
| 140 shouldNotThrow("ctx.drawImage(bitmap, 62, 64, -52, -64, 0, 0, 20, 20)"); | 129 ctx.drawImage(bitmap, 42, 64, -52, -64, 0, 0, 20, 20); |
| 141 | 130 |
| 142 // negative size of source, imageRect does not contain sourceRect on top | 131 // negative size of source, imageRect does not contain sourceRect on the rig
ht side |
| 143 shouldNotThrow("ctx.drawImage(bitmap, 52, 54, -52, -64, 0, 0, 20, 20)"); | 132 ctx.drawImage(bitmap, 62, 64, -52, -64, 0, 0, 20, 20); |
| 144 | 133 |
| 145 // negative size of source, imageRect does not contain sourceRect on bot
tom | 134 // negative size of source, imageRect does not contain sourceRect on top |
| 146 shouldNotThrow("ctx.drawImage(bitmap, 52, 74, -52, -64, 0, 0, 20, 20)"); | 135 ctx.drawImage(bitmap, 52, 54, -52, -64, 0, 0, 20, 20); |
| 147 | 136 |
| 148 // negative size of source, imageRect does not contain sourceRect on eve
ry side | 137 // negative size of source, imageRect does not contain sourceRect on bottom |
| 149 shouldNotThrow("ctx.drawImage(bitmap, 62, 74, -72, -84, 0, 0, 20, 20)"); | 138 ctx.drawImage(bitmap, 52, 74, -52, -64, 0, 0, 20, 20); |
| 150 | 139 |
| 151 finishJSTest(); | 140 // negative size of source, imageRect does not contain sourceRect on every s
ide |
| 152 } | 141 ctx.drawImage(bitmap, 62, 74, -72, -84, 0, 0, 20, 20); |
| 142 } |
| 143 |
| 144 async_test(t => { |
| 145 myImage.onload = function() { |
| 146 t.step(draw); |
| 147 createImageBitmap(myImage).then(t.step_func(function(image) { |
| 148 drawBitmap(image); |
| 149 })); |
| 150 t.done(); |
| 151 } |
| 152 }, "This test checks behavior of valid arguments to Canvas::drawImage that use a
valid source image."); |
| 153 </script> | 153 </script> |
| 154 </body> | |
| 155 </html> | |
| OLD | NEW |