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'; | 9 import 'dart:json'; |
10 | 10 |
11 main() { | 11 main() { |
12 useHtmlConfiguration(); | 12 useHtmlConfiguration(); |
13 var url = "../../../../tests/html/xhr_cross_origin_data.txt"; | |
14 | 13 |
15 test('XHR No file', () { | 14 test('XHR No file', () { |
16 HttpRequest xhr = new HttpRequest(); | 15 HttpRequest xhr = new HttpRequest(); |
17 xhr.open("GET", "NonExistingFile", true); | 16 xhr.open("GET", "NonExistingFile", true); |
18 xhr.on.readyStateChange.add(expectAsyncUntil1((event) { | 17 xhr.on.readyStateChange.add(expectAsync1((event) { |
19 if (xhr.readyState == HttpRequest.DONE) { | 18 if (xhr.readyState == HttpRequest.DONE) { |
20 expect(xhr.status, equals(404)); | 19 expect(xhr.status, equals(0)); |
21 expect(xhr.responseText, equals('')); | 20 expect(xhr.responseText, equals('')); |
22 } | 21 } |
23 }, () => xhr.readyState == HttpRequest.DONE)); | 22 })); |
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)); | |
39 xhr.send(); | 23 xhr.send(); |
40 }); | 24 }); |
41 | 25 |
42 test('XHR.get No file', () { | 26 test('XHR.get No file', () { |
43 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { | 27 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { |
44 expect(xhr.readyState, equals(HttpRequest.DONE)); | 28 expect(xhr.readyState, equals(HttpRequest.DONE)); |
45 expect(xhr.status, equals(404)); | 29 expect(xhr.status, equals(0)); |
46 expect(xhr.responseText, equals('')); | 30 expect(xhr.responseText, equals('')); |
47 })); | 31 })); |
48 }); | 32 }); |
49 | |
50 test('XHR.get file', () { | |
51 var xhr = new HttpRequest.get(url, expectAsync1((event) { | |
52 expect(event.readyState, equals(HttpRequest.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 }); | |
77 } | 33 } |
OLD | NEW |