| 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 part '../../../sdk/lib/io/http_parser.dart'; | 8 part '../../../sdk/lib/io/http_parser.dart'; |
| 9 | 9 |
| 10 class HttpParserTest { | 10 class HttpParserTest { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 80 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 81 if (chunkSize == -1) chunkSize = requestData.length; | 81 if (chunkSize == -1) chunkSize = requestData.length; |
| 82 reset(); | 82 reset(); |
| 83 int written = 0; | 83 int written = 0; |
| 84 int unparsed; | 84 int unparsed; |
| 85 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 85 for (int pos = 0; pos < requestData.length; pos += chunkSize) { |
| 86 int remaining = requestData.length - pos; | 86 int remaining = requestData.length - pos; |
| 87 int writeLength = min(chunkSize, remaining); | 87 int writeLength = min(chunkSize, remaining); |
| 88 written += writeLength; | 88 written += writeLength; |
| 89 int parsed = httpParser.writeList(requestData, pos, writeLength); | 89 httpParser.writeList(requestData, pos, writeLength); |
| 90 unparsed = writeLength - parsed; | 90 unparsed = httpParser.readUnparsedData().length; |
| 91 if (httpParser.upgrade) { | 91 if (httpParser.upgrade) { |
| 92 unparsed += requestData.length - written; | 92 unparsed += requestData.length - written; |
| 93 break; | 93 break; |
| 94 } else { | 94 } else { |
| 95 Expect.equals(0, unparsed); | 95 Expect.equals(0, unparsed); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 Expect.equals(expectedMethod, method); | 98 Expect.equals(expectedMethod, method); |
| 99 Expect.equals(expectedUri, uri); | 99 Expect.equals(expectedUri, uri); |
| 100 Expect.equals(expectedVersion, version); | 100 Expect.equals(expectedVersion, version); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 126 httpParser.error = (e) { | 126 httpParser.error = (e) { |
| 127 errorCalled = true; | 127 errorCalled = true; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 errorCalled = false; | 130 errorCalled = false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 133 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 134 if (chunkSize == -1) chunkSize = requestData.length; | 134 if (chunkSize == -1) chunkSize = requestData.length; |
| 135 reset(); | 135 reset(); |
| 136 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 136 for (int pos = 0; |
| 137 pos < requestData.length && !errorCalled; |
| 138 pos += chunkSize) { |
| 137 int remaining = requestData.length - pos; | 139 int remaining = requestData.length - pos; |
| 138 int writeLength = min(chunkSize, remaining); | 140 int writeLength = min(chunkSize, remaining); |
| 139 httpParser.writeList(requestData, pos, writeLength); | 141 httpParser.writeList(requestData, pos, writeLength); |
| 140 } | 142 } |
| 141 Expect.isTrue(errorCalled); | 143 Expect.isTrue(errorCalled); |
| 142 } | 144 } |
| 143 | 145 |
| 144 // Test parsing the request three times delivering the data in | 146 // Test parsing the request three times delivering the data in |
| 145 // different chunks. | 147 // different chunks. |
| 146 List<int> requestData = request.charCodes; | 148 List<int> requestData = request.charCodes; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 225 |
| 224 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 226 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 225 if (chunkSize == -1) chunkSize = requestData.length; | 227 if (chunkSize == -1) chunkSize = requestData.length; |
| 226 reset(); | 228 reset(); |
| 227 int written = 0; | 229 int written = 0; |
| 228 int unparsed; | 230 int unparsed; |
| 229 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 231 for (int pos = 0; pos < requestData.length; pos += chunkSize) { |
| 230 int remaining = requestData.length - pos; | 232 int remaining = requestData.length - pos; |
| 231 int writeLength = min(chunkSize, remaining); | 233 int writeLength = min(chunkSize, remaining); |
| 232 written += writeLength; | 234 written += writeLength; |
| 233 int parsed = httpParser.writeList(requestData, pos, writeLength); | 235 httpParser.writeList(requestData, pos, writeLength); |
| 234 unparsed = writeLength - parsed; | 236 unparsed = httpParser.readUnparsedData().length; |
| 235 if (httpParser.upgrade) { | 237 if (httpParser.upgrade) { |
| 236 unparsed += requestData.length - written; | 238 unparsed += requestData.length - written; |
| 237 break; | 239 break; |
| 238 } else { | 240 } else { |
| 239 Expect.equals(0, unparsed); | 241 Expect.equals(0, unparsed); |
| 240 } | 242 } |
| 241 } | 243 } |
| 242 if (close) httpParser.connectionClosed(); | 244 if (close) httpParser.connectionClosed(); |
| 243 Expect.equals(expectedVersion, version); | 245 Expect.equals(expectedVersion, version); |
| 244 Expect.equals(expectedStatusCode, statusCode); | 246 Expect.equals(expectedStatusCode, statusCode); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 273 httpParser = new _HttpParser(); | 275 httpParser = new _HttpParser(); |
| 274 httpParser.requestStart = (m, u) => Expect.fail("Expected response"); | 276 httpParser.requestStart = (m, u) => Expect.fail("Expected response"); |
| 275 httpParser.error = (e) => errorCalled = true; | 277 httpParser.error = (e) => errorCalled = true; |
| 276 | 278 |
| 277 errorCalled = false; | 279 errorCalled = false; |
| 278 } | 280 } |
| 279 | 281 |
| 280 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 282 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 281 if (chunkSize == -1) chunkSize = requestData.length; | 283 if (chunkSize == -1) chunkSize = requestData.length; |
| 282 reset(); | 284 reset(); |
| 283 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 285 for (int pos = 0; |
| 286 pos < requestData.length && !errorCalled; |
| 287 pos += chunkSize) { |
| 284 int remaining = requestData.length - pos; | 288 int remaining = requestData.length - pos; |
| 285 int writeLength = min(chunkSize, remaining); | 289 int writeLength = min(chunkSize, remaining); |
| 286 httpParser.writeList(requestData, pos, writeLength); | 290 httpParser.writeList(requestData, pos, writeLength); |
| 287 } | 291 } |
| 288 if (close) httpParser.connectionClosed(); | 292 if (close) httpParser.connectionClosed(); |
| 289 Expect.isTrue(errorCalled); | 293 Expect.isTrue(errorCalled); |
| 290 } | 294 } |
| 291 | 295 |
| 292 // Test parsing the request three times delivering the data in | 296 // Test parsing the request three times delivering the data in |
| 293 // different chunks. | 297 // different chunks. |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 0123456789012345678901234567890\r | 841 0123456789012345678901234567890\r |
| 838 0\r\n\r\n"""; | 842 0\r\n\r\n"""; |
| 839 _testParseInvalidResponse(response); | 843 _testParseInvalidResponse(response); |
| 840 } | 844 } |
| 841 } | 845 } |
| 842 | 846 |
| 843 | 847 |
| 844 void main() { | 848 void main() { |
| 845 HttpParserTest.runAllTests(); | 849 HttpParserTest.runAllTests(); |
| 846 } | 850 } |
| OLD | NEW |