Index: tests/html/xhr_cross_origin_test.dart |
diff --git a/tests/html/xhr_cross_origin_test.dart b/tests/html/xhr_cross_origin_test.dart |
index 77500467fef5ee23445d6d76791a6daa210a7895..cb56240317d654bb84b42d85b718bc9a035c473f 100644 |
--- a/tests/html/xhr_cross_origin_test.dart |
+++ b/tests/html/xhr_cross_origin_test.dart |
@@ -4,7 +4,7 @@ |
library XHRCrossOriginTest; |
import '../../pkg/unittest/lib/unittest.dart'; |
-import '../../pkg/unittest/lib/html_config.dart'; |
+import '../../pkg/unittest/lib/html_individual_config.dart'; |
import 'dart:html'; |
import 'dart:json' as json; |
@@ -25,47 +25,69 @@ int get crossOriginPort { |
} |
main() { |
- useHtmlConfiguration(); |
+ useHtmlIndividualConfiguration(); |
- var port = crossOriginPort; |
- var host = '${window.location.protocol}//${window.location.hostname}:$port'; |
- |
- test('XHR Cross-domain', () { |
- var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
- var xhr = new HttpRequest(); |
- xhr.open('GET', url, async: true); |
- var validate = expectAsync1((data) { |
- expect(data, contains('feed')); |
- expect(data['feed'], contains('entry')); |
- expect(data, isMap); |
+ group('supported', () { |
+ test('supported', () { |
+ expect(HttpRequest.supportsCrossOrigin, isTrue); |
}); |
- xhr.onReadyStateChange.listen((e) { |
- guardAsync(() { |
- if (xhr.readyState == HttpRequest.DONE) { |
- validate(json.parse(xhr.response)); |
- } |
+ }); |
+ |
+ group('functional', () { |
+ |
+ var port = crossOriginPort; |
+ var host = '${window.location.protocol}//${window.location.hostname}:$port'; |
+ |
+ test('XHR.get Cross-domain', () { |
+ var gotError = false; |
+ var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
+ return HttpRequest.request(url).then((xhr) { |
+ var data = json.parse(xhr.response); |
+ expect(data, contains('feed')); |
+ expect(data['feed'], contains('entry')); |
+ expect(data, isMap); |
+ }).catchError((error) {}, test: (error) { |
+ gotError = true; |
+ // Consume errors when not supporting cross origin. |
+ return !HttpRequest.supportsCrossOrigin; |
+ }).whenComplete(() { |
+ // Expect that we got an error when cross origin is not supported. |
+ expect(gotError, !HttpRequest.supportsCrossOrigin); |
}); |
}); |
- xhr.send(); |
- }); |
- test('XHR.get Cross-domain', () { |
- var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
- HttpRequest.request(url).then(expectAsync1((xhr) { |
- var data = json.parse(xhr.response); |
- expect(data, contains('feed')); |
- expect(data['feed'], contains('entry')); |
- expect(data, isMap); |
- })); |
- }); |
+ // Skip the rest if not supported. |
+ if (!HttpRequest.supportsCrossOrigin) { |
+ return; |
+ } |
- test('XHR.getWithCredentials Cross-domain', () { |
- var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
- HttpRequest.request(url, withCredentials: true).then(expectAsync1((xhr) { |
- var data = json.parse(xhr.response); |
- expect(data, contains('feed')); |
- expect(data['feed'], contains('entry')); |
- expect(data, isMap); |
- })); |
+ test('XHR Cross-domain', () { |
+ var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
+ var xhr = new HttpRequest(); |
+ xhr.open('GET', url, async: true); |
+ var validate = expectAsync1((data) { |
+ expect(data, contains('feed')); |
+ expect(data['feed'], contains('entry')); |
+ expect(data, isMap); |
+ }); |
+ xhr.onReadyStateChange.listen((e) { |
+ guardAsync(() { |
+ if (xhr.readyState == HttpRequest.DONE) { |
+ validate(json.parse(xhr.response)); |
+ } |
+ }); |
+ }); |
+ xhr.send(); |
+ }); |
+ |
+ test('XHR.getWithCredentials Cross-domain', () { |
+ var url = '$host/root_dart/tests/html/xhr_cross_origin_data.txt'; |
+ return HttpRequest.request(url, withCredentials: true).then((xhr) { |
+ var data = json.parse(xhr.response); |
+ expect(data, contains('feed')); |
+ expect(data['feed'], contains('entry')); |
+ expect(data, isMap); |
+ }); |
+ }); |
}); |
} |