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/http_server_socket_test.dart

Issue 10533078: Enable standalone/io/http_test, splitting it into three separate tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 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 #import("dart:io"); 5 #import("dart:io");
6 #import("dart:isolate"); 6 #import("dart:isolate");
7 7
8 class ExpectedDataOutputStream implements OutputStream { 8 class ExpectedDataOutputStream implements OutputStream {
9 ExpectedDataOutputStream(List<int> this._data, 9 ExpectedDataOutputStream(List<int> this._data,
10 int this._cutoff, 10 int this._cutoff,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 Function _onConnection; 162 Function _onConnection;
163 Function _onError; 163 Function _onError;
164 Set<Socket> _sockets; 164 Set<Socket> _sockets;
165 } 165 }
166 166
167 void testSocketClose() { 167 void testSocketClose() {
168 ServerSocketMock serverSocket = new ServerSocketMock("0.0.0.0", 5432, 5); 168 ServerSocketMock serverSocket = new ServerSocketMock("0.0.0.0", 5432, 5);
169 169
170 HttpServer server = new HttpServer(); 170 HttpServer server = new HttpServer();
171 server.listenOn(serverSocket); 171 server.listenOn(serverSocket);
172 void testContent(String request, 172 void testContent(String requestString,
173 String response, 173 String responseString,
174 [int okayFrom = 0, 174 [int okayFrom = 0,
175 bool expectError = true]) { 175 bool expectError = true]) {
176 // Inner callback to actually run a given setting. 176 // Inner callback to actually run a given setting.
177 void runSettings(int cutoff, 177 void runSettings(int cutoff,
178 bool closeAsError, 178 bool closeAsError,
179 bool expectError) { 179 bool expectError) {
180 server.defaultRequestHandler = 180 server.defaultRequestHandler =
181 (HttpRequest request, HttpResponse response) { 181 (HttpRequest request, HttpResponse response) {
182 request.inputStream.onData = () { 182 request.inputStream.onData = () {
183 }; 183 };
184 request.inputStream.onClosed = () { 184 request.inputStream.onClosed = () {
185 response.outputStream.close(); 185 response.outputStream.close();
186 }; 186 };
187 }; 187 };
188 188
189 if (expectError) { 189 if (expectError) {
190 ReceivePort port = new ReceivePort(); 190 ReceivePort port = new ReceivePort();
191 server.onError = (Exception error) { 191 server.onError = (Exception error) {
192 port.close(); 192 port.close();
193 }; 193 };
194 } else { 194 } else {
195 server.onError = (Exception error) { 195 server.onError = (Exception error) {
196 Expect.fail("An error was not expected: $error"); 196 Expect.fail("An error was not expected: $error");
197 }; 197 };
198 } 198 }
199 199
200 serverSocket.spawnSocket(request, response, cutoff, closeAsError); 200 serverSocket.spawnSocket(requestString, responseString,
201 cutoff, closeAsError);
201 // TODO(ajohnsen): Validate HttpServers number of connections. 202 // TODO(ajohnsen): Validate HttpServers number of connections.
202 } 203 }
203 for (int i = 1; i < response.length; i++) { 204 for (int i = 1; i < responseString.length; i++) {
204 bool _expectError = expectError && i < response.length - okayFrom; 205 bool _expectError = expectError && i < responseString.length - okayFrom;
205 runSettings(i, false, _expectError); 206 runSettings(i, false, _expectError);
206 runSettings(i, true, _expectError); 207 runSettings(i, true, _expectError);
207 } 208 }
208 } 209 }
209 testContent( 210 testContent(
210 "GET / HTTP/1.1\r\nKeep-Alive: False\r\n\r\n", 211 "GET / HTTP/1.1\r\nKeep-Alive: False\r\n\r\n",
211 "HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\nconnection: close" 212 "HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\nconnection: close"
212 "\r\n\r\n0\r\n\r\n"); 213 "\r\n\r\n0\r\n\r\n");
213 214
214 server.close(); 215 server.close();
215 } 216 }
216 217
217 void main() { 218 void main() {
218 testSocketClose(); 219 testSocketClose();
219 } 220 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_server_early_client_close_test.dart ('k') | tests/standalone/io/http_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698