Chromium Code Reviews| 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 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'dart:math'; | 8 import 'dart:math'; |
| 9 | 9 |
| 10 import 'package:unittest/html_individual_config.dart'; | 10 import 'package:unittest/html_individual_config.dart'; |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 final x = 20; | 671 final x = 20; |
| 672 final y = 20; | 672 final y = 20; |
| 673 | 673 |
| 674 test('without maxWidth', () { | 674 test('without maxWidth', () { |
| 675 context.font = '40pt Garamond'; | 675 context.font = '40pt Garamond'; |
| 676 context.fillStyle = 'blue'; | 676 context.fillStyle = 'blue'; |
| 677 | 677 |
| 678 // Draw a blue box. | 678 // Draw a blue box. |
| 679 context.fillText('█', x, y); | 679 context.fillText('█', x, y); |
| 680 | 680 |
| 681 var width = context.measureText('█').width.toInt(); | 681 var width = context.measureText('█').width.ceil(); |
| 682 | 682 |
| 683 checkPixel(readPixel(x, y), [0, 0, 255, 255]); | 683 checkPixel(readPixel(x, y), [0, 0, 255, 255]); |
| 684 checkPixel(readPixel(x + 10, y), [0, 0, 255, 255]); | 684 checkPixel(readPixel(x + 10, y), [0, 0, 255, 255]); |
| 685 | 685 |
| 686 expectPixelUnfilled(x - 10, y); | 686 expectPixelUnfilled(x - 10, y); |
| 687 expectPixelFilled(x, y); | 687 expectPixelFilled(x, y); |
| 688 expectPixelFilled(x + 10, y); | 688 expectPixelFilled(x + 10, y); |
| 689 | 689 |
| 690 // The box does not draw after `width` pixels. | 690 // The box does not draw after `width` pixels. |
| 691 expectPixelFilled(x + width - 1, y); | 691 expectPixelFilled(x + width - 1, y); |
| 692 expectPixelUnfilled(x + width + 1, y); | 692 expectPixelUnfilled(x + width + 1, y); |
|
vsm
2014/07/30 07:34:23
Line 692 was failing without the change to ceil ab
| |
| 693 }); | 693 }); |
| 694 | 694 |
| 695 test('with maxWidth null', () { | 695 test('with maxWidth null', () { |
| 696 context.font = '40pt Garamond'; | 696 context.font = '40pt Garamond'; |
| 697 context.fillStyle = 'blue'; | 697 context.fillStyle = 'blue'; |
| 698 | 698 |
| 699 // Draw a blue box with null maxWidth. | 699 // Draw a blue box with null maxWidth. |
| 700 context.fillText('█', x, y, null); | 700 context.fillText('█', x, y, null); |
| 701 | 701 |
| 702 var width = context.measureText('█').width.toInt(); | 702 var width = context.measureText('█').width.ceil(); |
| 703 | 703 |
| 704 checkPixel(readPixel(x, y), [0, 0, 255, 255]); | 704 checkPixel(readPixel(x, y), [0, 0, 255, 255]); |
| 705 checkPixel(readPixel(x + 10, y), [0, 0, 255, 255]); | 705 checkPixel(readPixel(x + 10, y), [0, 0, 255, 255]); |
| 706 | 706 |
| 707 expectPixelUnfilled(x - 10, y); | 707 expectPixelUnfilled(x - 10, y); |
| 708 expectPixelFilled(x, y); | 708 expectPixelFilled(x, y); |
| 709 expectPixelFilled(x + 10, y); | 709 expectPixelFilled(x + 10, y); |
| 710 | 710 |
| 711 // The box does not draw after `width` pixels. | 711 // The box does not draw after `width` pixels. |
| 712 expectPixelFilled(x + width - 1, y); | 712 expectPixelFilled(x + width - 1, y); |
| 713 expectPixelUnfilled(x + width + 1, y); | 713 expectPixelUnfilled(x + width + 1, y); |
|
vsm
2014/07/30 07:34:23
Ditto.
| |
| 714 }); | 714 }); |
| 715 | 715 |
| 716 test('with maxWidth defined', () { | 716 test('with maxWidth defined', () { |
| 717 context.font = '40pt Garamond'; | 717 context.font = '40pt Garamond'; |
| 718 context.fillStyle = 'blue'; | 718 context.fillStyle = 'blue'; |
| 719 | 719 |
| 720 final maxWidth = 20; | 720 final maxWidth = 20; |
| 721 | 721 |
| 722 // Draw a blue box that's at most 20 pixels wide. | 722 // Draw a blue box that's at most 20 pixels wide. |
| 723 context.fillText('█', x, y, maxWidth); | 723 context.fillText('█', x, y, maxWidth); |
| 724 | 724 |
| 725 checkPixel(readPixel(x, y), [0, 0, 255, 255]); | 725 checkPixel(readPixel(x, y), [0, 0, 255, 255]); |
| 726 checkPixel(readPixel(x + 10, y), [0, 0, 255, 255]); | 726 checkPixel(readPixel(x + 10, y), [0, 0, 255, 255]); |
| 727 | 727 |
| 728 // The box does not draw after 20 pixels. | 728 // The box does not draw after 20 pixels. |
| 729 expectPixelUnfilled(x - 10, y); | 729 expectPixelUnfilled(x - 10, y); |
| 730 expectPixelUnfilled(x + maxWidth + 1, y); | 730 expectPixelUnfilled(x + maxWidth + 1, y); |
| 731 expectPixelUnfilled(x + maxWidth + 20, y); | 731 expectPixelUnfilled(x + maxWidth + 20, y); |
| 732 expectPixelFilled(x, y); | 732 expectPixelFilled(x, y); |
| 733 expectPixelFilled(x + 10, y); | 733 expectPixelFilled(x + 10, y); |
| 734 }); | 734 }); |
| 735 }); | 735 }); |
| 736 } | 736 } |
| OLD | NEW |