Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // | |
| 5 // VMOptions= | |
| 6 // VMOptions=--short_socket_read | |
| 7 // VMOptions=--short_socket_write | |
| 8 // VMOptions=--short_socket_read --short_socket_write | |
| 9 | |
| 10 import "dart:async"; | |
| 11 import "dart:convert"; | |
| 12 import "dart:io"; | |
| 13 import "dart:typed_data"; | |
| 14 | |
| 15 import "package:async_helper/async_helper.dart"; | |
| 16 import "package:crypto/crypto.dart"; | |
| 17 import "package:expect/expect.dart"; | |
| 18 import "package:path/path.dart"; | |
| 19 | |
| 20 const String HOST_NAME = 'localhost'; | |
| 21 | |
| 22 class SecurityConfiguration { | |
| 23 final bool secure; | |
| 24 | |
| 25 SecurityConfiguration({bool this.secure}); | |
| 26 | |
| 27 Future<HttpServer> createServer({int backlog: 0}) => | |
| 28 secure ? HttpServer.bindSecure(HOST_NAME, | |
| 29 0, | |
| 30 serverContext, | |
| 31 backlog: backlog) | |
| 32 : HttpServer.bind(HOST_NAME, | |
| 33 0, | |
| 34 backlog: backlog); | |
| 35 | |
| 36 Future<WebSocket> createClient(int port) => | |
| 37 // TODO(whesse): Add client context argument to WebSocket.connect | |
| 38 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/'); | |
| 39 | |
| 40 void testCompressionSupport(bool enabled, bool allowContextTakeover) { | |
| 41 asyncStart(); | |
| 42 | |
| 43 var options = new CompressionOptions( | |
| 44 enabled: enabled, | |
| 45 serverNoContextTakeover: allowContextTakeover, | |
| 46 clientNoContextTakeover: allowContextTakeover); | |
| 47 | |
| 48 createServer().then((server) { | |
| 49 server.listen((request) { | |
| 50 Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request)); | |
| 51 WebSocketTransformer.upgrade(request, compression: options).then((webSoc ket) { | |
|
Søren Gjesse
2015/10/19 16:53:20
Long line.
butlermatt
2015/10/22 19:36:09
Done.
| |
| 52 webSocket.listen((message) { | |
| 53 Expect.equals("Hello World", message); | |
| 54 | |
| 55 webSocket.add(message); | |
| 56 webSocket.close(); | |
| 57 }); | |
| 58 webSocket.add("Hello World"); | |
| 59 }); | |
| 60 }); | |
| 61 | |
| 62 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; | |
| 63 WebSocket.connect(url, compression: options).then((websocket) { | |
| 64 var future = websocket.listen((message) { | |
| 65 Expect.equals("Hello World", message); | |
| 66 }).asFuture(); | |
| 67 websocket.add("Hello World"); | |
| 68 return future; | |
| 69 }).then((_) { | |
| 70 server.close(); | |
| 71 asyncEnd(); | |
| 72 }); | |
| 73 }); | |
| 74 } | |
| 75 | |
| 76 void runTests() { | |
| 77 testCompressionSupport(false, false); | |
| 78 testCompressionSupport(true, false); | |
| 79 testCompressionSupport(true, true); | |
|
Søren Gjesse
2015/10/19 16:53:20
Please add tests where the client wants to use com
butlermatt
2015/10/22 19:36:09
Done.
| |
| 80 } | |
| 81 } | |
| 82 | |
| 83 main() { | |
| 84 new SecurityConfiguration(secure: false).runTests(); | |
| 85 // TODO(whesse): Make WebSocket.connect() take an optional context: parameter. | |
| 86 // new SecurityConfiguration(secure: true).runTests(); | |
| 87 } | |
| OLD | NEW |