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

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

Issue 14081024: Revert "Add new InternetAddress class with a static lookup function (including IPv6 results)" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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";
11 import "dart:async"; 11 import "dart:async";
12 import "dart:io"; 12 import "dart:io";
13 import "dart:isolate"; 13 import "dart:isolate";
14 14
15 const SERVER_ADDRESS = "127.0.0.1";
15 const HOST_NAME = "localhost"; 16 const HOST_NAME = "localhost";
16 const CERTIFICATE = "localhost_cert"; 17 const CERTIFICATE = "localhost_cert";
17 18
18 void testArguments() { 19 void testArguments() {
19 Expect.throws(() => 20 Expect.throws(() =>
20 SecureServerSocket.bind(HOST_NAME, 65536, 5, CERTIFICATE)); 21 SecureServerSocket.bind(SERVER_ADDRESS, 65536, 5, CERTIFICATE));
21 Expect.throws(() => 22 Expect.throws(() =>
22 SecureServerSocket.bind(HOST_NAME, -1, CERTIFICATE)); 23 SecureServerSocket.bind(SERVER_ADDRESS, -1, CERTIFICATE));
23 Expect.throws(() => 24 Expect.throws(() =>
24 SecureServerSocket.bind(HOST_NAME, 0, -1, CERTIFICATE)); 25 SecureServerSocket.bind(SERVER_ADDRESS, 0, -1, CERTIFICATE));
25 } 26 }
26 27
27 void testSimpleBind() { 28 void testSimpleBind() {
28 ReceivePort port = new ReceivePort(); 29 ReceivePort port = new ReceivePort();
29 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((s) { 30 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) {
30 Expect.isTrue(s.port > 0); 31 Expect.isTrue(s.port > 0);
31 s.close(); 32 s.close();
32 port.close(); 33 port.close();
33 }); 34 });
34 } 35 }
35 36
36 void testInvalidBind() { 37 void testInvalidBind() {
37 int count = 0; 38 int count = 0;
38 ReceivePort port = new ReceivePort(); 39 ReceivePort port = new ReceivePort();
39 port.receive((_, __) { count++; if (count == 3) port.close(); }); 40 port.receive((_, __) { count++; if (count == 3) port.close(); });
(...skipping 11 matching lines...) Expand all
51 Expect.fail("Failure expected"); 52 Expect.fail("Failure expected");
52 }).catchError((error) { 53 }).catchError((error) {
53 Expect.isTrue(error is SocketIOException); 54 Expect.isTrue(error is SocketIOException);
54 port.toSendPort().send(1); 55 port.toSendPort().send(1);
55 }); 56 });
56 57
57 // Bind to a port already in use. 58 // Bind to a port already in use.
58 // Either an error or a successful bind is allowed. 59 // Either an error or a successful bind is allowed.
59 // Windows platforms allow multiple binding to the same socket, with 60 // Windows platforms allow multiple binding to the same socket, with
60 // unpredictable results. 61 // unpredictable results.
61 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((s) { 62 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) {
62 SecureServerSocket.bind(HOST_NAME, 63 SecureServerSocket.bind(SERVER_ADDRESS,
63 s.port, 64 s.port,
64 5, 65 5,
65 CERTIFICATE).then((t) { 66 CERTIFICATE).then((t) {
66 Expect.equals('windows', Platform.operatingSystem); 67 Expect.equals('windows', Platform.operatingSystem);
67 Expect.equals(s.port, t.port); 68 Expect.equals(s.port, t.port);
68 s.close(); 69 s.close();
69 t.close(); 70 t.close();
70 port.toSendPort().send(1); 71 port.toSendPort().send(1);
71 }).catchError((error) { 72 }).catchError((error) {
72 Expect.notEquals('windows', Platform.operatingSystem); 73 Expect.notEquals('windows', Platform.operatingSystem);
73 Expect.isTrue(error is SocketIOException); 74 Expect.isTrue(error is SocketIOException);
74 s.close(); 75 s.close();
75 port.toSendPort().send(1); 76 port.toSendPort().send(1);
76 }); 77 });
77 }); 78 });
78 } 79 }
79 80
80 void testSimpleConnect(String certificate) { 81 void testSimpleConnect(String certificate) {
81 ReceivePort port = new ReceivePort(); 82 ReceivePort port = new ReceivePort();
82 SecureServerSocket.bind(HOST_NAME, 0, 5, certificate).then((server) { 83 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) {
83 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); 84 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port);
84 server.listen((serverEnd) { 85 server.listen((serverEnd) {
85 clientEndFuture.then((clientEnd) { 86 clientEndFuture.then((clientEnd) {
86 clientEnd.close(); 87 clientEnd.close();
87 serverEnd.close(); 88 serverEnd.close();
88 server.close(); 89 server.close();
89 port.close(); 90 port.close();
90 }); 91 });
91 }); 92 });
92 }); 93 });
93 } 94 }
94 95
95 void testSimpleConnectFail(String certificate) { 96 void testSimpleConnectFail(String certificate) {
96 ReceivePort port = new ReceivePort(); 97 ReceivePort port = new ReceivePort();
97 SecureServerSocket.bind(HOST_NAME, 0, 5, certificate).then((server) { 98 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) {
98 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port) 99 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port)
99 .then((clientEnd) { 100 .then((clientEnd) {
100 Expect.fail("No client connection expected."); 101 Expect.fail("No client connection expected.");
101 }) 102 })
102 .catchError((error) { 103 .catchError((error) {
103 Expect.isTrue(error is SocketIOException); 104 Expect.isTrue(error is SocketIOException);
104 }); 105 });
105 server.listen((serverEnd) { 106 server.listen((serverEnd) {
106 Expect.fail("No server connection expected."); 107 Expect.fail("No server connection expected.");
107 }, 108 },
108 onError: (error) { 109 onError: (error) {
109 Expect.isTrue(error is SocketIOException); 110 Expect.isTrue(error is SocketIOException);
110 clientEndFuture.then((_) => port.close()); 111 clientEndFuture.then((_) => port.close());
111 }); 112 });
112 }); 113 });
113 } 114 }
114 115
115 void testServerListenAfterConnect() { 116 void testServerListenAfterConnect() {
116 ReceivePort port = new ReceivePort(); 117 ReceivePort port = new ReceivePort();
117 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 118 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) {
118 Expect.isTrue(server.port > 0); 119 Expect.isTrue(server.port > 0);
119 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); 120 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port);
120 new Timer(const Duration(milliseconds: 500), () { 121 new Timer(const Duration(milliseconds: 500), () {
121 server.listen((serverEnd) { 122 server.listen((serverEnd) {
122 clientEndFuture.then((clientEnd) { 123 clientEndFuture.then((clientEnd) {
123 clientEnd.close(); 124 clientEnd.close();
124 serverEnd.close(); 125 serverEnd.close();
125 server.close(); 126 server.close();
126 port.close(); 127 port.close();
127 }); 128 });
(...skipping 20 matching lines...) Expand all
148 } 149 }
149 150
150 void verifyTestData(List<int> data) { 151 void verifyTestData(List<int> data) {
151 Expect.equals(messageSize, data.length); 152 Expect.equals(messageSize, data.length);
152 List<int> expected = createTestData(); 153 List<int> expected = createTestData();
153 for (int i = 0; i < messageSize; i++) { 154 for (int i = 0; i < messageSize; i++) {
154 Expect.equals(expected[i], data[i]); 155 Expect.equals(expected[i], data[i]);
155 } 156 }
156 } 157 }
157 158
158 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 159 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) {
159 server.listen((client) { 160 server.listen((client) {
160 int bytesRead = 0; 161 int bytesRead = 0;
161 int bytesWritten = 0; 162 int bytesWritten = 0;
162 List<int> data = new List<int>(messageSize); 163 List<int> data = new List<int>(messageSize);
163 164
164 client.listen( 165 client.listen(
165 (buffer) { 166 (buffer) {
166 Expect.isTrue(bytesWritten == 0); 167 Expect.isTrue(bytesWritten == 0);
167 data.setRange(bytesRead, bytesRead + buffer.length, buffer); 168 data.setRange(bytesRead, bytesRead + buffer.length, buffer);
168 bytesRead += buffer.length; 169 bytesRead += buffer.length;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 testArguments(); 208 testArguments();
208 testSimpleBind(); 209 testSimpleBind();
209 testInvalidBind(); 210 testInvalidBind();
210 testSimpleConnect(CERTIFICATE); 211 testSimpleConnect(CERTIFICATE);
211 testSimpleConnect("CN=localhost"); 212 testSimpleConnect("CN=localhost");
212 testSimpleConnectFail("not_a_nickname"); 213 testSimpleConnectFail("not_a_nickname");
213 testSimpleConnectFail("CN=notARealDistinguishedName"); 214 testSimpleConnectFail("CN=notARealDistinguishedName");
214 testServerListenAfterConnect(); 215 testServerListenAfterConnect();
215 testSimpleReadWrite(); 216 testSimpleReadWrite();
216 } 217 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_server_closing_test.dart ('k') | tests/standalone/io/secure_session_resume_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698