Update QuickOffice ids.
[chromium-blink-merge.git] / net / spdy / hpack_encoder_test.cc
blobd02e27610b43e625add5741617bfbab933450fd5
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/hpack_encoder.h"
7 #include <map>
8 #include <string>
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace net {
14 namespace {
16 using std::string;
18 // Test that EncoderHeaderSet() simply encodes everything as literals
19 // without indexing.
20 TEST(HpackEncoderTest, Basic) {
21 HpackEncoder encoder(kuint32max);
23 std::map<string, string> header_set1;
24 header_set1["name1"] = "value1";
25 header_set1["name2"] = "value2";
27 string encoded_header_set1;
28 EXPECT_TRUE(encoder.EncodeHeaderSet(header_set1, &encoded_header_set1));
29 EXPECT_EQ("\x40\x05name1\x06value1"
30 "\x40\x05name2\x06value2", encoded_header_set1);
32 std::map<string, string> header_set2;
33 header_set2["name2"] = "different-value";
34 header_set2["name3"] = "value3";
36 string encoded_header_set2;
37 EXPECT_TRUE(encoder.EncodeHeaderSet(header_set2, &encoded_header_set2));
38 EXPECT_EQ("\x40\x05name2\x0f" "different-value"
39 "\x40\x05name3\x06value3", encoded_header_set2);
42 // Test that trying to encode a header set with a too-long header
43 // field will fail.
44 TEST(HpackEncoderTest, HeaderTooLarge) {
45 HpackEncoder encoder(10);
47 std::map<string, string> header_set;
48 header_set["name1"] = "too-long value";
49 header_set["name2"] = "value2";
51 // TODO(akalin): Verify that the encoder did not attempt to encode
52 // the second header field.
53 string encoded_header_set;
54 EXPECT_FALSE(encoder.EncodeHeaderSet(header_set, &encoded_header_set));
57 } // namespace
59 } // namespace net