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

Side by Side Diff: tests/standalone/io/secure_client_server_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 unified diff | Download patch
OLDNEW
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 // OtherResources=certificates/server_chain.pem 9 // OtherResources=certificates/server_chain.pem
10 // OtherResources=certificates/server_key.pem 10 // OtherResources=certificates/server_key.pem
11 // OtherResources=certificates/trusted_certs.pem 11 // OtherResources=certificates/trusted_certs.pem
12 12
13 import "dart:async"; 13 import "dart:async";
14 import "dart:io"; 14 import "dart:io";
15 15
16 import "package:async_helper/async_helper.dart"; 16 import "package:async_helper/async_helper.dart";
17 import "package:expect/expect.dart"; 17 import "package:expect/expect.dart";
18 18
19 InternetAddress HOST; 19 InternetAddress HOST;
20 20
21 String localFile(path) => Platform.script.resolve(path).toFilePath(); 21 String localFile(path) => Platform.script.resolve(path).toFilePath();
22 22
23 SecurityContext serverContext = new SecurityContext() 23 SecurityContext serverContext = new SecurityContext()
24 ..useCertificateChain(localFile('certificates/server_chain.pem')) 24 ..useCertificateChain(localFile('certificates/server_chain.pem'))
25 ..usePrivateKey(localFile('certificates/server_key.pem'), 25 ..usePrivateKey(localFile('certificates/server_key.pem'),
26 password: 'dartdart'); 26 password: 'dartdart');
27 27
28 SecurityContext clientContext = new SecurityContext() 28 SecurityContext clientContext = new SecurityContext()
29 ..setTrustedCertificates( 29 ..setTrustedCertificates(localFile('certificates/trusted_certs.pem'));
30 localFile('certificates/trusted_certs.pem'));
31
32 30
33 Future<SecureServerSocket> startEchoServer() { 31 Future<SecureServerSocket> startEchoServer() {
34 return SecureServerSocket.bind(HOST, 32 return SecureServerSocket.bind(HOST, 0, serverContext).then((server) {
35 0,
36 serverContext).then((server) {
37 server.listen((SecureSocket client) { 33 server.listen((SecureSocket client) {
38 client.fold(<int>[], (message, data) => message..addAll(data)) 34 client.fold(<int>[], (message, data) => message..addAll(data)).then(
39 .then((message) { 35 (message) {
40 client.add(message); 36 client.add(message);
41 client.close(); 37 client.close();
42 }); 38 });
43 }); 39 });
44 return server; 40 return server;
45 }); 41 });
46 } 42 }
47 43
48 Future testClient(server) { 44 Future testClient(server) {
49 return SecureSocket.connect(HOST, server.port, context: clientContext) 45 return SecureSocket
50 .then((socket) { 46 .connect(HOST, server.port, context: clientContext)
47 .then((socket) {
51 socket.write("Hello server."); 48 socket.write("Hello server.");
52 socket.close(); 49 socket.close();
53 return socket.fold(<int>[], (message, data) => message..addAll(data)) 50 return socket.fold(<int>[], (message, data) => message..addAll(data)).then(
54 .then((message) { 51 (message) {
55 Expect.listEquals("Hello server.".codeUnits, message); 52 Expect.listEquals("Hello server.".codeUnits, message);
56 return server; 53 return server;
57 }); 54 });
58 }); 55 });
59 } 56 }
60 57
61 void main() { 58 void main() {
62 asyncStart(); 59 asyncStart();
63 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first ) 60 InternetAddress
61 .lookup("localhost")
62 .then((hosts) => HOST = hosts.first)
64 .then((_) => startEchoServer()) 63 .then((_) => startEchoServer())
65 .then(testClient) 64 .then(testClient)
66 .then((server) => server.close()) 65 .then((server) => server.close())
67 .then((_) => asyncEnd()); 66 .then((_) => asyncEnd());
68 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698