Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <head> | 2 <title>Test that color gets applied properly with canvas2d text drawing when fil led with negative maxwidth..</title> |
|
fs
2016/08/26 09:13:18
Nit: Double . (Since this is a title, I believe we
sivag
2016/08/26 10:01:35
Done.
| |
| 3 <script src="../../resources/testharness.js"></script> | |
| 4 <script src="../../resources/testharnessreport.js"></script> | |
| 3 <style> | 5 <style> |
| 4 @font-face { | 6 @font-face { |
| 5 font-family: Ahem; | 7 font-family: Ahem; |
| 6 src: url('../../resources/Ahem.ttf'); | 8 src: url('../../resources/Ahem.ttf'); |
| 7 } | 9 } |
| 8 </style> | 10 </style> |
| 9 </head> | 11 <canvas width="100" height="100"> |
|
fs
2016/08/26 09:13:18
Same as the other test.
sivag
2016/08/26 10:01:35
Done.
| |
| 10 <body> | |
| 11 <p>On success, there should only be a green rectangle.</p> | |
| 12 <canvas id="c" class="output" width="100" height="100"><p class="fallback">FAIL (fallback content)</p></canvas> | |
| 13 <div id="console"></div> | |
| 14 | |
| 15 <script> | 12 <script> |
| 16 function drawCanvas(ctx) { | 13 async_test(function(t) { |
| 17 ctx.fillStyle = '#0f0'; | 14 var canvas = document.querySelector('canvas'); |
| 18 ctx.fillRect(0,0,100,100); | 15 var ctx = canvas.getContext("2d"); |
| 19 ctx.fillStyle = '#f00'; | 16 ctx.font = "200px Ahem"; |
| 20 ctx.fillText("X", 0, 100, -5); | 17 // Kick off loading of the font. |
| 21 } | 18 ctx.fillText(" ", 0, 0); |
| 22 | 19 // Wait for the font to load, then run. |
| 23 function doDeferredTest() { | 20 document.fonts.onloadingdone = t.step_func_done(function() { |
| 24 drawCanvas(ctx); | 21 // Draw to canvas. |
| 25 | 22 ctx.fillStyle = '#0f0'; |
| 26 // Check that the letter rendered appropriately | 23 ctx.fillRect(0, 0, 100, 100); |
| 27 var renderedCorrectly = true; | 24 ctx.fillStyle = '#f00'; |
| 28 | 25 ctx.fillText("X", 0, 100, -5); |
| 29 // Check that there is only a green rectangle | 26 // Check that there is only a green rectangle. |
| 30 var imageData = ctx.getImageData(50,50,1,1); | 27 var imageData = ctx.getImageData(50, 50, 1, 1); |
| 31 if (imageData.data[0] != 0) renderedCorrectly = false; | 28 assert_equals(imageData.data[0], 0, "red"); |
| 32 if (imageData.data[1] != 255) renderedCorrectly = false; | 29 assert_equals(imageData.data[1], 255, "green"); |
| 33 if (imageData.data[2] != 0) renderedCorrectly = false; | 30 assert_equals(imageData.data[2], 0, "blue"); |
| 34 if (imageData.data[3] != 255) renderedCorrectly = false; | 31 assert_equals(imageData.data[3], 255, "alpha"); |
| 35 | 32 }); |
| 36 if (renderedCorrectly) | 33 }); |
| 37 document.getElementById("console").innerHTML = "TEST PASSED"; | |
| 38 else | |
| 39 document.getElementById("console").innerHTML = "TEST FAILED"; | |
| 40 | |
| 41 if (window.testRunner) | |
| 42 testRunner.notifyDone(); | |
| 43 } | |
| 44 | |
| 45 if (window.testRunner) { | |
| 46 testRunner.dumpAsText(); | |
| 47 testRunner.waitUntilDone(); | |
| 48 } | |
| 49 | |
| 50 var canvas = document.getElementById('c'); | |
| 51 var ctx = canvas.getContext("2d"); | |
| 52 ctx.font = "200px Ahem"; | |
| 53 | |
| 54 // Kick off loading of the font | |
| 55 ctx.fillText(" ", 0, 0); | |
| 56 | |
| 57 // Wait for the font to load, then run | |
| 58 setTimeout(function() { | |
| 59 doDeferredTest(); | |
| 60 }, 50); | |
| 61 </script> | 34 </script> |
| 62 </body> | |
| 63 </html> | |
| OLD | NEW |