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

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

Issue 59673006: Use typed-data views for incoming http data. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « sdk/lib/io/http_parser.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) 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:collection'; 10 import 'dart:collection';
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 reset(); 117 reset();
118 for (int pos = 0; pos < requestData.length; pos += chunkSize) { 118 for (int pos = 0; pos < requestData.length; pos += chunkSize) {
119 int end = min(requestData.length, pos + chunkSize); 119 int end = min(requestData.length, pos + chunkSize);
120 controller.add(requestData.sublist(pos, end)); 120 controller.add(requestData.sublist(pos, end));
121 } 121 }
122 controller.close(); 122 controller.close();
123 } 123 }
124 124
125 // Test parsing the request three times delivering the data in 125 // Test parsing the request three times delivering the data in
126 // different chunks. 126 // different chunks.
127 List<int> requestData = request.codeUnits; 127 List<int> requestData = new Uint8List.fromList(request.codeUnits);
128 testWrite(requestData); 128 testWrite(requestData);
129 testWrite(requestData, 10); 129 testWrite(requestData, 10);
130 testWrite(requestData, 1); 130 testWrite(requestData, 1);
131 } 131 }
132 132
133 static void _testParseInvalidRequest(String request) { 133 static void _testParseInvalidRequest(String request) {
134 _HttpParser httpParser; 134 _HttpParser httpParser;
135 bool errorCalled; 135 bool errorCalled;
136 StreamController controller; 136 StreamController controller;
137 137
(...skipping 22 matching lines...) Expand all
160 pos < requestData.length && !errorCalled; 160 pos < requestData.length && !errorCalled;
161 pos += chunkSize) { 161 pos += chunkSize) {
162 int end = min(requestData.length, pos + chunkSize); 162 int end = min(requestData.length, pos + chunkSize);
163 controller.add(requestData.sublist(pos, end)); 163 controller.add(requestData.sublist(pos, end));
164 } 164 }
165 controller.close(); 165 controller.close();
166 } 166 }
167 167
168 // Test parsing the request three times delivering the data in 168 // Test parsing the request three times delivering the data in
169 // different chunks. 169 // different chunks.
170 List<int> requestData = request.codeUnits; 170 List<int> requestData = new Uint8List.fromList(request.codeUnits);
171 testWrite(requestData); 171 testWrite(requestData);
172 testWrite(requestData, 10); 172 testWrite(requestData, 10);
173 testWrite(requestData, 1); 173 testWrite(requestData, 1);
174 } 174 }
175 175
176 static void _testParseResponse(String response, 176 static void _testParseResponse(String response,
177 int expectedStatusCode, 177 int expectedStatusCode,
178 String expectedReasonPhrase, 178 String expectedReasonPhrase,
179 {int expectedTransferLength: 0, 179 {int expectedTransferLength: 0,
180 int expectedBytesReceived: 0, 180 int expectedBytesReceived: 0,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 for (int pos = 0; pos < requestData.length; pos += chunkSize) { 266 for (int pos = 0; pos < requestData.length; pos += chunkSize) {
267 int end = min(requestData.length, pos + chunkSize); 267 int end = min(requestData.length, pos + chunkSize);
268 controller.add(requestData.sublist(pos, end)); 268 controller.add(requestData.sublist(pos, end));
269 269
270 } 270 }
271 if (close) controller.close(); 271 if (close) controller.close();
272 } 272 }
273 273
274 // Test parsing the request three times delivering the data in 274 // Test parsing the request three times delivering the data in
275 // different chunks. 275 // different chunks.
276 List<int> responseData = response.codeUnits; 276 List<int> responseData = new Uint8List.fromList(response.codeUnits);
277 testWrite(responseData); 277 testWrite(responseData);
278 testWrite(responseData, 10); 278 testWrite(responseData, 10);
279 testWrite(responseData, 1); 279 testWrite(responseData, 1);
280 } 280 }
281 281
282 static void _testParseInvalidResponse(String response, [bool close = false]) { 282 static void _testParseInvalidResponse(String response, [bool close = false]) {
283 void testWrite(List<int> requestData, [int chunkSize = -1]) { 283 void testWrite(List<int> requestData, [int chunkSize = -1]) {
284 _HttpParser httpParser = new _HttpParser.responseParser(); 284 _HttpParser httpParser = new _HttpParser.responseParser();
285 StreamController controller = new StreamController(sync: true); 285 StreamController controller = new StreamController(sync: true);
286 bool errorCalled = false;; 286 bool errorCalled = false;;
(...skipping 24 matching lines...) Expand all
311 pos < requestData.length && !errorCalled; 311 pos < requestData.length && !errorCalled;
312 pos += chunkSize) { 312 pos += chunkSize) {
313 int end = min(requestData.length, pos + chunkSize); 313 int end = min(requestData.length, pos + chunkSize);
314 controller.add(requestData.sublist(pos, end)); 314 controller.add(requestData.sublist(pos, end));
315 } 315 }
316 controller.close(); 316 controller.close();
317 } 317 }
318 318
319 // Test parsing the request three times delivering the data in 319 // Test parsing the request three times delivering the data in
320 // different chunks. 320 // different chunks.
321 List<int> responseData = response.codeUnits; 321 List<int> responseData = new Uint8List.fromList(response.codeUnits);
322 testWrite(responseData); 322 testWrite(responseData);
323 testWrite(responseData, 10); 323 testWrite(responseData, 10);
324 testWrite(responseData, 1); 324 testWrite(responseData, 1);
325 } 325 }
326 326
327 static void testParseRequest() { 327 static void testParseRequest() {
328 String request; 328 String request;
329 Map headers; 329 Map headers;
330 var methods = [ 330 var methods = [
331 // RFC 2616 methods. 331 // RFC 2616 methods.
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 0123456789012345678901234567890\r 872 0123456789012345678901234567890\r
873 0\r\n\r\n"""; 873 0\r\n\r\n""";
874 _testParseInvalidResponse(response); 874 _testParseInvalidResponse(response);
875 } 875 }
876 } 876 }
877 877
878 878
879 void main() { 879 void main() {
880 HttpParserTest.runAllTests(); 880 HttpParserTest.runAllTests();
881 } 881 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698