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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-fillPath-pattern-shadow.js

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
(Empty)
1 description("Ensure correct behavior of canvas with fillPath using a pattern fil lStyle and a shadow");
2
3 function print(message, color)
4 {
5 var paragraph = document.createElement("div");
6 paragraph.appendChild(document.createTextNode(message));
7 paragraph.style.fontFamily = "monospace";
8 if (color)
9 paragraph.style.color = color;
10 document.getElementById("console").appendChild(paragraph);
11 }
12
13 function shouldBeAround(a, b)
14 {
15 var evalA;
16 try {
17 evalA = eval(a);
18 } catch(e) {
19 evalA = e;
20 }
21
22 if (Math.abs(evalA - b) < 15)
23 print("PASS " + a + " is around " + b , "green")
24 else
25 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")", "red");
26 }
27
28 var aCanvas = document.createElement('canvas');
29 aCanvas.setAttribute('width', '50');
30 aCanvas.setAttribute('height', '50');
31
32 var aCtx = aCanvas.getContext('2d');
33 aCtx.fillStyle = 'rgba(0, 0, 255, 0.5)';
34 aCtx.fillRect(0, 0, 50, 50);
35
36 var pattern = aCtx.createPattern(aCanvas, 'repeat');
37
38 var canvas = document.createElement('canvas');
39 document.body.appendChild(canvas);
40 canvas.setAttribute('width', '600');
41 canvas.setAttribute('height', '1100');
42 var ctx = canvas.getContext('2d');
43
44 ctx.save();
45 ctx.fillStyle = pattern;
46 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
47 ctx.shadowOffsetX = 250;
48
49 function fillShape(x, y) {
50 ctx.beginPath();
51 ctx.arc(x, y, 100, 0, Math.PI*2, true);
52 ctx.arc(x, y, 50, 0, Math.PI*2, false);
53 ctx.fill();
54 }
55
56 // Alpha shadow.
57 ctx.shadowBlur = 0;
58 fillShape(150, 150);
59
60 // Blurry shadow.
61 ctx.shadowBlur = 10;
62 fillShape(150, 400);
63
64 ctx.rotate(Math.PI/2);
65
66 // Rotated alpha shadow.
67 ctx.shadowBlur = 0;
68 fillShape(650, -150);
69
70 // Rotated blurry shadow.
71 ctx.shadowBlur = 10;
72 fillShape(900, -150);
73
74 ctx.restore();
75
76 var imageData, data;
77 ctx.fillStyle = 'black';
78
79 function test(alphaTestFunction, x, y, r, g, b, a) {
80 // Get pixel.
81 imageData = ctx.getImageData(x, y, 1, 1);
82 data = imageData.data;
83 // Test pixel color components.
84 shouldBe('data[0]', r+'');
85 shouldBe('data[1]', g+'');
86 shouldBe('data[2]', b+'');
87 alphaTestFunction('data[3]', a+'');
88 // Plot test point.
89 ctx.fillRect(x, y, 3, 3);
90 }
91
92 print('Verifying alpha shadow...');
93 test(shouldBe, 400, 150, 0, 0, 0, 0);
94 test(shouldBeAround, 400, 75, 255, 0, 0, 64);
95 test(shouldBeAround, 400, 225, 255, 0, 0, 64);
96 test(shouldBeAround, 325, 150, 255, 0, 0, 64);
97 test(shouldBeAround, 475, 150, 255, 0, 0, 64);
98
99 print(' ');
100 print('Verifying blurry shadow...');
101 test(shouldBe, 400, 400, 0, 0, 0, 0);
102 test(shouldBeAround, 400, 300, 255, 0, 0, 31);
103 test(shouldBeAround, 400, 500, 255, 0, 0, 31);
104 test(shouldBeAround, 300, 400, 255, 0, 0, 31);
105 test(shouldBeAround, 500, 400, 255, 0, 0, 31);
106
107 print(' ');
108 print('Verifying rotated alpha shadow...');
109 test(shouldBe, 400, 650, 0, 0, 0, 0);
110 test(shouldBeAround, 400, 575, 255, 0, 0, 64);
111 test(shouldBeAround, 400, 725, 255, 0, 0, 64);
112 test(shouldBeAround, 325, 650, 255, 0, 0, 64);
113 test(shouldBeAround, 475, 650, 255, 0, 0, 64);
114
115 print(' ');
116 print('Verifying rotated blurry shadow...');
117 test(shouldBe, 400, 900, 0, 0, 0, 0);
118 test(shouldBeAround, 400, 800, 255, 0, 0, 31);
119 test(shouldBeAround, 400, 1000, 255, 0, 0, 31);
120 test(shouldBeAround, 300, 900, 255, 0, 0, 31);
121 test(shouldBeAround, 500, 900, 255, 0, 0, 31);
122
123 print(' ');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698