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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 | 425 |
| 426 WebSocket.connect(url).then((websocket) { | 426 WebSocket.connect(url).then((websocket) { |
| 427 return websocket.listen((message) { | 427 return websocket.listen((message) { |
| 428 Expect.equals("Hello", message); | 428 Expect.equals("Hello", message); |
| 429 websocket.close(); | 429 websocket.close(); |
| 430 }).asFuture(); | 430 }).asFuture(); |
| 431 }).then((_) => server.close()); | 431 }).then((_) => server.close()); |
| 432 }); | 432 }); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void testOnRequest(bool useFuture) { | |
| 436 createServer().then((server) { | |
| 437 server.listen((request) { | |
| 438 Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request)); | |
| 439 Expect.equals(request.headers['My-Header'][0], 'my-value'); | |
| 440 WebSocketTransformer.upgrade(request).then((webSocket) { | |
| 441 webSocket.listen((_) { webSocket.close(); }); | |
| 442 webSocket.add("Hello"); | |
| 443 }); | |
| 444 }); | |
| 445 | |
| 446 onRequest(request) { | |
| 447 request.headers.set('My-Header', 'my-value'); | |
| 448 return useFuture ? new Future.value() : null; | |
|
Lasse Reichstein Nielsen
2015/01/12 15:11:56
Consider actually delaying some action to just bef
Søren Gjesse
2015/01/12 15:36:34
Removed the use of a callback.
| |
| 449 } | |
| 450 | |
| 451 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; | |
| 452 | |
| 453 WebSocket.connect(url, onRequest: onRequest).then((websocket) { | |
| 454 return websocket.listen((message) { | |
| 455 Expect.equals("Hello", message); | |
| 456 websocket.close(); | |
| 457 }).asFuture(); | |
| 458 }).then((_) => server.close()); | |
| 459 }); | |
| 460 } | |
|
kustermann
2015/01/09 14:45:12
[Since this file already imports async_helper, you
Søren Gjesse
2015/01/12 15:36:34
Done.
| |
| 461 | |
| 462 | |
| 435 void runTests() { | 463 void runTests() { |
| 436 testRequestResponseClientCloses(2, null, null, 1); | 464 testRequestResponseClientCloses(2, null, null, 1); |
| 437 testRequestResponseClientCloses(2, 3001, null, 2); | 465 testRequestResponseClientCloses(2, 3001, null, 2); |
| 438 testRequestResponseClientCloses(2, 3002, "Got tired", 3); | 466 testRequestResponseClientCloses(2, 3002, "Got tired", 3); |
| 439 testRequestResponseServerCloses(2, null, null); | 467 testRequestResponseServerCloses(2, null, null); |
| 440 testRequestResponseServerCloses(2, 3001, null); | 468 testRequestResponseServerCloses(2, 3001, null); |
| 441 testRequestResponseServerCloses(2, 3002, "Got tired"); | 469 testRequestResponseServerCloses(2, 3002, "Got tired"); |
| 442 testMessageLength(125); | 470 testMessageLength(125); |
| 443 testMessageLength(126); | 471 testMessageLength(126); |
| 444 testMessageLength(127); | 472 testMessageLength(127); |
| 445 testMessageLength(65535); | 473 testMessageLength(65535); |
| 446 testMessageLength(65536); | 474 testMessageLength(65536); |
| 447 testDoubleCloseClient(); | 475 testDoubleCloseClient(); |
| 448 testDoubleCloseServer(); | 476 testDoubleCloseServer(); |
| 449 testImmediateCloseServer(); | 477 testImmediateCloseServer(); |
| 450 testImmediateCloseClient(); | 478 testImmediateCloseClient(); |
| 451 testNoUpgrade(); | 479 testNoUpgrade(); |
| 452 testUsePOST(); | 480 testUsePOST(); |
| 453 testConnections(10, 3002, "Got tired"); | 481 testConnections(10, 3002, "Got tired"); |
| 454 testIndividualUpgrade(5); | 482 testIndividualUpgrade(5); |
| 455 testFromUpgradedSocket(); | 483 testFromUpgradedSocket(); |
| 484 testOnRequest(true); | |
| 485 testOnRequest(false); | |
| 456 } | 486 } |
| 457 } | 487 } |
| 458 | 488 |
| 459 | 489 |
| 460 void initializeSSL() { | 490 void initializeSSL() { |
| 461 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); | 491 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); |
| 462 SecureSocket.initialize(database: testPkcertDatabase, | 492 SecureSocket.initialize(database: testPkcertDatabase, |
| 463 password: "dartdart"); | 493 password: "dartdart"); |
| 464 } | 494 } |
| 465 | 495 |
| 466 | 496 |
| 467 main() { | 497 main() { |
| 468 new SecurityConfiguration(secure: false).runTests(); | 498 new SecurityConfiguration(secure: false).runTests(); |
| 469 initializeSSL(); | 499 initializeSSL(); |
| 470 new SecurityConfiguration(secure: true).runTests(); | 500 new SecurityConfiguration(secure: true).runTests(); |
| 471 } | 501 } |
| OLD | NEW |