| 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 url_test; | 5 library url_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 | 9 |
| 10 // Some rounding errors in the browsers. | 10 // Some rounding errors in the browsers. |
| 11 checkPixel(List<int> pixel, List<int> expected) { | 11 checkPixel(List<int> pixel, List<int> expected) { |
| 12 expect(pixel[0], closeTo(expected[0], 1)); | 12 expect(pixel[0], closeTo(expected[0], 2)); |
| 13 expect(pixel[1], closeTo(expected[1], 1)); | 13 expect(pixel[1], closeTo(expected[1], 2)); |
| 14 expect(pixel[2], closeTo(expected[2], 1)); | 14 expect(pixel[2], closeTo(expected[2], 2)); |
| 15 expect(pixel[3], closeTo(expected[3], 1)); | 15 expect(pixel[3], closeTo(expected[3], 2)); |
| 16 } | 16 } |
| 17 | 17 |
| 18 main() { | 18 main() { |
| 19 useHtmlConfiguration(); | 19 useHtmlConfiguration(); |
| 20 var canvas = new CanvasElement(); | 20 var canvas = new CanvasElement(); |
| 21 canvas.width = 100; | 21 canvas.width = 100; |
| 22 canvas.height = 100; | 22 canvas.height = 100; |
| 23 | 23 |
| 24 var context = canvas.context2d; | 24 var context = canvas.context2d; |
| 25 | 25 |
| 26 List<int> readPixel() { | 26 List<int> readPixel() { |
| 27 var imageData = context.getImageData(2, 2, 1, 1); | 27 var imageData = context.getImageData(2, 2, 1, 1); |
| 28 return imageData.data; | 28 return imageData.data; |
| 29 } | 29 } |
| 30 | 30 |
| 31 test('setFillColorRgb', () { | 31 test('setFillColorRgb', () { |
| 32 context.setFillColorRgb(255, 0, 255, 1); | 32 context.setFillColorRgb(255, 0, 255, 1); |
| 33 context.fillRect(0, 0, canvas.width, canvas.height); | 33 context.fillRect(0, 0, canvas.width, canvas.height); |
| 34 expect(readPixel(), [255, 0, 255, 255]); | 34 expect(readPixel(), [255, 0, 255, 255]); |
| 35 }); | 35 }); |
| 36 | 36 |
| 37 test('setFillColorHsl hue', () { | 37 test('setFillColorHsl hue', () { |
| 38 context.setFillColorHsl(0, 100, 50); | 38 context.setFillColorHsl(0, 100, 50); |
| 39 context.fillRect(0, 0, canvas.width, canvas.height); | 39 context.fillRect(0, 0, canvas.width, canvas.height); |
| 40 expect(readPixel(), [255, 0, 0, 255]); | 40 checkPixel(readPixel(), [255, 0, 0, 255]); |
| 41 }); | 41 }); |
| 42 | 42 |
| 43 test('setFillColorHsl hue 2', () { | 43 test('setFillColorHsl hue 2', () { |
| 44 context.setFillColorHsl(240, 100, 50); | 44 context.setFillColorHsl(240, 100, 50); |
| 45 context.fillRect(0, 0, canvas.width, canvas.height); | 45 context.fillRect(0, 0, canvas.width, canvas.height); |
| 46 expect(readPixel(), [0, 0, 255, 255]); | 46 checkPixel(readPixel(), [0, 0, 255, 255]); |
| 47 }); | 47 }); |
| 48 | 48 |
| 49 test('setFillColorHsl sat', () { | 49 test('setFillColorHsl sat', () { |
| 50 context.setFillColorHsl(0, 0, 50); | 50 context.setFillColorHsl(0, 0, 50); |
| 51 context.fillRect(0, 0, canvas.width, canvas.height); | 51 context.fillRect(0, 0, canvas.width, canvas.height); |
| 52 checkPixel(readPixel(), [127, 127, 127, 255]); | 52 checkPixel(readPixel(), [127, 127, 127, 255]); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('setStrokeColorRgb', () { | 55 test('setStrokeColorRgb', () { |
| 56 context.setStrokeColorRgb(255, 0, 255, 1); | 56 context.setStrokeColorRgb(255, 0, 255, 1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 test('setStrokeColorHsl sat', () { | 76 test('setStrokeColorHsl sat', () { |
| 77 context.setStrokeColorHsl(0, 0, 50); | 77 context.setStrokeColorHsl(0, 0, 50); |
| 78 context.lineWidth = 10; | 78 context.lineWidth = 10; |
| 79 context.strokeRect(0, 0, canvas.width, canvas.height); | 79 context.strokeRect(0, 0, canvas.width, canvas.height); |
| 80 checkPixel(readPixel(), [127, 127, 127, 255]); | 80 checkPixel(readPixel(), [127, 127, 127, 255]); |
| 81 }); | 81 }); |
| 82 | 82 |
| 83 test('fillStyle', () { | 83 test('fillStyle', () { |
| 84 context.fillStyle = "red"; | 84 context.fillStyle = "red"; |
| 85 context.fillRect(0, 0, canvas.width, canvas.height); | 85 context.fillRect(0, 0, canvas.width, canvas.height); |
| 86 expect(readPixel(), [255, 0, 0, 255]); | 86 checkPixel(readPixel(), [255, 0, 0, 255]); |
| 87 }); | 87 }); |
| 88 | 88 |
| 89 test('strokeStyle', () { | 89 test('strokeStyle', () { |
| 90 context.strokeStyle = "blue"; | 90 context.strokeStyle = "blue"; |
| 91 context.lineWidth = 10; | 91 context.lineWidth = 10; |
| 92 context.strokeRect(0, 0, canvas.width, canvas.height); | 92 context.strokeRect(0, 0, canvas.width, canvas.height); |
| 93 expect(readPixel(), [0, 0, 255, 255]); | 93 expect(readPixel(), [0, 0, 255, 255]); |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 test('fillStyle linearGradient', () { | 96 test('fillStyle linearGradient', () { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 context.fillStyle = 'green'; | 109 context.fillStyle = 'green'; |
| 110 context.fillRect(0, 0, canvas.width, canvas.height); | 110 context.fillRect(0, 0, canvas.width, canvas.height); |
| 111 | 111 |
| 112 context.putImageData(expectedData, 0, 0); | 112 context.putImageData(expectedData, 0, 0); |
| 113 | 113 |
| 114 var resultingData = context.getImageData(0, 0, 10, 10); | 114 var resultingData = context.getImageData(0, 0, 10, 10); |
| 115 // Make sure that we read back what we wrote. | 115 // Make sure that we read back what we wrote. |
| 116 expect(resultingData.data, expectedData.data); | 116 expect(resultingData.data, expectedData.data); |
| 117 }); | 117 }); |
| 118 } | 118 } |
| OLD | NEW |