OLD | NEW |
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:async'; | 5 import 'dart:async'; |
6 import 'dart:math'; | 6 import 'dart:math'; |
7 import 'dart:scalarlist'; | 7 import 'dart:scalarlist'; |
8 | 8 |
9 part '../../../sdk/lib/io/http.dart'; | 9 part '../../../sdk/lib/io/http.dart'; |
10 part '../../../sdk/lib/io/http_headers.dart'; | 10 part '../../../sdk/lib/io/http_headers.dart'; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 if (!upgrade) Expect.isTrue(dataEndCalled); | 108 if (!upgrade) Expect.isTrue(dataEndCalled); |
109 if (unparsedLength == 0) { | 109 if (unparsedLength == 0) { |
110 Expect.equals(0, unparsed); | 110 Expect.equals(0, unparsed); |
111 } else { | 111 } else { |
112 Expect.equals(unparsedLength, unparsed); | 112 Expect.equals(unparsedLength, unparsed); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // Test parsing the request three times delivering the data in | 116 // Test parsing the request three times delivering the data in |
117 // different chunks. | 117 // different chunks. |
118 List<int> requestData = request.charCodes; | 118 List<int> requestData = request.codeUnits; |
119 testWrite(requestData); | 119 testWrite(requestData); |
120 testWrite(requestData, 10); | 120 testWrite(requestData, 10); |
121 testWrite(requestData, 1); | 121 testWrite(requestData, 1); |
122 } | 122 } |
123 | 123 |
124 static void _testParseInvalidRequest(String request) { | 124 static void _testParseInvalidRequest(String request) { |
125 _HttpParser httpParser; | 125 _HttpParser httpParser; |
126 bool errorCalled; | 126 bool errorCalled; |
127 | 127 |
128 void reset() { | 128 void reset() { |
(...skipping 17 matching lines...) Expand all Loading... |
146 pos += chunkSize) { | 146 pos += chunkSize) { |
147 int remaining = requestData.length - pos; | 147 int remaining = requestData.length - pos; |
148 int writeLength = min(chunkSize, remaining); | 148 int writeLength = min(chunkSize, remaining); |
149 httpParser.streamData(requestData.getRange(pos, writeLength)); | 149 httpParser.streamData(requestData.getRange(pos, writeLength)); |
150 } | 150 } |
151 Expect.isTrue(errorCalled); | 151 Expect.isTrue(errorCalled); |
152 } | 152 } |
153 | 153 |
154 // Test parsing the request three times delivering the data in | 154 // Test parsing the request three times delivering the data in |
155 // different chunks. | 155 // different chunks. |
156 List<int> requestData = request.charCodes; | 156 List<int> requestData = request.codeUnits; |
157 testWrite(requestData); | 157 testWrite(requestData); |
158 testWrite(requestData, 10); | 158 testWrite(requestData, 10); |
159 testWrite(requestData, 1); | 159 testWrite(requestData, 1); |
160 } | 160 } |
161 | 161 |
162 static void _testParseResponse(String response, | 162 static void _testParseResponse(String response, |
163 int expectedStatusCode, | 163 int expectedStatusCode, |
164 String expectedReasonPhrase, | 164 String expectedReasonPhrase, |
165 {int expectedContentLength: -1, | 165 {int expectedContentLength: -1, |
166 int expectedBytesReceived: 0, | 166 int expectedBytesReceived: 0, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 if (unparsedLength == 0) { | 261 if (unparsedLength == 0) { |
262 Expect.equals(0, unparsed); | 262 Expect.equals(0, unparsed); |
263 } else { | 263 } else { |
264 Expect.equals(unparsedLength, unparsed); | 264 Expect.equals(unparsedLength, unparsed); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 // Test parsing the request three times delivering the data in | 268 // Test parsing the request three times delivering the data in |
269 // different chunks. | 269 // different chunks. |
270 List<int> responseData = response.charCodes; | 270 List<int> responseData = response.codeUnits; |
271 testWrite(responseData); | 271 testWrite(responseData); |
272 testWrite(responseData, 10); | 272 testWrite(responseData, 10); |
273 testWrite(responseData, 1); | 273 testWrite(responseData, 1); |
274 } | 274 } |
275 | 275 |
276 static void _testParseInvalidResponse(String response, [bool close = false]) { | 276 static void _testParseInvalidResponse(String response, [bool close = false]) { |
277 _HttpParser httpParser; | 277 _HttpParser httpParser; |
278 bool errorCalled; | 278 bool errorCalled; |
279 | 279 |
280 void reset() { | 280 void reset() { |
(...skipping 16 matching lines...) Expand all Loading... |
297 int remaining = requestData.length - pos; | 297 int remaining = requestData.length - pos; |
298 int writeLength = min(chunkSize, remaining); | 298 int writeLength = min(chunkSize, remaining); |
299 httpParser.streamData(requestData.getRange(pos, writeLength)); | 299 httpParser.streamData(requestData.getRange(pos, writeLength)); |
300 } | 300 } |
301 if (close) httpParser.streamDone(); | 301 if (close) httpParser.streamDone(); |
302 Expect.isTrue(errorCalled); | 302 Expect.isTrue(errorCalled); |
303 } | 303 } |
304 | 304 |
305 // Test parsing the request three times delivering the data in | 305 // Test parsing the request three times delivering the data in |
306 // different chunks. | 306 // different chunks. |
307 List<int> responseData = response.charCodes; | 307 List<int> responseData = response.codeUnits; |
308 testWrite(responseData); | 308 testWrite(responseData); |
309 testWrite(responseData, 10); | 309 testWrite(responseData, 10); |
310 testWrite(responseData, 1); | 310 testWrite(responseData, 1); |
311 } | 311 } |
312 | 312 |
313 static void testParseRequest() { | 313 static void testParseRequest() { |
314 String request; | 314 String request; |
315 Map headers; | 315 Map headers; |
316 var methods = [ | 316 var methods = [ |
317 // RFC 2616 methods. | 317 // RFC 2616 methods. |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 0123456789012345678901234567890\r | 858 0123456789012345678901234567890\r |
859 0\r\n\r\n"""; | 859 0\r\n\r\n"""; |
860 _testParseInvalidResponse(response); | 860 _testParseInvalidResponse(response); |
861 } | 861 } |
862 } | 862 } |
863 | 863 |
864 | 864 |
865 void main() { | 865 void main() { |
866 HttpParserTest.runAllTests(); | 866 HttpParserTest.runAllTests(); |
867 } | 867 } |
OLD | NEW |