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

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

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: omewhat better take at higher-level HC::T impl, a bit lessy hacky, and actually write to cache now. Created 3 years, 6 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
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 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 transaction.handler = PreserveRequestHeaders_Handler; 1321 transaction.handler = PreserveRequestHeaders_Handler;
1322 transaction.request_headers = EXTRA_HEADER; 1322 transaction.request_headers = EXTRA_HEADER;
1323 transaction.response_headers = "Cache-Control: max-age=0\n"; 1323 transaction.response_headers = "Cache-Control: max-age=0\n";
1324 AddMockTransaction(&transaction); 1324 AddMockTransaction(&transaction);
1325 1325
1326 // Write, then revalidate the entry. 1326 // Write, then revalidate the entry.
1327 RunTransactionTest(cache.http_cache(), transaction); 1327 RunTransactionTest(cache.http_cache(), transaction);
1328 RunTransactionTest(cache.http_cache(), transaction); 1328 RunTransactionTest(cache.http_cache(), transaction);
1329 1329
1330 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1330 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1331 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1331 EXPECT_EQ(0, cache.disk_cache()->open_count());
1332 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1332 EXPECT_EQ(2, cache.disk_cache()->create_count());
1333 RemoveMockTransaction(&transaction); 1333 RemoveMockTransaction(&transaction);
1334 } 1334 }
1335 1335
1336 // Tests that we don't remove extra headers for conditionalized requests. 1336 // Tests that we don't remove extra headers for conditionalized requests.
1337 TEST(HttpCache, ConditionalizedGET_PreserveRequestHeaders) { 1337 TEST(HttpCache, ConditionalizedGET_PreserveRequestHeaders) {
1338 MockHttpCache cache; 1338 MockHttpCache cache;
1339 1339
1340 // Write to the cache. 1340 // Write to the cache.
1341 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); 1341 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
1342 1342
(...skipping 3600 matching lines...) Expand 10 before | Expand all | Expand 10 after
4943 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 4943 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
4944 4944
4945 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); 4945 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n"));
4946 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 4946 EXPECT_EQ(2, cache.network_layer()->transaction_count());
4947 EXPECT_EQ(1, cache.disk_cache()->open_count()); 4947 EXPECT_EQ(1, cache.disk_cache()->open_count());
4948 EXPECT_EQ(2, cache.disk_cache()->create_count()); 4948 EXPECT_EQ(2, cache.disk_cache()->create_count());
4949 4949
4950 // The last response was saved. 4950 // The last response was saved.
4951 RunTransactionTest(cache.http_cache(), transaction); 4951 RunTransactionTest(cache.http_cache(), transaction);
4952 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 4952 EXPECT_EQ(3, cache.network_layer()->transaction_count());
4953 EXPECT_EQ(2, cache.disk_cache()->open_count()); 4953 EXPECT_EQ(1, cache.disk_cache()->open_count());
4954 EXPECT_EQ(2, cache.disk_cache()->create_count()); 4954 EXPECT_EQ(3, cache.disk_cache()->create_count());
4955 } 4955 }
4956 4956
4957 // Verifies that conditionalization failures when asking for a range that would 4957 // Verifies that conditionalization failures when asking for a range that would
4958 // require the cache to modify the range to ask, result in a network request 4958 // require the cache to modify the range to ask, result in a network request
4959 // that matches the user's one. 4959 // that matches the user's one.
4960 TEST(HttpCache, RangeGET_NoConditionalization2) { 4960 TEST(HttpCache, RangeGET_NoConditionalization2) {
4961 MockHttpCache cache; 4961 MockHttpCache cache;
4962 cache.FailConditionalizations(); 4962 cache.FailConditionalizations();
4963 std::string headers; 4963 std::string headers;
4964 4964
(...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after
7377 RunTransactionTest(cache.http_cache(), transaction); 7377 RunTransactionTest(cache.http_cache(), transaction);
7378 7378
7379 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 7379 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7380 EXPECT_EQ(0, cache.disk_cache()->open_count()); 7380 EXPECT_EQ(0, cache.disk_cache()->open_count());
7381 EXPECT_EQ(1, cache.disk_cache()->create_count()); 7381 EXPECT_EQ(1, cache.disk_cache()->create_count());
7382 7382
7383 // Try loading again; it should result in a network fetch. 7383 // Try loading again; it should result in a network fetch.
7384 RunTransactionTest(cache.http_cache(), transaction); 7384 RunTransactionTest(cache.http_cache(), transaction);
7385 7385
7386 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 7386 EXPECT_EQ(2, cache.network_layer()->transaction_count());
7387 EXPECT_EQ(1, cache.disk_cache()->open_count()); 7387 EXPECT_EQ(0, cache.disk_cache()->open_count());
7388 EXPECT_EQ(1, cache.disk_cache()->create_count()); 7388 EXPECT_EQ(2, cache.disk_cache()->create_count());
7389 7389
7390 disk_cache::Entry* entry; 7390 disk_cache::Entry* entry;
7391 EXPECT_TRUE(cache.OpenBackendEntry(transaction.url, &entry)); 7391 EXPECT_TRUE(cache.OpenBackendEntry(transaction.url, &entry));
7392 entry->Close(); 7392 entry->Close();
7393 } 7393 }
7394 7394
7395 // Verify that no-cache resources are stored in cache and fetched from cache 7395 // Verify that no-cache resources are stored in cache and fetched from cache
7396 // when the LOAD_SKIP_CACHE_VALIDATION flag is set. 7396 // when the LOAD_SKIP_CACHE_VALIDATION flag is set.
7397 TEST(HttpCache, CacheControlNoCacheHistoryLoad) { 7397 TEST(HttpCache, CacheControlNoCacheHistoryLoad) {
7398 MockHttpCache cache; 7398 MockHttpCache cache;
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after
9074 ASSERT_TRUE(attrs->GetDictionary( 9074 ASSERT_TRUE(attrs->GetDictionary(
9075 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 9075 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
9076 std::string size; 9076 std::string size;
9077 ASSERT_TRUE(size_attrs->GetString("value", &size)); 9077 ASSERT_TRUE(size_attrs->GetString("value", &size));
9078 int actual_size = 0; 9078 int actual_size = 0;
9079 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 9079 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
9080 ASSERT_LT(0, actual_size); 9080 ASSERT_LT(0, actual_size);
9081 } 9081 }
9082 9082
9083 } // namespace net 9083 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698