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

Side by Side Diff: net/spdy/hpack/hpack_encoder_test.cc

Issue 1357953002: Replace the existing SpdyHeaderBlock typedef with a class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add NET_EXPORT to fix compile error on win_chromium_compile_dbg_ng. Created 5 years, 2 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
« no previous file with comments | « net/spdy/hpack/hpack_decoder_test.cc ('k') | net/spdy/spdy_framer.cc » ('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/hpack_encoder.h" 5 #include "net/spdy/hpack/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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 EXPECT_EQ(expected_out, actual_out); 285 EXPECT_EQ(expected_out, actual_out);
286 } 286 }
287 287
288 TEST_F(HpackEncoderTest, MultipleEncodingPasses) { 288 TEST_F(HpackEncoderTest, MultipleEncodingPasses) {
289 // Pass 1. 289 // Pass 1.
290 { 290 {
291 SpdyHeaderBlock headers; 291 SpdyHeaderBlock headers;
292 headers["key1"] = "value1"; 292 headers["key1"] = "value1";
293 headers["cookie"] = "a=bb"; 293 headers["cookie"] = "a=bb";
294 294
295 ExpectIndex(IndexOf(key_1_));
295 ExpectIndex(IndexOf(cookie_a_)); 296 ExpectIndex(IndexOf(cookie_a_));
296 ExpectIndex(IndexOf(key_1_));
297 CompareWithExpectedEncoding(headers); 297 CompareWithExpectedEncoding(headers);
298 } 298 }
299 // Header table is: 299 // Header table is:
300 // 65: key1: value1 300 // 65: key1: value1
301 // 64: key2: value2 301 // 64: key2: value2
302 // 63: cookie: a=bb 302 // 63: cookie: a=bb
303 // 62: cookie: c=dd 303 // 62: cookie: c=dd
304 // Pass 2. 304 // Pass 2.
305 { 305 {
306 SpdyHeaderBlock headers; 306 SpdyHeaderBlock headers;
307 headers["key2"] = "value2"; 307 headers["key2"] = "value2";
308 headers["cookie"] = "c=dd; e=ff"; 308 headers["cookie"] = "c=dd; e=ff";
309 309
310 ExpectIndex(IndexOf(cookie_c_)); 310 // "key2: value2"
311 ExpectIndex(64);
312 // "cookie: c=dd"
313 ExpectIndex(62);
311 // This cookie evicts |key1| from the dynamic table. 314 // This cookie evicts |key1| from the dynamic table.
312 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff"); 315 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff");
313 // "key2: value2"
314 ExpectIndex(65);
315 316
316 CompareWithExpectedEncoding(headers); 317 CompareWithExpectedEncoding(headers);
317 } 318 }
318 // Header table is: 319 // Header table is:
319 // 65: key2: value2 320 // 65: key2: value2
320 // 64: cookie: a=bb 321 // 64: cookie: a=bb
321 // 63: cookie: c=dd 322 // 63: cookie: c=dd
322 // 62: cookie: e=ff 323 // 62: cookie: e=ff
323 // Pass 3. 324 // Pass 3.
324 { 325 {
325 SpdyHeaderBlock headers; 326 SpdyHeaderBlock headers;
326 headers["key2"] = "value2"; 327 headers["key2"] = "value2";
327 headers["cookie"] = "a=bb; b=cc; c=dd"; 328 headers["cookie"] = "a=bb; b=cc; c=dd";
328 329
330 // "key2: value2"
331 ExpectIndex(65);
329 // "cookie: a=bb" 332 // "cookie: a=bb"
330 ExpectIndex(64); 333 ExpectIndex(64);
331 // This cookie evicts |key2| from the dynamic table. 334 // This cookie evicts |key2| from the dynamic table.
332 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "b=cc"); 335 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "b=cc");
333 // "cookie: c=dd" 336 // "cookie: c=dd"
334 ExpectIndex(64); 337 ExpectIndex(64);
335 // "key2: value2"
336 ExpectIndexedLiteral("key2", "value2");
337 338
338 CompareWithExpectedEncoding(headers); 339 CompareWithExpectedEncoding(headers);
339 } 340 }
340 } 341 }
341 342
342 TEST_F(HpackEncoderTest, PseudoHeadersFirst) { 343 TEST_F(HpackEncoderTest, PseudoHeadersFirst) {
343 SpdyHeaderBlock headers; 344 SpdyHeaderBlock headers;
345 // A pseudo-header that should not be indexed.
346 headers[":path"] = "/spam/eggs.html";
344 // A pseudo-header to be indexed. 347 // A pseudo-header to be indexed.
345 headers[":authority"] = "www.example.com"; 348 headers[":authority"] = "www.example.com";
346 // A pseudo-header that should not be indexed.
347 headers[":path"] = "/spam/eggs.html";
348 // A regular header which precedes ":" alphabetically, should still be encoded 349 // A regular header which precedes ":" alphabetically, should still be encoded
349 // after pseudo-headers. 350 // after pseudo-headers.
350 headers["-foo"] = "bar"; 351 headers["-foo"] = "bar";
351 headers["foo"] = "bar"; 352 headers["foo"] = "bar";
352 headers["cookie"] = "c=dd"; 353 headers["cookie"] = "c=dd";
353 354
354 // Pseudo-headers are encoded in alphabetical order. 355 // Headers are indexed in the order in which they were added.
355 // This entry pushes "cookie: a=bb" back to 63. 356 // This entry pushes "cookie: a=bb" back to 63.
357 ExpectNonIndexedLiteral(":path", "/spam/eggs.html");
356 ExpectIndexedLiteral(peer_.table()->GetByName(":authority"), 358 ExpectIndexedLiteral(peer_.table()->GetByName(":authority"),
357 "www.example.com"); 359 "www.example.com");
358 ExpectNonIndexedLiteral(":path", "/spam/eggs.html");
359 // Regular headers are endoded in alphabetical order.
360 // This entry pushes "cookie: a=bb" back to 64.
361 ExpectIndexedLiteral("-foo", "bar"); 360 ExpectIndexedLiteral("-foo", "bar");
362 ExpectIndex(64);
363 ExpectIndexedLiteral("foo", "bar"); 361 ExpectIndexedLiteral("foo", "bar");
362 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "c=dd");
364 CompareWithExpectedEncoding(headers); 363 CompareWithExpectedEncoding(headers);
365 } 364 }
366 365
367 TEST_F(HpackEncoderTest, CookieToCrumbs) { 366 TEST_F(HpackEncoderTest, CookieToCrumbs) {
368 test::HpackEncoderPeer peer(NULL); 367 test::HpackEncoderPeer peer(NULL);
369 std::vector<StringPiece> out; 368 std::vector<StringPiece> out;
370 369
371 // Leading and trailing whitespace is consumed. A space after ';' is consumed. 370 // Leading and trailing whitespace is consumed. A space after ';' is consumed.
372 // All other spaces remain. ';' at beginning and end of string produce empty 371 // All other spaces remain. ';' at beginning and end of string produce empty
373 // crumbs. 372 // crumbs.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 expected_.AppendUint32(62); 455 expected_.AppendUint32(62);
457 expected_.AppendPrefix(kStringLiteralIdentityEncoded); 456 expected_.AppendPrefix(kStringLiteralIdentityEncoded);
458 expected_.AppendUint32(3); 457 expected_.AppendUint32(3);
459 expected_.AppendBytes("bar"); 458 expected_.AppendBytes("bar");
460 CompareWithExpectedEncoding(headers); 459 CompareWithExpectedEncoding(headers);
461 } 460 }
462 461
463 } // namespace 462 } // namespace
464 463
465 } // namespace net 464 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_decoder_test.cc ('k') | net/spdy/spdy_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698