OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include <string> | |
6 | |
7 #include "net/quic/quic_spdy_compressor.h" | |
8 #include "net/quic/quic_spdy_decompressor.h" | |
9 #include "net/quic/spdy_utils.h" | |
10 #include "net/quic/test_tools/quic_test_utils.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using std::string; | |
14 | |
15 namespace net { | |
16 namespace test { | |
17 namespace { | |
18 | |
19 class QuicSpdyDecompressorTest : public ::testing::Test { | |
20 protected: | |
21 QuicSpdyDecompressor decompressor_; | |
22 QuicSpdyCompressor compressor_; | |
23 TestDecompressorVisitor visitor_; | |
24 }; | |
25 | |
26 TEST_F(QuicSpdyDecompressorTest, Decompress) { | |
27 SpdyHeaderBlock headers; | |
28 headers[":host"] = "www.google.com"; | |
29 headers[":path"] = "/index.hml"; | |
30 headers[":scheme"] = "https"; | |
31 | |
32 EXPECT_EQ(1u, decompressor_.current_header_id()); | |
33 string compressed_headers = compressor_.CompressHeaders(headers).substr(4); | |
34 EXPECT_EQ(compressed_headers.length(), | |
35 decompressor_.DecompressData(compressed_headers, &visitor_)); | |
36 | |
37 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers), visitor_.data()); | |
38 EXPECT_EQ(2u, decompressor_.current_header_id()); | |
39 } | |
40 | |
41 TEST_F(QuicSpdyDecompressorTest, DecompressPartial) { | |
42 SpdyHeaderBlock headers; | |
43 headers[":host"] = "www.google.com"; | |
44 headers[":path"] = "/index.hml"; | |
45 headers[":scheme"] = "https"; | |
46 string compressed_headers = compressor_.CompressHeaders(headers).substr(4); | |
47 | |
48 for (size_t i = 0; i < compressed_headers.length(); ++i) { | |
49 QuicSpdyDecompressor decompressor; | |
50 TestDecompressorVisitor visitor; | |
51 | |
52 EXPECT_EQ(1u, decompressor.current_header_id()); | |
53 | |
54 string partial_compressed_headers = compressed_headers.substr(0, i); | |
55 EXPECT_EQ(partial_compressed_headers.length(), | |
56 decompressor.DecompressData(partial_compressed_headers, | |
57 &visitor)); | |
58 EXPECT_EQ(1u, decompressor.current_header_id()) << "i: " << i; | |
59 | |
60 string remaining_compressed_headers = | |
61 compressed_headers.substr(partial_compressed_headers.length()); | |
62 EXPECT_EQ(remaining_compressed_headers.length(), | |
63 decompressor.DecompressData(remaining_compressed_headers, | |
64 &visitor)); | |
65 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers), visitor.data()); | |
66 | |
67 EXPECT_EQ(2u, decompressor.current_header_id()); | |
68 } | |
69 } | |
70 | |
71 TEST_F(QuicSpdyDecompressorTest, DecompressAndIgnoreTrailingData) { | |
72 SpdyHeaderBlock headers; | |
73 headers[":host"] = "www.google.com"; | |
74 headers[":path"] = "/index.hml"; | |
75 headers[":scheme"] = "https"; | |
76 | |
77 string compressed_headers = compressor_.CompressHeaders(headers).substr(4); | |
78 EXPECT_EQ(compressed_headers.length(), | |
79 decompressor_.DecompressData(compressed_headers + "abc123", | |
80 &visitor_)); | |
81 | |
82 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers), visitor_.data()); | |
83 } | |
84 | |
85 TEST_F(QuicSpdyDecompressorTest, DecompressError) { | |
86 SpdyHeaderBlock headers; | |
87 headers[":host"] = "www.google.com"; | |
88 headers[":path"] = "/index.hml"; | |
89 headers[":scheme"] = "https"; | |
90 | |
91 EXPECT_EQ(1u, decompressor_.current_header_id()); | |
92 string compressed_headers = compressor_.CompressHeaders(headers).substr(4); | |
93 compressed_headers[compressed_headers.length() - 1] ^= 0x01; | |
94 EXPECT_NE(compressed_headers.length(), | |
95 decompressor_.DecompressData(compressed_headers, &visitor_)); | |
96 | |
97 EXPECT_TRUE(visitor_.error()); | |
98 EXPECT_EQ("", visitor_.data()); | |
99 } | |
100 | |
101 } // namespace | |
102 } // namespace test | |
103 } // namespace net | |
OLD | NEW |