Chromium Code Reviews| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 }); | 281 }); |
| 282 }); | 282 }); |
| 283 } | 283 } |
| 284 | 284 |
| 285 for (int i = 0; i < totalConnections; i++) { | 285 for (int i = 0; i < totalConnections; i++) { |
| 286 webSocketConnection(); | 286 webSocketConnection(); |
| 287 } | 287 } |
| 288 }); | 288 }); |
| 289 } | 289 } |
| 290 | 290 |
| 291 testIndivitualUpgrade(int connections) { | |
| 292 createServer().then((server) { | |
| 293 int closeCount = 0; | |
|
Anders Johnsen
2013/03/04 14:41:57
Unused?
Søren Gjesse
2013/03/04 15:50:15
Removed.
| |
| 294 server.listen((request) { | |
| 295 if (WebSocketTransformer.isUpgradeRequest(request)) { | |
| 296 WebSocketTransformer.upgrade(request).then((webSocket) { | |
| 297 webSocket.listen((_) { webSocket.close(); }); | |
| 298 webSocket.send("Hello"); | |
| 299 }); | |
| 300 } else { | |
| 301 Expect.isFalse(WebSocketTransformer.isUpgradeRequest(request)); | |
| 302 request.response.statusCode = HttpStatus.OK; | |
| 303 request.response.close(); | |
| 304 } | |
| 305 }); | |
| 306 | |
| 307 var futures = []; | |
| 308 | |
| 309 var wsProtocol = '${secure ? "wss" : "ws"}'; | |
| 310 var baseWsUrl = '$wsProtocol://$HOST_NAME:${server.port}/'; | |
| 311 var httpProtocol = '${secure ? "https" : "http"}'; | |
| 312 var baseHttpUrl = '$httpProtocol://$HOST_NAME:${server.port}/'; | |
| 313 HttpClient client = new HttpClient(); | |
| 314 | |
| 315 for (int i = 0; i < connections; i++) { | |
| 316 var completer1 = new Completer(); | |
| 317 futures.add(completer1.future); | |
| 318 WebSocket.connect('${baseWsUrl}') | |
| 319 .then((websocket) { | |
| 320 websocket.listen((_) { websocket.close(); }, | |
| 321 onDone: completer1.complete); | |
| 322 }); | |
| 323 | |
| 324 var completer2 = new Completer(); | |
| 325 futures.add(completer2.future); | |
| 326 client.openUrl("GET", new Uri.fromString('${baseHttpUrl}')) | |
|
Anders Johnsen
2013/03/04 14:41:57
Add the result of client.openUrl directl to future
Søren Gjesse
2013/03/04 15:50:15
Done.
| |
| 327 .then((request) => request.close()) | |
| 328 .then((response) { | |
| 329 response.listen((_) { }); | |
| 330 Expect.equals(HttpStatus.OK, response.statusCode); | |
| 331 completer2.complete(); | |
| 332 }); | |
| 333 } | |
| 334 | |
| 335 Future.wait(futures).then((_) { | |
| 336 server.close(); | |
| 337 client.close(); | |
| 338 }); | |
| 339 }); | |
| 340 } | |
| 341 | |
| 291 void runTests() { | 342 void runTests() { |
| 292 testRequestResponseClientCloses(2, null, null); | 343 testRequestResponseClientCloses(2, null, null); |
| 293 testRequestResponseClientCloses(2, 3001, null); | 344 testRequestResponseClientCloses(2, 3001, null); |
| 294 testRequestResponseClientCloses(2, 3002, "Got tired"); | 345 testRequestResponseClientCloses(2, 3002, "Got tired"); |
| 295 testRequestResponseServerCloses(2, null, null); | 346 testRequestResponseServerCloses(2, null, null); |
| 296 testRequestResponseServerCloses(2, 3001, null); | 347 testRequestResponseServerCloses(2, 3001, null); |
| 297 testRequestResponseServerCloses(2, 3002, "Got tired"); | 348 testRequestResponseServerCloses(2, 3002, "Got tired"); |
| 298 testMessageLength(125); | 349 testMessageLength(125); |
| 299 testMessageLength(126); | 350 testMessageLength(126); |
| 300 testMessageLength(127); | 351 testMessageLength(127); |
| 301 testMessageLength(65535); | 352 testMessageLength(65535); |
| 302 testMessageLength(65536); | 353 testMessageLength(65536); |
| 303 testDoubleCloseClient(); | 354 testDoubleCloseClient(); |
| 304 testDoubleCloseServer(); | 355 testDoubleCloseServer(); |
| 305 testNoUpgrade(); | 356 testNoUpgrade(); |
| 306 testUsePOST(); | 357 testUsePOST(); |
| 307 testConnections(10, 3002, "Got tired"); | 358 testConnections(10, 3002, "Got tired"); |
| 359 testIndivitualUpgrade(5); | |
| 308 } | 360 } |
| 309 } | 361 } |
| 310 | 362 |
| 311 | 363 |
| 312 void initializeSSL() { | 364 void initializeSSL() { |
| 313 var testPkcertDatabase = | 365 var testPkcertDatabase = |
| 314 new Path(new Options().script).directoryPath.append("pkcert/"); | 366 new Path(new Options().script).directoryPath.append("pkcert/"); |
| 315 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), | 367 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), |
| 316 password: "dartdart"); | 368 password: "dartdart"); |
| 317 } | 369 } |
| 318 | 370 |
| 319 | 371 |
| 320 main() { | 372 main() { |
| 321 new SecurityConfiguration(secure: false).runTests(); | 373 new SecurityConfiguration(secure: false).runTests(); |
| 322 initializeSSL(); | 374 initializeSSL(); |
| 323 new SecurityConfiguration(secure: true).runTests(); | 375 new SecurityConfiguration(secure: true).runTests(); |
| 324 } | 376 } |
| OLD | NEW |