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

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

Issue 12230033: Adding supported checks and flags to FormData (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixing up XHR test as well. Created 7 years, 10 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
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/scripts/generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_individual_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:async';
8 import 'dart:html'; 9 import 'dart:html';
9 import 'dart:json' as json; 10 import 'dart:json' as json;
10 11
11 void fail(message) { 12 void fail(message) {
12 guardAsync(() { 13 guardAsync(() {
13 expect(false, isTrue, reason: message); 14 expect(false, isTrue, reason: message);
14 }); 15 });
15 } 16 }
16 17
17 main() { 18 main() {
18 useHtmlIndividualConfiguration(); 19 useHtmlIndividualConfiguration();
19 var url = "/tests/html/xhr_cross_origin_data.txt"; 20 var url = "/tests/html/xhr_cross_origin_data.txt";
20 21
21 void validate200Response(xhr) { 22 void validate200Response(xhr) {
22 expect(xhr.status, equals(200)); 23 expect(xhr.status, equals(200));
23 var data = json.parse(xhr.response); 24 var data = json.parse(xhr.responseText);
24 expect(data, contains('feed')); 25 expect(data, contains('feed'));
25 expect(data['feed'], contains('entry')); 26 expect(data['feed'], contains('entry'));
26 expect(data, isMap); 27 expect(data, isMap);
27 } 28 }
28 29
29 void validate404(xhr) { 30 void validate404(xhr) {
30 expect(xhr.status, equals(404)); 31 expect(xhr.status, equals(404));
31 expect(xhr.responseText, equals('')); 32 expect(xhr.responseText, equals(''));
32 } 33 }
33 34
34 group('supported_HttpRequestProgressEvent', () { 35 group('supported_HttpRequestProgressEvent', () {
35 test('supported', () { 36 test('supported', () {
36 expect(HttpRequestProgressEvent.supported, isTrue); 37 expect(HttpRequestProgressEvent.supported, isTrue);
37 }); 38 });
38 }); 39 });
39 40
41 group('supported_onProgress', () {
42 test('XHR.request onProgress', () {
Emily Fortuna 2013/02/14 21:56:23 this doesn't actually perform a supported check ..
blois 2013/02/14 23:22:45 Yeah, I was thinking that it was sufficient to jus
43 var progressCalled = false;
44 HttpRequest.request(url,
45 onProgress: (_) {
46 progressCalled = true;
47 }).then(expectAsync1(
48 (xhr) {
49 expect(xhr.readyState, equals(HttpRequest.DONE));
50 expect(progressCalled, isTrue);
51 validate200Response(xhr);
52 }));
53 });
54 });
55
56 group('supported_onLoadEnd', () {
57 test('XHR file', () {
58 var loadEndCalled = false;
59
60 var xhr = new HttpRequest();
61 xhr.open('GET', url, true);
62 xhr.onReadyStateChange.listen(expectAsyncUntil1((e) {
63 if (xhr.readyState == HttpRequest.DONE) {
64 validate200Response(xhr);
65
66 Timer.run(expectAsync0(() {
67 expect(loadEndCalled, true);
68 }));
69 }
70 }, () => xhr.readyState == HttpRequest.DONE));
71
72
73 xhr.onLoadEnd.listen((ProgressEvent e) {
74 loadEndCalled = true;
75 });
76 xhr.send();
77 });
78 });
79
40 group('xhr', () { 80 group('xhr', () {
41 test('XHR No file', () { 81 test('XHR No file', () {
42 HttpRequest xhr = new HttpRequest(); 82 HttpRequest xhr = new HttpRequest();
43 xhr.open("GET", "NonExistingFile", true); 83 xhr.open("GET", "NonExistingFile", true);
44 xhr.onReadyStateChange.listen(expectAsyncUntil1((event) { 84 xhr.onReadyStateChange.listen(expectAsyncUntil1((event) {
45 if (xhr.readyState == HttpRequest.DONE) { 85 if (xhr.readyState == HttpRequest.DONE) {
46 validate404(xhr); 86 validate404(xhr);
47 } 87 }
48 }, () => xhr.readyState == HttpRequest.DONE)); 88 }, () => xhr.readyState == HttpRequest.DONE));
49 xhr.send(); 89 xhr.send();
50 }); 90 });
51 91
52 test('XHR file', () {
53 var xhr = new HttpRequest();
54 xhr.open('GET', url, true);
55 xhr.onReadyStateChange.listen(expectAsyncUntil1((e) {
56 if (xhr.readyState == HttpRequest.DONE) {
57 validate200Response(xhr);
58 }
59 }, () => xhr.readyState == HttpRequest.DONE));
60
61 xhr.onLoadEnd.listen(expectAsync1((ProgressEvent e) {
62 expect(e.currentTarget, xhr);
63 expect(e.target, xhr);
64 }));
65 xhr.send();
66 });
67
68 test('XHR.request No file', () { 92 test('XHR.request No file', () {
69 HttpRequest.request('NonExistingFile').then( 93 HttpRequest.request('NonExistingFile').then(
70 (_) { fail('Request should not have succeeded.'); }, 94 (_) { fail('Request should not have succeeded.'); },
71 onError: expectAsync1((e) { 95 onError: expectAsync1((e) {
72 var xhr = e.error.target; 96 var xhr = e.error.target;
73 expect(xhr.readyState, equals(HttpRequest.DONE)); 97 expect(xhr.readyState, equals(HttpRequest.DONE));
74 validate404(xhr); 98 validate404(xhr);
75 })); 99 }));
76 }); 100 });
77 101
78 test('XHR.request file', () { 102 test('XHR.request file', () {
79 HttpRequest.request(url).then(expectAsync1((xhr) { 103 HttpRequest.request(url).then(expectAsync1((xhr) {
80 expect(xhr.readyState, equals(HttpRequest.DONE)); 104 expect(xhr.readyState, equals(HttpRequest.DONE));
81 validate200Response(xhr); 105 validate200Response(xhr);
82 })); 106 }));
83 }); 107 });
84 108
85 test('XHR.request onProgress', () {
86 var progressCalled = false;
87 HttpRequest.request(url,
88 onProgress: (_) {
89 progressCalled = true;
90 }).then(expectAsync1(
91 (xhr) {
92 expect(xhr.readyState, equals(HttpRequest.DONE));
93 expect(progressCalled, isTrue);
94 validate200Response(xhr);
95 }));
96 });
97
98 test('XHR.request withCredentials No file', () { 109 test('XHR.request withCredentials No file', () {
99 HttpRequest.request('NonExistingFile', withCredentials: true).then( 110 HttpRequest.request('NonExistingFile', withCredentials: true).then(
100 (_) { fail('Request should not have succeeded.'); }, 111 (_) { fail('Request should not have succeeded.'); },
101 onError: expectAsync1((e) { 112 onError: expectAsync1((e) {
102 var xhr = e.error.target; 113 var xhr = e.error.target;
103 expect(xhr.readyState, equals(HttpRequest.DONE)); 114 expect(xhr.readyState, equals(HttpRequest.DONE));
104 validate404(xhr); 115 validate404(xhr);
105 })); 116 }));
106 }); 117 });
107 118
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 test('HttpRequestProgressEvent', () { 150 test('HttpRequestProgressEvent', () {
140 var expectation = HttpRequestProgressEvent.supported ? 151 var expectation = HttpRequestProgressEvent.supported ?
141 returnsNormally : throws; 152 returnsNormally : throws;
142 expect(() { 153 expect(() {
143 var event = new Event.eventType('XMLHttpRequestProgressEvent', ''); 154 var event = new Event.eventType('XMLHttpRequestProgressEvent', '');
144 expect(event is HttpRequestProgressEvent, isTrue); 155 expect(event is HttpRequestProgressEvent, isTrue);
145 }, expectation); 156 }, expectation);
146 }); 157 });
147 }); 158 });
148 } 159 }
OLDNEW
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/scripts/generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698