| 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_huffman_table.h" | 5 #include "net/spdy/hpack_huffman_table.h" |
| 6 | 6 |
| 7 #include <bitset> | 7 #include <bitset> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "net/spdy/hpack_constants.h" | 11 #include "net/spdy/hpack_constants.h" |
| 12 #include "net/spdy/hpack_input_stream.h" | 12 #include "net/spdy/hpack_input_stream.h" |
| 13 #include "net/spdy/hpack_output_stream.h" | 13 #include "net/spdy/hpack_output_stream.h" |
| 14 #include "net/spdy/spdy_test_utils.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using base::StringPiece; | 18 using base::StringPiece; |
| 19 using net::test::a2b_hex; |
| 18 using std::string; | 20 using std::string; |
| 19 using testing::ElementsAre; | 21 using testing::ElementsAre; |
| 20 using testing::ElementsAreArray; | 22 using testing::ElementsAreArray; |
| 21 using testing::Pointwise; | 23 using testing::Pointwise; |
| 22 | 24 |
| 23 namespace net { | 25 namespace net { |
| 24 | 26 |
| 25 namespace test { | 27 namespace test { |
| 26 | 28 |
| 27 typedef HpackHuffmanTable::DecodeEntry DecodeEntry; | 29 typedef HpackHuffmanTable::DecodeEntry DecodeEntry; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 EXPECT_EQ(buffer, "\x06"); | 384 EXPECT_EQ(buffer, "\x06"); |
| 383 } | 385 } |
| 384 } | 386 } |
| 385 | 387 |
| 386 TEST_F(HpackHuffmanTableTest, SpecRequestExamples) { | 388 TEST_F(HpackHuffmanTableTest, SpecRequestExamples) { |
| 387 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 389 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
| 388 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); | 390 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); |
| 389 | 391 |
| 390 string buffer; | 392 string buffer; |
| 391 string test_table[] = { | 393 string test_table[] = { |
| 392 "\xdb\x6d\x88\x3e\x68\xd1\xcb\x12\x25\xba\x7f", | 394 a2b_hex("e7cf9bebe89b6fb16fa9b6ff"), |
| 393 "www.example.com", | 395 "www.example.com", |
| 394 "\x63\x65\x4a\x13\x98\xff", | 396 a2b_hex("b9b9949556bf"), |
| 395 "no-cache", | 397 "no-cache", |
| 396 "\x4e\xb0\x8b\x74\x97\x90\xfa\x7f", | 398 a2b_hex("571c5cdb737b2faf"), |
| 397 "custom-key", | 399 "custom-key", |
| 398 "\x4e\xb0\x8b\x74\x97\x9a\x17\xa8\xff", | 400 a2b_hex("571c5cdb73724d9c57"), |
| 399 "custom-value", | 401 "custom-value", |
| 400 }; | 402 }; |
| 401 // Round-trip each test example. | 403 // Round-trip each test example. |
| 402 for (size_t i = 0; i != arraysize(test_table); i += 2) { | 404 for (size_t i = 0; i != arraysize(test_table); i += 2) { |
| 403 const string& encodedFixture(test_table[i]); | 405 const string& encodedFixture(test_table[i]); |
| 404 const string& decodedFixture(test_table[i+1]); | 406 const string& decodedFixture(test_table[i+1]); |
| 405 HpackInputStream input_stream(kuint32max, encodedFixture); | 407 HpackInputStream input_stream(kuint32max, encodedFixture); |
| 406 | 408 |
| 407 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), | 409 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), |
| 408 &buffer)); | 410 &buffer)); |
| 409 EXPECT_EQ(decodedFixture, buffer); | 411 EXPECT_EQ(decodedFixture, buffer); |
| 410 buffer = EncodeString(decodedFixture); | 412 buffer = EncodeString(decodedFixture); |
| 411 EXPECT_EQ(encodedFixture, buffer); | 413 EXPECT_EQ(encodedFixture, buffer); |
| 412 } | 414 } |
| 413 } | 415 } |
| 414 | 416 |
| 415 TEST_F(HpackHuffmanTableTest, SpecResponseExamples) { | 417 TEST_F(HpackHuffmanTableTest, SpecResponseExamples) { |
| 416 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 418 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
| 417 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); | 419 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); |
| 418 | 420 |
| 419 string buffer; | 421 string buffer; |
| 420 string test_table[] = { | 422 string test_table[] = { |
| 421 "\x98\xa7", | 423 a2b_hex("4017"), |
| 422 "302", | 424 "302", |
| 423 "\x73\xd5\xcd\x11\x1f", | 425 a2b_hex("bf06724b97"), |
| 424 "private", | 426 "private", |
| 425 "\xef\x6b\x3a\x7a\x0e\x6e\x8f\xa2\x63\xd0\x72\x9a\x6e\x83\x97\xd8" | 427 a2b_hex("d6dbb29884de2a718805062098513109" |
| 426 "\x69\xbd\x87\x37\x47\xbb\xbf\xc7", | 428 "b56ba3"), |
| 427 "Mon, 21 Oct 2013 20:13:21 GMT", | 429 "Mon, 21 Oct 2013 20:13:21 GMT", |
| 428 "\xce\x31\x74\x3d\x80\x1b\x6d\xb1\x07\xcd\x1a\x39\x62\x44\xb7\x4f", | 430 a2b_hex("adcebf198e7e7cf9bebe89b6fb16fa9b" |
| 431 "6f"), |
| 429 "https://www.example.com", | 432 "https://www.example.com", |
| 430 "\xc5\xad\xb7\x7f\x87\x6f\xc7\xfb\xf7\xfd\xbf\xbe\xbf\xf3\xf7\xf4" | 433 a2b_hex("e0d6cf9f6e8f9fd3e5f6fa76fefd3c7e" |
| 431 "\xfb\x7e\xbb\xbe\x9f\x5f\x87\xe3\x7f\xef\xed\xfa\xee\xfa\x7c\x3f" | 434 "df9eff1f2f0f3cfe9f6fcf7f8f879f61" |
| 432 "\x1d\x5d\x1a\x23\xce\x54\x64\x36\xcd\x49\x4b\xd5\xd1\xcc\x5f\x05" | 435 "ad4f4cc9a973a2200ec3725e18b1b74e" |
| 433 "\x35\x96\x9b", | 436 "3f"), |
| 434 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", | 437 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", |
| 435 }; | 438 }; |
| 436 // Round-trip each test example. | 439 // Round-trip each test example. |
| 437 for (size_t i = 0; i != arraysize(test_table); i += 2) { | 440 for (size_t i = 0; i != arraysize(test_table); i += 2) { |
| 438 const string& encodedFixture(test_table[i]); | 441 const string& encodedFixture(test_table[i]); |
| 439 const string& decodedFixture(test_table[i+1]); | 442 const string& decodedFixture(test_table[i+1]); |
| 440 HpackInputStream input_stream(kuint32max, encodedFixture); | 443 HpackInputStream input_stream(kuint32max, encodedFixture); |
| 441 | 444 |
| 442 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), | 445 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), |
| 443 &buffer)); | 446 &buffer)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 output_stream.TakeString(&encoding); | 513 output_stream.TakeString(&encoding); |
| 511 EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i])); | 514 EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i])); |
| 512 } | 515 } |
| 513 } | 516 } |
| 514 | 517 |
| 515 } // namespace | 518 } // namespace |
| 516 | 519 |
| 517 } // namespace test | 520 } // namespace test |
| 518 | 521 |
| 519 } // namespace net | 522 } // namespace net |
| OLD | NEW |