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 // 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 "dart:async"; | 10 import "dart:async"; |
(...skipping 24 matching lines...) Expand all Loading... |
35 0, | 35 0, |
36 backlog: backlog, | 36 backlog: backlog, |
37 certificateName: CERT_NAME) | 37 certificateName: CERT_NAME) |
38 : HttpServer.bind(HOST_NAME, | 38 : HttpServer.bind(HOST_NAME, |
39 0, | 39 0, |
40 backlog: backlog); | 40 backlog: backlog); |
41 | 41 |
42 Future<WebSocket> createClient(int port) => | 42 Future<WebSocket> createClient(int port) => |
43 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/'); | 43 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/'); |
44 | 44 |
| 45 checkCloseStatus(webSocket, closeStatus, closeReason) { |
| 46 Expect.equals(closeStatus == null ? WebSocketStatus.NO_STATUS_RECEIVED |
| 47 : closeStatus, webSocket.closeCode); |
| 48 Expect.equals(closeReason == null ? "" |
| 49 : closeReason, webSocket.closeReason); |
| 50 } |
| 51 |
45 void testRequestResponseClientCloses(int totalConnections, | 52 void testRequestResponseClientCloses(int totalConnections, |
46 int closeStatus, | 53 int closeStatus, |
47 String closeReason, | 54 String closeReason, |
48 int numberOfMessages) { | 55 int numberOfMessages) { |
49 assert (numberOfMessages >= 1); | 56 assert (numberOfMessages >= 1); |
50 | 57 |
51 asyncStart(); | 58 asyncStart(); |
52 createServer().then((server) { | 59 createServer().then((server) { |
53 server.transform(new WebSocketTransformer()).listen((webSocket) { | 60 server.transform(new WebSocketTransformer()).listen((webSocket) { |
54 asyncStart(); | 61 asyncStart(); |
55 webSocket.listen( | 62 webSocket.listen( |
56 webSocket.add, | 63 webSocket.add, |
57 onDone: () { | 64 onDone: () { |
58 Expect.equals(closeStatus == null | 65 checkCloseStatus(webSocket, closeStatus, closeReason); |
59 ? WebSocketStatus.NO_STATUS_RECEIVED | |
60 : closeStatus, webSocket.closeCode); | |
61 Expect.equals( | |
62 closeReason == null ? "" | |
63 : closeReason, webSocket.closeReason); | |
64 asyncEnd(); | 66 asyncEnd(); |
65 }); | 67 }); |
66 }, onDone: () { | 68 }, onDone: () { |
67 asyncEnd(); | 69 asyncEnd(); |
68 }); | 70 }); |
69 | 71 |
70 int closeCount = 0; | 72 int closeCount = 0; |
71 String messageText = "Hello, world!"; | 73 String messageText = "Hello, world!"; |
72 for (int i = 0; i < totalConnections; i++) { | 74 for (int i = 0; i < totalConnections; i++) { |
73 asyncStart(); | 75 asyncStart(); |
74 createClient(server.port).then((webSocket) { | 76 createClient(server.port).then((webSocket) { |
75 webSocket.add(messageText); | 77 webSocket.add(messageText); |
76 webSocket.listen( | 78 webSocket.listen( |
77 (message) { | 79 (message) { |
78 numberOfMessages--; | 80 numberOfMessages--; |
79 Expect.equals(messageText, message); | 81 Expect.equals(messageText, message); |
80 | 82 |
81 if (numberOfMessages > 0) { | 83 if (numberOfMessages > 0) { |
82 webSocket.add(message); | 84 webSocket.add(message); |
83 } else { | 85 } else { |
84 webSocket.close(closeStatus, closeReason); | 86 webSocket.close(closeStatus, closeReason); |
85 } | 87 } |
86 }, | 88 }, |
87 onDone: () { | 89 onDone: () { |
88 Expect.equals(closeStatus == null | 90 checkCloseStatus(webSocket, closeStatus, closeReason); |
89 ? WebSocketStatus.NO_STATUS_RECEIVED | |
90 : closeStatus, webSocket.closeCode); | |
91 Expect.equals("", webSocket.closeReason); | |
92 closeCount++; | 91 closeCount++; |
93 if (closeCount == totalConnections) { | 92 if (closeCount == totalConnections) { |
94 server.close(); | 93 server.close(); |
95 } | 94 } |
96 asyncEnd(); | 95 asyncEnd(); |
97 }); | 96 }); |
98 }); | 97 }); |
99 } | 98 } |
100 }); | 99 }); |
101 } | 100 } |
(...skipping 10 matching lines...) Expand all Loading... |
112 (message) { | 111 (message) { |
113 messageCount++; | 112 messageCount++; |
114 if (messageCount < 10) { | 113 if (messageCount < 10) { |
115 Expect.equals(messageText, message); | 114 Expect.equals(messageText, message); |
116 webSocket.add(message); | 115 webSocket.add(message); |
117 } else { | 116 } else { |
118 webSocket.close(closeStatus, closeReason); | 117 webSocket.close(closeStatus, closeReason); |
119 } | 118 } |
120 }, | 119 }, |
121 onDone: () { | 120 onDone: () { |
122 Expect.equals(closeStatus == null | 121 checkCloseStatus(webSocket, closeStatus, closeReason); |
123 ? WebSocketStatus.NO_STATUS_RECEIVED | |
124 : closeStatus, webSocket.closeCode); | |
125 Expect.equals("", webSocket.closeReason); | |
126 closeCount++; | 122 closeCount++; |
127 if (closeCount == totalConnections) { | 123 if (closeCount == totalConnections) { |
128 server.close(); | 124 server.close(); |
129 } | 125 } |
130 }); | 126 }); |
131 webSocket.add(messageText); | 127 webSocket.add(messageText); |
132 }); | 128 }); |
133 | 129 |
134 for (int i = 0; i < totalConnections; i++) { | 130 for (int i = 0; i < totalConnections; i++) { |
135 createClient(server.port).then((webSocket) { | 131 createClient(server.port).then((webSocket) { |
136 webSocket.listen( | 132 webSocket.listen( |
137 webSocket.add, | 133 webSocket.add, |
138 onDone: () { | 134 onDone: () { |
139 Expect.equals(closeStatus == null | 135 checkCloseStatus(webSocket, closeStatus, closeReason); |
140 ? WebSocketStatus.NO_STATUS_RECEIVED | |
141 : closeStatus, webSocket.closeCode); | |
142 Expect.equals(closeReason == null | |
143 ? "" | |
144 : closeReason, webSocket.closeReason); | |
145 }); | 136 }); |
146 }); | 137 }); |
147 } | 138 } |
148 }); | 139 }); |
149 } | 140 } |
150 | 141 |
151 | 142 |
152 void testMessageLength(int messageLength) { | 143 void testMessageLength(int messageLength) { |
153 createServer().then((server) { | 144 createServer().then((server) { |
154 Uint8List originalMessage = new Uint8List(messageLength); | 145 Uint8List originalMessage = new Uint8List(messageLength); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 (message) { | 347 (message) { |
357 messageCount++; | 348 messageCount++; |
358 if (messageCount < 10) { | 349 if (messageCount < 10) { |
359 Expect.equals(messageText, message); | 350 Expect.equals(messageText, message); |
360 webSocket.add(message); | 351 webSocket.add(message); |
361 } else { | 352 } else { |
362 webSocket.close(closeStatus, closeReason); | 353 webSocket.close(closeStatus, closeReason); |
363 } | 354 } |
364 }, | 355 }, |
365 onDone: () { | 356 onDone: () { |
366 Expect.equals(closeStatus, webSocket.closeCode); | 357 checkCloseStatus(webSocket, closeStatus, closeReason); |
367 Expect.equals("", webSocket.closeReason); | |
368 closeCount++; | 358 closeCount++; |
369 if (closeCount == totalConnections) { | 359 if (closeCount == totalConnections) { |
370 server.close(); | 360 server.close(); |
371 } | 361 } |
372 }); | 362 }); |
373 webSocket.add(messageText); | 363 webSocket.add(messageText); |
374 }); | 364 }); |
375 | 365 |
376 void webSocketConnection() { | 366 void webSocketConnection() { |
377 bool onopenCalled = false; | 367 bool onopenCalled = false; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 SecureSocket.initialize(database: testPkcertDatabase, | 586 SecureSocket.initialize(database: testPkcertDatabase, |
597 password: "dartdart"); | 587 password: "dartdart"); |
598 } | 588 } |
599 | 589 |
600 | 590 |
601 main() { | 591 main() { |
602 new SecurityConfiguration(secure: false).runTests(); | 592 new SecurityConfiguration(secure: false).runTests(); |
603 initializeSSL(); | 593 initializeSSL(); |
604 new SecurityConfiguration(secure: true).runTests(); | 594 new SecurityConfiguration(secure: true).runTests(); |
605 } | 595 } |
OLD | NEW |