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 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
10 import 'package:unittest/html_individual_config.dart'; | 10 import 'package:unittest/html_individual_config.dart'; |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
12 | 12 |
13 void fail(message) { | |
14 guardAsync(() { | |
15 expect(false, isTrue, reason: message); | |
16 }); | |
17 } | |
18 | |
19 main() { | 13 main() { |
20 useHtmlIndividualConfiguration(); | 14 useHtmlIndividualConfiguration(); |
21 // Cache blocker is a workaround for: | 15 // Cache blocker is a workaround for: |
22 // https://code.google.com/p/dart/issues/detail?id=11834 | 16 // https://code.google.com/p/dart/issues/detail?id=11834 |
23 var cacheBlocker = new DateTime.now().millisecondsSinceEpoch; | 17 var cacheBlocker = new DateTime.now().millisecondsSinceEpoch; |
24 var url = '/root_dart/tests/html/xhr_cross_origin_data.txt?' | 18 var url = '/root_dart/tests/html/xhr_cross_origin_data.txt?' |
25 'cacheBlock=$cacheBlocker'; | 19 'cacheBlock=$cacheBlocker'; |
26 | 20 |
27 void validate200Response(xhr) { | 21 void validate200Response(xhr) { |
28 expect(xhr.status, equals(200)); | 22 expect(xhr.status, equals(200)); |
(...skipping 23 matching lines...) Expand all Loading... |
52 group('supported_overrideMimeType', () { | 46 group('supported_overrideMimeType', () { |
53 test('supported', () { | 47 test('supported', () { |
54 expect(HttpRequest.supportsOverrideMimeType, isTrue); | 48 expect(HttpRequest.supportsOverrideMimeType, isTrue); |
55 }); | 49 }); |
56 }); | 50 }); |
57 | 51 |
58 group('xhr', () { | 52 group('xhr', () { |
59 test('XHR No file', () { | 53 test('XHR No file', () { |
60 HttpRequest xhr = new HttpRequest(); | 54 HttpRequest xhr = new HttpRequest(); |
61 xhr.open("GET", "NonExistingFile", async: true); | 55 xhr.open("GET", "NonExistingFile", async: true); |
62 xhr.onReadyStateChange.listen(expectAsyncUntil1((event) { | 56 xhr.onReadyStateChange.listen(expectAsyncUntil((event) { |
63 if (xhr.readyState == HttpRequest.DONE) { | 57 if (xhr.readyState == HttpRequest.DONE) { |
64 validate404(xhr); | 58 validate404(xhr); |
65 } | 59 } |
66 }, () => xhr.readyState == HttpRequest.DONE)); | 60 }, () => xhr.readyState == HttpRequest.DONE)); |
67 xhr.send(); | 61 xhr.send(); |
68 }); | 62 }); |
69 | 63 |
70 test('XHR file', () { | 64 test('XHR file', () { |
71 var loadEndCalled = false; | 65 var loadEndCalled = false; |
72 | 66 |
73 var xhr = new HttpRequest(); | 67 var xhr = new HttpRequest(); |
74 xhr.open('GET', url, async: true); | 68 xhr.open('GET', url, async: true); |
75 xhr.onReadyStateChange.listen(expectAsyncUntil1((e) { | 69 xhr.onReadyStateChange.listen(expectAsyncUntil((e) { |
76 if (xhr.readyState == HttpRequest.DONE) { | 70 if (xhr.readyState == HttpRequest.DONE) { |
77 validate200Response(xhr); | 71 validate200Response(xhr); |
78 | 72 |
79 Timer.run(expectAsync(() { | 73 Timer.run(expectAsync(() { |
80 expect(loadEndCalled, HttpRequest.supportsLoadEndEvent); | 74 expect(loadEndCalled, HttpRequest.supportsLoadEndEvent); |
81 })); | 75 })); |
82 } | 76 } |
83 }, () => xhr.readyState == HttpRequest.DONE)); | 77 }, () => xhr.readyState == HttpRequest.DONE)); |
84 | 78 |
85 xhr.onLoadEnd.listen((ProgressEvent e) { | 79 xhr.onLoadEnd.listen((ProgressEvent e) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return HttpRequest.request(url).then( | 246 return HttpRequest.request(url).then( |
253 (xhr) { | 247 (xhr) { |
254 var serverHeader = xhr.responseHeaders['server']; | 248 var serverHeader = xhr.responseHeaders['server']; |
255 expect(serverHeader, isNotNull); | 249 expect(serverHeader, isNotNull); |
256 // Should be like: 'Dart/0.1 (dart:io)' | 250 // Should be like: 'Dart/0.1 (dart:io)' |
257 expect(serverHeader.startsWith('Dart/'), isTrue); | 251 expect(serverHeader.startsWith('Dart/'), isTrue); |
258 }); | 252 }); |
259 }); | 253 }); |
260 }); | 254 }); |
261 } | 255 } |
OLD | NEW |