Chromium Code Reviews| Index: tests/html/xhr_test.dart |
| diff --git a/tests/html/xhr_test.dart b/tests/html/xhr_test.dart |
| index 4d0ac0699233add59bdf2b56359fd55fe2bd1d6c..beebebc67237c845a437fca383c32907eba73a31 100644 |
| --- a/tests/html/xhr_test.dart |
| +++ b/tests/html/xhr_test.dart |
| @@ -6,27 +6,72 @@ library XHRTest; |
| import '../../pkg/unittest/lib/unittest.dart'; |
| import '../../pkg/unittest/lib/html_config.dart'; |
| import 'dart:html'; |
| +import 'dart:json' as json; |
| main() { |
| useHtmlConfiguration(); |
| + var url = "../../../../tests/html/xhr_cross_origin_data.txt"; |
| test('XHR No file', () { |
| HttpRequest xhr = new HttpRequest(); |
| xhr.open("GET", "NonExistingFile", true); |
| - xhr.on.readyStateChange.add(expectAsync1((event) { |
| + xhr.on.readyStateChange.add(expectAsyncUntil1((event) { |
|
blois
2013/01/10 17:58:16
Does the load event not suffice here?
|
| if (xhr.readyState == HttpRequest.DONE) { |
| - expect(xhr.status, equals(0)); |
| + expect(xhr.status, equals(404)); |
| expect(xhr.responseText, equals('')); |
| } |
| - })); |
| + }, () => xhr.readyState == HttpRequest.DONE)); |
| + xhr.send(); |
| + }); |
| + |
| + test('XHR file', () { |
| + var xhr = new HttpRequest(); |
| + xhr.open('GET', url, true); |
| + xhr.on.readyStateChange.add(expectAsyncUntil1((e) { |
| + if (xhr.readyState == HttpRequest.DONE) { |
| + expect(xhr.status, equals(200)); |
| + var data = json.parse(xhr.response); |
| + expect(data, contains('feed')); |
| + expect(data['feed'], contains('entry')); |
| + expect(data, isMap); |
| + } |
| + }, () => xhr.readyState == HttpRequest.DONE)); |
| xhr.send(); |
| }); |
| test('XHR.get No file', () { |
| new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { |
| expect(xhr.readyState, equals(HttpRequest.DONE)); |
| - expect(xhr.status, equals(0)); |
| + expect(xhr.status, equals(404)); |
| + expect(xhr.responseText, equals('')); |
| + })); |
| + }); |
| + |
| + test('XHR.get file', () { |
| + var xhr = new HttpRequest.get(url, expectAsync1((event) { |
| + expect(event.readyState, equals(HttpRequest.DONE)); |
|
ricow1
2013/01/10 20:03:41
I would extract this body into a function, we do t
Emily Fortuna
2013/01/11 02:57:12
Done.
|
| + expect(event.status, equals(200)); |
| + var data = json.parse(event.response); |
| + expect(data, contains('feed')); |
| + expect(data['feed'], contains('entry')); |
| + expect(data, isMap); |
| + })); |
| + }); |
| + |
| + test('XHR.getWithCredentials No file', () { |
| + new HttpRequest.getWithCredentials("NonExistingFile", expectAsync1((xhr) { |
| + expect(xhr.status, equals(404)); |
| expect(xhr.responseText, equals('')); |
| })); |
| }); |
| + |
| + test('XHR.getWithCredentials file', () { |
| + new HttpRequest.getWithCredentials(url, expectAsync1((xhr) { |
| + expect(xhr.status, equals(200)); |
| + var data = json.parse(xhr.response); |
| + expect(data, contains('feed')); |
| + expect(data['feed'], contains('entry')); |
| + expect(data, isMap); |
| + })); |
| + }); |
| } |