| 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 { |
| 11 static void runAllTests() { | 11 static void runAllTests() { |
| 12 testParseRequest(); | 12 testParseRequest(); |
| 13 testParseResponse(); | 13 testParseResponse(); |
| 14 testParseInvalidRequest(); | 14 testParseInvalidRequest(); |
| 15 testParseInvalidResponse(); | 15 testParseInvalidResponse(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 static void _testParseRequest(String request, | 18 static void _testParseRequest(String request, |
| 19 String expectedMethod, | 19 String expectedMethod, |
| 20 String expectedUri, | 20 String expectedUri, |
| 21 [int expectedContentLength = -1, | 21 {int expectedContentLength: -1, |
| 22 int expectedBytesReceived = 0, | 22 int expectedBytesReceived: 0, |
| 23 Map expectedHeaders = null, | 23 Map expectedHeaders: null, |
| 24 bool chunked = false, | 24 bool chunked: false, |
| 25 bool upgrade = false, | 25 bool upgrade: false, |
| 26 int unparsedLength = 0, | 26 int unparsedLength: 0, |
| 27 bool connectionClose = false, | 27 bool connectionClose: false, |
| 28 String expectedVersion = "1.1"]) { | 28 String expectedVersion: "1.1"}) { |
| 29 _HttpParser httpParser; | 29 _HttpParser httpParser; |
| 30 bool headersCompleteCalled; | 30 bool headersCompleteCalled; |
| 31 bool dataEndCalled; | 31 bool dataEndCalled; |
| 32 String method; | 32 String method; |
| 33 String uri; | 33 String uri; |
| 34 String version; | 34 String version; |
| 35 Map headers; | 35 Map headers; |
| 36 int contentLength; | 36 int contentLength; |
| 37 int bytesReceived; | 37 int bytesReceived; |
| 38 | 38 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, |
| 157 Map expectedHeaders = null, | 157 Map expectedHeaders: null, |
| 158 bool chunked = false, | 158 bool chunked: false, |
| 159 bool close = false, | 159 bool close: false, |
| 160 String responseToMethod = null, | 160 String responseToMethod: null, |
| 161 bool connectionClose = false, | 161 bool connectionClose: false, |
| 162 bool upgrade = false, | 162 bool upgrade: false, |
| 163 int unparsedLength = 0, | 163 int unparsedLength: 0, |
| 164 String expectedVersion = "1.1"]) { | 164 String expectedVersion: "1.1"}) { |
| 165 _HttpParser httpParser; | 165 _HttpParser httpParser; |
| 166 bool headersCompleteCalled; | 166 bool headersCompleteCalled; |
| 167 bool dataEndCalled; | 167 bool dataEndCalled; |
| 168 bool dataEndClose; | 168 bool dataEndClose; |
| 169 int statusCode; | 169 int statusCode; |
| 170 String reasonPhrase; | 170 String reasonPhrase; |
| 171 String version; | 171 String version; |
| 172 Map headers; | 172 Map headers; |
| 173 int contentLength; | 173 int contentLength; |
| 174 int bytesReceived; | 174 int bytesReceived; |
| (...skipping 662 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 |