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 FormDataTest; | 5 library FormDataTest; |
6 | 6 |
7 import '../../pkg/unittest/lib/unittest.dart'; | 7 import '../../pkg/unittest/lib/unittest.dart'; |
8 import '../../pkg/unittest/lib/html_config.dart'; | 8 import '../../pkg/unittest/lib/html_config.dart'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 | 10 |
| 11 void fail(message) { |
| 12 guardAsync(() { |
| 13 expect(false, isTrue, reason: message); |
| 14 }); |
| 15 } |
| 16 |
11 void main() { | 17 void main() { |
12 // TODO(efortuna): This is a bad test. Revisit when we have tests that can run | 18 // TODO(efortuna): This is a bad test. Revisit when we have tests that can run |
13 // both a server and fire up a browser. | 19 // both a server and fire up a browser. |
14 useHtmlConfiguration(); | 20 useHtmlConfiguration(); |
15 | 21 |
16 var isFormData = predicate((x) => x is FormData, 'is a FormData'); | 22 var isFormData = predicate((x) => x is FormData, 'is a FormData'); |
17 | 23 |
18 test('constructorTest1', () { | 24 test('constructorTest1', () { |
19 var form = new FormData(); | 25 var form = new FormData(); |
20 expect(form, isNotNull); | 26 expect(form, isNotNull); |
(...skipping 15 matching lines...) Expand all Loading... |
36 expect(form, isNotNull); | 42 expect(form, isNotNull); |
37 }); | 43 }); |
38 | 44 |
39 test('appendBlob', () { | 45 test('appendBlob', () { |
40 var form = new FormData(); | 46 var form = new FormData(); |
41 var blob = new Blob( | 47 var blob = new Blob( |
42 ['Indescribable... Indestructible! Nothing can stop it!'], | 48 ['Indescribable... Indestructible! Nothing can stop it!'], |
43 'text/plain'); | 49 'text/plain'); |
44 form.append('theBlob', blob, 'theBlob.txt'); | 50 form.append('theBlob', blob, 'theBlob.txt'); |
45 }); | 51 }); |
| 52 |
| 53 test('send', () { |
| 54 var form = new FormData(); |
| 55 var blobString = 'Indescribable... Indestructible! Nothing can stop it!'; |
| 56 var blob = new Blob( |
| 57 [blobString], |
| 58 'text/plain'); |
| 59 form.append('theBlob', blob, 'theBlob.txt'); |
| 60 |
| 61 var xhr = new HttpRequest(); |
| 62 xhr.open("POST", "http://localhost:9876/echo"); |
| 63 |
| 64 xhr.on.load.add(expectAsync1((e) { |
| 65 expect(xhr.responseText.contains(blobString), true); |
| 66 })); |
| 67 xhr.on.error.add((e) { |
| 68 fail('$e'); |
| 69 }); |
| 70 xhr.send(form); |
| 71 }); |
46 } | 72 } |
OLD | NEW |