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:math'); | 5 #import('dart:math'); |
6 #import('dart:scalarlist'); | 6 #import('dart:scalarlist'); |
7 | 7 |
8 #source("../../../runtime/bin/http_parser.dart"); | 8 #source("../../../runtime/bin/http_parser.dart"); |
9 | 9 |
10 class HttpParserTest { | 10 class HttpParserTest { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (!upgrade) Expect.isTrue(dataEndCalled); | 103 if (!upgrade) Expect.isTrue(dataEndCalled); |
104 if (unparsedLength == 0) { | 104 if (unparsedLength == 0) { |
105 Expect.equals(0, unparsed); | 105 Expect.equals(0, unparsed); |
106 } else { | 106 } else { |
107 Expect.equals(unparsedLength, unparsed); | 107 Expect.equals(unparsedLength, unparsed); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 // Test parsing the request three times delivering the data in | 111 // Test parsing the request three times delivering the data in |
112 // different chunks. | 112 // different chunks. |
113 List<int> requestData = request.charCodes(); | 113 List<int> requestData = request.charCodes; |
114 testWrite(requestData); | 114 testWrite(requestData); |
115 testWrite(requestData, 10); | 115 testWrite(requestData, 10); |
116 testWrite(requestData, 1); | 116 testWrite(requestData, 1); |
117 } | 117 } |
118 | 118 |
119 static void _testParseInvalidRequest(String request) { | 119 static void _testParseInvalidRequest(String request) { |
120 _HttpParser httpParser; | 120 _HttpParser httpParser; |
121 bool errorCalled; | 121 bool errorCalled; |
122 | 122 |
123 void reset() { | 123 void reset() { |
(...skipping 12 matching lines...) Expand all Loading... |
136 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 136 for (int pos = 0; pos < requestData.length; pos += chunkSize) { |
137 int remaining = requestData.length - pos; | 137 int remaining = requestData.length - pos; |
138 int writeLength = min(chunkSize, remaining); | 138 int writeLength = min(chunkSize, remaining); |
139 httpParser.writeList(requestData, pos, writeLength); | 139 httpParser.writeList(requestData, pos, writeLength); |
140 } | 140 } |
141 Expect.isTrue(errorCalled); | 141 Expect.isTrue(errorCalled); |
142 } | 142 } |
143 | 143 |
144 // Test parsing the request three times delivering the data in | 144 // Test parsing the request three times delivering the data in |
145 // different chunks. | 145 // different chunks. |
146 List<int> requestData = request.charCodes(); | 146 List<int> requestData = request.charCodes; |
147 testWrite(requestData); | 147 testWrite(requestData); |
148 testWrite(requestData, 10); | 148 testWrite(requestData, 10); |
149 testWrite(requestData, 1); | 149 testWrite(requestData, 1); |
150 } | 150 } |
151 | 151 |
152 static void _testParseResponse(String response, | 152 static void _testParseResponse(String response, |
153 int expectedStatusCode, | 153 int expectedStatusCode, |
154 String expectedReasonPhrase, | 154 String expectedReasonPhrase, |
155 {int expectedContentLength: -1, | 155 {int expectedContentLength: -1, |
156 int expectedBytesReceived: 0, | 156 int expectedBytesReceived: 0, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 if (unparsedLength == 0) { | 253 if (unparsedLength == 0) { |
254 Expect.equals(0, unparsed); | 254 Expect.equals(0, unparsed); |
255 } else { | 255 } else { |
256 Expect.equals(unparsedLength, unparsed); | 256 Expect.equals(unparsedLength, unparsed); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 // Test parsing the request three times delivering the data in | 260 // Test parsing the request three times delivering the data in |
261 // different chunks. | 261 // different chunks. |
262 List<int> responseData = response.charCodes(); | 262 List<int> responseData = response.charCodes; |
263 testWrite(responseData); | 263 testWrite(responseData); |
264 testWrite(responseData, 10); | 264 testWrite(responseData, 10); |
265 testWrite(responseData, 1); | 265 testWrite(responseData, 1); |
266 } | 266 } |
267 | 267 |
268 static void _testParseInvalidResponse(String response, [bool close = false]) { | 268 static void _testParseInvalidResponse(String response, [bool close = false]) { |
269 _HttpParser httpParser; | 269 _HttpParser httpParser; |
270 bool errorCalled; | 270 bool errorCalled; |
271 | 271 |
272 void reset() { | 272 void reset() { |
(...skipping 11 matching lines...) Expand all Loading... |
284 int remaining = requestData.length - pos; | 284 int remaining = requestData.length - pos; |
285 int writeLength = min(chunkSize, remaining); | 285 int writeLength = min(chunkSize, remaining); |
286 httpParser.writeList(requestData, pos, writeLength); | 286 httpParser.writeList(requestData, pos, writeLength); |
287 } | 287 } |
288 if (close) httpParser.connectionClosed(); | 288 if (close) httpParser.connectionClosed(); |
289 Expect.isTrue(errorCalled); | 289 Expect.isTrue(errorCalled); |
290 } | 290 } |
291 | 291 |
292 // Test parsing the request three times delivering the data in | 292 // Test parsing the request three times delivering the data in |
293 // different chunks. | 293 // different chunks. |
294 List<int> responseData = response.charCodes(); | 294 List<int> responseData = response.charCodes; |
295 testWrite(responseData); | 295 testWrite(responseData); |
296 testWrite(responseData, 10); | 296 testWrite(responseData, 10); |
297 testWrite(responseData, 1); | 297 testWrite(responseData, 1); |
298 } | 298 } |
299 | 299 |
300 static void testParseRequest() { | 300 static void testParseRequest() { |
301 String request; | 301 String request; |
302 Map headers; | 302 Map headers; |
303 var methods = [ | 303 var methods = [ |
304 // RFC 2616 methods. | 304 // RFC 2616 methods. |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 0123456789012345678901234567890\r | 837 0123456789012345678901234567890\r |
838 0\r\n\r\n"""; | 838 0\r\n\r\n"""; |
839 _testParseInvalidResponse(response); | 839 _testParseInvalidResponse(response); |
840 } | 840 } |
841 } | 841 } |
842 | 842 |
843 | 843 |
844 void main() { | 844 void main() { |
845 HttpParserTest.runAllTests(); | 845 HttpParserTest.runAllTests(); |
846 } | 846 } |
OLD | NEW |