| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 }); | 332 }); |
| 333 | 333 |
| 334 group('drawImage_image_element', () { | 334 group('drawImage_image_element', () { |
| 335 setUp(setupFunc); | 335 setUp(setupFunc); |
| 336 tearDown(tearDownFunc); | 336 tearDown(tearDownFunc); |
| 337 // Draw an image to the canvas from an image element. | 337 // Draw an image to the canvas from an image element. |
| 338 test('with 3 params', () { | 338 test('with 3 params', () { |
| 339 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 339 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
| 340 var img = new ImageElement(); | 340 var img = new ImageElement(); |
| 341 | 341 |
| 342 img.onLoad.listen(expectAsync1((_) { | 342 img.onLoad.listen(expectAsync((_) { |
| 343 context.drawImage(img, 50, 50); | 343 context.drawImage(img, 50, 50); |
| 344 | 344 |
| 345 expectPixelFilled(50, 50); | 345 expectPixelFilled(50, 50); |
| 346 expectPixelFilled(55, 55); | 346 expectPixelFilled(55, 55); |
| 347 expectPixelFilled(59, 59); | 347 expectPixelFilled(59, 59); |
| 348 expectPixelUnfilled(60, 60); | 348 expectPixelUnfilled(60, 60); |
| 349 expectPixelUnfilled(0, 0); | 349 expectPixelUnfilled(0, 0); |
| 350 expectPixelUnfilled(70, 70); | 350 expectPixelUnfilled(70, 70); |
| 351 })); | 351 })); |
| 352 img.onError.listen((_) { | 352 img.onError.listen((_) { |
| 353 guardAsync(() { | 353 guardAsync(() { |
| 354 fail('URL failed to load.'); | 354 fail('URL failed to load.'); |
| 355 }); | 355 }); |
| 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(expectAsync((_) { |
| 366 context.drawImageToRect(img, new Rectangle(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(expectAsync((_) { |
| 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 Rectangle(50, 50, 20, 20), | 396 context.drawImageToRect(img, new Rectangle(50, 50, 20, 20), |
| 397 sourceRect: new Rectangle(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]); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 'Smxbp5EiYhAVAAAAAAAABZUrmsBAAAAAAAAR64BAAAAAAAAPteBAXPFgQGcgQAitZyDd' | 475 'Smxbp5EiYhAVAAAAAAAABZUrmsBAAAAAAAAR64BAAAAAAAAPteBAXPFgQGcgQAitZyDd' |
| 476 'W5khoVWX1ZQOIOBASPjg4QCYloA4AEAAAAAAAASsIEIuoEIVLCBCFS6gQhUsoEDH0O2d' | 476 'W5khoVWX1ZQOIOBASPjg4QCYloA4AEAAAAAAAASsIEIuoEIVLCBCFS6gQhUsoEDH0O2d' |
| 477 'QEAAAAAAABZ54EAo72BAACA8AIAnQEqCAAIAABHCIWFiIWEiAICAnWqA/gD+gINTRgA/' | 477 'QEAAAAAAABZ54EAo72BAACA8AIAnQEqCAAIAABHCIWFiIWEiAICAnWqA/gD+gINTRgA/' |
| 478 'v0hRf/kb+PnRv/I4//8WE8DijI//FRAo5WBACgAsQEAARAQABgAGFgv9AAIAAAcU7trA' | 478 'v0hRf/kb+PnRv/I4//8WE8DijI//FRAo5WBACgAsQEAARAQABgAGFgv9AAIAAAcU7trA' |
| 479 'QAAAAAAAA67jLOBALeH94EB8YIBfw=='; | 479 'QAAAAAAAA67jLOBALeH94EB8YIBfw=='; |
| 480 group('drawImage_video_element', () { | 480 group('drawImage_video_element', () { |
| 481 setUp(setupFunc); | 481 setUp(setupFunc); |
| 482 tearDown(tearDownFunc); | 482 tearDown(tearDownFunc); |
| 483 | 483 |
| 484 test('with 3 params', () { | 484 test('with 3 params', () { |
| 485 video.onCanPlay.listen(expectAsync1((_) { | 485 video.onCanPlay.listen(expectAsync((_) { |
| 486 context.drawImage(video, 50, 50); | 486 context.drawImage(video, 50, 50); |
| 487 | 487 |
| 488 expectPixelFilled(50, 50); | 488 expectPixelFilled(50, 50); |
| 489 expectPixelFilled(54, 54); | 489 expectPixelFilled(54, 54); |
| 490 expectPixelFilled(57, 57); | 490 expectPixelFilled(57, 57); |
| 491 expectPixelUnfilled(58, 58); | 491 expectPixelUnfilled(58, 58); |
| 492 expectPixelUnfilled(0, 0); | 492 expectPixelUnfilled(0, 0); |
| 493 expectPixelUnfilled(70, 70); | 493 expectPixelUnfilled(70, 70); |
| 494 })); | 494 })); |
| 495 | 495 |
| 496 video.onError.listen((_) { | 496 video.onError.listen((_) { |
| 497 guardAsync(() { | 497 guardAsync(() { |
| 498 fail('URL failed to load.'); | 498 fail('URL failed to load.'); |
| 499 }); | 499 }); |
| 500 }); | 500 }); |
| 501 | 501 |
| 502 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { | 502 if(video.canPlayType('video/webm; codecs="vp8.0, vorbis"', '') != '') { |
| 503 video.src = webmVideoUrl; | 503 video.src = webmVideoUrl; |
| 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(expectAsync((_) { |
| 514 context.drawImageToRect(video, new Rectangle(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(expectAsync((_) { |
| 544 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20), | 544 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20), |
| 545 sourceRect: new Rectangle(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); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 571 }); | 571 }); |
| 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(expectAsync((_) { |
| 582 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20), | 582 context.drawImageToRect(video, new Rectangle(50, 50, 20, 20), |
| 583 sourceRect: new Rectangle(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); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 738 |
| 739 // The box does not draw after 20 pixels. | 739 // The box does not draw after 20 pixels. |
| 740 expectPixelUnfilled(x - 10, y); | 740 expectPixelUnfilled(x - 10, y); |
| 741 expectPixelUnfilled(x + maxWidth + 1, y); | 741 expectPixelUnfilled(x + maxWidth + 1, y); |
| 742 expectPixelUnfilled(x + maxWidth + 20, y); | 742 expectPixelUnfilled(x + maxWidth + 20, y); |
| 743 expectPixelFilled(x, y); | 743 expectPixelFilled(x, y); |
| 744 expectPixelFilled(x + 10, y); | 744 expectPixelFilled(x + 10, y); |
| 745 }); | 745 }); |
| 746 }); | 746 }); |
| 747 } | 747 } |
| OLD | NEW |