| 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" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 EXPECT_EQ(buffer, "\x06"); | 384 EXPECT_EQ(buffer, "\x06"); |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(HpackHuffmanTableTest, SpecRequestExamples) { | 388 TEST_F(HpackHuffmanTableTest, SpecRequestExamples) { |
| 389 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 389 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
| 390 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); | 390 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); |
| 391 | 391 |
| 392 string buffer; | 392 string buffer; |
| 393 string test_table[] = { | 393 string test_table[] = { |
| 394 a2b_hex("e7cf9bebe89b6fb16fa9b6ff"), | 394 a2b_hex("f1e3c2e5f23a6ba0ab90f4ff"), |
| 395 "www.example.com", | 395 "www.example.com", |
| 396 a2b_hex("b9b9949556bf"), | 396 a2b_hex("a8eb10649cbf"), |
| 397 "no-cache", | 397 "no-cache", |
| 398 a2b_hex("571c5cdb737b2faf"), | 398 a2b_hex("25a849e95ba97d7f"), |
| 399 "custom-key", | 399 "custom-key", |
| 400 a2b_hex("571c5cdb73724d9c57"), | 400 a2b_hex("25a849e95bb8e8b4bf"), |
| 401 "custom-value", | 401 "custom-value", |
| 402 }; | 402 }; |
| 403 // Round-trip each test example. | 403 // Round-trip each test example. |
| 404 for (size_t i = 0; i != arraysize(test_table); i += 2) { | 404 for (size_t i = 0; i != arraysize(test_table); i += 2) { |
| 405 const string& encodedFixture(test_table[i]); | 405 const string& encodedFixture(test_table[i]); |
| 406 const string& decodedFixture(test_table[i+1]); | 406 const string& decodedFixture(test_table[i+1]); |
| 407 HpackInputStream input_stream(kuint32max, encodedFixture); | 407 HpackInputStream input_stream(kuint32max, encodedFixture); |
| 408 | 408 |
| 409 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), | 409 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), |
| 410 &buffer)); | 410 &buffer)); |
| 411 EXPECT_EQ(decodedFixture, buffer); | 411 EXPECT_EQ(decodedFixture, buffer); |
| 412 buffer = EncodeString(decodedFixture); | 412 buffer = EncodeString(decodedFixture); |
| 413 EXPECT_EQ(encodedFixture, buffer); | 413 EXPECT_EQ(encodedFixture, buffer); |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST_F(HpackHuffmanTableTest, SpecResponseExamples) { | 417 TEST_F(HpackHuffmanTableTest, SpecResponseExamples) { |
| 418 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 418 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
| 419 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); | 419 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); |
| 420 | 420 |
| 421 string buffer; | 421 string buffer; |
| 422 string test_table[] = { | 422 string test_table[] = { |
| 423 a2b_hex("4017"), | 423 a2b_hex("6402"), |
| 424 "302", | 424 "302", |
| 425 a2b_hex("bf06724b97"), | 425 a2b_hex("aec3771a4b"), |
| 426 "private", | 426 "private", |
| 427 a2b_hex("d6dbb29884de2a718805062098513109" | 427 a2b_hex("d07abe941054d444a8200595040b8166" |
| 428 "b56ba3"), | 428 "e082a62d1bff"), |
| 429 "Mon, 21 Oct 2013 20:13:21 GMT", | 429 "Mon, 21 Oct 2013 20:13:21 GMT", |
| 430 a2b_hex("adcebf198e7e7cf9bebe89b6fb16fa9b" | 430 a2b_hex("9d29ad171863c78f0b97c8e9ae82ae43" |
| 431 "6f"), | 431 "d3"), |
| 432 "https://www.example.com", | 432 "https://www.example.com", |
| 433 a2b_hex("e0d6cf9f6e8f9fd3e5f6fa76fefd3c7e" | 433 a2b_hex("94e7821dd7f2e6c7b335dfdfcd5b3960" |
| 434 "df9eff1f2f0f3cfe9f6fcf7f8f879f61" | 434 "d5af27087f3672c1ab270fb5291f9587" |
| 435 "ad4f4cc9a973a2200ec3725e18b1b74e" | 435 "316065c003ed4ee5b1063d5007"), |
| 436 "3f"), | |
| 437 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", | 436 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", |
| 438 }; | 437 }; |
| 439 // Round-trip each test example. | 438 // Round-trip each test example. |
| 440 for (size_t i = 0; i != arraysize(test_table); i += 2) { | 439 for (size_t i = 0; i != arraysize(test_table); i += 2) { |
| 441 const string& encodedFixture(test_table[i]); | 440 const string& encodedFixture(test_table[i]); |
| 442 const string& decodedFixture(test_table[i+1]); | 441 const string& decodedFixture(test_table[i+1]); |
| 443 HpackInputStream input_stream(kuint32max, encodedFixture); | 442 HpackInputStream input_stream(kuint32max, encodedFixture); |
| 444 | 443 |
| 445 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), | 444 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), |
| 446 &buffer)); | 445 &buffer)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 output_stream.TakeString(&encoding); | 512 output_stream.TakeString(&encoding); |
| 514 EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i])); | 513 EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i])); |
| 515 } | 514 } |
| 516 } | 515 } |
| 517 | 516 |
| 518 } // namespace | 517 } // namespace |
| 519 | 518 |
| 520 } // namespace test | 519 } // namespace test |
| 521 | 520 |
| 522 } // namespace net | 521 } // namespace net |
| OLD | NEW |