Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / spdy / spdy_pinnable_buffer_piece_test.cc
blob456e4a86defe745a7ee3471b97c4c90a48b0ab7a
1 // Copyright 2014 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_pinnable_buffer_piece.h"
7 #include "net/spdy/spdy_prefixed_buffer_reader.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace net {
12 namespace test {
14 using base::StringPiece;
16 class SpdyPinnableBufferPieceTest : public ::testing::Test {
17 protected:
18 SpdyPrefixedBufferReader Build(std::string prefix, std::string suffix) {
19 prefix_ = prefix;
20 suffix_ = suffix;
21 return SpdyPrefixedBufferReader(prefix_.data(), prefix_.length(),
22 suffix_.data(), suffix_.length());
24 std::string prefix_, suffix_;
27 TEST_F(SpdyPinnableBufferPieceTest, Pin) {
28 SpdyPrefixedBufferReader reader = Build("foobar", "");
29 SpdyPinnableBufferPiece piece;
30 EXPECT_TRUE(reader.ReadN(6, &piece));
32 // Piece points to underlying prefix storage.
33 EXPECT_EQ(StringPiece("foobar"), piece);
34 EXPECT_FALSE(piece.IsPinned());
35 EXPECT_EQ(prefix_.data(), piece.buffer());
37 piece.Pin();
39 // Piece now points to allocated storage.
40 EXPECT_EQ(StringPiece("foobar"), piece);
41 EXPECT_TRUE(piece.IsPinned());
42 EXPECT_NE(prefix_.data(), piece.buffer());
44 // Pinning again has no effect.
45 const char* buffer = piece.buffer();
46 piece.Pin();
47 EXPECT_EQ(buffer, piece.buffer());
50 TEST_F(SpdyPinnableBufferPieceTest, Swap) {
51 SpdyPrefixedBufferReader reader = Build("foobar", "");
52 SpdyPinnableBufferPiece piece1, piece2;
53 EXPECT_TRUE(reader.ReadN(4, &piece1));
54 EXPECT_TRUE(reader.ReadN(2, &piece2));
56 piece1.Pin();
58 EXPECT_EQ(StringPiece("foob"), piece1);
59 EXPECT_TRUE(piece1.IsPinned());
60 EXPECT_EQ(StringPiece("ar"), piece2);
61 EXPECT_FALSE(piece2.IsPinned());
63 piece1.Swap(&piece2);
65 EXPECT_EQ(StringPiece("ar"), piece1);
66 EXPECT_FALSE(piece1.IsPinned());
67 EXPECT_EQ(StringPiece("foob"), piece2);
68 EXPECT_TRUE(piece2.IsPinned());
70 SpdyPinnableBufferPiece empty;
71 piece2.Swap(&empty);
73 EXPECT_EQ(StringPiece(""), piece2);
74 EXPECT_FALSE(piece2.IsPinned());
77 } // namespace test
79 } // namespace net