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

Side by Side Diff: tests/standalone/io/secure_server_socket_test.dart

Issue 16123036: Clean up dart:io exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
OLDNEW
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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 15 matching lines...) Expand all
26 26
27 void testInvalidBind() { 27 void testInvalidBind() {
28 int count = 0; 28 int count = 0;
29 ReceivePort port = new ReceivePort(); 29 ReceivePort port = new ReceivePort();
30 port.receive((_, __) { count++; if (count == 3) port.close(); }); 30 port.receive((_, __) { count++; if (count == 3) port.close(); });
31 31
32 // Bind to a unknown DNS name. 32 // Bind to a unknown DNS name.
33 SecureServerSocket.bind("ko.faar.__hest__", 0, CERTIFICATE).then((_) { 33 SecureServerSocket.bind("ko.faar.__hest__", 0, CERTIFICATE).then((_) {
34 Expect.fail("Failure expected"); 34 Expect.fail("Failure expected");
35 }).catchError((error) { 35 }).catchError((error) {
36 Expect.isTrue(error is SocketIOException); 36 Expect.isTrue(error is SocketException);
37 port.toSendPort().send(1); 37 port.toSendPort().send(1);
38 }); 38 });
39 39
40 // Bind to an unavaliable IP-address. 40 // Bind to an unavaliable IP-address.
41 SecureServerSocket.bind("8.8.8.8", 0, CERTIFICATE).then((_) { 41 SecureServerSocket.bind("8.8.8.8", 0, CERTIFICATE).then((_) {
42 Expect.fail("Failure expected"); 42 Expect.fail("Failure expected");
43 }).catchError((error) { 43 }).catchError((error) {
44 Expect.isTrue(error is SocketIOException); 44 Expect.isTrue(error is SocketException);
45 port.toSendPort().send(1); 45 port.toSendPort().send(1);
46 }); 46 });
47 47
48 // Bind to a port already in use. 48 // Bind to a port already in use.
49 // Either an error or a successful bind is allowed. 49 // Either an error or a successful bind is allowed.
50 // Windows platforms allow multiple binding to the same socket, with 50 // Windows platforms allow multiple binding to the same socket, with
51 // unpredictable results. 51 // unpredictable results.
52 SecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((s) { 52 SecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((s) {
53 SecureServerSocket.bind(HOST_NAME, 53 SecureServerSocket.bind(HOST_NAME,
54 s.port, 54 s.port,
55 CERTIFICATE).then((t) { 55 CERTIFICATE).then((t) {
56 Expect.equals('windows', Platform.operatingSystem); 56 Expect.equals('windows', Platform.operatingSystem);
57 Expect.equals(s.port, t.port); 57 Expect.equals(s.port, t.port);
58 s.close(); 58 s.close();
59 t.close(); 59 t.close();
60 port.toSendPort().send(1); 60 port.toSendPort().send(1);
61 }).catchError((error) { 61 }).catchError((error) {
62 Expect.notEquals('windows', Platform.operatingSystem); 62 Expect.notEquals('windows', Platform.operatingSystem);
63 Expect.isTrue(error is SocketIOException); 63 Expect.isTrue(error is SocketException);
64 s.close(); 64 s.close();
65 port.toSendPort().send(1); 65 port.toSendPort().send(1);
66 }); 66 });
67 }); 67 });
68 } 68 }
69 69
70 void testSimpleConnect(String certificate) { 70 void testSimpleConnect(String certificate) {
71 ReceivePort port = new ReceivePort(); 71 ReceivePort port = new ReceivePort();
72 SecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) { 72 SecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) {
73 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); 73 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port);
74 server.listen((serverEnd) { 74 server.listen((serverEnd) {
75 clientEndFuture.then((clientEnd) { 75 clientEndFuture.then((clientEnd) {
76 clientEnd.close(); 76 clientEnd.close();
77 serverEnd.close(); 77 serverEnd.close();
78 server.close(); 78 server.close();
79 port.close(); 79 port.close();
80 }); 80 });
81 }); 81 });
82 }); 82 });
83 } 83 }
84 84
85 void testSimpleConnectFail(String certificate, bool cancelOnError) { 85 void testSimpleConnectFail(String certificate, bool cancelOnError) {
86 ReceivePort port = new ReceivePort(); 86 ReceivePort port = new ReceivePort();
87 SecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) { 87 SecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) {
88 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port) 88 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port)
89 .then((clientEnd) { 89 .then((clientEnd) {
90 Expect.fail("No client connection expected."); 90 Expect.fail("No client connection expected.");
91 }) 91 })
92 .catchError((error) { 92 .catchError((error) {
93 Expect.isTrue(error is SocketIOException); 93 Expect.isTrue(error is SocketException);
94 }); 94 });
95 server.listen((serverEnd) { 95 server.listen((serverEnd) {
96 Expect.fail("No server connection expected."); 96 Expect.fail("No server connection expected.");
97 }, 97 },
98 onError: (error) { 98 onError: (error) {
99 Expect.isTrue(error is SocketIOException); 99 Expect.isTrue(error is SocketException);
100 clientEndFuture.then((_) { 100 clientEndFuture.then((_) {
101 if (!cancelOnError) server.close(); 101 if (!cancelOnError) server.close();
102 port.close(); 102 port.close();
103 }); 103 });
104 }, 104 },
105 cancelOnError: cancelOnError); 105 cancelOnError: cancelOnError);
106 }); 106 });
107 } 107 }
108 108
109 void testServerListenAfterConnect() { 109 void testServerListenAfterConnect() {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 testInvalidBind(); 202 testInvalidBind();
203 testSimpleConnect(CERTIFICATE); 203 testSimpleConnect(CERTIFICATE);
204 testSimpleConnect("CN=localhost"); 204 testSimpleConnect("CN=localhost");
205 testSimpleConnectFail("not_a_nickname", false); 205 testSimpleConnectFail("not_a_nickname", false);
206 testSimpleConnectFail("CN=notARealDistinguishedName", false); 206 testSimpleConnectFail("CN=notARealDistinguishedName", false);
207 testSimpleConnectFail("not_a_nickname", true); 207 testSimpleConnectFail("not_a_nickname", true);
208 testSimpleConnectFail("CN=notARealDistinguishedName", true); 208 testSimpleConnectFail("CN=notARealDistinguishedName", true);
209 testServerListenAfterConnect(); 209 testServerListenAfterConnect();
210 testSimpleReadWrite(); 210 testSimpleReadWrite();
211 } 211 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_no_builtin_roots_test.dart ('k') | tests/standalone/io/socket_exception_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698