1- name: 2d.type.delete 2 desc: window.CanvasRenderingContext2D is Configurable 3 notes: &bindings Defined in "Web IDL" (draft) 4 testing: 5 - context.2d.type 6 code: | 7 @assert window.CanvasRenderingContext2D !== undefined; 8 @assert delete window.CanvasRenderingContext2D === true; 9 @assert window.CanvasRenderingContext2D === undefined; 10 11- name: 2d.voidreturn 12 desc: void methods return undefined 13 notes: *bindings 14 images: 15 - yellow.png 16 code: | 17 @assert ctx.save() === undefined; 18 @assert ctx.restore() === undefined; 19 @assert ctx.scale(1, 1) === undefined; 20 @assert ctx.rotate(0) === undefined; 21 @assert ctx.translate(0, 0) === undefined; 22 if (ctx.transform) { // (avoid spurious failures, since the aim here is not to test that all features are supported) 23 @assert ctx.transform(1, 0, 0, 1, 0, 0) === undefined; 24 } 25 if (ctx.setTransform) { 26 @assert ctx.setTransform(1, 0, 0, 1, 0, 0) === undefined; 27 @assert ctx.setTransform() === undefined; 28 } 29 @assert ctx.clearRect(0, 0, 0, 0) === undefined; 30 @assert ctx.fillRect(0, 0, 0, 0) === undefined; 31 @assert ctx.strokeRect(0, 0, 0, 0) === undefined; 32 @assert ctx.beginPath() === undefined; 33 @assert ctx.closePath() === undefined; 34 @assert ctx.moveTo(0, 0) === undefined; 35 @assert ctx.lineTo(0, 0) === undefined; 36 @assert ctx.quadraticCurveTo(0, 0, 0, 0) === undefined; 37 @assert ctx.bezierCurveTo(0, 0, 0, 0, 0, 0) === undefined; 38 @assert ctx.arcTo(0, 0, 0, 0, 1) === undefined; 39 @assert ctx.rect(0, 0, 0, 0) === undefined; 40 @assert ctx.arc(0, 0, 1, 0, 0, true) === undefined; 41 @assert ctx.fill() === undefined; 42 @assert ctx.stroke() === undefined; 43 @assert ctx.clip() === undefined; 44 if (ctx.fillText) { 45 @assert ctx.fillText('test', 0, 0) === undefined; 46 @assert ctx.strokeText('test', 0, 0) === undefined; 47 } 48 if (ctx.putImageData) { 49 @assert ctx.putImageData(ctx.getImageData(0, 0, 1, 1), 0, 0) === undefined; 50 } 51 @assert ctx.drawImage(document.getElementById('yellow.png'), 0, 0, 1, 1, 0, 0, 0, 0) === undefined; 52 @assert ctx.drawImage(canvas, 0, 0, 1, 1, 0, 0, 0, 0) === undefined; 53 @assert ctx.createLinearGradient(0, 0, 0, 0).addColorStop(0, 'white') === undefined; 54 55- name: 2d.missingargs 56 desc: Missing arguments cause TypeError 57 code: | 58 @assert throws TypeError ctx.scale(); 59 @assert throws TypeError ctx.scale(1); 60 @assert throws TypeError ctx.rotate(); 61 @assert throws TypeError ctx.translate(); 62 @assert throws TypeError ctx.translate(0); 63 if (ctx.transform) { // (avoid spurious failures, since the aim here is not to test that all features are supported) 64 @assert throws TypeError ctx.transform(); 65 @assert throws TypeError ctx.transform(1); 66 @assert throws TypeError ctx.transform(1, 0); 67 @assert throws TypeError ctx.transform(1, 0, 0); 68 @assert throws TypeError ctx.transform(1, 0, 0, 1); 69 @assert throws TypeError ctx.transform(1, 0, 0, 1, 0); 70 } 71 if (ctx.setTransform) { 72 @assert throws TypeError ctx.setTransform(1); 73 @assert throws TypeError ctx.setTransform(1, 0); 74 @assert throws TypeError ctx.setTransform(1, 0, 0); 75 @assert throws TypeError ctx.setTransform(1, 0, 0, 1); 76 @assert throws TypeError ctx.setTransform(1, 0, 0, 1, 0); 77 } 78 @assert throws TypeError ctx.createLinearGradient(); 79 @assert throws TypeError ctx.createLinearGradient(0); 80 @assert throws TypeError ctx.createLinearGradient(0, 0); 81 @assert throws TypeError ctx.createLinearGradient(0, 0, 1); 82 @assert throws TypeError ctx.createRadialGradient(); 83 @assert throws TypeError ctx.createRadialGradient(0); 84 @assert throws TypeError ctx.createRadialGradient(0, 0); 85 @assert throws TypeError ctx.createRadialGradient(0, 0, 1); 86 @assert throws TypeError ctx.createRadialGradient(0, 0, 1, 0); 87 @assert throws TypeError ctx.createRadialGradient(0, 0, 1, 0, 0); 88 @assert throws TypeError ctx.createPattern(canvas); 89 @assert throws TypeError ctx.clearRect(); 90 @assert throws TypeError ctx.clearRect(0); 91 @assert throws TypeError ctx.clearRect(0, 0); 92 @assert throws TypeError ctx.clearRect(0, 0, 0); 93 @assert throws TypeError ctx.fillRect(); 94 @assert throws TypeError ctx.fillRect(0); 95 @assert throws TypeError ctx.fillRect(0, 0); 96 @assert throws TypeError ctx.fillRect(0, 0, 0); 97 @assert throws TypeError ctx.strokeRect(); 98 @assert throws TypeError ctx.strokeRect(0); 99 @assert throws TypeError ctx.strokeRect(0, 0); 100 @assert throws TypeError ctx.strokeRect(0, 0, 0); 101 @assert throws TypeError ctx.moveTo(); 102 @assert throws TypeError ctx.moveTo(0); 103 @assert throws TypeError ctx.lineTo(); 104 @assert throws TypeError ctx.lineTo(0); 105 @assert throws TypeError ctx.quadraticCurveTo(); 106 @assert throws TypeError ctx.quadraticCurveTo(0); 107 @assert throws TypeError ctx.quadraticCurveTo(0, 0); 108 @assert throws TypeError ctx.quadraticCurveTo(0, 0, 0); 109 @assert throws TypeError ctx.bezierCurveTo(); 110 @assert throws TypeError ctx.bezierCurveTo(0); 111 @assert throws TypeError ctx.bezierCurveTo(0, 0); 112 @assert throws TypeError ctx.bezierCurveTo(0, 0, 0); 113 @assert throws TypeError ctx.bezierCurveTo(0, 0, 0, 0); 114 @assert throws TypeError ctx.bezierCurveTo(0, 0, 0, 0, 0); 115 @assert throws TypeError ctx.arcTo(); 116 @assert throws TypeError ctx.arcTo(0); 117 @assert throws TypeError ctx.arcTo(0, 0); 118 @assert throws TypeError ctx.arcTo(0, 0, 0); 119 @assert throws TypeError ctx.arcTo(0, 0, 0, 0); 120 @assert throws TypeError ctx.rect(); 121 @assert throws TypeError ctx.rect(0); 122 @assert throws TypeError ctx.rect(0, 0); 123 @assert throws TypeError ctx.rect(0, 0, 0); 124 @assert throws TypeError ctx.arc(); 125 @assert throws TypeError ctx.arc(0); 126 @assert throws TypeError ctx.arc(0, 0); 127 @assert throws TypeError ctx.arc(0, 0, 1); 128 @assert throws TypeError ctx.arc(0, 0, 1, 0); 129 // (6th argument to arc is optional) 130 if (ctx.isPointInPath) { 131 @assert throws TypeError ctx.isPointInPath(); 132 @assert throws TypeError ctx.isPointInPath(0); 133 } 134 if (ctx.drawFocusRing) { 135 @assert throws TypeError ctx.drawFocusRing(); 136 @assert throws TypeError ctx.drawFocusRing(canvas); 137 @assert throws TypeError ctx.drawFocusRing(canvas, 0); 138 } 139 if (ctx.fillText) { 140 @assert throws TypeError ctx.fillText(); 141 @assert throws TypeError ctx.fillText('test'); 142 @assert throws TypeError ctx.fillText('test', 0); 143 @assert throws TypeError ctx.strokeText(); 144 @assert throws TypeError ctx.strokeText('test'); 145 @assert throws TypeError ctx.strokeText('test', 0); 146 @assert throws TypeError ctx.measureText(); 147 } 148 @assert throws TypeError ctx.drawImage(); 149 @assert throws TypeError ctx.drawImage(canvas); 150 @assert throws TypeError ctx.drawImage(canvas, 0); 151 // TODO: n >= 3 args on drawImage could be either a valid overload, 152 // or too few for another overload, or too many for another 153 // overload - what should happen? 154 if (ctx.createImageData) { 155 @assert throws TypeError ctx.createImageData(); 156 @assert throws TypeError ctx.createImageData(1); 157 } 158 if (ctx.getImageData) { 159 @assert throws TypeError ctx.getImageData(); 160 @assert throws TypeError ctx.getImageData(0); 161 @assert throws TypeError ctx.getImageData(0, 0); 162 @assert throws TypeError ctx.getImageData(0, 0, 1); 163 } 164 if (ctx.putImageData) { 165 var imgdata = ctx.getImageData(0, 0, 1, 1); 166 @assert throws TypeError ctx.putImageData(); 167 @assert throws TypeError ctx.putImageData(imgdata); 168 @assert throws TypeError ctx.putImageData(imgdata, 0); 169 } 170 var g = ctx.createLinearGradient(0, 0, 0, 0); 171 @assert throws TypeError g.addColorStop(); @moz-todo 172 @assert throws TypeError g.addColorStop(0); @moz-todo 173 174- name: 2d.coordinatespace 175 desc: Coordinate space goes from top-left to bottom-right 176 notes: This should not be upside down. 177 manual: We can't tell that getPixelData isn't using the wrong coordinate space too. 178 testing: 179 - 2d.coordinatespace 180 code: | 181 ctx.fillStyle = '#00f'; 182 ctx.fillRect(0, 0, 100, 50); 183 ctx.fillStyle = '#0ff'; 184 ctx.fillRect(0, 0, 50, 25); 185 @assert pixel 25,12 == 0,255,255,255; 186 @assert pixel 75,12 == 0,0,255,255; 187 @assert pixel 25,37 == 0,0,255,255; 188 @assert pixel 75,37 == 0,0,255,255; 189 expected: | 190 size 100 50 191 cr.set_source_rgb(0, 0, 1) 192 cr.rectangle(0, 0, 100, 50) 193 cr.fill() 194 cr.set_source_rgb(0, 1, 1) 195 cr.rectangle(0, 0, 50, 25) 196 cr.fill() 197 198