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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 })); | 379 })); |
| 380 } | 380 } |
| 381 | 381 |
| 382 Future.wait(futures).then((_) { | 382 Future.wait(futures).then((_) { |
| 383 server.close(); | 383 server.close(); |
| 384 client.close(); | 384 client.close(); |
| 385 }); | 385 }); |
| 386 }); | 386 }); |
| 387 } | 387 } |
| 388 | 388 |
| 389 testFromSocket() { | 389 testFromUpgradedSocket() { |
|
Anders Johnsen
2014/05/01 05:53:04
It would be nice if you added a asyncStart/asyncEn
nweiz
2014/05/01 18:13:14
Done.
| |
| 390 createServer().then((server) { | 390 createServer().then((server) { |
| 391 server.listen((request) { | 391 server.listen((request) { |
| 392 Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION)); | 392 Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION)); |
| 393 Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE)); | 393 Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE)); |
| 394 | 394 |
| 395 var key = request.headers.value('Sec-WebSocket-Key'); | 395 var key = request.headers.value('Sec-WebSocket-Key'); |
| 396 var sha1 = new SHA1()..add("$key$WEB_SOCKET_GUID".codeUnits); | 396 var sha1 = new SHA1()..add("$key$WEB_SOCKET_GUID".codeUnits); |
| 397 var accept = CryptoUtils.bytesToBase64(sha1.close()); | 397 var accept = CryptoUtils.bytesToBase64(sha1.close()); |
| 398 request.response | 398 request.response |
| 399 ..statusCode = HttpStatus.SWITCHING_PROTOCOLS | 399 ..statusCode = HttpStatus.SWITCHING_PROTOCOLS |
| 400 ..headers.add(HttpHeaders.CONNECTION, "Upgrade") | 400 ..headers.add(HttpHeaders.CONNECTION, "Upgrade") |
| 401 ..headers.add(HttpHeaders.UPGRADE, "websocket") | 401 ..headers.add(HttpHeaders.UPGRADE, "websocket") |
| 402 ..headers.add("Sec-WebSocket-Accept", accept); | 402 ..headers.add("Sec-WebSocket-Accept", accept); |
| 403 request.response.contentLength = 0; | 403 request.response.contentLength = 0; |
| 404 return request.response.detachSocket() | 404 request.response.detachSocket() |
| 405 .then((socket) => new WebSocket.fromUpgradedSocket(socket)) | 405 .then((socket) => new WebSocket.fromUpgradedSocket(socket)) |
| 406 .then((websocket) { | 406 .then((websocket) { |
| 407 websocket.add("Hello"); | 407 websocket.add("Hello"); |
| 408 websocket.close(); | 408 websocket.close(); |
| 409 }); | 409 }); |
| 410 }); | 410 }); |
| 411 | 411 |
| 412 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; | 412 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; |
| 413 | 413 |
| 414 var client = new HttpClient(); | |
| 415 var completer = new Completer(); | |
| 416 WebSocket.connect(url).then((websocket) { | 414 WebSocket.connect(url).then((websocket) { |
| 417 return websocket.listen((message) { | 415 return websocket.listen((message) { |
| 418 Expect.equals("Hello", message); | 416 Expect.equals("Hello", message); |
| 419 websocket.close(); | 417 websocket.close(); |
| 420 }).asFuture(); | 418 }).asFuture(); |
| 421 }).then((_) => server.close()); | 419 }).then((_) => server.close()); |
| 422 }); | 420 }); |
| 423 } | 421 } |
| 424 | 422 |
| 425 void runTests() { | 423 void runTests() { |
| 426 testRequestResponseClientCloses(2, null, null); | 424 testRequestResponseClientCloses(2, null, null); |
| 427 testRequestResponseClientCloses(2, 3001, null); | 425 testRequestResponseClientCloses(2, 3001, null); |
| 428 testRequestResponseClientCloses(2, 3002, "Got tired"); | 426 testRequestResponseClientCloses(2, 3002, "Got tired"); |
| 429 testRequestResponseServerCloses(2, null, null); | 427 testRequestResponseServerCloses(2, null, null); |
| 430 testRequestResponseServerCloses(2, 3001, null); | 428 testRequestResponseServerCloses(2, 3001, null); |
| 431 testRequestResponseServerCloses(2, 3002, "Got tired"); | 429 testRequestResponseServerCloses(2, 3002, "Got tired"); |
| 432 testMessageLength(125); | 430 testMessageLength(125); |
| 433 testMessageLength(126); | 431 testMessageLength(126); |
| 434 testMessageLength(127); | 432 testMessageLength(127); |
| 435 testMessageLength(65535); | 433 testMessageLength(65535); |
| 436 testMessageLength(65536); | 434 testMessageLength(65536); |
| 437 testDoubleCloseClient(); | 435 testDoubleCloseClient(); |
| 438 testDoubleCloseServer(); | 436 testDoubleCloseServer(); |
| 439 testImmediateCloseServer(); | 437 testImmediateCloseServer(); |
| 440 testImmediateCloseClient(); | 438 testImmediateCloseClient(); |
| 441 testNoUpgrade(); | 439 testNoUpgrade(); |
| 442 testUsePOST(); | 440 testUsePOST(); |
| 443 testConnections(10, 3002, "Got tired"); | 441 testConnections(10, 3002, "Got tired"); |
| 444 testIndividualUpgrade(5); | 442 testIndividualUpgrade(5); |
| 445 testFromSocket(); | 443 testFromUpgradedSocket(); |
| 446 } | 444 } |
| 447 } | 445 } |
| 448 | 446 |
| 449 | 447 |
| 450 void initializeSSL() { | 448 void initializeSSL() { |
| 451 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); | 449 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); |
| 452 SecureSocket.initialize(database: testPkcertDatabase, | 450 SecureSocket.initialize(database: testPkcertDatabase, |
| 453 password: "dartdart"); | 451 password: "dartdart"); |
| 454 } | 452 } |
| 455 | 453 |
| 456 | 454 |
| 457 main() { | 455 main() { |
| 458 asyncStart(); | 456 asyncStart(); |
| 459 new SecurityConfiguration(secure: false).runTests(); | 457 new SecurityConfiguration(secure: false).runTests(); |
| 460 initializeSSL(); | 458 initializeSSL(); |
| 461 new SecurityConfiguration(secure: true).runTests(); | 459 new SecurityConfiguration(secure: true).runTests(); |
| 462 asyncEnd(); | 460 asyncEnd(); |
| 463 } | 461 } |
| OLD | NEW |