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

Side by Side Diff: test/codegen/lib/html/url_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: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library url_test;
6 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_config.dart';
8 import 'dart:html';
9 import 'dart:typed_data';
10
11 main() {
12 useHtmlConfiguration();
13
14 Blob createImageBlob() {
15 var canvas = new CanvasElement();
16 canvas.width = 100;
17 canvas.height = 100;
18
19 var context = canvas.context2D;
20 context.fillStyle = 'red';
21 context.fillRect(0, 0, canvas.width, canvas.height);
22
23 var dataUri = canvas.toDataUrl('image/png');
24 var byteString = window.atob(dataUri.split(',')[1]);
25 var mimeString = dataUri.split(',')[0].split(':')[1].split(';')[0];
26
27 var arrayBuffer = new Uint8List(byteString.length);
28 var dataArray = new Uint8List.view(arrayBuffer.buffer);
29 for (var i = 0; i < byteString.length; i++) {
30 dataArray[i] = byteString.codeUnitAt(i);
31 }
32
33 var blob = new Blob([arrayBuffer], 'image/png');
34 return blob;
35 }
36
37 group('blob', () {
38 test('createObjectUrlFromBlob', () {
39 var blob = createImageBlob();
40 var url = Url.createObjectUrlFromBlob(blob);
41 expect(url.length, greaterThan(0));
42 expect(url, startsWith('blob:'));
43
44 var img = new ImageElement();
45 img.onLoad.listen(expectAsync((_) {
46 expect(img.complete, true);
47 }));
48 img.onError.listen((_) {
49 fail('URL failed to load.');
50 });
51 img.src = url;
52 });
53
54 test('revokeObjectUrl', () {
55 var blob = createImageBlob();
56 var url = Url.createObjectUrlFromBlob(blob);
57 expect(url, startsWith('blob:'));
58 Url.revokeObjectUrl(url);
59
60 var img = new ImageElement();
61 // Image should fail to load since the URL was revoked.
62 img.onError.listen(expectAsync((_) {
63 }));
64 img.onLoad.listen((_) {
65 fail('URL should not have loaded.');
66 });
67 img.src = url;
68 });
69
70 });
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698