| 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/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" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 enum SpdyProtocolTestTypes { | 14 enum SpdyProtocolTestTypes { |
| 15 SPDY2, | 15 SPDY2 = 2, |
| 16 SPDY3, | 16 SPDY3 = 3, |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 class SpdyProtocolTest | 23 class SpdyProtocolTest |
| 24 : public ::testing::TestWithParam<SpdyProtocolTestTypes> { | 24 : public ::testing::TestWithParam<SpdyProtocolTestTypes> { |
| 25 protected: | 25 protected: |
| 26 virtual void SetUp() { | 26 virtual void SetUp() { |
| 27 spdy_version_ = (GetParam() == SPDY2) ? 2 : 3; | 27 spdy_version_ = GetParam(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void TearDown() {} | 30 bool IsSpdy2() { return spdy_version_ == SPDY2; } |
| 31 | |
| 32 bool IsSpdy2() { return spdy_version_ < 3; } | |
| 33 | 31 |
| 34 // Version of SPDY protocol to be used. | 32 // Version of SPDY protocol to be used. |
| 35 int spdy_version_; | 33 int spdy_version_; |
| 36 }; | 34 }; |
| 37 | 35 |
| 38 //----------------------------------------------------------------------------- | |
| 39 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. | 36 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. |
| 40 INSTANTIATE_TEST_CASE_P(SpdyProtocolTests, | 37 INSTANTIATE_TEST_CASE_P(SpdyProtocolTests, |
| 41 SpdyProtocolTest, | 38 SpdyProtocolTest, |
| 42 ::testing::Values(SPDY2, SPDY3)); | 39 ::testing::Values(SPDY2, SPDY3)); |
| 43 | 40 |
| 44 // Test our protocol constants | 41 // Test our protocol constants |
| 45 TEST_P(SpdyProtocolTest, ProtocolConstants) { | 42 TEST_P(SpdyProtocolTest, ProtocolConstants) { |
| 46 EXPECT_EQ(8u, SpdyFrame::kHeaderSize); | 43 EXPECT_EQ(8u, SpdyFrame::kHeaderSize); |
| 47 EXPECT_EQ(8u, SpdyDataFrame::size()); | 44 EXPECT_EQ(8u, SpdyDataFrame::size()); |
| 48 EXPECT_EQ(8u, SpdyControlFrame::kHeaderSize); | 45 EXPECT_EQ(8u, SpdyControlFrame::kHeaderSize); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 type = static_cast<SpdyControlType>(type + 1)) { | 264 type = static_cast<SpdyControlType>(type + 1)) { |
| 268 frame.set_type(type); | 265 frame.set_type(type); |
| 269 if (type == SYN_STREAM || type == SYN_REPLY || type == HEADERS) { | 266 if (type == SYN_STREAM || type == SYN_REPLY || type == HEADERS) { |
| 270 EXPECT_TRUE(frame.has_header_block()); | 267 EXPECT_TRUE(frame.has_header_block()); |
| 271 } else { | 268 } else { |
| 272 EXPECT_FALSE(frame.has_header_block()); | 269 EXPECT_FALSE(frame.has_header_block()); |
| 273 } | 270 } |
| 274 } | 271 } |
| 275 } | 272 } |
| 276 | 273 |
| 277 //----------------------------------------------------------------------------- | |
| 278 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. | |
| 279 class SpdyProtocolDeathTest : public SpdyProtocolTest {}; | 274 class SpdyProtocolDeathTest : public SpdyProtocolTest {}; |
| 280 | 275 |
| 276 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. |
| 281 INSTANTIATE_TEST_CASE_P(SpdyProtocolDeathTests, | 277 INSTANTIATE_TEST_CASE_P(SpdyProtocolDeathTests, |
| 282 SpdyProtocolDeathTest, | 278 SpdyProtocolDeathTest, |
| 283 ::testing::Values(SPDY2, SPDY3)); | 279 ::testing::Values(SPDY2, SPDY3)); |
| 284 | 280 |
| 285 // Make sure that overflows both die in debug mode, and do not cause problems | 281 // Make sure that overflows both die in debug mode, and do not cause problems |
| 286 // in opt mode. Note: The EXPECT_DEBUG_DEATH call does not work on Win32 yet, | 282 // in opt mode. Note: The EXPECT_DEBUG_DEATH call does not work on Win32 yet, |
| 287 // so we comment it out. | 283 // so we comment it out. |
| 288 TEST_P(SpdyProtocolDeathTest, TestDataFrame) { | 284 TEST_P(SpdyProtocolDeathTest, TestDataFrame) { |
| 289 SpdyDataFrame frame; | 285 SpdyDataFrame frame; |
| 290 | 286 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 379 |
| 384 rst_frame->set_status( | 380 rst_frame->set_status( |
| 385 static_cast<SpdyStatusCodes>(INVALID - 1)); | 381 static_cast<SpdyStatusCodes>(INVALID - 1)); |
| 386 EXPECT_EQ(INVALID, rst_frame->status()); | 382 EXPECT_EQ(INVALID, rst_frame->status()); |
| 387 | 383 |
| 388 rst_frame->set_status(NUM_STATUS_CODES); | 384 rst_frame->set_status(NUM_STATUS_CODES); |
| 389 EXPECT_EQ(INVALID, rst_frame->status()); | 385 EXPECT_EQ(INVALID, rst_frame->status()); |
| 390 } | 386 } |
| 391 | 387 |
| 392 } // namespace net | 388 } // namespace net |
| OLD | NEW |