OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes t.dart'; | 5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes t.dart'; |
6 import '../../pkg/unittest/lib/html_individual_config.dart'; | 6 import '../../pkg/unittest/lib/html_individual_config.dart'; |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:math'; | 8 import 'dart:math'; |
9 | 9 |
10 // Some rounding errors in the browsers. | 10 // Some rounding errors in the browsers. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 test('fillStyle linearGradient', () { | 152 test('fillStyle linearGradient', () { |
153 var gradient = context.createLinearGradient(0,0,20,20); | 153 var gradient = context.createLinearGradient(0,0,20,20); |
154 gradient.addColorStop(0,'red'); | 154 gradient.addColorStop(0,'red'); |
155 gradient.addColorStop(1,'blue'); | 155 gradient.addColorStop(1,'blue'); |
156 context.fillStyle = gradient; | 156 context.fillStyle = gradient; |
157 context.fillRect(0, 0, canvas.width, canvas.height); | 157 context.fillRect(0, 0, canvas.width, canvas.height); |
158 expect(context.fillStyle is CanvasGradient, isTrue); | 158 expect(context.fillStyle is CanvasGradient, isTrue); |
159 }); | 159 }); |
160 | 160 |
161 test('putImageData', () { | 161 test('putImageData', () { |
162 context.fillStyle = 'green'; | |
163 context.fillRect(0, 0, canvas.width, canvas.height); | |
164 | |
162 ImageData expectedData = context.getImageData(0, 0, 10, 10); | 165 ImageData expectedData = context.getImageData(0, 0, 10, 10); |
163 expectedData.data[0] = 25; | 166 expectedData.data[0] = 25; |
164 expectedData.data[1] = 65; | 167 expectedData.data[1] = 65; |
165 expectedData.data[2] = 255; | 168 expectedData.data[2] = 255; |
166 // Set alpha to 255 to make the pixels show up. | 169 // Set alpha to 255 to make the pixels show up. |
167 expectedData.data[3] = 255; | 170 expectedData.data[3] = 255; |
168 context.fillStyle = 'green'; | |
169 context.fillRect(0, 0, canvas.width, canvas.height); | |
170 | 171 |
171 context.putImageData(expectedData, 0, 0); | 172 context.putImageData(expectedData, 0, 0); |
172 | 173 |
173 var resultingData = context.getImageData(0, 0, 10, 10); | 174 var resultingData = context.getImageData(0, 0, 10, 10); |
174 // Make sure that we read back what we wrote. | 175 // Make sure that we read back what we wrote. |
175 expect(resultingData.data, expectedData.data); | 176 expect(resultingData.data, expectedData.data); |
176 }); | 177 }); |
178 | |
179 test('putImageData dirty rectangle', () { | |
180 context.fillStyle = 'green'; | |
181 context.fillRect(0, 0, canvas.width, canvas.height); | |
182 | |
183 ImageData drawnData = context.getImageData(0, 0, 10, 10); | |
184 drawnData.data[0] = 25; | |
185 drawnData.data[1] = 65; | |
186 drawnData.data[2] = 255; | |
187 // Set alpha to 255 to make the pixels show up. | |
188 drawnData.data[3] = 255; | |
189 | |
190 // Draw these pixels to the 8th pixel. | |
191 drawnData.data[9 * 4 + 0] = 25; | |
192 drawnData.data[9 * 4 + 1] = 65; | |
193 drawnData.data[9 * 4 + 2] = 255; | |
194 // Set alpha to 255 to make the pixels show up. | |
195 drawnData.data[9 * 4 + 3] = 255; | |
196 | |
197 // Use a dirty rectangle to limit what pixels are drawn. | |
198 context.putImageData(drawnData, 0, 0, 1, 1, 5, 5); | |
sra1
2013/05/09 22:11:20
Have a separate test for passing 4/5/6 arguments t
| |
199 | |
200 // Expect the data to be all green, as we skip all drawn pixels. | |
sra1
2013/05/09 22:11:20
Have one pixel actually change otherwise the test
| |
201 ImageData expectedData = context.createImageData(10, 10); | |
202 for (int i = 0; i < expectedData.data.length; i++) { | |
203 switch (i % 4) { | |
204 case 0: | |
205 expectedData.data[i] = 0; | |
206 break; | |
207 case 1: | |
208 expectedData.data[i] = 128; | |
209 break; | |
210 case 2: | |
211 expectedData.data[i] = 0; | |
212 break; | |
213 case 3: | |
214 expectedData.data[i] = 255; | |
215 break; | |
216 } | |
217 } | |
218 | |
219 // Make sure that our data is all green. | |
220 var resultingData = context.getImageData(0, 0, 10, 10); | |
221 expect(resultingData.data, expectedData.data); | |
222 }); | |
177 }); | 223 }); |
178 | 224 |
179 group('arc', () { | 225 group('arc', () { |
180 setUp(setupFunc); | 226 setUp(setupFunc); |
181 tearDown(tearDownFunc); | 227 tearDown(tearDownFunc); |
182 | 228 |
183 test('default arc should be clockwise', () { | 229 test('default arc should be clockwise', () { |
184 context.beginPath(); | 230 context.beginPath(); |
185 final r = 10; | 231 final r = 10; |
186 | 232 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 var imageData = context.createImageData(15, 15); | 642 var imageData = context.createImageData(15, 15); |
597 expect(imageData.width, 15); | 643 expect(imageData.width, 15); |
598 expect(imageData.height, 15); | 644 expect(imageData.height, 15); |
599 | 645 |
600 var other = context.createImageDataFromImageData(imageData); | 646 var other = context.createImageDataFromImageData(imageData); |
601 expect(other.width, 15); | 647 expect(other.width, 15); |
602 expect(other.height, 15); | 648 expect(other.height, 15); |
603 }); | 649 }); |
604 }); | 650 }); |
605 } | 651 } |
OLD | NEW |