Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: net/spdy/buffered_spdy_framer_spdy3_unittest.cc

Issue 9582034: Fork SPDY/2 and SPDY/3 versions of our SPDY tests, in preparation for landing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix merge bug Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 7 #include "net/spdy/spdy_test_util_spdy3.h"
8 #include "testing/platform_test.h" 8 #include "testing/platform_test.h"
9 9
10 using namespace net::test_spdy3;
11
10 namespace spdy { 12 namespace spdy {
11 13
12 namespace test { 14 namespace {
13 15
14 class TestBufferedSpdyVisitor : public BufferedSpdyFramerVisitorInterface { 16 class TestBufferedSpdyVisitor : public BufferedSpdyFramerVisitorInterface {
15 public: 17 public:
16 TestBufferedSpdyVisitor() 18 TestBufferedSpdyVisitor()
17 : error_count_(0), 19 : error_count_(0),
18 syn_frame_count_(0), 20 syn_frame_count_(0),
19 syn_reply_frame_count_(0), 21 syn_reply_frame_count_(0),
20 headers_frame_count_(0), 22 headers_frame_count_(0),
21 header_stream_id_(-1) { 23 header_stream_id_(-1) {
22 } 24 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 int syn_reply_frame_count_; 126 int syn_reply_frame_count_;
125 int headers_frame_count_; 127 int headers_frame_count_;
126 128
127 // Header block streaming state: 129 // Header block streaming state:
128 SpdyStreamId header_stream_id_; 130 SpdyStreamId header_stream_id_;
129 131
130 // Headers from OnSyn, OnSynReply and OnHeaders for verification. 132 // Headers from OnSyn, OnSynReply and OnHeaders for verification.
131 SpdyHeaderBlock headers_; 133 SpdyHeaderBlock headers_;
132 }; 134 };
133 135
134 } // namespace test 136 } // namespace
135 137
136 } // namespace spdy 138 class BufferedSpdyFramerSpdy3Test : public PlatformTest {
137
138 using spdy::test::TestBufferedSpdyVisitor;
139
140 namespace spdy {
141
142 class BufferedSpdyFramerTest : public PlatformTest {
143 protected: 139 protected:
144 void EnableCompression(bool enabled) { 140 void EnableCompression(bool enabled) {
145 SpdyFramer::set_enable_compression_default(enabled); 141 SpdyFramer::set_enable_compression_default(enabled);
146 } 142 }
147 143
148 // Returns true if the two header blocks have equivalent content. 144 // Returns true if the two header blocks have equivalent content.
149 bool CompareHeaderBlocks(const SpdyHeaderBlock* expected, 145 bool CompareHeaderBlocks(const SpdyHeaderBlock* expected,
150 const SpdyHeaderBlock* actual) { 146 const SpdyHeaderBlock* actual) {
151 if (expected->size() != actual->size()) { 147 if (expected->size() != actual->size()) {
152 LOG(ERROR) << "Expected " << expected->size() << " headers; actually got " 148 LOG(ERROR) << "Expected " << expected->size() << " headers; actually got "
(...skipping 13 matching lines...) Expand all
166 << "' to have a value of '" << it->second 162 << "' to have a value of '" << it->second
167 << "'. The actual value received was '" << it2->second 163 << "'. The actual value received was '" << it2->second
168 << "'."; 164 << "'.";
169 return false; 165 return false;
170 } 166 }
171 } 167 }
172 return true; 168 return true;
173 } 169 }
174 }; 170 };
175 171
176 TEST_F(BufferedSpdyFramerTest, ReadSynStreamHeaderBlock) { 172 TEST_F(BufferedSpdyFramerSpdy3Test, ReadSynStreamHeaderBlock) {
177 EnableCompression(false); 173 EnableCompression(false);
178 174
179 SpdyHeaderBlock headers; 175 SpdyHeaderBlock headers;
180 headers["aa"] = "vv"; 176 headers["aa"] = "vv";
181 headers["bb"] = "ww"; 177 headers["bb"] = "ww";
182 BufferedSpdyFramer framer; 178 BufferedSpdyFramer framer;
183 scoped_ptr<SpdySynStreamControlFrame> control_frame( 179 scoped_ptr<SpdySynStreamControlFrame> control_frame(
184 framer.CreateSynStream(1, // stream_id 180 framer.CreateSynStream(1, // stream_id
185 0, // associated_stream_id 181 0, // associated_stream_id
186 1, // priority 182 1, // priority
187 CONTROL_FLAG_NONE, 183 CONTROL_FLAG_NONE,
188 true, // compress 184 true, // compress
189 &headers)); 185 &headers));
190 EXPECT_TRUE(control_frame.get() != NULL); 186 EXPECT_TRUE(control_frame.get() != NULL);
191 187
192 TestBufferedSpdyVisitor visitor; 188 TestBufferedSpdyVisitor visitor;
193 visitor.SimulateInFramer( 189 visitor.SimulateInFramer(
194 reinterpret_cast<unsigned char*>(control_frame.get()->data()), 190 reinterpret_cast<unsigned char*>(control_frame.get()->data()),
195 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 191 control_frame.get()->length() + SpdyControlFrame::kHeaderSize);
196 EXPECT_EQ(0, visitor.error_count_); 192 EXPECT_EQ(0, visitor.error_count_);
197 EXPECT_EQ(1, visitor.syn_frame_count_); 193 EXPECT_EQ(1, visitor.syn_frame_count_);
198 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 194 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
199 EXPECT_EQ(0, visitor.headers_frame_count_); 195 EXPECT_EQ(0, visitor.headers_frame_count_);
200 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 196 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
201 } 197 }
202 198
203 TEST_F(BufferedSpdyFramerTest, ReadSynReplyHeaderBlock) { 199 TEST_F(BufferedSpdyFramerSpdy3Test, ReadSynReplyHeaderBlock) {
204 EnableCompression(false); 200 EnableCompression(false);
205 201
206 SpdyHeaderBlock headers; 202 SpdyHeaderBlock headers;
207 headers["alpha"] = "beta"; 203 headers["alpha"] = "beta";
208 headers["gamma"] = "delta"; 204 headers["gamma"] = "delta";
209 BufferedSpdyFramer framer; 205 BufferedSpdyFramer framer;
210 scoped_ptr<SpdySynReplyControlFrame> control_frame( 206 scoped_ptr<SpdySynReplyControlFrame> control_frame(
211 framer.CreateSynReply(1, // stream_id 207 framer.CreateSynReply(1, // stream_id
212 CONTROL_FLAG_NONE, 208 CONTROL_FLAG_NONE,
213 true, // compress 209 true, // compress
214 &headers)); 210 &headers));
215 EXPECT_TRUE(control_frame.get() != NULL); 211 EXPECT_TRUE(control_frame.get() != NULL);
216 212
217 TestBufferedSpdyVisitor visitor; 213 TestBufferedSpdyVisitor visitor;
218 visitor.SimulateInFramer( 214 visitor.SimulateInFramer(
219 reinterpret_cast<unsigned char*>(control_frame.get()->data()), 215 reinterpret_cast<unsigned char*>(control_frame.get()->data()),
220 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 216 control_frame.get()->length() + SpdyControlFrame::kHeaderSize);
221 EXPECT_EQ(0, visitor.error_count_); 217 EXPECT_EQ(0, visitor.error_count_);
222 EXPECT_EQ(0, visitor.syn_frame_count_); 218 EXPECT_EQ(0, visitor.syn_frame_count_);
223 EXPECT_EQ(1, visitor.syn_reply_frame_count_); 219 EXPECT_EQ(1, visitor.syn_reply_frame_count_);
224 EXPECT_EQ(0, visitor.headers_frame_count_); 220 EXPECT_EQ(0, visitor.headers_frame_count_);
225 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 221 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
226 } 222 }
227 223
228 TEST_F(BufferedSpdyFramerTest, ReadHeadersHeaderBlock) { 224 TEST_F(BufferedSpdyFramerSpdy3Test, ReadHeadersHeaderBlock) {
229 EnableCompression(false); 225 EnableCompression(false);
230 226
231 SpdyHeaderBlock headers; 227 SpdyHeaderBlock headers;
232 headers["alpha"] = "beta"; 228 headers["alpha"] = "beta";
233 headers["gamma"] = "delta"; 229 headers["gamma"] = "delta";
234 BufferedSpdyFramer framer; 230 BufferedSpdyFramer framer;
235 scoped_ptr<SpdyHeadersControlFrame> control_frame( 231 scoped_ptr<SpdyHeadersControlFrame> control_frame(
236 framer.CreateHeaders(1, // stream_id 232 framer.CreateHeaders(1, // stream_id
237 CONTROL_FLAG_NONE, 233 CONTROL_FLAG_NONE,
238 true, // compress 234 true, // compress
239 &headers)); 235 &headers));
240 EXPECT_TRUE(control_frame.get() != NULL); 236 EXPECT_TRUE(control_frame.get() != NULL);
241 237
242 TestBufferedSpdyVisitor visitor; 238 TestBufferedSpdyVisitor visitor;
243 visitor.SimulateInFramer( 239 visitor.SimulateInFramer(
244 reinterpret_cast<unsigned char*>(control_frame.get()->data()), 240 reinterpret_cast<unsigned char*>(control_frame.get()->data()),
245 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 241 control_frame.get()->length() + SpdyControlFrame::kHeaderSize);
246 EXPECT_EQ(0, visitor.error_count_); 242 EXPECT_EQ(0, visitor.error_count_);
247 EXPECT_EQ(0, visitor.syn_frame_count_); 243 EXPECT_EQ(0, visitor.syn_frame_count_);
248 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 244 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
249 EXPECT_EQ(1, visitor.headers_frame_count_); 245 EXPECT_EQ(1, visitor.headers_frame_count_);
250 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 246 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
251 } 247 }
252 } // namespace spdy 248 } // namespace spdy
OLDNEW
« no previous file with comments | « net/spdy/buffered_spdy_framer_spdy2_unittest.cc ('k') | net/spdy/buffered_spdy_framer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698