Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <body> | 2 <title>On success, the square should have the bottom left portion of the base of the green I and red otherwise.</title> |
|
fs
2016/08/25 11:16:48
Let's make this something akin to "fillText with g
sivag
2016/08/25 13:29:27
Done.
| |
| 3 <p>On success, the square should have the bottom left portion of the base of the green I and red otherwise.</p> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <canvas id="c" class="output" width="100" height="100"><p class="fallback">FAIL (fallback content)</p></canvas> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <div id="console"></div> | 5 <canvas width="100" height="100"></canvas> |
| 6 <script> | |
| 7 test(function() { | |
| 8 function drawCanvas(ctx) { | |
| 9 ctx.fillStyle = '#f00'; | |
| 10 ctx.fillRect(0,0,100,100); | |
| 11 var gradient = ctx.createLinearGradient(0, 0, 100, 100); | |
| 12 gradient.addColorStop(0, '#0f0'); | |
| 13 gradient.addColorStop(1, '#0f0'); | |
| 14 ctx.fillStyle = gradient; | |
| 15 ctx.font = "500px Times"; | |
| 16 ctx.fillText("I", -5, 100); | |
| 17 } | |
| 18 var canvas = document.querySelector('canvas'); | |
| 19 var ctx = canvas.getContext("2d"); | |
| 20 drawCanvas(ctx); | |
| 21 // Check for a green pixel from the text. | |
| 22 var imageData = ctx.getImageData(75,75,1,1); | |
| 23 assert_equals(imageData.data[0], 0, "red"); | |
| 24 assert_equals(imageData.data[1], 255, "green"); | |
| 25 assert_equals(imageData.data[2], 0, "blue"); | |
| 26 assert_equals(imageData.data[3], 255, "alpha"); | |
| 6 | 27 |
| 7 <script> | 28 // Check the red pixel outside of text wan't touched. |
|
fs
2016/08/25 11:16:48
Nit: wasn't; the text
sivag
2016/08/25 13:29:27
Done.
| |
| 8 | 29 var imageData = ctx.getImageData(25,25,1,1); |
| 9 function drawCanvas(ctx) { | 30 assert_equals(imageData.data[0], 255, "red"); |
| 10 | 31 assert_equals(imageData.data[1], 0, "green"); |
| 11 ctx.fillStyle = '#f00'; | 32 assert_equals(imageData.data[2], 0, "blue"); |
| 12 ctx.fillRect(0,0,100,100); | 33 assert_equals(imageData.data[3], 255, "alpha"); |
| 13 | 34 }); |
| 14 var gradient = ctx.createLinearGradient(0, 0, 100, 100); | |
| 15 gradient.addColorStop(0, '#0f0'); | |
| 16 gradient.addColorStop(1, '#0f0'); | |
| 17 | |
| 18 ctx.fillStyle = gradient; | |
| 19 ctx.font = "500px Times"; | |
| 20 | |
| 21 ctx.fillText("I", -5, 100); | |
| 22 } | |
| 23 | |
| 24 if (window.testRunner) | |
| 25 testRunner.dumpAsText(); | |
| 26 | |
| 27 var canvas = document.getElementById('c'); | |
| 28 var ctx = canvas.getContext("2d"); | |
| 29 drawCanvas(ctx); | |
| 30 | |
| 31 // Check that the letter rendered appropriately | |
| 32 var renderedCorrectly = true; | |
| 33 | |
| 34 // Check for a green pixel from the text | |
| 35 var imageData = ctx.getImageData(75,75,1,1); | |
| 36 if (imageData.data[0] != 0) renderedCorrectly = false; | |
| 37 if (imageData.data[1] != 255) renderedCorrectly = false; | |
| 38 if (imageData.data[2] != 0) renderedCorrectly = false; | |
| 39 if (imageData.data[3] != 255) renderedCorrectly = false; | |
| 40 | |
| 41 // Check the red pixel outside of text wasn't touched | |
| 42 var imageData = ctx.getImageData(25,25,1,1); | |
| 43 if (imageData.data[0] != 255) renderedCorrectly = false; | |
| 44 if (imageData.data[1] != 0) renderedCorrectly = false; | |
| 45 if (imageData.data[2] != 0) renderedCorrectly = false; | |
| 46 if (imageData.data[3] != 255) renderedCorrectly = false; | |
| 47 | |
| 48 if (renderedCorrectly) | |
| 49 » document.getElementById("console").innerHTML = "TEST PASSED"; | |
| 50 else | |
| 51 » document.getElementById("console").innerHTML = "TEST FAILED"; | |
| 52 | |
| 53 </script> | 35 </script> |
| 54 </body> | |
| 55 </html> | |
| OLD | NEW |