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

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

Issue 10916081: Add secure sockets to dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month 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
« sdk/lib/io/tls_socket.dart ('K') | « tests/standalone/io/pkcert/pkcs11.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/tls_socket_test.dart
diff --git a/tests/standalone/io/tls_socket_test.dart b/tests/standalone/io/tls_socket_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..061d93f8f5af2564acdc436cdbb93723b8d2d62a
--- /dev/null
+++ b/tests/standalone/io/tls_socket_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// VMOptions=
+// VMOptions=--short_socket_read
+// The --short_socket_write option does not work with external server
+// www.google.dk. Add this to the test when we have secure server sockets.
+// See TODO below.
+
+#import("dart:isolate");
+#import("dart:io");
+
+void main() {
+ var testPkcertDatabase =
+ new Path.fromNative(new Options().script).directoryPath.append('pkcert/');
+ TlsSocket.setCertificateDatabase(testPkcertDatabase.toNativePath());
+ // TODO(3593): Use a Dart HTTPS server for this test using TLS server sockets.
+ // When we use a Dart HTTPS server, allow --short_socket_write. The flag
+ // causes fragmentation of the client hello message, which doesn't seem to
+ // work with www.google.dk.
+ var tls = new TlsSocket("www.google.dk", 443);
+ List<String> chunks = <String>[];
+ tls.onConnect = () {
+ var request_bytes =
+ "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes;
+ tls.writeList(request_bytes, 0, 20);
+ tls.writeList(request_bytes, 20, request_bytes.length - 20);
+ };
+ var useReadList; // Mutually recursive onData callbacks.
+ void useRead() {
+ var data = tls.read();
+ var received = new String.fromCharCodes(data);
+ chunks.add(received);
+ tls.onData = useReadList;
+ }
+ useReadList = () {
+ var buffer = new List(2000);
+ int len = tls.readList(buffer, 0, 2000);
+ var received = new String.fromCharCodes(buffer.getRange(0, len));
+ chunks.add(received);
+ tls.onData = useRead;
+ };
+ tls.onData = useRead;
+ tls.onClosed = () {
+ String fullPage = Strings.concatAll(chunks);
+ Expect.isTrue(fullPage.contains('</body></html>'));
+ tls.close();
+ };
+}
« sdk/lib/io/tls_socket.dart ('K') | « tests/standalone/io/pkcert/pkcs11.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698