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:async"; | 6 import "dart:async"; |
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 import "package:path/path.dart"; | 10 import "package:path/path.dart"; |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 void testGoogleUrl(bool expectSuccess) { | 36 void testGoogleUrl(bool expectSuccess) { |
37 // We need to use an external server that is backed by a | 37 // We need to use an external server that is backed by a |
38 // built-in root certificate authority. | 38 // built-in root certificate authority. |
39 | 39 |
40 // First, check if the lookup fails. If not then run the test. | 40 // First, check if the lookup fails. If not then run the test. |
41 InternetAddress.lookup('www.google.com').then((_) { | 41 InternetAddress.lookup('www.google.com').then((_) { |
42 HttpClient client = new HttpClient(); | 42 HttpClient client = new HttpClient(); |
43 client.getUrl(Uri.parse('https://www.google.com')) | 43 client.getUrl(Uri.parse('https://www.google.com')) |
44 .then((request) => request.close()) | 44 .then((request) { |
| 45 request.followRedirects = false; |
| 46 return request.close(); |
| 47 }) |
45 .then((response) { | 48 .then((response) { |
46 Expect.isTrue(expectSuccess, "Unexpected successful connection"); | 49 Expect.isTrue(expectSuccess, "Unexpected successful connection"); |
47 print('SUCCESS'); | 50 print('SUCCESS'); |
48 return response.last; | 51 return response.drain().catchError((_) {}); |
49 }) | 52 }) |
50 .catchError((error) { | 53 .catchError((error) { |
51 // Allow SocketExceptions if www.google.com is unreachable or down. | 54 // Allow SocketExceptions if www.google.com is unreachable or down. |
52 Expect.isTrue((!expectSuccess && error is HandshakeException) || | 55 Expect.isTrue((!expectSuccess && error is HandshakeException) || |
53 error is SocketException); | 56 error is SocketException); |
54 print('SUCCESS'); | 57 print('SUCCESS'); |
55 }) | 58 }) |
56 .whenComplete(client.close); | 59 .whenComplete(client.close); |
57 }, | 60 }, |
58 onError: (e) { | 61 onError: (e) { |
(...skipping 21 matching lines...) Expand all Loading... |
80 }); | 83 }); |
81 } | 84 } |
82 | 85 |
83 asyncStart(); | 86 asyncStart(); |
84 Future.wait([runChild(['--child']), | 87 Future.wait([runChild(['--child']), |
85 runChild(['--child', '--database']), | 88 runChild(['--child', '--database']), |
86 runChild(['--child', '--builtin-roots']), | 89 runChild(['--child', '--builtin-roots']), |
87 runChild(['--child', '--builtin-roots', '--database'])]) | 90 runChild(['--child', '--builtin-roots', '--database'])]) |
88 .then((_) => asyncEnd()); | 91 .then((_) => asyncEnd()); |
89 } | 92 } |
OLD | NEW |