| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 4153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4164 unframed_data -= to_read; | 4164 unframed_data -= to_read; |
| 4165 framed_data += to_read; | 4165 framed_data += to_read; |
| 4166 } | 4166 } |
| 4167 EXPECT_EQ(0, visitor.error_count_); | 4167 EXPECT_EQ(0, visitor.error_count_); |
| 4168 EXPECT_EQ(1, visitor.altsvc_count_); | 4168 EXPECT_EQ(1, visitor.altsvc_count_); |
| 4169 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); | 4169 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); |
| 4170 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); | 4170 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); |
| 4171 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); | 4171 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); |
| 4172 } | 4172 } |
| 4173 | 4173 |
| 4174 // While RFC7838 Section 4 says that an ALTSVC frame on stream 0 with empty |
| 4175 // origin MUST be ignored, it is not implemented at the framer level: instead, |
| 4176 // such frames are passed on to the consumer. |
| 4177 TEST_P(SpdyFramerTest, ReadAltSvcFrame) { |
| 4178 struct { |
| 4179 uint32_t stream_id; |
| 4180 const char* origin; |
| 4181 } test_cases[] = {{0, ""}, |
| 4182 {1, ""}, |
| 4183 {0, "https://www.example.com"}, |
| 4184 {1, "https://www.example.com"}}; |
| 4185 for (auto test_case : test_cases) { |
| 4186 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4187 SpdyAltSvcIR altsvc_ir(test_case.stream_id); |
| 4188 SpdyAltSvcWireFormat::AlternativeService altsvc( |
| 4189 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4190 altsvc_ir.add_altsvc(altsvc); |
| 4191 altsvc_ir.set_origin(test_case.origin); |
| 4192 SpdySerializedFrame frame(framer.SerializeAltSvc(altsvc_ir)); |
| 4193 |
| 4194 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 4195 framer.set_visitor(&visitor); |
| 4196 framer.ProcessInput(frame.data(), frame.size()); |
| 4197 |
| 4198 EXPECT_EQ(0, visitor.error_count_); |
| 4199 EXPECT_EQ(1, visitor.altsvc_count_); |
| 4200 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4201 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) |
| 4202 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 4203 } |
| 4204 } |
| 4205 |
| 4206 // An ALTSVC frame with invalid Alt-Svc-Field-Value results in an error. |
| 4207 TEST_P(SpdyFramerTest, ErrorOnAltSvcFrameWithInvalidValue) { |
| 4208 // Alt-Svc-Field-Value must be "clear" or must contain an "=" character |
| 4209 // per RFC7838 Section 3. |
| 4210 const char kFrameData[] = { |
| 4211 0x00, 0x00, 0x16, // Length: 22 |
| 4212 0x0a, // Type: ALTSVC |
| 4213 0x00, // Flags: none |
| 4214 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 4215 0x00, 0x00, // Origin-Len: 0 |
| 4216 0x74, 0x68, 0x69, 0x73, // thisisnotavalidvalue |
| 4217 0x69, 0x73, 0x6e, 0x6f, 0x74, 0x61, 0x76, 0x61, |
| 4218 0x6c, 0x69, 0x64, 0x76, 0x61, 0x6c, 0x75, 0x65, |
| 4219 }; |
| 4220 |
| 4221 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4222 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 4223 framer.set_visitor(&visitor); |
| 4224 framer.ProcessInput(kFrameData, sizeof(kFrameData)); |
| 4225 |
| 4226 EXPECT_EQ(1, visitor.error_count_); |
| 4227 EXPECT_EQ(0, visitor.altsvc_count_); |
| 4228 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4229 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.spdy_framer_error()) |
| 4230 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 4231 } |
| 4232 |
| 4174 // Tests handling of PRIORITY frames. | 4233 // Tests handling of PRIORITY frames. |
| 4175 TEST_P(SpdyFramerTest, ReadPriority) { | 4234 TEST_P(SpdyFramerTest, ReadPriority) { |
| 4176 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 4235 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4177 SpdyPriorityIR priority(3, 1, 256, false); | 4236 SpdyPriorityIR priority(3, 1, 256, false); |
| 4178 SpdySerializedFrame frame(framer.SerializePriority(priority)); | 4237 SpdySerializedFrame frame(framer.SerializePriority(priority)); |
| 4179 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4238 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4180 framer.set_visitor(&visitor); | 4239 framer.set_visitor(&visitor); |
| 4181 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); | 4240 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); |
| 4182 framer.ProcessInput(frame.data(), frame.size()); | 4241 framer.ProcessInput(frame.data(), frame.size()); |
| 4183 | 4242 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4421 | 4480 |
| 4422 EXPECT_EQ(1, visitor->data_frame_count_); | 4481 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4423 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4482 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4424 EXPECT_EQ(0, visitor->headers_frame_count_); | 4483 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4425 } | 4484 } |
| 4426 } | 4485 } |
| 4427 | 4486 |
| 4428 } // namespace test | 4487 } // namespace test |
| 4429 | 4488 |
| 4430 } // namespace net | 4489 } // namespace net |
| OLD | NEW |