| 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; |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 | 10 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 }); | 275 }); |
| 276 img.src = dataUrl; | 276 img.src = dataUrl; |
| 277 }); | 277 }); |
| 278 | 278 |
| 279 // Draw an image to the canvas from an image element and scale it. | 279 // Draw an image to the canvas from an image element and scale it. |
| 280 test('drawImage from img element with 5 params', () { | 280 test('drawImage from img element with 5 params', () { |
| 281 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 281 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
| 282 var img = new ImageElement(); | 282 var img = new ImageElement(); |
| 283 | 283 |
| 284 img.onLoad.listen(expectAsync1((_) { | 284 img.onLoad.listen(expectAsync1((_) { |
| 285 context.drawImageAtScale(img, new Rect(50, 50, 20, 20)); | 285 context.drawImageToRect(img, new Rect(50, 50, 20, 20)); |
| 286 | 286 |
| 287 expectPixelFilled(50, 50); | 287 expectPixelFilled(50, 50); |
| 288 expectPixelFilled(55, 55); | 288 expectPixelFilled(55, 55); |
| 289 expectPixelFilled(59, 59); | 289 expectPixelFilled(59, 59); |
| 290 expectPixelFilled(60, 60); | 290 expectPixelFilled(60, 60); |
| 291 expectPixelFilled(69, 69); | 291 expectPixelFilled(69, 69); |
| 292 expectPixelUnfilled(70, 70); | 292 expectPixelUnfilled(70, 70); |
| 293 expectPixelUnfilled(0, 0); | 293 expectPixelUnfilled(0, 0); |
| 294 expectPixelUnfilled(80, 80); | 294 expectPixelUnfilled(80, 80); |
| 295 })); | 295 })); |
| 296 img.onError.listen((_) { | 296 img.onError.listen((_) { |
| 297 guardAsync(() { | 297 guardAsync(() { |
| 298 fail('URL failed to load.'); | 298 fail('URL failed to load.'); |
| 299 }); | 299 }); |
| 300 }); | 300 }); |
| 301 img.src = dataUrl; | 301 img.src = dataUrl; |
| 302 }); | 302 }); |
| 303 | 303 |
| 304 // Draw an image to the canvas from an image element and scale it. | 304 // Draw an image to the canvas from an image element and scale it. |
| 305 test('drawImage from img element with 9 params', () { | 305 test('drawImage from img element with 9 params', () { |
| 306 otherContext.fillStyle = "blue"; | 306 otherContext.fillStyle = "blue"; |
| 307 otherContext.fillRect(5, 5, 5, 5); | 307 otherContext.fillRect(5, 5, 5, 5); |
| 308 var dataUrl = otherCanvas.toDataUrl('image/gif'); | 308 var dataUrl = otherCanvas.toDataUrl('image/gif'); |
| 309 var img = new ImageElement(); | 309 var img = new ImageElement(); |
| 310 | 310 |
| 311 img.onLoad.listen(expectAsync1((_) { | 311 img.onLoad.listen(expectAsync1((_) { |
| 312 // This will take a 6x6 square from the first canvas from position 2,2 | 312 // 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 | 313 // and then scale it to a 20x20 square and place it to the second canvas |
| 314 // at 50,50. | 314 // at 50,50. |
| 315 context.drawImageAtScale(img, new Rect(50, 50, 20, 20), | 315 context.drawImageToRect(img, new Rect(50, 50, 20, 20), |
| 316 sourceRect: new Rect(2, 2, 6, 6)); | 316 sourceRect: new Rect(2, 2, 6, 6)); |
| 317 | 317 |
| 318 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 318 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
| 319 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 319 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
| 320 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 320 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
| 321 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 321 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
| 322 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 322 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
| 323 | 323 |
| 324 expectPixelFilled(50, 50); | 324 expectPixelFilled(50, 50); |
| 325 expectPixelFilled(55, 55); | 325 expectPixelFilled(55, 55); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // video.src = mp4VideoUrl; | 417 // video.src = mp4VideoUrl; |
| 418 // } else { | 418 // } else { |
| 419 // logMessage('Video is not supported on this system.'); | 419 // logMessage('Video is not supported on this system.'); |
| 420 // } | 420 // } |
| 421 // }); | 421 // }); |
| 422 // | 422 // |
| 423 // test('drawImage from video element with 5 params', () { | 423 // test('drawImage from video element with 5 params', () { |
| 424 // var video = new VideoElement(); | 424 // var video = new VideoElement(); |
| 425 // | 425 // |
| 426 // video.onLoadedData.listen(expectAsync1((_) { | 426 // video.onLoadedData.listen(expectAsync1((_) { |
| 427 // context.drawImageAtScale(video, new Rect(50, 50, 20, 20)); | 427 // context.drawImageToRect(video, new Rect(50, 50, 20, 20)); |
| 428 // | 428 // |
| 429 // expectPixelFilled(50, 50); | 429 // expectPixelFilled(50, 50); |
| 430 // expectPixelFilled(55, 55); | 430 // expectPixelFilled(55, 55); |
| 431 // expectPixelFilled(59, 59); | 431 // expectPixelFilled(59, 59); |
| 432 // expectPixelFilled(60, 60); | 432 // expectPixelFilled(60, 60); |
| 433 // expectPixelFilled(69, 69); | 433 // expectPixelFilled(69, 69); |
| 434 // expectPixelUnfilled(70, 70); | 434 // expectPixelUnfilled(70, 70); |
| 435 // expectPixelUnfilled(0, 0); | 435 // expectPixelUnfilled(0, 0); |
| 436 // expectPixelUnfilled(80, 80); | 436 // expectPixelUnfilled(80, 80); |
| 437 // })); | 437 // })); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 449 // } else { | 449 // } else { |
| 450 // // TODO(amouravski): Better fallback? | 450 // // TODO(amouravski): Better fallback? |
| 451 // logMessage('Video is not supported on this system.'); | 451 // logMessage('Video is not supported on this system.'); |
| 452 // } | 452 // } |
| 453 // }); | 453 // }); |
| 454 // | 454 // |
| 455 // test('drawImage from video element with 9 params', () { | 455 // test('drawImage from video element with 9 params', () { |
| 456 // var video = new VideoElement(); | 456 // var video = new VideoElement(); |
| 457 // | 457 // |
| 458 // video.onLoadedData.listen(expectAsync1((_) { | 458 // video.onLoadedData.listen(expectAsync1((_) { |
| 459 // context.drawImageAtScale(video, new Rect(50, 50, 20, 20), | 459 // context.drawImageToRect(video, new Rect(50, 50, 20, 20), |
| 460 // sourceRect: new Rect(2, 2, 6, 6)); | 460 // sourceRect: new Rect(2, 2, 6, 6)); |
| 461 // | 461 // |
| 462 // expectPixelFilled(50, 50); | 462 // expectPixelFilled(50, 50); |
| 463 // expectPixelFilled(55, 55); | 463 // expectPixelFilled(55, 55); |
| 464 // expectPixelFilled(59, 59); | 464 // expectPixelFilled(59, 59); |
| 465 // expectPixelFilled(60, 60); | 465 // expectPixelFilled(60, 60); |
| 466 // expectPixelFilled(69, 69); | 466 // expectPixelFilled(69, 69); |
| 467 // expectPixelUnfilled(70, 70); | 467 // expectPixelUnfilled(70, 70); |
| 468 // expectPixelUnfilled(0, 0); | 468 // expectPixelUnfilled(0, 0); |
| 469 // expectPixelUnfilled(80, 80); | 469 // expectPixelUnfilled(80, 80); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 491 | 491 |
| 492 expectPixelFilled(50, 50); | 492 expectPixelFilled(50, 50); |
| 493 expectPixelFilled(55, 55); | 493 expectPixelFilled(55, 55); |
| 494 expectPixelFilled(59, 59); | 494 expectPixelFilled(59, 59); |
| 495 expectPixelUnfilled(60, 60); | 495 expectPixelUnfilled(60, 60); |
| 496 expectPixelUnfilled(0, 0); | 496 expectPixelUnfilled(0, 0); |
| 497 expectPixelUnfilled(70, 70); | 497 expectPixelUnfilled(70, 70); |
| 498 }); | 498 }); |
| 499 test('drawImage from canvas element with 5 params', () { | 499 test('drawImage from canvas element with 5 params', () { |
| 500 // Draw an image to the canvas from a canvas element. | 500 // Draw an image to the canvas from a canvas element. |
| 501 context.drawImageAtScale(otherCanvas, new Rect(50, 50, 20, 20)); | 501 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20)); |
| 502 | 502 |
| 503 expectPixelFilled(50, 50); | 503 expectPixelFilled(50, 50); |
| 504 expectPixelFilled(55, 55); | 504 expectPixelFilled(55, 55); |
| 505 expectPixelFilled(59, 59); | 505 expectPixelFilled(59, 59); |
| 506 expectPixelFilled(60, 60); | 506 expectPixelFilled(60, 60); |
| 507 expectPixelFilled(69, 69); | 507 expectPixelFilled(69, 69); |
| 508 expectPixelUnfilled(70, 70); | 508 expectPixelUnfilled(70, 70); |
| 509 expectPixelUnfilled(0, 0); | 509 expectPixelUnfilled(0, 0); |
| 510 expectPixelUnfilled(80, 80); | 510 expectPixelUnfilled(80, 80); |
| 511 }); | 511 }); |
| 512 test('drawImage from canvas element with 9 params', () { | 512 test('drawImage from canvas element with 9 params', () { |
| 513 // Draw an image to the canvas from a canvas element. | 513 // Draw an image to the canvas from a canvas element. |
| 514 otherContext.fillStyle = "blue"; | 514 otherContext.fillStyle = "blue"; |
| 515 otherContext.fillRect(5, 5, 5, 5); | 515 otherContext.fillRect(5, 5, 5, 5); |
| 516 context.drawImageAtScale(otherCanvas, new Rect(50, 50, 20, 20), | 516 context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20), |
| 517 sourceRect: new Rect(2, 2, 6, 6)); | 517 sourceRect: new Rect(2, 2, 6, 6)); |
| 518 | 518 |
| 519 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); | 519 checkPixel(readPixel(50, 50), [255, 0, 0, 255]); |
| 520 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); | 520 checkPixel(readPixel(55, 55), [255, 0, 0, 255]); |
| 521 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); | 521 checkPixel(readPixel(60, 50), [255, 0, 0, 255]); |
| 522 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); | 522 checkPixel(readPixel(65, 65), [0, 0, 255, 255]); |
| 523 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); | 523 checkPixel(readPixel(69, 69), [0, 0, 255, 255]); |
| 524 expectPixelFilled(50, 50); | 524 expectPixelFilled(50, 50); |
| 525 expectPixelFilled(55, 55); | 525 expectPixelFilled(55, 55); |
| 526 expectPixelFilled(59, 59); | 526 expectPixelFilled(59, 59); |
| 527 expectPixelFilled(60, 60); | 527 expectPixelFilled(60, 60); |
| 528 expectPixelFilled(69, 69); | 528 expectPixelFilled(69, 69); |
| 529 expectPixelUnfilled(70, 70); | 529 expectPixelUnfilled(70, 70); |
| 530 expectPixelUnfilled(0, 0); | 530 expectPixelUnfilled(0, 0); |
| 531 expectPixelUnfilled(80, 80); | 531 expectPixelUnfilled(80, 80); |
| 532 }); | 532 }); |
| 533 }); | 533 }); |
| 534 } | 534 } |
| OLD | NEW |