| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 void set_allow_huffman_compression(bool allow) { | 51 void set_allow_huffman_compression(bool allow) { |
| 52 encoder_->allow_huffman_compression_ = allow; | 52 encoder_->allow_huffman_compression_ = allow; |
| 53 } | 53 } |
| 54 void EmitString(StringPiece str) { | 54 void EmitString(StringPiece str) { |
| 55 encoder_->EmitString(str); | 55 encoder_->EmitString(str); |
| 56 } | 56 } |
| 57 void TakeString(string* out) { | 57 void TakeString(string* out) { |
| 58 encoder_->output_stream_.TakeString(out); | 58 encoder_->output_stream_.TakeString(out); |
| 59 } | 59 } |
| 60 void UpdateCharacterCounts(StringPiece str) { |
| 61 encoder_->UpdateCharacterCounts(str); |
| 62 } |
| 60 static void CookieToCrumbs(StringPiece cookie, | 63 static void CookieToCrumbs(StringPiece cookie, |
| 61 std::vector<StringPiece>* out) { | 64 std::vector<StringPiece>* out) { |
| 62 Representations tmp; | 65 Representations tmp; |
| 63 HpackEncoder::CookieToCrumbs(make_pair("", cookie), &tmp); | 66 HpackEncoder::CookieToCrumbs(make_pair("", cookie), &tmp); |
| 64 | 67 |
| 65 out->clear(); | 68 out->clear(); |
| 66 for (size_t i = 0; i != tmp.size(); ++i) { | 69 for (size_t i = 0; i != tmp.size(); ++i) { |
| 67 out->push_back(tmp[i].second); | 70 out->push_back(tmp[i].second); |
| 68 } | 71 } |
| 69 } | 72 } |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 peer.CookieToCrumbs("baz=bing", &out); | 416 peer.CookieToCrumbs("baz=bing", &out); |
| 414 EXPECT_THAT(out, ElementsAre("baz=bing")); | 417 EXPECT_THAT(out, ElementsAre("baz=bing")); |
| 415 | 418 |
| 416 peer.CookieToCrumbs("", &out); | 419 peer.CookieToCrumbs("", &out); |
| 417 EXPECT_THAT(out, ElementsAre("")); | 420 EXPECT_THAT(out, ElementsAre("")); |
| 418 | 421 |
| 419 peer.CookieToCrumbs("foo;bar; baz;bing;", &out); | 422 peer.CookieToCrumbs("foo;bar; baz;bing;", &out); |
| 420 EXPECT_THAT(out, ElementsAre("foo", "bar", "baz", "bing", "")); | 423 EXPECT_THAT(out, ElementsAre("foo", "bar", "baz", "bing", "")); |
| 421 } | 424 } |
| 422 | 425 |
| 426 TEST_F(HpackEncoderTest, UpdateCharacterCounts) { |
| 427 std::vector<size_t> counts(256, 0); |
| 428 size_t total_counts = 0; |
| 429 encoder_.SetCharCountsStorage(&counts, &total_counts); |
| 430 |
| 431 char kTestString[] = "foo\0\1\xff""boo"; |
| 432 peer_.UpdateCharacterCounts( |
| 433 StringPiece(kTestString, arraysize(kTestString) - 1)); |
| 434 |
| 435 std::vector<size_t> expect(256, 0); |
| 436 expect[static_cast<uint8>('f')] = 1; |
| 437 expect[static_cast<uint8>('o')] = 4; |
| 438 expect[static_cast<uint8>('\0')] = 1; |
| 439 expect[static_cast<uint8>('\1')] = 1; |
| 440 expect[static_cast<uint8>('\xff')] = 1; |
| 441 expect[static_cast<uint8>('b')] = 1; |
| 442 |
| 443 EXPECT_EQ(expect, counts); |
| 444 EXPECT_EQ(9u, total_counts); |
| 445 } |
| 446 |
| 423 } // namespace | 447 } // namespace |
| 424 | 448 |
| 425 } // namespace net | 449 } // namespace net |
| OLD | NEW |