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

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

Issue 11194025: Second round of cleanups for new optional parameter semantics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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) 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 5
6 #import("dart:isolate"); 6 #import("dart:isolate");
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 void testNoBody(int totalConnections) { 9 void testNoBody(int totalConnections) {
10 HttpServer server = new HttpServer(); 10 HttpServer server = new HttpServer();
11 server.onError = (e) => Expect.fail("Unexpected error $e"); 11 server.onError = (e) => Expect.fail("Unexpected error $e");
12 server.listen("127.0.0.1", 0, totalConnections); 12 server.listen("127.0.0.1", 0, backlog: totalConnections);
13 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 13 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
14 response.contentLength = 0; 14 response.contentLength = 0;
15 OutputStream stream = response.outputStream; 15 OutputStream stream = response.outputStream;
16 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 16 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
17 stream.close(); 17 stream.close();
18 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 18 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
19 }; 19 };
20 20
21 int count = 0; 21 int count = 0;
22 HttpClient client = new HttpClient(); 22 HttpClient client = new HttpClient();
(...skipping 12 matching lines...) Expand all
35 client.shutdown(); 35 client.shutdown();
36 server.close(); 36 server.close();
37 } 37 }
38 }; 38 };
39 } 39 }
40 } 40 }
41 41
42 void testBody(int totalConnections) { 42 void testBody(int totalConnections) {
43 HttpServer server = new HttpServer(); 43 HttpServer server = new HttpServer();
44 server.onError = (e) => Expect.fail("Unexpected error $e"); 44 server.onError = (e) => Expect.fail("Unexpected error $e");
45 server.listen("127.0.0.1", 0, totalConnections); 45 server.listen("127.0.0.1", 0, backlog: totalConnections);
46 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 46 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
47 response.contentLength = 2; 47 response.contentLength = 2;
48 OutputStream stream = response.outputStream; 48 OutputStream stream = response.outputStream;
49 stream.writeString("x"); 49 stream.writeString("x");
50 Expect.throws(() => response.contentLength = 3, (e) => e is HttpException); 50 Expect.throws(() => response.contentLength = 3, (e) => e is HttpException);
51 stream.writeString("x"); 51 stream.writeString("x");
52 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 52 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
53 stream.close(); 53 stream.close();
54 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 54 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
55 }; 55 };
(...skipping 19 matching lines...) Expand all
75 client.shutdown(); 75 client.shutdown();
76 server.close(); 76 server.close();
77 } 77 }
78 }; 78 };
79 } 79 }
80 } 80 }
81 81
82 void testHttp10() { 82 void testHttp10() {
83 HttpServer server = new HttpServer(); 83 HttpServer server = new HttpServer();
84 server.onError = (e) => Expect.fail("Unexpected error $e"); 84 server.onError = (e) => Expect.fail("Unexpected error $e");
85 server.listen("127.0.0.1", 0, 5); 85 server.listen("127.0.0.1", 0, backlog: 5);
86 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 86 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
87 OutputStream stream = response.outputStream; 87 OutputStream stream = response.outputStream;
88 Expect.equals("1.0", request.protocolVersion); 88 Expect.equals("1.0", request.protocolVersion);
89 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 89 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
90 response.contentLength = 0; 90 response.contentLength = 0;
91 stream.close(); 91 stream.close();
92 }; 92 };
93 93
94 Socket socket = new Socket("127.0.0.1", server.port); 94 Socket socket = new Socket("127.0.0.1", server.port);
95 socket.onConnect = () { 95 socket.onConnect = () {
96 List<int> buffer = new List<int>(1024); 96 List<int> buffer = new List<int>(1024);
97 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n"); 97 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n");
98 socket.onData = () => socket.readList(buffer, 0, buffer.length); 98 socket.onData = () => socket.readList(buffer, 0, buffer.length);
99 socket.onClosed = () { 99 socket.onClosed = () {
100 socket.close(true); 100 socket.close(true);
101 server.close(); 101 server.close();
102 }; 102 };
103 }; 103 };
104 } 104 }
105 105
106 void main() { 106 void main() {
107 testNoBody(5); 107 testNoBody(5);
108 testBody(5); 108 testBody(5);
109 testHttp10(); 109 testHttp10();
110 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698