15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/spdy/spdy_protocol.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <limits>
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/spdy/spdy_bitmasks.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/spdy/spdy_framer.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/test/gtest_util.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdyProtocolTestTypes {
195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SPDY2 = net::SPDY2,
205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SPDY3 = net::SPDY3,
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SpdyProtocolTest
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public ::testing::TestWithParam<SpdyProtocolTestTypes> {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUp() {
315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    spdy_version_ = static_cast<SpdyMajorVersion>(GetParam());
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Version of SPDY protocol to be used.
355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SpdyMajorVersion spdy_version_;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(SpdyProtocolTests,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        SpdyProtocolTest,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        ::testing::Values(SPDY2, SPDY3));
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SpdyProtocolDeathTest : public SpdyProtocolTest {};
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(SpdyProtocolDeathTests,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        SpdyProtocolDeathTest,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        ::testing::Values(SPDY2, SPDY3));
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_P(SpdyProtocolDeathTest, TestSpdySettingsAndIdOutOfBounds) {
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<SettingsFlagsAndId> flags_and_id;
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  EXPECT_DFATAL(flags_and_id.reset(new SettingsFlagsAndId(1, 0xFFFFFFFF)),
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                "SPDY setting ID too large.");
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Make sure that we get expected values in opt mode.
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (flags_and_id.get() != NULL) {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(1, flags_and_id->flags());
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(static_cast<SpdyPingId>(0xffffff), flags_and_id->id());
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
63