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

Side by Side Diff: tests/standalone/io/tls_socket_test.dart

Issue 11417116: Fix secure socket tests to close sockets after writing. Fix handling of close events in TlsSocket … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve comments and code. Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // The --short_socket_write option does not work with external server 7 // The --short_socket_write option does not work with external server
8 // www.google.dk. Add this to the test when we have secure server sockets. 8 // www.google.dk. Add this to the test when we have secure server sockets.
9 // See TODO below. 9 // See TODO below.
10 10
11 #import("dart:isolate"); 11 #import("dart:isolate");
12 #import("dart:io"); 12 #import("dart:io");
13 13
14 void main() { 14 void main() {
15 var testPkcertDatabase = 15 var testPkcertDatabase =
16 new Path.fromNative(new Options().script).directoryPath.append('pkcert/'); 16 new Path.fromNative(new Options().script).directoryPath.append('pkcert/');
17 TlsSocket.setCertificateDatabase(testPkcertDatabase.toNativePath()); 17 TlsSocket.setCertificateDatabase(testPkcertDatabase.toNativePath());
18 // TODO(3593): Use a Dart HTTPS server for this test using TLS server sockets. 18 // TODO(3593): Use a Dart HTTPS server for this test using TLS server sockets.
19 // When we use a Dart HTTPS server, allow --short_socket_write. The flag 19 // When we use a Dart HTTPS server, allow --short_socket_write. The flag
20 // causes fragmentation of the client hello message, which doesn't seem to 20 // causes fragmentation of the client hello message, which doesn't seem to
21 // work with www.google.dk. 21 // work with www.google.dk.
22 var tls = new TlsSocket("www.google.dk", 443); 22 var tls = new TlsSocket("www.google.dk", 443);
23 List<String> chunks = <String>[]; 23 List<String> chunks = <String>[];
24 tls.onConnect = () { 24 tls.onConnect = () {
25 var request_bytes = 25 var request_bytes =
26 "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes; 26 "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes;
27 tls.writeList(request_bytes, 0, 20); 27 tls.writeList(request_bytes, 0, 20);
28 tls.writeList(request_bytes, 20, request_bytes.length - 20); 28 tls.writeList(request_bytes, 20, request_bytes.length - 20);
29 tls.close(true);
29 }; 30 };
30 var useReadList; // Mutually recursive onData callbacks. 31 var useReadList; // Mutually recursive onData callbacks.
31 void useRead() { 32 void useRead() {
32 var data = tls.read(); 33 var data = tls.read();
33 var received = new String.fromCharCodes(data); 34 var received = new String.fromCharCodes(data);
34 chunks.add(received); 35 chunks.add(received);
35 tls.onData = useReadList; 36 tls.onData = useReadList;
36 } 37 }
37 useReadList = () { 38 useReadList = () {
38 var buffer = new List(2000); 39 var buffer = new List(2000);
39 int len = tls.readList(buffer, 0, 2000); 40 int len = tls.readList(buffer, 0, 2000);
40 var received = new String.fromCharCodes(buffer.getRange(0, len)); 41 var received = new String.fromCharCodes(buffer.getRange(0, len));
41 chunks.add(received); 42 chunks.add(received);
42 tls.onData = useRead; 43 tls.onData = useRead;
43 }; 44 };
44 tls.onData = useRead; 45 tls.onData = useRead;
45 tls.onClosed = () { 46 tls.onClosed = () {
46 String fullPage = Strings.concatAll(chunks); 47 String fullPage = Strings.concatAll(chunks);
47 Expect.isTrue(fullPage.contains('</body></html>')); 48 Expect.isTrue(fullPage.contains('</body></html>'));
48 tls.close();
49 }; 49 };
50 } 50 }
OLDNEW
« sdk/lib/io/tls_socket.dart ('K') | « tests/standalone/io/tls_server_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698