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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-fillPath-pattern-shadow.html

Issue 2678493002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Created 3 years, 10 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 PUBLIC "-//IETF//DTD HTML//EN"> 1 <script src="../../resources/testharness.js"></script>
2 <html> 2 <script src="../../resources/testharnessreport.js"></script>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body> 3 <body>
7 <script src="script-tests/canvas-fillPath-pattern-shadow.js"></script> 4 <script>
5 test(function(t) {
6
7 function print(message, color)
Justin Novosad 2017/02/06 20:04:23 indent
zakerinasab 2017/02/09 18:02:00 Done.
8 {
9 var paragraph = document.createElement("div");
10 paragraph.appendChild(document.createTextNode(message));
11 paragraph.style.fontFamily = "monospace";
12 if (color)
13 paragraph.style.color = color;
14 document.getElementById("console").appendChild(paragraph);
15 }
16
17 function shouldBeAround(a, b)
Justin Novosad 2017/02/06 20:04:23 Remove this. We use assert_approx_equals now.
zakerinasab 2017/02/09 18:02:00 Done.
18 {
19 var evalA;
20 try {
21 evalA = eval(a);
22 } catch(e) {
23 evalA = e;
24 }
25
26 if (Math.abs(evalA - b) < 15)
27 print("PASS " + a + " is around " + b , "green")
28 else
29 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")", "red");
30 }
31
32 var aCanvas = document.createElement('canvas');
33 aCanvas.setAttribute('width', '50');
34 aCanvas.setAttribute('height', '50');
35
36 var aCtx = aCanvas.getContext('2d');
37 aCtx.fillStyle = 'rgba(0, 0, 255, 0.5)';
38 aCtx.fillRect(0, 0, 50, 50);
39
40 var pattern = aCtx.createPattern(aCanvas, 'repeat');
41
42 var canvas = document.createElement('canvas');
43 document.body.appendChild(canvas);
44 canvas.setAttribute('width', '600');
45 canvas.setAttribute('height', '1100');
46 var ctx = canvas.getContext('2d');
47
48 ctx.save();
49 ctx.fillStyle = pattern;
50 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
51 ctx.shadowOffsetX = 250;
52
53 function fillShape(x, y) {
54 ctx.beginPath();
55 ctx.arc(x, y, 100, 0, Math.PI*2, true);
56 ctx.arc(x, y, 50, 0, Math.PI*2, false);
57 ctx.fill();
58 }
59
60 // Alpha shadow.
61 ctx.shadowBlur = 0;
62 fillShape(150, 150);
63
64 // Blurry shadow.
65 ctx.shadowBlur = 10;
66 fillShape(150, 400);
67
68 ctx.rotate(Math.PI/2);
69
70 // Rotated alpha shadow.
71 ctx.shadowBlur = 0;
72 fillShape(650, -150);
73
74 // Rotated blurry shadow.
75 ctx.shadowBlur = 10;
76 fillShape(900, -150);
77
78 ctx.restore();
79
80 var imageData, data;
81 ctx.fillStyle = 'black';
82
83 function test(x, y, r, g, b, a, alphaApprox) {
Justin Novosad 2017/02/06 20:04:23 This is confusing because testharness.js also defi
zakerinasab 2017/02/09 18:02:01 Done.
84 // Get pixel.
85 imageData = ctx.getImageData(x, y, 1, 1);
86 data = imageData.data;
87 // Test pixel color components.
88 assert_equals(data[0], r);
89 assert_equals(data[1], g);
90 assert_equals(data[2], b);
91 if (alphaApprox === undefined)
92 alphaApprox = 15;
93 assert_approx_equals(data[3], a, alphaApprox);
94 // Plot test point.
95 ctx.fillRect(x, y, 3, 3);
96 }
97
98 // Verifying alpha shadow...
99 test(400, 150, 0, 0, 0, 0, 0);
Justin Novosad 2017/02/06 20:04:23 Could use generate_tests()
zakerinasab 2017/02/09 18:02:00 Done.
100 test(400, 75, 255, 0, 0, 64);
101 test(400, 225, 255, 0, 0, 64);
102 test(325, 150, 255, 0, 0, 64);
103 test(475, 150, 255, 0, 0, 64);
104
105 // Verifying blurry shadow...
106 test(400, 400, 0, 0, 0, 0, 0);
107 test(400, 300, 255, 0, 0, 31);
108 test(400, 500, 255, 0, 0, 31);
109 test(300, 400, 255, 0, 0, 31);
110 test(500, 400, 255, 0, 0, 31);
111
112 // Verifying rotated alpha shadow...
113 test(400, 650, 0, 0, 0, 0, 0);
114 test(400, 575, 255, 0, 0, 64);
115 test(400, 725, 255, 0, 0, 64);
116 test(325, 650, 255, 0, 0, 64);
117 test(475, 650, 255, 0, 0, 64);
118
119 // Verifying rotated blurry shadow...
120 test(400, 900, 0, 0, 0, 0, 0);
121 test(400, 800, 255, 0, 0, 31);
122 test(400, 1000, 255, 0, 0, 31);
123 test(300, 900, 255, 0, 0, 31);
124 test(500, 900, 255, 0, 0, 31);
125
126 }, "Ensure correct behavior of canvas with fillPath using a pattern fillStyle an d a shadow");
127 </script>
8 </body> 128 </body>
9 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698