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

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

Issue 8898003: Deprecate SpdyControlFrame::size in favor of SpdyControlFrame::kHeaderSize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/spdy_protocol.h" 5 #include "net/spdy/spdy_protocol.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "net/spdy/spdy_bitmasks.h" 8 #include "net/spdy/spdy_bitmasks.h"
9 #include "net/spdy/spdy_framer.h" 9 #include "net/spdy/spdy_framer.h"
10 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 using spdy::kLengthMask; 43 using spdy::kLengthMask;
44 using spdy::kSpdyProtocolVersion; 44 using spdy::kSpdyProtocolVersion;
45 using spdy::kStreamIdMask; 45 using spdy::kStreamIdMask;
46 46
47 namespace { 47 namespace {
48 48
49 // Test our protocol constants 49 // Test our protocol constants
50 TEST(SpdyProtocolTest, ProtocolConstants) { 50 TEST(SpdyProtocolTest, ProtocolConstants) {
51 EXPECT_EQ(8u, SpdyFrame::kHeaderSize); 51 EXPECT_EQ(8u, SpdyFrame::kHeaderSize);
52 EXPECT_EQ(8u, SpdyDataFrame::size()); 52 EXPECT_EQ(8u, SpdyDataFrame::size());
53 EXPECT_EQ(8u, SpdyControlFrame::size()); 53 EXPECT_EQ(8u, SpdyControlFrame::kHeaderSize);
54 EXPECT_EQ(18u, SpdySynStreamControlFrame::size()); 54 EXPECT_EQ(18u, SpdySynStreamControlFrame::size());
55 EXPECT_EQ(14u, SpdySynReplyControlFrame::size()); 55 EXPECT_EQ(14u, SpdySynReplyControlFrame::size());
56 EXPECT_EQ(16u, SpdyRstStreamControlFrame::size()); 56 EXPECT_EQ(16u, SpdyRstStreamControlFrame::size());
57 EXPECT_EQ(12u, SpdySettingsControlFrame::size()); 57 EXPECT_EQ(12u, SpdySettingsControlFrame::size());
58 EXPECT_EQ(8u, SpdyNoOpControlFrame::size()); 58 EXPECT_EQ(8u, SpdyNoOpControlFrame::size());
59 EXPECT_EQ(12u, SpdyPingControlFrame::size()); 59 EXPECT_EQ(12u, SpdyPingControlFrame::size());
60 EXPECT_EQ(12u, SpdyGoAwayControlFrame::size()); 60 EXPECT_EQ(12u, SpdyGoAwayControlFrame::size());
61 EXPECT_EQ(14u, SpdyHeadersControlFrame::size()); 61 EXPECT_EQ(14u, SpdyHeadersControlFrame::size());
62 EXPECT_EQ(16u, SpdyWindowUpdateControlFrame::size()); 62 EXPECT_EQ(16u, SpdyWindowUpdateControlFrame::size());
63 EXPECT_EQ(4u, sizeof(FlagsAndLength)); 63 EXPECT_EQ(4u, sizeof(FlagsAndLength));
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 EXPECT_EQ(parsed.flags(), ids[pos].flags()); 258 EXPECT_EQ(parsed.flags(), ids[pos].flags());
259 EXPECT_EQ(parsed.id(), ids[pos].id()); 259 EXPECT_EQ(parsed.id(), ids[pos].id());
260 EXPECT_EQ(value, static_cast<uint32>(pos)); 260 EXPECT_EQ(value, static_cast<uint32>(pos));
261 ++it; 261 ++it;
262 ++pos; 262 ++pos;
263 } 263 }
264 } 264 }
265 } 265 }
266 266
267 TEST(SpdyProtocolTest, HasHeaderBlock) { 267 TEST(SpdyProtocolTest, HasHeaderBlock) {
268 SpdyControlFrame frame(SpdyControlFrame::size()); 268 SpdyControlFrame frame(SpdyControlFrame::kHeaderSize);
269 for (SpdyControlType type = SYN_STREAM; 269 for (SpdyControlType type = SYN_STREAM;
270 type < NUM_CONTROL_FRAME_TYPES; 270 type < NUM_CONTROL_FRAME_TYPES;
271 type = static_cast<SpdyControlType>(type + 1)) { 271 type = static_cast<SpdyControlType>(type + 1)) {
272 frame.set_type(type); 272 frame.set_type(type);
273 if (type == SYN_STREAM || type == SYN_REPLY || type == HEADERS) { 273 if (type == SYN_STREAM || type == SYN_REPLY || type == HEADERS) {
274 EXPECT_TRUE(frame.has_header_block()); 274 EXPECT_TRUE(frame.has_header_block());
275 } else { 275 } else {
276 EXPECT_FALSE(frame.has_header_block()); 276 EXPECT_FALSE(frame.has_header_block());
277 } 277 }
278 } 278 }
(...skipping 22 matching lines...) Expand all
301 EXPECT_DEBUG_DEATH(frame.set_length(~0), ""); 301 EXPECT_DEBUG_DEATH(frame.set_length(~0), "");
302 #else 302 #else
303 EXPECT_DEATH(frame.set_length(~0), ""); 303 EXPECT_DEATH(frame.set_length(~0), "");
304 #endif 304 #endif
305 #endif 305 #endif
306 EXPECT_EQ(0, frame.flags()); 306 EXPECT_EQ(0, frame.flags());
307 } 307 }
308 308
309 TEST(SpdyProtocolDeathTest, TestSpdyControlFrameStreamId) { 309 TEST(SpdyProtocolDeathTest, TestSpdyControlFrameStreamId) {
310 SpdyControlFrame frame_store(SpdySynStreamControlFrame::size()); 310 SpdyControlFrame frame_store(SpdySynStreamControlFrame::size());
311 memset(frame_store.data(), '1', SpdyControlFrame::size()); 311 memset(frame_store.data(), '1', SpdyControlFrame::kHeaderSize);
312 SpdySynStreamControlFrame* frame = 312 SpdySynStreamControlFrame* frame =
313 reinterpret_cast<SpdySynStreamControlFrame*>(&frame_store); 313 reinterpret_cast<SpdySynStreamControlFrame*>(&frame_store);
314 314
315 // Set the stream ID to various values. 315 // Set the stream ID to various values.
316 frame->set_stream_id(0); 316 frame->set_stream_id(0);
317 EXPECT_EQ(0u, frame->stream_id()); 317 EXPECT_EQ(0u, frame->stream_id());
318 EXPECT_FALSE(frame->is_control_frame()); 318 EXPECT_FALSE(frame->is_control_frame());
319 frame->set_stream_id(kStreamIdMask); 319 frame->set_stream_id(kStreamIdMask);
320 EXPECT_EQ(kStreamIdMask, frame->stream_id()); 320 EXPECT_EQ(kStreamIdMask, frame->stream_id());
321 EXPECT_FALSE(frame->is_control_frame()); 321 EXPECT_FALSE(frame->is_control_frame());
322 } 322 }
323 323
324 TEST(SpdyProtocolDeathTest, TestSpdyControlFrameVersion) { 324 TEST(SpdyProtocolDeathTest, TestSpdyControlFrameVersion) {
325 const unsigned int kVersionMask = 0x7fff; 325 const unsigned int kVersionMask = 0x7fff;
326 SpdyControlFrame frame(SpdySynStreamControlFrame::size()); 326 SpdyControlFrame frame(SpdySynStreamControlFrame::size());
327 memset(frame.data(), '1', SpdyControlFrame::size()); 327 memset(frame.data(), '1', SpdyControlFrame::kHeaderSize);
328 328
329 // Set the version to various values, and make sure it does not affect the 329 // Set the version to various values, and make sure it does not affect the
330 // type. 330 // type.
331 frame.set_type(SYN_STREAM); 331 frame.set_type(SYN_STREAM);
332 frame.set_version(0); 332 frame.set_version(0);
333 EXPECT_EQ(0, frame.version()); 333 EXPECT_EQ(0, frame.version());
334 EXPECT_TRUE(frame.is_control_frame()); 334 EXPECT_TRUE(frame.is_control_frame());
335 EXPECT_EQ(SYN_STREAM, frame.type()); 335 EXPECT_EQ(SYN_STREAM, frame.type());
336 336
337 SpdySynStreamControlFrame* syn_stream = 337 SpdySynStreamControlFrame* syn_stream =
338 reinterpret_cast<SpdySynStreamControlFrame*>(&frame); 338 reinterpret_cast<SpdySynStreamControlFrame*>(&frame);
339 syn_stream->set_stream_id(~0 & kVersionMask); 339 syn_stream->set_stream_id(~0 & kVersionMask);
340 EXPECT_EQ(~0 & kVersionMask, syn_stream->stream_id()); 340 EXPECT_EQ(~0 & kVersionMask, syn_stream->stream_id());
341 EXPECT_TRUE(frame.is_control_frame()); 341 EXPECT_TRUE(frame.is_control_frame());
342 EXPECT_EQ(SYN_STREAM, frame.type()); 342 EXPECT_EQ(SYN_STREAM, frame.type());
343 } 343 }
344 344
345 TEST(SpdyProtocolDeathTest, TestSpdyControlFrameType) { 345 TEST(SpdyProtocolDeathTest, TestSpdyControlFrameType) {
346 SpdyControlFrame frame(SpdyControlFrame::size()); 346 SpdyControlFrame frame(SpdyControlFrame::kHeaderSize);
347 memset(frame.data(), 255, SpdyControlFrame::size()); 347 memset(frame.data(), 255, SpdyControlFrame::kHeaderSize);
348 348
349 // type() should be out of bounds. 349 // type() should be out of bounds.
350 EXPECT_FALSE(frame.AppearsToBeAValidControlFrame()); 350 EXPECT_FALSE(frame.AppearsToBeAValidControlFrame());
351 351
352 uint16 version = frame.version(); 352 uint16 version = frame.version();
353 353
354 for (int i = SYN_STREAM; i <= spdy::NOOP; ++i) { 354 for (int i = SYN_STREAM; i <= spdy::NOOP; ++i) {
355 frame.set_type(static_cast<SpdyControlType>(i)); 355 frame.set_type(static_cast<SpdyControlType>(i));
356 EXPECT_EQ(i, static_cast<int>(frame.type())); 356 EXPECT_EQ(i, static_cast<int>(frame.type()));
357 EXPECT_TRUE(frame.AppearsToBeAValidControlFrame()); 357 EXPECT_TRUE(frame.AppearsToBeAValidControlFrame());
(...skipping 15 matching lines...) Expand all
373 373
374 rst_frame->set_status( 374 rst_frame->set_status(
375 static_cast<spdy::SpdyStatusCodes>(spdy::INVALID - 1)); 375 static_cast<spdy::SpdyStatusCodes>(spdy::INVALID - 1));
376 EXPECT_EQ(spdy::INVALID, rst_frame->status()); 376 EXPECT_EQ(spdy::INVALID, rst_frame->status());
377 377
378 rst_frame->set_status(spdy::NUM_STATUS_CODES); 378 rst_frame->set_status(spdy::NUM_STATUS_CODES);
379 EXPECT_EQ(spdy::INVALID, rst_frame->status()); 379 EXPECT_EQ(spdy::INVALID, rst_frame->status());
380 } 380 }
381 381
382 } // namespace 382 } // namespace
OLDNEW
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698