| 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:async'; | 8 import 'dart:async'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:json' as json; | 10 import 'dart:json' as json; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 expect(HttpRequest.supportsProgressEvent, isTrue); | 44 expect(HttpRequest.supportsProgressEvent, isTrue); |
| 45 }); | 45 }); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 group('supported_onLoadEnd', () { | 48 group('supported_onLoadEnd', () { |
| 49 test('supported', () { | 49 test('supported', () { |
| 50 expect(HttpRequest.supportsLoadEndEvent, isTrue); | 50 expect(HttpRequest.supportsLoadEndEvent, isTrue); |
| 51 }); | 51 }); |
| 52 }); | 52 }); |
| 53 | 53 |
| 54 group('supported_overrideMimeType', () { |
| 55 test('supported', () { |
| 56 expect(HttpRequest.supportsOverrideMimeType, isTrue); |
| 57 }); |
| 58 }); |
| 59 |
| 54 group('xhr', () { | 60 group('xhr', () { |
| 55 test('XHR No file', () { | 61 test('XHR No file', () { |
| 56 HttpRequest xhr = new HttpRequest(); | 62 HttpRequest xhr = new HttpRequest(); |
| 57 xhr.open("GET", "NonExistingFile", async: true); | 63 xhr.open("GET", "NonExistingFile", async: true); |
| 58 xhr.onReadyStateChange.listen(expectAsyncUntil1((event) { | 64 xhr.onReadyStateChange.listen(expectAsyncUntil1((event) { |
| 59 if (xhr.readyState == HttpRequest.DONE) { | 65 if (xhr.readyState == HttpRequest.DONE) { |
| 60 validate404(xhr); | 66 validate404(xhr); |
| 61 } | 67 } |
| 62 }, () => xhr.readyState == HttpRequest.DONE)); | 68 }, () => xhr.readyState == HttpRequest.DONE)); |
| 63 xhr.send(); | 69 xhr.send(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 HttpRequest.getString('NonExistingFile').then( | 145 HttpRequest.getString('NonExistingFile').then( |
| 140 (_) { fail('Succeeded for non-existing file.'); }, | 146 (_) { fail('Succeeded for non-existing file.'); }, |
| 141 onError: expectAsync1((error) { | 147 onError: expectAsync1((error) { |
| 142 validate404(error.target); | 148 validate404(error.target); |
| 143 })); | 149 })); |
| 144 }); | 150 }); |
| 145 | 151 |
| 146 test('XHR.request responseType arraybuffer', () { | 152 test('XHR.request responseType arraybuffer', () { |
| 147 if (Platform.supportsTypedData) { | 153 if (Platform.supportsTypedData) { |
| 148 HttpRequest.request(url, responseType: 'arraybuffer', | 154 HttpRequest.request(url, responseType: 'arraybuffer', |
| 149 mimeType: 'application/binary', | |
| 150 requestHeaders: {'Content-Type': 'text/xml'}).then( | 155 requestHeaders: {'Content-Type': 'text/xml'}).then( |
| 151 expectAsync1((xhr) { | 156 expectAsync1((xhr) { |
| 152 expect(xhr.status, equals(200)); | 157 expect(xhr.status, equals(200)); |
| 153 var byteBuffer = xhr.response; | 158 var byteBuffer = xhr.response; |
| 154 expect(byteBuffer, new isInstanceOf<ByteBuffer>()); | 159 expect(byteBuffer, new isInstanceOf<ByteBuffer>()); |
| 155 expect(byteBuffer, isNotNull); | 160 expect(byteBuffer, isNotNull); |
| 156 })); | 161 })); |
| 157 } | 162 } |
| 158 }); | 163 }); |
| 159 | 164 |
| 160 test('HttpRequestProgressEvent', () { | 165 test('HttpRequestProgressEvent', () { |
| 161 var expectation = HttpRequestProgressEvent.supported ? | 166 var expectation = HttpRequestProgressEvent.supported ? |
| 162 returnsNormally : throws; | 167 returnsNormally : throws; |
| 163 expect(() { | 168 expect(() { |
| 164 var event = new Event.eventType('XMLHttpRequestProgressEvent', ''); | 169 var event = new Event.eventType('XMLHttpRequestProgressEvent', ''); |
| 165 expect(event is HttpRequestProgressEvent, isTrue); | 170 expect(event is HttpRequestProgressEvent, isTrue); |
| 166 }, expectation); | 171 }, expectation); |
| 167 }); | 172 }); |
| 173 |
| 174 test('overrideMimeType', () { |
| 175 var expectation = |
| 176 HttpRequest.supportsOverrideMimeType ? returnsNormally : throws; |
| 177 |
| 178 expect(() { |
| 179 HttpRequest.request(url, mimeType: 'application/binary'); |
| 180 }, expectation); |
| 181 }); |
| 168 }); | 182 }); |
| 169 | 183 |
| 170 group('xhr_requestBlob', () { | 184 group('xhr_requestBlob', () { |
| 171 test('XHR.request responseType blob', () { | 185 test('XHR.request responseType blob', () { |
| 172 if (Platform.supportsTypedData) { | 186 if (Platform.supportsTypedData) { |
| 173 return HttpRequest.request(url, responseType: 'blob').then( | 187 return HttpRequest.request(url, responseType: 'blob').then( |
| 174 (xhr) { | 188 (xhr) { |
| 175 expect(xhr.status, equals(200)); | 189 expect(xhr.status, equals(200)); |
| 176 var blob = xhr.response; | 190 var blob = xhr.response; |
| 177 expect(blob is Blob, isTrue); | 191 expect(blob is Blob, isTrue); |
| 178 expect(blob, isNotNull); | 192 expect(blob, isNotNull); |
| 179 }); | 193 }); |
| 180 } | 194 } |
| 181 }); | 195 }); |
| 182 }); | 196 }); |
| 183 } | 197 } |
| OLD | NEW |