| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "net/http/http_chunked_decoder.h" | 5 #include "net/http/http_chunked_decoder.h" | 
| 6 | 6 | 
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" | 
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" | 
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" | 
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" | 
| 11 | 11 | 
| 12 namespace net { | 12 namespace net { | 
| 13 | 13 | 
| 14 namespace { | 14 namespace { | 
| 15 | 15 | 
| 16 typedef testing::Test HttpChunkedDecoderTest; | 16 typedef testing::Test HttpChunkedDecoderTest; | 
| 17 | 17 | 
| 18 void RunTest(const char* inputs[], size_t num_inputs, | 18 void RunTest(const char* const inputs[], | 
|  | 19              size_t num_inputs, | 
| 19              const char* expected_output, | 20              const char* expected_output, | 
| 20              bool expected_eof, | 21              bool expected_eof, | 
| 21              int bytes_after_eof) { | 22              int bytes_after_eof) { | 
| 22   HttpChunkedDecoder decoder; | 23   HttpChunkedDecoder decoder; | 
| 23   EXPECT_FALSE(decoder.reached_eof()); | 24   EXPECT_FALSE(decoder.reached_eof()); | 
| 24 | 25 | 
| 25   std::string result; | 26   std::string result; | 
| 26 | 27 | 
| 27   for (size_t i = 0; i < num_inputs; ++i) { | 28   for (size_t i = 0; i < num_inputs; ++i) { | 
| 28     std::string input = inputs[i]; | 29     std::string input = inputs[i]; | 
| 29     int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); | 30     int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); | 
| 30     EXPECT_GE(n, 0); | 31     EXPECT_GE(n, 0); | 
| 31     if (n > 0) | 32     if (n > 0) | 
| 32       result.append(input.data(), n); | 33       result.append(input.data(), n); | 
| 33   } | 34   } | 
| 34 | 35 | 
| 35   EXPECT_EQ(expected_output, result); | 36   EXPECT_EQ(expected_output, result); | 
| 36   EXPECT_EQ(expected_eof, decoder.reached_eof()); | 37   EXPECT_EQ(expected_eof, decoder.reached_eof()); | 
| 37   EXPECT_EQ(bytes_after_eof, decoder.bytes_after_eof()); | 38   EXPECT_EQ(bytes_after_eof, decoder.bytes_after_eof()); | 
| 38 } | 39 } | 
| 39 | 40 | 
| 40 // Feed the inputs to the decoder, until it returns an error. | 41 // Feed the inputs to the decoder, until it returns an error. | 
| 41 void RunTestUntilFailure(const char* inputs[], | 42 void RunTestUntilFailure(const char* const inputs[], | 
| 42                          size_t num_inputs, | 43                          size_t num_inputs, | 
| 43                          size_t fail_index) { | 44                          size_t fail_index) { | 
| 44   HttpChunkedDecoder decoder; | 45   HttpChunkedDecoder decoder; | 
| 45   EXPECT_FALSE(decoder.reached_eof()); | 46   EXPECT_FALSE(decoder.reached_eof()); | 
| 46 | 47 | 
| 47   for (size_t i = 0; i < num_inputs; ++i) { | 48   for (size_t i = 0; i < num_inputs; ++i) { | 
| 48     std::string input = inputs[i]; | 49     std::string input = inputs[i]; | 
| 49     int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); | 50     int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); | 
| 50     if (n < 0) { | 51     if (n < 0) { | 
| 51       EXPECT_EQ(ERR_INVALID_CHUNKED_ENCODING, n); | 52       EXPECT_EQ(ERR_INVALID_CHUNKED_ENCODING, n); | 
| 52       EXPECT_EQ(fail_index, i); | 53       EXPECT_EQ(fail_index, i); | 
| 53       return; | 54       return; | 
| 54     } | 55     } | 
| 55   } | 56   } | 
| 56   FAIL();  // We should have failed on the |fail_index| iteration of the loop. | 57   FAIL();  // We should have failed on the |fail_index| iteration of the loop. | 
| 57 } | 58 } | 
| 58 | 59 | 
| 59 TEST(HttpChunkedDecoderTest, Basic) { | 60 TEST(HttpChunkedDecoderTest, Basic) { | 
| 60   const char* inputs[] = { | 61   const char* const inputs[] = { | 
| 61     "B\r\nhello hello\r\n0\r\n\r\n" | 62     "B\r\nhello hello\r\n0\r\n\r\n" | 
| 62   }; | 63   }; | 
| 63   RunTest(inputs, arraysize(inputs), "hello hello", true, 0); | 64   RunTest(inputs, arraysize(inputs), "hello hello", true, 0); | 
| 64 } | 65 } | 
| 65 | 66 | 
| 66 TEST(HttpChunkedDecoderTest, OneChunk) { | 67 TEST(HttpChunkedDecoderTest, OneChunk) { | 
| 67   const char* inputs[] = { | 68   const char* const inputs[] = { | 
| 68     "5\r\nhello\r\n" | 69     "5\r\nhello\r\n" | 
| 69   }; | 70   }; | 
| 70   RunTest(inputs, arraysize(inputs), "hello", false, 0); | 71   RunTest(inputs, arraysize(inputs), "hello", false, 0); | 
| 71 } | 72 } | 
| 72 | 73 | 
| 73 TEST(HttpChunkedDecoderTest, Typical) { | 74 TEST(HttpChunkedDecoderTest, Typical) { | 
| 74   const char* inputs[] = { | 75   const char* const inputs[] = { | 
| 75     "5\r\nhello\r\n", | 76     "5\r\nhello\r\n", | 
| 76     "1\r\n \r\n", | 77     "1\r\n \r\n", | 
| 77     "5\r\nworld\r\n", | 78     "5\r\nworld\r\n", | 
| 78     "0\r\n\r\n" | 79     "0\r\n\r\n" | 
| 79   }; | 80   }; | 
| 80   RunTest(inputs, arraysize(inputs), "hello world", true, 0); | 81   RunTest(inputs, arraysize(inputs), "hello world", true, 0); | 
| 81 } | 82 } | 
| 82 | 83 | 
| 83 TEST(HttpChunkedDecoderTest, Incremental) { | 84 TEST(HttpChunkedDecoderTest, Incremental) { | 
| 84   const char* inputs[] = { | 85   const char* const inputs[] = { | 
| 85     "5", | 86     "5", | 
| 86     "\r", | 87     "\r", | 
| 87     "\n", | 88     "\n", | 
| 88     "hello", | 89     "hello", | 
| 89     "\r", | 90     "\r", | 
| 90     "\n", | 91     "\n", | 
| 91     "0", | 92     "0", | 
| 92     "\r", | 93     "\r", | 
| 93     "\n", | 94     "\n", | 
| 94     "\r", | 95     "\r", | 
| 95     "\n" | 96     "\n" | 
| 96   }; | 97   }; | 
| 97   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 98   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 
| 98 } | 99 } | 
| 99 | 100 | 
| 100 // Same as above, but group carriage returns with previous input. | 101 // Same as above, but group carriage returns with previous input. | 
| 101 TEST(HttpChunkedDecoderTest, Incremental2) { | 102 TEST(HttpChunkedDecoderTest, Incremental2) { | 
| 102   const char* inputs[] = { | 103   const char* const inputs[] = { | 
| 103     "5\r", | 104     "5\r", | 
| 104     "\n", | 105     "\n", | 
| 105     "hello\r", | 106     "hello\r", | 
| 106     "\n", | 107     "\n", | 
| 107     "0\r", | 108     "0\r", | 
| 108     "\n\r", | 109     "\n\r", | 
| 109     "\n" | 110     "\n" | 
| 110   }; | 111   }; | 
| 111   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 112   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 
| 112 } | 113 } | 
| 113 | 114 | 
| 114 TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) { | 115 TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) { | 
| 115   // Compatibility: [RFC 2616 - Invalid] | 116   // Compatibility: [RFC 2616 - Invalid] | 
| 116   // {Firefox3} - Valid | 117   // {Firefox3} - Valid | 
| 117   // {IE7, Safari3.1, Opera9.51} - Invalid | 118   // {IE7, Safari3.1, Opera9.51} - Invalid | 
| 118   const char* inputs[] = { | 119   const char* const inputs[] = { | 
| 119     "5\nhello\n", | 120     "5\nhello\n", | 
| 120     "1\n \n", | 121     "1\n \n", | 
| 121     "5\nworld\n", | 122     "5\nworld\n", | 
| 122     "0\n\n" | 123     "0\n\n" | 
| 123   }; | 124   }; | 
| 124   RunTest(inputs, arraysize(inputs), "hello world", true, 0); | 125   RunTest(inputs, arraysize(inputs), "hello world", true, 0); | 
| 125 } | 126 } | 
| 126 | 127 | 
| 127 TEST(HttpChunkedDecoderTest, Extensions) { | 128 TEST(HttpChunkedDecoderTest, Extensions) { | 
| 128   const char* inputs[] = { | 129   const char* const inputs[] = { | 
| 129     "5;x=0\r\nhello\r\n", | 130     "5;x=0\r\nhello\r\n", | 
| 130     "0;y=\"2 \"\r\n\r\n" | 131     "0;y=\"2 \"\r\n\r\n" | 
| 131   }; | 132   }; | 
| 132   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 133   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 
| 133 } | 134 } | 
| 134 | 135 | 
| 135 TEST(HttpChunkedDecoderTest, Trailers) { | 136 TEST(HttpChunkedDecoderTest, Trailers) { | 
| 136   const char* inputs[] = { | 137   const char* const inputs[] = { | 
| 137     "5\r\nhello\r\n", | 138     "5\r\nhello\r\n", | 
| 138     "0\r\n", | 139     "0\r\n", | 
| 139     "Foo: 1\r\n", | 140     "Foo: 1\r\n", | 
| 140     "Bar: 2\r\n", | 141     "Bar: 2\r\n", | 
| 141     "\r\n" | 142     "\r\n" | 
| 142   }; | 143   }; | 
| 143   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 144   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 
| 144 } | 145 } | 
| 145 | 146 | 
| 146 TEST(HttpChunkedDecoderTest, TrailersUnfinished) { | 147 TEST(HttpChunkedDecoderTest, TrailersUnfinished) { | 
| 147   const char* inputs[] = { | 148   const char* const inputs[] = { | 
| 148     "5\r\nhello\r\n", | 149     "5\r\nhello\r\n", | 
| 149     "0\r\n", | 150     "0\r\n", | 
| 150     "Foo: 1\r\n" | 151     "Foo: 1\r\n" | 
| 151   }; | 152   }; | 
| 152   RunTest(inputs, arraysize(inputs), "hello", false, 0); | 153   RunTest(inputs, arraysize(inputs), "hello", false, 0); | 
| 153 } | 154 } | 
| 154 | 155 | 
| 155 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TooBig) { | 156 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TooBig) { | 
| 156   const char* inputs[] = { | 157   const char* const inputs[] = { | 
| 157     // This chunked body is not terminated. | 158     // This chunked body is not terminated. | 
| 158     // However we will fail decoding because the chunk-size | 159     // However we will fail decoding because the chunk-size | 
| 159     // number is larger than we can handle. | 160     // number is larger than we can handle. | 
| 160     "48469410265455838241\r\nhello\r\n", | 161     "48469410265455838241\r\nhello\r\n", | 
| 161     "0\r\n\r\n" | 162     "0\r\n\r\n" | 
| 162   }; | 163   }; | 
| 163   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 164   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 164 } | 165 } | 
| 165 | 166 | 
| 166 TEST(HttpChunkedDecoderTest, InvalidChunkSize_0X) { | 167 TEST(HttpChunkedDecoderTest, InvalidChunkSize_0X) { | 
| 167   const char* inputs[] = { | 168   const char* const inputs[] = { | 
| 168     // Compatibility [RFC 2616 - Invalid]: | 169     // Compatibility [RFC 2616 - Invalid]: | 
| 169     // {Safari3.1, IE7} - Invalid | 170     // {Safari3.1, IE7} - Invalid | 
| 170     // {Firefox3, Opera 9.51} - Valid | 171     // {Firefox3, Opera 9.51} - Valid | 
| 171     "0x5\r\nhello\r\n", | 172     "0x5\r\nhello\r\n", | 
| 172     "0\r\n\r\n" | 173     "0\r\n\r\n" | 
| 173   }; | 174   }; | 
| 174   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 175   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 175 } | 176 } | 
| 176 | 177 | 
| 177 TEST(HttpChunkedDecoderTest, ChunkSize_TrailingSpace) { | 178 TEST(HttpChunkedDecoderTest, ChunkSize_TrailingSpace) { | 
| 178   const char* inputs[] = { | 179   const char* const inputs[] = { | 
| 179     // Compatibility [RFC 2616 - Invalid]: | 180     // Compatibility [RFC 2616 - Invalid]: | 
| 180     // {IE7, Safari3.1, Firefox3, Opera 9.51} - Valid | 181     // {IE7, Safari3.1, Firefox3, Opera 9.51} - Valid | 
| 181     // | 182     // | 
| 182     // At least yahoo.com depends on this being valid. | 183     // At least yahoo.com depends on this being valid. | 
| 183     "5      \r\nhello\r\n", | 184     "5      \r\nhello\r\n", | 
| 184     "0\r\n\r\n" | 185     "0\r\n\r\n" | 
| 185   }; | 186   }; | 
| 186   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 187   RunTest(inputs, arraysize(inputs), "hello", true, 0); | 
| 187 } | 188 } | 
| 188 | 189 | 
| 189 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingTab) { | 190 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingTab) { | 
| 190   const char* inputs[] = { | 191   const char* const inputs[] = { | 
| 191     // Compatibility [RFC 2616 - Invalid]: | 192     // Compatibility [RFC 2616 - Invalid]: | 
| 192     // {IE7, Safari3.1, Firefox3, Opera 9.51} - Valid | 193     // {IE7, Safari3.1, Firefox3, Opera 9.51} - Valid | 
| 193     "5\t\r\nhello\r\n", | 194     "5\t\r\nhello\r\n", | 
| 194     "0\r\n\r\n" | 195     "0\r\n\r\n" | 
| 195   }; | 196   }; | 
| 196   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 197   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 197 } | 198 } | 
| 198 | 199 | 
| 199 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingFormFeed) { | 200 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingFormFeed) { | 
| 200   const char* inputs[] = { | 201   const char* const inputs[] = { | 
| 201     // Compatibility [RFC 2616- Invalid]: | 202     // Compatibility [RFC 2616- Invalid]: | 
| 202     // {Safari3.1} - Invalid | 203     // {Safari3.1} - Invalid | 
| 203     // {IE7, Firefox3, Opera 9.51} - Valid | 204     // {IE7, Firefox3, Opera 9.51} - Valid | 
| 204     "5\f\r\nhello\r\n", | 205     "5\f\r\nhello\r\n", | 
| 205     "0\r\n\r\n" | 206     "0\r\n\r\n" | 
| 206   }; | 207   }; | 
| 207   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 208   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 208 } | 209 } | 
| 209 | 210 | 
| 210 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingVerticalTab) { | 211 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingVerticalTab) { | 
| 211   const char* inputs[] = { | 212   const char* const inputs[] = { | 
| 212     // Compatibility [RFC 2616 - Invalid]: | 213     // Compatibility [RFC 2616 - Invalid]: | 
| 213     // {Safari 3.1} - Invalid | 214     // {Safari 3.1} - Invalid | 
| 214     // {IE7, Firefox3, Opera 9.51} - Valid | 215     // {IE7, Firefox3, Opera 9.51} - Valid | 
| 215     "5\v\r\nhello\r\n", | 216     "5\v\r\nhello\r\n", | 
| 216     "0\r\n\r\n" | 217     "0\r\n\r\n" | 
| 217   }; | 218   }; | 
| 218   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 219   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 219 } | 220 } | 
| 220 | 221 | 
| 221 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingNonHexDigit) { | 222 TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingNonHexDigit) { | 
| 222   const char* inputs[] = { | 223   const char* const inputs[] = { | 
| 223     // Compatibility [RFC 2616 - Invalid]: | 224     // Compatibility [RFC 2616 - Invalid]: | 
| 224     // {Safari 3.1} - Invalid | 225     // {Safari 3.1} - Invalid | 
| 225     // {IE7, Firefox3, Opera 9.51} - Valid | 226     // {IE7, Firefox3, Opera 9.51} - Valid | 
| 226     "5H\r\nhello\r\n", | 227     "5H\r\nhello\r\n", | 
| 227     "0\r\n\r\n" | 228     "0\r\n\r\n" | 
| 228   }; | 229   }; | 
| 229   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 230   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 230 } | 231 } | 
| 231 | 232 | 
| 232 TEST(HttpChunkedDecoderTest, InvalidChunkSize_LeadingSpace) { | 233 TEST(HttpChunkedDecoderTest, InvalidChunkSize_LeadingSpace) { | 
| 233   const char* inputs[] = { | 234   const char* const inputs[] = { | 
| 234     // Compatibility [RFC 2616 - Invalid]: | 235     // Compatibility [RFC 2616 - Invalid]: | 
| 235     // {IE7} - Invalid | 236     // {IE7} - Invalid | 
| 236     // {Safari 3.1, Firefox3, Opera 9.51} - Valid | 237     // {Safari 3.1, Firefox3, Opera 9.51} - Valid | 
| 237     " 5\r\nhello\r\n", | 238     " 5\r\nhello\r\n", | 
| 238     "0\r\n\r\n" | 239     "0\r\n\r\n" | 
| 239   }; | 240   }; | 
| 240   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 241   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 241 } | 242 } | 
| 242 | 243 | 
| 243 TEST(HttpChunkedDecoderTest, InvalidLeadingSeparator) { | 244 TEST(HttpChunkedDecoderTest, InvalidLeadingSeparator) { | 
| 244   const char* inputs[] = { | 245   const char* const inputs[] = { | 
| 245     "\r\n5\r\nhello\r\n", | 246     "\r\n5\r\nhello\r\n", | 
| 246     "0\r\n\r\n" | 247     "0\r\n\r\n" | 
| 247   }; | 248   }; | 
| 248   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 249   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 249 } | 250 } | 
| 250 | 251 | 
| 251 TEST(HttpChunkedDecoderTest, InvalidChunkSize_NoSeparator) { | 252 TEST(HttpChunkedDecoderTest, InvalidChunkSize_NoSeparator) { | 
| 252   const char* inputs[] = { | 253   const char* const inputs[] = { | 
| 253     "5\r\nhello", | 254     "5\r\nhello", | 
| 254     "1\r\n \r\n", | 255     "1\r\n \r\n", | 
| 255     "0\r\n\r\n" | 256     "0\r\n\r\n" | 
| 256   }; | 257   }; | 
| 257   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 258   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 
| 258 } | 259 } | 
| 259 | 260 | 
| 260 TEST(HttpChunkedDecoderTest, InvalidChunkSize_Negative) { | 261 TEST(HttpChunkedDecoderTest, InvalidChunkSize_Negative) { | 
| 261   const char* inputs[] = { | 262   const char* const inputs[] = { | 
| 262     "8\r\n12345678\r\n-5\r\nhello\r\n", | 263     "8\r\n12345678\r\n-5\r\nhello\r\n", | 
| 263     "0\r\n\r\n" | 264     "0\r\n\r\n" | 
| 264   }; | 265   }; | 
| 265   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 266   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 266 } | 267 } | 
| 267 | 268 | 
| 268 TEST(HttpChunkedDecoderTest, InvalidChunkSize_Plus) { | 269 TEST(HttpChunkedDecoderTest, InvalidChunkSize_Plus) { | 
| 269   const char* inputs[] = { | 270   const char* const inputs[] = { | 
| 270     // Compatibility [RFC 2616 - Invalid]: | 271     // Compatibility [RFC 2616 - Invalid]: | 
| 271     // {IE7, Safari 3.1} - Invalid | 272     // {IE7, Safari 3.1} - Invalid | 
| 272     // {Firefox3, Opera 9.51} - Valid | 273     // {Firefox3, Opera 9.51} - Valid | 
| 273     "+5\r\nhello\r\n", | 274     "+5\r\nhello\r\n", | 
| 274     "0\r\n\r\n" | 275     "0\r\n\r\n" | 
| 275   }; | 276   }; | 
| 276   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 277   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 277 } | 278 } | 
| 278 | 279 | 
| 279 TEST(HttpChunkedDecoderTest, InvalidConsecutiveCRLFs) { | 280 TEST(HttpChunkedDecoderTest, InvalidConsecutiveCRLFs) { | 
| 280   const char* inputs[] = { | 281   const char* const inputs[] = { | 
| 281     "5\r\nhello\r\n", | 282     "5\r\nhello\r\n", | 
| 282     "\r\n\r\n\r\n\r\n", | 283     "\r\n\r\n\r\n\r\n", | 
| 283     "0\r\n\r\n" | 284     "0\r\n\r\n" | 
| 284   }; | 285   }; | 
| 285   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 286   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 
| 286 } | 287 } | 
| 287 | 288 | 
| 288 TEST(HttpChunkedDecoderTest, ExcessiveChunkLen) { | 289 TEST(HttpChunkedDecoderTest, ExcessiveChunkLen) { | 
| 289   const char* inputs[] = { | 290   const char* const inputs[] = { | 
| 290     "c0000000\r\nhello\r\n" | 291     "c0000000\r\nhello\r\n" | 
| 291   }; | 292   }; | 
| 292   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 293   RunTestUntilFailure(inputs, arraysize(inputs), 0); | 
| 293 } | 294 } | 
| 294 | 295 | 
| 295 TEST(HttpChunkedDecoderTest, BasicExtraData) { | 296 TEST(HttpChunkedDecoderTest, BasicExtraData) { | 
| 296   const char* inputs[] = { | 297   const char* const inputs[] = { | 
| 297     "5\r\nhello\r\n0\r\n\r\nextra bytes" | 298     "5\r\nhello\r\n0\r\n\r\nextra bytes" | 
| 298   }; | 299   }; | 
| 299   RunTest(inputs, arraysize(inputs), "hello", true, 11); | 300   RunTest(inputs, arraysize(inputs), "hello", true, 11); | 
| 300 } | 301 } | 
| 301 | 302 | 
| 302 TEST(HttpChunkedDecoderTest, IncrementalExtraData) { | 303 TEST(HttpChunkedDecoderTest, IncrementalExtraData) { | 
| 303   const char* inputs[] = { | 304   const char* const inputs[] = { | 
| 304     "5", | 305     "5", | 
| 305     "\r", | 306     "\r", | 
| 306     "\n", | 307     "\n", | 
| 307     "hello", | 308     "hello", | 
| 308     "\r", | 309     "\r", | 
| 309     "\n", | 310     "\n", | 
| 310     "0", | 311     "0", | 
| 311     "\r", | 312     "\r", | 
| 312     "\n", | 313     "\n", | 
| 313     "\r", | 314     "\r", | 
| 314     "\nextra bytes" | 315     "\nextra bytes" | 
| 315   }; | 316   }; | 
| 316   RunTest(inputs, arraysize(inputs), "hello", true, 11); | 317   RunTest(inputs, arraysize(inputs), "hello", true, 11); | 
| 317 } | 318 } | 
| 318 | 319 | 
| 319 TEST(HttpChunkedDecoderTest, MultipleExtraDataBlocks) { | 320 TEST(HttpChunkedDecoderTest, MultipleExtraDataBlocks) { | 
| 320   const char* inputs[] = { | 321   const char* const inputs[] = { | 
| 321     "5\r\nhello\r\n0\r\n\r\nextra", | 322     "5\r\nhello\r\n0\r\n\r\nextra", | 
| 322     " bytes" | 323     " bytes" | 
| 323   }; | 324   }; | 
| 324   RunTest(inputs, arraysize(inputs), "hello", true, 11); | 325   RunTest(inputs, arraysize(inputs), "hello", true, 11); | 
| 325 } | 326 } | 
| 326 | 327 | 
| 327 // Test when the line with the chunk length is too long. | 328 // Test when the line with the chunk length is too long. | 
| 328 TEST(HttpChunkedDecoderTest, LongChunkLengthLine) { | 329 TEST(HttpChunkedDecoderTest, LongChunkLengthLine) { | 
| 329   int big_chunk_length = HttpChunkedDecoder::kMaxLineBufLen; | 330   int big_chunk_length = HttpChunkedDecoder::kMaxLineBufLen; | 
| 330   scoped_ptr<char[]> big_chunk(new char[big_chunk_length + 1]); | 331   scoped_ptr<char[]> big_chunk(new char[big_chunk_length + 1]); | 
| 331   memset(big_chunk.get(), '0', big_chunk_length); | 332   memset(big_chunk.get(), '0', big_chunk_length); | 
| 332   big_chunk[big_chunk_length] = 0; | 333   big_chunk[big_chunk_length] = 0; | 
| 333   const char* inputs[] = { | 334   const char* const inputs[] = { | 
| 334     big_chunk.get(), | 335     big_chunk.get(), | 
| 335     "5" | 336     "5" | 
| 336   }; | 337   }; | 
| 337   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 338   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 
| 338 } | 339 } | 
| 339 | 340 | 
| 340 // Test when the extension portion of the line with the chunk length is too | 341 // Test when the extension portion of the line with the chunk length is too | 
| 341 // long. | 342 // long. | 
| 342 TEST(HttpChunkedDecoderTest, LongLengthLengthLine) { | 343 TEST(HttpChunkedDecoderTest, LongLengthLengthLine) { | 
| 343   int big_chunk_length = HttpChunkedDecoder::kMaxLineBufLen; | 344   int big_chunk_length = HttpChunkedDecoder::kMaxLineBufLen; | 
| 344   scoped_ptr<char[]> big_chunk(new char[big_chunk_length + 1]); | 345   scoped_ptr<char[]> big_chunk(new char[big_chunk_length + 1]); | 
| 345   memset(big_chunk.get(), '0', big_chunk_length); | 346   memset(big_chunk.get(), '0', big_chunk_length); | 
| 346   big_chunk[big_chunk_length] = 0; | 347   big_chunk[big_chunk_length] = 0; | 
| 347   const char* inputs[] = { | 348   const char* const inputs[] = { | 
| 348     "5;", | 349     "5;", | 
| 349     big_chunk.get() | 350     big_chunk.get() | 
| 350   }; | 351   }; | 
| 351   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 352   RunTestUntilFailure(inputs, arraysize(inputs), 1); | 
| 352 } | 353 } | 
| 353 | 354 | 
| 354 }  // namespace | 355 }  // namespace | 
| 355 | 356 | 
| 356 }  // namespace net | 357 }  // namespace net | 
| OLD | NEW | 
|---|