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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, 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 // XXVMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // XXVMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:isolate"; 10 import "dart:async";
11 import "dart:io"; 11 import "dart:io";
12 12
13 void main() { 13 Future<HttpServer> startServer() {
14 ReceivePort keepAlive = new ReceivePort(); 14 return HttpServer.bindSecure(
15 SecureSocket.initialize(); 15 "127.0.0.1",
16 List<String> chunks = <String>[]; 16 0,
17 SecureSocket.connect("www.google.dk", 443).then((socket) { 17 backlog: 5,
18 socket.add("GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".codeUnits); 18 certificateName: 'localhost_cert').then((server) {
19 socket.close(); 19 server.listen((HttpRequest request) {
20 socket.listen( 20 request.listen(
21 (List<int> data) { 21 (_) { },
22 var received = new String.fromCharCodes(data); 22 onDone: () {
23 chunks.add(received); 23 request.response.contentLength = 100;
24 }, 24 for (int i = 0; i < 10; i++) {
25 onDone: () { 25 request.response.add([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
26 String fullPage = chunks.join(); 26 }
27 Expect.isTrue(fullPage.contains('</body></html>')); 27 request.response.close();
28 keepAlive.close(); 28 });
29 }, 29 });
30 onError: (e) => Expect.fail("Unexpected error $e")); 30 return server;
31 }); 31 });
32 } 32 }
33
34 void InitializeSSL() {
35 var testPkcertDatabase =
36 new Path(new Options().script).directoryPath.append('pkcert/');
37 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(),
38 password: 'dartdart');
39 }
40
41 void main() {
42 InitializeSSL();
43 List<int> body = <int>[];
44 startServer().then((server) {
45 SecureSocket.connect("localhost", server.port).then((socket) {
46 socket.add("GET / HTTP/1.0\r\nHost: localhost\r\n\r\n".codeUnits);
47 socket.close();
48 socket.listen(
49 (List<int> data) {
50 body.addAll(data);
51 },
52 onDone: () {
53 Expect.isTrue(body.length > 100, "$body\n${body.length}");
54 Expect.equals(72, body[0]);
55 Expect.equals(9, body[body.length - 1]);
56 server.close();
57 },
58 onError: (e) => Expect.fail("Unexpected error $e"));
59 });
60 });
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698