Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/2d.fillText.gradient.html

Issue 2278723005: Convert LayoutTests/fast/canvas/2d tests to testharness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test changed as per the comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <body> 2 <title>Test that color gradient is applied properly for fillText() in 2d canvas. </title>
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
7 <script> 6 <script>
8 7 test(function() {
9 function drawCanvas(ctx) { 8 var canvas = document.querySelector('canvas');
10 9 var ctx = canvas.getContext("2d");
11 ctx.fillStyle = '#f00'; 10 ctx.fillStyle = '#f00';
12 ctx.fillRect(0,0,100,100); 11 ctx.fillRect(0,0,100,100);
13 12 var gradient = ctx.createLinearGradient(0, 0, 100, 100);
14 var gradient = ctx.createLinearGradient(0, 0, 100, 100); 13 gradient.addColorStop(0, '#0f0');
15 gradient.addColorStop(0, '#0f0'); 14 gradient.addColorStop(1, '#0f0');
16 gradient.addColorStop(1, '#0f0'); 15 ctx.fillStyle = gradient;
17 16 ctx.font = "500px Times";
18 ctx.fillStyle = gradient; 17 ctx.fillText("I", -5, 100);
19 ctx.font = "500px Times"; 18 // Check for a green pixel from the text.
20 19 var imageData = ctx.getImageData(75,75,1,1);
21 ctx.fillText("I", -5, 100); 20 assert_equals(imageData.data[0], 0, "red");
22 } 21 assert_equals(imageData.data[1], 255, "green");
23 22 assert_equals(imageData.data[2], 0, "blue");
24 if (window.testRunner) 23 assert_equals(imageData.data[3], 255, "alpha");
25 testRunner.dumpAsText(); 24 // Check the red pixel outside of text wasn't touched.
26 25 var imageData = ctx.getImageData(25,25,1,1);
27 var canvas = document.getElementById('c'); 26 assert_equals(imageData.data[0], 255, "red");
28 var ctx = canvas.getContext("2d"); 27 assert_equals(imageData.data[1], 0, "green");
29 drawCanvas(ctx); 28 assert_equals(imageData.data[2], 0, "blue");
30 29 assert_equals(imageData.data[3], 255, "alpha");
31 // Check that the letter rendered appropriately 30 });
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> 31 </script>
54 </body>
55 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698