| 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 | 8 |
| 8 void testGoogle() { | 9 void testGoogle() { |
| 9 HttpClient client = new HttpClient(); | 10 HttpClient client = new HttpClient(); |
| 10 var conn = client.get('www.google.com', 80, '/'); | 11 var conn = client.get('www.google.com', 80, '/'); |
| 11 | 12 |
| 12 conn.onRequest = (HttpClientRequest request) { | 13 conn.onRequest = (HttpClientRequest request) { |
| 13 request.keepAlive = false; | 14 request.keepAlive = false; |
| 14 request.outputStream.close(); | 15 request.outputStream.close(); |
| 15 }; | 16 }; |
| 16 conn.onResponse = (HttpClientResponse response) { | 17 conn.onResponse = (HttpClientResponse response) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 56 } |
| 56 | 57 |
| 57 void testInvalidUrl() { | 58 void testInvalidUrl() { |
| 58 HttpClient client = new HttpClient(); | 59 HttpClient client = new HttpClient(); |
| 59 Expect.throws( | 60 Expect.throws( |
| 60 () => client.getUrl(new Uri.fromString('ftp://www.google.com'))); | 61 () => client.getUrl(new Uri.fromString('ftp://www.google.com'))); |
| 61 Expect.throws( | 62 Expect.throws( |
| 62 () => client.getUrl(new Uri.fromString('http://usr:pwd@www.google.com'))); | 63 () => client.getUrl(new Uri.fromString('http://usr:pwd@www.google.com'))); |
| 63 } | 64 } |
| 64 | 65 |
| 66 void testBadHostName() { |
| 67 HttpClient client = new HttpClient(); |
| 68 HttpClientConnection connection = |
| 69 client.get("some.bad.host.name.7654321", 0, "/"); |
| 70 connection.onRequest = (HttpClientRequest request) { |
| 71 Expect.fail("Should not open a request on bad hostname"); |
| 72 }; |
| 73 ReceivePort port = new ReceivePort(); |
| 74 connection.onError = (Exception error) { |
| 75 port.close(); // We expect onError to be called, due to bad host name. |
| 76 }; |
| 77 } |
| 78 |
| 65 void main() { | 79 void main() { |
| 66 // TODO(sgjesse): Making empty www.google.com requests seems to fail | 80 // TODO(sgjesse): Making empty www.google.com requests seems to fail |
| 67 //on buildbot. | 81 //on buildbot. |
| 68 //testGoogle(); | 82 //testGoogle(); |
| 69 //testGoogleUrl(); | 83 //testGoogleUrl(); |
| 70 testInvalidUrl(); | 84 testInvalidUrl(); |
| 85 testBadHostName(); |
| 71 } | 86 } |
| OLD | NEW |