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

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

Issue 12041082: Adding supported checks for HttpRequestProgressEvent. (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
« 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_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 10
11 main() { 11 main() {
12 useHtmlConfiguration(); 12 useHtmlIndividualConfiguration();
13 var url = "/tests/html/xhr_cross_origin_data.txt"; 13 var url = "/tests/html/xhr_cross_origin_data.txt";
14 14
15 void validate200Response(xhr) { 15 void validate200Response(xhr) {
16 expect(xhr.status, equals(200)); 16 expect(xhr.status, equals(200));
17 var data = json.parse(xhr.response); 17 var data = json.parse(xhr.response);
18 expect(data, contains('feed')); 18 expect(data, contains('feed'));
19 expect(data['feed'], contains('entry')); 19 expect(data['feed'], contains('entry'));
20 expect(data, isMap); 20 expect(data, isMap);
21 } 21 }
22 22
23 void validate404(xhr) { 23 void validate404(xhr) {
24 expect(xhr.status, equals(404)); 24 expect(xhr.status, equals(404));
25 expect(xhr.responseText, equals('')); 25 expect(xhr.responseText, equals(''));
26 } 26 }
27 27
28 test('XHR No file', () { 28 group('supported_HttpRequestProgressEvent', () {
29 HttpRequest xhr = new HttpRequest(); 29 test('supported', () {
30 xhr.open("GET", "NonExistingFile", true); 30 expect(HttpRequestProgressEvent.supported, isTrue);
31 xhr.on.readyStateChange.add(expectAsyncUntil1((event) { 31 });
32 if (xhr.readyState == HttpRequest.DONE) {
33 validate404(xhr);
34 }
35 }, () => xhr.readyState == HttpRequest.DONE));
36 xhr.send();
37 }); 32 });
38 33
39 test('XHR file', () { 34 group('xhr', () {
40 var xhr = new HttpRequest(); 35 test('XHR No file', () {
41 xhr.open('GET', url, true); 36 HttpRequest xhr = new HttpRequest();
42 xhr.on.readyStateChange.add(expectAsyncUntil1((e) { 37 xhr.open("GET", "NonExistingFile", true);
43 if (xhr.readyState == HttpRequest.DONE) { 38 xhr.on.readyStateChange.add(expectAsyncUntil1((event) {
39 if (xhr.readyState == HttpRequest.DONE) {
40 validate404(xhr);
41 }
42 }, () => xhr.readyState == HttpRequest.DONE));
43 xhr.send();
44 });
45
46 test('XHR file', () {
47 var xhr = new HttpRequest();
48 xhr.open('GET', url, true);
49 xhr.on.readyStateChange.add(expectAsyncUntil1((e) {
50 if (xhr.readyState == HttpRequest.DONE) {
51 validate200Response(xhr);
52 }
53 }, () => xhr.readyState == HttpRequest.DONE));
54 xhr.send();
55 });
56
57 test('XHR.get No file', () {
58 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) {
59 expect(xhr.readyState, equals(HttpRequest.DONE));
60 validate404(xhr);
61 }));
62 });
63
64 test('XHR.get file', () {
65 var xhr = new HttpRequest.get(url, expectAsync1((event) {
66 expect(event.readyState, equals(HttpRequest.DONE));
67 validate200Response(event);
68 }));
69 });
70
71 test('XHR.getWithCredentials No file', () {
72 new HttpRequest.getWithCredentials("NonExistingFile", expectAsync1((xhr) {
73 expect(xhr.readyState, equals(HttpRequest.DONE));
74 validate404(xhr);
75 }));
76 });
77
78 test('XHR.getWithCredentials file', () {
79 new HttpRequest.getWithCredentials(url, expectAsync1((xhr) {
80 expect(xhr.readyState, equals(HttpRequest.DONE));
44 validate200Response(xhr); 81 validate200Response(xhr);
45 } 82 }));
46 }, () => xhr.readyState == HttpRequest.DONE)); 83 });
47 xhr.send();
48 });
49 84
50 test('XHR.get No file', () { 85 test('HttpRequestProgressEvent', () {
51 new HttpRequest.get("NonExistingFile", expectAsync1((xhr) { 86 var expectation = HttpRequestProgressEvent.supported ?
52 expect(xhr.readyState, equals(HttpRequest.DONE)); 87 returnsNormally : throws;
53 validate404(xhr); 88 expect(() {
54 })); 89 var event = new Event.eventType('XMLHttpRequestProgressEvent', '');
55 }); 90 expect(event is HttpRequestProgressEvent, isTrue);
56 91 }, expectation);
57 test('XHR.get file', () { 92 });
58 var xhr = new HttpRequest.get(url, expectAsync1((event) {
59 expect(event.readyState, equals(HttpRequest.DONE));
60 validate200Response(event);
61 }));
62 });
63
64 test('XHR.getWithCredentials No file', () {
65 new HttpRequest.getWithCredentials("NonExistingFile", expectAsync1((xhr) {
66 expect(xhr.readyState, equals(HttpRequest.DONE));
67 validate404(xhr);
68 }));
69 });
70
71 test('XHR.getWithCredentials file', () {
72 new HttpRequest.getWithCredentials(url, expectAsync1((xhr) {
73 expect(xhr.readyState, equals(HttpRequest.DONE));
74 validate200Response(xhr);
75 }));
76 }); 93 });
77 } 94 }
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