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

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

Issue 187583002: Cleanup: have common HttpResponseHeaders routine to update with range (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/http/http_byte_range.h"
12 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 struct TestData { 18 struct TestData {
18 const char* raw_headers; 19 const char* raw_headers;
19 const char* expected_headers; 20 const char* expected_headers;
20 int expected_response_code; 21 int expected_response_code;
21 net::HttpVersion expected_parsed_version; 22 net::HttpVersion expected_parsed_version;
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1845
1845 std::string name(tests[i].new_status); 1846 std::string name(tests[i].new_status);
1846 parsed->ReplaceStatusLine(name); 1847 parsed->ReplaceStatusLine(name);
1847 1848
1848 std::string resulting_headers; 1849 std::string resulting_headers;
1849 parsed->GetNormalizedHeaders(&resulting_headers); 1850 parsed->GetNormalizedHeaders(&resulting_headers);
1850 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); 1851 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1851 } 1852 }
1852 } 1853 }
1853 1854
1855 TEST(HttpResponseHeadersTest, UpdateWithNewRange) {
1856 const struct {
1857 const char* orig_headers;
1858 const char* expected_headers;
1859 const char* expected_headers_with_replaced_status;
1860 } tests[] = {
1861 { "HTTP/1.1 200 OK\n"
1862 "Content-Length: 450\n",
1863
1864 "HTTP/1.1 200 OK\n"
1865 "Content-Range: bytes 3-5/450\n"
1866 "Content-Length: 3\n",
1867
1868 "HTTP/1.1 206 Partial Content\n"
1869 "Content-Range: bytes 3-5/450\n"
1870 "Content-Length: 3\n",
1871 },
1872 { "HTTP/1.1 200 OK\n"
1873 "Content-Length: 5\n",
1874
1875 "HTTP/1.1 200 OK\n"
1876 "Content-Range: bytes 3-5/5\n"
1877 "Content-Length: 3\n",
1878
1879 "HTTP/1.1 206 Partial Content\n"
1880 "Content-Range: bytes 3-5/5\n"
1881 "Content-Length: 3\n",
1882 },
1883 };
1884 const net::HttpByteRange range = net::HttpByteRange::Bounded(3, 5);
1885
1886 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1887 std::string orig_headers(tests[i].orig_headers);
1888 std::replace(orig_headers.begin(), orig_headers.end(), '\n', '\0');
1889 scoped_refptr<net::HttpResponseHeaders> parsed(
1890 new net::HttpResponseHeaders(orig_headers + '\0'));
1891 int64 content_size = parsed->GetContentLength();
1892 std::string resulting_headers;
1893
1894 // Update headers without replacing status line.
1895 parsed->UpdateWithNewRange(range, content_size, false);
1896 parsed->GetNormalizedHeaders(&resulting_headers);
1897 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1898
1899 // Replace status line too.
1900 parsed->UpdateWithNewRange(range, content_size, true);
1901 parsed->GetNormalizedHeaders(&resulting_headers);
1902 EXPECT_EQ(std::string(tests[i].expected_headers_with_replaced_status),
1903 resulting_headers);
1904 }
1905 }
1906
1854 TEST(HttpResponseHeadersTest, ToNetLogParamAndBackAgain) { 1907 TEST(HttpResponseHeadersTest, ToNetLogParamAndBackAgain) {
1855 std::string headers("HTTP/1.1 404\n" 1908 std::string headers("HTTP/1.1 404\n"
1856 "Content-Length: 450\n" 1909 "Content-Length: 450\n"
1857 "Connection: keep-alive\n"); 1910 "Connection: keep-alive\n");
1858 HeadersToRaw(&headers); 1911 HeadersToRaw(&headers);
1859 scoped_refptr<net::HttpResponseHeaders> parsed( 1912 scoped_refptr<net::HttpResponseHeaders> parsed(
1860 new net::HttpResponseHeaders(headers)); 1913 new net::HttpResponseHeaders(headers));
1861 1914
1862 scoped_ptr<base::Value> event_param( 1915 scoped_ptr<base::Value> event_param(
1863 parsed->NetLogCallback(net::NetLog::LOG_ALL_BUT_BYTES)); 1916 parsed->NetLogCallback(net::NetLog::LOG_ALL_BUT_BYTES));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 2162 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
2110 std::string headers(tests[i].headers); 2163 std::string headers(tests[i].headers);
2111 HeadersToRaw(&headers); 2164 HeadersToRaw(&headers);
2112 scoped_refptr<net::HttpResponseHeaders> parsed( 2165 scoped_refptr<net::HttpResponseHeaders> parsed(
2113 new net::HttpResponseHeaders(headers)); 2166 new net::HttpResponseHeaders(headers));
2114 2167
2115 EXPECT_EQ(tests[i].expected_result, parsed->IsChromeProxyResponse()); 2168 EXPECT_EQ(tests[i].expected_result, parsed->IsChromeProxyResponse());
2116 } 2169 }
2117 } 2170 }
2118 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) 2171 #endif // defined(SPDY_PROXY_AUTH_ORIGIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698