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; | 5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes
t.dart'; |
6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/html_individual_config.dart'; |
7 import '../../pkg/unittest/lib/html_config.dart'; | |
8 import 'dart:html'; | 7 import 'dart:html'; |
9 import 'dart:math'; | 8 import 'dart:math'; |
10 | 9 |
11 // Some rounding errors in the browsers. | 10 // Some rounding errors in the browsers. |
12 checkPixel(List<int> pixel, List<int> expected) { | 11 checkPixel(List<int> pixel, List<int> expected) { |
13 expect(pixel[0], closeTo(expected[0], 2)); | 12 expect(pixel[0], closeTo(expected[0], 2)); |
14 expect(pixel[1], closeTo(expected[1], 2)); | 13 expect(pixel[1], closeTo(expected[1], 2)); |
15 expect(pixel[2], closeTo(expected[2], 2)); | 14 expect(pixel[2], closeTo(expected[2], 2)); |
16 expect(pixel[3], closeTo(expected[3], 2)); | 15 expect(pixel[3], closeTo(expected[3], 2)); |
17 } | 16 } |
18 | 17 |
| 18 var canvas; |
| 19 var context; |
| 20 var otherCanvas; |
| 21 var otherContext; |
| 22 var video; |
| 23 |
| 24 void createCanvas() { |
| 25 canvas = new CanvasElement(); |
| 26 canvas.width = 100; |
| 27 canvas.height = 100; |
| 28 |
| 29 context = canvas.context2d; |
| 30 } |
| 31 |
| 32 void createOtherCanvas() { |
| 33 otherCanvas = new CanvasElement(); |
| 34 otherCanvas.width = 10; |
| 35 otherCanvas.height = 10; |
| 36 otherContext = otherCanvas.context2d; |
| 37 otherContext.fillStyle = "red"; |
| 38 otherContext.fillRect(0, 0, otherCanvas.width, otherCanvas.height); |
| 39 } |
| 40 |
| 41 void setupFunc() { |
| 42 createCanvas(); |
| 43 createOtherCanvas(); |
| 44 video = new VideoElement(); |
| 45 } |
| 46 |
| 47 void tearDownFunc() { |
| 48 canvas = null; |
| 49 context = null; |
| 50 otherCanvas = null; |
| 51 otherContext = null; |
| 52 video = null; |
| 53 } |
| 54 |
| 55 List<int> readPixel(int x, int y) { |
| 56 var imageData = context.getImageData(x, y, 1, 1); |
| 57 return imageData.data; |
| 58 } |
| 59 |
| 60 /// Returns true if the pixel has some data in it, false otherwise. |
| 61 bool isPixelFilled(int x, int y) => readPixel(x,y).any((p) => p != 0); |
| 62 |
| 63 String pixelDataToString(List<int> data, int x, int y) { |
| 64 return '[${data.join(", ")}]'; |
| 65 } |
| 66 |
| 67 String _filled(bool v) => v ? "filled" : "unfilled"; |
| 68 |
| 69 void expectPixelFilled(int x, int y, [bool filled = true]) { |
| 70 expect(isPixelFilled(x, y), filled, reason: |
| 71 'Pixel at ($x, $y) was expected to' |
| 72 ' be: <${_filled(filled)}> but was: <${_filled(!filled)}> with data: ' |
| 73 '${pixelDataToString(readPixel(x, y), x, y)}'); |
| 74 } |
| 75 |
| 76 void expectPixelUnfilled(int x, int y) { |
| 77 expectPixelFilled(x, y, false); |
| 78 } |
| 79 |
19 main() { | 80 main() { |
20 useHtmlConfiguration(); | 81 useHtmlIndividualConfiguration(); |
21 | 82 |
22 group('canvasRenderingContext2d', () { | 83 group('pixel_manipulation', () { |
23 var canvas; | 84 setUp(setupFunc); |
24 var context; | 85 tearDown(tearDownFunc); |
25 var otherCanvas; | |
26 var otherContext; | |
27 | |
28 void createOtherCanvas() { | |
29 otherCanvas = new CanvasElement(); | |
30 otherCanvas.width = 10; | |
31 otherCanvas.height = 10; | |
32 otherContext = otherCanvas.context2d; | |
33 otherContext.fillStyle = "red"; | |
34 otherContext.fillRect(0, 0, otherCanvas.width, otherCanvas.height); | |
35 } | |
36 | |
37 setUp(() { | |
38 canvas = new CanvasElement(); | |
39 canvas.width = 100; | |
40 canvas.height = 100; | |
41 | |
42 context = canvas.context2d; | |
43 | |
44 createOtherCanvas(); | |
45 }); | |
46 | |
47 tearDown(() { | |
48 canvas = null; | |
49 context = null; | |
50 otherCanvas = null; | |
51 otherContext = null; | |
52 }); | |
53 | |
54 List<int> readPixel(int x, int y) { | |
55 var imageData = context.getImageData(x, y, 1, 1); | |
56 return imageData.data; | |
57 } | |
58 | |
59 /// Returns true if the pixel has some data in it, false otherwise. | |
60 bool isPixelFilled(int x, int y) => readPixel(x,y).any((p) => p != 0); | |
61 | |
62 String pixelDataToString(int x, int y) { | |
63 var data = readPixel(x, y); | |
64 | |
65 return '[${data.join(", ")}]'; | |
66 } | |
67 | |
68 String _filled(bool v) => v ? "filled" : "unfilled"; | |
69 | |
70 void expectPixelFilled(int x, int y, [bool filled = true]) { | |
71 expect(isPixelFilled(x, y), filled, reason: | |
72 'Pixel at ($x, $y) was expected to' | |
73 ' be: <${_filled(filled)}> but was: <${_filled(!filled)}> with data: ' | |
74 '${pixelDataToString(x,y)}'); | |
75 } | |
76 | |
77 void expectPixelUnfilled(int x, int y) { | |
78 expectPixelFilled(x, y, false); | |
79 } | |
80 | |
81 | 86 |
82 test('setFillColorRgb', () { | 87 test('setFillColorRgb', () { |
83 context.setFillColorRgb(255, 0, 255, 1); | 88 context.setFillColorRgb(255, 0, 255, 1); |
84 context.fillRect(0, 0, canvas.width, canvas.height); | 89 context.fillRect(0, 0, canvas.width, canvas.height); |
85 expect(readPixel(2, 2), [255, 0, 255, 255]); | 90 expect(readPixel(2, 2), [255, 0, 255, 255]); |
86 }); | 91 }); |
87 | 92 |
88 test('setFillColorHsl hue', () { | 93 test('setFillColorHsl hue', () { |
89 context.setFillColorHsl(0, 100, 50); | 94 context.setFillColorHsl(0, 100, 50); |
90 context.fillRect(0, 0, canvas.width, canvas.height); | 95 context.fillRect(0, 0, canvas.width, canvas.height); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 expectedData.data[3] = 255; | 167 expectedData.data[3] = 255; |
163 context.fillStyle = 'green'; | 168 context.fillStyle = 'green'; |
164 context.fillRect(0, 0, canvas.width, canvas.height); | 169 context.fillRect(0, 0, canvas.width, canvas.height); |
165 | 170 |
166 context.putImageData(expectedData, 0, 0); | 171 context.putImageData(expectedData, 0, 0); |
167 | 172 |
168 var resultingData = context.getImageData(0, 0, 10, 10); | 173 var resultingData = context.getImageData(0, 0, 10, 10); |
169 // Make sure that we read back what we wrote. | 174 // Make sure that we read back what we wrote. |
170 expect(resultingData.data, expectedData.data); | 175 expect(resultingData.data, expectedData.data); |
171 }); | 176 }); |
| 177 }); |
| 178 |
| 179 group('arc', () { |
| 180 setUp(setupFunc); |
| 181 tearDown(tearDownFunc); |
172 | 182 |
173 test('default arc should be clockwise', () { | 183 test('default arc should be clockwise', () { |
174 context.beginPath(); | 184 context.beginPath(); |
175 final r = 10; | 185 final r = 10; |
176 | 186 |
177 // Center of arc. | 187 // Center of arc. |
178 final cx = 20; | 188 final cx = 20; |
179 final cy = 20; | 189 final cy = 20; |
180 // Arc centered at (20, 20) with radius 10 will go clockwise | 190 // Arc centered at (20, 20) with radius 10 will go clockwise |
181 // from (20 + r, 20) to (20, 20 + r), which is 1/4 of a circle. | 191 // from (20 + r, 20) to (20, 20 + r), which is 1/4 of a circle. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 255 |
246 // (cx - r/SQRT2, cy - r/SQRT2) should be filled. | 256 // (cx - r/SQRT2, cy - r/SQRT2) should be filled. |
247 expectPixelFilled((cx - r/SQRT2).toInt(), (cy + r/SQRT2).toInt(), true); | 257 expectPixelFilled((cx - r/SQRT2).toInt(), (cy + r/SQRT2).toInt(), true); |
248 | 258 |
249 // (cx + r/SQRT2, cy + r/SQRT2) should be filled. | 259 // (cx + r/SQRT2, cy + r/SQRT2) should be filled. |
250 expectPixelFilled((cx - r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), true); | 260 expectPixelFilled((cx - r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), true); |
251 | 261 |
252 // (cx - r/SQRT2, cy - r/SQRT2) should be filled. | 262 // (cx - r/SQRT2, cy - r/SQRT2) should be filled. |
253 expectPixelFilled((cx + r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), true); | 263 expectPixelFilled((cx + r/SQRT2).toInt(), (cy - r/SQRT2).toInt(), true); |
254 }); | 264 }); |
| 265 }); |
255 | 266 |
| 267 group('drawImage_image_element', () { |
| 268 setUp(setupFunc); |
| 269 tearDown(tearDownFunc); |
256 // Draw an image to the canvas from an image element. | 270 // Draw an image to the canvas from an image element. |
257 test('drawImage from img element with 3 params', () { | 271 test('with 3 params', () { |
258 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 272 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
259 var img = new ImageElement(); | 273 var img = new ImageElement(); |
260 | 274 |
261 img.onLoad.listen(expectAsync1((_) { | 275 img.onLoad.listen(expectAsync1((_) { |
262 context.drawImage(img, 50, 50); | 276 context.drawImage(img, 50, 50); |
263 | 277 |
264 expectPixelFilled(50, 50); | 278 expectPixelFilled(50, 50); |
265 expectPixelFilled(55, 55); | 279 expectPixelFilled(55, 55); |
266 expectPixelFilled(59, 59); | 280 expectPixelFilled(59, 59); |
267 expectPixelUnfilled(60, 60); | 281 expectPixelUnfilled(60, 60); |
268 expectPixelUnfilled(0, 0); | 282 expectPixelUnfilled(0, 0); |
269 expectPixelUnfilled(70, 70); | 283 expectPixelUnfilled(70, 70); |
270 })); | 284 })); |
271 img.onError.listen((_) { | 285 img.onError.listen((_) { |
272 guardAsync(() { | 286 guardAsync(() { |
273 fail('URL failed to load.'); | 287 fail('URL failed to load.'); |
274 }); | 288 }); |
275 }); | 289 }); |
276 img.src = dataUrl; | 290 img.src = dataUrl; |
277 }); | 291 }); |
278 | 292 |
279 // Draw an image to the canvas from an image element and scale it. | 293 // Draw an image to the canvas from an image element and scale it. |
280 test('drawImage from img element with 5 params', () { | 294 test('with 5 params', () { |
281 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 295 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
282 var img = new ImageElement(); | 296 var img = new ImageElement(); |
283 | 297 |
284 img.onLoad.listen(expectAsync1((_) { | 298 img.onLoad.listen(expectAsync1((_) { |
285 context.drawImageToRect(img, new Rect(50, 50, 20, 20)); | 299 context.drawImageToRect(img, new Rect(50, 50, 20, 20)); |
286 | 300 |
287 expectPixelFilled(50, 50); | 301 expectPixelFilled(50, 50); |
288 expectPixelFilled(55, 55); | 302 expectPixelFilled(55, 55); |
289 expectPixelFilled(59, 59); | 303 expectPixelFilled(59, 59); |
290 expectPixelFilled(60, 60); | 304 expectPixelFilled(60, 60); |
291 expectPixelFilled(69, 69); | 305 expectPixelFilled(69, 69); |
292 expectPixelUnfilled(70, 70); | 306 expectPixelUnfilled(70, 70); |
293 expectPixelUnfilled(0, 0); | 307 expectPixelUnfilled(0, 0); |
294 expectPixelUnfilled(80, 80); | 308 expectPixelUnfilled(80, 80); |
295 })); | 309 })); |
296 img.onError.listen((_) { | 310 img.onError.listen((_) { |
297 guardAsync(() { | 311 guardAsync(() { |
298 fail('URL failed to load.'); | 312 fail('URL failed to load.'); |
299 }); | 313 }); |
300 }); | 314 }); |
301 img.src = dataUrl; | 315 img.src = dataUrl; |
302 }); | 316 }); |
303 | 317 |
304 // Draw an image to the canvas from an image element and scale it. | 318 // Draw an image to the canvas from an image element and scale it. |
305 test('drawImage from img element with 9 params', () { | 319 test('with 9 params', () { |
306 otherContext.fillStyle = "blue"; | 320 otherContext.fillStyle = "blue"; |
307 otherContext.fillRect(5, 5, 5, 5); | 321 otherContext.fillRect(5, 5, 5, 5); |
308 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 322 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
309 var img = new ImageElement(); | 323 var img = new ImageElement(); |
310 | 324 |
311 img.onLoad.listen(expectAsync1((_) { | 325 img.onLoad.listen(expectAsync1((_) { |
312 // This will take a 6x6 square from the first canvas from position 2,2 | 326 // This will take a 6x6 square from the first canvas from position 2,2 |
313 // and then scale it to a 20x20 square and place it to the second canvas | 327 // and then scale it to a 20x20 square and place it to the second |
314 // at 50,50. | 328 // canvas at 50,50. |
315 context.drawImageToRect(img, new Rect(50, 50, 20, 20), | 329 context.drawImageToRect(img, new Rect(50, 50, 20, 20), |
316 sourceRect: new Rect(2, 2, 6, 6)); | 330 sourceRect: new Rect(2, 2, 6, 6)); |
317 | 331 |
318 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 332 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
319 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 333 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
320 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 334 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
321 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 335 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
322 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 336 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
323 | 337 |
324 expectPixelFilled(50, 50); | 338 expectPixelFilled(50, 50); |
325 expectPixelFilled(55, 55); | 339 expectPixelFilled(55, 55); |
326 expectPixelFilled(59, 59); | 340 expectPixelFilled(59, 59); |
327 expectPixelFilled(60, 60); | 341 expectPixelFilled(60, 60); |
328 expectPixelFilled(69, 69); | 342 expectPixelFilled(69, 69); |
329 expectPixelUnfilled(70, 70); | 343 expectPixelUnfilled(70, 70); |
330 expectPixelUnfilled(0, 0); | 344 expectPixelUnfilled(0, 0); |
331 expectPixelUnfilled(80, 80); | 345 expectPixelUnfilled(80, 80); |
332 })); | 346 })); |
333 img.onError.listen((_) { | 347 img.onError.listen((_) { |
334 guardAsync(() { | 348 guardAsync(() { |
335 fail('URL failed to load.'); | 349 fail('URL failed to load.'); |
336 }); | 350 }); |
337 }); | 351 }); |
338 img.src = dataUrl; | 352 img.src = dataUrl; |
339 }); | 353 }); |
340 | 354 }); |
341 // These base64 strings are the same video, representing 2 frames of 8x8 red | 355 |
342 // pixels. | 356 // These videos and base64 strings are the same video, representing 2 |
343 // The videos were created with: | 357 // frames of 8x8 red pixels. |
344 // convert -size 8x8 xc:red blank1.jpg | 358 // The videos were created with: |
345 // convert -size 8x8 xc:red blank2.jpg | 359 // convert -size 8x8 xc:red blank1.jpg |
346 // avconv -f image2 -i "blank%d.jpg" -c:v libx264 small.mp4 | 360 // convert -size 8x8 xc:red blank2.jpg |
347 // python -m base64 -e small.mp4 | 361 // avconv -f image2 -i "blank%d.jpg" -c:v libx264 small.mp4 |
348 // avconv -i small.mp4 small.webm | 362 // avconv -i small.mp4 small.webm |
349 // python -m base64 -e small.webm | 363 // python -m base64 -e small.mp4 |
350 var mp4VideoUrl = | 364 // python -m base64 -e small.webm |
351 'data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZn' | 365 var mp4VideoUrl = '/root_dart/tests/html/small.mp4'; |
352 'JlZQAAAsdtZGF0AAACmwYF//+X3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDEyMCByMj' | 366 var webmVideoUrl = '/root_dart/tests/html/small.webm'; |
353 'E1MSBhM2Y0NDA3IC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMj' | 367 var mp4VideoDataUrl = |
354 'AxMSAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYm' | 368 'data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAA' |
355 'FjPTEgcmVmPTMgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MToweDExMSBtZT1oZXggc3VibW' | 369 'AIZnJlZQAAAsdtZGF0AAACmwYF//+X3EXpvebZSLeWLNgg2SP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gv9AAIAAAcU7trAQAAAAAAAA67jLOBALeH94EB8YIBfw=='; | 406 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmAQAAAAAAA' |
393 | 407 'EEq17GDD0JATYCLTGF2ZjUzLjIxLjFXQYtMYXZmNTMuMjEuMXOkkJatuHwTJ7cvFLSzB' |
394 // test('drawImage from video element with 3 params', () { | 408 'Smxbp5EiYhAVAAAAAAAABZUrmsBAAAAAAAAR64BAAAAAAAAPteBAXPFgQGcgQAitZyDd' |
395 // var video = new VideoElement(); | 409 'W5khoVWX1ZQOIOBASPjg4QCYloA4AEAAAAAAAASsIEIuoEIVLCBCFS6gQhUsoEDH0O2d' |
396 // | 410 'QEAAAAAAABZ54EAo72BAACA8AIAnQEqCAAIAABHCIWFiIWEiAICAnWqA/gD+gINTRgA/' |
397 // video.onLoadedData.listen(expectAsync1((_) { | 411 'v0hRf/kb+PnRv/I4//8WE8DijI//FRAo5WBACgAsQEAARAQABgAGFgv9AAIAAAcU7trA' |
398 // context.drawImage(video, 50, 50); | 412 'QAAAAAAAA67jLOBALeH94EB8YIBfw=='; |
399 // | 413 group('drawImage_video_element', () { |
400 // expectPixelFilled(50, 50); | 414 setUp(setupFunc); |
401 // expectPixelFilled(54, 54); | 415 tearDown(tearDownFunc); |
402 // expectPixelFilled(57, 57); | 416 |
403 // expectPixelUnfilled(58, 58); | 417 test('with 3 params', () { |
404 // expectPixelUnfilled(0, 0); | 418 video.onCanPlay.listen(expectAsync1((_) { |
405 // expectPixelUnfilled(70, 70); | 419 context.drawImage(video, 50, 50); |
406 // })); | 420 |
407 // video.onError.listen((_) { | 421 expectPixelFilled(50, 50); |
408 // guardAsync(() { | 422 expectPixelFilled(54, 54); |
409 // fail('URL failed to load.'); | 423 expectPixelFilled(57, 57); |
410 // }); | 424 expectPixelUnfilled(58, 58); |
411 // }); | 425 expectPixelUnfilled(0, 0); |
412 // | 426 expectPixelUnfilled(70, 70); |
413 // if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { | 427 })); |
414 // video.src = webmVideoUrl; | 428 |
415 // } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"'
, | 429 video.onError.listen((_) { |
416 // null) != '') { | 430 guardAsync(() { |
417 // video.src = mp4VideoUrl; | 431 fail('URL failed to load.'); |
418 // } else { | 432 }); |
419 // logMessage('Video is not supported on this system.'); | 433 }); |
420 // } | 434 |
421 // }); | 435 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { |
422 // | 436 video.src = webmVideoUrl; |
423 // test('drawImage from video element with 5 params', () { | 437 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', |
424 // var video = new VideoElement(); | 438 null) != '') { |
425 // | 439 video.src = mp4VideoUrl; |
426 // video.onLoadedData.listen(expectAsync1((_) { | 440 } else { |
427 // context.drawImageToRect(video, new Rect(50, 50, 20, 20)); | 441 window.console.log('Video is not supported on this system.'); |
428 // | 442 } |
429 // expectPixelFilled(50, 50); | 443 }); |
430 // expectPixelFilled(55, 55); | 444 |
431 // expectPixelFilled(59, 59); | 445 test('with 5 params', () { |
432 // expectPixelFilled(60, 60); | 446 video.onCanPlay.listen(expectAsync1((_) { |
433 // expectPixelFilled(69, 69); | 447 context.drawImageToRect(video, new Rect(50, 50, 20, 20)); |
434 // expectPixelUnfilled(70, 70); | 448 |
435 // expectPixelUnfilled(0, 0); | 449 expectPixelFilled(50, 50); |
436 // expectPixelUnfilled(80, 80); | 450 expectPixelFilled(55, 55); |
437 // })); | 451 expectPixelFilled(59, 59); |
438 // video.onError.listen((_) { | 452 expectPixelFilled(60, 60); |
439 // guardAsync(() { | 453 expectPixelFilled(69, 69); |
440 // fail('URL failed to load.'); | 454 expectPixelUnfilled(70, 70); |
441 // }); | 455 expectPixelUnfilled(0, 0); |
442 // }); | 456 expectPixelUnfilled(80, 80); |
443 // | 457 })); |
444 // if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { | 458 video.onError.listen((_) { |
445 // video.src = webmVideoUrl; | 459 guardAsync(() { |
446 // } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"'
, | 460 fail('URL failed to load.'); |
447 // null) != '') { | 461 }); |
448 // video.src = mp4VideoUrl; | 462 }); |
449 // } else { | 463 |
450 // // TODO(amouravski): Better fallback? | 464 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { |
451 // logMessage('Video is not supported on this system.'); | 465 video.src = webmVideoUrl; |
452 // } | 466 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', |
453 // }); | 467 null) != '') { |
454 // | 468 video.src = mp4VideoUrl; |
455 // test('drawImage from video element with 9 params', () { | 469 } else { |
456 // var video = new VideoElement(); | 470 // TODO(amouravski): Better fallback? |
457 // | 471 window.console.log('Video is not supported on this system.'); |
458 // video.onLoadedData.listen(expectAsync1((_) { | 472 } |
459 // context.drawImageToRect(video, new Rect(50, 50, 20, 20), | 473 }); |
460 // sourceRect: new Rect(2, 2, 6, 6)); | 474 |
461 // | 475 test('with 9 params', () { |
462 // expectPixelFilled(50, 50); | 476 video.onCanPlay.listen(expectAsync1((_) { |
463 // expectPixelFilled(55, 55); | 477 context.drawImageToRect(video, new Rect(50, 50, 20, 20), |
464 // expectPixelFilled(59, 59); | 478 sourceRect: new Rect(2, 2, 6, 6)); |
465 // expectPixelFilled(60, 60); | 479 |
466 // expectPixelFilled(69, 69); | 480 expectPixelFilled(50, 50); |
467 // expectPixelUnfilled(70, 70); | 481 expectPixelFilled(55, 55); |
468 // expectPixelUnfilled(0, 0); | 482 expectPixelFilled(59, 59); |
469 // expectPixelUnfilled(80, 80); | 483 expectPixelFilled(60, 60); |
470 // })); | 484 expectPixelFilled(69, 69); |
471 // video.onError.listen((_) { | 485 expectPixelUnfilled(70, 70); |
472 // guardAsync(() { | 486 expectPixelUnfilled(0, 0); |
473 // fail('URL failed to load.'); | 487 expectPixelUnfilled(80, 80); |
474 // }); | 488 })); |
475 // }); | 489 video.onError.listen((_) { |
476 // | 490 guardAsync(() { |
477 // if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { | 491 fail('URL failed to load.'); |
478 // video.src = webmVideoUrl; | 492 }); |
479 // } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"'
, | 493 }); |
480 // null) != '') { | 494 |
481 // video.src = mp4VideoUrl; | 495 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { |
482 // } else { | 496 video.src = webmVideoUrl; |
483 // // TODO(amouravski): Better fallback? | 497 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', |
484 // logMessage('Video is not supported on this system.'); | 498 null) != '') { |
485 // } | 499 video.src = mp4VideoUrl; |
486 // }); | 500 } else { |
487 | 501 // TODO(amouravski): Better fallback? |
488 test('drawImage from canvas element with 3 params', () { | 502 window.console.log('Video is not supported on this system.'); |
| 503 } |
| 504 }); |
| 505 }); |
| 506 |
| 507 group('drawImage_video_element_dataUrl', () { |
| 508 setUp(setupFunc); |
| 509 tearDown(tearDownFunc); |
| 510 |
| 511 test('with 9 params', () { |
| 512 video = new VideoElement(); |
| 513 canvas = new CanvasElement(); |
| 514 video.onCanPlay.listen(expectAsync1((_) { |
| 515 context.drawImageToRect(video, new Rect(50, 50, 20, 20), |
| 516 sourceRect: new Rect(2, 2, 6, 6)); |
| 517 |
| 518 expectPixelFilled(50, 50); |
| 519 expectPixelFilled(55, 55); |
| 520 expectPixelFilled(59, 59); |
| 521 expectPixelFilled(60, 60); |
| 522 expectPixelFilled(69, 69); |
| 523 expectPixelUnfilled(70, 70); |
| 524 expectPixelUnfilled(0, 0); |
| 525 expectPixelUnfilled(80, 80); |
| 526 })); |
| 527 video.onError.listen((_) { |
| 528 guardAsync(() { |
| 529 fail('URL failed to load.'); |
| 530 }); |
| 531 }); |
| 532 |
| 533 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { |
| 534 video.src = webmVideoDataUrl; |
| 535 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', |
| 536 null) != '') { |
| 537 video.src = mp4VideoDataUrl; |
| 538 } else { |
| 539 // TODO(amouravski): Better fallback? |
| 540 window.console.log('Video is not supported on this system.'); |
| 541 } |
| 542 }); |
| 543 }); |
| 544 |
| 545 group('drawImage_canvas_element', () { |
| 546 setUp(setupFunc); |
| 547 tearDown(tearDownFunc); |
| 548 |
| 549 test('with 3 params', () { |
489 // Draw an image to the canvas from a canvas element. | 550 // Draw an image to the canvas from a canvas element. |
490 context.drawImage(otherCanvas, 50, 50); | 551 context.drawImage(otherCanvas, 50, 50); |
491 | 552 |
492 expectPixelFilled(50, 50); | 553 expectPixelFilled(50, 50); |
493 expectPixelFilled(55, 55); | 554 expectPixelFilled(55, 55); |
494 expectPixelFilled(59, 59); | 555 expectPixelFilled(59, 59); |
495 expectPixelUnfilled(60, 60); | 556 expectPixelUnfilled(60, 60); |
496 expectPixelUnfilled(0, 0); | 557 expectPixelUnfilled(0, 0); |
497 expectPixelUnfilled(70, 70); | 558 expectPixelUnfilled(70, 70); |
498 }); | 559 }); |
499 test('drawImage from canvas element with 5 params', () { | 560 test('with 5 params', () { |
500 // Draw an image to the canvas from a canvas element. | 561 // Draw an image to the canvas from a canvas element. |
501 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20)); | 562 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20)); |
502 | 563 |
503 expectPixelFilled(50, 50); | 564 expectPixelFilled(50, 50); |
504 expectPixelFilled(55, 55); | 565 expectPixelFilled(55, 55); |
505 expectPixelFilled(59, 59); | 566 expectPixelFilled(59, 59); |
506 expectPixelFilled(60, 60); | 567 expectPixelFilled(60, 60); |
507 expectPixelFilled(69, 69); | 568 expectPixelFilled(69, 69); |
508 expectPixelUnfilled(70, 70); | 569 expectPixelUnfilled(70, 70); |
509 expectPixelUnfilled(0, 0); | 570 expectPixelUnfilled(0, 0); |
510 expectPixelUnfilled(80, 80); | 571 expectPixelUnfilled(80, 80); |
511 }); | 572 }); |
512 test('drawImage from canvas element with 9 params', () { | 573 test('with 9 params', () { |
513 // Draw an image to the canvas from a canvas element. | 574 // Draw an image to the canvas from a canvas element. |
514 otherContext.fillStyle = "blue"; | 575 otherContext.fillStyle = "blue"; |
515 otherContext.fillRect(5, 5, 5, 5); | 576 otherContext.fillRect(5, 5, 5, 5); |
516 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20), | 577 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20), |
517 sourceRect: new Rect(2, 2, 6, 6)); | 578 sourceRect: new Rect(2, 2, 6, 6)); |
518 | 579 |
519 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 580 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
520 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 581 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
521 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 582 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
522 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 583 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
523 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 584 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
524 expectPixelFilled(50, 50); | 585 expectPixelFilled(50, 50); |
525 expectPixelFilled(55, 55); | 586 expectPixelFilled(55, 55); |
526 expectPixelFilled(59, 59); | 587 expectPixelFilled(59, 59); |
527 expectPixelFilled(60, 60); | 588 expectPixelFilled(60, 60); |
528 expectPixelFilled(69, 69); | 589 expectPixelFilled(69, 69); |
529 expectPixelUnfilled(70, 70); | 590 expectPixelUnfilled(70, 70); |
530 expectPixelUnfilled(0, 0); | 591 expectPixelUnfilled(0, 0); |
531 expectPixelUnfilled(80, 80); | 592 expectPixelUnfilled(80, 80); |
532 }); | 593 }); |
533 }); | 594 }); |
534 } | 595 } |
OLD | NEW |