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 XHRTest; | 5 library XHRTest; |
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 import 'dart:json' as json; | |
9 | 10 |
10 main() { | 11 main() { |
11 useHtmlConfiguration(); | 12 useHtmlConfiguration(); |
13 var url = "../../../../tests/html/xhr_cross_origin_data.txt"; | |
12 | 14 |
13 test('XHR No file', () { | 15 test('XHR No file', () { |
14 HttpRequest xhr = new HttpRequest(); | 16 HttpRequest xhr = new HttpRequest(); |
15 xhr.open("GET", "NonExistingFile", true); | 17 xhr.open("GET", "NonExistingFile", true); |
16 xhr.on.readyStateChange.add(expectAsync1((event) { | 18 xhr.on.readyStateChange.add(expectAsyncUntil1((event) { |
blois
2013/01/10 17:58:16
Does the load event not suffice here?
| |
17 if (xhr.readyState == HttpRequest.DONE) { | 19 if (xhr.readyState == HttpRequest.DONE) { |
18 expect(xhr.status, equals(0)); | 20 expect(xhr.status, equals(404)); |
19 expect(xhr.responseText, equals('')); | 21 expect(xhr.responseText, equals('')); |
20 } | 22 } |
21 })); | 23 }, () => xhr.readyState == HttpRequest.DONE)); |
24 xhr.send(); | |
25 }); | |
26 | |
27 test('XHR file', () { | |
28 var xhr = new HttpRequest(); | |
29 xhr.open('GET', url, true); | |
30 xhr.on.readyStateChange.add(expectAsyncUntil1((e) { | |
31 if (xhr.readyState == HttpRequest.DONE) { | |
32 expect(xhr.status, equals(200)); | |
33 var data = json.parse(xhr.response); | |
34 expect(data, contains('feed')); | |
35 expect(data['feed'], contains('entry')); | |
36 expect(data, isMap); | |
37 } | |
38 }, () => xhr.readyState == HttpRequest.DONE)); | |
22 xhr.send(); | 39 xhr.send(); |
23 }); | 40 }); |
24 | 41 |
25 test('XHR.get No file', () { | 42 test('XHR.get No file', () { |
26 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { | 43 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { |
27 expect(xhr.readyState, equals(HttpRequest.DONE)); | 44 expect(xhr.readyState, equals(HttpRequest.DONE)); |
28 expect(xhr.status, equals(0)); | 45 expect(xhr.status, equals(404)); |
29 expect(xhr.responseText, equals('')); | 46 expect(xhr.responseText, equals('')); |
30 })); | 47 })); |
31 }); | 48 }); |
49 | |
50 test('XHR.get file', () { | |
51 var xhr = new HttpRequest.get(url, expectAsync1((event) { | |
52 expect(event.readyState, equals(HttpRequest.DONE)); | |
ricow1
2013/01/10 20:03:41
I would extract this body into a function, we do t
Emily Fortuna
2013/01/11 02:57:12
Done.
| |
53 expect(event.status, equals(200)); | |
54 var data = json.parse(event.response); | |
55 expect(data, contains('feed')); | |
56 expect(data['feed'], contains('entry')); | |
57 expect(data, isMap); | |
58 })); | |
59 }); | |
60 | |
61 test('XHR.getWithCredentials No file', () { | |
62 new HttpRequest.getWithCredentials("NonExistingFile", expectAsync1((xhr) { | |
63 expect(xhr.status, equals(404)); | |
64 expect(xhr.responseText, equals('')); | |
65 })); | |
66 }); | |
67 | |
68 test('XHR.getWithCredentials file', () { | |
69 new HttpRequest.getWithCredentials(url, expectAsync1((xhr) { | |
70 expect(xhr.status, equals(200)); | |
71 var data = json.parse(xhr.response); | |
72 expect(data, contains('feed')); | |
73 expect(data['feed'], contains('entry')); | |
74 expect(data, isMap); | |
75 })); | |
76 }); | |
32 } | 77 } |
OLD | NEW |