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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-fillPath-gradient-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-gradient-shadow.js"></script> 4 <script>
5 test(function(t) {
6
7 var canvas = document.createElement('canvas');
Justin Novosad 2017/02/06 20:04:23 indent
zakerinasab 2017/02/09 18:02:00 Done.
8 document.body.appendChild(canvas);
9 canvas.setAttribute('width', '600');
10 canvas.setAttribute('height', '1100');
11 var ctx = canvas.getContext('2d');
12
13 var gradient = ctx.createLinearGradient(0, 0, 300, 0);
14 gradient.addColorStop(0, 'rgba(0, 0, 255, 0.5)');
15 gradient.addColorStop(1, 'rgba(0, 0, 255, 0.5)');
16
17 ctx.save();
18 ctx.fillStyle = gradient;
19 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
20 ctx.shadowOffsetX = 250;
21
22 function fillShape(x, y) {
23 ctx.beginPath();
24 ctx.arc(x, y, 100, 0, Math.PI*2, true);
25 ctx.arc(x, y, 50, 0, Math.PI*2, false);
26 ctx.fill();
27 }
28
29 // Alpha shadow.
30 ctx.shadowBlur = 0;
31 fillShape(150, 150);
32
33 // Blurry shadow.
34 ctx.shadowBlur = 10;
35 fillShape(150, 400);
36
37 ctx.rotate(Math.PI/2);
38
39 // Rotated alpha shadow.
40 ctx.shadowBlur = 0;
41 fillShape(650, -150);
42
43 // Rotated blurry shadow.
44 ctx.shadowBlur = 10;
45 fillShape(900, -150);
46
47 ctx.restore();
48
49 var imageData, data;
50 ctx.fillStyle = 'black';
51
52 function test(x, y, r, g, b, a, alphaApprox) {
53 // Get pixel.
54 imageData = ctx.getImageData(x, y, 1, 1);
55 data = imageData.data;
56 // Test pixel color components.
57 assert_equals(data[0], r);
58 assert_equals(data[1], g);
59 assert_equals(data[2], b);
60 if (alphaApprox === undefined)
61 alphaApprox = 15;
62 assert_approx_equals(data[3], a, alphaApprox);
63 // Plot test point.
64 ctx.fillRect(x, y, 3, 3);
65 }
66
67 // Verifying alpha shadow...
68 test(400, 150, 0, 0, 0, 0, 0);
69 test(400, 75, 255, 0, 0, 64);
70 test(400, 225, 255, 0, 0, 64);
71 test(325, 150, 255, 0, 0, 64);
72 test(475, 150, 255, 0, 0, 64);
73
74 // Verifying blurry shadow...
75 test(400, 400, 0, 0, 0, 0, 0);
76 test(400, 300, 255, 0, 0, 31);
77 test(400, 500, 255, 0, 0, 31);
78 test(300, 400, 255, 0, 0, 31);
79 test(500, 400, 255, 0, 0, 31);
80
81 // Verifying rotated alpha shadow...
82 test(400, 650, 0, 0, 0, 0, 0);
83 test(400, 575, 255, 0, 0, 64);
84 test(400, 725, 255, 0, 0, 64);
85 test(325, 650, 255, 0, 0, 64);
86 test(475, 650, 255, 0, 0, 64);
87
88 // Verifying rotated blurry shadow...
89 test(400, 900, 0, 0, 0, 0, 0);
90 test(400, 800, 255, 0, 0, 31);
91 test(400, 1000, 255, 0, 0, 31);
92 test(300, 900, 255, 0, 0, 31);
93 test(500, 900, 255, 0, 0, 31);
94
95 }, "Ensure correct behavior of canvas with fillPath using a gradient fillStyle a nd a shadow");
96
97 </script>
8 </body> 98 </body>
9 </html> 99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698