OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/hpack_encoder.h" | 5 #include "net/spdy/hpack_encoder.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 static void CookieToCrumbs(StringPiece cookie, | 63 static void CookieToCrumbs(StringPiece cookie, |
64 std::vector<StringPiece>* out) { | 64 std::vector<StringPiece>* out) { |
65 Representations tmp; | 65 Representations tmp; |
66 HpackEncoder::CookieToCrumbs(make_pair("", cookie), &tmp); | 66 HpackEncoder::CookieToCrumbs(make_pair("", cookie), &tmp); |
67 | 67 |
68 out->clear(); | 68 out->clear(); |
69 for (size_t i = 0; i != tmp.size(); ++i) { | 69 for (size_t i = 0; i != tmp.size(); ++i) { |
70 out->push_back(tmp[i].second); | 70 out->push_back(tmp[i].second); |
71 } | 71 } |
72 } | 72 } |
| 73 static void DecomposeRepresentation(StringPiece value, |
| 74 std::vector<StringPiece>* out) { |
| 75 Representations tmp; |
| 76 HpackEncoder::DecomposeRepresentation(make_pair("foobar", value), &tmp); |
| 77 |
| 78 out->clear(); |
| 79 for (size_t i = 0; i != tmp.size(); ++i) { |
| 80 out->push_back(tmp[i].second); |
| 81 } |
| 82 } |
73 | 83 |
74 private: | 84 private: |
75 HpackEncoder* encoder_; | 85 HpackEncoder* encoder_; |
76 }; | 86 }; |
77 | 87 |
78 } // namespace test | 88 } // namespace test |
79 | 89 |
80 namespace { | 90 namespace { |
81 | 91 |
82 using std::map; | 92 using std::map; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 expect[static_cast<uint8>('o')] = 4; | 416 expect[static_cast<uint8>('o')] = 4; |
407 expect[static_cast<uint8>('\0')] = 1; | 417 expect[static_cast<uint8>('\0')] = 1; |
408 expect[static_cast<uint8>('\1')] = 1; | 418 expect[static_cast<uint8>('\1')] = 1; |
409 expect[static_cast<uint8>('\xff')] = 1; | 419 expect[static_cast<uint8>('\xff')] = 1; |
410 expect[static_cast<uint8>('b')] = 1; | 420 expect[static_cast<uint8>('b')] = 1; |
411 | 421 |
412 EXPECT_EQ(expect, counts); | 422 EXPECT_EQ(expect, counts); |
413 EXPECT_EQ(9u, total_counts); | 423 EXPECT_EQ(9u, total_counts); |
414 } | 424 } |
415 | 425 |
| 426 TEST_F(HpackEncoderTest, DecomposeRepresentation) { |
| 427 test::HpackEncoderPeer peer(NULL); |
| 428 std::vector<StringPiece> out; |
| 429 |
| 430 peer.DecomposeRepresentation("", &out); |
| 431 EXPECT_THAT(out, ElementsAre("")); |
| 432 |
| 433 peer.DecomposeRepresentation("foobar", &out); |
| 434 EXPECT_THAT(out, ElementsAre("foobar")); |
| 435 |
| 436 peer.DecomposeRepresentation(StringPiece("foo\0bar", 7), &out); |
| 437 EXPECT_THAT(out, ElementsAre("foo", "bar")); |
| 438 |
| 439 peer.DecomposeRepresentation(StringPiece("\0foo\0bar", 8), &out); |
| 440 EXPECT_THAT(out, ElementsAre("", "foo", "bar")); |
| 441 |
| 442 peer.DecomposeRepresentation(StringPiece("foo\0bar\0", 8), &out); |
| 443 EXPECT_THAT(out, ElementsAre("foo", "bar", "")); |
| 444 |
| 445 peer.DecomposeRepresentation(StringPiece("\0foo\0bar\0", 9), &out); |
| 446 EXPECT_THAT(out, ElementsAre("", "foo", "bar", "")); |
| 447 } |
| 448 |
| 449 // Test that encoded headers do not have \0-delimited multiple values, as this |
| 450 // became disallowed in HTTP/2 draft-14. |
| 451 TEST_F(HpackEncoderTest, CrumbleNullByteDelimitedValue) { |
| 452 map<string, string> headers; |
| 453 // A header field to be crumbled: "spam: foo\0bar". |
| 454 headers["spam"] = string("foo\0bar", 7); |
| 455 |
| 456 ExpectIndexedLiteral("spam", "foo"); |
| 457 expected_.AppendPrefix(kLiteralIncrementalIndexOpcode); |
| 458 expected_.AppendUint32(62); |
| 459 expected_.AppendPrefix(kStringLiteralIdentityEncoded); |
| 460 expected_.AppendUint32(3); |
| 461 expected_.AppendBytes("bar"); |
| 462 CompareWithExpectedEncoding(headers); |
| 463 } |
| 464 |
416 } // namespace | 465 } // namespace |
417 | 466 |
418 } // namespace net | 467 } // namespace net |
OLD | NEW |