Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1939)

Unified Diff: tests/html/xhr_test.dart

Issue 11810004: Make browser tests all run from a server instead of the local filesystem. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/html/xhr_test.dart
diff --git a/tests/html/xhr_test.dart b/tests/html/xhr_test.dart
index 4d0ac0699233add59bdf2b56359fd55fe2bd1d6c..0db7f4fd72d5894d7bcaf5449c6f7411146c122a 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";
+
+ void validate200Response(xhr) {
+ expect(xhr.status, equals(200));
+ var data = json.parse(xhr.response);
+ expect(data, contains('feed'));
+ expect(data['feed'], contains('entry'));
+ expect(data, isMap);
+ }
+
+ void validate404(xhr) {
+ expect(xhr.status, equals(404));
+ expect(xhr.responseText, equals(''));
+ }
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) {
if (xhr.readyState == HttpRequest.DONE) {
- expect(xhr.status, equals(0));
- expect(xhr.responseText, equals(''));
+ validate404(xhr);
}
- }));
+ }, () => 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) {
+ validate200Response(xhr);
+ }
+ }, () => 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.responseText, equals(''));
+ validate404(xhr);
+ }));
+ });
+
+ test('XHR.get file', () {
+ var xhr = new HttpRequest.get(url, expectAsync1((event) {
+ expect(event.readyState, equals(HttpRequest.DONE));
+ validate200Response(event);
+ }));
+ });
+
+ test('XHR.getWithCredentials No file', () {
+ new HttpRequest.getWithCredentials("NonExistingFile", expectAsync1((xhr) {
+ expect(xhr.readyState, equals(HttpRequest.DONE));
+ validate404(xhr);
+ }));
+ });
+
+ test('XHR.getWithCredentials file', () {
+ new HttpRequest.getWithCredentials(url, expectAsync1((xhr) {
+ expect(xhr.readyState, equals(HttpRequest.DONE));
+ validate200Response(xhr);
}));
});
}

Powered by Google App Engine
This is Rietveld 408576698