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