| OLD | NEW |
| 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(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 }; | 23 }; |
| 24 }; | 24 }; |
| 25 conn.onError = (error) => Expect.fail("Unexpected IO error $error"); | 25 conn.onError = (error) => Expect.fail("Unexpected IO error $error"); |
| 26 } | 26 } |
| 27 | 27 |
| 28 int testGoogleUrlCount = 0; | 28 int testGoogleUrlCount = 0; |
| 29 void testGoogleUrl() { | 29 void testGoogleUrl() { |
| 30 HttpClient client = new HttpClient(); | 30 HttpClient client = new HttpClient(); |
| 31 | 31 |
| 32 void testUrl(String url) { | 32 void testUrl(String url) { |
| 33 var requestUri = new Uri.fromString(url); | 33 var requestUri = Uri.parse(url); |
| 34 var conn = client.getUrl(requestUri); | 34 var conn = client.getUrl(requestUri); |
| 35 | 35 |
| 36 conn.onRequest = (HttpClientRequest request) { | 36 conn.onRequest = (HttpClientRequest request) { |
| 37 request.outputStream.close(); | 37 request.outputStream.close(); |
| 38 }; | 38 }; |
| 39 conn.onResponse = (HttpClientResponse response) { | 39 conn.onResponse = (HttpClientResponse response) { |
| 40 testGoogleUrlCount++; | 40 testGoogleUrlCount++; |
| 41 Expect.isTrue(response.statusCode < 500); | 41 Expect.isTrue(response.statusCode < 500); |
| 42 if (requestUri.path.length == 0) { | 42 if (requestUri.path.length == 0) { |
| 43 Expect.isTrue(response.statusCode != 404); | 43 Expect.isTrue(response.statusCode != 404); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 55 testUrl('http://www.google.com'); | 55 testUrl('http://www.google.com'); |
| 56 testUrl('http://www.google.com/abc'); | 56 testUrl('http://www.google.com/abc'); |
| 57 testUrl('http://www.google.com/?abc'); | 57 testUrl('http://www.google.com/?abc'); |
| 58 testUrl('http://www.google.com/abc?abc'); | 58 testUrl('http://www.google.com/abc?abc'); |
| 59 testUrl('http://www.google.com/abc?abc#abc'); | 59 testUrl('http://www.google.com/abc?abc#abc'); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void testInvalidUrl() { | 62 void testInvalidUrl() { |
| 63 HttpClient client = new HttpClient(); | 63 HttpClient client = new HttpClient(); |
| 64 Expect.throws( | 64 Expect.throws( |
| 65 () => client.getUrl(new Uri.fromString('ftp://www.google.com'))); | 65 () => client.getUrl(Uri.parse('ftp://www.google.com'))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void testBadHostName() { | 68 void testBadHostName() { |
| 69 HttpClient client = new HttpClient(); | 69 HttpClient client = new HttpClient(); |
| 70 HttpClientConnection connection = | 70 HttpClientConnection connection = |
| 71 client.get("some.bad.host.name.7654321", 0, "/"); | 71 client.get("some.bad.host.name.7654321", 0, "/"); |
| 72 connection.onRequest = (HttpClientRequest request) { | 72 connection.onRequest = (HttpClientRequest request) { |
| 73 Expect.fail("Should not open a request on bad hostname"); | 73 Expect.fail("Should not open a request on bad hostname"); |
| 74 }; | 74 }; |
| 75 ReceivePort port = new ReceivePort(); | 75 ReceivePort port = new ReceivePort(); |
| 76 connection.onError = (Exception error) { | 76 connection.onError = (Exception error) { |
| 77 port.close(); // We expect onError to be called, due to bad host name. | 77 port.close(); // We expect onError to be called, due to bad host name. |
| 78 }; | 78 }; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void main() { | 81 void main() { |
| 82 testGoogle(); | 82 testGoogle(); |
| 83 testGoogleUrl(); | 83 testGoogleUrl(); |
| 84 testInvalidUrl(); | 84 testInvalidUrl(); |
| 85 testBadHostName(); | 85 testBadHostName(); |
| 86 } | 86 } |
| OLD | NEW |