Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: client/tests/client/dom/CanvasTest.dart

Issue 9314008: Migrate all LayoutTests/dart/dom to main repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update config file Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/tests/client/dom/CallbacksTest.dart ('k') | client/tests/client/dom/CanvasUsingHtmlTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/tests/client/dom/CanvasTest.dart
diff --git a/client/tests/client/dom/CanvasTest.dart b/client/tests/client/dom/CanvasTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..669d062d4552629775dd8418ceb4bcb78cb46bc6
--- /dev/null
+++ b/client/tests/client/dom/CanvasTest.dart
@@ -0,0 +1,84 @@
+#library('CanvasTest');
+#import('../../../testing/unittest/unittest.dart');
+#import('dart:dom');
+
+main() {
+ HTMLCanvasElement canvas;
+ CanvasRenderingContext2D context;
+ int width = 100;
+ int height = 100;
+
+ // FIXME: once main is run on content loaded, this hack won't be necessary.
+ window.setTimeout(() {
+ canvas = document.createElement('canvas');
+ canvas.setAttribute('width', '$width');
+ canvas.setAttribute('height', '$height');
+ document.body.appendChild(canvas);
+
+ context = canvas.getContext('2d');
+ }, 0);
+
+ forLayoutTests();
+ test('FillStyle', () {
+ context.fillStyle = "red";
+ context.fillRect(10, 10, 20, 20);
+
+ CanvasPixelArray data = context.getImageData(0, 0, width, height).data;
+ checkPixel(data, 0, [0, 0, 0, 0]);
+ checkPixel(data, 9 + width * 10, [0, 0, 0, 0]);
+ checkPixel(data, 10 + width * 10, [255, 0, 0, 255]);
+ checkPixel(data, 29 + width * 10, [255, 0, 0, 255]);
+ checkPixel(data, 30 + width * 10, [0, 0, 0, 0]);
+ });
+ test('SetFillColor', () {
+ // With floats.
+ context.setFillColor(10, 10, 10, 10);
+ context.fillRect(10, 10, 20, 20);
+
+ // With rationals.
+ context.setFillColor(10.0, 10.0, 10.0, 10.0);
+ context.fillRect(20, 20, 30, 30);
+
+ // With ints.
+ context.setFillColor(10, 10, 10, 10);
+ context.fillRect(30, 30, 40, 40);
+
+ // TODO(vsm): Verify the result once we have the ability to read pixels.
+ });
+ test('StrokeStyle', () {
+ context.strokeStyle = "blue";
+ context.strokeRect(30, 30, 10, 20);
+
+ // TODO(vsm): Verify the result once we have the ability to read pixels.
+ });
+ test('CreateImageData', () {
+ ImageData image = context.createImageData(canvas.width,
+ canvas.height);
+ CanvasPixelArray data = image.data;
+
+ Expect.equals(40000, data.length);
+ checkPixel(data, 0, [0, 0, 0, 0]);
+ checkPixel(data, width * height - 1, [0, 0, 0, 0]);
+
+ data[100] = 200;
+ Expect.equals(200, data[100]);
+ });
+ test('PutImageData', () {
+ ImageData data = context.getImageData(0, 0, width, height);
+ data.data[0] = 25;
+ data.data[3] = 255;
+ context.putImageData(data, 0, 0);
+
+ data = context.getImageData(0, 0, width, height);
+ Expect.equals(25, data.data[0]);
+ Expect.equals(255, data.data[3]);
+ });
+}
+
+void checkPixel(CanvasPixelArray data, int offset, List<int> rgba)
+{
+ offset *= 4;
+ for (var i = 0; i < 4; ++i) {
+ Expect.equals(rgba[i], data[offset + i]);
+ }
+}
« no previous file with comments | « client/tests/client/dom/CallbacksTest.dart ('k') | client/tests/client/dom/CanvasUsingHtmlTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698