file_manager: Fix a bug where hosted documents could not be opened without active...
[chromium-blink-merge.git] / net / spdy / spdy_frame_builder_test.cc
blob014449b2e57673c0da459bff45be580422876a7b
1 // Copyright (c) 2013 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_frame_builder.h"
7 #include "net/spdy/spdy_framer.h"
8 #include "net/spdy/spdy_protocol.h"
9 #include "testing/platform_test.h"
11 namespace net {
13 TEST(SpdyFrameBuilderTestVersionAgnostic, GetWritableBuffer) {
14 const size_t builder_size = 10;
15 SpdyFrameBuilder builder(builder_size);
16 char* writable_buffer = builder.GetWritableBuffer(builder_size);
17 memset(writable_buffer, ~1, builder_size);
18 EXPECT_TRUE(builder.Seek(builder_size));
19 scoped_ptr<SpdyFrame> frame(builder.take());
20 char expected[builder_size];
21 memset(expected, ~1, builder_size);
22 EXPECT_EQ(base::StringPiece(expected, builder_size),
23 base::StringPiece(frame->data(), builder_size));
26 class SpdyFrameBuilderTest : public ::testing::TestWithParam<SpdyMajorVersion> {
27 protected:
28 virtual void SetUp() {
29 spdy_version_ = GetParam();
32 // Major version of SPDY protocol to be used.
33 SpdyMajorVersion spdy_version_;
36 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
37 INSTANTIATE_TEST_CASE_P(SpdyFrameBuilderTests,
38 SpdyFrameBuilderTest,
39 ::testing::Values(SPDY2, SPDY3, SPDY4));
41 TEST_P(SpdyFrameBuilderTest, RewriteLength) {
42 // Create an empty SETTINGS frame both via framer and manually via builder.
43 // The one created via builder is initially given the incorrect length, but
44 // then is corrected via RewriteLength().
45 SpdyFramer framer(spdy_version_);
46 SettingsMap settings;
47 scoped_ptr<SpdyFrame> expected(framer.CreateSettings(settings));
48 SpdyFrameBuilder builder(expected->size() + 1);
49 if (spdy_version_ < 4) {
50 builder.WriteControlFrameHeader(framer, SETTINGS, 0);
51 } else {
52 builder.WriteFramePrefix(framer, SETTINGS, 0, 0);
54 builder.WriteUInt32(0); // Write the number of settings.
55 EXPECT_TRUE(builder.GetWritableBuffer(1) != NULL);
56 builder.RewriteLength(framer);
57 scoped_ptr<SpdyFrame> built(builder.take());
58 EXPECT_EQ(base::StringPiece(expected->data(), expected->size()),
59 base::StringPiece(built->data(), expected->size()));
62 } // namespace net