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

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

Issue 10222001: Make CanvasPixelArray pretent to be Uint8ClampedArray (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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/client-leg.status ('k') | client/tests/client/html/CanvasPixelArrayTypeAliasTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/tests/client/dom/CanvasPixelArrayTypeAliasTest.dart
diff --git a/client/tests/client/dom/CanvasPixelArrayTypeAliasTest.dart b/client/tests/client/dom/CanvasPixelArrayTypeAliasTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5aeffb46d01b98854bb1d864f7579eecfa5f3e91
--- /dev/null
+++ b/client/tests/client/dom/CanvasPixelArrayTypeAliasTest.dart
@@ -0,0 +1,51 @@
+#library('CanvasTest');
+#import('../../../../lib/unittest/unittest.dart');
+#import('../../../../lib/unittest/dom_config.dart');
+#import('dart:dom');
+
+// We have aliased the legacy type CanvasPixelArray with the new type
+// Uint8ClampedArray by mapping the CanvasPixelArray type tag to
+// Uint8ClampedArray. It is not a perfect match since CanvasPixelArray is
+// missing the ArrayBufferView members. These should appear to be null.
+
+Object confuseType(x) => [1, x, [x], 's'] [1]; // returns 'x'
+
+main() {
+ HTMLCanvasElement canvas;
+ CanvasRenderingContext2D context;
+ int width = 100;
+ int height = 100;
+
+ canvas = document.createElement('canvas');
+ canvas.setAttribute('width', '$width');
+ canvas.setAttribute('height', '$height');
+ document.body.appendChild(canvas);
+
+ context = canvas.getContext('2d');
+
+ useDomConfiguration();
+
+ test('CreateImageData', () {
+ ImageData image = context.createImageData(canvas.width,
+ canvas.height);
+ Uint8ClampedArray data = image.data;
+ // It is legal for the dart2js compiler to believe the type of the native
+ // ImageData.data and elides the check, so check the type explicitly:
+ Expect.isTrue(confuseType(data) is Uint8ClampedArray);
+
+ 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]);
+ });
+}
+
+void checkPixel(Uint8ClampedArray 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/client-leg.status ('k') | client/tests/client/html/CanvasPixelArrayTypeAliasTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698