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

Side by Side Diff: tests/standalone/io/http_client_test.dart

Issue 11231070: Fix bug in HTTP client request generation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « runtime/bin/websocket_impl.dart ('k') | no next file » | 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 #import("dart:io"); 5 #import("dart:io");
6 #import("dart:uri"); 6 #import("dart:uri");
7 #import("dart:isolate"); 7 #import("dart:isolate");
8 8
9 void testGoogle() { 9 void testGoogle() {
10 HttpClient client = new HttpClient(); 10 HttpClient client = new HttpClient();
11 var conn = client.get('www.google.com', 80, '/'); 11 var conn = client.get('www.google.com', 80, '/');
12 12
13 conn.onRequest = (HttpClientRequest request) { 13 conn.onRequest = (HttpClientRequest request) {
14 request.outputStream.close(); 14 request.outputStream.close();
15 }; 15 };
16 conn.onResponse = (HttpClientResponse response) { 16 conn.onResponse = (HttpClientResponse response) {
17 Expect.isTrue(response.statusCode < 500); 17 Expect.isTrue(response.statusCode < 500);
18 response.inputStream.onData = () { 18 response.inputStream.onData = () {
19 response.inputStream.read(); 19 response.inputStream.read();
20 }; 20 };
21 response.inputStream.onClosed = () { 21 response.inputStream.onClosed = () {
22 client.shutdown(); 22 client.shutdown();
23 }; 23 };
24 }; 24 };
25 conn.onError = (error) => Expect.fail("Unexpected IO error"); 25 conn.onError = (error) => Expect.fail("Unexpected IO error");
26 } 26 }
27 27
28 int testGoogleUrlCount = 0;
28 void testGoogleUrl() { 29 void testGoogleUrl() {
29 HttpClient client = new HttpClient(); 30 HttpClient client = new HttpClient();
30 31
31 void testUrl(String url) { 32 void testUrl(String url) {
32 var conn = client.getUrl(new Uri.fromString(url)); 33 var requestUri = new Uri.fromString(url);
34 var conn = client.getUrl(requestUri);
33 35
34 conn.onRequest = (HttpClientRequest request) { 36 conn.onRequest = (HttpClientRequest request) {
35 request.outputStream.close(); 37 request.outputStream.close();
36 }; 38 };
37 conn.onResponse = (HttpClientResponse response) { 39 conn.onResponse = (HttpClientResponse response) {
40 testGoogleUrlCount++;
38 Expect.isTrue(response.statusCode < 500); 41 Expect.isTrue(response.statusCode < 500);
42 if (requestUri.path.length == 0) {
43 Expect.isTrue(response.statusCode != 404);
44 }
39 response.inputStream.onData = () { 45 response.inputStream.onData = () {
40 response.inputStream.read(); 46 response.inputStream.read();
41 }; 47 };
42 response.inputStream.onClosed = () { 48 response.inputStream.onClosed = () {
43 client.shutdown(); 49 if (testGoogleUrlCount == 5) client.shutdown();
44 }; 50 };
45 }; 51 };
46 conn.onError = (error) => Expect.fail("Unexpected IO error"); 52 conn.onError = (error) => Expect.fail("Unexpected IO error $error");
47 } 53 }
48 54
49 testUrl('http://www.google.com'); 55 testUrl('http://www.google.com');
50 testUrl('http://www.google.com/abc'); 56 testUrl('http://www.google.com/abc');
51 testUrl('http://www.google.com/?abc'); 57 testUrl('http://www.google.com/?abc');
52 testUrl('http://www.google.com/abc?abc'); 58 testUrl('http://www.google.com/abc?abc');
53 testUrl('http://www.google.com/abc?abc#abc'); 59 testUrl('http://www.google.com/abc?abc#abc');
54 } 60 }
55 61
56 void testInvalidUrl() { 62 void testInvalidUrl() {
(...skipping 16 matching lines...) Expand all
73 port.close(); // We expect onError to be called, due to bad host name. 79 port.close(); // We expect onError to be called, due to bad host name.
74 }; 80 };
75 } 81 }
76 82
77 void main() { 83 void main() {
78 testGoogle(); 84 testGoogle();
79 testGoogleUrl(); 85 testGoogleUrl();
80 testInvalidUrl(); 86 testInvalidUrl();
81 testBadHostName(); 87 testBadHostName();
82 } 88 }
OLDNEW
« no previous file with comments | « runtime/bin/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698