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 "net/spdy/spdy_test_util_common.h" | 7 #include "net/spdy/spdy_test_util_common.h" |
8 #include "testing/platform_test.h" | 8 #include "testing/platform_test.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class TestBufferedSpdyVisitor : public BufferedSpdyFramerVisitorInterface { | 14 class TestBufferedSpdyVisitor : public BufferedSpdyFramerVisitorInterface { |
15 public: | 15 public: |
16 explicit TestBufferedSpdyVisitor(SpdyMajorVersion spdy_version) | 16 explicit TestBufferedSpdyVisitor(SpdyMajorVersion spdy_version) |
17 : buffered_spdy_framer_(spdy_version, true), | 17 : buffered_spdy_framer_(spdy_version, true), |
18 error_count_(0), | 18 error_count_(0), |
19 setting_count_(0), | 19 setting_count_(0), |
20 syn_frame_count_(0), | 20 syn_frame_count_(0), |
21 syn_reply_frame_count_(0), | 21 syn_reply_frame_count_(0), |
22 headers_frame_count_(0), | 22 headers_frame_count_(0), |
23 push_promise_frame_count_(0), | 23 push_promise_frame_count_(0), |
24 goaway_count_(0), | |
24 header_stream_id_(static_cast<SpdyStreamId>(-1)), | 25 header_stream_id_(static_cast<SpdyStreamId>(-1)), |
25 promised_stream_id_(static_cast<SpdyStreamId>(-1)) { | 26 promised_stream_id_(static_cast<SpdyStreamId>(-1)) {} |
eroman
2015/10/06 17:19:41
unrelated side-note: seems like this would be clea
Bence
2015/10/07 15:18:27
Acknowledged.
| |
26 } | |
27 | 27 |
28 void OnError(SpdyFramer::SpdyError error_code) override { | 28 void OnError(SpdyFramer::SpdyError error_code) override { |
29 LOG(INFO) << "SpdyFramer Error: " << error_code; | 29 LOG(INFO) << "SpdyFramer Error: " << error_code; |
30 error_count_++; | 30 error_count_++; |
31 } | 31 } |
32 | 32 |
33 void OnStreamError(SpdyStreamId stream_id, | 33 void OnStreamError(SpdyStreamId stream_id, |
34 const std::string& description) override { | 34 const std::string& description) override { |
35 LOG(INFO) << "SpdyFramer Error on stream: " << stream_id << " " | 35 LOG(INFO) << "SpdyFramer Error on stream: " << stream_id << " " |
36 << description; | 36 << description; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) override { | 93 void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) override { |
94 setting_count_++; | 94 setting_count_++; |
95 } | 95 } |
96 | 96 |
97 void OnPing(SpdyPingId unique_id, bool is_ack) override {} | 97 void OnPing(SpdyPingId unique_id, bool is_ack) override {} |
98 | 98 |
99 void OnRstStream(SpdyStreamId stream_id, | 99 void OnRstStream(SpdyStreamId stream_id, |
100 SpdyRstStreamStatus status) override {} | 100 SpdyRstStreamStatus status) override {} |
101 | 101 |
102 void OnGoAway(SpdyStreamId last_accepted_stream_id, | 102 void OnGoAway(SpdyStreamId last_accepted_stream_id, |
103 SpdyGoAwayStatus status) override {} | 103 SpdyGoAwayStatus status, |
104 StringPiece debug_data) override { | |
105 goaway_count_++; | |
106 goaway_last_accepted_stream_id_ = last_accepted_stream_id; | |
107 goaway_status_ = status; | |
108 goaway_debug_data_.assign(debug_data.data(), debug_data.size()); | |
109 } | |
104 | 110 |
105 bool OnCredentialFrameData(const char*, size_t) { | 111 bool OnCredentialFrameData(const char*, size_t) { |
106 LOG(FATAL) << "Unexpected OnCredentialFrameData call."; | 112 LOG(FATAL) << "Unexpected OnCredentialFrameData call."; |
107 return false; | 113 return false; |
108 } | 114 } |
109 | 115 |
110 void OnDataFrameHeader(const SpdyFrame* frame) { | 116 void OnDataFrameHeader(const SpdyFrame* frame) { |
111 LOG(FATAL) << "Unexpected OnDataFrameHeader call."; | 117 LOG(FATAL) << "Unexpected OnDataFrameHeader call."; |
112 } | 118 } |
113 | 119 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 161 |
156 BufferedSpdyFramer buffered_spdy_framer_; | 162 BufferedSpdyFramer buffered_spdy_framer_; |
157 | 163 |
158 // Counters from the visitor callbacks. | 164 // Counters from the visitor callbacks. |
159 int error_count_; | 165 int error_count_; |
160 int setting_count_; | 166 int setting_count_; |
161 int syn_frame_count_; | 167 int syn_frame_count_; |
162 int syn_reply_frame_count_; | 168 int syn_reply_frame_count_; |
163 int headers_frame_count_; | 169 int headers_frame_count_; |
164 int push_promise_frame_count_; | 170 int push_promise_frame_count_; |
171 int goaway_count_; | |
165 | 172 |
166 // Header block streaming state: | 173 // Header block streaming state: |
167 SpdyStreamId header_stream_id_; | 174 SpdyStreamId header_stream_id_; |
168 SpdyStreamId promised_stream_id_; | 175 SpdyStreamId promised_stream_id_; |
169 | 176 |
170 // Headers from OnSyn, OnSynReply, OnHeaders and OnPushPromise for | 177 // Headers from OnSyn, OnSynReply, OnHeaders and OnPushPromise for |
171 // verification. | 178 // verification. |
172 SpdyHeaderBlock headers_; | 179 SpdyHeaderBlock headers_; |
180 | |
181 // OnGoAway parameters. | |
182 SpdyStreamId goaway_last_accepted_stream_id_; | |
183 SpdyGoAwayStatus goaway_status_; | |
184 std::string goaway_debug_data_; | |
173 }; | 185 }; |
174 | 186 |
175 } // namespace | 187 } // namespace |
176 | 188 |
177 class BufferedSpdyFramerTest | 189 class BufferedSpdyFramerTest |
178 : public PlatformTest, | 190 : public PlatformTest, |
179 public ::testing::WithParamInterface<NextProto> { | 191 public ::testing::WithParamInterface<NextProto> { |
180 protected: | 192 protected: |
181 // Returns true if the two header blocks have equivalent content. | 193 // Returns true if the two header blocks have equivalent content. |
182 bool CompareHeaderBlocks(const SpdyHeaderBlock* expected, | 194 bool CompareHeaderBlocks(const SpdyHeaderBlock* expected, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 EXPECT_EQ(0, visitor.error_count_); | 345 EXPECT_EQ(0, visitor.error_count_); |
334 EXPECT_EQ(0, visitor.syn_frame_count_); | 346 EXPECT_EQ(0, visitor.syn_frame_count_); |
335 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 347 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
336 EXPECT_EQ(0, visitor.headers_frame_count_); | 348 EXPECT_EQ(0, visitor.headers_frame_count_); |
337 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 349 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
338 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 350 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
339 EXPECT_EQ(1u, visitor.header_stream_id_); | 351 EXPECT_EQ(1u, visitor.header_stream_id_); |
340 EXPECT_EQ(2u, visitor.promised_stream_id_); | 352 EXPECT_EQ(2u, visitor.promised_stream_id_); |
341 } | 353 } |
342 | 354 |
355 TEST_P(BufferedSpdyFramerTest, GoAwayDebugData) { | |
356 if (spdy_version() < HTTP2) | |
357 return; | |
358 BufferedSpdyFramer framer(spdy_version(), true); | |
359 scoped_ptr<SpdyFrame> goaway_frame( | |
360 framer.CreateGoAway(2u, GOAWAY_FRAME_SIZE_ERROR, "foo")); | |
361 | |
362 TestBufferedSpdyVisitor visitor(spdy_version()); | |
363 visitor.SimulateInFramer( | |
364 reinterpret_cast<unsigned char*>(goaway_frame.get()->data()), | |
365 goaway_frame.get()->size()); | |
366 EXPECT_EQ(0, visitor.error_count_); | |
367 EXPECT_EQ(1, visitor.goaway_count_); | |
368 EXPECT_EQ(2u, visitor.goaway_last_accepted_stream_id_); | |
369 EXPECT_EQ(GOAWAY_FRAME_SIZE_ERROR, visitor.goaway_status_); | |
370 EXPECT_EQ("foo", visitor.goaway_debug_data_); | |
371 } | |
372 | |
343 } // namespace net | 373 } // namespace net |
OLD | NEW |