| 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 XHRCrossOriginTest; | 5 library XHRCrossOriginTest; |
| 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 }).catchError((error) {}, test: (error) { | 49 }).catchError((error) {}, test: (error) { |
| 50 gotError = true; | 50 gotError = true; |
| 51 // Consume errors when not supporting cross origin. | 51 // Consume errors when not supporting cross origin. |
| 52 return !HttpRequest.supportsCrossOrigin; | 52 return !HttpRequest.supportsCrossOrigin; |
| 53 }).whenComplete(() { | 53 }).whenComplete(() { |
| 54 // Expect that we got an error when cross origin is not supported. | 54 // Expect that we got an error when cross origin is not supported. |
| 55 expect(gotError, !HttpRequest.supportsCrossOrigin); | 55 expect(gotError, !HttpRequest.supportsCrossOrigin); |
| 56 }); | 56 }); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 test('XHR.requestCrossOrigin', () { |
| 60 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
| 61 return HttpRequest.requestCrossOrigin(url).then((response) { |
| 62 expect(response, contains('feed')); |
| 63 }); |
| 64 }); |
| 65 |
| 66 test('XHR.requestCrossOrigin errors', () { |
| 67 var gotError = false; |
| 68 return HttpRequest.requestCrossOrigin('does_not_exist').then((response) { |
| 69 expect(true, isFalse, reason: '404s should fail request.'); |
| 70 }).catchError((error) {}, test: (error) { |
| 71 gotError = true; |
| 72 return true; |
| 73 }).whenComplete(() { |
| 74 expect(gotError, isTrue); |
| 75 }); |
| 76 }); |
| 77 |
| 59 // Skip the rest if not supported. | 78 // Skip the rest if not supported. |
| 60 if (!HttpRequest.supportsCrossOrigin) { | 79 if (!HttpRequest.supportsCrossOrigin) { |
| 61 return; | 80 return; |
| 62 } | 81 } |
| 63 | 82 |
| 64 test('XHR Cross-domain', () { | 83 test('XHR Cross-domain', () { |
| 65 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; | 84 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
| 66 var xhr = new HttpRequest(); | 85 var xhr = new HttpRequest(); |
| 67 xhr.open('GET', url, async: true); | 86 xhr.open('GET', url, async: true); |
| 68 var validate = expectAsync1((data) { | 87 var validate = expectAsync1((data) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; | 103 var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
| 85 return HttpRequest.request(url, withCredentials: true).then((xhr) { | 104 return HttpRequest.request(url, withCredentials: true).then((xhr) { |
| 86 var data = json.parse(xhr.response); | 105 var data = json.parse(xhr.response); |
| 87 expect(data, contains('feed')); | 106 expect(data, contains('feed')); |
| 88 expect(data['feed'], contains('entry')); | 107 expect(data['feed'], contains('entry')); |
| 89 expect(data, isMap); | 108 expect(data, isMap); |
| 90 }); | 109 }); |
| 91 }); | 110 }); |
| 92 }); | 111 }); |
| 93 } | 112 } |
| OLD | NEW |