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

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

Issue 14690009: Make Completers asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 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) 2013, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:math'; 7 import 'dart:math';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 // Test parsing the request three times delivering the data in 269 // Test parsing the request three times delivering the data in
270 // different chunks. 270 // different chunks.
271 List<int> responseData = response.codeUnits; 271 List<int> responseData = response.codeUnits;
272 testWrite(responseData); 272 testWrite(responseData);
273 testWrite(responseData, 10); 273 testWrite(responseData, 10);
274 testWrite(responseData, 1); 274 testWrite(responseData, 1);
275 } 275 }
276 276
277 static void _testParseInvalidResponse(String response, [bool close = false]) { 277 static void _testParseInvalidResponse(String response, [bool close = false]) {
278 _HttpParser httpParser; 278 void testWrite(List<int> requestData, [int chunkSize = -1]) {
279 bool errorCalled; 279 _HttpParser httpParser = new _HttpParser.responseParser();
280 StreamController controller; 280 StreamController controller = new StreamController();
281 bool errorCalled = false;;
281 282
282 void reset() { 283 if (chunkSize == -1) chunkSize = requestData.length;
283 httpParser = new _HttpParser.responseParser(); 284
284 controller = new StreamController();
285 var port = new ReceivePort(); 285 var port = new ReceivePort();
286 controller.stream.pipe(httpParser); 286 controller.stream.pipe(httpParser);
287 var subscription = httpParser.listen((incoming) { 287 var subscription = httpParser.listen((incoming) {
288 incoming.listen( 288 incoming.listen(
289 (data) {}, 289 (data) {},
290 onError: (e) { 290 onError: (e) {
291 Expect.isFalse(errorCalled); 291 Expect.isFalse(errorCalled);
292 errorCalled = true; 292 errorCalled = true;
293 }); 293 });
294 }); 294 });
295 subscription.onError((e) { 295 subscription.onError((e) {
296 Expect.isFalse(errorCalled); 296 Expect.isFalse(errorCalled);
297 errorCalled = true; 297 errorCalled = true;
298 }); 298 });
299 subscription.onDone(() { 299 subscription.onDone(() {
300 port.close(); 300 port.close();
301 Expect.isTrue(errorCalled); 301 Expect.isTrue(errorCalled);
302 }); 302 });
303
303 errorCalled = false; 304 errorCalled = false;
304 }
305
306 void testWrite(List<int> requestData, [int chunkSize = -1]) {
307 if (chunkSize == -1) chunkSize = requestData.length;
308 reset();
309 for (int pos = 0; 305 for (int pos = 0;
310 pos < requestData.length && !errorCalled; 306 pos < requestData.length && !errorCalled;
311 pos += chunkSize) { 307 pos += chunkSize) {
312 int end = min(requestData.length, pos + chunkSize); 308 int end = min(requestData.length, pos + chunkSize);
313 controller.add(requestData.sublist(pos, end)); 309 controller.add(requestData.sublist(pos, end));
314 } 310 }
315 controller.close(); 311 controller.close();
316 } 312 }
317 313
318 // Test parsing the request three times delivering the data in 314 // Test parsing the request three times delivering the data in
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 0123456789012345678901234567890\r 867 0123456789012345678901234567890\r
872 0\r\n\r\n"""; 868 0\r\n\r\n""";
873 _testParseInvalidResponse(response); 869 _testParseInvalidResponse(response);
874 } 870 }
875 } 871 }
876 872
877 873
878 void main() { 874 void main() {
879 HttpParserTest.runAllTests(); 875 HttpParserTest.runAllTests();
880 } 876 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698