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

Unified Diff: test/codegen/lib/html/canvas_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: ptal Created 4 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
Index: test/codegen/lib/html/canvas_test.dart
diff --git a/test/codegen/lib/html/canvas_test.dart b/test/codegen/lib/html/canvas_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d83c1d963065533393f45a8ef4bf5efabb79a11d
--- /dev/null
+++ b/test/codegen/lib/html/canvas_test.dart
@@ -0,0 +1,56 @@
+library CanvasTest;
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'dart:html';
+
+main() {
+ CanvasElement canvas;
+ CanvasRenderingContext2D context;
+ int width = 100;
+ int height = 100;
+
+ canvas = new CanvasElement(width:width, height:height);
+ document.body.append(canvas);
+
+ context = canvas.context2D;
+
+ useHtmlConfiguration();
+ test('CreateImageData', () {
+ ImageData image = context.createImageData(canvas.width,
+ canvas.height);
+ List<int> data = image.data;
+
+ expect(data, hasLength(40000));
+ checkPixel(data, 0, [0, 0, 0, 0]);
+ checkPixel(data, width * height - 1, [0, 0, 0, 0]);
+
+ data[100] = 200;
+ expect(data[100], equals(200));
+ });
+
+ test('toDataUrl', () {
+ var canvas = new CanvasElement(width: 100, height: 100);
+ var context = canvas.context2D;
+ context.fillStyle = 'red';
+ context.fill();
+
+ var url = canvas.toDataUrl();
+
+ var img = new ImageElement();
+ img.onLoad.listen(expectAsync((_) {
+ expect(img.complete, true);
+ }));
+ img.onError.listen((_) {
+ fail('URL failed to load.');
+ });
+ img.src = url;
+ });
+}
+
+void checkPixel(List<int> data, int offset, List<int> rgba)
+{
+ offset *= 4;
+ for (var i = 0; i < 4; ++i) {
+ expect(data[offset + i], equals(rgba[i]));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698