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

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

Issue 822713002: Update from https://crrev.com/309415 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years 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
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_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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 CompareWithExpectedEncoding(headers); 312 CompareWithExpectedEncoding(headers);
313 } 313 }
314 // Header table is: 314 // Header table is:
315 // 65: key1: value1 315 // 65: key1: value1
316 // 64: key2: value2 316 // 64: key2: value2
317 // 63: cookie: a=bb 317 // 63: cookie: a=bb
318 // 62: cookie: c=dd 318 // 62: cookie: c=dd
319 // Pass 2. 319 // Pass 2.
320 { 320 {
321 map<string, string> headers; 321 map<string, string> headers;
322 headers["key1"] = "value1";
323 headers["key2"] = "value2"; 322 headers["key2"] = "value2";
324 headers["cookie"] = "c=dd; e=ff"; 323 headers["cookie"] = "c=dd; e=ff";
325 324
326 ExpectIndex(IndexOf(cookie_c_)); 325 ExpectIndex(IndexOf(cookie_c_));
327 // key1 by index. 326 // This cookie evicts |key1| from the dynamic table.
327 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff");
328 // "key2: value2"
328 ExpectIndex(65); 329 ExpectIndex(65);
329 // key2 by index.
330 ExpectIndex(64);
331 // This cookie evicts |key1| from the header table.
332 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "e=ff");
333 330
334 CompareWithExpectedEncoding(headers); 331 CompareWithExpectedEncoding(headers);
335 } 332 }
336 // Header table is: 333 // Header table is:
337 // 65: key2: value2 334 // 65: key2: value2
338 // 64: cookie: a=bb 335 // 64: cookie: a=bb
339 // 63: cookie: c=dd 336 // 63: cookie: c=dd
340 // 62: cookie: e=ff 337 // 62: cookie: e=ff
341 // Pass 3. 338 // Pass 3.
342 { 339 {
343 map<string, string> headers; 340 map<string, string> headers;
344 headers["key1"] = "value1"; 341 headers["key2"] = "value2";
345 headers["key3"] = "value3"; 342 headers["cookie"] = "a=bb; b=cc; c=dd";
346 headers["cookie"] = "e=ff";
347 343
348 // cookie: e=ff by index. 344 // "cookie: a=bb"
349 ExpectIndex(62); 345 ExpectIndex(64);
350 ExpectIndexedLiteral("key1", "value1"); 346 // This cookie evicts |key2| from the dynamic table.
351 ExpectIndexedLiteral("key3", "value3"); 347 ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "b=cc");
348 // "cookie: c=dd"
349 ExpectIndex(64);
350 // "key2: value2"
351 ExpectIndexedLiteral("key2", "value2");
352 352
353 CompareWithExpectedEncoding(headers); 353 CompareWithExpectedEncoding(headers);
354 } 354 }
355 } 355 }
356 356
357 TEST_F(HpackEncoderTest, PseudoHeadersFirst) { 357 TEST_F(HpackEncoderTest, PseudoHeadersFirst) {
358 map<string, string> headers; 358 map<string, string> headers;
359 // A pseudo-header to be indexed. 359 // A pseudo-header to be indexed.
360 headers[":authority"] = "www.example.com"; 360 headers[":authority"] = "www.example.com";
361 // A pseudo-header that should not be indexed. 361 // A pseudo-header that should not be indexed.
362 headers[":path"] = "/spam/eggs.html"; 362 headers[":path"] = "/spam/eggs.html";
363 // A regular header which precedes ":" alphabetically, should still be encoded 363 // A regular header which precedes ":" alphabetically, should still be encoded
364 // after pseudo-headers. 364 // after pseudo-headers.
365 headers["-foo"] = "bar"; 365 headers["-foo"] = "bar";
366 headers["foo"] = "bar"; 366 headers["foo"] = "bar";
367 headers["cookie"] = "c=dd"; 367 headers["cookie"] = "c=dd";
368 368
369 // Pseudo-headers are encoded in alphabetical order. 369 // Pseudo-headers are encoded in alphabetical order.
370 // This entry pushes "cookie: a=bb" back to 63.
370 ExpectIndexedLiteral(peer_.table()->GetByName(":authority"), 371 ExpectIndexedLiteral(peer_.table()->GetByName(":authority"),
371 "www.example.com"); 372 "www.example.com");
372 ExpectNonIndexedLiteral(":path", "/spam/eggs.html"); 373 ExpectNonIndexedLiteral(":path", "/spam/eggs.html");
373 // Regular headers in the header table are encoded first. 374 // Regular headers are endoded in alphabetical order.
374 ExpectIndex(IndexOf(cookie_a_)); 375 // This entry pushes "cookie: a=bb" back to 64.
375 // Regular headers not in the header table are encoded, in alphabetical order.
376 ExpectIndexedLiteral("-foo", "bar"); 376 ExpectIndexedLiteral("-foo", "bar");
377 ExpectIndex(64);
377 ExpectIndexedLiteral("foo", "bar"); 378 ExpectIndexedLiteral("foo", "bar");
378 CompareWithExpectedEncoding(headers); 379 CompareWithExpectedEncoding(headers);
379 } 380 }
380 381
381 TEST_F(HpackEncoderTest, CookieToCrumbs) { 382 TEST_F(HpackEncoderTest, CookieToCrumbs) {
382 test::HpackEncoderPeer peer(NULL); 383 test::HpackEncoderPeer peer(NULL);
383 std::vector<StringPiece> out; 384 std::vector<StringPiece> out;
384 385
385 // A space after ';' is consumed. All other spaces remain. ';' at beginning 386 // A space after ';' is consumed. All other spaces remain. ';' at beginning
386 // and end of string produce empty crumbs. Duplicate crumbs are removed. 387 // and end of string produce empty crumbs. Duplicate crumbs are removed.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 expected_.AppendUint32(62); 462 expected_.AppendUint32(62);
462 expected_.AppendPrefix(kStringLiteralIdentityEncoded); 463 expected_.AppendPrefix(kStringLiteralIdentityEncoded);
463 expected_.AppendUint32(3); 464 expected_.AppendUint32(3);
464 expected_.AppendBytes("bar"); 465 expected_.AppendBytes("bar");
465 CompareWithExpectedEncoding(headers); 466 CompareWithExpectedEncoding(headers);
466 } 467 }
467 468
468 } // namespace 469 } // namespace
469 470
470 } // namespace net 471 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698