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 header_stream_id_(static_cast<SpdyStreamId>(-1)), | 24 header_stream_id_(static_cast<SpdyStreamId>(-1)), |
25 promised_stream_id_(static_cast<SpdyStreamId>(-1)) { | 25 promised_stream_id_(static_cast<SpdyStreamId>(-1)) { |
26 } | 26 } |
27 | 27 |
28 virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE { | 28 virtual 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 virtual void OnStreamError( | 33 virtual void OnStreamError( |
34 SpdyStreamId stream_id, | 34 SpdyStreamId stream_id, |
35 const std::string& description) OVERRIDE { | 35 const std::string& description) override { |
36 LOG(INFO) << "SpdyFramer Error on stream: " << stream_id << " " | 36 LOG(INFO) << "SpdyFramer Error on stream: " << stream_id << " " |
37 << description; | 37 << description; |
38 error_count_++; | 38 error_count_++; |
39 } | 39 } |
40 | 40 |
41 virtual void OnSynStream(SpdyStreamId stream_id, | 41 virtual void OnSynStream(SpdyStreamId stream_id, |
42 SpdyStreamId associated_stream_id, | 42 SpdyStreamId associated_stream_id, |
43 SpdyPriority priority, | 43 SpdyPriority priority, |
44 bool fin, | 44 bool fin, |
45 bool unidirectional, | 45 bool unidirectional, |
46 const SpdyHeaderBlock& headers) OVERRIDE { | 46 const SpdyHeaderBlock& headers) override { |
47 header_stream_id_ = stream_id; | 47 header_stream_id_ = stream_id; |
48 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 48 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
49 syn_frame_count_++; | 49 syn_frame_count_++; |
50 headers_ = headers; | 50 headers_ = headers; |
51 } | 51 } |
52 | 52 |
53 virtual void OnSynReply(SpdyStreamId stream_id, | 53 virtual void OnSynReply(SpdyStreamId stream_id, |
54 bool fin, | 54 bool fin, |
55 const SpdyHeaderBlock& headers) OVERRIDE { | 55 const SpdyHeaderBlock& headers) override { |
56 header_stream_id_ = stream_id; | 56 header_stream_id_ = stream_id; |
57 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 57 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
58 syn_reply_frame_count_++; | 58 syn_reply_frame_count_++; |
59 headers_ = headers; | 59 headers_ = headers; |
60 } | 60 } |
61 | 61 |
62 virtual void OnHeaders(SpdyStreamId stream_id, | 62 virtual void OnHeaders(SpdyStreamId stream_id, |
63 bool fin, | 63 bool fin, |
64 const SpdyHeaderBlock& headers) OVERRIDE { | 64 const SpdyHeaderBlock& headers) override { |
65 header_stream_id_ = stream_id; | 65 header_stream_id_ = stream_id; |
66 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 66 EXPECT_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
67 headers_frame_count_++; | 67 headers_frame_count_++; |
68 headers_ = headers; | 68 headers_ = headers; |
69 } | 69 } |
70 | 70 |
71 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 71 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
72 size_t length, | 72 size_t length, |
73 bool fin) OVERRIDE { | 73 bool fin) override { |
74 ADD_FAILURE() << "Unexpected OnDataFrameHeader call."; | 74 ADD_FAILURE() << "Unexpected OnDataFrameHeader call."; |
75 } | 75 } |
76 | 76 |
77 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 77 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
78 const char* data, | 78 const char* data, |
79 size_t len, | 79 size_t len, |
80 bool fin) OVERRIDE { | 80 bool fin) override { |
81 LOG(FATAL) << "Unexpected OnStreamFrameData call."; | 81 LOG(FATAL) << "Unexpected OnStreamFrameData call."; |
82 } | 82 } |
83 | 83 |
84 virtual void OnSettings(bool clear_persisted) OVERRIDE {} | 84 virtual void OnSettings(bool clear_persisted) override {} |
85 | 85 |
86 virtual void OnSetting(SpdySettingsIds id, | 86 virtual void OnSetting(SpdySettingsIds id, |
87 uint8 flags, | 87 uint8 flags, |
88 uint32 value) OVERRIDE { | 88 uint32 value) override { |
89 setting_count_++; | 89 setting_count_++; |
90 } | 90 } |
91 | 91 |
92 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE {} | 92 virtual void OnPing(SpdyPingId unique_id, bool is_ack) override {} |
93 | 93 |
94 virtual void OnRstStream(SpdyStreamId stream_id, | 94 virtual void OnRstStream(SpdyStreamId stream_id, |
95 SpdyRstStreamStatus status) OVERRIDE { | 95 SpdyRstStreamStatus status) override { |
96 } | 96 } |
97 | 97 |
98 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 98 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
99 SpdyGoAwayStatus status) OVERRIDE { | 99 SpdyGoAwayStatus status) override { |
100 } | 100 } |
101 | 101 |
102 bool OnCredentialFrameData(const char*, size_t) { | 102 bool OnCredentialFrameData(const char*, size_t) { |
103 LOG(FATAL) << "Unexpected OnCredentialFrameData call."; | 103 LOG(FATAL) << "Unexpected OnCredentialFrameData call."; |
104 return false; | 104 return false; |
105 } | 105 } |
106 | 106 |
107 void OnDataFrameHeader(const SpdyFrame* frame) { | 107 void OnDataFrameHeader(const SpdyFrame* frame) { |
108 LOG(FATAL) << "Unexpected OnDataFrameHeader call."; | 108 LOG(FATAL) << "Unexpected OnDataFrameHeader call."; |
109 } | 109 } |
110 | 110 |
111 void OnRstStream(const SpdyFrame& frame) {} | 111 void OnRstStream(const SpdyFrame& frame) {} |
112 void OnGoAway(const SpdyFrame& frame) {} | 112 void OnGoAway(const SpdyFrame& frame) {} |
113 void OnPing(const SpdyFrame& frame) {} | 113 void OnPing(const SpdyFrame& frame) {} |
114 virtual void OnWindowUpdate(SpdyStreamId stream_id, | 114 virtual void OnWindowUpdate(SpdyStreamId stream_id, |
115 uint32 delta_window_size) OVERRIDE {} | 115 uint32 delta_window_size) override {} |
116 | 116 |
117 virtual void OnPushPromise(SpdyStreamId stream_id, | 117 virtual void OnPushPromise(SpdyStreamId stream_id, |
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 { | 128 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) override { |
129 return true; | 129 return true; |
130 } | 130 } |
131 | 131 |
132 void OnCredential(const SpdyFrame& frame) {} | 132 void OnCredential(const SpdyFrame& frame) {} |
133 | 133 |
134 // Convenience function which runs a framer simulation with particular input. | 134 // Convenience function which runs a framer simulation with particular input. |
135 void SimulateInFramer(const unsigned char* input, size_t size) { | 135 void SimulateInFramer(const unsigned char* input, size_t size) { |
136 buffered_spdy_framer_.set_visitor(this); | 136 buffered_spdy_framer_.set_visitor(this); |
137 size_t input_remaining = size; | 137 size_t input_remaining = size; |
138 const char* input_ptr = reinterpret_cast<const char*>(input); | 138 const char* input_ptr = reinterpret_cast<const char*>(input); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 EXPECT_EQ(0, visitor.syn_frame_count_); | 332 EXPECT_EQ(0, visitor.syn_frame_count_); |
333 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 333 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
334 EXPECT_EQ(0, visitor.headers_frame_count_); | 334 EXPECT_EQ(0, visitor.headers_frame_count_); |
335 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 335 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
336 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 336 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
337 EXPECT_EQ(1u, visitor.header_stream_id_); | 337 EXPECT_EQ(1u, visitor.header_stream_id_); |
338 EXPECT_EQ(2u, visitor.promised_stream_id_); | 338 EXPECT_EQ(2u, visitor.promised_stream_id_); |
339 } | 339 } |
340 | 340 |
341 } // namespace net | 341 } // namespace net |
OLD | NEW |