| 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:convert"; |
| 11 import 'dart:typed_data'; | 11 import 'dart:typed_data'; |
| 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: |
| 22 // https://code.google.com/p/dart/issues/detail?id=11834 | 22 // https://code.google.com/p/dart/issues/detail?id=11834 |
| 23 var cacheBlocker = new DateTime.now().millisecondsSinceEpoch; | 23 var cacheBlocker = new DateTime.now().millisecondsSinceEpoch; |
| 24 var url = '/root_dart/tests/html/xhr_cross_origin_data.txt?' | 24 var url = '/root_dart/tests/html/xhr_cross_origin_data.txt?' |
| 25 'cacheBlock=$cacheBlocker'; | 25 'cacheBlock=$cacheBlocker'; |
| 26 | 26 |
| 27 void validate200Response(xhr) { | 27 void validate200Response(xhr) { |
| 28 expect(xhr.status, equals(200)); | 28 expect(xhr.status, equals(200)); |
| 29 var data = json.parse(xhr.responseText); | 29 var data = JSON.decode(xhr.responseText); |
| 30 expect(data, contains('feed')); | 30 expect(data, contains('feed')); |
| 31 expect(data['feed'], contains('entry')); | 31 expect(data['feed'], contains('entry')); |
| 32 expect(data, isMap); | 32 expect(data, isMap); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void validate404(xhr) { | 35 void validate404(xhr) { |
| 36 expect(xhr.status, equals(404)); | 36 expect(xhr.status, equals(404)); |
| 37 expect(xhr.responseText, equals('')); | 37 expect(xhr.responseText, equals('')); |
| 38 } | 38 } |
| 39 | 39 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 (xhr) { | 235 (xhr) { |
| 236 expect(xhr.status, equals(200)); | 236 expect(xhr.status, equals(200)); |
| 237 var blob = xhr.response; | 237 var blob = xhr.response; |
| 238 expect(blob is Blob, isTrue); | 238 expect(blob is Blob, isTrue); |
| 239 expect(blob, isNotNull); | 239 expect(blob, isNotNull); |
| 240 }); | 240 }); |
| 241 } | 241 } |
| 242 }); | 242 }); |
| 243 }); | 243 }); |
| 244 } | 244 } |
| OLD | NEW |