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/script-tests/canvas-scale-shadowBlur.js

Issue 2696023002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Rebaseline 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 that canvas shadowBlur is not affected by transformations.") ;
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) < 10)
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 canvas = document.createElement('canvas');
29 document.body.appendChild(canvas);
30 canvas.setAttribute('width', '600');
31 canvas.setAttribute('height', '600');
32 var ctx = canvas.getContext('2d');
33
34 ctx.shadowBlur = 25;
35 ctx.shadowOffsetX = 100;
36 ctx.shadowOffsetY = 100;
37 ctx.fillStyle = 'rgba(0, 0, 255, 1)';
38
39 // top left
40 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
41 ctx.scale(4, 4);
42 ctx.rotate(Math.PI/2);
43 ctx.translate(25, -50);
44 ctx.fillRect(0, 0, 25, 25);
45
46 // bottom left
47 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
48 ctx.setTransform(1, 0, 0, 1, 0, 0);
49 ctx.scale(0.5, 0.5);
50 ctx.fillRect(200, 600, 200, 200);
51
52 // top right
53 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
54 ctx.scale(2, 2);
55 ctx.fillRect(300, 100, 100, 100);
56
57 // bottom right
58 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
59 ctx.fillRect(300, 300, 100, 100);
60
61 var d;
62
63 // top left
64 d = ctx.getImageData(250, 250, 1, 1).data;
65 shouldBe('d[0]', '255');
66 shouldBe('d[1]', '0');
67 shouldBe('d[2]', '0');
68 shouldBeAround('d[3]', '255');
69
70 d = ctx.getImageData(250, 175, 1, 1).data;
71 shouldBe('d[0]', '0');
72 shouldBe('d[1]', '0');
73 shouldBe('d[2]', '0');
74 shouldBe('d[3]', '0');
75
76 d = ctx.getImageData(250, 325, 1, 1).data;
77 shouldBe('d[0]', '0');
78 shouldBe('d[1]', '0');
79 shouldBe('d[2]', '0');
80 shouldBe('d[3]', '0');
81
82 d = ctx.getImageData(175, 250, 1, 1).data;
83 shouldBe('d[0]', '0');
84 shouldBe('d[1]', '0');
85 shouldBe('d[2]', '0');
86 shouldBe('d[3]', '0');
87
88 d = ctx.getImageData(325, 250, 1, 1).data;
89 shouldBe('d[0]', '0');
90 shouldBe('d[1]', '0');
91 shouldBe('d[2]', '0');
92 shouldBe('d[3]', '0');
93
94 // bottom left
95 d = ctx.getImageData(250, 450, 1, 1).data;
96 shouldBe('d[0]', '255');
97 shouldBe('d[1]', '0');
98 shouldBe('d[2]', '0');
99 shouldBeAround('d[3]', '126');
100
101 d = ctx.getImageData(250, 375, 1, 1).data;
102 shouldBe('d[0]', '0');
103 shouldBe('d[1]', '0');
104 shouldBe('d[2]', '0');
105 shouldBe('d[3]', '0');
106
107 d = ctx.getImageData(250, 525, 1, 1).data;
108 shouldBe('d[0]', '0');
109 shouldBe('d[1]', '0');
110 shouldBe('d[2]', '0');
111 shouldBe('d[3]', '0');
112
113 d = ctx.getImageData(175, 450, 1, 1).data;
114 shouldBe('d[0]', '0');
115 shouldBe('d[1]', '0');
116 shouldBe('d[2]', '0');
117 shouldBe('d[3]', '0');
118
119 d = ctx.getImageData(325, 450, 1, 1).data;
120 shouldBe('d[0]', '0');
121 shouldBe('d[1]', '0');
122 shouldBe('d[2]', '0');
123 shouldBe('d[3]', '0');
124
125 d = ctx.getImageData(250, 250, 1, 1).data;
126 shouldBe('d[0]', '255');
127 shouldBe('d[1]', '0');
128 shouldBe('d[2]', '0');
129 shouldBeAround('d[3]', '255');
130
131 // top right
132 d = ctx.getImageData(450, 250, 1, 1).data;
133 shouldBe('d[0]', '255');
134 shouldBe('d[1]', '0');
135 shouldBe('d[2]', '0');
136 shouldBeAround('d[3]', '255');
137
138 d = ctx.getImageData(450, 175, 1, 1).data;
139 shouldBe('d[0]', '0');
140 shouldBe('d[1]', '0');
141 shouldBe('d[2]', '0');
142 shouldBe('d[3]', '0');
143
144 d = ctx.getImageData(450, 325, 1, 1).data;
145 shouldBe('d[0]', '0');
146 shouldBe('d[1]', '0');
147 shouldBe('d[2]', '0');
148 shouldBe('d[3]', '0');
149
150 d = ctx.getImageData(375, 250, 1, 1).data;
151 shouldBe('d[0]', '0');
152 shouldBe('d[1]', '0');
153 shouldBe('d[2]', '0');
154 shouldBe('d[3]', '0');
155
156 d = ctx.getImageData(525, 250, 1, 1).data;
157 shouldBe('d[0]', '0');
158 shouldBe('d[1]', '0');
159 shouldBe('d[2]', '0');
160 shouldBe('d[3]', '0');
161
162 // top right
163 d = ctx.getImageData(450, 450, 1, 1).data;
164 shouldBe('d[0]', '255');
165 shouldBe('d[1]', '0');
166 shouldBe('d[2]', '0');
167 shouldBeAround('d[3]', '126');
168
169 d = ctx.getImageData(450, 375, 1, 1).data;
170 shouldBe('d[0]', '0');
171 shouldBe('d[1]', '0');
172 shouldBe('d[2]', '0');
173 shouldBe('d[3]', '0');
174
175 d = ctx.getImageData(450, 525, 1, 1).data;
176 shouldBe('d[0]', '0');
177 shouldBe('d[1]', '0');
178 shouldBe('d[2]', '0');
179 shouldBe('d[3]', '0');
180
181 d = ctx.getImageData(375, 450, 1, 1).data;
182 shouldBe('d[0]', '0');
183 shouldBe('d[1]', '0');
184 shouldBe('d[2]', '0');
185 shouldBe('d[3]', '0');
186
187 d = ctx.getImageData(525, 450, 1, 1).data;
188 shouldBe('d[0]', '0');
189 shouldBe('d[1]', '0');
190 shouldBe('d[2]', '0');
191 shouldBe('d[3]', '0');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698