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/http/http_response_headers_unittest.cc

Issue 1800003: Auto-format style pass over files. (Closed)
Patch Set: Remove trailing whitespace. Created 10 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
« no previous file with comments | « net/http/http_response_headers.cc ('k') | net/http/http_stream_parser.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 (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 200, 271 200,
272 HttpVersion(1,1), 272 HttpVersion(1,1),
273 HttpVersion(1,1) 273 HttpVersion(1,1)
274 }; 274 };
275 TestCommon(test); 275 TestCommon(test);
276 } 276 }
277 277
278 TEST(HttpResponseHeadersTest, GetNormalizedHeader) { 278 TEST(HttpResponseHeadersTest, GetNormalizedHeader) {
279 std::string headers = 279 std::string headers =
280 "HTTP/1.1 200 OK\n" 280 "HTTP/1.1 200 OK\n"
281 "Cache-control: private\n" 281 "Cache-control: private\n"
282 "cache-Control: no-store\n"; 282 "cache-Control: no-store\n";
283 HeadersToRaw(&headers); 283 HeadersToRaw(&headers);
284 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 284 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
285 285
286 std::string value; 286 std::string value;
287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value)); 287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value));
288 EXPECT_EQ("private, no-store", value); 288 EXPECT_EQ("private, no-store", value);
289 } 289 }
290 290
291 TEST(HttpResponseHeadersTest, Persist) { 291 TEST(HttpResponseHeadersTest, Persist) {
292 const struct { 292 const struct {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 std::string h2; 461 std::string h2;
462 parsed2->GetNormalizedHeaders(&h2); 462 parsed2->GetNormalizedHeaders(&h2);
463 EXPECT_EQ(string(tests[i].expected_headers), h2); 463 EXPECT_EQ(string(tests[i].expected_headers), h2);
464 } 464 }
465 } 465 }
466 466
467 TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) { 467 TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) {
468 // Ensure that commas in quoted strings are not regarded as value separators. 468 // Ensure that commas in quoted strings are not regarded as value separators.
469 // Ensure that whitespace following a value is trimmed properly 469 // Ensure that whitespace following a value is trimmed properly
470 std::string headers = 470 std::string headers =
471 "HTTP/1.1 200 OK\n" 471 "HTTP/1.1 200 OK\n"
472 "Cache-control:private , no-cache=\"set-cookie,server\" \n" 472 "Cache-control:private , no-cache=\"set-cookie,server\" \n"
473 "cache-Control: no-store\n"; 473 "cache-Control: no-store\n";
474 HeadersToRaw(&headers); 474 HeadersToRaw(&headers);
475 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 475 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
476 476
477 void* iter = NULL; 477 void* iter = NULL;
478 std::string value; 478 std::string value;
479 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 479 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
480 EXPECT_EQ("private", value); 480 EXPECT_EQ("private", value);
481 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 481 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
482 EXPECT_EQ("no-cache=\"set-cookie,server\"", value); 482 EXPECT_EQ("no-cache=\"set-cookie,server\"", value);
483 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 483 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
484 EXPECT_EQ("no-store", value); 484 EXPECT_EQ("no-store", value);
485 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 485 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "cache-control", &value));
486 } 486 }
487 487
488 TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) { 488 TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) {
489 // Even though WWW-Authenticate has commas, it should not be treated as 489 // Even though WWW-Authenticate has commas, it should not be treated as
490 // coalesced values. 490 // coalesced values.
491 std::string headers = 491 std::string headers =
492 "HTTP/1.1 401 OK\n" 492 "HTTP/1.1 401 OK\n"
493 "WWW-Authenticate:Digest realm=foobar, nonce=x, domain=y\n" 493 "WWW-Authenticate:Digest realm=foobar, nonce=x, domain=y\n"
494 "WWW-Authenticate:Basic realm=quatar\n"; 494 "WWW-Authenticate:Basic realm=quatar\n";
495 HeadersToRaw(&headers); 495 HeadersToRaw(&headers);
496 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 496 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
497 497
498 void* iter = NULL; 498 void* iter = NULL;
499 std::string value; 499 std::string value;
500 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); 500 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
501 EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value); 501 EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value);
502 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); 502 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
503 EXPECT_EQ("Basic realm=quatar", value); 503 EXPECT_EQ("Basic realm=quatar", value);
504 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); 504 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
505 } 505 }
506 506
507 TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) { 507 TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) {
508 // The comma in a date valued header should not be treated as a 508 // The comma in a date valued header should not be treated as a
509 // field-value separator 509 // field-value separator
510 std::string headers = 510 std::string headers =
511 "HTTP/1.1 200 OK\n" 511 "HTTP/1.1 200 OK\n"
512 "Date: Tue, 07 Aug 2007 23:10:55 GMT\n" 512 "Date: Tue, 07 Aug 2007 23:10:55 GMT\n"
513 "Last-Modified: Wed, 01 Aug 2007 23:23:45 GMT\n"; 513 "Last-Modified: Wed, 01 Aug 2007 23:23:45 GMT\n";
514 HeadersToRaw(&headers); 514 HeadersToRaw(&headers);
515 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 515 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
516 516
517 std::string value; 517 std::string value;
518 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "date", &value)); 518 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "date", &value));
519 EXPECT_EQ("Tue, 07 Aug 2007 23:10:55 GMT", value); 519 EXPECT_EQ("Tue, 07 Aug 2007 23:10:55 GMT", value);
520 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "last-modified", &value)); 520 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "last-modified", &value));
521 EXPECT_EQ("Wed, 01 Aug 2007 23:23:45 GMT", value); 521 EXPECT_EQ("Wed, 01 Aug 2007 23:23:45 GMT", value);
522 } 522 }
523 523
524 TEST(HttpResponseHeadersTest, GetMimeType) { 524 TEST(HttpResponseHeadersTest, GetMimeType) {
525 const ContentTypeTestData tests[] = { 525 const ContentTypeTestData tests[] = {
526 { "HTTP/1.1 200 OK\n" 526 { "HTTP/1.1 200 OK\n"
527 "Content-type: text/html\n", 527 "Content-type: text/html\n",
528 "text/html", true, 528 "text/html", true,
529 "", false, 529 "", false,
530 "text/html" }, 530 "text/html" },
531 // Multiple content-type headers should give us the last one. 531 // Multiple content-type headers should give us the last one.
532 { "HTTP/1.1 200 OK\n" 532 { "HTTP/1.1 200 OK\n"
533 "Content-type: text/html\n" 533 "Content-type: text/html\n"
534 "Content-type: text/html\n", 534 "Content-type: text/html\n",
535 "text/html", true, 535 "text/html", true,
536 "", false, 536 "", false,
537 "text/html, text/html" }, 537 "text/html, text/html" },
538 { "HTTP/1.1 200 OK\n" 538 { "HTTP/1.1 200 OK\n"
539 "Content-type: text/plain\n" 539 "Content-type: text/plain\n"
540 "Content-type: text/html\n" 540 "Content-type: text/html\n"
541 "Content-type: text/plain\n" 541 "Content-type: text/plain\n"
542 "Content-type: text/html\n", 542 "Content-type: text/html\n",
543 "text/html", true, 543 "text/html", true,
544 "", false, 544 "", false,
545 "text/plain, text/html, text/plain, text/html" }, 545 "text/plain, text/html, text/plain, text/html" },
546 // Test charset parsing. 546 // Test charset parsing.
547 { "HTTP/1.1 200 OK\n" 547 { "HTTP/1.1 200 OK\n"
548 "Content-type: text/html\n" 548 "Content-type: text/html\n"
549 "Content-type: text/html; charset=ISO-8859-1\n", 549 "Content-type: text/html; charset=ISO-8859-1\n",
550 "text/html", true, 550 "text/html", true,
551 "iso-8859-1", true, 551 "iso-8859-1", true,
552 "text/html, text/html; charset=ISO-8859-1" }, 552 "text/html, text/html; charset=ISO-8859-1" },
553 // Test charset in double quotes. 553 // Test charset in double quotes.
554 { "HTTP/1.1 200 OK\n" 554 { "HTTP/1.1 200 OK\n"
555 "Content-type: text/html\n" 555 "Content-type: text/html\n"
556 "Content-type: text/html; charset=\"ISO-8859-1\"\n", 556 "Content-type: text/html; charset=\"ISO-8859-1\"\n",
557 "text/html", true, 557 "text/html", true,
558 "iso-8859-1", true, 558 "iso-8859-1", true,
559 "text/html, text/html; charset=\"ISO-8859-1\"" }, 559 "text/html, text/html; charset=\"ISO-8859-1\"" },
560 // If there are multiple matching content-type headers, we carry 560 // If there are multiple matching content-type headers, we carry
561 // over the charset value. 561 // over the charset value.
562 { "HTTP/1.1 200 OK\n" 562 { "HTTP/1.1 200 OK\n"
563 "Content-type: text/html;charset=utf-8\n" 563 "Content-type: text/html;charset=utf-8\n"
564 "Content-type: text/html\n", 564 "Content-type: text/html\n",
565 "text/html", true, 565 "text/html", true,
566 "utf-8", true, 566 "utf-8", true,
567 "text/html;charset=utf-8, text/html" }, 567 "text/html;charset=utf-8, text/html" },
568 // Test single quotes. 568 // Test single quotes.
569 { "HTTP/1.1 200 OK\n" 569 { "HTTP/1.1 200 OK\n"
570 "Content-type: text/html;charset='utf-8'\n" 570 "Content-type: text/html;charset='utf-8'\n"
571 "Content-type: text/html\n", 571 "Content-type: text/html\n",
572 "text/html", true, 572 "text/html", true,
573 "utf-8", true, 573 "utf-8", true,
574 "text/html;charset='utf-8', text/html" }, 574 "text/html;charset='utf-8', text/html" },
575 // Last charset wins if matching content-type. 575 // Last charset wins if matching content-type.
576 { "HTTP/1.1 200 OK\n" 576 { "HTTP/1.1 200 OK\n"
577 "Content-type: text/html;charset=utf-8\n" 577 "Content-type: text/html;charset=utf-8\n"
578 "Content-type: text/html;charset=iso-8859-1\n", 578 "Content-type: text/html;charset=iso-8859-1\n",
579 "text/html", true, 579 "text/html", true,
580 "iso-8859-1", true, 580 "iso-8859-1", true,
581 "text/html;charset=utf-8, text/html;charset=iso-8859-1" }, 581 "text/html;charset=utf-8, text/html;charset=iso-8859-1" },
582 // Charset is ignored if the content types change. 582 // Charset is ignored if the content types change.
583 { "HTTP/1.1 200 OK\n" 583 { "HTTP/1.1 200 OK\n"
584 "Content-type: text/plain;charset=utf-8\n" 584 "Content-type: text/plain;charset=utf-8\n"
585 "Content-type: text/html\n", 585 "Content-type: text/html\n",
586 "text/html", true, 586 "text/html", true,
587 "", false, 587 "", false,
588 "text/plain;charset=utf-8, text/html" }, 588 "text/plain;charset=utf-8, text/html" },
589 // Empty content-type 589 // Empty content-type
590 { "HTTP/1.1 200 OK\n" 590 { "HTTP/1.1 200 OK\n"
591 "Content-type: \n", 591 "Content-type: \n",
592 "", false, 592 "", false,
593 "", false, 593 "", false,
594 "" }, 594 "" },
595 // Emtpy charset 595 // Emtpy charset
596 { "HTTP/1.1 200 OK\n" 596 { "HTTP/1.1 200 OK\n"
597 "Content-type: text/html;charset=\n", 597 "Content-type: text/html;charset=\n",
598 "text/html", true, 598 "text/html", true,
599 "", false, 599 "", false,
600 "text/html;charset=" }, 600 "text/html;charset=" },
601 // Multiple charsets, last one wins. 601 // Multiple charsets, last one wins.
602 { "HTTP/1.1 200 OK\n" 602 { "HTTP/1.1 200 OK\n"
603 "Content-type: text/html;charset=utf-8; charset=iso-8859-1\n", 603 "Content-type: text/html;charset=utf-8; charset=iso-8859-1\n",
604 "text/html", true, 604 "text/html", true,
605 "iso-8859-1", true, 605 "iso-8859-1", true,
606 "text/html;charset=utf-8; charset=iso-8859-1" }, 606 "text/html;charset=utf-8; charset=iso-8859-1" },
607 // Multiple params. 607 // Multiple params.
608 { "HTTP/1.1 200 OK\n" 608 { "HTTP/1.1 200 OK\n"
609 "Content-type: text/html; foo=utf-8; charset=iso-8859-1\n", 609 "Content-type: text/html; foo=utf-8; charset=iso-8859-1\n",
610 "text/html", true, 610 "text/html", true,
611 "iso-8859-1", true, 611 "iso-8859-1", true,
612 "text/html; foo=utf-8; charset=iso-8859-1" }, 612 "text/html; foo=utf-8; charset=iso-8859-1" },
613 { "HTTP/1.1 200 OK\n" 613 { "HTTP/1.1 200 OK\n"
614 "Content-type: text/html ; charset=utf-8 ; bar=iso-8859-1\n", 614 "Content-type: text/html ; charset=utf-8 ; bar=iso-8859-1\n",
615 "text/html", true, 615 "text/html", true,
616 "utf-8", true, 616 "utf-8", true,
617 "text/html ; charset=utf-8 ; bar=iso-8859-1" }, 617 "text/html ; charset=utf-8 ; bar=iso-8859-1" },
618 // Comma embeded in quotes. 618 // Comma embeded in quotes.
619 { "HTTP/1.1 200 OK\n" 619 { "HTTP/1.1 200 OK\n"
620 "Content-type: text/html ; charset='utf-8,text/plain' ;\n", 620 "Content-type: text/html ; charset='utf-8,text/plain' ;\n",
621 "text/html", true, 621 "text/html", true,
622 "utf-8,text/plain", true, 622 "utf-8,text/plain", true,
623 "text/html ; charset='utf-8,text/plain' ;" }, 623 "text/html ; charset='utf-8,text/plain' ;" },
624 // Charset with leading spaces. 624 // Charset with leading spaces.
625 { "HTTP/1.1 200 OK\n" 625 { "HTTP/1.1 200 OK\n"
626 "Content-type: text/html ; charset= 'utf-8' ;\n", 626 "Content-type: text/html ; charset= 'utf-8' ;\n",
627 "text/html", true, 627 "text/html", true,
628 "utf-8", true, 628 "utf-8", true,
629 "text/html ; charset= 'utf-8' ;" }, 629 "text/html ; charset= 'utf-8' ;" },
630 // Media type comments in mime-type. 630 // Media type comments in mime-type.
631 { "HTTP/1.1 200 OK\n" 631 { "HTTP/1.1 200 OK\n"
632 "Content-type: text/html (html)\n", 632 "Content-type: text/html (html)\n",
633 "text/html", true, 633 "text/html", true,
634 "", false, 634 "", false,
635 "text/html (html)" }, 635 "text/html (html)" },
636 // Incomplete charset= param 636 // Incomplete charset= param
637 { "HTTP/1.1 200 OK\n" 637 { "HTTP/1.1 200 OK\n"
638 "Content-type: text/html; char=\n", 638 "Content-type: text/html; char=\n",
639 "text/html", true, 639 "text/html", true,
640 "", false, 640 "", false,
641 "text/html; char=" }, 641 "text/html; char=" },
642 // Invalid media type: no slash 642 // Invalid media type: no slash
643 { "HTTP/1.1 200 OK\n" 643 { "HTTP/1.1 200 OK\n"
644 "Content-type: texthtml\n", 644 "Content-type: texthtml\n",
645 "", false, 645 "", false,
646 "", false, 646 "", false,
647 "texthtml" }, 647 "texthtml" },
648 // Invalid media type: */* 648 // Invalid media type: */*
649 { "HTTP/1.1 200 OK\n" 649 { "HTTP/1.1 200 OK\n"
650 "Content-type: */*\n", 650 "Content-type: */*\n",
651 "", false, 651 "", false,
652 "", false, 652 "", false,
653 "*/*" }, 653 "*/*" },
654 }; 654 };
655 655
656 for (size_t i = 0; i < arraysize(tests); ++i) { 656 for (size_t i = 0; i < arraysize(tests); ++i) {
657 string headers(tests[i].raw_headers); 657 string headers(tests[i].raw_headers);
658 HeadersToRaw(&headers); 658 HeadersToRaw(&headers);
659 scoped_refptr<HttpResponseHeaders> parsed = 659 scoped_refptr<HttpResponseHeaders> parsed =
660 new HttpResponseHeaders(headers); 660 new HttpResponseHeaders(headers);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 false 1470 false
1471 } 1471 }
1472 }; 1472 };
1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1474 string headers(tests[i].headers); 1474 string headers(tests[i].headers);
1475 HeadersToRaw(&headers); 1475 HeadersToRaw(&headers);
1476 scoped_refptr<HttpResponseHeaders> parsed = 1476 scoped_refptr<HttpResponseHeaders> parsed =
1477 new HttpResponseHeaders(headers); 1477 new HttpResponseHeaders(headers);
1478 1478
1479 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) << 1479 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) <<
1480 "Failed test case " << i; 1480 "Failed test case " << i;
1481 } 1481 }
1482 } 1482 }
1483 1483
1484 TEST(HttpResponseHeadersTest, GetStatusText) { 1484 TEST(HttpResponseHeadersTest, GetStatusText) {
1485 std::string headers("HTTP/1.1 404 Not Found"); 1485 std::string headers("HTTP/1.1 404 Not Found");
1486 HeadersToRaw(&headers); 1486 HeadersToRaw(&headers);
1487 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); 1487 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers);
1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); 1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText());
1489 } 1489 }
1490 1490
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 new HttpResponseHeaders(orig_headers); 1649 new HttpResponseHeaders(orig_headers);
1650 1650
1651 string name(tests[i].new_status); 1651 string name(tests[i].new_status);
1652 parsed->ReplaceStatusLine(name); 1652 parsed->ReplaceStatusLine(name);
1653 1653
1654 string resulting_headers; 1654 string resulting_headers;
1655 parsed->GetNormalizedHeaders(&resulting_headers); 1655 parsed->GetNormalizedHeaders(&resulting_headers);
1656 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); 1656 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers);
1657 } 1657 }
1658 } 1658 }
OLDNEW
« no previous file with comments | « net/http/http_response_headers.cc ('k') | net/http/http_stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698