| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 5 |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| 11 void testInvalidUrl() { | 11 void testInvalidUrl() { |
| 12 HttpClient client = new HttpClient(); | 12 HttpClient client = new HttpClient(); |
| 13 Expect.throws( | 13 Expect.throws( |
| 14 () => client.getUrl(Uri.parse('ftp://www.google.com')), | 14 () => client.getUrl(Uri.parse('ftp://www.google.com')), |
| 15 (e) => e.toString().contains("Unsupported scheme")); | 15 (e) => e.toString().contains("Unsupported scheme")); |
| 16 Expect.throws( | 16 Expect.throws( |
| 17 () => client.getUrl(Uri.parse('httpx://www.google.com')), | 17 () => client.getUrl(Uri.parse('httpx://www.google.com')), |
| 18 (e) => e.toString().contains("Unsupported scheme")); | 18 (e) => e.toString().contains("Unsupported scheme")); |
| 19 Expect.throws( | 19 Expect.throws( |
| 20 () => client.getUrl(Uri.parse('http://::1')), | 20 () => client.getUrl(Uri.parse('http://::1')), |
| 21 (e) => e.toString().contains("No host specified")); | 21 (e) => e is FormatException); |
| 22 Expect.throws( | 22 Expect.throws( |
| 23 () => client.getUrl(Uri.parse('http://user@:1')), | 23 () => client.getUrl(Uri.parse('http://user@:1')), |
| 24 (e) => e.toString().contains("No host specified")); | 24 (e) => e.toString().contains("No host specified")); |
| 25 Expect.throws( | 25 Expect.throws( |
| 26 () => client.getUrl(Uri.parse('http:///')), | 26 () => client.getUrl(Uri.parse('http:///')), |
| 27 (e) => e.toString().contains("No host specified")); | 27 (e) => e.toString().contains("No host specified")); |
| 28 Expect.throws( | 28 Expect.throws( |
| 29 () => client.getUrl(Uri.parse('http:///index.html')), | 29 () => client.getUrl(Uri.parse('http:///index.html')), |
| 30 (e) => e.toString().contains("No host specified")); | 30 (e) => e.toString().contains("No host specified")); |
| 31 Expect.throws( | 31 Expect.throws( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 Expect.fail("Should not open a request on bad hostname"); | 44 Expect.fail("Should not open a request on bad hostname"); |
| 45 }).catchError((error) { | 45 }).catchError((error) { |
| 46 asyncEnd(); // We expect onError to be called, due to bad host name. | 46 asyncEnd(); // We expect onError to be called, due to bad host name. |
| 47 }, test: (error) => error is! String); | 47 }, test: (error) => error is! String); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void main() { | 50 void main() { |
| 51 testInvalidUrl(); | 51 testInvalidUrl(); |
| 52 testBadHostName(); | 52 testBadHostName(); |
| 53 } | 53 } |
| OLD | NEW |