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
3 // found in the LICENSE file.
5 #include "net/spdy/spdy_protocol.h"
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "net/spdy/spdy_bitmasks.h"
12 #include "net/spdy/spdy_framer.h"
13 #include "net/test/gtest_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 enum SpdyProtocolTestTypes
{
27 class SpdyProtocolTest
28 : public ::testing::TestWithParam
<SpdyProtocolTestTypes
> {
30 virtual void SetUp() {
31 spdy_version_
= GetParam();
34 // Version of SPDY protocol to be used.
38 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
39 INSTANTIATE_TEST_CASE_P(SpdyProtocolTests
,
41 ::testing::Values(SPDY2
, SPDY3
));
43 // Test our protocol constants
44 TEST_P(SpdyProtocolTest
, ProtocolConstants
) {
45 EXPECT_EQ(1, SYN_STREAM
);
46 EXPECT_EQ(2, SYN_REPLY
);
47 EXPECT_EQ(3, RST_STREAM
);
48 EXPECT_EQ(4, SETTINGS
);
52 EXPECT_EQ(8, HEADERS
);
53 EXPECT_EQ(9, WINDOW_UPDATE
);
54 EXPECT_EQ(10, CREDENTIAL
);
55 EXPECT_EQ(11, BLOCKED
);
56 EXPECT_EQ(12, PUSH_PROMISE
);
57 EXPECT_EQ(12, LAST_CONTROL_TYPE
);
58 EXPECT_EQ(std::numeric_limits
<int32
>::max(), kSpdyMaximumWindowSize
);
61 class SpdyProtocolDeathTest
: public SpdyProtocolTest
{};
63 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
64 INSTANTIATE_TEST_CASE_P(SpdyProtocolDeathTests
,
65 SpdyProtocolDeathTest
,
66 ::testing::Values(SPDY2
, SPDY3
));
68 TEST_P(SpdyProtocolDeathTest
, TestSpdySettingsAndIdOutOfBounds
) {
69 scoped_ptr
<SettingsFlagsAndId
> flags_and_id
;
71 EXPECT_DFATAL(flags_and_id
.reset(new SettingsFlagsAndId(1, ~0)),
72 "SPDY setting ID too large.");
73 // Make sure that we get expected values in opt mode.
74 if (flags_and_id
.get() != NULL
) {
75 EXPECT_EQ(1, flags_and_id
->flags());
76 EXPECT_EQ(static_cast<SpdyPingId
>(0xffffff), flags_and_id
->id());