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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 }); | 356 }); |
357 img.src = dataUrl; | 357 img.src = dataUrl; |
358 }); | 358 }); |
359 | 359 |
360 // Draw an image to the canvas from an image element and scale it. | 360 // Draw an image to the canvas from an image element and scale it. |
361 test('with 5 params', () { | 361 test('with 5 params', () { |
362 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 362 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
363 var img = new ImageElement(); | 363 var img = new ImageElement(); |
364 | 364 |
365 img.onLoad.listen(expectAsync1((_) { | 365 img.onLoad.listen(expectAsync1((_) { |
366 context.drawImageToRect(img, new Rect(50, 50, 20, 20)); | 366 context.drawImageToRect(img, new Rectangle(50, 50, 20, 20)); |
367 | 367 |
368 expectPixelFilled(50, 50); | 368 expectPixelFilled(50, 50); |
369 expectPixelFilled(55, 55); | 369 expectPixelFilled(55, 55); |
370 expectPixelFilled(59, 59); | 370 expectPixelFilled(59, 59); |
371 expectPixelFilled(60, 60); | 371 expectPixelFilled(60, 60); |
372 expectPixelFilled(69, 69); | 372 expectPixelFilled(69, 69); |
373 expectPixelUnfilled(70, 70); | 373 expectPixelUnfilled(70, 70); |
374 expectPixelUnfilled(0, 0); | 374 expectPixelUnfilled(0, 0); |
375 expectPixelUnfilled(80, 80); | 375 expectPixelUnfilled(80, 80); |
376 })); | 376 })); |
377 img.onError.listen((_) { | 377 img.onError.listen((_) { |
378 guardAsync(() { | 378 guardAsync(() { |
379 fail('URL failed to load.'); | 379 fail('URL failed to load.'); |
380 }); | 380 }); |
381 }); | 381 }); |
382 img.src = dataUrl; | 382 img.src = dataUrl; |
383 }); | 383 }); |
384 | 384 |
385 // Draw an image to the canvas from an image element and scale it. | 385 // Draw an image to the canvas from an image element and scale it. |
386 test('with 9 params', () { | 386 test('with 9 params', () { |
387 otherContext.fillStyle = "blue"; | 387 otherContext.fillStyle = "blue"; |
388 otherContext.fillRect(5, 5, 5, 5); | 388 otherContext.fillRect(5, 5, 5, 5); |
389 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 389 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
390 var img = new ImageElement(); | 390 var img = new ImageElement(); |
391 | 391 |
392 img.onLoad.listen(expectAsync1((_) { | 392 img.onLoad.listen(expectAsync1((_) { |
393 // This will take a 6x6 square from the first canvas from position 2,2 | 393 // This will take a 6x6 square from the first canvas from position 2,2 |
394 // and then scale it to a 20x20 square and place it to the second | 394 // and then scale it to a 20x20 square and place it to the second |
395 // canvas at 50,50. | 395 // canvas at 50,50. |
396 context.drawImageToRect(img, new Rect(50, 50, 20, 20), | 396 context.drawImageToRect(img, new Rectangle(50, 50, 20, 20), |
397 sourceRect: new Rect(2, 2, 6, 6)); | 397 sourceRect: new Rectangle(2, 2, 6, 6)); |
398 | 398 |
399 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 399 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
400 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 400 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
401 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 401 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
402 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 402 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
403 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 403 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
404 | 404 |
405 expectPixelFilled(50, 50); | 405 expectPixelFilled(50, 50); |
406 expectPixelFilled(55, 55); | 406 expectPixelFilled(55, 55); |
407 expectPixelFilled(59, 59); | 407 expectPixelFilled(59, 59); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', | 504 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', |
505 null) != '') { | 505 null) != '') { |
506 video.src = mp4VideoUrl; | 506 video.src = mp4VideoUrl; |
507 } else { | 507 } else { |
508 window.console.log('Video is not supported on this system.'); | 508 window.console.log('Video is not supported on this system.'); |
509 } | 509 } |
510 }); | 510 }); |
511 | 511 |
512 test('with 5 params', () { | 512 test('with 5 params', () { |
513 video.onCanPlay.listen(expectAsync1((_) { | 513 video.onCanPlay.listen(expectAsync1((_) { |
514 context.drawImageToRect(video, new Rect(50, 50, 20, 20)); | 514 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20)); |
515 | 515 |
516 expectPixelFilled(50, 50); | 516 expectPixelFilled(50, 50); |
517 expectPixelFilled(55, 55); | 517 expectPixelFilled(55, 55); |
518 expectPixelFilled(59, 59); | 518 expectPixelFilled(59, 59); |
519 expectPixelFilled(60, 60); | 519 expectPixelFilled(60, 60); |
520 expectPixelFilled(69, 69); | 520 expectPixelFilled(69, 69); |
521 expectPixelUnfilled(70, 70); | 521 expectPixelUnfilled(70, 70); |
522 expectPixelUnfilled(0, 0); | 522 expectPixelUnfilled(0, 0); |
523 expectPixelUnfilled(80, 80); | 523 expectPixelUnfilled(80, 80); |
524 })); | 524 })); |
525 video.onError.listen((_) { | 525 video.onError.listen((_) { |
526 guardAsync(() { | 526 guardAsync(() { |
527 fail('URL failed to load.'); | 527 fail('URL failed to load.'); |
528 }); | 528 }); |
529 }); | 529 }); |
530 | 530 |
531 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { | 531 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { |
532 video.src = webmVideoUrl; | 532 video.src = webmVideoUrl; |
533 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', | 533 } else if(video.canPlayType('video/mp4; codecs="avc1.4D401E, mp4a.40.2"', |
534 null) != '') { | 534 null) != '') { |
535 video.src = mp4VideoUrl; | 535 video.src = mp4VideoUrl; |
536 } else { | 536 } else { |
537 // TODO(amouravski): Better fallback? | 537 // TODO(amouravski): Better fallback? |
538 window.console.log('Video is not supported on this system.'); | 538 window.console.log('Video is not supported on this system.'); |
539 } | 539 } |
540 }); | 540 }); |
541 | 541 |
542 test('with 9 params', () { | 542 test('with 9 params', () { |
543 video.onCanPlay.listen(expectAsync1((_) { | 543 video.onCanPlay.listen(expectAsync1((_) { |
544 context.drawImageToRect(video, new Rect(50, 50, 20, 20), | 544 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20), |
545 sourceRect: new Rect(2, 2, 6, 6)); | 545 sourceRect: new Rectangle(2, 2, 6, 6)); |
546 | 546 |
547 expectPixelFilled(50, 50); | 547 expectPixelFilled(50, 50); |
548 expectPixelFilled(55, 55); | 548 expectPixelFilled(55, 55); |
549 expectPixelFilled(59, 59); | 549 expectPixelFilled(59, 59); |
550 expectPixelFilled(60, 60); | 550 expectPixelFilled(60, 60); |
551 expectPixelFilled(69, 69); | 551 expectPixelFilled(69, 69); |
552 expectPixelUnfilled(70, 70); | 552 expectPixelUnfilled(70, 70); |
553 expectPixelUnfilled(0, 0); | 553 expectPixelUnfilled(0, 0); |
554 expectPixelUnfilled(80, 80); | 554 expectPixelUnfilled(80, 80); |
555 })); | 555 })); |
(...skipping 16 matching lines...) Expand all Loading... |
572 }); | 572 }); |
573 | 573 |
574 group('drawImage_video_element_dataUrl', () { | 574 group('drawImage_video_element_dataUrl', () { |
575 setUp(setupFunc); | 575 setUp(setupFunc); |
576 tearDown(tearDownFunc); | 576 tearDown(tearDownFunc); |
577 | 577 |
578 test('with 9 params', () { | 578 test('with 9 params', () { |
579 video = new VideoElement(); | 579 video = new VideoElement(); |
580 canvas = new CanvasElement(); | 580 canvas = new CanvasElement(); |
581 video.onCanPlay.listen(expectAsync1((_) { | 581 video.onCanPlay.listen(expectAsync1((_) { |
582 context.drawImageToRect(video, new Rect(50, 50, 20, 20), | 582 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20), |
583 sourceRect: new Rect(2, 2, 6, 6)); | 583 sourceRect: new Rectangle(2, 2, 6, 6)); |
584 | 584 |
585 expectPixelFilled(50, 50); | 585 expectPixelFilled(50, 50); |
586 expectPixelFilled(55, 55); | 586 expectPixelFilled(55, 55); |
587 expectPixelFilled(59, 59); | 587 expectPixelFilled(59, 59); |
588 expectPixelFilled(60, 60); | 588 expectPixelFilled(60, 60); |
589 expectPixelFilled(69, 69); | 589 expectPixelFilled(69, 69); |
590 expectPixelUnfilled(70, 70); | 590 expectPixelUnfilled(70, 70); |
591 expectPixelUnfilled(0, 0); | 591 expectPixelUnfilled(0, 0); |
592 expectPixelUnfilled(80, 80); | 592 expectPixelUnfilled(80, 80); |
593 })); | 593 })); |
(...skipping 25 matching lines...) Expand all Loading... |
619 | 619 |
620 expectPixelFilled(50, 50); | 620 expectPixelFilled(50, 50); |
621 expectPixelFilled(55, 55); | 621 expectPixelFilled(55, 55); |
622 expectPixelFilled(59, 59); | 622 expectPixelFilled(59, 59); |
623 expectPixelUnfilled(60, 60); | 623 expectPixelUnfilled(60, 60); |
624 expectPixelUnfilled(0, 0); | 624 expectPixelUnfilled(0, 0); |
625 expectPixelUnfilled(70, 70); | 625 expectPixelUnfilled(70, 70); |
626 }); | 626 }); |
627 test('with 5 params', () { | 627 test('with 5 params', () { |
628 // Draw an image to the canvas from a canvas element. | 628 // Draw an image to the canvas from a canvas element. |
629 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20)); | 629 context.drawImageToRect(otherCanvas, new Rectangle(50, 50, 20, 20)); |
630 | 630 |
631 expectPixelFilled(50, 50); | 631 expectPixelFilled(50, 50); |
632 expectPixelFilled(55, 55); | 632 expectPixelFilled(55, 55); |
633 expectPixelFilled(59, 59); | 633 expectPixelFilled(59, 59); |
634 expectPixelFilled(60, 60); | 634 expectPixelFilled(60, 60); |
635 expectPixelFilled(69, 69); | 635 expectPixelFilled(69, 69); |
636 expectPixelUnfilled(70, 70); | 636 expectPixelUnfilled(70, 70); |
637 expectPixelUnfilled(0, 0); | 637 expectPixelUnfilled(0, 0); |
638 expectPixelUnfilled(80, 80); | 638 expectPixelUnfilled(80, 80); |
639 }); | 639 }); |
640 test('with 9 params', () { | 640 test('with 9 params', () { |
641 // Draw an image to the canvas from a canvas element. | 641 // Draw an image to the canvas from a canvas element. |
642 otherContext.fillStyle = "blue"; | 642 otherContext.fillStyle = "blue"; |
643 otherContext.fillRect(5, 5, 5, 5); | 643 otherContext.fillRect(5, 5, 5, 5); |
644 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20), | 644 context.drawImageToRect(otherCanvas, new Rectangle(50, 50, 20, 20), |
645 sourceRect: new Rect(2, 2, 6, 6)); | 645 sourceRect: new Rectangle(2, 2, 6, 6)); |
646 | 646 |
647 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 647 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
648 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 648 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
649 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 649 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
650 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 650 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
651 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 651 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
652 expectPixelFilled(50, 50); | 652 expectPixelFilled(50, 50); |
653 expectPixelFilled(55, 55); | 653 expectPixelFilled(55, 55); |
654 expectPixelFilled(59, 59); | 654 expectPixelFilled(59, 59); |
655 expectPixelFilled(60, 60); | 655 expectPixelFilled(60, 60); |
(...skipping 12 matching lines...) Expand all Loading... |
668 expect(other.width, 15); | 668 expect(other.width, 15); |
669 expect(other.height, 15); | 669 expect(other.height, 15); |
670 }); | 670 }); |
671 | 671 |
672 test('createPattern', () { | 672 test('createPattern', () { |
673 var pattern = context.createPattern(new CanvasElement(), ''); | 673 var pattern = context.createPattern(new CanvasElement(), ''); |
674 //var pattern2 = context.createPatternFromImage(new ImageElement(), ''); | 674 //var pattern2 = context.createPatternFromImage(new ImageElement(), ''); |
675 }); | 675 }); |
676 }); | 676 }); |
677 } | 677 } |
OLD | NEW |