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

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

Issue 14036017: 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 testSimpleBind() { 19 void testSimpleBind() {
19 ReceivePort port = new ReceivePort(); 20 ReceivePort port = new ReceivePort();
20 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((s) { 21 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) {
21 Expect.isTrue(s.port > 0); 22 Expect.isTrue(s.port > 0);
22 s.close(); 23 s.close();
23 port.close(); 24 port.close();
24 }); 25 });
25 } 26 }
26 27
27 void testInvalidBind() { 28 void testInvalidBind() {
28 int count = 0; 29 int count = 0;
29 ReceivePort port = new ReceivePort(); 30 ReceivePort port = new ReceivePort();
30 port.receive((_, __) { count++; if (count == 3) port.close(); }); 31 port.receive((_, __) { count++; if (count == 3) port.close(); });
(...skipping 11 matching lines...) Expand all
42 Expect.fail("Failure expected"); 43 Expect.fail("Failure expected");
43 }).catchError((error) { 44 }).catchError((error) {
44 Expect.isTrue(error is SocketIOException); 45 Expect.isTrue(error is SocketIOException);
45 port.toSendPort().send(1); 46 port.toSendPort().send(1);
46 }); 47 });
47 48
48 // Bind to a port already in use. 49 // Bind to a port already in use.
49 // Either an error or a successful bind is allowed. 50 // Either an error or a successful bind is allowed.
50 // Windows platforms allow multiple binding to the same socket, with 51 // Windows platforms allow multiple binding to the same socket, with
51 // unpredictable results. 52 // unpredictable results.
52 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((s) { 53 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) {
53 SecureServerSocket.bind(HOST_NAME, 54 SecureServerSocket.bind(SERVER_ADDRESS,
54 s.port, 55 s.port,
55 5, 56 5,
56 CERTIFICATE).then((t) { 57 CERTIFICATE).then((t) {
57 Expect.equals('windows', Platform.operatingSystem); 58 Expect.equals('windows', Platform.operatingSystem);
58 Expect.equals(s.port, t.port); 59 Expect.equals(s.port, t.port);
59 s.close(); 60 s.close();
60 t.close(); 61 t.close();
61 port.toSendPort().send(1); 62 port.toSendPort().send(1);
62 }).catchError((error) { 63 }).catchError((error) {
63 Expect.notEquals('windows', Platform.operatingSystem); 64 Expect.notEquals('windows', Platform.operatingSystem);
64 Expect.isTrue(error is SocketIOException); 65 Expect.isTrue(error is SocketIOException);
65 s.close(); 66 s.close();
66 port.toSendPort().send(1); 67 port.toSendPort().send(1);
67 }); 68 });
68 }); 69 });
69 } 70 }
70 71
71 void testSimpleConnect(String certificate) { 72 void testSimpleConnect(String certificate) {
72 ReceivePort port = new ReceivePort(); 73 ReceivePort port = new ReceivePort();
73 SecureServerSocket.bind(HOST_NAME, 0, 5, certificate).then((server) { 74 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) {
74 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); 75 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port);
75 server.listen((serverEnd) { 76 server.listen((serverEnd) {
76 clientEndFuture.then((clientEnd) { 77 clientEndFuture.then((clientEnd) {
77 clientEnd.close(); 78 clientEnd.close();
78 serverEnd.close(); 79 serverEnd.close();
79 server.close(); 80 server.close();
80 port.close(); 81 port.close();
81 }); 82 });
82 }); 83 });
83 }); 84 });
84 } 85 }
85 86
86 void testSimpleConnectFail(String certificate) { 87 void testSimpleConnectFail(String certificate) {
87 ReceivePort port = new ReceivePort(); 88 ReceivePort port = new ReceivePort();
88 SecureServerSocket.bind(HOST_NAME, 0, 5, certificate).then((server) { 89 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) {
89 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port) 90 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port)
90 .then((clientEnd) { 91 .then((clientEnd) {
91 Expect.fail("No client connection expected."); 92 Expect.fail("No client connection expected.");
92 }) 93 })
93 .catchError((error) { 94 .catchError((error) {
94 Expect.isTrue(error is SocketIOException); 95 Expect.isTrue(error is SocketIOException);
95 }); 96 });
96 server.listen((serverEnd) { 97 server.listen((serverEnd) {
97 Expect.fail("No server connection expected."); 98 Expect.fail("No server connection expected.");
98 }, 99 },
99 onError: (error) { 100 onError: (error) {
100 Expect.isTrue(error is SocketIOException); 101 Expect.isTrue(error is SocketIOException);
101 clientEndFuture.then((_) => port.close()); 102 clientEndFuture.then((_) => port.close());
102 }); 103 });
103 }); 104 });
104 } 105 }
105 106
106 void testServerListenAfterConnect() { 107 void testServerListenAfterConnect() {
107 ReceivePort port = new ReceivePort(); 108 ReceivePort port = new ReceivePort();
108 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 109 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) {
109 Expect.isTrue(server.port > 0); 110 Expect.isTrue(server.port > 0);
110 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); 111 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port);
111 new Timer(const Duration(milliseconds: 500), () { 112 new Timer(const Duration(milliseconds: 500), () {
112 server.listen((serverEnd) { 113 server.listen((serverEnd) {
113 clientEndFuture.then((clientEnd) { 114 clientEndFuture.then((clientEnd) {
114 clientEnd.close(); 115 clientEnd.close();
115 serverEnd.close(); 116 serverEnd.close();
116 server.close(); 117 server.close();
117 port.close(); 118 port.close();
118 }); 119 });
(...skipping 20 matching lines...) Expand all
139 } 140 }
140 141
141 void verifyTestData(List<int> data) { 142 void verifyTestData(List<int> data) {
142 Expect.equals(messageSize, data.length); 143 Expect.equals(messageSize, data.length);
143 List<int> expected = createTestData(); 144 List<int> expected = createTestData();
144 for (int i = 0; i < messageSize; i++) { 145 for (int i = 0; i < messageSize; i++) {
145 Expect.equals(expected[i], data[i]); 146 Expect.equals(expected[i], data[i]);
146 } 147 }
147 } 148 }
148 149
149 SecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 150 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) {
150 server.listen((client) { 151 server.listen((client) {
151 int bytesRead = 0; 152 int bytesRead = 0;
152 int bytesWritten = 0; 153 int bytesWritten = 0;
153 List<int> data = new List<int>(messageSize); 154 List<int> data = new List<int>(messageSize);
154 155
155 client.listen( 156 client.listen(
156 (buffer) { 157 (buffer) {
157 Expect.isTrue(bytesWritten == 0); 158 Expect.isTrue(bytesWritten == 0);
158 data.setRange(bytesRead, bytesRead + buffer.length, buffer); 159 data.setRange(bytesRead, bytesRead + buffer.length, buffer);
159 bytesRead += buffer.length; 160 bytesRead += buffer.length;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 useBuiltinRoots: false); 198 useBuiltinRoots: false);
198 testSimpleBind(); 199 testSimpleBind();
199 testInvalidBind(); 200 testInvalidBind();
200 testSimpleConnect(CERTIFICATE); 201 testSimpleConnect(CERTIFICATE);
201 testSimpleConnect("CN=localhost"); 202 testSimpleConnect("CN=localhost");
202 testSimpleConnectFail("not_a_nickname"); 203 testSimpleConnectFail("not_a_nickname");
203 testSimpleConnectFail("CN=notARealDistinguishedName"); 204 testSimpleConnectFail("CN=notARealDistinguishedName");
204 testServerListenAfterConnect(); 205 testServerListenAfterConnect();
205 testSimpleReadWrite(); 206 testSimpleReadWrite();
206 } 207 }
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