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

Side by Side Diff: tests/html/xhr_test.dart

Issue 11641005: Add cross-origin test with credentials. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_config.dart'; 7 import '../../pkg/unittest/lib/html_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:json'; 9 import 'dart:json';
10 10
11 main() { 11 main() {
12 useHtmlConfiguration(); 12 useHtmlConfiguration();
13 var url = "../../../../tests/html/xhr_cross_origin_data.txt";
13 14
14 test('XHR No file', () { 15 test('XHR No file', () {
15 HttpRequest xhr = new HttpRequest(); 16 HttpRequest xhr = new HttpRequest();
16 xhr.open("GET", "NonExistingFile", true); 17 xhr.open("GET", "NonExistingFile", true);
17 xhr.on.readyStateChange.add(expectAsync1((event) { 18 xhr.on.readyStateChange.add(expectAsyncUntil1((event) {
18 if (xhr.readyState == HttpRequest.DONE) { 19 if (xhr.readyState == HttpRequest.DONE) {
19 expect(xhr.status, equals(0)); 20 expect(xhr.status, equals(404));
20 expect(xhr.responseText, equals('')); 21 expect(xhr.responseText, equals(''));
21 } 22 }
22 })); 23 }, () => xhr.readyState == HttpRequest.DONE));
24 xhr.send();
25 });
26
27 test('XHR file', () {
28 var xhr = new HttpRequest();
29 xhr.open('GET', url, true);
30 xhr.on.readyStateChange.add(expectAsyncUntil1((e) {
31 if (xhr.readyState == HttpRequest.DONE) {
32 expect(xhr.status, equals(200));
33 var data = JSON.parse(xhr.response);
34 expect(data, contains('feed'));
35 expect(data['feed'], contains('entry'));
36 expect(data, isMap);
37 }
38 }, () => xhr.readyState == HttpRequest.DONE));
23 xhr.send(); 39 xhr.send();
24 }); 40 });
25 41
26 test('XHR.get No file', () { 42 test('XHR.get No file', () {
27 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { 43 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) {
28 expect(xhr.readyState, equals(HttpRequest.DONE)); 44 expect(xhr.readyState, equals(HttpRequest.DONE));
29 expect(xhr.status, equals(0)); 45 expect(xhr.status, equals(404));
30 expect(xhr.responseText, equals('')); 46 expect(xhr.responseText, equals(''));
31 })); 47 }));
32 }); 48 });
49
50 test('XHR.get file', () {
51 var xhr = new HttpRequest.get(url, expectAsync1((xhr) {
52 expect(xhr.readyState, equals(HttpRequest.DONE));
53 expect(xhr.status, equals(200));
54 var data = JSON.parse(xhr.response);
55 expect(data, contains('feed'));
56 expect(data['feed'], contains('entry'));
57 expect(data, isMap);
58 }));
59 });
60
61 test('XHR.getWithCredentials No file', () {
62 new HttpRequest.getWithCredentials("NonExistingFile", expectAsync1((xhr) {
63 expect(xhr.status, equals(404));
64 expect(xhr.responseText, equals(''));
65 }));
66 });
67
68 test('XHR.getWithCredentials file', () {
69 new HttpRequest.getWithCredentials(url, expectAsync1((xhr) {
70 expect(xhr.status, equals(200));
71 var data = JSON.parse(xhr.response);
72 expect(data, contains('feed'));
73 expect(data['feed'], contains('entry'));
74 expect(data, isMap);
75 }));
76 });
33 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698