Index: net/spdy/spdy_header_block_test.cc |
diff --git a/net/spdy/spdy_header_block_test.cc b/net/spdy/spdy_header_block_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c2568aaa60805476cf56c59aa616c84d30795279 |
--- /dev/null |
+++ b/net/spdy/spdy_header_block_test.cc |
@@ -0,0 +1,90 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/spdy/spdy_header_block.h" |
+ |
+#include <utility> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/values.h" |
+#include "net/log/net_log.h" |
+#include "net/spdy/spdy_test_utils.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using std::make_pair; |
+using std::string; |
+using ::testing::ElementsAre; |
+ |
+namespace net { |
+ |
+std::pair<StringPiece, StringPiece> Pair(StringPiece k, StringPiece v) { |
+ return make_pair(k, v); |
+} |
+ |
+// This test verifies that SpdyHeaderBlock behaves correctly when empty. |
+TEST(SpdyHeaderBlockTest, EmptyBlock) { |
+ SpdyHeaderBlock block; |
+ EXPECT_TRUE(block.empty()); |
+ EXPECT_EQ(0u, block.size()); |
+ EXPECT_EQ(block.end(), block.find("foo")); |
+ EXPECT_TRUE(block.end() == block.begin()); |
+ |
+ // Should have no effect. |
+ block.erase("bar"); |
+} |
+ |
+// This test verifies that headers can be set in a variety of ways. |
+TEST(SpdyHeaderBlockTest, AddHeaders) { |
+ SpdyHeaderBlock block1; |
+ block1["foo"] = string(300, 'x'); |
+ block1["bar"] = "baz"; |
+ block1.ReplaceOrAppendHeader("qux", "qux1"); |
+ block1["qux"] = "qux2"; |
+ block1.insert(make_pair("key", "value")); |
+ |
+ EXPECT_EQ(Pair("foo", string(300, 'x')), *block1.find("foo")); |
+ EXPECT_EQ("baz", block1["bar"]); |
+ string qux("qux"); |
+ EXPECT_EQ("qux2", block1[qux]); |
+ EXPECT_EQ(Pair("key", "value"), *block1.find("key")); |
+ |
+ block1.erase("key"); |
+ EXPECT_EQ(block1.end(), block1.find("key")); |
+} |
+ |
+// This test verifies that SpdyHeaderBlock can be copied. |
+TEST(SpdyHeaderBlockTest, CopyBlocks) { |
+ SpdyHeaderBlock block1; |
+ block1["foo"] = string(300, 'x'); |
+ block1["bar"] = "baz"; |
+ block1.ReplaceOrAppendHeader("qux", "qux1"); |
+ |
+ SpdyHeaderBlock block2; |
+ block2 = block1; |
+ |
+ SpdyHeaderBlock block3(block1); |
+ |
+ EXPECT_THAT(block1, ElementsAre(Pair("foo", string(300, 'x')), |
+ Pair("bar", "baz"), Pair("qux", "qux1"))); |
+ EXPECT_THAT(block2, ElementsAre(Pair("foo", string(300, 'x')), |
+ Pair("bar", "baz"), Pair("qux", "qux1"))); |
+ EXPECT_THAT(block3, ElementsAre(Pair("foo", string(300, 'x')), |
+ Pair("bar", "baz"), Pair("qux", "qux1"))); |
+} |
+ |
+TEST(SpdyHeaderBlockTest, ToNetLogParamAndBackAgain) { |
+ SpdyHeaderBlock headers; |
+ headers["A"] = "a"; |
+ headers["B"] = "b"; |
+ |
+ scoped_ptr<base::Value> event_param(SpdyHeaderBlockNetLogCallback( |
+ &headers, NetLogCaptureMode::IncludeCookiesAndCredentials())); |
+ |
+ SpdyHeaderBlock headers2; |
+ ASSERT_TRUE(SpdyHeaderBlockFromNetLogParam(event_param.get(), &headers2)); |
+ EXPECT_EQ(headers, headers2); |
+} |
+ |
+} // namespace net |