| 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 main() { | 10 main() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 group('blob', () { | 36 group('blob', () { |
| 37 test('createObjectUrl', () { | 37 test('createObjectUrl', () { |
| 38 var blob = createImageBlob(); | 38 var blob = createImageBlob(); |
| 39 var url = Url.createObjectUrl(blob); | 39 var url = Url.createObjectUrl(blob); |
| 40 expect(url.length, greaterThan(0)); | 40 expect(url.length, greaterThan(0)); |
| 41 expect(url, startsWith('blob:')); | 41 expect(url, startsWith('blob:')); |
| 42 | 42 |
| 43 var img = new ImageElement(); | 43 var img = new ImageElement(); |
| 44 img.on.load.add(expectAsync1((_) { | 44 img.onLoad.listen(expectAsync1((_) { |
| 45 expect(img.complete, true); | 45 expect(img.complete, true); |
| 46 })); | 46 })); |
| 47 img.on.error.add((_) { | 47 img.onError.listen((_) { |
| 48 guardAsync(() { | 48 guardAsync(() { |
| 49 expect(true, isFalse, reason: 'URL failed to load.'); | 49 expect(true, isFalse, reason: 'URL failed to load.'); |
| 50 }); | 50 }); |
| 51 }); | 51 }); |
| 52 img.src = url; | 52 img.src = url; |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('revokeObjectUrl', () { | 55 test('revokeObjectUrl', () { |
| 56 var blob = createImageBlob(); | 56 var blob = createImageBlob(); |
| 57 var url = Url.createObjectUrl(blob); | 57 var url = Url.createObjectUrl(blob); |
| 58 expect(url, startsWith('blob:')); | 58 expect(url, startsWith('blob:')); |
| 59 Url.revokeObjectUrl(url); | 59 Url.revokeObjectUrl(url); |
| 60 | 60 |
| 61 var img = new ImageElement(); | 61 var img = new ImageElement(); |
| 62 // Image should fail to load since the URL was revoked. | 62 // Image should fail to load since the URL was revoked. |
| 63 img.on.error.add(expectAsync1((_) { | 63 img.onError.listen(expectAsync1((_) { |
| 64 })); | 64 })); |
| 65 img.on.load.add((_) { | 65 img.onLoad.listen((_) { |
| 66 guardAsync(() { | 66 guardAsync(() { |
| 67 expect(true, isFalse, reason: 'URL should not have loaded.'); | 67 expect(true, isFalse, reason: 'URL should not have loaded.'); |
| 68 }); | 68 }); |
| 69 }); | 69 }); |
| 70 img.src = url; | 70 img.src = url; |
| 71 }); | 71 }); |
| 72 | 72 |
| 73 }); | 73 }); |
| 74 } | 74 } |
| OLD | NEW |