OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/quic/quic_spdy_stream.h" | 5 #include "net/quic/quic_spdy_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 TEST_P(QuicSpdyStreamTest, ParseHeaderStatusCode) { | 194 TEST_P(QuicSpdyStreamTest, ParseHeaderStatusCode) { |
195 // A valid status code should be 3-digit integer. The first digit should be in | 195 // A valid status code should be 3-digit integer. The first digit should be in |
196 // the range of [1, 5]. All the others are invalid. | 196 // the range of [1, 5]. All the others are invalid. |
197 Initialize(kShouldProcessData); | 197 Initialize(kShouldProcessData); |
198 int status_code = 0; | 198 int status_code = 0; |
199 | 199 |
200 // Valid status code. | 200 // Valid status code. |
201 headers_.ReplaceOrAppendHeader(":status", "404"); | 201 headers_.ReplaceOrAppendHeader(":status", "404"); |
202 EXPECT_TRUE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 202 EXPECT_TRUE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
203 EXPECT_EQ(404, status_code); | 203 EXPECT_EQ(404, status_code); |
204 | 204 |
205 // Invalid status codes. | 205 // Invalid status codes. |
206 headers_.ReplaceOrAppendHeader(":status", "010"); | 206 headers_.ReplaceOrAppendHeader(":status", "010"); |
207 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 207 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
208 | 208 |
209 headers_.ReplaceOrAppendHeader(":status", "600"); | 209 headers_.ReplaceOrAppendHeader(":status", "600"); |
210 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 210 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
211 | 211 |
212 headers_.ReplaceOrAppendHeader(":status", "200 ok"); | 212 headers_.ReplaceOrAppendHeader(":status", "200 ok"); |
213 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 213 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
214 | 214 |
215 headers_.ReplaceOrAppendHeader(":status", "2000"); | 215 headers_.ReplaceOrAppendHeader(":status", "2000"); |
216 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 216 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
217 | 217 |
218 headers_.ReplaceOrAppendHeader(":status", "+200"); | 218 headers_.ReplaceOrAppendHeader(":status", "+200"); |
219 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 219 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
220 | 220 |
221 headers_.ReplaceOrAppendHeader(":status", "+20"); | 221 headers_.ReplaceOrAppendHeader(":status", "+20"); |
222 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 222 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
223 | 223 |
224 // Leading or trailing spaces are also invalid. | 224 // Leading or trailing spaces are also invalid. |
225 headers_.ReplaceOrAppendHeader(":status", " 200"); | 225 headers_.ReplaceOrAppendHeader(":status", " 200"); |
226 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 226 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
227 | 227 |
228 headers_.ReplaceOrAppendHeader(":status", "200 "); | 228 headers_.ReplaceOrAppendHeader(":status", "200 "); |
229 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 229 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
230 | 230 |
231 headers_.ReplaceOrAppendHeader(":status", " 200 "); | 231 headers_.ReplaceOrAppendHeader(":status", " 200 "); |
232 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 232 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
233 | 233 |
234 headers_.ReplaceOrAppendHeader(":status", " "); | 234 headers_.ReplaceOrAppendHeader(":status", " "); |
235 EXPECT_FALSE(stream_->ParseHeaderStatusCode(&headers_, &status_code)); | 235 EXPECT_FALSE(stream_->ParseHeaderStatusCode(headers_, &status_code)); |
236 } | 236 } |
237 | 237 |
238 TEST_P(QuicSpdyStreamTest, MarkHeadersConsumed) { | 238 TEST_P(QuicSpdyStreamTest, MarkHeadersConsumed) { |
239 Initialize(kShouldProcessData); | 239 Initialize(kShouldProcessData); |
240 | 240 |
241 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 241 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
242 string body = "this is the body"; | 242 string body = "this is the body"; |
243 | 243 |
244 stream_->OnStreamHeaders(headers); | 244 stream_->OnStreamHeaders(headers); |
245 stream_->OnStreamHeadersComplete(false, headers.size()); | 245 stream_->OnStreamHeadersComplete(false, headers.size()); |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 993 |
994 // Writing Trailers should fail, as the FIN has already been sent. | 994 // Writing Trailers should fail, as the FIN has already been sent. |
995 // populated with the number of body bytes written. | 995 // populated with the number of body bytes written. |
996 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 996 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
997 "Trailers cannot be sent after a FIN"); | 997 "Trailers cannot be sent after a FIN"); |
998 } | 998 } |
999 | 999 |
1000 } // namespace | 1000 } // namespace |
1001 } // namespace test | 1001 } // namespace test |
1002 } // namespace net | 1002 } // namespace net |
OLD | NEW |