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

Side by Side Diff: tests/standalone/io/https_server_test.dart

Issue 11299228: Add HttpsServer class and test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adress comment Created 8 years 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
« sdk/lib/io/http_impl.dart ('K') | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #import("dart:io"); 5 import "dart:io";
6 #import("dart:isolate"); 6 import "dart:uri";
7 import "dart:isolate";
8
9 const SERVER_ADDRESS = "127.0.0.1";
10 const HOST_NAME = "localhost";
7 11
8 void testListenOn() { 12 void testListenOn() {
9 ServerSocket socket = new ServerSocket("127.0.0.1", 0, 5);
10
11 socket.onError = (Exception e) {
12 Expect.fail("ServerSocket closed unexpected");
13 };
14
15 void test(void onDone()) { 13 void test(void onDone()) {
16 HttpServer server = new HttpServer(); 14 HttpsServer server = new HttpsServer();
17 Expect.throws(() => server.port); 15 Expect.throws(() => server.port);
18 16
19 ReceivePort serverPort = new ReceivePort(); 17 ReceivePort serverPort = new ReceivePort();
20 server.defaultRequestHandler = 18 server.defaultRequestHandler =
21 (HttpRequest request, HttpResponse response) { 19 (HttpRequest request, HttpResponse response) {
22 request.inputStream.onClosed = () { 20 request.inputStream.onClosed = () {
23 response.outputStream.close(); 21 response.outputStream.close();
24 serverPort.close(); 22 serverPort.close();
25 }; 23 };
26 }; 24 };
27 25
28 server.onError = (Exception e) { 26 server.onError = (Exception e) {
29 Expect.fail("Unexpected error in Http Server: $e"); 27 Expect.fail("Unexpected error in Https Server: $e");
30 }; 28 };
31 29
32 server.listenOn(socket); 30 server.listen(SERVER_ADDRESS,
33 Expect.equals(socket.port, server.port); 31 0,
32 backlog: 5,
33 certificate_name: 'CN=$HOST_NAME');
34 34
35 HttpClient client = new HttpClient(); 35 HttpClient client = new HttpClient();
36 HttpClientConnection conn = client.get("127.0.0.1", socket.port, "/"); 36 HttpClientConnection conn =
37 client.getUrl(new Uri.fromString("https://$HOST_NAME:${server.port}/"));
37 conn.onRequest = (HttpClientRequest request) { 38 conn.onRequest = (HttpClientRequest request) {
38 request.outputStream.close(); 39 request.outputStream.close();
39 }; 40 };
40 ReceivePort clientPort = new ReceivePort(); 41 ReceivePort clientPort = new ReceivePort();
41 conn.onResponse = (HttpClientResponse response) { 42 conn.onResponse = (HttpClientResponse response) {
42 response.inputStream.onClosed = () { 43 response.inputStream.onClosed = () {
43 client.shutdown(); 44 client.shutdown();
44 clientPort.close(); 45 clientPort.close();
45 server.close(); 46 server.close();
46 Expect.throws(() => server.port); 47 Expect.throws(() => server.port);
47 onDone(); 48 onDone();
48 }; 49 };
49 }; 50 };
50 conn.onError = (Exception e) { 51 conn.onError = (Exception e) {
51 Expect.fail("Unexpected error in Http Client: $e"); 52 Expect.fail("Unexpected error in Https Client: $e");
52 }; 53 };
53 }; 54 };
54 55
55 // Test two connection after each other. 56 // Test two connection after each other.
56 test(() { 57 test(() {
57 test(() { 58 test(() {
58 socket.close();
59 }); 59 });
60 }); 60 });
61 } 61 }
62 62
63 void InitializeSSL() {
64 var testPkcertDatabase =
65 new Path.fromNative(new Options().script).directoryPath.append('pkcert/');
66 SecureSocket.setCertificateDatabase(testPkcertDatabase.toNativePath(),
67 'dartdart');
68 }
69
63 void main() { 70 void main() {
71 InitializeSSL();
64 testListenOn(); 72 testListenOn();
65 } 73 }
OLDNEW
« sdk/lib/io/http_impl.dart ('K') | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698