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 { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 SpdyStreamId promised_stream_id, | 118 SpdyStreamId promised_stream_id, |
119 const SpdyHeaderBlock& headers) OVERRIDE { | 119 const SpdyHeaderBlock& headers) OVERRIDE { |
120 header_stream_id_ = stream_id; | 120 header_stream_id_ = stream_id; |
121 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 121 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
122 push_promise_frame_count_++; | 122 push_promise_frame_count_++; |
123 promised_stream_id_ = promised_stream_id; | 123 promised_stream_id_ = promised_stream_id; |
124 EXPECT_NE(promised_stream_id_, SpdyFramer::kInvalidStream); | 124 EXPECT_NE(promised_stream_id_, SpdyFramer::kInvalidStream); |
125 headers_ = headers; | 125 headers_ = headers; |
126 } | 126 } |
127 | 127 |
| 128 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) OVERRIDE { |
| 129 return true; |
| 130 } |
| 131 |
128 void OnCredential(const SpdyFrame& frame) {} | 132 void OnCredential(const SpdyFrame& frame) {} |
129 | 133 |
130 // Convenience function which runs a framer simulation with particular input. | 134 // Convenience function which runs a framer simulation with particular input. |
131 void SimulateInFramer(const unsigned char* input, size_t size) { | 135 void SimulateInFramer(const unsigned char* input, size_t size) { |
132 buffered_spdy_framer_.set_visitor(this); | 136 buffered_spdy_framer_.set_visitor(this); |
133 size_t input_remaining = size; | 137 size_t input_remaining = size; |
134 const char* input_ptr = reinterpret_cast<const char*>(input); | 138 const char* input_ptr = reinterpret_cast<const char*>(input); |
135 while (input_remaining > 0 && | 139 while (input_remaining > 0 && |
136 buffered_spdy_framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { | 140 buffered_spdy_framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { |
137 // To make the tests more interesting, we feed random (amd small) chunks | 141 // To make the tests more interesting, we feed random (amd small) chunks |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 &headers)); | 273 &headers)); |
270 EXPECT_TRUE(control_frame.get() != NULL); | 274 EXPECT_TRUE(control_frame.get() != NULL); |
271 | 275 |
272 TestBufferedSpdyVisitor visitor(spdy_version()); | 276 TestBufferedSpdyVisitor visitor(spdy_version()); |
273 visitor.SimulateInFramer( | 277 visitor.SimulateInFramer( |
274 reinterpret_cast<unsigned char*>(control_frame.get()->data()), | 278 reinterpret_cast<unsigned char*>(control_frame.get()->data()), |
275 control_frame.get()->size()); | 279 control_frame.get()->size()); |
276 EXPECT_EQ(0, visitor.error_count_); | 280 EXPECT_EQ(0, visitor.error_count_); |
277 EXPECT_EQ(0, visitor.syn_frame_count_); | 281 EXPECT_EQ(0, visitor.syn_frame_count_); |
278 EXPECT_EQ(0, visitor.push_promise_frame_count_); | 282 EXPECT_EQ(0, visitor.push_promise_frame_count_); |
279 if(spdy_version() < SPDY4) { | 283 if (spdy_version() < SPDY4) { |
280 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | 284 EXPECT_EQ(1, visitor.syn_reply_frame_count_); |
281 EXPECT_EQ(0, visitor.headers_frame_count_); | 285 EXPECT_EQ(0, visitor.headers_frame_count_); |
282 } else { | 286 } else { |
283 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 287 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
284 EXPECT_EQ(1, visitor.headers_frame_count_); | 288 EXPECT_EQ(1, visitor.headers_frame_count_); |
285 } | 289 } |
286 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 290 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
287 } | 291 } |
288 | 292 |
289 TEST_P(BufferedSpdyFramerTest, ReadHeadersHeaderBlock) { | 293 TEST_P(BufferedSpdyFramerTest, ReadHeadersHeaderBlock) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 EXPECT_EQ(0, visitor.syn_frame_count_); | 332 EXPECT_EQ(0, visitor.syn_frame_count_); |
329 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 333 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
330 EXPECT_EQ(0, visitor.headers_frame_count_); | 334 EXPECT_EQ(0, visitor.headers_frame_count_); |
331 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 335 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
332 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 336 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
333 EXPECT_EQ(1u, visitor.header_stream_id_); | 337 EXPECT_EQ(1u, visitor.header_stream_id_); |
334 EXPECT_EQ(2u, visitor.promised_stream_id_); | 338 EXPECT_EQ(2u, visitor.promised_stream_id_); |
335 } | 339 } |
336 | 340 |
337 } // namespace net | 341 } // namespace net |
OLD | NEW |