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

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

Issue 976373005: Http Cache: Update vary data after a 304. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | no next file » | 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 response_headers->assign(kTypicalGET_Transaction.response_headers); 2101 response_headers->assign(kTypicalGET_Transaction.response_headers);
2102 response_data->clear(); 2102 response_data->clear();
2103 } else { 2103 } else {
2104 response_status->assign(kTypicalGET_Transaction.status); 2104 response_status->assign(kTypicalGET_Transaction.status);
2105 response_headers->assign(kTypicalGET_Transaction.response_headers); 2105 response_headers->assign(kTypicalGET_Transaction.response_headers);
2106 response_data->assign(kTypicalGET_Transaction.data); 2106 response_data->assign(kTypicalGET_Transaction.data);
2107 } 2107 }
2108 } 2108 }
2109 2109
2110 // Tests revalidation after a vary match. 2110 // Tests revalidation after a vary match.
2111 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMatch) { 2111 TEST(HttpCache, GET_ValidateCache_VaryMatch) {
2112 MockHttpCache cache; 2112 MockHttpCache cache;
2113 2113
2114 // Write to the cache. 2114 // Write to the cache.
2115 MockTransaction transaction(kTypicalGET_Transaction); 2115 MockTransaction transaction(kTypicalGET_Transaction);
2116 transaction.request_headers = "Foo: bar\r\n"; 2116 transaction.request_headers = "Foo: bar\r\n";
2117 transaction.response_headers = 2117 transaction.response_headers =
2118 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 2118 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
2119 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2119 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
2120 "Etag: \"foopy\"\n" 2120 "Etag: \"foopy\"\n"
2121 "Cache-Control: max-age=0\n" 2121 "Cache-Control: max-age=0\n"
(...skipping 12 matching lines...) Expand all
2134 EXPECT_TRUE(server.EtagUsed()); 2134 EXPECT_TRUE(server.EtagUsed());
2135 EXPECT_TRUE(server.LastModifiedUsed()); 2135 EXPECT_TRUE(server.LastModifiedUsed());
2136 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2136 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2137 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2137 EXPECT_EQ(1, cache.disk_cache()->open_count());
2138 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2138 EXPECT_EQ(1, cache.disk_cache()->create_count());
2139 TestLoadTimingNetworkRequest(load_timing_info); 2139 TestLoadTimingNetworkRequest(load_timing_info);
2140 RemoveMockTransaction(&transaction); 2140 RemoveMockTransaction(&transaction);
2141 } 2141 }
2142 2142
2143 // Tests revalidation after a vary mismatch if etag is present. 2143 // Tests revalidation after a vary mismatch if etag is present.
2144 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMismatch) { 2144 TEST(HttpCache, GET_ValidateCache_VaryMismatch) {
2145 MockHttpCache cache; 2145 MockHttpCache cache;
2146 2146
2147 // Write to the cache. 2147 // Write to the cache.
2148 MockTransaction transaction(kTypicalGET_Transaction); 2148 MockTransaction transaction(kTypicalGET_Transaction);
2149 transaction.request_headers = "Foo: bar\r\n"; 2149 transaction.request_headers = "Foo: bar\r\n";
2150 transaction.response_headers = 2150 transaction.response_headers =
2151 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 2151 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
2152 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2152 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
2153 "Etag: \"foopy\"\n" 2153 "Etag: \"foopy\"\n"
2154 "Cache-Control: max-age=0\n" 2154 "Cache-Control: max-age=0\n"
(...skipping 13 matching lines...) Expand all
2168 EXPECT_TRUE(server.EtagUsed()); 2168 EXPECT_TRUE(server.EtagUsed());
2169 EXPECT_FALSE(server.LastModifiedUsed()); 2169 EXPECT_FALSE(server.LastModifiedUsed());
2170 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2170 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2171 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2171 EXPECT_EQ(1, cache.disk_cache()->open_count());
2172 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2172 EXPECT_EQ(1, cache.disk_cache()->create_count());
2173 TestLoadTimingNetworkRequest(load_timing_info); 2173 TestLoadTimingNetworkRequest(load_timing_info);
2174 RemoveMockTransaction(&transaction); 2174 RemoveMockTransaction(&transaction);
2175 } 2175 }
2176 2176
2177 // Tests lack of revalidation after a vary mismatch and no etag. 2177 // Tests lack of revalidation after a vary mismatch and no etag.
2178 TEST(HttpCache, SimpleGET_LoadDontValidateCache_VaryMismatch) { 2178 TEST(HttpCache, GET_DontValidateCache_VaryMismatch) {
2179 MockHttpCache cache; 2179 MockHttpCache cache;
2180 2180
2181 // Write to the cache. 2181 // Write to the cache.
2182 MockTransaction transaction(kTypicalGET_Transaction); 2182 MockTransaction transaction(kTypicalGET_Transaction);
2183 transaction.request_headers = "Foo: bar\r\n"; 2183 transaction.request_headers = "Foo: bar\r\n";
2184 transaction.response_headers = 2184 transaction.response_headers =
2185 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 2185 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
2186 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2186 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
2187 "Cache-Control: max-age=0\n" 2187 "Cache-Control: max-age=0\n"
2188 "Vary: Foo\n"; 2188 "Vary: Foo\n";
(...skipping 11 matching lines...) Expand all
2200 2200
2201 EXPECT_FALSE(server.EtagUsed()); 2201 EXPECT_FALSE(server.EtagUsed());
2202 EXPECT_FALSE(server.LastModifiedUsed()); 2202 EXPECT_FALSE(server.LastModifiedUsed());
2203 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2203 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2204 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2204 EXPECT_EQ(1, cache.disk_cache()->open_count());
2205 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2205 EXPECT_EQ(1, cache.disk_cache()->create_count());
2206 TestLoadTimingNetworkRequest(load_timing_info); 2206 TestLoadTimingNetworkRequest(load_timing_info);
2207 RemoveMockTransaction(&transaction); 2207 RemoveMockTransaction(&transaction);
2208 } 2208 }
2209 2209
2210 // Tests that a new vary header provided when revalidating an entry is saved.
2211 TEST(HttpCache, GET_ValidateCache_VaryMatch_UpdateVary) {
2212 MockHttpCache cache;
2213
2214 // Write to the cache.
2215 ScopedMockTransaction transaction(kTypicalGET_Transaction);
2216 transaction.request_headers = "Foo: bar\r\n Name: bar\r\n";
Adam Rice 2015/03/06 09:49:11 What purpose does the space between \r\n and Name:
rvargas (doing something else) 2015/03/06 20:44:11 Better readability. We skip white space when readi
2217 transaction.response_headers =
2218 "Etag: \"foopy\"\n"
2219 "Cache-Control: max-age=0\n"
2220 "Vary: Foo\n";
2221 RunTransactionTest(cache.http_cache(), transaction);
2222
2223 // Validate the entry and change the vary field in the response.
2224 transaction.request_headers = "Foo: bar\r\n Name: none\r\n";
2225 transaction.status = "HTTP/1.1 304 Not Modified";
2226 transaction.response_headers =
2227 "Etag: \"foopy\"\n"
2228 "Cache-Control: max-age=3600\n"
2229 "Vary: Name\n";
2230 RunTransactionTest(cache.http_cache(), transaction);
2231
2232 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2233 EXPECT_EQ(1, cache.disk_cache()->open_count());
2234 EXPECT_EQ(1, cache.disk_cache()->create_count());
2235
2236 // Make sure that the ActiveEntry is gone.
2237 base::MessageLoop::current()->RunUntilIdle();
Adam Rice 2015/03/06 09:49:11 Optional: change these all to base::RunLoop().RunU
rvargas (doing something else) 2015/03/06 20:44:11 I couldn't come up with a name that makes me happy
2238
2239 // Generate a vary mismatch.
2240 transaction.request_headers = "Foo: bar\r\n Name: bar\r\n";
2241 RunTransactionTest(cache.http_cache(), transaction);
2242
2243 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2244 EXPECT_EQ(2, cache.disk_cache()->open_count());
2245 EXPECT_EQ(1, cache.disk_cache()->create_count());
2246 }
2247
2248 // Tests that new request headers causing a vary mismatch are paired with the
2249 // new response when the server says the old response can be used.
2250 TEST(HttpCache, GET_ValidateCache_VaryMismatch_UpdateRequestHeader) {
2251 MockHttpCache cache;
2252
2253 // Write to the cache.
2254 ScopedMockTransaction transaction(kTypicalGET_Transaction);
2255 transaction.request_headers = "Foo: bar\r\n";
2256 transaction.response_headers =
2257 "Etag: \"foopy\"\n"
2258 "Cache-Control: max-age=3600\n"
2259 "Vary: Foo\n";
2260 RunTransactionTest(cache.http_cache(), transaction);
2261
2262 // Vary-mismatch validation receives 304.
2263 transaction.request_headers = "Foo: none\r\n";
2264 transaction.status = "HTTP/1.1 304 Not Modified";
2265 RunTransactionTest(cache.http_cache(), transaction);
2266
2267 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2268 EXPECT_EQ(1, cache.disk_cache()->open_count());
2269 EXPECT_EQ(1, cache.disk_cache()->create_count());
2270
2271 // Make sure that the ActiveEntry is gone.
2272 base::MessageLoop::current()->RunUntilIdle();
2273
2274 // Generate a vary mismatch.
2275 transaction.request_headers = "Foo: bar\r\n";
2276 RunTransactionTest(cache.http_cache(), transaction);
2277
2278 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2279 EXPECT_EQ(2, cache.disk_cache()->open_count());
2280 EXPECT_EQ(1, cache.disk_cache()->create_count());
2281 }
2282
2283 // Tests that a 304 without vary headers doesn't delete the previouysly stored
Adam Rice 2015/03/06 09:49:12 s/previouysly/previously/ Also in the following t
rvargas (doing something else) 2015/03/06 20:44:11 Done.
2284 // vary data after a vary match revalidation.
2285 TEST(HttpCache, GET_ValidateCache_VaryMatch_DontDeleteVary) {
2286 MockHttpCache cache;
2287
2288 // Write to the cache.
2289 ScopedMockTransaction transaction(kTypicalGET_Transaction);
2290 transaction.request_headers = "Foo: bar\r\n";
2291 transaction.response_headers =
2292 "Etag: \"foopy\"\n"
2293 "Cache-Control: max-age=0\n"
2294 "Vary: Foo\n";
2295 RunTransactionTest(cache.http_cache(), transaction);
2296
2297 // Validate the entry and remove the vary field in the response.
2298 transaction.status = "HTTP/1.1 304 Not Modified";
2299 transaction.response_headers =
2300 "Etag: \"foopy\"\n"
2301 "Cache-Control: max-age=3600\n";
2302 RunTransactionTest(cache.http_cache(), transaction);
2303
2304 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2305 EXPECT_EQ(1, cache.disk_cache()->open_count());
2306 EXPECT_EQ(1, cache.disk_cache()->create_count());
2307
2308 // Make sure that the ActiveEntry is gone.
2309 base::MessageLoop::current()->RunUntilIdle();
2310
2311 // Generate a vary mismatch.
2312 transaction.request_headers = "Foo: none\r\n";
2313 RunTransactionTest(cache.http_cache(), transaction);
2314
2315 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2316 EXPECT_EQ(2, cache.disk_cache()->open_count());
2317 EXPECT_EQ(1, cache.disk_cache()->create_count());
2318 }
2319
2320 // Tests that a 304 without vary headers doesn't delete the previouysly stored
2321 // vary data after a vary mismatch.
2322 TEST(HttpCache, GET_ValidateCache_VaryMismatch_DontDeleteVary) {
2323 MockHttpCache cache;
2324
2325 // Write to the cache.
2326 ScopedMockTransaction transaction(kTypicalGET_Transaction);
2327 transaction.request_headers = "Foo: bar\r\n";
2328 transaction.response_headers =
2329 "Etag: \"foopy\"\n"
2330 "Cache-Control: max-age=3600\n"
2331 "Vary: Foo\n";
2332 RunTransactionTest(cache.http_cache(), transaction);
2333
2334 // Vary-mismatch validation receives 304 and no vary header.
2335 transaction.request_headers = "Foo: none\r\n";
2336 transaction.status = "HTTP/1.1 304 Not Modified";
2337 transaction.response_headers =
2338 "Etag: \"foopy\"\n"
2339 "Cache-Control: max-age=3600\n";
2340 RunTransactionTest(cache.http_cache(), transaction);
2341
2342 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2343 EXPECT_EQ(1, cache.disk_cache()->open_count());
2344 EXPECT_EQ(1, cache.disk_cache()->create_count());
2345
2346 // Make sure that the ActiveEntry is gone.
2347 base::MessageLoop::current()->RunUntilIdle();
2348
2349 // Generate a vary mismatch.
2350 transaction.request_headers = "Foo: bar\r\n";
2351 RunTransactionTest(cache.http_cache(), transaction);
2352
2353 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2354 EXPECT_EQ(2, cache.disk_cache()->open_count());
2355 EXPECT_EQ(1, cache.disk_cache()->create_count());
2356 }
2357
2210 static void ETagGet_UnconditionalRequest_Handler( 2358 static void ETagGet_UnconditionalRequest_Handler(
2211 const net::HttpRequestInfo* request, 2359 const net::HttpRequestInfo* request,
2212 std::string* response_status, 2360 std::string* response_status,
2213 std::string* response_headers, 2361 std::string* response_headers,
2214 std::string* response_data) { 2362 std::string* response_data) {
2215 EXPECT_FALSE( 2363 EXPECT_FALSE(
2216 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)); 2364 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch));
2217 } 2365 }
2218 2366
2219 TEST(HttpCache, ETagGET_Http10) { 2367 TEST(HttpCache, ETagGET_Http10) {
(...skipping 5549 matching lines...) Expand 10 before | Expand all | Expand 10 after
7769 7917
7770 // Here the second transaction proceeds without reading the first body. 7918 // Here the second transaction proceeds without reading the first body.
7771 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); 7919 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState());
7772 base::MessageLoop::current()->RunUntilIdle(); 7920 base::MessageLoop::current()->RunUntilIdle();
7773 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); 7921 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState());
7774 ASSERT_TRUE(second->trans->GetResponseInfo()); 7922 ASSERT_TRUE(second->trans->GetResponseInfo());
7775 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( 7923 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue(
7776 "Cache-Control", "no-store")); 7924 "Cache-Control", "no-store"));
7777 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); 7925 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction);
7778 } 7926 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698