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

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

Issue 2670013002: net: remove GetNormalizedHeaders() function (Closed)
Patch Set: n Created 3 years, 10 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 | « google_apis/gaia/gaia_auth_fetcher.cc ('k') | net/http/http_response_headers.h » ('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) 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 "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 using net::test::IsOk; 63 using net::test::IsOk;
64 64
65 using base::Time; 65 using base::Time;
66 66
67 namespace net { 67 namespace net {
68 68
69 using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus; 69 using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus;
70 70
71 namespace { 71 namespace {
72 72
73 // Returns a simple text serialization of the given
74 // |HttpResponseHeaders|. This is used by tests to verify that an
75 // |HttpResponseHeaders| matches an expectation string.
76 //
77 // * One line per header, written as:
78 // HEADER_NAME: HEADER_VALUE\n
79 // * The original case of header names is preserved.
80 // * Whitespace around head names/values is stripped.
81 // * Repeated headers are not aggregated.
82 // * Headers are listed in their original order.
83 // TODO(tfarina): this is a duplicate function from
84 // http_response_headers_unittest.cc:ToSimpleString(). Figure out how to merge
85 // them. crbug.com/488593
86 std::string ToSimpleString(const scoped_refptr<HttpResponseHeaders>& parsed) {
87 std::string result = parsed->GetStatusLine() + "\n";
88
89 size_t iter = 0;
90 std::string name;
91 std::string value;
92 while (parsed->EnumerateHeaderLines(&iter, &name, &value)) {
93 std::string new_line = name + ": " + value + "\n";
94
95 result += new_line;
96 }
97
98 return result;
99 }
100
73 // Tests the load timing values of a request that goes through a 101 // Tests the load timing values of a request that goes through a
74 // MockNetworkTransaction. 102 // MockNetworkTransaction.
75 void TestLoadTimingNetworkRequest(const LoadTimingInfo& load_timing_info) { 103 void TestLoadTimingNetworkRequest(const LoadTimingInfo& load_timing_info) {
76 EXPECT_FALSE(load_timing_info.socket_reused); 104 EXPECT_FALSE(load_timing_info.socket_reused);
77 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); 105 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id);
78 106
79 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); 107 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
80 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); 108 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
81 109
82 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, 110 ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), 283 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info),
256 response, log, load_timing_info, nullptr, nullptr, 284 response, log, load_timing_info, nullptr, nullptr,
257 nullptr); 285 nullptr);
258 } 286 }
259 287
260 void RunTransactionTestWithResponse(HttpCache* cache, 288 void RunTransactionTestWithResponse(HttpCache* cache,
261 const MockTransaction& trans_info, 289 const MockTransaction& trans_info,
262 std::string* response_headers) { 290 std::string* response_headers) {
263 HttpResponseInfo response; 291 HttpResponseInfo response;
264 RunTransactionTestWithResponseInfo(cache, trans_info, &response); 292 RunTransactionTestWithResponseInfo(cache, trans_info, &response);
265 response.headers->GetNormalizedHeaders(response_headers); 293 *response_headers = ToSimpleString(response.headers);
266 } 294 }
267 295
268 void RunTransactionTestWithResponseAndGetTiming( 296 void RunTransactionTestWithResponseAndGetTiming(
269 HttpCache* cache, 297 HttpCache* cache,
270 const MockTransaction& trans_info, 298 const MockTransaction& trans_info,
271 std::string* response_headers, 299 std::string* response_headers,
272 const NetLogWithSource& log, 300 const NetLogWithSource& log,
273 LoadTimingInfo* load_timing_info) { 301 LoadTimingInfo* load_timing_info) {
274 HttpResponseInfo response; 302 HttpResponseInfo response;
275 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), 303 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info),
276 &response, log, load_timing_info, nullptr, nullptr, 304 &response, log, load_timing_info, nullptr, nullptr,
277 nullptr); 305 nullptr);
278 response.headers->GetNormalizedHeaders(response_headers); 306 *response_headers = ToSimpleString(response.headers);
279 } 307 }
280 308
281 // This class provides a handler for kFastNoStoreGET_Transaction so that the 309 // This class provides a handler for kFastNoStoreGET_Transaction so that the
282 // no-store header can be included on demand. 310 // no-store header can be included on demand.
283 class FastTransactionServer { 311 class FastTransactionServer {
284 public: 312 public:
285 FastTransactionServer() { 313 FastTransactionServer() {
286 no_store = false; 314 no_store = false;
287 } 315 }
288 ~FastTransactionServer() {} 316 ~FastTransactionServer() {}
(...skipping 6438 matching lines...) Expand 10 before | Expand all | Expand 10 after
6727 6755
6728 HttpResponseInfo response; 6756 HttpResponseInfo response;
6729 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); 6757 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response);
6730 6758
6731 // The request and response times should have been updated. 6759 // The request and response times should have been updated.
6732 EXPECT_EQ(request_time.ToInternalValue(), 6760 EXPECT_EQ(request_time.ToInternalValue(),
6733 response.request_time.ToInternalValue()); 6761 response.request_time.ToInternalValue());
6734 EXPECT_EQ(response_time.ToInternalValue(), 6762 EXPECT_EQ(response_time.ToInternalValue(),
6735 response.response_time.ToInternalValue()); 6763 response.response_time.ToInternalValue());
6736 6764
6737 std::string headers;
6738 response.headers->GetNormalizedHeaders(&headers);
6739
6740 EXPECT_EQ("HTTP/1.1 200 OK\n" 6765 EXPECT_EQ("HTTP/1.1 200 OK\n"
6741 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 6766 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
6742 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 6767 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
6743 headers); 6768 ToSimpleString(response.headers));
6744 6769
6745 RemoveMockTransaction(&mock_network_response); 6770 RemoveMockTransaction(&mock_network_response);
6746 } 6771 }
6747 6772
6748 // Tests that we can write metadata to an entry. 6773 // Tests that we can write metadata to an entry.
6749 TEST(HttpCache, WriteMetadata_OK) { 6774 TEST(HttpCache, WriteMetadata_OK) {
6750 MockHttpCache cache; 6775 MockHttpCache cache;
6751 6776
6752 // Write to the cache 6777 // Write to the cache
6753 HttpResponseInfo response; 6778 HttpResponseInfo response;
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after
8322 RunTransactionTestWithResponseInfo(cache.http_cache(), 8347 RunTransactionTestWithResponseInfo(cache.http_cache(),
8323 kTypicalGET_Transaction, &response_info); 8348 kTypicalGET_Transaction, &response_info);
8324 8349
8325 EXPECT_FALSE(response_info.was_cached); 8350 EXPECT_FALSE(response_info.was_cached);
8326 EXPECT_TRUE(response_info.network_accessed); 8351 EXPECT_TRUE(response_info.network_accessed);
8327 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, 8352 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8328 response_info.cache_entry_status); 8353 response_info.cache_entry_status);
8329 } 8354 }
8330 8355
8331 } // namespace net 8356 } // namespace net
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.cc ('k') | net/http/http_response_headers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698