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

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

Issue 12330133: Don't use external servers in the tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed long lines Created 7 years, 10 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/secure_socket_test.dart
diff --git a/tests/standalone/io/secure_socket_test.dart b/tests/standalone/io/secure_socket_test.dart
index 409d40e615e3902ee128a08e9c6986292bbcbabd..2fb4062ab34eac378978d533e473db557ca597a9 100644
--- a/tests/standalone/io/secure_socket_test.dart
+++ b/tests/standalone/io/secure_socket_test.dart
@@ -1,32 +1,61 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, 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
-// VMOptions=--short_socket_write
-// VMOptions=--short_socket_read --short_socket_write
+// XXVMOptions=--short_socket_write
+// XXVMOptions=--short_socket_read --short_socket_write
-import "dart:isolate";
+import "dart:async";
import "dart:io";
+Future<HttpServer> startServer() {
+ return HttpServer.bindSecure(
+ "127.0.0.1",
+ 0,
+ backlog: 5,
+ certificateName: 'localhost_cert').then((server) {
+ server.listen((HttpRequest request) {
+ request.listen(
+ (_) { },
+ onDone: () {
+ request.response.contentLength = 100;
+ for (int i = 0; i < 10; i++) {
+ request.response.add([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
+ }
+ request.response.close();
+ });
+ });
+ return server;
+ });
+}
+
+void InitializeSSL() {
+ var testPkcertDatabase =
+ new Path(new Options().script).directoryPath.append('pkcert/');
+ SecureSocket.initialize(database: testPkcertDatabase.toNativePath(),
+ password: 'dartdart');
+}
+
void main() {
- ReceivePort keepAlive = new ReceivePort();
- SecureSocket.initialize();
- List<String> chunks = <String>[];
- SecureSocket.connect("www.google.dk", 443).then((socket) {
- socket.add("GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".codeUnits);
- socket.close();
- socket.listen(
- (List<int> data) {
- var received = new String.fromCharCodes(data);
- chunks.add(received);
- },
- onDone: () {
- String fullPage = chunks.join();
- Expect.isTrue(fullPage.contains('</body></html>'));
- keepAlive.close();
- },
- onError: (e) => Expect.fail("Unexpected error $e"));
+ InitializeSSL();
+ List<int> body = <int>[];
+ startServer().then((server) {
+ SecureSocket.connect("localhost", server.port).then((socket) {
+ socket.add("GET / HTTP/1.0\r\nHost: localhost\r\n\r\n".codeUnits);
+ socket.close();
+ socket.listen(
+ (List<int> data) {
+ body.addAll(data);
+ },
+ onDone: () {
+ Expect.isTrue(body.length > 100, "$body\n${body.length}");
+ Expect.equals(72, body[0]);
+ Expect.equals(9, body[body.length - 1]);
+ server.close();
+ },
+ onError: (e) => Expect.fail("Unexpected error $e"));
+ });
});
}

Powered by Google App Engine
This is Rietveld 408576698