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'; | |
7 import '../../pkg/unittest/lib/html_individual_config.dart'; | |
8 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:convert'; |
9 import 'dart:html'; | 8 import 'dart:html'; |
10 import "dart:convert"; | |
11 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 import 'package:unittest/html_individual_config.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
12 | 12 |
13 void fail(message) { | 13 void fail(message) { |
14 guardAsync(() { | 14 guardAsync(() { |
15 expect(false, isTrue, reason: message); | 15 expect(false, isTrue, reason: message); |
16 }); | 16 }); |
17 } | 17 } |
18 | 18 |
19 main() { | 19 main() { |
20 useHtmlIndividualConfiguration(); | 20 useHtmlIndividualConfiguration(); |
21 // Cache blocker is a workaround for: | 21 // Cache blocker is a workaround for: |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 '${Uri.encodeQueryComponent(data[key])}'); | 218 '${Uri.encodeQueryComponent(data[key])}'); |
219 } | 219 } |
220 var encodedData = parts.join('&'); | 220 var encodedData = parts.join('&'); |
221 | 221 |
222 return HttpRequest.postFormData( | 222 return HttpRequest.postFormData( |
223 '${window.location.protocol}//${window.location.host}/echo', data) | 223 '${window.location.protocol}//${window.location.host}/echo', data) |
224 .then((xhr) { | 224 .then((xhr) { |
225 expect(xhr.responseText, encodedData); | 225 expect(xhr.responseText, encodedData); |
226 }); | 226 }); |
227 }); | 227 }); |
228 | |
229 }); | 228 }); |
230 | 229 |
231 group('xhr_requestBlob', () { | 230 group('xhr_requestBlob', () { |
232 test('XHR.request responseType blob', () { | 231 test('XHR.request responseType blob', () { |
233 if (Platform.supportsTypedData) { | 232 if (Platform.supportsTypedData) { |
234 return HttpRequest.request(url, responseType: 'blob').then( | 233 return HttpRequest.request(url, responseType: 'blob').then( |
235 (xhr) { | 234 (xhr) { |
236 expect(xhr.status, equals(200)); | 235 expect(xhr.status, equals(200)); |
237 var blob = xhr.response; | 236 var blob = xhr.response; |
238 expect(blob is Blob, isTrue); | 237 expect(blob is Blob, isTrue); |
239 expect(blob, isNotNull); | 238 expect(blob, isNotNull); |
240 }); | 239 }); |
241 } | 240 } |
242 }); | 241 }); |
243 }); | 242 }); |
| 243 |
| 244 group('json', () { |
| 245 test('xhr responseType json', () { |
| 246 var url = '${window.location.protocol}//${window.location.host}/echo'; |
| 247 var data = { |
| 248 'key': 'value', |
| 249 'a': 'b', |
| 250 'one': 2, |
| 251 }; |
| 252 |
| 253 HttpRequest.request(url, |
| 254 method: 'POST', |
| 255 sendData: JSON.encode(data), |
| 256 responseType: 'json').then( |
| 257 expectAsync1((xhr) { |
| 258 expect(xhr.status, equals(200)); |
| 259 var json = xhr.response; |
| 260 expect(json, equals(data)); |
| 261 })); |
| 262 }); |
| 263 }); |
244 } | 264 } |
OLD | NEW |