Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: net/spdy/hpack_huffman_table_test.cc

Issue 269183008: HPACK changes required for specification draft '07 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Write '07 examples as a new file name. Remove previous one. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/hpack_header_table.cc ('k') | net/spdy/hpack_input_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/string_number_conversions.h"
11 #include "net/spdy/hpack_constants.h" 12 #include "net/spdy/hpack_constants.h"
12 #include "net/spdy/hpack_input_stream.h" 13 #include "net/spdy/hpack_input_stream.h"
13 #include "net/spdy/hpack_output_stream.h" 14 #include "net/spdy/hpack_output_stream.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;
18 using std::string; 19 using std::string;
19 using testing::ElementsAre; 20 using testing::ElementsAre;
20 using testing::ElementsAreArray; 21 using testing::ElementsAreArray;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 string result; 97 string result;
97 HpackOutputStream output_stream; 98 HpackOutputStream output_stream;
98 table_.EncodeString(input, &output_stream); 99 table_.EncodeString(input, &output_stream);
99 100
100 output_stream.TakeString(&result); 101 output_stream.TakeString(&result);
101 // Verify EncodedSize() agrees with EncodeString(). 102 // Verify EncodedSize() agrees with EncodeString().
102 EXPECT_EQ(result.size(), table_.EncodedSize(input)); 103 EXPECT_EQ(result.size(), table_.EncodedSize(input));
103 return result; 104 return result;
104 } 105 }
105 106
107 string a2b_hex(const char* hex_data) {
Ryan Hamilton 2014/05/06 22:28:07 nit: should we consider moving this elsewhere? (I
Johnny 2014/05/06 22:43:17 Done. Moved to spdy_test_utils.cc.
108 std::vector<uint8> output;
109 string result;
110 if (base::HexStringToBytes(hex_data, &output))
111 result.assign(reinterpret_cast<const char*>(&output[0]), output.size());
112 return result;
113 }
114
106 HpackHuffmanTable table_; 115 HpackHuffmanTable table_;
107 HpackHuffmanTablePeer peer_; 116 HpackHuffmanTablePeer peer_;
108 }; 117 };
109 118
110 MATCHER(DecodeEntryEq, "") { 119 MATCHER(DecodeEntryEq, "") {
111 const DecodeEntry& lhs = std::tr1::get<0>(arg); 120 const DecodeEntry& lhs = std::tr1::get<0>(arg);
112 const DecodeEntry& rhs = std::tr1::get<1>(arg); 121 const DecodeEntry& rhs = std::tr1::get<1>(arg);
113 return lhs.next_table_index == rhs.next_table_index && 122 return lhs.next_table_index == rhs.next_table_index &&
114 lhs.length == rhs.length && 123 lhs.length == rhs.length &&
115 lhs.symbol_id == rhs.symbol_id; 124 lhs.symbol_id == rhs.symbol_id;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 EXPECT_EQ(buffer, "\x06"); 391 EXPECT_EQ(buffer, "\x06");
383 } 392 }
384 } 393 }
385 394
386 TEST_F(HpackHuffmanTableTest, SpecRequestExamples) { 395 TEST_F(HpackHuffmanTableTest, SpecRequestExamples) {
387 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); 396 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode();
388 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); 397 EXPECT_TRUE(table_.Initialize(&code[0], code.size()));
389 398
390 string buffer; 399 string buffer;
391 string test_table[] = { 400 string test_table[] = {
392 "\xdb\x6d\x88\x3e\x68\xd1\xcb\x12\x25\xba\x7f", 401 a2b_hex("e7cf9bebe89b6fb16fa9b6ff"),
393 "www.example.com", 402 "www.example.com",
394 "\x63\x65\x4a\x13\x98\xff", 403 a2b_hex("b9b9949556bf"),
395 "no-cache", 404 "no-cache",
396 "\x4e\xb0\x8b\x74\x97\x90\xfa\x7f", 405 a2b_hex("571c5cdb737b2faf"),
397 "custom-key", 406 "custom-key",
398 "\x4e\xb0\x8b\x74\x97\x9a\x17\xa8\xff", 407 a2b_hex("571c5cdb73724d9c57"),
399 "custom-value", 408 "custom-value",
400 }; 409 };
401 // Round-trip each test example. 410 // Round-trip each test example.
402 for (size_t i = 0; i != arraysize(test_table); i += 2) { 411 for (size_t i = 0; i != arraysize(test_table); i += 2) {
403 const string& encodedFixture(test_table[i]); 412 const string& encodedFixture(test_table[i]);
404 const string& decodedFixture(test_table[i+1]); 413 const string& decodedFixture(test_table[i+1]);
405 HpackInputStream input_stream(kuint32max, encodedFixture); 414 HpackInputStream input_stream(kuint32max, encodedFixture);
406 415
407 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), 416 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(),
408 &buffer)); 417 &buffer));
409 EXPECT_EQ(decodedFixture, buffer); 418 EXPECT_EQ(decodedFixture, buffer);
410 buffer = EncodeString(decodedFixture); 419 buffer = EncodeString(decodedFixture);
411 EXPECT_EQ(encodedFixture, buffer); 420 EXPECT_EQ(encodedFixture, buffer);
412 } 421 }
413 } 422 }
414 423
415 TEST_F(HpackHuffmanTableTest, SpecResponseExamples) { 424 TEST_F(HpackHuffmanTableTest, SpecResponseExamples) {
416 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); 425 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode();
417 EXPECT_TRUE(table_.Initialize(&code[0], code.size())); 426 EXPECT_TRUE(table_.Initialize(&code[0], code.size()));
418 427
419 string buffer; 428 string buffer;
420 string test_table[] = { 429 string test_table[] = {
421 "\x98\xa7", 430 a2b_hex("4017"),
422 "302", 431 "302",
423 "\x73\xd5\xcd\x11\x1f", 432 a2b_hex("bf06724b97"),
424 "private", 433 "private",
425 "\xef\x6b\x3a\x7a\x0e\x6e\x8f\xa2\x63\xd0\x72\x9a\x6e\x83\x97\xd8" 434 a2b_hex("d6dbb29884de2a718805062098513109"
426 "\x69\xbd\x87\x37\x47\xbb\xbf\xc7", 435 "b56ba3"),
427 "Mon, 21 Oct 2013 20:13:21 GMT", 436 "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", 437 a2b_hex("adcebf198e7e7cf9bebe89b6fb16fa9b"
438 "6f"),
429 "https://www.example.com", 439 "https://www.example.com",
430 "\xc5\xad\xb7\x7f\x87\x6f\xc7\xfb\xf7\xfd\xbf\xbe\xbf\xf3\xf7\xf4" 440 a2b_hex("e0d6cf9f6e8f9fd3e5f6fa76fefd3c7e"
431 "\xfb\x7e\xbb\xbe\x9f\x5f\x87\xe3\x7f\xef\xed\xfa\xee\xfa\x7c\x3f" 441 "df9eff1f2f0f3cfe9f6fcf7f8f879f61"
432 "\x1d\x5d\x1a\x23\xce\x54\x64\x36\xcd\x49\x4b\xd5\xd1\xcc\x5f\x05" 442 "ad4f4cc9a973a2200ec3725e18b1b74e"
433 "\x35\x96\x9b", 443 "3f"),
434 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", 444 "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1",
435 }; 445 };
436 // Round-trip each test example. 446 // Round-trip each test example.
437 for (size_t i = 0; i != arraysize(test_table); i += 2) { 447 for (size_t i = 0; i != arraysize(test_table); i += 2) {
438 const string& encodedFixture(test_table[i]); 448 const string& encodedFixture(test_table[i]);
439 const string& decodedFixture(test_table[i+1]); 449 const string& decodedFixture(test_table[i+1]);
440 HpackInputStream input_stream(kuint32max, encodedFixture); 450 HpackInputStream input_stream(kuint32max, encodedFixture);
441 451
442 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(), 452 EXPECT_TRUE(table_.DecodeString(&input_stream, decodedFixture.size(),
443 &buffer)); 453 &buffer));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 output_stream.TakeString(&encoding); 520 output_stream.TakeString(&encoding);
511 EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i])); 521 EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i]));
512 } 522 }
513 } 523 }
514 524
515 } // namespace 525 } // namespace
516 526
517 } // namespace test 527 } // namespace test
518 528
519 } // namespace net 529 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack_header_table.cc ('k') | net/spdy/hpack_input_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698