| 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_individual_config.dart'; | 7 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
| 10 | 10 |
| 11 void fail(message) { |
| 12 guardAsync(() { |
| 13 expect(false, isTrue, reason: message); |
| 14 }); |
| 15 } |
| 16 |
| 11 main() { | 17 main() { |
| 12 useHtmlIndividualConfiguration(); | 18 useHtmlIndividualConfiguration(); |
| 13 var url = "/tests/html/xhr_cross_origin_data.txt"; | 19 var url = "/tests/html/xhr_cross_origin_data.txt"; |
| 14 | 20 |
| 15 void validate200Response(xhr) { | 21 void validate200Response(xhr) { |
| 16 expect(xhr.status, equals(200)); | 22 expect(xhr.status, equals(200)); |
| 17 var data = json.parse(xhr.response); | 23 var data = json.parse(xhr.response); |
| 18 expect(data, contains('feed')); | 24 expect(data, contains('feed')); |
| 19 expect(data['feed'], contains('entry')); | 25 expect(data['feed'], contains('entry')); |
| 20 expect(data, isMap); | 26 expect(data, isMap); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 })); | 86 })); |
| 81 }); | 87 }); |
| 82 | 88 |
| 83 test('XHR.getWithCredentials file', () { | 89 test('XHR.getWithCredentials file', () { |
| 84 new HttpRequest.getWithCredentials(url, expectAsync1((xhr) { | 90 new HttpRequest.getWithCredentials(url, expectAsync1((xhr) { |
| 85 expect(xhr.readyState, equals(HttpRequest.DONE)); | 91 expect(xhr.readyState, equals(HttpRequest.DONE)); |
| 86 validate200Response(xhr); | 92 validate200Response(xhr); |
| 87 })); | 93 })); |
| 88 }); | 94 }); |
| 89 | 95 |
| 96 test('XHR.getString file', () { |
| 97 HttpRequest.getString(url).then(expectAsync1((str) {})); |
| 98 }); |
| 99 |
| 100 test('XHR.getString No file', () { |
| 101 HttpRequest.getString('NonExistingFile').then( |
| 102 (_) { fail('Succeeded for non-existing file.'); }, |
| 103 onError: expectAsync1((e) { |
| 104 validate404(e.error.target); |
| 105 })); |
| 106 }); |
| 107 |
| 108 test('XHR.request', () { |
| 109 if (ArrayBuffer.supported) { |
| 110 HttpRequest.request(url, responseType: 'ArrayBuffer').then( |
| 111 expectAsync1((xhr) { |
| 112 validate200Response(xhr); |
| 113 var arrayBuffer = xhr.response; |
| 114 expect(arrayBuffer, new isInstanceOf<ArrayBuffer>()); |
| 115 expect(arrayBuffer, isNotNull); |
| 116 })); |
| 117 } |
| 118 }); |
| 119 |
| 90 test('HttpRequestProgressEvent', () { | 120 test('HttpRequestProgressEvent', () { |
| 91 var expectation = HttpRequestProgressEvent.supported ? | 121 var expectation = HttpRequestProgressEvent.supported ? |
| 92 returnsNormally : throws; | 122 returnsNormally : throws; |
| 93 expect(() { | 123 expect(() { |
| 94 var event = new Event.eventType('XMLHttpRequestProgressEvent', ''); | 124 var event = new Event.eventType('XMLHttpRequestProgressEvent', ''); |
| 95 expect(event is HttpRequestProgressEvent, isTrue); | 125 expect(event is HttpRequestProgressEvent, isTrue); |
| 96 }, expectation); | 126 }, expectation); |
| 97 }); | 127 }); |
| 98 }); | 128 }); |
| 99 } | 129 } |
| OLD | NEW |