Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: net/spdy/spdy_header_block_test.cc

Issue 1357953002: Replace the existing SpdyHeaderBlock typedef with a class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add NET_EXPORT to fix compile error on win_chromium_compile_dbg_ng. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_header_block.cc ('k') | net/spdy/spdy_header_block_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "net/spdy/spdy_header_block.h"
6
7 #include <utility>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "net/log/net_log.h"
12 #include "net/spdy/spdy_test_utils.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using std::make_pair;
17 using std::string;
18 using ::testing::ElementsAre;
19
20 namespace net {
21
22 std::pair<StringPiece, StringPiece> Pair(StringPiece k, StringPiece v) {
23 return make_pair(k, v);
24 }
25
26 // This test verifies that SpdyHeaderBlock behaves correctly when empty.
27 TEST(SpdyHeaderBlockTest, EmptyBlock) {
28 SpdyHeaderBlock block;
29 EXPECT_TRUE(block.empty());
30 EXPECT_EQ(0u, block.size());
31 EXPECT_EQ(block.end(), block.find("foo"));
32 EXPECT_TRUE(block.end() == block.begin());
33
34 // Should have no effect.
35 block.erase("bar");
36 }
37
38 // This test verifies that headers can be set in a variety of ways.
39 TEST(SpdyHeaderBlockTest, AddHeaders) {
40 SpdyHeaderBlock block1;
41 block1["foo"] = string(300, 'x');
42 block1["bar"] = "baz";
43 block1.ReplaceOrAppendHeader("qux", "qux1");
44 block1["qux"] = "qux2";
45 block1.insert(make_pair("key", "value"));
46
47 EXPECT_EQ(Pair("foo", string(300, 'x')), *block1.find("foo"));
48 EXPECT_EQ("baz", block1["bar"]);
49 string qux("qux");
50 EXPECT_EQ("qux2", block1[qux]);
51 EXPECT_EQ(Pair("key", "value"), *block1.find("key"));
52
53 block1.erase("key");
54 EXPECT_EQ(block1.end(), block1.find("key"));
55 }
56
57 // This test verifies that SpdyHeaderBlock can be copied.
58 TEST(SpdyHeaderBlockTest, CopyBlocks) {
59 SpdyHeaderBlock block1;
60 block1["foo"] = string(300, 'x');
61 block1["bar"] = "baz";
62 block1.ReplaceOrAppendHeader("qux", "qux1");
63
64 SpdyHeaderBlock block2;
65 block2 = block1;
66
67 SpdyHeaderBlock block3(block1);
68
69 EXPECT_THAT(block1, ElementsAre(Pair("foo", string(300, 'x')),
70 Pair("bar", "baz"), Pair("qux", "qux1")));
71 EXPECT_THAT(block2, ElementsAre(Pair("foo", string(300, 'x')),
72 Pair("bar", "baz"), Pair("qux", "qux1")));
73 EXPECT_THAT(block3, ElementsAre(Pair("foo", string(300, 'x')),
74 Pair("bar", "baz"), Pair("qux", "qux1")));
75 }
76
77 TEST(SpdyHeaderBlockTest, ToNetLogParamAndBackAgain) {
78 SpdyHeaderBlock headers;
79 headers["A"] = "a";
80 headers["B"] = "b";
81
82 scoped_ptr<base::Value> event_param(SpdyHeaderBlockNetLogCallback(
83 &headers, NetLogCaptureMode::IncludeCookiesAndCredentials()));
84
85 SpdyHeaderBlock headers2;
86 ASSERT_TRUE(SpdyHeaderBlockFromNetLogParam(event_param.get(), &headers2));
87 EXPECT_EQ(headers, headers2);
88 }
89
90 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_header_block.cc ('k') | net/spdy/spdy_header_block_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698