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

Side by Side Diff: tests/standalone/io/raw_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, 9 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
Anders Johnsen 2013/02/26 09:42:14 XX?
Søren Gjesse 2013/02/26 10:00:00 Ditto.
8 // VMOptions=--short_socket_read --short_socket_write 8 // XXVMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:async"; 10 import "dart:async";
11 import "dart:io"; 11 import "dart:io";
12 import "dart:isolate"; 12 import "dart:isolate";
13 13
14 Future<HttpServer> startServer() {
15 return HttpServer.bindSecure(
16 "127.0.0.1",
17 0,
18 backlog: 5,
19 certificateName: 'localhost_cert').then((server) {
20 server.listen((HttpRequest request) {
21 request.listen(
22 (_) { },
23 onDone: () {
24 request.response.contentLength = 100;
25 for (int i = 0; i < 10; i++) {
26 request.response.add([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
27 }
28 request.response.close();
29 });
30 });
31 return server;
32 });
33 }
34
35 void InitializeSSL() {
36 var testPkcertDatabase =
37 new Path(new Options().script).directoryPath.append('pkcert/');
38 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(),
39 password: 'dartdart');
40 }
14 41
15 void main() { 42 void main() {
16 List<int> message = "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".codeUnits; 43 List<int> message = "GET / HTTP/1.0\r\nHost: localhost\r\n\r\n".codeUnits;
17 int written = 0; 44 int written = 0;
18 List<String> chunks = <String>[]; 45 List<int> body = <int>[];
19 SecureSocket.initialize(); 46 InitializeSSL();
20 // TODO(3593): Use a Dart HTTPS server for this test. 47 startServer().then((server) {
21 RawSecureSocket.connect("www.google.dk", 443).then((socket) { 48 RawSecureSocket.connect("localhost", server.port).then((socket) {
22 socket.listen((RawSocketEvent event) { 49 socket.listen(
23 switch (event) { 50 (RawSocketEvent event) {
24 case RawSocketEvent.READ: 51 switch (event) {
25 var data = socket.read(); 52 case RawSocketEvent.READ:
26 var received = new String.fromCharCodes(data); 53 body.addAll(socket.read());
27 chunks.add(received); 54 break;
28 break; 55 case RawSocketEvent.WRITE:
29 case RawSocketEvent.WRITE: 56 written +=
30 written += 57 socket.write(message, written, message.length - written);
31 socket.write(message, written, message.length - written); 58 if (written < message.length) {
32 if (written < message.length) { 59 socket.writeEventsEnabled = true;
33 socket.writeEventsEnabled = true; 60 } else {
34 } else { 61 socket.shutdown(SocketDirection.SEND);
35 socket.shutdown(SocketDirection.SEND); 62 }
36 } 63 break;
37 break; 64 case RawSocketEvent.READ_CLOSED:
38 case RawSocketEvent.READ_CLOSED: 65 Expect.isTrue(body.length > 100, "$body\n${body.length}");
39 String fullPage = chunks.join(); 66 Expect.equals(72, body[0]);
40 Expect.isTrue(fullPage.contains('</body></html>')); 67 Expect.equals(9, body[body.length - 1]);
41 break; 68 server.close();
42 default: throw "Unexpected event $event"; 69 break;
43 } 70 default: throw "Unexpected event $event";
44 }, onError: (AsyncError a) { 71 }
45 Expect.fail("onError handler of RawSecureSocket stream hit: $a"); 72 },
73 onError: (AsyncError a) {
74 Expect.fail("onError handler of RawSecureSocket stream hit: $a");
75 });
46 }); 76 });
47 }); 77 });
48 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698