Index: tests/standalone/io/tls_stream_test.dart |
diff --git a/tests/standalone/io/tls_socket_test.dart b/tests/standalone/io/tls_stream_test.dart |
similarity index 55% |
copy from tests/standalone/io/tls_socket_test.dart |
copy to tests/standalone/io/tls_stream_test.dart |
index 1a82d2d949b9d873fa939f8381163413b2c2d21e..c726efd95917ec39a59941741ccb162ba4c88978 100644 |
--- a/tests/standalone/io/tls_socket_test.dart |
+++ b/tests/standalone/io/tls_stream_test.dart |
@@ -11,20 +11,6 @@ |
#import("dart:isolate"); |
#import("dart:io"); |
-void WriteAndClose(Socket socket, String message) { |
- var data = message.charCodes; |
- int written = 0; |
- void write() { |
- written += socket.writeList(data, written, data.length - written); |
- if (written < data.length) { |
- socket.onWrite = write; |
- } else { |
- socket.close(true); |
- } |
- } |
- write(); |
-} |
- |
void main() { |
var testPkcertDatabase = |
new Path.fromNative(new Options().script).directoryPath.append('pkcert/'); |
@@ -35,25 +21,15 @@ void main() { |
// work with www.google.dk. |
var tls = new TlsSocket("www.google.dk", 443); |
List<String> chunks = <String>[]; |
- tls.onConnect = () { |
- WriteAndClose(tls, "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n"); |
- }; |
- 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; |
+ var input = tls.inputStream; |
+ var output = tls.outputStream; |
+ |
+ output.write("GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes); |
+ output.close(); |
+ input.onData = () { |
+ chunks.add(new String.fromCharCodes(input.read())); |
}; |
- tls.onData = useRead; |
- tls.onClosed = () { |
+ input.onClosed = () { |
String fullPage = Strings.concatAll(chunks); |
Expect.isTrue(fullPage.contains('</body></html>')); |
}; |