Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 description("Test for chromium's canvas bug where fillText resets the current co ntext https://bugs.webkit.org/show_bug.cgi?id=26436 . You must see green box wit h message 'This text should be seen', and black box below the green box.") | |
|
sivag
2016/09/15 05:31:14
May be you can keep the bug-id part and descriptio
Abhishek Kanike
2016/09/15 11:52:56
Done.
| |
| 2 | |
| 3 function pixelValueAt(context, x, y) { | |
| 4 var imageData = context.getImageData(x, y, 1, 1); | |
| 5 return imageData.data; | |
| 6 } | |
| 7 | |
| 8 function pixelToString(p) { | |
| 9 return "[" + p[0] + ", " + p[1] + ", " + p[2] + ", " + p[3] + "]" | |
| 10 } | |
| 11 | |
| 12 function pixelShouldBe(context, x, y, expectedPixelString) { | |
| 13 var pixel = pixelValueAt(context, x, y); | |
| 14 var expectedPixel = eval(expectedPixelString); | |
| 15 | |
| 16 var pixelString = "pixel " + x + ", " + y; | |
| 17 if (areArraysEqual(pixel, expectedPixel)) { | |
| 18 testPassed(pixelString + " is " + pixelToString(pixel)); | |
| 19 } else { | |
| 20 testFailed(pixelString + " should be " + pixelToString(expectedPixel) + " was " + pixelToString(pixel)); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 var canvas = document.createElement("canvas"); | |
| 25 canvas.height = 100; | |
| 26 canvas.width = 500; | |
| 27 canvas.style.height = "100"; | |
| 28 canvas.style.width = "500"; | |
| 29 | |
| 30 document.body.appendChild(canvas); | |
| 31 | |
| 32 var ctx = canvas.getContext('2d'); | |
| 33 ctx.fillStyle = 'rgb(0,255,0)'; | |
| 34 ctx.fillRect(0, 0, 500, 100); | |
| 35 ctx.fillStyle = 'rgb(0,0,0)'; | |
| 36 ctx.fillText("This text should be seen", 20, 20); | |
| 37 ctx.translate(0, 50); | |
| 38 ctx.font = "10pt Arial"; | |
| 39 ctx.fillText("This text should NOT be seen", 20, 20); | |
| 40 // If fillText resets the current context, this rectangle won't hide the text. | |
| 41 ctx.fillStyle = 'rgb(0,0,0)'; | |
| 42 ctx.fillRect(0, 0, 500, 50); | |
| 43 | |
| 44 pixelShouldBe(ctx, 0, 0, "[0,255,0,255]"); | |
| OLD | NEW |