OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <head> | 2 <title>Test that gradient gets applied properly with canvas2d text drawing when
filled with maxwidth</title> |
| 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"></canvas> |
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 = '#f00'; | 14 var canvas = document.querySelector('canvas'); |
18 ctx.fillRect(0,0,100,100); | 15 var ctx = canvas.getContext("2d"); |
19 var gradient = ctx.createLinearGradient(0, 0, 100, 100); | 16 ctx.font = "100px Ahem"; |
20 gradient.addColorStop(0, '#0f0'); | 17 // Kick off loading of the font. |
21 gradient.addColorStop(1, '#0f0'); | 18 ctx.fillText(" ", 0, 0); |
22 ctx.fillStyle = gradient; | 19 // Wait for the font to load, then run. |
23 ctx.fillText("X", 0, 80, 200); | 20 document.fonts.onloadingdone = t.step_func_done(function() { |
24 ctx.fillStyle = '#f00'; | 21 // Draw to canvas. |
25 ctx.fillText("X", 0, 80, -10); | 22 ctx.fillStyle = '#f00'; |
26 } | 23 ctx.fillRect(0, 0, 100, 100); |
27 | 24 var gradient = ctx.createLinearGradient(0, 0, 100, 100); |
28 function doDeferredTest() { | 25 gradient.addColorStop(0, '#0f0'); |
29 drawCanvas(ctx); | 26 gradient.addColorStop(1, '#0f0'); |
30 | 27 ctx.fillStyle = gradient; |
31 // Check that the letter rendered appropriately | 28 ctx.fillText("X", 0, 80, 200); |
32 var renderedCorrectly = true; | 29 ctx.fillStyle = '#f00'; |
33 | 30 ctx.fillText("X", 0, 80, -10); |
34 // Check that there is only a green rectangle | 31 // Check that there is only a green rectangle. |
35 var imageData = ctx.getImageData(50,50,1,1); | 32 var imageData = ctx.getImageData(50, 50, 1, 1); |
36 if (imageData.data[0] != 0) renderedCorrectly = false; | 33 assert_equals(imageData.data[0], 0, "red"); |
37 if (imageData.data[1] != 255) renderedCorrectly = false; | 34 assert_equals(imageData.data[1], 255, "green"); |
38 if (imageData.data[2] != 0) renderedCorrectly = false; | 35 assert_equals(imageData.data[2], 0, "blue"); |
39 if (imageData.data[3] != 255) renderedCorrectly = false; | 36 assert_equals(imageData.data[3], 255, "alpha"); |
40 | 37 }); |
41 if (renderedCorrectly) | 38 }); |
42 document.getElementById("console").innerHTML = "TEST PASSED"; | |
43 else | |
44 document.getElementById("console").innerHTML = "TEST FAILED"; | |
45 | |
46 if (window.testRunner) | |
47 testRunner.notifyDone(); | |
48 } | |
49 | |
50 if (window.testRunner) { | |
51 testRunner.dumpAsText(); | |
52 testRunner.waitUntilDone(); | |
53 } | |
54 | |
55 var canvas = document.getElementById('c'); | |
56 var ctx = canvas.getContext("2d"); | |
57 ctx.font = "100px Ahem"; | |
58 | |
59 // Kick off loading of the font | |
60 ctx.fillText(" ", 0, 0); | |
61 | |
62 // Wait for the font to load, then run | |
63 document.fonts.addEventListener('loadingdone', doDeferredTest); | |
64 </script> | 39 </script> |
65 </body> | |
66 </html> | |
OLD | NEW |