| 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/buffered_spdy_framer.h" | 5 #include "net/spdy/buffered_spdy_framer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 void OnSettings() override {} | 76 void OnSettings() override {} |
| 77 | 77 |
| 78 void OnSetting(SpdySettingsIds id, uint32_t value) override { | 78 void OnSetting(SpdySettingsIds id, uint32_t value) override { |
| 79 setting_count_++; | 79 setting_count_++; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void OnPing(SpdyPingId unique_id, bool is_ack) override {} | 82 void OnPing(SpdyPingId unique_id, bool is_ack) override {} |
| 83 | 83 |
| 84 void OnRstStream(SpdyStreamId stream_id, | 84 void OnRstStream(SpdyStreamId stream_id, SpdyErrorCode error_code) override {} |
| 85 SpdyRstStreamStatus status) override {} | |
| 86 | 85 |
| 87 void OnGoAway(SpdyStreamId last_accepted_stream_id, | 86 void OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 88 SpdyGoAwayStatus status, | 87 SpdyErrorCode error_code, |
| 89 base::StringPiece debug_data) override { | 88 base::StringPiece debug_data) override { |
| 90 goaway_count_++; | 89 goaway_count_++; |
| 91 goaway_last_accepted_stream_id_ = last_accepted_stream_id; | 90 goaway_last_accepted_stream_id_ = last_accepted_stream_id; |
| 92 goaway_status_ = status; | 91 goaway_error_code_ = error_code; |
| 93 goaway_debug_data_.assign(debug_data.data(), debug_data.size()); | 92 goaway_debug_data_.assign(debug_data.data(), debug_data.size()); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void OnDataFrameHeader(const SpdySerializedFrame* frame) { | 95 void OnDataFrameHeader(const SpdySerializedFrame* frame) { |
| 97 LOG(FATAL) << "Unexpected OnDataFrameHeader call."; | 96 LOG(FATAL) << "Unexpected OnDataFrameHeader call."; |
| 98 } | 97 } |
| 99 | 98 |
| 100 void OnRstStream(const SpdySerializedFrame& frame) {} | 99 void OnRstStream(const SpdySerializedFrame& frame) {} |
| 101 void OnGoAway(const SpdySerializedFrame& frame) {} | 100 void OnGoAway(const SpdySerializedFrame& frame) {} |
| 102 void OnPing(const SpdySerializedFrame& frame) {} | 101 void OnPing(const SpdySerializedFrame& frame) {} |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 159 |
| 161 // Header block streaming state: | 160 // Header block streaming state: |
| 162 SpdyStreamId header_stream_id_; | 161 SpdyStreamId header_stream_id_; |
| 163 SpdyStreamId promised_stream_id_; | 162 SpdyStreamId promised_stream_id_; |
| 164 | 163 |
| 165 // Headers from OnHeaders and OnPushPromise for verification. | 164 // Headers from OnHeaders and OnPushPromise for verification. |
| 166 SpdyHeaderBlock headers_; | 165 SpdyHeaderBlock headers_; |
| 167 | 166 |
| 168 // OnGoAway parameters. | 167 // OnGoAway parameters. |
| 169 SpdyStreamId goaway_last_accepted_stream_id_; | 168 SpdyStreamId goaway_last_accepted_stream_id_; |
| 170 SpdyGoAwayStatus goaway_status_; | 169 SpdyErrorCode goaway_error_code_; |
| 171 std::string goaway_debug_data_; | 170 std::string goaway_debug_data_; |
| 172 | 171 |
| 173 // OnAltSvc parameters. | 172 // OnAltSvc parameters. |
| 174 SpdyStreamId altsvc_stream_id_; | 173 SpdyStreamId altsvc_stream_id_; |
| 175 std::string altsvc_origin_; | 174 std::string altsvc_origin_; |
| 176 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector_; | 175 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector_; |
| 177 }; | 176 }; |
| 178 | 177 |
| 179 } // namespace | 178 } // namespace |
| 180 | 179 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 EXPECT_EQ(0, visitor.headers_frame_count_); | 256 EXPECT_EQ(0, visitor.headers_frame_count_); |
| 258 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 257 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
| 259 EXPECT_EQ(headers, visitor.headers_); | 258 EXPECT_EQ(headers, visitor.headers_); |
| 260 EXPECT_EQ(1u, visitor.header_stream_id_); | 259 EXPECT_EQ(1u, visitor.header_stream_id_); |
| 261 EXPECT_EQ(2u, visitor.promised_stream_id_); | 260 EXPECT_EQ(2u, visitor.promised_stream_id_); |
| 262 } | 261 } |
| 263 | 262 |
| 264 TEST_F(BufferedSpdyFramerTest, GoAwayDebugData) { | 263 TEST_F(BufferedSpdyFramerTest, GoAwayDebugData) { |
| 265 BufferedSpdyFramer framer; | 264 BufferedSpdyFramer framer; |
| 266 std::unique_ptr<SpdySerializedFrame> goaway_frame( | 265 std::unique_ptr<SpdySerializedFrame> goaway_frame( |
| 267 framer.CreateGoAway(2u, GOAWAY_FRAME_SIZE_ERROR, "foo")); | 266 framer.CreateGoAway(2u, ERROR_CODE_FRAME_SIZE_ERROR, "foo")); |
| 268 | 267 |
| 269 TestBufferedSpdyVisitor visitor; | 268 TestBufferedSpdyVisitor visitor; |
| 270 visitor.SimulateInFramer( | 269 visitor.SimulateInFramer( |
| 271 reinterpret_cast<unsigned char*>(goaway_frame.get()->data()), | 270 reinterpret_cast<unsigned char*>(goaway_frame.get()->data()), |
| 272 goaway_frame.get()->size()); | 271 goaway_frame.get()->size()); |
| 273 EXPECT_EQ(0, visitor.error_count_); | 272 EXPECT_EQ(0, visitor.error_count_); |
| 274 EXPECT_EQ(1, visitor.goaway_count_); | 273 EXPECT_EQ(1, visitor.goaway_count_); |
| 275 EXPECT_EQ(2u, visitor.goaway_last_accepted_stream_id_); | 274 EXPECT_EQ(2u, visitor.goaway_last_accepted_stream_id_); |
| 276 EXPECT_EQ(GOAWAY_FRAME_SIZE_ERROR, visitor.goaway_status_); | 275 EXPECT_EQ(ERROR_CODE_FRAME_SIZE_ERROR, visitor.goaway_error_code_); |
| 277 EXPECT_EQ("foo", visitor.goaway_debug_data_); | 276 EXPECT_EQ("foo", visitor.goaway_debug_data_); |
| 278 } | 277 } |
| 279 | 278 |
| 280 TEST_F(BufferedSpdyFramerTest, OnAltSvc) { | 279 TEST_F(BufferedSpdyFramerTest, OnAltSvc) { |
| 281 const SpdyStreamId altsvc_stream_id(1); | 280 const SpdyStreamId altsvc_stream_id(1); |
| 282 const char altsvc_origin[] = "https://www.example.org"; | 281 const char altsvc_origin[] = "https://www.example.org"; |
| 283 SpdyAltSvcIR altsvc_ir(altsvc_stream_id); | 282 SpdyAltSvcIR altsvc_ir(altsvc_stream_id); |
| 284 SpdyAltSvcWireFormat::AlternativeService alternative_service( | 283 SpdyAltSvcWireFormat::AlternativeService alternative_service( |
| 285 "quic", "alternative.example.org", 443, 86400, | 284 "quic", "alternative.example.org", 443, 86400, |
| 286 SpdyAltSvcWireFormat::VersionVector()); | 285 SpdyAltSvcWireFormat::VersionVector()); |
| 287 altsvc_ir.add_altsvc(alternative_service); | 286 altsvc_ir.add_altsvc(alternative_service); |
| 288 altsvc_ir.set_origin(altsvc_origin); | 287 altsvc_ir.set_origin(altsvc_origin); |
| 289 BufferedSpdyFramer framer; | 288 BufferedSpdyFramer framer; |
| 290 SpdySerializedFrame altsvc_frame(framer.SerializeFrame(altsvc_ir)); | 289 SpdySerializedFrame altsvc_frame(framer.SerializeFrame(altsvc_ir)); |
| 291 | 290 |
| 292 TestBufferedSpdyVisitor visitor; | 291 TestBufferedSpdyVisitor visitor; |
| 293 visitor.SimulateInFramer( | 292 visitor.SimulateInFramer( |
| 294 reinterpret_cast<unsigned char*>(altsvc_frame.data()), | 293 reinterpret_cast<unsigned char*>(altsvc_frame.data()), |
| 295 altsvc_frame.size()); | 294 altsvc_frame.size()); |
| 296 EXPECT_EQ(0, visitor.error_count_); | 295 EXPECT_EQ(0, visitor.error_count_); |
| 297 EXPECT_EQ(1, visitor.altsvc_count_); | 296 EXPECT_EQ(1, visitor.altsvc_count_); |
| 298 EXPECT_EQ(altsvc_stream_id, visitor.altsvc_stream_id_); | 297 EXPECT_EQ(altsvc_stream_id, visitor.altsvc_stream_id_); |
| 299 EXPECT_EQ(altsvc_origin, visitor.altsvc_origin_); | 298 EXPECT_EQ(altsvc_origin, visitor.altsvc_origin_); |
| 300 ASSERT_EQ(1u, visitor.altsvc_vector_.size()); | 299 ASSERT_EQ(1u, visitor.altsvc_vector_.size()); |
| 301 EXPECT_EQ(alternative_service, visitor.altsvc_vector_[0]); | 300 EXPECT_EQ(alternative_service, visitor.altsvc_vector_[0]); |
| 302 } | 301 } |
| 303 | 302 |
| 304 } // namespace net | 303 } // namespace net |
| OLD | NEW |