Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: tests/standalone/io/web_socket_compression_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/standalone/io/web_socket_compression_test.dart
diff --git a/tests/standalone/io/web_socket_compression_test.dart b/tests/standalone/io/web_socket_compression_test.dart
index 99f341eeaf6939a821a11ebb5b36528938a45864..5507c84a4423091ffbd0849cc77483bd03619c07 100644
--- a/tests/standalone/io/web_socket_compression_test.dart
+++ b/tests/standalone/io/web_socket_compression_test.dart
@@ -27,21 +27,16 @@ String localFile(path) => Platform.script.resolve(path).toFilePath();
SecurityContext serverContext = new SecurityContext()
..useCertificateChain(localFile('certificates/server_chain.pem'))
..usePrivateKey(localFile('certificates/server_key.pem'),
- password: 'dartdart');
+ password: 'dartdart');
class SecurityConfiguration {
final bool secure;
SecurityConfiguration({bool this.secure});
- Future<HttpServer> createServer({int backlog: 0}) =>
- secure ? HttpServer.bindSecure(HOST_NAME,
- 0,
- serverContext,
- backlog: backlog)
- : HttpServer.bind(HOST_NAME,
- 0,
- backlog: backlog);
+ Future<HttpServer> createServer({int backlog: 0}) => secure
+ ? HttpServer.bindSecure(HOST_NAME, 0, serverContext, backlog: backlog)
+ : HttpServer.bind(HOST_NAME, 0, backlog: backlog);
Future<WebSocket> createClient(int port) =>
// TODO(whesse): Add client context argument to WebSocket.connect
@@ -87,9 +82,8 @@ class SecurityConfiguration {
});
}
- void testCompressionSupport({server: false,
- client: false,
- contextTakeover: false}) {
+ void testCompressionSupport(
+ {server: false, client: false, contextTakeover: false}) {
asyncStart();
var clientOptions = new CompressionOptions(
@@ -104,15 +98,16 @@ class SecurityConfiguration {
createServer().then((server) {
server.listen((request) {
Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request));
- WebSocketTransformer.upgrade(request, compression: serverOptions)
- .then((webSocket) {
- webSocket.listen((message) {
- Expect.equals("Hello World", message);
-
- webSocket.add(message);
- webSocket.close();
- });
- webSocket.add("Hello World");
+ WebSocketTransformer
+ .upgrade(request, compression: serverOptions)
+ .then((webSocket) {
+ webSocket.listen((message) {
+ Expect.equals("Hello World", message);
+
+ webSocket.add(message);
+ webSocket.close();
+ });
+ webSocket.add("Hello World");
});
});
@@ -130,20 +125,22 @@ class SecurityConfiguration {
});
}
- void testContextSupport({CompressionOptions serverOpts,
- CompressionOptions clientOpts,
- int messages}) {
+ void testContextSupport(
+ {CompressionOptions serverOpts,
+ CompressionOptions clientOpts,
+ int messages}) {
asyncStart();
createServer().then((server) {
server.listen((request) {
Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request));
- WebSocketTransformer.upgrade(request, compression: serverOpts)
- .then((webSocket) {
- webSocket.listen((message) {
- Expect.equals("Hello World", message);
- webSocket.add(message);
- });
+ WebSocketTransformer
+ .upgrade(request, compression: serverOpts)
+ .then((webSocket) {
+ webSocket.listen((message) {
+ Expect.equals("Hello World", message);
+ webSocket.add(message);
+ });
});
});
@@ -178,11 +175,12 @@ class SecurityConfiguration {
var digest = sha1.convert("$key$WEB_SOCKET_GUID".codeUnits);
var accept = BASE64.encode(digest.bytes);
request.response
- ..statusCode = HttpStatus.SWITCHING_PROTOCOLS
- ..headers.add(HttpHeaders.CONNECTION, "Upgrade")
- ..headers.add(HttpHeaders.UPGRADE, "websocket")
- ..headers.add("Sec-WebSocket-Accept", accept)
- ..headers.add("Sec-WebSocket-Extensions",
+ ..statusCode = HttpStatus.SWITCHING_PROTOCOLS
+ ..headers.add(HttpHeaders.CONNECTION, "Upgrade")
+ ..headers.add(HttpHeaders.UPGRADE, "websocket")
+ ..headers.add("Sec-WebSocket-Accept", accept)
+ ..headers.add(
+ "Sec-WebSocket-Extensions",
"permessage-deflate;"
// Test quoted values and space padded =
'server_max_window_bits="10"; client_max_window_bits = 12'
@@ -208,50 +206,50 @@ class SecurityConfiguration {
});
}
- void testReturnHeaders(String headerValue, String expected, {
- CompressionOptions serverCompression: CompressionOptions.DEFAULT}) {
+ void testReturnHeaders(String headerValue, String expected,
+ {CompressionOptions serverCompression: CompressionOptions.DEFAULT}) {
asyncStart();
createServer().then((server) {
server.listen((request) {
// Stuff
Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request));
- WebSocketTransformer.upgrade(request, compression: serverCompression)
- .then((webSocket) {
- webSocket.listen((message) {
- Expect.equals("Hello World", message);
-
- webSocket.add(message);
- webSocket.close();
- });
+ WebSocketTransformer
+ .upgrade(request, compression: serverCompression)
+ .then((webSocket) {
+ webSocket.listen((message) {
+ Expect.equals("Hello World", message);
+
+ webSocket.add(message);
+ webSocket.close();
+ });
});
});
var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/';
- createWebsocket(url, headerValue)
- .then((HttpClientResponse response) {
- Expect.equals(response.statusCode, HttpStatus.SWITCHING_PROTOCOLS);
- print(response.headers.value('Sec-WebSocket-Extensions'));
- Expect.equals(response.headers.value("Sec-WebSocket-Extensions"),
- expected);
-
- String accept = response.headers.value("Sec-WebSocket-Accept");
- Expect.isNotNull(accept);
-
- var protocol = response.headers.value('Sec-WebSocket-Protocol');
- return response.detachSocket().then((socket) =>
- new WebSocket.fromUpgradedSocket(
- socket, protocol: protocol, serverSide: false));
- }).then((websocket) {
- var future = websocket.listen((message) {
- Expect.equals("Hello", message);
- websocket.close();
- }).asFuture();
- websocket.add("Hello World");
- return future;
- }).then((_) {
- server.close();
- asyncEnd();
- });
+ createWebsocket(url, headerValue).then((HttpClientResponse response) {
+ Expect.equals(response.statusCode, HttpStatus.SWITCHING_PROTOCOLS);
+ print(response.headers.value('Sec-WebSocket-Extensions'));
+ Expect.equals(
+ response.headers.value("Sec-WebSocket-Extensions"), expected);
+
+ String accept = response.headers.value("Sec-WebSocket-Accept");
+ Expect.isNotNull(accept);
+
+ var protocol = response.headers.value('Sec-WebSocket-Protocol');
+ return response.detachSocket().then((socket) =>
+ new WebSocket.fromUpgradedSocket(socket,
+ protocol: protocol, serverSide: false));
+ }).then((websocket) {
+ var future = websocket.listen((message) {
+ Expect.equals("Hello", message);
+ websocket.close();
+ }).asFuture();
+ websocket.add("Hello World");
+ return future;
+ }).then((_) {
+ server.close();
+ asyncEnd();
+ });
}); // End createServer
}
@@ -271,12 +269,12 @@ class SecurityConfiguration {
hv.parameters['client_max_window_bits']);
WebSocketTransformer.upgrade(request).then((webSocket) {
- webSocket.listen((message) {
- Expect.equals('Hello World', message);
+ webSocket.listen((message) {
+ Expect.equals('Hello World', message);
- webSocket.add(message);
- webSocket.close();
- });
+ webSocket.add(message);
+ webSocket.close();
+ });
});
});
@@ -311,66 +309,65 @@ class SecurityConfiguration {
// Test Multiple messages with various context takeover configurations.
// no context takeover on the server.
var serverComp = new CompressionOptions(serverNoContextTakeover: true);
- testContextSupport(serverOpts: serverComp,
- clientOpts: serverComp,
- messages: 5);
+ testContextSupport(
+ serverOpts: serverComp, clientOpts: serverComp, messages: 5);
// no contexttakeover on the client.
var clientComp = new CompressionOptions(clientNoContextTakeover: true);
- testContextSupport(serverOpts: clientComp,
- clientOpts: clientComp,
- messages: 5);
+ testContextSupport(
+ serverOpts: clientComp, clientOpts: clientComp, messages: 5);
// no context takeover enabled for both.
- var compression = new CompressionOptions(serverNoContextTakeover: true,
- clientNoContextTakeover: true);
- testContextSupport(serverOpts: compression,
- clientOpts: compression,
- messages: 5);
+ var compression = new CompressionOptions(
+ serverNoContextTakeover: true, clientNoContextTakeover: true);
+ testContextSupport(
+ serverOpts: compression, clientOpts: compression, messages: 5);
// no context take over for opposing configurations.
- testContextSupport(serverOpts: serverComp,
- clientOpts: clientComp,
- messages: 5);
- testContextSupport(serverOpts: clientComp,
- clientOpts: serverComp,
- messages: 5);
+ testContextSupport(
+ serverOpts: serverComp, clientOpts: clientComp, messages: 5);
+ testContextSupport(
+ serverOpts: clientComp, clientOpts: serverComp, messages: 5);
testCompressionHeaders();
// Chrome headers
testReturnHeaders('permessage-deflate; client_max_window_bits',
- "permessage-deflate; client_max_window_bits=15");
+ "permessage-deflate; client_max_window_bits=15");
// Firefox headers
- testReturnHeaders('permessage-deflate',
- "permessage-deflate; client_max_window_bits=15");
+ testReturnHeaders(
+ 'permessage-deflate', "permessage-deflate; client_max_window_bits=15");
// Ensure max_window_bits resize appropriately.
- testReturnHeaders('permessage-deflate; server_max_window_bits=10',
- "permessage-deflate;"
- " server_max_window_bits=10;"
- " client_max_window_bits=10");
+ testReturnHeaders(
+ 'permessage-deflate; server_max_window_bits=10',
+ "permessage-deflate;"
+ " server_max_window_bits=10;"
+ " client_max_window_bits=10");
// Don't provider context takeover if requested but not enabled.
// Default is not enabled.
- testReturnHeaders('permessage-deflate; client_max_window_bits;'
- 'client_no_context_takeover',
- 'permessage-deflate; client_max_window_bits=15');
+ testReturnHeaders(
+ 'permessage-deflate; client_max_window_bits;'
+ 'client_no_context_takeover',
+ 'permessage-deflate; client_max_window_bits=15');
// Enable context Takeover and provide if requested.
- compression = new CompressionOptions(clientNoContextTakeover: true,
- serverNoContextTakeover: true);
- testReturnHeaders('permessage-deflate; client_max_window_bits; '
- 'client_no_context_takeover',
- 'permessage-deflate; client_no_context_takeover; '
- 'client_max_window_bits=15',
- serverCompression: compression);
+ compression = new CompressionOptions(
+ clientNoContextTakeover: true, serverNoContextTakeover: true);
+ testReturnHeaders(
+ 'permessage-deflate; client_max_window_bits; '
+ 'client_no_context_takeover',
+ 'permessage-deflate; client_no_context_takeover; '
+ 'client_max_window_bits=15',
+ serverCompression: compression);
// Enable context takeover and don't provide if not requested
- compression = new CompressionOptions(clientNoContextTakeover: true,
- serverNoContextTakeover: true);
+ compression = new CompressionOptions(
+ clientNoContextTakeover: true, serverNoContextTakeover: true);
testReturnHeaders('permessage-deflate; client_max_window_bits; ',
- 'permessage-deflate; client_max_window_bits=15',
- serverCompression: compression);
+ 'permessage-deflate; client_max_window_bits=15',
+ serverCompression: compression);
compression = CompressionOptions.DEFAULT;
testClientRequestHeaders(compression);
- compression = new CompressionOptions(clientNoContextTakeover: true,
- serverNoContextTakeover: true);
+ compression = new CompressionOptions(
+ clientNoContextTakeover: true, serverNoContextTakeover: true);
testClientRequestHeaders(compression);
- compression = new CompressionOptions(clientNoContextTakeover: true,
+ compression = new CompressionOptions(
+ clientNoContextTakeover: true,
serverNoContextTakeover: true,
clientMaxWindowBits: 8,
serverMaxWindowBits: 8);

Powered by Google App Engine
This is Rietveld 408576698