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

Side by Side Diff: tests/standalone/src/io/HttpClientTest.dart

Issue 9625008: Add support for using an URL for establishing HTTP connections (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed rewiev comments from @ager Created 8 years, 9 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 | « runtime/bin/http_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 7
7 void testGoogle() { 8 void testGoogle() {
8 HttpClient client = new HttpClient(); 9 HttpClient client = new HttpClient();
9 var conn = client.get('www.google.com', 80, '/'); 10 var conn = client.get('www.google.com', 80, '/');
10 11
11 conn.onRequest = (HttpClientRequest request) { 12 conn.onRequest = (HttpClientRequest request) {
12 request.keepAlive = false; 13 request.keepAlive = false;
13 request.outputStream.close(); 14 request.outputStream.close();
14 }; 15 };
15 conn.onResponse = (HttpClientResponse response) { 16 conn.onResponse = (HttpClientResponse response) {
16 Expect.isTrue(response.statusCode < 500); 17 Expect.isTrue(response.statusCode < 500);
17 response.inputStream.onData = () { 18 response.inputStream.onData = () {
18 response.inputStream.read(); 19 response.inputStream.read();
19 }; 20 };
20 response.inputStream.onClosed = () { 21 response.inputStream.onClosed = () {
21 client.shutdown(); 22 client.shutdown();
22 }; 23 };
23 }; 24 };
25 conn.onError = (error) => Expect.fail("Unexpected IO error");
26 }
27
28 void testGoogleUrl() {
29 HttpClient client = new HttpClient();
30
31 void testUrl(String url) {
32 var conn = client.getUrl(new Uri.fromString(url));
33
34 conn.onRequest = (HttpClientRequest request) {
35 request.keepAlive = false;
36 request.outputStream.close();
37 };
38 conn.onResponse = (HttpClientResponse response) {
39 Expect.isTrue(response.statusCode < 500);
40 response.inputStream.onData = () {
41 response.inputStream.read();
42 };
43 response.inputStream.onClosed = () {
44 client.shutdown();
45 };
46 };
47 conn.onError = (error) => Expect.fail("Unexpected IO error");
48 }
49
50 testUrl('http://www.google.com');
51 testUrl('http://www.google.com/abc');
52 testUrl('http://www.google.com/?abc');
53 testUrl('http://www.google.com/abc?abc');
54 testUrl('http://www.google.com/abc?abc#abc');
55 }
56
57 void testInvalidUrl() {
58 HttpClient client = new HttpClient();
59 Expect.throws(
60 () => client.getUrl(new Uri.fromString('ftp://www.google.com')));
61 Expect.throws(
62 () => client.getUrl(new Uri.fromString('http://usr:pwd@www.google.com')));
24 } 63 }
25 64
26 void main() { 65 void main() {
27 testGoogle(); 66 testGoogle();
67 testGoogleUrl();
68 testInvalidUrl();
28 } 69 }
OLDNEW
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698