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

Side by Side Diff: net/http/http_response_headers_unittest.cc

Issue 8511063: Improve merging of header modifications in webRequest.OnHeadersReceived (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 1617
1618 std::string name(tests[i].to_remove); 1618 std::string name(tests[i].to_remove);
1619 parsed->RemoveHeader(name); 1619 parsed->RemoveHeader(name);
1620 1620
1621 std::string resulting_headers; 1621 std::string resulting_headers;
1622 parsed->GetNormalizedHeaders(&resulting_headers); 1622 parsed->GetNormalizedHeaders(&resulting_headers);
1623 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); 1623 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1624 } 1624 }
1625 } 1625 }
1626 1626
1627 TEST(HttpResponseHeadersTest, RemoveIndividualHeader) {
1628 const struct {
1629 const char* orig_headers;
1630 const char* to_remove_name;
1631 const char* to_remove_value;
1632 const char* expected_headers;
1633 } tests[] = {
1634 { "HTTP/1.1 200 OK\n"
1635 "connection: keep-alive\n"
1636 "Cache-control: max-age=10000\n"
1637 "Content-Length: 450\n",
1638
1639 "Content-Length",
1640
1641 "450",
1642
1643 "HTTP/1.1 200 OK\n"
1644 "connection: keep-alive\n"
1645 "Cache-control: max-age=10000\n"
1646 },
1647 { "HTTP/1.1 200 OK\n"
1648 "connection: keep-alive \n"
1649 "Content-Length : 450 \n"
1650 "Cache-control: max-age=10000\n",
1651
1652 "Content-Length",
1653
1654 "450",
1655
1656 "HTTP/1.1 200 OK\n"
1657 "connection: keep-alive\n"
1658 "Cache-control: max-age=10000\n"
1659 },
1660 };
Matt Perry 2011/11/11 22:05:08 how about a test case where the name matches but t
battre 2011/11/17 12:01:04 Done.
1661
1662 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1663 std::string orig_headers(tests[i].orig_headers);
1664 HeadersToRaw(&orig_headers);
1665 scoped_refptr<net::HttpResponseHeaders> parsed(
1666 new net::HttpResponseHeaders(orig_headers));
1667
1668 std::string name(tests[i].to_remove_name);
1669 std::string value(tests[i].to_remove_value);
1670 parsed->RemoveHeader(name, value);
1671
1672 std::string resulting_headers;
1673 parsed->GetNormalizedHeaders(&resulting_headers);
1674 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1675 }
1676 }
1677
1627 TEST(HttpResponseHeadersTest, ReplaceStatus) { 1678 TEST(HttpResponseHeadersTest, ReplaceStatus) {
1628 const struct { 1679 const struct {
1629 const char* orig_headers; 1680 const char* orig_headers;
1630 const char* new_status; 1681 const char* new_status;
1631 const char* expected_headers; 1682 const char* expected_headers;
1632 } tests[] = { 1683 } tests[] = {
1633 { "HTTP/1.1 206 Partial Content\n" 1684 { "HTTP/1.1 206 Partial Content\n"
1634 "connection: keep-alive\n" 1685 "connection: keep-alive\n"
1635 "Cache-control: max-age=10000\n" 1686 "Cache-control: max-age=10000\n"
1636 "Content-Length: 450\n", 1687 "Content-Length: 450\n",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 new net::HttpResponseHeaders(orig_headers)); 1722 new net::HttpResponseHeaders(orig_headers));
1672 1723
1673 std::string name(tests[i].new_status); 1724 std::string name(tests[i].new_status);
1674 parsed->ReplaceStatusLine(name); 1725 parsed->ReplaceStatusLine(name);
1675 1726
1676 std::string resulting_headers; 1727 std::string resulting_headers;
1677 parsed->GetNormalizedHeaders(&resulting_headers); 1728 parsed->GetNormalizedHeaders(&resulting_headers);
1678 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); 1729 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1679 } 1730 }
1680 } 1731 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698