| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 xhr.onLoadEnd.listen((ProgressEvent e) { | 80 xhr.onLoadEnd.listen((ProgressEvent e) { |
| 81 loadEndCalled = true; | 81 loadEndCalled = true; |
| 82 }); | 82 }); |
| 83 xhr.send(); | 83 xhr.send(); |
| 84 }); | 84 }); |
| 85 | 85 |
| 86 test('XHR.request No file', () { | 86 test('XHR.request No file', () { |
| 87 HttpRequest.request('NonExistingFile').then( | 87 HttpRequest.request('NonExistingFile').then( |
| 88 (_) { fail('Request should not have succeeded.'); }, | 88 (_) { fail('Request should not have succeeded.'); }, |
| 89 onError: expectAsync1((e) { | 89 onError: expectAsync1((error) { |
| 90 var xhr = e.error.target; | 90 var xhr = error.target; |
| 91 expect(xhr.readyState, equals(HttpRequest.DONE)); | 91 expect(xhr.readyState, equals(HttpRequest.DONE)); |
| 92 validate404(xhr); | 92 validate404(xhr); |
| 93 })); | 93 })); |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 test('XHR.request file', () { | 96 test('XHR.request file', () { |
| 97 HttpRequest.request(url).then(expectAsync1((xhr) { | 97 HttpRequest.request(url).then(expectAsync1((xhr) { |
| 98 expect(xhr.readyState, equals(HttpRequest.DONE)); | 98 expect(xhr.readyState, equals(HttpRequest.DONE)); |
| 99 validate200Response(xhr); | 99 validate200Response(xhr); |
| 100 })); | 100 })); |
| 101 }); | 101 }); |
| 102 | 102 |
| 103 test('XHR.request onProgress', () { | 103 test('XHR.request onProgress', () { |
| 104 var progressCalled = false; | 104 var progressCalled = false; |
| 105 HttpRequest.request(url, | 105 HttpRequest.request(url, |
| 106 onProgress: (_) { | 106 onProgress: (_) { |
| 107 progressCalled = true; | 107 progressCalled = true; |
| 108 }).then(expectAsync1( | 108 }).then(expectAsync1( |
| 109 (xhr) { | 109 (xhr) { |
| 110 expect(xhr.readyState, equals(HttpRequest.DONE)); | 110 expect(xhr.readyState, equals(HttpRequest.DONE)); |
| 111 expect(progressCalled, HttpRequest.supportsProgressEvent); | 111 expect(progressCalled, HttpRequest.supportsProgressEvent); |
| 112 validate200Response(xhr); | 112 validate200Response(xhr); |
| 113 })); | 113 })); |
| 114 }); | 114 }); |
| 115 | 115 |
| 116 test('XHR.request withCredentials No file', () { | 116 test('XHR.request withCredentials No file', () { |
| 117 HttpRequest.request('NonExistingFile', withCredentials: true).then( | 117 HttpRequest.request('NonExistingFile', withCredentials: true).then( |
| 118 (_) { fail('Request should not have succeeded.'); }, | 118 (_) { fail('Request should not have succeeded.'); }, |
| 119 onError: expectAsync1((e) { | 119 onError: expectAsync1((error) { |
| 120 var xhr = e.error.target; | 120 var xhr = error.target; |
| 121 expect(xhr.readyState, equals(HttpRequest.DONE)); | 121 expect(xhr.readyState, equals(HttpRequest.DONE)); |
| 122 validate404(xhr); | 122 validate404(xhr); |
| 123 })); | 123 })); |
| 124 }); | 124 }); |
| 125 | 125 |
| 126 test('XHR.request withCredentials file', () { | 126 test('XHR.request withCredentials file', () { |
| 127 HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) { | 127 HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) { |
| 128 expect(xhr.readyState, equals(HttpRequest.DONE)); | 128 expect(xhr.readyState, equals(HttpRequest.DONE)); |
| 129 validate200Response(xhr); | 129 validate200Response(xhr); |
| 130 })); | 130 })); |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 test('XHR.getString file', () { | 133 test('XHR.getString file', () { |
| 134 HttpRequest.getString(url).then(expectAsync1((str) {})); | 134 HttpRequest.getString(url).then(expectAsync1((str) {})); |
| 135 }); | 135 }); |
| 136 | 136 |
| 137 test('XHR.getString No file', () { | 137 test('XHR.getString No file', () { |
| 138 HttpRequest.getString('NonExistingFile').then( | 138 HttpRequest.getString('NonExistingFile').then( |
| 139 (_) { fail('Succeeded for non-existing file.'); }, | 139 (_) { fail('Succeeded for non-existing file.'); }, |
| 140 onError: expectAsync1((e) { | 140 onError: expectAsync1((error) { |
| 141 validate404(e.error.target); | 141 validate404(error.target); |
| 142 })); | 142 })); |
| 143 }); | 143 }); |
| 144 | 144 |
| 145 test('XHR.request responseType arraybuffer', () { | 145 test('XHR.request responseType arraybuffer', () { |
| 146 if (ArrayBuffer.supported) { | 146 if (ArrayBuffer.supported) { |
| 147 HttpRequest.request(url, responseType: 'arraybuffer').then( | 147 HttpRequest.request(url, responseType: 'arraybuffer').then( |
| 148 expectAsync1((xhr) { | 148 expectAsync1((xhr) { |
| 149 expect(xhr.status, equals(200)); | 149 expect(xhr.status, equals(200)); |
| 150 var arrayBuffer = xhr.response; | 150 var arrayBuffer = xhr.response; |
| 151 expect(arrayBuffer, new isInstanceOf<ArrayBuffer>()); | 151 expect(arrayBuffer, new isInstanceOf<ArrayBuffer>()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 171 (xhr) { | 171 (xhr) { |
| 172 expect(xhr.status, equals(200)); | 172 expect(xhr.status, equals(200)); |
| 173 var blob = xhr.response; | 173 var blob = xhr.response; |
| 174 expect(blob is Blob, isTrue); | 174 expect(blob is Blob, isTrue); |
| 175 expect(blob, isNotNull); | 175 expect(blob, isNotNull); |
| 176 }); | 176 }); |
| 177 } | 177 } |
| 178 }); | 178 }); |
| 179 }); | 179 }); |
| 180 } | 180 } |
| OLD | NEW |