• Home
  • Raw
  • Download

Lines Matching +full:cache +full:- +full:base

2 // Use of this source code is governed by a BSD-style license that can be
15 #include "base/containers/cxx20_erase.h"
16 #include "base/files/scoped_temp_dir.h"
17 #include "base/format_macros.h"
18 #include "base/functional/bind.h"
19 #include "base/functional/callback_helpers.h"
20 #include "base/memory/ptr_util.h"
21 #include "base/memory/raw_ptr.h"
22 #include "base/run_loop.h"
23 #include "base/strings/strcat.h"
24 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_util.h"
26 #include "base/strings/stringprintf.h"
27 #include "base/test/bind.h"
28 #include "base/test/metrics/histogram_tester.h"
29 #include "base/test/scoped_feature_list.h"
30 #include "base/test/simple_test_clock.h"
31 #include "base/time/time.h"
32 #include "base/trace_event/memory_allocator_dump.h"
33 #include "base/trace_event/memory_dump_request_args.h"
34 #include "base/trace_event/process_memory_dump.h"
35 #include "net/base/cache_type.h"
36 #include "net/base/completion_repeating_callback.h"
37 #include "net/base/elements_upload_data_stream.h"
38 #include "net/base/features.h"
39 #include "net/base/host_port_pair.h"
40 #include "net/base/ip_address.h"
41 #include "net/base/ip_endpoint.h"
42 #include "net/base/load_flags.h"
43 #include "net/base/load_timing_info.h"
44 #include "net/base/load_timing_info_test_util.h"
45 #include "net/base/net_errors.h"
46 #include "net/base/schemeful_site.h"
47 #include "net/base/tracing.h"
48 #include "net/base/upload_bytes_element_reader.h"
78 #include "third_party/abseil-cpp/absl/types/optional.h"
93 using base::Time;
154 explicit DeleteCacheCompletionCallback(std::unique_ptr<MockHttpCache> cache) in DeleteCacheCompletionCallback() argument
155 : cache_(std::move(cache)) {} in DeleteCacheCompletionCallback()
162 return base::BindOnce(&DeleteCacheCompletionCallback::OnComplete, in callback()
163 base::Unretained(this)); in callback()
175 //-----------------------------------------------------------------------------
199 void RunTransactionTestBase(HttpCache* cache, in RunTransactionTestBase() argument
210 // write to the cache in RunTransactionTestBase()
213 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans); in RunTransactionTestBase()
217 rv = trans->Start(&request, callback.callback(), net_log); in RunTransactionTestBase()
225 const HttpResponseInfo* response = trans->GetResponseInfo(); in RunTransactionTestBase()
236 trans->GetLoadTimingInfo(load_timing_info); in RunTransactionTestBase()
240 ASSERT_TRUE(trans->GetRemoteEndpoint(remote_endpoint)); in RunTransactionTestBase()
245 *sent_bytes = trans->GetTotalSentBytes(); in RunTransactionTestBase()
247 *received_bytes = trans->GetTotalReceivedBytes(); in RunTransactionTestBase()
250 void RunTransactionTestWithRequest(HttpCache* cache, in RunTransactionTestWithRequest() argument
254 RunTransactionTestBase(cache, trans_info, request, response_info, in RunTransactionTestWithRequest()
259 void RunTransactionTestAndGetTiming(HttpCache* cache, in RunTransactionTestAndGetTiming() argument
263 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), in RunTransactionTestAndGetTiming()
269 HttpCache* cache, in RunTransactionTestAndGetTimingAndConnectedSocketAddress() argument
274 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), in RunTransactionTestAndGetTimingAndConnectedSocketAddress()
279 void RunTransactionTest(HttpCache* cache, const MockTransaction& trans_info) { in RunTransactionTest() argument
280 RunTransactionTestAndGetTiming(cache, trans_info, NetLogWithSource(), in RunTransactionTest()
284 void RunTransactionTestWithLog(HttpCache* cache, in RunTransactionTestWithLog() argument
287 RunTransactionTestAndGetTiming(cache, trans_info, log, nullptr); in RunTransactionTestWithLog()
290 void RunTransactionTestWithResponseInfo(HttpCache* cache, in RunTransactionTestWithResponseInfo() argument
293 RunTransactionTestWithRequest(cache, trans_info, MockHttpRequest(trans_info), in RunTransactionTestWithResponseInfo()
298 HttpCache* cache, in RunTransactionTestWithResponseInfoAndGetTiming() argument
303 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), in RunTransactionTestWithResponseInfoAndGetTiming()
308 void RunTransactionTestWithResponse(HttpCache* cache, in RunTransactionTestWithResponse() argument
312 RunTransactionTestWithResponseInfo(cache, trans_info, &response); in RunTransactionTestWithResponse()
317 HttpCache* cache, in RunTransactionTestWithResponseAndGetTiming() argument
323 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), in RunTransactionTestWithResponseAndGetTiming()
330 // no-store header can be included on demand.
349 *response_headers = "Cache-Control: no-store\n"; in FastNoStoreHandler()
360 base::Time(),
365 "Cache-Control: max-age=10000\n",
366 base::Time(),
372 base::BindRepeating(&FastTransactionServer::FastNoStoreHandler),
420 // X-Require-Mock-Auth -> return 401.
421 // X-Require-Mock-Auth-Alt -> return 401.
422 // X-Return-Default-Range -> assume 40-49 was requested.
423 // The -Alt variant doesn't cause the MockNetworkTransaction to
460 if (request->extra_headers.IsEmpty()) { in RangeHandler()
461 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); in RangeHandler()
462 response_data->clear(); in RangeHandler()
467 EXPECT_TRUE(request->extra_headers.HasHeader(kExtraHeaderKey)); in RangeHandler()
470 request->extra_headers.HasHeader("X-Require-Mock-Auth") || in RangeHandler()
471 request->extra_headers.HasHeader("X-Require-Mock-Auth-Alt"); in RangeHandler()
473 if (require_auth && !request->extra_headers.HasHeader("Authorization")) { in RangeHandler()
474 response_status->assign("HTTP/1.1 401 Unauthorized"); in RangeHandler()
475 response_data->assign("WWW-Authenticate: Foo\n"); in RangeHandler()
480 response_status->assign("HTTP/1.1 301 Moved Permanently"); in RangeHandler()
481 response_headers->assign("Location: /elsewhere\nContent-Length: 5"); in RangeHandler()
482 response_data->assign("12345"); in RangeHandler()
487 response_status->assign("HTTP/1.1 304 Not Modified"); in RangeHandler()
488 response_data->clear(); in RangeHandler()
494 if (!request->extra_headers.GetHeader(HttpRequestHeaders::kRange, in RangeHandler()
498 (modified_ && request->extra_headers.HasHeader("If-Range"))) { in RangeHandler()
499 // This is not a byte range request, or a failed If-Range. We return 200. in RangeHandler()
500 response_status->assign("HTTP/1.1 200 OK"); in RangeHandler()
501 response_headers->assign("Date: Wed, 28 Nov 2007 09:40:09 GMT"); in RangeHandler()
502 response_data->assign("Not a range"); in RangeHandler()
509 if (request->extra_headers.HasHeader("X-Return-Default-Range")) { in RangeHandler()
515 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); in RangeHandler()
516 response_data->clear(); in RangeHandler()
526 std::string content_range = base::StringPrintf("Content-Range: bytes %" PRId64 in RangeHandler()
527 "-%" PRId64 "/%" PRId64 "\n", in RangeHandler()
529 response_headers->append(content_range); in RangeHandler()
531 if (!request->extra_headers.HasHeader("If-None-Match") || modified_) { in RangeHandler()
537 EXPECT_EQ(9, (end - start) % 10); in RangeHandler()
539 base::StringAppendF(&data, "rg: %02" PRId64 "-%02" PRId64 " ", in RangeHandler()
545 if (end - start != 9) { in RangeHandler()
546 // We also have to fix content-length. in RangeHandler()
547 int64_t len = end - start + 1; in RangeHandler()
549 base::StringPrintf("Content-Length: %" PRId64 "\n", len); in RangeHandler()
550 response_headers->replace(response_headers->find("Content-Length:"), in RangeHandler()
554 response_status->assign("HTTP/1.1 304 Not Modified"); in RangeHandler()
555 response_data->clear(); in RangeHandler()
562 base::Time(),
563 "Range: bytes = 40-49\r\n" EXTRA_HEADER,
567 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
569 "Accept-Ranges: bytes\n"
570 "Content-Length: 10\n",
571 base::Time(),
572 "rg: 40-49 ",
577 base::BindRepeating(&RangeTransactionServer::RangeHandler),
586 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 "
587 "rg: 40-49 rg: 50-59 rg: 60-69 rg: 70-79 ";
592 auto headers = base::MakeRefCounted<HttpResponseHeaders>( in Verify206Response()
595 ASSERT_EQ(206, headers->response_code()); in Verify206Response()
599 headers->GetContentRangeFor206(&range_start, &range_end, &object_size)); in Verify206Response()
600 int64_t content_length = headers->GetContentLength(); in Verify206Response()
602 int length = end - start + 1; in Verify206Response()
609 void CreateTruncatedEntry(std::string raw_headers, MockHttpCache* cache) { in CreateTruncatedEntry() argument
610 // Create a disk cache entry that stores an incomplete resource. in CreateTruncatedEntry()
613 ASSERT_TRUE(cache->CreateBackendEntry(request.CacheKey(), &entry, nullptr)); in CreateTruncatedEntry()
616 response.response_time = base::Time::Now(); in CreateTruncatedEntry()
617 response.request_time = base::Time::Now(); in CreateTruncatedEntry()
618 response.headers = base::MakeRefCounted<HttpResponseHeaders>( in CreateTruncatedEntry()
623 auto buf = base::MakeRefCounted<IOBufferWithSize>(100); in CreateTruncatedEntry()
624 int len = static_cast<int>(base::strlcpy(buf->data(), in CreateTruncatedEntry()
625 "rg: 00-09 rg: 10-19 ", 100)); in CreateTruncatedEntry()
627 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); in CreateTruncatedEntry()
629 entry->Close(); in CreateTruncatedEntry()
634 void VerifyTruncatedFlag(MockHttpCache* cache, in VerifyTruncatedFlag() argument
639 ASSERT_TRUE(cache->OpenBackendEntry(key, &entry)); in VerifyTruncatedFlag()
647 EXPECT_EQ(data_size, entry->GetDataSize(1)); in VerifyTruncatedFlag()
654 trans->status = status; in AssignTo()
655 trans->response_headers = headers; in AssignTo()
656 trans->data = body; in AssignTo()
687 base::WeakPtr<SpdySession> session, in CreateHttp2Stream()
718 // Gets the entries from |net_log| created by the cache layer and asserted on in
723 base::EraseIf(entries, ShouldIgnoreLogEntry); in GetFilteredNetLogEntries()
751 // Helper function, generating valid HTTP cache key from `url`.
771 int OpenEntry(HttpCache* cache, in OpenEntry() argument
775 return cache->OpenEntry(GenerateCacheKey(url), entry, trans); in OpenEntry()
778 int OpenOrCreateEntry(HttpCache* cache, in OpenOrCreateEntry() argument
782 return cache->OpenOrCreateEntry(GenerateCacheKey(url), entry, trans); in OpenOrCreateEntry()
785 int CreateEntry(HttpCache* cache, in CreateEntry() argument
789 return cache->CreateEntry(GenerateCacheKey(url), entry, trans); in CreateEntry()
792 int DoomEntry(HttpCache* cache, in DoomEntry() argument
795 return cache->DoomEntry(GenerateCacheKey(url), trans); in DoomEntry()
798 void DeactivateEntry(HttpCache* cache, ActiveEntry* entry) { in DeactivateEntry() argument
799 cache->DeactivateEntry(entry); in DeactivateEntry()
817 MockHttpCache cache; in ComputeCacheKey() local
818 return *cache.http_cache()->GenerateCacheKeyForRequest(&request_info); in ComputeCacheKey()
822 //-----------------------------------------------------------------------------
826 MockHttpCache cache; in TEST_F() local
829 EXPECT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
834 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(0)); in TEST_F() local
839 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); in TEST_F()
844 MockHttpCache cache; in TEST_F() local
847 // Write to the cache. in TEST_F()
848 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
852 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
853 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
854 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
859 // called once for simple GET calls that traverse the cache.
861 MockHttpCache cache; in TEST_F() local
870 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
873 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
877 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
887 MockHttpCache cache; in TEST_F() local
892 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
898 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
902 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
908 // called once for requests that hit the cache.
910 MockHttpCache cache; in TEST_F() local
913 // Populate the cache. in TEST_F()
916 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
920 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
922 // Load from the cache (only), observe the callback being called. in TEST_F()
928 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
931 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
935 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
941 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
948 // is called for a request that hit the cache and returns an error, the cache
951 MockHttpCache cache; in TEST_F() local
954 // Populate the cache. in TEST_F()
957 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
963 // Attempt to read from cache entry, but abort transaction due to a in TEST_F()
969 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
972 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
976 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
980 // Used the cache entry only. in TEST_F()
986 // Request the same resource once more, observe that it is read from cache. in TEST_F()
990 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
993 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
997 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
1001 // Used the cache entry only. in TEST_F()
1008 // returns `ERR_INCONSISTENT_IP_ADDRESS_SPACE`, the cache entry is invalidated.
1011 MockHttpCache cache; in TEST_F() local
1016 // Populate the cache. in TEST_F()
1017 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
1022 // Attempt to read from cache entry, but abort transaction due to a in TEST_F()
1028 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
1031 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
1035 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
1040 // Used the cache entry only. in TEST_F()
1047 // cache. in TEST_F()
1051 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
1054 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
1058 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
1071 // cache entry is invalidated, and we'll retry the connection from the network.
1075 MockHttpCache cache; in TEST_F() local
1080 // Populate the cache. in TEST_F()
1081 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
1086 // Attempt to read from cache entry, but abort transaction due to a in TEST_F()
1093 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
1096 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
1100 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
1107 // Used the cache entry only. in TEST_F()
1114 // cache. in TEST_F()
1118 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
1121 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
1125 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
1139 MockHttpCache cache; in TEST_F() local
1145 // Populate the cache. in TEST_F()
1148 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1152 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1154 // Load from the cache (only), observe the callback being called. in TEST_F()
1160 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
1163 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
1167 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
1173 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1175 // The transport info mentions both the cache and the original proxy. in TEST_F()
1184 MockHttpCache cache; in TEST_F() local
1187 // Configure the cache to delay the response for AddTransactionToEntry so it in TEST_F()
1189 // transaction (i.e. network activity when run in parallel with the cache in TEST_F()
1191 cache.http_cache()->DelayAddTransactionToEntryForTesting(); in TEST_F()
1193 // Write to the cache. in TEST_F()
1194 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
1198 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1199 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1200 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1212 base::test::ScopedFeatureList& scoped_feature_list, in InitializeSplitCacheScopedFeatureList()
1214 std::vector<base::test::FeatureRef> enabled_features; in InitializeSplitCacheScopedFeatureList()
1215 std::vector<base::test::FeatureRef> disabled_features; in InitializeSplitCacheScopedFeatureList()
1256 base::test::ScopedFeatureList feature_list_;
1262 MockHttpCache cache; in TEST_P() local
1272 // Attempt to populate the cache. in TEST_P()
1273 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_P()
1276 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_P()
1305 CHECK(base::FeatureList::IsEnabled( in HttpCacheTest_SplitCacheFeatureEnabled()
1331 MockHttpCache cache; in TEST_F() local
1333 cache.disk_cache()->set_fail_requests(true); in TEST_F()
1338 // Read from the network, and don't use the cache. in TEST_F()
1339 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
1357 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1358 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1359 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
1364 // This will initialize a cache object with NULL backend. in TEST_F()
1366 factory->set_fail(true); in TEST_F()
1367 factory->FinishCreation(); // We'll complete synchronously. in TEST_F()
1368 MockHttpCache cache(std::move(factory)); in TEST_F() local
1370 // Read from the network, and don't use the cache. in TEST_F()
1371 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1373 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1374 EXPECT_FALSE(cache.http_cache()->GetCurrentBackend()); in TEST_F()
1379 MockHttpCache cache; in TEST_F() local
1381 // Write to the cache. in TEST_F()
1382 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1386 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
1389 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
1392 int rv = trans->Start(&request, cb.callback(), NetLogWithSource()); in TEST_F()
1395 rv = trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
1400 MockHttpCache cache; in TEST_F() local
1402 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_ALL); in TEST_F()
1404 // Read from the network, and fail to write to the cache. in TEST_F()
1405 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1407 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1408 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1409 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1411 // This one should see an empty cache again. in TEST_F()
1412 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1414 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1415 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1416 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1422 MockHttpCache cache; in TEST_F() local
1427 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
1430 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
1432 rv = c->callback.WaitForResult(); in TEST_F()
1435 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_ALL); in TEST_F()
1439 ASSERT_TRUE(cache.OpenBackendEntry(request.CacheKey(), &en)); in TEST_F()
1440 en->Close(); in TEST_F()
1442 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
1445 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1446 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1447 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1449 // This one should see an empty cache again. in TEST_F()
1450 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1452 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1453 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1454 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1457 // Tests that we handle failures to read from the cache.
1459 MockHttpCache cache; in TEST_F() local
1461 // Read from the network, and write to the cache. in TEST_F()
1462 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1464 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1465 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1466 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1468 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_ALL); in TEST_F()
1472 // Now fail to read from the cache. in TEST_F()
1474 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
1477 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
1478 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
1480 // Now verify that the entry was removed from the cache. in TEST_F()
1481 cache.disk_cache()->set_soft_failures_mask(0); in TEST_F()
1483 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1484 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1485 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1487 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1489 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
1490 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1491 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
1495 MockHttpCache cache; in TEST_F() local
1502 // Write to the cache. in TEST_F()
1503 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
1525 // Force this transaction to read from the cache. in TEST_F()
1531 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
1555 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1556 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1557 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1562 MockHttpCache cache; in TEST_F() local
1564 // force this transaction to read from the cache in TEST_F()
1572 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
1574 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
1581 EXPECT_EQ(0, cache.network_layer()->transaction_count()); in TEST_F()
1582 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1583 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
1587 MockHttpCache cache; in TEST_F() local
1589 // write to the cache in TEST_F()
1590 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1592 // force this transaction to read from the cache if valid in TEST_F()
1596 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1598 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1599 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1600 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1604 MockHttpCache cache; in TEST_F() local
1606 // force this transaction to read from the cache if valid in TEST_F()
1610 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1612 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1613 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1614 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1619 MockHttpCache cache; in TEST_F() local
1621 // Write to the cache. in TEST_F()
1624 transaction.response_headers = "Cache-Control: max-age=10000\n" in TEST_F()
1627 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1629 // Read from the cache. in TEST_F()
1631 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1633 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1634 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1635 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1641 MockHttpCache cache; in TEST_F() local
1643 // Write to the cache. in TEST_F()
1646 transaction.response_headers = "Cache-Control: max-age=10000\n" in TEST_F()
1649 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1651 // Attempt to read from the cache... this is a vary mismatch that must reach in TEST_F()
1656 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
1660 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1661 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1662 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1669 MockHttpCache cache; in TEST_F() local
1671 // Write to the cache. in TEST_F()
1674 "Cache-Control: max-age=10000\n" in TEST_F()
1677 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1679 // Attempt to read from the cache... we will still load it from network, in TEST_F()
1683 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
1687 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1688 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1689 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1697 MockHttpCache cache; in TEST_F() local
1698 cache.disk_cache()->set_support_in_memory_entry_data(use_memory_entry_data); in TEST_F()
1700 // Prime cache. in TEST_F()
1702 transaction.response_headers = "Cache-Control: no-cache\n"; in TEST_F()
1705 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1706 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1707 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1708 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1718 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
1721 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
1724 const HttpResponseInfo* response_info = trans->GetResponseInfo(); in TEST_F()
1728 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1730 EXPECT_EQ(false, response_info->was_cached); in TEST_F()
1731 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1732 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1734 EXPECT_EQ(true, response_info->was_cached); in TEST_F()
1735 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1736 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1747 MockHttpCache cache; in TEST_F() local
1748 cache.disk_cache()->set_support_in_memory_entry_data(true); in TEST_F()
1751 // Prime cache. in TEST_F()
1753 transaction.response_headers = "Cache-Control: no-cache\n"; in TEST_F()
1754 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1755 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1756 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1757 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1765 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
1768 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
1774 // Confirm if we have an empty cache, a read is marked as network verified.
1776 MockHttpCache cache; in TEST_F() local
1778 // write to the cache in TEST_F()
1780 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
1783 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1784 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1785 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1791 // Confirm if we have a fresh entry in cache, it isn't marked as
1794 MockHttpCache cache; in TEST_F() local
1796 // Prime cache. in TEST_F()
1799 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1800 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1801 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1803 // Re-run transaction; make sure we don't mark the network as accessed. in TEST_F()
1805 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
1808 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
1814 MockHttpCache cache; in TEST_F() local
1816 // Write to the cache. in TEST_F()
1817 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1819 // Force this transaction to write to the cache again. in TEST_F()
1826 // Write to the cache. in TEST_F()
1827 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
1852 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1853 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1854 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1859 MockHttpCache cache; in TEST_F() local
1861 // write to the cache in TEST_F()
1862 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1864 // force this transaction to write to the cache again in TEST_F()
1866 transaction.request_headers = "pragma: no-cache\r\n"; in TEST_F()
1868 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1870 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1871 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1872 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1876 MockHttpCache cache; in TEST_F() local
1878 // write to the cache in TEST_F()
1879 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1881 // force this transaction to write to the cache again in TEST_F()
1883 transaction.request_headers = "cache-control: no-cache\r\n"; in TEST_F()
1885 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1887 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1888 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
1889 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
1893 MockHttpCache cache; in TEST_F() local
1895 // Write to the cache. in TEST_F()
1896 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1898 // Read from the cache. in TEST_F()
1899 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1901 // Force this transaction to validate the cache. in TEST_F()
1908 cache.http_cache(), transaction, &response_info, in TEST_F()
1911 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1912 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1913 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1919 MockHttpCache cache; in TEST_F() local
1921 // write to the cache in TEST_F()
1922 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1924 // read from the cache in TEST_F()
1925 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
1927 // force this transaction to validate the cache in TEST_F()
1929 transaction.request_headers = "cache-control: max-age=0\r\n"; in TEST_F()
1931 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
1933 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
1934 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
1935 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
1941 MockHttpCache cache; in TEST_F() local
1946 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
1955 cache.http_cache(), prefetch_transaction, &response_info, in TEST_F()
1962 cache.http_cache(), prefetch_transaction, &response_info, in TEST_F()
1969 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
1976 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
1987 MockHttpCache cache; in TEST_F() local
1992 cache.http_cache(), kTypicalGET_Transaction, &response_info, in TEST_F()
2003 cache.http_cache(), prefetch_transaction, &response_info, in TEST_F()
2017 cache.http_cache(), can_use_restricted_prefetch_transaction, in TEST_F()
2025 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
2033 MockHttpCache cache; in TEST_F() local
2041 cache.http_cache(), prefetch_transaction, &response_info, in TEST_F()
2051 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
2058 // can use the entry in the cache now, since it has been evicted in favor of in TEST_F()
2061 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
2069 MockHttpCache cache; in TEST_F() local
2076 cache.http_cache(), prefetch_transaction, &response_info, in TEST_F()
2082 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_WRITE); in TEST_F()
2084 cache.http_cache(), kSimpleGET_Transaction, &response_info, in TEST_F()
2088 // Make sure that if a prefetch entry is truncated, then an attempt to re-use it
2091 MockHttpCache cache; in TEST_F() local
2095 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
2096 "Content-Length: 20\n" in TEST_F()
2106 int rv = cache.CreateTransaction(&c.trans); in TEST_F()
2110 c.trans->Start(&request, c.callback.callback(), NetLogWithSource())); in TEST_F()
2115 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
2117 c.trans->Read(buf.get(), buf->size(), c.callback.callback())); in TEST_F()
2118 EXPECT_EQ(buf->size(), rv); in TEST_F()
2122 base::RunLoop().RunUntilIdle(); in TEST_F()
2124 VerifyTruncatedFlag(&cache, request.CacheKey(), /*flag_value=*/true, in TEST_F()
2134 int rv = cache.CreateTransaction(&c.trans); in TEST_F()
2136 c.trans->SetConnectedCallback(base::BindRepeating( in TEST_F()
2137 [](const TransportInfo& info, CompletionOnceCallback callback) -> int { in TEST_F()
2141 c.trans->Start(&request, c.callback.callback(), NetLogWithSource())); in TEST_F()
2146 base::RunLoop().RunUntilIdle(); in TEST_F()
2148 VerifyTruncatedFlag(&cache, request.CacheKey(), /*flag_value=*/true, in TEST_F()
2155 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
2157 base::RunLoop().RunUntilIdle(); in TEST_F()
2159 VerifyTruncatedFlag(&cache, request.CacheKey(), /*flag_value=*/false, in TEST_F()
2164 // Make sure that if a stale-while-revalidate entry is truncated, then an
2165 // attempt to re-use it gets aborted in connected handler that truncated bit is
2168 MockHttpCache cache; in TEST_F() local
2172 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
2173 "Content-Length: 20\n" in TEST_F()
2174 "Cache-Control: max-age=0, stale-while-revalidate=60\n" in TEST_F()
2179 // Do a truncated read of a stale-while-revalidate resource. in TEST_F()
2184 int rv = cache.CreateTransaction(&c.trans); in TEST_F()
2188 c.trans->Start(&request, c.callback.callback(), NetLogWithSource())); in TEST_F()
2193 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
2195 c.trans->Read(buf.get(), buf->size(), c.callback.callback())); in TEST_F()
2196 EXPECT_EQ(buf->size(), rv); in TEST_F()
2200 base::RunLoop().RunUntilIdle(); in TEST_F()
2202 VerifyTruncatedFlag(&cache, request.CacheKey(), /*flag_value=*/true, in TEST_F()
2211 int rv = cache.CreateTransaction(&c.trans); in TEST_F()
2213 c.trans->SetConnectedCallback(base::BindRepeating( in TEST_F()
2214 [](const TransportInfo& info, CompletionOnceCallback callback) -> int { in TEST_F()
2218 c.trans->Start(&request, c.callback.callback(), NetLogWithSource())); in TEST_F()
2223 base::RunLoop().RunUntilIdle(); in TEST_F()
2225 VerifyTruncatedFlag(&cache, request.CacheKey(), /*flag_value=*/true, in TEST_F()
2232 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
2234 base::RunLoop().RunUntilIdle(); in TEST_F()
2236 VerifyTruncatedFlag(&cache, request.CacheKey(), /*flag_value=*/false, in TEST_F()
2242 base::BindRepeating([](const net::HttpRequestInfo* request,
2246 EXPECT_TRUE(request->extra_headers.HasHeader(kExtraHeaderKey)); in __anond56f448a0602()
2252 MockHttpCache cache; in TEST_F() local
2253 cache.disk_cache()->set_support_in_memory_entry_data(use_memory_entry_data); in TEST_F()
2258 transaction.response_headers = "Cache-Control: max-age=0\n"; in TEST_F()
2262 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
2263 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
2265 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
2268 // entry has caching-hostile headers w/o opening it. in TEST_F()
2270 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2271 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
2273 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
2274 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2283 MockHttpCache cache; in TEST_F() local
2286 cache.disk_cache()->set_support_in_memory_entry_data(use_memory_entry_data); in TEST_F()
2288 // Write to the cache. in TEST_F()
2289 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); in TEST_F()
2293 transaction.request_headers = "If-None-Match: \"foopy\"\r\n" EXTRA_HEADER; in TEST_F()
2296 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
2298 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
2299 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
2300 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2306 MockHttpCache cache; in TEST_F() local
2317 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
2318 ASSERT_THAT(c->result, IsOk()); in TEST_F()
2319 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
2321 c->result = in TEST_F()
2322 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
2327 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); in TEST_F()
2331 base::RunLoop().RunUntilIdle(); in TEST_F()
2335 EXPECT_EQ(kNumTransactions, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
2337 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2338 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2339 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2343 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
2348 if (c->result == ERR_IO_PENDING) in TEST_F()
2349 c->result = c->callback.WaitForResult(); in TEST_F()
2354 EXPECT_FALSE(cache.IsWriterPresent(cache_key)); in TEST_F()
2355 EXPECT_EQ(kNumTransactions - i, cache.GetCountReaders(cache_key)); in TEST_F()
2358 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
2361 // We should not have had to re-open the disk entry in TEST_F()
2362 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2363 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2364 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2368 MockHttpCache cache; in TEST_F() local
2373 transaction_pre.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
2374 transaction_pre.data = "rg: 00-09 "; in TEST_F()
2378 RunTransactionTestWithRequest(cache.http_cache(), transaction_pre, in TEST_F()
2381 EXPECT_EQ(206, response_pre.headers->response_code()); in TEST_F()
2382 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2383 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2384 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2400 RunTransactionTestWithRequest(cache.http_cache(), transaction_all, in TEST_F()
2403 EXPECT_EQ(200, response_all.headers->response_code()); in TEST_F()
2404 // 1 from previous test, failed validation, and re-try. in TEST_F()
2405 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
2406 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
2407 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2415 MockHttpCache cache; in TEST_F() local
2419 transaction_pre.request_headers = "Range: bytes = 10-19\r\n" EXTRA_HEADER; in TEST_F()
2420 transaction_pre.data = "rg: 10-19 "; in TEST_F()
2424 RunTransactionTestWithRequest(cache.http_cache(), transaction_pre, in TEST_F()
2427 EXPECT_EQ(206, response_pre.headers->response_code()); in TEST_F()
2428 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2429 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2430 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2436 // cache and during validation it fails conditionalization. in TEST_F()
2437 cache.FailConditionalizations(); in TEST_F()
2439 transaction_pre.request_headers = "Range: bytes = 10-29\r\n" EXTRA_HEADER; in TEST_F()
2443 transaction_pre.data = "rg: 10-19 rg: 10-19 rg: 20-29 "; in TEST_F()
2446 RunTransactionTestWithRequest(cache.http_cache(), transaction_pre, in TEST_F()
2449 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
2450 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
2451 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
2456 MockHttpCache cache; in TEST_F() local
2461 transaction_pre.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
2462 transaction_pre.data = "rg: 00-09 "; in TEST_F()
2466 RunTransactionTestWithRequest(cache.http_cache(), transaction_pre, in TEST_F()
2469 EXPECT_EQ(206, response_pre.headers->response_code()); in TEST_F()
2470 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2471 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2472 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2477 // file gets stored via a sparse-entry. in TEST_F()
2481 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49" in TEST_F()
2482 " rg: 50-59 rg: 60-69 rg: 70-79 "; in TEST_F()
2486 RunTransactionTestWithRequest(cache.http_cache(), transaction_all, in TEST_F()
2489 EXPECT_EQ(200, response_all.headers->response_code()); in TEST_F()
2491 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
2492 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
2493 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2497 // Grab it again, should not need re-validation. in TEST_F()
2501 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49" in TEST_F()
2502 " rg: 50-59 rg: 60-69 rg: 70-79 "; in TEST_F()
2506 RunTransactionTestWithRequest(cache.http_cache(), transaction_all2, in TEST_F()
2509 EXPECT_EQ(200, response_all2.headers->response_code()); in TEST_F()
2511 // Only one more cache open, no new network traffic. in TEST_F()
2512 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
2513 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
2514 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
2518 // This test verifies that the ConnectedCallback passed to a cache transaction
2520 // cache hit.
2522 MockHttpCache cache; in TEST_F() local
2524 // Request an infix range and populate the cache with it. in TEST_F()
2527 mock_transaction.request_headers = "Range: bytes = 20-29\r\n" EXTRA_HEADER; in TEST_F()
2528 mock_transaction.data = "rg: 20-29 "; in TEST_F()
2531 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
2535 // per subrange, as split up by cache hits. in TEST_F()
2538 mock_transaction.request_headers = "Range: bytes = 10-39\r\n" EXTRA_HEADER; in TEST_F()
2539 mock_transaction.data = "rg: 10-19 rg: 20-29 rg: 30-39 "; in TEST_F()
2546 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2549 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2553 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2565 // registered with the mocking framework - the pointee data is consulted in TEST_F()
2580 // This test verifies that when the ConnectedCallback passed to a cache range
2582 // partial read from cache, then the cache entry is invalidated.
2584 MockHttpCache cache; in TEST_F() local
2586 // Request an infix range and populate the cache with it. in TEST_F()
2589 mock_transaction.request_headers = "Range: bytes = 20-29\r\n" EXTRA_HEADER; in TEST_F()
2590 mock_transaction.data = "rg: 20-29 "; in TEST_F()
2593 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
2597 mock_transaction.request_headers = "Range: bytes = 10-39\r\n" EXTRA_HEADER; in TEST_F()
2598 mock_transaction.data = "rg: 10-19 rg: 20-29 rg: 30-39 "; in TEST_F()
2605 // 2. for the cached infix: from the cache in TEST_F()
2609 // the transaction fails partway and 3) is never created. The cache entry is in TEST_F()
2615 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2618 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2622 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2642 // Request the same range again, observe that nothing is read from cache. in TEST_F()
2647 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2650 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2654 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2664 // the cache entry was doomed during the last transaction so they are not in TEST_F()
2671 // This test verifies that when the ConnectedCallback passed to a cache range
2673 // network transaction, then the cache entry is invalidated.
2676 MockHttpCache cache; in TEST_F() local
2678 // Request a prefix range and populate the cache with it. in TEST_F()
2681 mock_transaction.request_headers = "Range: bytes = 10-19\r\n" EXTRA_HEADER; in TEST_F()
2682 mock_transaction.data = "rg: 10-19 "; in TEST_F()
2685 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
2689 mock_transaction.request_headers = "Range: bytes = 10-29\r\n" EXTRA_HEADER; in TEST_F()
2690 mock_transaction.data = "rg: 10-19 rg: 20-29 "; in TEST_F()
2696 // 1. for the prefix: from the cache in TEST_F()
2702 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2705 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2709 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2729 // Request the same range again, observe that nothing is read from cache. in TEST_F()
2734 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2737 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2741 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2751 // the cache entry was doomed during the last transaction so they are not in TEST_F()
2758 // This test verifies that when the ConnectedCallback passed to a cache
2760 // the overall cache transaction fails with that error. The cache entry is still
2763 MockHttpCache cache; in TEST_F() local
2765 // Request an infix range and populate the cache with it. in TEST_F()
2768 mock_transaction.request_headers = "Range: bytes = 20-29\r\n" EXTRA_HEADER; in TEST_F()
2769 mock_transaction.data = "rg: 20-29 "; in TEST_F()
2772 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
2776 mock_transaction.request_headers = "Range: bytes = 10-39\r\n" EXTRA_HEADER; in TEST_F()
2777 mock_transaction.data = "rg: 10-19 rg: 20-29 rg: 30-39 "; in TEST_F()
2784 // 2. for the cached infix: from the cache in TEST_F()
2789 // cached, such that the cache entry ends up with both the prefix and infix. in TEST_F()
2794 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2797 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2801 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2824 // read from cache. Only the suffix is fetched from the network. in TEST_F()
2829 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2832 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2836 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2840 // 1 call for the first range's cache transaction: the first 20 bytes were in TEST_F()
2855 // This test verifies that the ConnectedCallback passed to a cache transaction
2857 // cache hit, even when a prefix of the range is cached.
2859 MockHttpCache cache; in TEST_F() local
2861 // Request a prefix range and populate the cache with it. in TEST_F()
2864 mock_transaction.request_headers = "Range: bytes = 10-19\r\n" EXTRA_HEADER; in TEST_F()
2865 mock_transaction.data = "rg: 10-19 "; in TEST_F()
2868 RunTransactionTest(cache.http_cache(), mock_transaction); in TEST_F()
2872 // per subrange, as split up by cache hits. in TEST_F()
2875 mock_transaction.request_headers = "Range: bytes = 10-39\r\n" EXTRA_HEADER; in TEST_F()
2876 mock_transaction.data = "rg: 10-19 rg: 20-29 rg: 30-39 "; in TEST_F()
2883 EXPECT_THAT(cache.CreateTransaction(&transaction), IsOk()); in TEST_F()
2886 transaction->SetConnectedCallback(connected_handler.Callback()); in TEST_F()
2890 transaction->Start(&request, callback.callback(), NetLogWithSource()), in TEST_F()
2894 // 1 call for the first range from the cache, reported as coming from the in TEST_F()
2909 // the cache.
2911 MockHttpCache cache; in TEST_F() local
2917 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
2918 ASSERT_THAT(c->result, IsOk()); in TEST_F()
2919 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
2921 cache.disk_cache()->set_fail_requests(true); in TEST_F()
2923 c->result = in TEST_F()
2924 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
2926 base::RunLoop().RunUntilIdle(); in TEST_F()
2928 EXPECT_FALSE(cache.IsWriterPresent(kRangeGET_TransactionOK.url)); in TEST_F()
2930 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2931 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2932 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
2934 c->result = c->callback.WaitForResult(); in TEST_F()
2936 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); in TEST_F()
2938 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
2939 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2940 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
2945 MockHttpCache cache; in TEST_F() local
2957 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
2958 ASSERT_THAT(c->result, IsOk()); in TEST_F()
2959 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
2961 c->result = in TEST_F()
2962 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
2967 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); in TEST_F()
2971 base::RunLoop().RunUntilIdle(); in TEST_F()
2975 EXPECT_TRUE(cache.IsWriterPresent(request.CacheKey())); in TEST_F()
2983 EXPECT_EQ(5, cache.network_layer()->transaction_count()); in TEST_F()
2984 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
2985 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
2988 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
2993 if (c->result == ERR_IO_PENDING) in TEST_F()
2994 c->result = c->callback.WaitForResult(); in TEST_F()
2996 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); in TEST_F()
2999 EXPECT_EQ(5, cache.network_layer()->transaction_count()); in TEST_F()
3000 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3001 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
3008 MockHttpCache cache; in TEST_F() local
3026 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3027 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3028 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3037 first_entry->SetDefer(MockDiskEntry::DEFER_READ); in TEST_F()
3040 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
3043 // Continue the transactions. 2nd will pause at the cache reading state and in TEST_F()
3045 base::RunLoop().RunUntilIdle(); in TEST_F()
3051 first_entry = cache.disk_cache()->GetDiskEntryRef(cache_key); in TEST_F()
3054 EXPECT_FALSE(first_entry->is_doomed()); in TEST_F()
3057 EXPECT_TRUE(first_entry->is_doomed()); in TEST_F()
3058 second_entry = cache.disk_cache()->GetDiskEntryRef(cache_key); in TEST_F()
3059 EXPECT_FALSE(second_entry->is_doomed()); in TEST_F()
3063 // Resume cache read by 1st transaction which will lead to dooming the entry in TEST_F()
3066 first_entry->ResumeDiskEntryOperation(); in TEST_F()
3067 base::RunLoop().RunUntilIdle(); in TEST_F()
3072 EXPECT_TRUE(second_entry->is_doomed()); in TEST_F()
3074 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
3075 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3076 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
3079 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
3083 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); in TEST_F()
3086 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
3087 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3088 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
3094 MockHttpCache cache; in TEST_F() local
3111 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3112 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3113 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3119 cache.disk_cache()->SetDefer(MockDiskEntry::DEFER_CREATE); in TEST_F()
3124 first_entry->SetDefer(MockDiskEntry::DEFER_READ); in TEST_F()
3127 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
3130 // Continue the transactions. 2nd will pause at the cache reading state and in TEST_F()
3133 base::RunLoop().RunUntilIdle(); in TEST_F()
3138 first_entry = cache.disk_cache()->GetDiskEntryRef(request.CacheKey()); in TEST_F()
3141 EXPECT_FALSE(first_entry->is_doomed()); in TEST_F()
3144 EXPECT_TRUE(first_entry->is_doomed()); in TEST_F()
3148 // Resume cache read by 2nd transaction which will lead to dooming the entry in TEST_F()
3151 first_entry->ResumeDiskEntryOperation(); in TEST_F()
3152 base::RunLoop().RunUntilIdle(); in TEST_F()
3155 cache.disk_cache()->ResumeCacheOperation(); in TEST_F()
3156 base::RunLoop().RunUntilIdle(); in TEST_F()
3161 // during that time, leading to it switching over to pass-through mode. in TEST_F()
3163 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
3164 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3165 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
3168 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
3172 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); in TEST_F()
3175 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
3176 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3177 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
3180 // Tests parallel validation on range requests with non-overlapping ranges.
3182 MockHttpCache cache; in TEST_F() local
3193 // Let 1st transaction complete headers phase for ranges 40-49. in TEST_F()
3198 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3199 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3200 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3202 c->result = in TEST_F()
3203 c->trans->Start(&request1, c->callback.callback(), NetLogWithSource()); in TEST_F()
3204 base::RunLoop().RunUntilIdle(); in TEST_F()
3206 // Start writing to the cache so that MockDiskEntry::CouldBeSparse() returns in TEST_F()
3209 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
3211 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
3212 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
3214 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
3217 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3220 // 2nd transaction requests ranges 30-39. in TEST_F()
3221 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; in TEST_F()
3225 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3226 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3227 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3229 c->result = in TEST_F()
3230 c->trans->Start(&request2, c->callback.callback(), NetLogWithSource()); in TEST_F()
3231 base::RunLoop().RunUntilIdle(); in TEST_F()
3233 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3237 EXPECT_TRUE(cache.IsWriterPresent(cache_key)); in TEST_F()
3238 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
3240 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3241 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3242 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3246 if (c->result == ERR_IO_PENDING) in TEST_F()
3247 c->result = c->callback.WaitForResult(); in TEST_F()
3250 ReadRemainingAndVerifyTransaction(c->trans.get(), first_read, in TEST_F()
3255 transaction.data = "rg: 30-39 "; in TEST_F()
3256 ReadAndVerifyTransaction(c->trans.get(), transaction); in TEST_F()
3259 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3260 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3261 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3263 // Fetch from the cache to check that ranges 30-49 have been successfully in TEST_F()
3267 range_transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; in TEST_F()
3268 range_transaction.data = "rg: 30-39 rg: 40-49 "; in TEST_F()
3270 RunTransactionTestWithResponse(cache.http_cache(), range_transaction, in TEST_F()
3275 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3276 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
3277 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3284 MockHttpCache cache; in TEST_F() local
3286 // Save a request in the cache so that the next request can become a in TEST_F()
3291 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
3298 context.result = cache.CreateTransaction(&context.trans); in TEST_F()
3300 context.result = context.trans->Start(&request, context.callback.callback(), in TEST_F()
3302 base::RunLoop().RunUntilIdle(); in TEST_F()
3304 EXPECT_EQ(1, cache.GetCountReaders(cache_key)); in TEST_F()
3308 // non-empty. in TEST_F()
3310 range_transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
3314 range_context.result = cache.CreateTransaction(&range_context.trans); in TEST_F()
3316 range_context.result = range_context.trans->Start( in TEST_F()
3318 base::RunLoop().RunUntilIdle(); in TEST_F()
3320 EXPECT_EQ(1, cache.GetCountReaders(cache_key)); in TEST_F()
3321 EXPECT_FALSE(cache.IsWriterPresent(cache_key)); in TEST_F()
3322 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
3328 // when there is a cache lock timeout.
3330 MockHttpCache cache; in TEST_F() local
3341 // Let 1st transaction complete headers phase for ranges 40-49. in TEST_F()
3346 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3347 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3348 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3350 c->result = in TEST_F()
3351 c->trans->Start(&request1, c->callback.callback(), NetLogWithSource()); in TEST_F()
3352 base::RunLoop().RunUntilIdle(); in TEST_F()
3354 // Start writing to the cache so that MockDiskEntry::CouldBeSparse() returns in TEST_F()
3357 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
3359 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
3360 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
3362 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
3365 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3368 // Cache lock timeout will lead to dooming the entry since the transaction may in TEST_F()
3370 cache.SimulateCacheLockTimeoutAfterHeaders(); in TEST_F()
3372 // 2nd transaction requests ranges 30-39. in TEST_F()
3373 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; in TEST_F()
3377 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3378 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3379 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3381 c->result = in TEST_F()
3382 c->trans->Start(&request2, c->callback.callback(), NetLogWithSource()); in TEST_F()
3383 base::RunLoop().RunUntilIdle(); in TEST_F()
3385 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3388 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(request1.CacheKey())); in TEST_F()
3390 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
3391 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3392 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3396 if (c->result == ERR_IO_PENDING) in TEST_F()
3397 c->result = c->callback.WaitForResult(); in TEST_F()
3400 ReadRemainingAndVerifyTransaction(c->trans.get(), first_read, in TEST_F()
3405 transaction.data = "rg: 30-39 "; in TEST_F()
3406 ReadAndVerifyTransaction(c->trans.get(), transaction); in TEST_F()
3409 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
3410 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3411 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3418 MockHttpCache cache; in TEST_F() local
3424 // Remove the cache-control and other headers so that the response cannot be in TEST_F()
3436 // of the response and write in the cache. in TEST_F()
3442 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3443 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3444 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3446 c->result = in TEST_F()
3447 c->trans->Start(&request1, c->callback.callback(), NetLogWithSource()); in TEST_F()
3448 base::RunLoop().RunUntilIdle(); in TEST_F()
3451 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
3453 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
3454 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
3456 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
3459 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3464 range_transaction.request_headers = "Range: bytes = 0-29\r\n" EXTRA_HEADER; in TEST_F()
3468 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3469 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3470 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3472 c->result = in TEST_F()
3473 c->trans->Start(&request2, c->callback.callback(), NetLogWithSource()); in TEST_F()
3474 base::RunLoop().RunUntilIdle(); in TEST_F()
3476 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3480 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3481 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3482 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
3486 if (c->result == ERR_IO_PENDING) in TEST_F()
3487 c->result = c->callback.WaitForResult(); in TEST_F()
3490 ReadRemainingAndVerifyTransaction(c->trans.get(), first_read, in TEST_F()
3494 range_transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 "; in TEST_F()
3495 ReadAndVerifyTransaction(c->trans.get(), range_transaction); in TEST_F()
3503 MockHttpCache cache; in TEST_F() local
3508 std::string response_headers_str = base::StrCat( in TEST_F()
3510 "Content-Length:", base::NumberToString(strlen(kFullRangeData)), "\n"}); in TEST_F()
3523 // of the response and write in the cache. in TEST_F()
3529 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3530 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3531 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3533 c->result = in TEST_F()
3534 c->trans->Start(&request1, c->callback.callback(), NetLogWithSource()); in TEST_F()
3535 base::RunLoop().RunUntilIdle(); in TEST_F()
3538 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
3540 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
3541 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
3543 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
3546 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3551 range_transaction.request_headers = "Range: bytes = 0-29\r\n" EXTRA_HEADER; in TEST_F()
3555 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3556 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3557 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3559 c->result = in TEST_F()
3560 c->trans->Start(&request2, c->callback.callback(), NetLogWithSource()); in TEST_F()
3561 base::RunLoop().RunUntilIdle(); in TEST_F()
3563 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3566 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3567 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3568 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3572 c0->result = c0->callback.WaitForResult(); in TEST_F()
3573 ReadRemainingAndVerifyTransaction(c0->trans.get(), first_read, transaction); in TEST_F()
3577 c1->result = c1->callback.WaitForResult(); in TEST_F()
3579 range_transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 "; in TEST_F()
3580 ReadAndVerifyTransaction(c1->trans.get(), range_transaction); in TEST_F()
3586 MockHttpCache cache; in TEST_F() local
3597 // Let 1st transaction complete headers phase for ranges 40-49. in TEST_F()
3602 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3603 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3604 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3606 c->result = in TEST_F()
3607 c->trans->Start(&request1, c->callback.callback(), NetLogWithSource()); in TEST_F()
3608 base::RunLoop().RunUntilIdle(); in TEST_F()
3610 // Start writing to the cache so that MockDiskEntry::CouldBeSparse() returns in TEST_F()
3613 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
3615 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
3616 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
3618 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
3621 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3624 // 2nd transaction requests ranges 30-49. in TEST_F()
3625 transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; in TEST_F()
3629 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3630 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3631 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3633 c->result = in TEST_F()
3634 c->trans->Start(&request2, c->callback.callback(), NetLogWithSource()); in TEST_F()
3635 base::RunLoop().RunUntilIdle(); in TEST_F()
3637 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3641 EXPECT_TRUE(cache.IsWriterPresent(cache_key)); in TEST_F()
3642 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
3645 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3646 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3647 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3651 if (c->result == ERR_IO_PENDING) in TEST_F()
3652 c->result = c->callback.WaitForResult(); in TEST_F()
3655 ReadRemainingAndVerifyTransaction(c->trans.get(), first_read, in TEST_F()
3660 transaction.data = "rg: 30-39 rg: 40-49 "; in TEST_F()
3661 ReadAndVerifyTransaction(c->trans.get(), transaction); in TEST_F()
3664 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3665 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3666 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3668 // Fetch from the cache to check that ranges 30-49 have been successfully in TEST_F()
3672 range_transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; in TEST_F()
3673 range_transaction.data = "rg: 30-39 rg: 40-49 "; in TEST_F()
3675 RunTransactionTestWithResponse(cache.http_cache(), range_transaction, in TEST_F()
3680 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3681 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3682 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3688 MockHttpCache cache; in TEST_F() local
3699 // Let 1st transaction complete headers phase for ranges 40-59. in TEST_F()
3701 transaction.request_headers = "Range: bytes = 40-59\r\n" EXTRA_HEADER; in TEST_F()
3705 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3706 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3707 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3709 c->result = in TEST_F()
3710 c->trans->Start(&request1, c->callback.callback(), NetLogWithSource()); in TEST_F()
3711 base::RunLoop().RunUntilIdle(); in TEST_F()
3713 // Start writing to the cache so that MockDiskEntry::CouldBeSparse() returns in TEST_F()
3716 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
3718 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
3719 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
3721 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
3724 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3727 // 2nd transaction requests ranges 30-59. in TEST_F()
3728 transaction.request_headers = "Range: bytes = 30-59\r\n" EXTRA_HEADER; in TEST_F()
3732 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3733 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3734 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3736 c->result = in TEST_F()
3737 c->trans->Start(&request2, c->callback.callback(), NetLogWithSource()); in TEST_F()
3738 base::RunLoop().RunUntilIdle(); in TEST_F()
3740 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3744 EXPECT_TRUE(cache.IsWriterPresent(cache_key)); in TEST_F()
3745 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
3747 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3748 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3749 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3754 base::RunLoop().RunUntilIdle(); in TEST_F()
3756 transaction.data = "rg: 30-39 rg: 40-49 rg: 50-59 "; in TEST_F()
3757 ReadAndVerifyTransaction(context_list[1]->trans.get(), transaction); in TEST_F()
3760 // 30-39 will be read from network, 40-49 from the cache and 50-59 from the in TEST_F()
3762 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
3763 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3764 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3766 // Fetch from the cache to check that ranges 30-49 have been successfully in TEST_F()
3770 range_transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; in TEST_F()
3771 range_transaction.data = "rg: 30-39 rg: 40-49 "; in TEST_F()
3773 RunTransactionTestWithResponse(cache.http_cache(), range_transaction, in TEST_F()
3778 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
3779 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
3780 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3788 MockHttpCache cache; in TEST_F() local
3790 transaction.request_headers = "Range: bytes = 0-\r\n" EXTRA_HEADER; in TEST_F()
3792 transaction.response_headers = "Location: /elsewhere\nContent-Length:5"; in TEST_F()
3798 // Write to the cache. in TEST_F()
3801 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
3803 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
3808 const HttpResponseInfo* info = trans->GetResponseInfo(); in TEST_F()
3811 EXPECT_EQ(info->headers->response_code(), 301); in TEST_F()
3814 info->headers->EnumerateHeader(nullptr, "Location", &location); in TEST_F()
3819 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
3820 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3821 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3823 // Active entries in the cache are not retired synchronously. Make in TEST_F()
3826 base::RunLoop().RunUntilIdle(); in TEST_F()
3828 // Read from the cache. in TEST_F()
3831 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
3833 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
3838 const HttpResponseInfo* info = trans->GetResponseInfo(); in TEST_F()
3841 EXPECT_EQ(info->headers->response_code(), 301); in TEST_F()
3844 info->headers->EnumerateHeader(nullptr, "Location", &location); in TEST_F()
3847 trans->DoneReading(); in TEST_F()
3849 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
3850 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
3851 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3857 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
3859 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
3864 const HttpResponseInfo* info = trans->GetResponseInfo(); in TEST_F()
3867 EXPECT_EQ(info->headers->response_code(), 301); in TEST_F()
3870 info->headers->EnumerateHeader(nullptr, "Location", &location); in TEST_F()
3875 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
3877 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
3878 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3885 MockHttpCache cache; in TEST_F() local
3890 // Create and run the first, successful, transaction to prime the cache. in TEST_F()
3893 c1->result = cache.CreateTransaction(&c1->trans); in TEST_F()
3894 ASSERT_THAT(c1->result, IsOk()); in TEST_F()
3895 EXPECT_EQ(LOAD_STATE_IDLE, c1->trans->GetLoadState()); in TEST_F()
3896 c1->result = in TEST_F()
3897 c1->trans->Start(&request, c1->callback.callback(), NetLogWithSource()); in TEST_F()
3898 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c1->trans->GetLoadState()); in TEST_F()
3899 base::RunLoop().RunUntilIdle(); in TEST_F()
3901 EXPECT_TRUE(cache.IsWriterPresent(request.CacheKey())); in TEST_F()
3902 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
3903 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3904 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3910 c2->result = cache.CreateTransaction(&c2->trans); in TEST_F()
3911 ASSERT_THAT(c2->result, IsOk()); in TEST_F()
3912 EXPECT_EQ(LOAD_STATE_IDLE, c2->trans->GetLoadState()); in TEST_F()
3913 c2->result = in TEST_F()
3914 c2->trans->Start(&request, c2->callback.callback(), NetLogWithSource()); in TEST_F()
3916 // Active Entry that c1 created instead of waiting on the cache to open the in TEST_F()
3918 EXPECT_EQ(LOAD_STATE_IDLE, c2->trans->GetLoadState()); in TEST_F()
3920 cache.disk_cache()->set_fail_requests(true); in TEST_F()
3924 base::RunLoop().RunUntilIdle(); in TEST_F()
3929 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
3934 if (context->result == ERR_IO_PENDING) in TEST_F()
3935 context->result = context->callback.WaitForResult(); in TEST_F()
3936 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
3939 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
3940 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3941 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
3946 MockHttpCache cache; in TEST_F() local
3954 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
3955 ASSERT_THAT(c->result, IsOk()); in TEST_F()
3956 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
3957 c->result = in TEST_F()
3958 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
3963 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); in TEST_F()
3967 base::RunLoop().RunUntilIdle(); in TEST_F()
3972 EXPECT_TRUE(cache.IsWriterPresent(request.CacheKey())); in TEST_F()
3974 EXPECT_EQ(5, cache.network_layer()->transaction_count()); in TEST_F()
3975 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3976 EXPECT_EQ(5, cache.disk_cache()->create_count()); in TEST_F()
3981 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
3985 if (context->result == ERR_IO_PENDING) in TEST_F()
3986 context->result = context->callback.WaitForResult(); in TEST_F()
3987 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
3990 EXPECT_EQ(5, cache.network_layer()->transaction_count()); in TEST_F()
3991 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
3992 EXPECT_EQ(5, cache.disk_cache()->create_count()); in TEST_F()
3999 base::ScopedTempDir temp_dir; in TEST_F()
4006 MockHttpCache cache(std::move(backend_factory)); in TEST_F() local
4014 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
4015 transaction.data = "rg: 00-09 "; in TEST_F()
4019 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
4022 EXPECT_EQ(206, response.headers->response_code()); in TEST_F()
4023 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4031 "2305843009213693952-2305843009213693961\r\n" EXTRA_HEADER; in TEST_F()
4032 transaction.data = "rg: 52-61 "; in TEST_F()
4036 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
4039 EXPECT_EQ(206, response.headers->response_code()); in TEST_F()
4040 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4043 // Can't actually cache it due to backend limitations. If the network in TEST_F()
4049 "2305843009213693952-2305843009213693961\r\n" EXTRA_HEADER; in TEST_F()
4050 transaction.data = "rg: 52-61 "; in TEST_F()
4054 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
4057 EXPECT_EQ(206, response.headers->response_code()); in TEST_F()
4058 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
4065 MockHttpCache cache; in TEST_F() local
4076 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4077 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4078 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
4084 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4090 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); in TEST_F()
4094 base::RunLoop().RunUntilIdle(); in TEST_F()
4098 EXPECT_EQ(kNumTransactions - 1, in TEST_F()
4099 cache.GetCountWriterTransactions(validate_request.CacheKey())); in TEST_F()
4101 EXPECT_EQ(1, cache.disk_cache()->doomed_count()); in TEST_F()
4103 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4104 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4105 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
4108 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
4112 if (context->result == ERR_IO_PENDING) in TEST_F()
4113 context->result = context->callback.WaitForResult(); in TEST_F()
4115 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
4118 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4119 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4120 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
4126 MockHttpCache cache; in TEST_F() local
4145 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4146 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4147 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
4149 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4155 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); in TEST_F()
4159 base::RunLoop().RunUntilIdle(); in TEST_F()
4164 EXPECT_TRUE(cache.disk_cache()->IsDiskEntryDoomed(request.CacheKey())); in TEST_F()
4166 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4167 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4168 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4173 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
4177 if (context->result == ERR_IO_PENDING) in TEST_F()
4178 context->result = context->callback.WaitForResult(); in TEST_F()
4179 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
4182 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4183 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4184 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4190 MockHttpCache cache; in TEST_F() local
4205 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4206 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4210 c->result = c->trans->Start(current_request, c->callback.callback(), in TEST_F()
4215 base::RunLoop().RunUntilIdle(); in TEST_F()
4217 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4218 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4219 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4222 EXPECT_EQ(1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4223 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4227 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4233 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
4236 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4237 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4238 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4244 MockHttpCache cache; in TEST_F() local
4255 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4256 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4258 c->result = in TEST_F()
4259 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
4263 base::RunLoop().RunUntilIdle(); in TEST_F()
4265 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4266 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4267 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4271 EXPECT_EQ(kNumTransactions, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4275 EXPECT_EQ(kNumTransactions - 1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4281 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
4284 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4285 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4286 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4292 MockHttpCache cache; in TEST_F() local
4310 cache.SimulateCacheLockTimeoutAfterHeaders(); in TEST_F()
4313 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4314 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4316 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4321 base::RunLoop().RunUntilIdle(); in TEST_F()
4327 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4328 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4329 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4332 EXPECT_TRUE(cache.IsWriterPresent(cache_key)); in TEST_F()
4333 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4335 base::RunLoop().RunUntilIdle(); in TEST_F()
4337 int rv = context_list[1]->callback.WaitForResult(); in TEST_F()
4340 ReadAndVerifyTransaction(context_list[0]->trans.get(), in TEST_F()
4347 MockHttpCache cache; in TEST_F() local
4362 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4363 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4368 c->trans->SetBeforeNetworkStartCallback(base::BindOnce(&DeferCallback)); in TEST_F()
4371 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4376 base::RunLoop().RunUntilIdle(); in TEST_F()
4378 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4379 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4380 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4384 EXPECT_EQ(kNumTransactions - 1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4385 EXPECT_TRUE(cache.IsHeadersTransactionPresent(cache_key)); in TEST_F()
4388 ReadAndVerifyTransaction(context_list[0]->trans.get(), in TEST_F()
4392 EXPECT_FALSE(cache.IsWriterPresent(cache_key)); in TEST_F()
4393 EXPECT_EQ(kNumTransactions - 2, cache.GetCountReaders(cache_key)); in TEST_F()
4394 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4395 EXPECT_TRUE(cache.IsHeadersTransactionPresent(cache_key)); in TEST_F()
4404 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4405 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4407 c->result = in TEST_F()
4408 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
4411 EXPECT_EQ(2, cache.GetCountAddToEntryQueue(cache_key)); in TEST_F()
4417 EXPECT_EQ(1, cache.GetCountReaders(cache_key)); in TEST_F()
4418 EXPECT_EQ(2, cache.GetCountAddToEntryQueue(cache_key)); in TEST_F()
4419 EXPECT_TRUE(cache.IsHeadersTransactionPresent(cache_key)); in TEST_F()
4423 context_list[3]->trans->ResumeNetworkStart(); in TEST_F()
4426 base::RunLoop().RunUntilIdle(); in TEST_F()
4428 EXPECT_EQ(3, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4432 ReadAndVerifyTransaction(context_list[i]->trans.get(), in TEST_F()
4436 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4437 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4438 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
4451 transaction->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
4457 auto buffer = base::MakeRefCounted<IOBufferWithSize>(1); in TEST_F()
4459 result = transaction->Read(buffer.get(), 1, buffer_callback.callback()); in TEST_F()
4462 // Read the second byte, but leave the cache write hanging. in TEST_F()
4465 mock_cache.disk_cache()->GetDiskEntryRef(cache_key); in TEST_F()
4466 entry->SetDefer(MockDiskEntry::DEFER_WRITE); in TEST_F()
4468 buffer = base::MakeRefCounted<IOBufferWithSize>(1); in TEST_F()
4470 result = transaction->Read(buffer.get(), 1, buffer_callback2.callback()); in TEST_F()
4472 base::RunLoop().RunUntilIdle(); in TEST_F()
4476 // waiting to be written to the cache. Destroy the transaction and make sure in TEST_F()
4480 EXPECT_FALSE(mock_cache.network_layer()->last_transaction()); in TEST_F()
4483 // Tests that a transaction writer can be destroyed mid-read.
4487 MockHttpCache cache; in TEST_F() local
4502 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4503 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4508 c->trans->SetBeforeNetworkStartCallback(base::BindOnce(&DeferCallback)); in TEST_F()
4511 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4516 base::RunLoop().RunUntilIdle(); in TEST_F()
4518 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4519 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4520 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4523 EXPECT_TRUE(cache.IsHeadersTransactionPresent(cache_key)); in TEST_F()
4524 EXPECT_EQ(2, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4526 // Initiate Read from both writers and kill 1 of them mid-read. in TEST_F()
4531 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
4533 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
4534 EXPECT_EQ(ERR_IO_PENDING, c->result); in TEST_F()
4539 base::RunLoop().RunUntilIdle(); in TEST_F()
4540 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
4541 std::string data_read(buffer->data(), kBufferSize); in TEST_F()
4549 c->trans->ResumeNetworkStart(); in TEST_F()
4551 base::RunLoop().RunUntilIdle(); in TEST_F()
4553 EXPECT_EQ(1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4561 ReadRemainingAndVerifyTransaction(context->trans.get(), first_read, in TEST_F()
4564 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
4567 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
4568 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4569 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
4575 MockHttpCache cache; in TEST_F() local
4594 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4595 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4603 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4608 base::RunLoop().RunUntilIdle(); in TEST_F()
4610 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4611 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4612 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4615 EXPECT_EQ(3, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4616 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4622 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
4623 c->result = in TEST_F()
4624 c->trans->Read(buffer.get(), kBufferSize, c->callback.callback()); in TEST_F()
4625 EXPECT_EQ(ERR_IO_PENDING, c->result); in TEST_F()
4628 base::RunLoop().RunUntilIdle(); in TEST_F()
4631 c->result = c->callback.WaitForResult(); in TEST_F()
4632 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, c->result); in TEST_F()
4636 // restarted. Since headers transaction is read-only it will error out. in TEST_F()
4638 read_only->result = read_only->callback.WaitForResult(); in TEST_F()
4639 EXPECT_EQ(ERR_CACHE_MISS, read_only->result); in TEST_F()
4641 EXPECT_FALSE(cache.IsWriterPresent(cache_key)); in TEST_F()
4646 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
4647 c->result = c->trans->Read(buffer.get(), kBufferSize, c->callback.callback()); in TEST_F()
4648 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, c->result); in TEST_F()
4651 // Tests the case when cache write failure happens. Idle and waiting
4654 MockHttpCache cache; in TEST_F() local
4669 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4670 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4676 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4681 base::RunLoop().RunUntilIdle(); in TEST_F()
4683 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4684 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4685 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4688 EXPECT_EQ(3, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4689 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4691 // Initiate Read from two writers and let the first get a cache write failure. in TEST_F()
4692 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_ALL); in TEST_F()
4695 cache.OpenBackendEntry(cache_key, &en); in TEST_F()
4696 en->Close(); in TEST_F()
4699 3, base::MakeRefCounted<IOBufferWithSize>(kBufferSize)); in TEST_F()
4702 c->result = in TEST_F()
4703 c->trans->Read(buffer[i].get(), kBufferSize, c->callback.callback()); in TEST_F()
4704 EXPECT_EQ(ERR_IO_PENDING, c->result); in TEST_F()
4708 base::RunLoop().RunUntilIdle(); in TEST_F()
4711 c->result = c->callback.WaitForResult(); in TEST_F()
4713 EXPECT_EQ(5, c->result); in TEST_F()
4714 std::string data_read(buffer[i]->data(), kBufferSize); in TEST_F()
4717 EXPECT_EQ(ERR_CACHE_WRITE_FAILURE, c->result); in TEST_F()
4722 // restarted. Since headers transaction is read-only it will error out. in TEST_F()
4724 read_only->result = read_only->callback.WaitForResult(); in TEST_F()
4725 EXPECT_EQ(ERR_CACHE_MISS, read_only->result); in TEST_F()
4727 EXPECT_FALSE(cache.IsWriterPresent(cache_key)); in TEST_F()
4731 c->result = in TEST_F()
4732 c->trans->Read(buffer[2].get(), kBufferSize, c->callback.callback()); in TEST_F()
4733 EXPECT_EQ(ERR_CACHE_WRITE_FAILURE, c->result); in TEST_F()
4736 // without writing to the cache. in TEST_F()
4738 ReadRemainingAndVerifyTransaction(succ_read->trans.get(), first_read, in TEST_F()
4743 // writing to the cache. Note that two POSTs only map to the same entry if their
4744 // upload data identifier is same and that should happen for back-forward case
4746 // because read-only transactions anyways do not join parallel writing.
4751 MockHttpCache cache; in TEST_F() local
4776 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4777 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4779 c->result = in TEST_F()
4780 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
4783 base::RunLoop().RunUntilIdle(); in TEST_F()
4788 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4789 EXPECT_EQ(1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4792 ReadAndVerifyTransaction(context_list[0]->trans.get(), in TEST_F()
4796 base::RunLoop().RunUntilIdle(); in TEST_F()
4797 EXPECT_EQ(1, cache.GetCountReaders(cache_key)); in TEST_F()
4798 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4799 ReadAndVerifyTransaction(context_list[1]->trans.get(), in TEST_F()
4802 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4803 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4804 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4812 MockHttpCache cache; in TEST_F() local
4827 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4828 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4834 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4839 base::RunLoop().RunUntilIdle(); in TEST_F()
4841 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4842 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4843 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4846 EXPECT_EQ(3, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4847 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4852 3, base::MakeRefCounted<IOBufferWithSize>(kBufferSize)); in TEST_F()
4855 c->result = in TEST_F()
4856 c->trans->Read(buffer[i].get(), kBufferSize, c->callback.callback()); in TEST_F()
4857 EXPECT_EQ(ERR_IO_PENDING, c->result); in TEST_F()
4861 base::RunLoop().RunUntilIdle(); in TEST_F()
4864 c->result = c->callback.WaitForResult(); in TEST_F()
4865 EXPECT_EQ(5, c->result); in TEST_F()
4866 std::string data_read(buffer[i]->data(), kBufferSize); in TEST_F()
4872 // without writing to the cache. in TEST_F()
4875 ReadRemainingAndVerifyTransaction(c->trans.get(), first_read[i], in TEST_F()
4879 EXPECT_EQ(3, cache.GetCountReaders(cache_key)); in TEST_F()
4886 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
4892 // Tests the case when parallel writing involves things bigger than what cache
4893 // can store. In this case, the best we can do is re-fetch it.
4895 MockHttpCache cache; in TEST_F() local
4896 cache.disk_cache()->set_max_file_size(10); in TEST_F()
4899 std::string response_headers = base::StrCat( in TEST_F()
4900 {kSimpleGET_Transaction.response_headers, "Content-Length: ", in TEST_F()
4901 base::NumberToString(strlen(kSimpleGET_Transaction.data)), "\n"}); in TEST_F()
4913 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4914 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4917 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
4922 base::RunLoop().RunUntilIdle(); in TEST_F()
4924 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4925 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4926 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4929 EXPECT_EQ(1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4930 EXPECT_EQ(kNumTransactions - 1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4935 kNumTransactions, base::MakeRefCounted<IOBufferWithSize>(kBufferSize)); in TEST_F()
4937 c->result = in TEST_F()
4938 c->trans->Read(buffer[0].get(), kBufferSize, c->callback.callback()); in TEST_F()
4939 EXPECT_EQ(ERR_IO_PENDING, c->result); in TEST_F()
4943 base::RunLoop().RunUntilIdle(); in TEST_F()
4944 c->result = c->callback.WaitForResult(); in TEST_F()
4945 EXPECT_EQ(kBufferSize, c->result); in TEST_F()
4946 std::string data_read(buffer[0]->data(), kBufferSize); in TEST_F()
4952 ReadRemainingAndVerifyTransaction(context_list[i]->trans.get(), in TEST_F()
4957 EXPECT_EQ(kNumTransactions, cache.network_layer()->transaction_count()); in TEST_F()
4968 MockHttpCache cache; in TEST_F() local
4979 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
4980 ASSERT_THAT(c->result, IsOk()); in TEST_F()
4982 c->result = in TEST_F()
4983 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
4987 base::RunLoop().RunUntilIdle(); in TEST_F()
4989 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
4990 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
4991 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
4994 EXPECT_EQ(2, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
4995 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
4998 int total_received_bytes = context_list[0]->trans->GetTotalReceivedBytes(); in TEST_F()
5003 ReadAndVerifyTransaction(context_list[1]->trans.get(), in TEST_F()
5006 EXPECT_EQ(1, cache.GetCountReaders(cache_key)); in TEST_F()
5010 EXPECT_EQ(0, context_list[1]->trans->GetTotalReceivedBytes()); in TEST_F()
5013 context_list[0]->trans->GetTotalReceivedBytes()); in TEST_F()
5015 ReadAndVerifyTransaction(context_list[0]->trans.get(), in TEST_F()
5021 MockHttpCache cache; in TEST_F() local
5025 c.result = cache.CreateTransaction(&c.trans); in TEST_F()
5029 c.trans->Start(&request, c.callback.callback(), NetLogWithSource()); in TEST_F()
5031 base::RunLoop().RunUntilIdle(); in TEST_F()
5033 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5034 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5035 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5038 EXPECT_EQ(1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5039 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
5045 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
5046 c.result = c.trans->Read(buffer.get(), kBufferSize, c.callback.callback()); in TEST_F()
5050 // Tests when a writer is destroyed mid-read, all the other writer transactions
5053 MockHttpCache cache; in TEST_F() local
5057 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
5058 "Content-Length: 22\n" in TEST_F()
5069 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5070 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5072 c->result = in TEST_F()
5073 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5077 base::RunLoop().RunUntilIdle(); in TEST_F()
5079 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5080 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5081 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5084 EXPECT_EQ(kNumTransactions, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5090 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
5092 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
5093 EXPECT_EQ(kBufferSize, cb.GetResult(c->result)); in TEST_F()
5100 base::RunLoop().RunUntilIdle(); in TEST_F()
5102 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5103 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5104 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5110 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
5117 MockHttpCache cache; in TEST_F() local
5132 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5133 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5140 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
5145 base::RunLoop().RunUntilIdle(); in TEST_F()
5147 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5148 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5149 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5152 EXPECT_EQ(kNumTransactions - 1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5153 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(cache_key)); in TEST_F()
5156 // restarting the validated transactions. Since it is a read-only transaction in TEST_F()
5158 context_list[0]->trans->StopCaching(); in TEST_F()
5160 base::RunLoop().RunUntilIdle(); in TEST_F()
5162 int rv = context_list[1]->callback.WaitForResult(); in TEST_F()
5165 ReadAndVerifyTransaction(context_list[0]->trans.get(), in TEST_F()
5170 // no-op if there are other writer transactions.
5172 MockHttpCache cache; in TEST_F() local
5187 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5188 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5193 c->trans->SetBeforeNetworkStartCallback(base::BindOnce(&DeferCallback)); in TEST_F()
5196 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
5201 base::RunLoop().RunUntilIdle(); in TEST_F()
5203 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
5204 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5205 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5208 EXPECT_TRUE(cache.IsHeadersTransactionPresent(cache_key)); in TEST_F()
5209 EXPECT_EQ(kNumTransactions - 1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5211 // Invoking StopCaching on the writer will be a no-op since there are multiple in TEST_F()
5213 context_list[0]->trans->StopCaching(); in TEST_F()
5217 c->trans->ResumeNetworkStart(); in TEST_F()
5218 base::RunLoop().RunUntilIdle(); in TEST_F()
5221 EXPECT_EQ(1, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5227 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
5230 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
5231 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5232 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
5238 MockHttpCache cache; in TEST_F() local
5249 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5250 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5253 c->trans->SetBeforeNetworkStartCallback(base::BindOnce(&DeferCallback)); in TEST_F()
5255 c->result = in TEST_F()
5256 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5259 base::RunLoop().RunUntilIdle(); in TEST_F()
5262 EXPECT_TRUE(cache.IsHeadersTransactionPresent(cache_key)); in TEST_F()
5263 EXPECT_EQ(1, cache.GetCountAddToEntryQueue(cache_key)); in TEST_F()
5265 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5266 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5267 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5272 base::RunLoop().RunUntilIdle(); in TEST_F()
5278 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); in TEST_F()
5281 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
5282 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5283 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
5286 // Similar to the above test, except here cache write fails and the
5289 MockHttpCache cache; in TEST_F() local
5300 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5301 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5302 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); in TEST_F()
5304 c->result = in TEST_F()
5305 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5310 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); in TEST_F()
5314 base::RunLoop().RunUntilIdle(); in TEST_F()
5318 EXPECT_EQ(kNumTransactions, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5323 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); in TEST_F()
5326 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5327 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5328 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5331 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_ALL); in TEST_F()
5334 cache.OpenBackendEntry(cache_key, &en); in TEST_F()
5335 en->Close(); in TEST_F()
5339 if (c->result == ERR_IO_PENDING) in TEST_F()
5340 c->result = c->callback.WaitForResult(); in TEST_F()
5343 EXPECT_TRUE(cache.disk_cache()->IsDiskEntryDoomed(cache_key)); in TEST_F()
5347 // Consumer gets the response even if cache write failed. in TEST_F()
5348 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5352 auto buffer = base::MakeRefCounted<IOBufferWithSize>(kBufferSize); in TEST_F()
5354 c->result = c->trans->Read(buffer.get(), kBufferSize, cb.callback()); in TEST_F()
5355 EXPECT_EQ(ERR_CACHE_WRITE_FAILURE, cb.GetResult(c->result)); in TEST_F()
5365 MockHttpCache cache; in TEST_F() local
5378 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5379 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5385 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
5390 base::RunLoop().RunUntilIdle(); in TEST_F()
5395 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5396 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5397 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5400 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); in TEST_F()
5401 c->result = c->callback.WaitForResult(); in TEST_F()
5402 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5408 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState()); in TEST_F()
5409 EXPECT_EQ(LOAD_STATE_IDLE, context_list[3]->trans->GetLoadState()); in TEST_F()
5412 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); in TEST_F()
5413 c->result = c->callback.WaitForResult(); in TEST_F()
5414 if (c->result == OK) in TEST_F()
5415 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5423 c->trans.reset(); in TEST_F()
5427 if (c->result == ERR_IO_PENDING) in TEST_F()
5428 c->result = c->callback.WaitForResult(); in TEST_F()
5429 if (c->result == OK) in TEST_F()
5430 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5433 // We should not have had to re-open the disk entry. in TEST_F()
5435 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5436 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5437 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5444 // We need simultaneous doomed / not_doomed entries so let's use a real cache. in TEST_F()
5445 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(1024 * 1024)); in TEST_F() local
5458 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5459 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5465 c->result = c->trans->Start(this_request, c->callback.callback(), in TEST_F()
5469 base::RunLoop().RunUntilIdle(); in TEST_F()
5474 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
5485 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); in TEST_F()
5486 c->result = c->callback.WaitForResult(); in TEST_F()
5487 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5492 // Test that a doomed writer doesn't set in-memory index hints. in TEST_F()
5493 MockHttpCache cache; in TEST_F() local
5494 cache.disk_cache()->set_support_in_memory_entry_data(true); in TEST_F()
5496 // Request 1 is a normal one to a no-cache/no-etag resource, to potentially in TEST_F()
5497 // set a "this is unvalidatable" hint in the cache. We also need it to in TEST_F()
5501 no_cache_transaction.response_headers = "Cache-Control: no-cache\n"; in TEST_F()
5506 c1.result = cache.CreateTransaction(&c1.trans); in TEST_F()
5508 c1.trans->SetBeforeNetworkStartCallback( in TEST_F()
5509 base::BindOnce([](bool* defer) { *defer = true; })); in TEST_F()
5511 c1.trans->Start(&request1, c1.callback.callback(), NetLogWithSource()); in TEST_F()
5515 base::RunLoop().RunUntilIdle(); in TEST_F()
5518 // Request 2 sets LOAD_BYPASS_CACHE to force the first one to be doomed --- in TEST_F()
5524 c2.result = cache.CreateTransaction(&c2.trans); in TEST_F()
5527 c2.trans->Start(&request2, c2.callback.callback(), NetLogWithSource()); in TEST_F()
5531 base::RunLoop().RunUntilIdle(); in TEST_F()
5535 c1.trans->ResumeNetworkStart(); in TEST_F()
5539 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
5540 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5541 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
5543 // Request 3 tries to read from cache, and it should successfully do so. It's in TEST_F()
5545 // cooperate with them, and is entirely driven by the state of the cache. in TEST_F()
5548 context3.result = cache.CreateTransaction(&context3.trans); in TEST_F()
5550 context3.result = context3.trans->Start( in TEST_F()
5552 base::RunLoop().RunUntilIdle(); in TEST_F()
5557 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
5558 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
5559 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
5566 MockHttpCache cache; in TEST_F() local
5580 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5581 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5583 c->result = in TEST_F()
5584 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5588 base::RunLoop().RunUntilIdle(); in TEST_F()
5594 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
5595 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5596 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
5603 if (c->result == ERR_IO_PENDING) in TEST_F()
5604 c->result = c->callback.WaitForResult(); in TEST_F()
5605 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction); in TEST_F()
5609 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
5610 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5611 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
5617 MockHttpCache cache; in TEST_F() local
5628 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5629 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5631 c->result = in TEST_F()
5632 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5637 base::RunLoop().RunUntilIdle(); in TEST_F()
5639 *cache.http_cache()->GenerateCacheKeyForRequest(&request); in TEST_F()
5640 EXPECT_EQ(kNumTransactions, cache.GetCountWriterTransactions(cache_key)); in TEST_F()
5644 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5645 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5646 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5650 if (c->result == ERR_IO_PENDING) in TEST_F()
5651 c->result = c->callback.WaitForResult(); in TEST_F()
5663 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5666 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5667 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5668 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5672 // cache entry.
5674 MockHttpCache cache; in TEST_F() local
5685 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5686 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5688 c->result = in TEST_F()
5689 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5692 // The first request should be creating the disk cache entry and the others in TEST_F()
5695 EXPECT_EQ(0, cache.network_layer()->transaction_count()); in TEST_F()
5696 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5697 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5710 c->result = c->callback.GetResult(c->result); in TEST_F()
5711 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5715 // We should have had to re-create the disk entry. in TEST_F()
5717 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5718 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5719 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
5722 // Tests that we can cancel a single request to open a disk cache entry.
5724 MockHttpCache cache; in TEST_F() local
5730 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5731 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5733 c->result = in TEST_F()
5734 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5735 EXPECT_THAT(c->result, IsError(ERR_IO_PENDING)); in TEST_F()
5737 // Release the reference that the mock disk cache keeps for this entry, so in TEST_F()
5738 // that we test that the http cache handles the cancellation correctly. in TEST_F()
5739 cache.disk_cache()->ReleaseAll(); in TEST_F()
5742 base::RunLoop().RunUntilIdle(); in TEST_F()
5743 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
5748 MockHttpCache cache; in TEST_F() local
5760 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5761 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5763 c->result = in TEST_F()
5764 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5767 // The first request should be deleting the disk cache entry and the others in TEST_F()
5770 EXPECT_EQ(0, cache.network_layer()->transaction_count()); in TEST_F()
5771 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5772 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
5777 c->result = c->callback.GetResult(c->result); in TEST_F()
5778 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); in TEST_F()
5781 // We should have had to re-create the disk entry multiple times. in TEST_F()
5783 EXPECT_EQ(5, cache.network_layer()->transaction_count()); in TEST_F()
5784 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
5785 EXPECT_EQ(5, cache.disk_cache()->create_count()); in TEST_F()
5788 // Tests that a (simulated) timeout allows transactions waiting on the cache
5791 MockHttpCache cache; in TEST_F() local
5792 cache.SimulateCacheLockTimeout(); in TEST_F()
5796 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk()); in TEST_F()
5797 ASSERT_EQ(ERR_IO_PENDING, c1.trans->Start(&request, c1.callback.callback(), in TEST_F()
5799 ASSERT_THAT(cache.CreateTransaction(&c2.trans), IsOk()); in TEST_F()
5800 ASSERT_EQ(ERR_IO_PENDING, c2.trans->Start(&request, c2.callback.callback(), in TEST_F()
5813 // Tests that a (simulated) timeout allows transactions waiting on the cache
5816 MockHttpCache cache; in TEST_F() local
5819 cache.SimulateCacheLockTimeout(); in TEST_F()
5823 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk()); in TEST_F()
5824 ASSERT_EQ(ERR_IO_PENDING, c1.trans->Start(&request, c1.callback.callback(), in TEST_F()
5828 ASSERT_THAT(cache.CreateTransaction(&c2.trans), IsOk()); in TEST_F()
5829 ASSERT_EQ(ERR_IO_PENDING, c2.trans->Start(&request, c2.callback.callback(), in TEST_F()
5842 MockHttpCache cache; in TEST_F() local
5844 // write to the cache in TEST_F()
5845 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
5851 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
5852 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
5857 auto buf = base::MakeRefCounted<IOBufferWithSize>(256); in TEST_F()
5858 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
5861 // Test that destroying the transaction while it is reading from the cache in TEST_F()
5867 base::RunLoop().RunUntilIdle(); in TEST_F()
5873 auto cache = std::make_unique<MockHttpCache>( in TEST_F() local
5885 c->result = cache->CreateTransaction(&c->trans); in TEST_F()
5886 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5888 c->result = in TEST_F()
5889 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
5892 // The first request should be creating the disk cache entry and the others in TEST_F()
5895 EXPECT_EQ(0, cache->network_layer()->transaction_count()); in TEST_F()
5896 EXPECT_EQ(0, cache->disk_cache()->open_count()); in TEST_F()
5897 EXPECT_EQ(0, cache->disk_cache()->create_count()); in TEST_F()
5899 cache.reset(); in TEST_F()
5906 MockHttpCache cache(std::move(factory)); in TEST_F() local
5919 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5920 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5923 context_list[0]->result = context_list[0]->trans->Start( in TEST_F()
5924 &request0, context_list[0]->callback.callback(), NetLogWithSource()); in TEST_F()
5925 context_list[1]->result = context_list[1]->trans->Start( in TEST_F()
5926 &request1, context_list[1]->callback.callback(), NetLogWithSource()); in TEST_F()
5927 context_list[2]->result = context_list[2]->trans->Start( in TEST_F()
5928 &request2, context_list[2]->callback.callback(), NetLogWithSource()); in TEST_F()
5931 base::RunLoop().RunUntilIdle(); in TEST_F()
5933 // The first request should be creating the disk cache. in TEST_F()
5934 EXPECT_FALSE(context_list[0]->callback.have_result()); in TEST_F()
5936 factory_ptr->FinishCreation(); in TEST_F()
5938 base::RunLoop().RunUntilIdle(); in TEST_F()
5939 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
5940 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
5943 EXPECT_TRUE(context_list[i]->callback.have_result()); in TEST_F()
5953 MockHttpCache cache(std::move(factory)); in TEST_F() local
5966 c->result = cache.CreateTransaction(&c->trans); in TEST_F()
5967 ASSERT_THAT(c->result, IsOk()); in TEST_F()
5970 context_list[0]->result = context_list[0]->trans->Start( in TEST_F()
5971 &request0, context_list[0]->callback.callback(), NetLogWithSource()); in TEST_F()
5972 context_list[1]->result = context_list[1]->trans->Start( in TEST_F()
5973 &request1, context_list[1]->callback.callback(), NetLogWithSource()); in TEST_F()
5974 context_list[2]->result = context_list[2]->trans->Start( in TEST_F()
5975 &request2, context_list[2]->callback.callback(), NetLogWithSource()); in TEST_F()
5978 base::RunLoop().RunUntilIdle(); in TEST_F()
5980 // The first request should be creating the disk cache. in TEST_F()
5981 EXPECT_FALSE(context_list[0]->callback.have_result()); in TEST_F()
5990 factory_ptr->FinishCreation(); in TEST_F()
5992 context_list[2]->result = in TEST_F()
5993 context_list[2]->callback.GetResult(context_list[2]->result); in TEST_F()
5994 ReadAndVerifyTransaction(context_list[2]->trans.get(), kETagGET_Transaction); in TEST_F()
5996 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
5997 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6004 auto cache = std::make_unique<MockHttpCache>(std::move(factory)); in TEST_F() local
6009 c->result = cache->CreateTransaction(&c->trans); in TEST_F()
6010 ASSERT_THAT(c->result, IsOk()); in TEST_F()
6012 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
6015 base::RunLoop().RunUntilIdle(); in TEST_F()
6017 // The request should be creating the disk cache. in TEST_F()
6018 EXPECT_FALSE(c->callback.have_result()); in TEST_F()
6022 // that's owned by `cache`. in TEST_F()
6023 disk_cache::BackendResultCallback callback = factory_ptr->ReleaseCallback(); in TEST_F()
6025 cache.reset(); in TEST_F()
6026 base::RunLoop().RunUntilIdle(); in TEST_F()
6032 // Tests that we can delete the cache while creating the backend, from within
6037 auto cache = std::make_unique<MockHttpCache>(std::move(factory)); in TEST_F() local
6038 auto* cache_ptr = cache.get(); in TEST_F()
6040 DeleteCacheCompletionCallback cb(std::move(cache)); in TEST_F()
6042 int rv = cache_ptr->http_cache()->GetBackend(&backend, cb.callback()); in TEST_F()
6049 c->result = cache_ptr->CreateTransaction(&c->trans); in TEST_F()
6050 ASSERT_THAT(c->result, IsOk()); in TEST_F()
6052 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
6056 rv = cache_ptr->http_cache()->GetBackend(&backend, cb2.callback()); in TEST_F()
6060 base::RunLoop().RunUntilIdle(); in TEST_F()
6063 EXPECT_FALSE(c->callback.have_result()); in TEST_F()
6066 factory_ptr->FinishCreation(); in TEST_F()
6069 // The cache should be gone by now. in TEST_F()
6070 base::RunLoop().RunUntilIdle(); in TEST_F()
6071 EXPECT_THAT(c->callback.GetResult(c->result), IsOk()); in TEST_F()
6076 MockHttpCache cache; in TEST_F() local
6078 // write to the cache in TEST_F()
6079 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); in TEST_F()
6081 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6082 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6083 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6088 RunTransactionTestAndGetTiming(cache.http_cache(), kTypicalGET_Transaction, in TEST_F()
6092 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6093 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6094 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6099 base::BindRepeating([](const HttpRequestInfo* request,
6104 request->extra_headers.HasHeader(HttpRequestHeaders::kIfNoneMatch)); in __anond56f448a0802()
6105 response_status->assign("HTTP/1.1 304 Not Modified"); in __anond56f448a0802()
6106 response_headers->assign(kETagGET_Transaction.response_headers); in __anond56f448a0802()
6107 response_data->clear(); in __anond56f448a0802()
6111 MockHttpCache cache; in TEST_F() local
6115 // write to the cache in TEST_F()
6116 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6118 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6119 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6120 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6129 cache.http_cache(), transaction, in TEST_F()
6133 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6134 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6135 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6149 return base::BindLambdaForTesting([this](const HttpRequestInfo* request, in GetHandlerCallback()
6153 if (request->extra_headers.HasHeader(HttpRequestHeaders::kIfNoneMatch)) { in GetHandlerCallback()
6157 if (request->extra_headers.HasHeader( in GetHandlerCallback()
6163 response_status->assign("HTTP/1.1 304 Not Modified"); in GetHandlerCallback()
6164 response_headers->assign(kTypicalGET_Transaction.response_headers); in GetHandlerCallback()
6165 response_data->clear(); in GetHandlerCallback()
6167 response_status->assign(kTypicalGET_Transaction.status); in GetHandlerCallback()
6168 response_headers->assign(kTypicalGET_Transaction.response_headers); in GetHandlerCallback()
6169 response_data->assign(kTypicalGET_Transaction.data); in GetHandlerCallback()
6181 MockHttpCache cache; in TEST_F() local
6183 // Write to the cache. in TEST_F()
6188 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
6190 "Cache-Control: max-age=0\n" in TEST_F()
6193 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6195 // Read from the cache. in TEST_F()
6199 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
6205 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6206 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6207 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6214 MockHttpCache cache; in TEST_F() local
6216 // Write to the cache. in TEST_F()
6221 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
6223 "Cache-Control: max-age=0\n" in TEST_F()
6226 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6228 // Read from the cache and revalidate the entry. in TEST_F()
6233 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
6239 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6240 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6241 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6248 MockHttpCache cache; in TEST_F() local
6250 // Write to the cache. in TEST_F()
6254 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
6256 "Cache-Control: max-age=0\n" in TEST_F()
6259 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6261 // Read from the cache and revalidate the entry. in TEST_F()
6265 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
6271 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6272 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6273 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6280 MockHttpCache cache; in TEST_F() local
6282 // Write to the cache. in TEST_F()
6287 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
6288 "Cache-Control: max-age=0\n" in TEST_F()
6291 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6293 // Read from the cache and don't revalidate the entry. in TEST_F()
6298 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, in TEST_F()
6304 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6305 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6306 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6313 MockHttpCache cache; in TEST_F() local
6315 // Write to the cache. in TEST_F()
6320 "Cache-Control: max-age=0\n" in TEST_F()
6322 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6329 "Cache-Control: max-age=3600\n" in TEST_F()
6331 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6333 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6334 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6335 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6338 base::RunLoop().RunUntilIdle(); in TEST_F()
6342 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6344 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
6345 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
6346 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6352 MockHttpCache cache; in TEST_F() local
6354 // Write to the cache. in TEST_F()
6359 "Cache-Control: max-age=3600\n" in TEST_F()
6361 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6363 // Vary-mismatch validation receives 304. in TEST_F()
6366 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6368 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6369 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6370 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6373 base::RunLoop().RunUntilIdle(); in TEST_F()
6377 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6379 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
6380 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
6381 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6387 MockHttpCache cache; in TEST_F() local
6389 // Write to the cache. in TEST_F()
6394 "Cache-Control: max-age=0\n" in TEST_F()
6396 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6402 "Cache-Control: max-age=3600\n"; in TEST_F()
6403 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6405 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6406 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6407 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6410 base::RunLoop().RunUntilIdle(); in TEST_F()
6414 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6416 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
6417 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
6418 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6424 MockHttpCache cache; in TEST_F() local
6426 // Write to the cache. in TEST_F()
6431 "Cache-Control: max-age=3600\n" in TEST_F()
6433 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6435 // Vary-mismatch validation receives 304 and no vary header. in TEST_F()
6440 "Cache-Control: max-age=3600\n"; in TEST_F()
6441 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6443 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6444 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6445 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6448 base::RunLoop().RunUntilIdle(); in TEST_F()
6452 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6454 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
6455 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
6456 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6464 request->extra_headers.HasHeader(HttpRequestHeaders::kIfNoneMatch)); in ETagGet_UnconditionalRequest_Handler()
6468 MockHttpCache cache; in TEST_F() local
6473 // Write to the cache. in TEST_F()
6474 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6476 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6477 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6478 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6483 base::BindRepeating(&ETagGet_UnconditionalRequest_Handler); in TEST_F()
6484 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6486 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6487 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6488 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6492 MockHttpCache cache; in TEST_F() local
6497 // Write to the cache. in TEST_F()
6498 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6500 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6501 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6502 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6507 base::BindRepeating(&ETagGet_UnconditionalRequest_Handler); in TEST_F()
6508 transaction.request_headers = "Range: bytes = 5-\r\n"; in TEST_F()
6509 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6511 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6512 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6513 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
6522 request->extra_headers.HasHeader(HttpRequestHeaders::kIfNoneMatch)); in ETagGet_ConditionalRequest_NoStore_Handler()
6523 response_status->assign("HTTP/1.1 304 Not Modified"); in ETagGet_ConditionalRequest_NoStore_Handler()
6524 response_headers->assign("Cache-Control: no-store\n"); in ETagGet_ConditionalRequest_NoStore_Handler()
6525 response_data->clear(); in ETagGet_ConditionalRequest_NoStore_Handler()
6529 MockHttpCache cache; in TEST_F() local
6533 // Write to the cache. in TEST_F()
6534 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6536 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6537 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6538 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6544 base::BindRepeating(&ETagGet_ConditionalRequest_NoStore_Handler); in TEST_F()
6545 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
6547 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
6548 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6549 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
6553 // Write to the cache again. This should create a new entry. in TEST_F()
6554 RunTransactionTest(cache.http_cache(), transaction2); in TEST_F()
6556 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
6557 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
6558 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
6563 // (1) loads |kUrl| -- expects |net_response_1| to be returned.
6564 // (2) loads |kUrl| from cache only -- expects |net_response_1| to be returned.
6565 // (3) loads |kUrl| using |extra_request_headers| -- expects |net_response_2| to
6567 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be
6576 MockHttpCache cache; in ConditionalizedRequestUpdatesCacheHelper() local
6595 // receive |kNetResponse1|, which it saves into the HTTP cache. in ConditionalizedRequestUpdatesCacheHelper()
6607 cache.http_cache(), request, &response_headers); in ConditionalizedRequestUpdatesCacheHelper()
6610 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in ConditionalizedRequestUpdatesCacheHelper()
6611 EXPECT_EQ(0, cache.disk_cache()->open_count()); in ConditionalizedRequestUpdatesCacheHelper()
6612 EXPECT_EQ(1, cache.disk_cache()->create_count()); in ConditionalizedRequestUpdatesCacheHelper()
6615 // cache, so we don't hit the network. in ConditionalizedRequestUpdatesCacheHelper()
6623 cache.http_cache(), request, &response_headers); in ConditionalizedRequestUpdatesCacheHelper()
6626 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in ConditionalizedRequestUpdatesCacheHelper()
6627 EXPECT_EQ(1, cache.disk_cache()->open_count()); in ConditionalizedRequestUpdatesCacheHelper()
6628 EXPECT_EQ(1, cache.disk_cache()->create_count()); in ConditionalizedRequestUpdatesCacheHelper()
6631 // "If-Modified-Since" header. This will cause the request to re-hit the in ConditionalizedRequestUpdatesCacheHelper()
6633 // different -- this simulates a change made to the CSS file. in ConditionalizedRequestUpdatesCacheHelper()
6642 cache.http_cache(), request, &response_headers); in ConditionalizedRequestUpdatesCacheHelper()
6645 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in ConditionalizedRequestUpdatesCacheHelper()
6646 EXPECT_EQ(1, cache.disk_cache()->open_count()); in ConditionalizedRequestUpdatesCacheHelper()
6647 EXPECT_EQ(1, cache.disk_cache()->create_count()); in ConditionalizedRequestUpdatesCacheHelper()
6650 // the cache. Moreover, the value in the cache should be |kNetResponse2| in ConditionalizedRequestUpdatesCacheHelper()
6652 // value in the cache with the modified response. in ConditionalizedRequestUpdatesCacheHelper()
6661 cache.http_cache(), request, &response_headers); in ConditionalizedRequestUpdatesCacheHelper()
6664 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in ConditionalizedRequestUpdatesCacheHelper()
6665 EXPECT_EQ(2, cache.disk_cache()->open_count()); in ConditionalizedRequestUpdatesCacheHelper()
6666 EXPECT_EQ(1, cache.disk_cache()->create_count()); in ConditionalizedRequestUpdatesCacheHelper()
6671 // Check that when an "if-modified-since" header is attached
6678 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6686 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", in TEST_F()
6691 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; in TEST_F()
6697 // Check that when an "if-none-match" header is attached
6718 const char extra_headers[] = "If-None-Match: \"ETAG1\"\r\n"; in TEST_F()
6724 // Check that when an "if-modified-since" header is attached
6733 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6742 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6750 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6755 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; in TEST_F()
6761 // Test that when doing an externally conditionalized if-modified-since
6762 // and there is no corresponding cache entry, a new cache entry is NOT
6765 MockHttpCache cache; in TEST_F() local
6772 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6777 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; in TEST_F()
6795 cache.http_cache(), request, &response_headers); in TEST_F()
6798 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6799 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6800 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
6805 // Test that when doing an externally conditionalized if-modified-since
6806 // and there is no corresponding cache entry, a new cache entry is NOT
6809 MockHttpCache cache; in TEST_F() local
6816 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6821 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; in TEST_F()
6839 cache.http_cache(), request, &response_headers); in TEST_F()
6842 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
6843 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
6844 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
6849 // Test that when doing an externally conditionalized if-modified-since
6850 // if the date does not match the cache entry's last-modified date,
6851 // then we do NOT use the response (304) to update the cache.
6852 // (the if-modified-since date is 2 days AFTER the cache's modification date).
6858 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6867 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6871 // This is two days in the future from the original response's last-modified in TEST_F()
6874 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n"; in TEST_F()
6880 // Test that when doing an externally conditionalized if-none-match
6881 // if the etag does not match the cache entry's etag, then we do not use the
6882 // response (304) to update the cache.
6888 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6897 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6902 const char kExtraRequestHeaders[] = "If-None-Match: \"Foo2\"\r\n"; in TEST_F()
6908 // Test that doing an externally conditionalized request with both if-none-match
6909 // and if-modified-since updates the cache.
6915 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6924 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", in TEST_F()
6929 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" in TEST_F()
6930 "If-None-Match: \"Foo1\"\r\n"; in TEST_F()
6936 // Test that doing an externally conditionalized request with both if-none-match
6937 // and if-modified-since does not update the cache with only one match.
6943 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6952 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", in TEST_F()
6958 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" in TEST_F()
6959 "If-None-Match: \"Foo2\"\r\n"; in TEST_F()
6965 // Test that doing an externally conditionalized request with both if-none-match
6966 // and if-modified-since does not update the cache with only one match.
6972 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
6981 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", in TEST_F()
6987 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n" in TEST_F()
6988 "If-None-Match: \"Foo1\"\r\n"; in TEST_F()
6995 MockHttpCache cache; in TEST_F() local
6997 // Do a typical GET request -- should write an entry into our cache. in TEST_F()
6999 RunTransactionTest(cache.http_cache(), trans); in TEST_F()
7001 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7002 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7003 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7006 // Since the cache key strips the hash sections, this should be a cache hit. in TEST_F()
7011 RunTransactionTest(cache.http_cache(), trans); in TEST_F()
7013 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7014 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7015 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7018 // Tests that we skip the cache for POST requests that do not have an upload
7021 MockHttpCache cache; in TEST_F() local
7023 RunTransactionTest(cache.http_cache(), kSimplePOST_Transaction); in TEST_F()
7025 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7026 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7027 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7030 // Tests POST handling with a disabled cache (no DCHECK).
7032 MockHttpCache cache; in TEST_F() local
7033 cache.http_cache()->set_mode(HttpCache::Mode::DISABLE); in TEST_F()
7035 RunTransactionTest(cache.http_cache(), kSimplePOST_Transaction); in TEST_F()
7037 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7038 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7039 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7043 MockHttpCache cache; in TEST_F() local
7052 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
7055 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
7060 EXPECT_EQ(0, cache.network_layer()->transaction_count()); in TEST_F()
7061 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7062 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7066 MockHttpCache cache; in TEST_F() local
7068 // Test that we hit the cache for POST requests. in TEST_F()
7082 // Populate the cache. in TEST_F()
7083 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
7086 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7087 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7088 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7090 // Load from cache. in TEST_F()
7092 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
7095 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7096 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7097 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7100 // Test that we don't hit the cache for POST requests if there is a byte range.
7102 MockHttpCache cache; in TEST_F() local
7105 transaction.request_headers = "Range: bytes = 0-4\r\n"; in TEST_F()
7118 // Attempt to populate the cache. in TEST_F()
7119 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
7122 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7123 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7124 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7129 MockHttpCache cache; in TEST_F() local
7140 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7142 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7143 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7144 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7149 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7151 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7152 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7153 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7158 MockHttpCache cache; in TEST_F() local
7164 // Attempt to populate the cache. in TEST_F()
7165 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7167 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7168 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7169 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7181 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7183 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7184 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7185 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7187 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7189 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7190 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7191 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
7196 // with cache split by top-frame origin.
7202 MockHttpCache cache; in TEST_P() local
7211 // Attempt to populate the cache. in TEST_P()
7212 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_P()
7219 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1b, in TEST_P()
7222 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_P()
7223 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_P()
7224 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_P()
7239 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_P()
7241 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_P()
7242 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_P()
7243 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_P()
7245 // req1b should still be cached, since it has a different top-level frame in TEST_P()
7247 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1b, in TEST_P()
7249 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_P()
7250 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_P()
7251 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_P()
7254 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_P()
7255 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_P()
7256 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_P()
7257 EXPECT_EQ(4, cache.disk_cache()->create_count()); in TEST_P()
7265 MockHttpCache cache; in TEST_F() local
7271 // Attempt to populate the cache. in TEST_F()
7272 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7274 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7275 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7276 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7288 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7290 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7291 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7292 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7294 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7296 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7297 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7298 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7304 // This will initialize a cache object with NULL backend. in TEST_F()
7306 factory->set_fail(true); in TEST_F()
7307 factory->FinishCreation(); in TEST_F()
7308 MockHttpCache cache(std::move(factory)); in TEST_F() local
7320 RunTransactionTestWithRequest(cache.http_cache(), transaction, req, nullptr); in TEST_F()
7327 MockHttpCache cache; in TEST_F() local
7333 // Attempt to populate the cache. in TEST_F()
7334 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7336 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7337 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7338 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7350 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7352 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7353 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7354 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7356 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7358 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7359 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7360 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7366 MockHttpCache cache; in TEST_F() local
7376 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
7379 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
7384 EXPECT_EQ(0, cache.network_layer()->transaction_count()); in TEST_F()
7385 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7386 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7392 MockHttpCache cache; in TEST_F() local
7396 // Populate the cache. in TEST_F()
7397 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7399 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7400 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7401 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7403 // Load from cache. in TEST_F()
7407 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7409 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7410 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7411 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7415 // Tests that a read-only request served from the cache preserves CL.
7417 MockHttpCache cache; in TEST_F() local
7420 transaction.response_headers = "Content-Length: 42\n"; in TEST_F()
7422 // Populate the cache. in TEST_F()
7423 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7425 // Load from cache. in TEST_F()
7431 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
7433 EXPECT_EQ("HTTP/1.1 200 OK\nContent-Length: 42\n", headers); in TEST_F()
7437 // Tests that a read-write request served from the cache preserves CL.
7439 MockHttpCache cache; in TEST_F() local
7443 server_headers.append("Content-Length: 42\n"); in TEST_F()
7446 // Populate the cache. in TEST_F()
7447 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7449 // Load from cache. in TEST_F()
7454 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
7456 EXPECT_NE(std::string::npos, headers.find("Content-Length: 42\n")); in TEST_F()
7460 // Tests that a HEAD request that includes byte ranges bypasses the cache.
7462 MockHttpCache cache; in TEST_F() local
7466 // Populate the cache. in TEST_F()
7467 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7469 // Load from cache. in TEST_F()
7471 transaction.request_headers = "Range: bytes = 0-4\r\n"; in TEST_F()
7474 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7476 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7477 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7483 MockHttpCache cache; in TEST_F() local
7486 // Write to the cache (40-49). in TEST_F()
7487 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
7498 // Load from cache. in TEST_F()
7499 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
7502 EXPECT_NE(std::string::npos, headers.find("Content-Length: 80\n")); in TEST_F()
7503 EXPECT_EQ(std::string::npos, headers.find("Content-Range")); in TEST_F()
7504 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7505 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7506 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7512 MockHttpCache cache; in TEST_F() local
7516 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
7518 "Accept-Ranges: bytes\n" in TEST_F()
7519 "Content-Length: 80\n"); in TEST_F()
7520 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
7531 // Load from cache. in TEST_F()
7532 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
7535 EXPECT_NE(std::string::npos, headers.find("Content-Length: 80\n")); in TEST_F()
7536 EXPECT_EQ(std::string::npos, headers.find("Content-Range")); in TEST_F()
7537 EXPECT_EQ(0, cache.network_layer()->transaction_count()); in TEST_F()
7538 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7539 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7545 MockHttpCache cache; in TEST_F() local
7549 // Populate the cache. in TEST_F()
7550 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7552 // Update the cache. in TEST_F()
7558 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
7562 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7568 base::RunLoop().RunUntilIdle(); in TEST_F()
7570 // Load from the cache. in TEST_F()
7572 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); in TEST_F()
7575 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7576 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
7577 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7581 // Tests that an externally conditionalized HEAD request updates the cache.
7583 MockHttpCache cache; in TEST_F() local
7587 // Populate the cache. in TEST_F()
7588 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7590 // Update the cache. in TEST_F()
7593 "If-Modified-Since: Wed, 28 Nov 2007 00:40:09 GMT\r\n"; in TEST_F()
7598 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
7602 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7608 base::RunLoop().RunUntilIdle(); in TEST_F()
7610 // Load from the cache. in TEST_F()
7612 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); in TEST_F()
7615 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7616 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
7617 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7623 MockHttpCache cache; in TEST_F() local
7627 // Populate the cache. in TEST_F()
7628 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7630 // Update the cache. in TEST_F()
7633 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7634 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7636 // Load from the cache. in TEST_F()
7640 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7645 // Tests that we do not cache the response of a PUT.
7647 MockHttpCache cache; in TEST_F() local
7660 // Attempt to populate the cache. in TEST_F()
7661 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
7664 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7665 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7666 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7671 MockHttpCache cache; in TEST_F() local
7676 // Attempt to populate the cache. in TEST_F()
7677 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7679 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7680 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7681 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7692 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7694 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7695 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7696 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7698 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7700 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7701 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7702 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7707 MockHttpCache cache; in TEST_F() local
7713 // Attempt to populate the cache. in TEST_F()
7714 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7716 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7717 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7718 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7730 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7732 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7733 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7734 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7736 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7738 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7739 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7740 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7746 MockHttpCache cache; in TEST_F() local
7752 // Attempt to populate the cache. in TEST_F()
7753 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7755 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7756 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7757 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7769 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7771 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7772 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7773 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7775 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7777 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7778 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
7779 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7783 // Tests that we do not cache the response of a DELETE.
7785 MockHttpCache cache; in TEST_F() local
7798 // Attempt to populate the cache. in TEST_F()
7799 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, in TEST_F()
7802 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7803 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7804 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
7809 MockHttpCache cache; in TEST_F() local
7814 // Attempt to populate the cache. in TEST_F()
7815 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7817 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7818 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7819 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7830 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7832 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7833 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7834 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7836 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7838 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7839 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7840 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7845 MockHttpCache cache; in TEST_F() local
7850 // Attempt to populate the cache. in TEST_F()
7851 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7853 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7854 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7855 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7860 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7862 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7863 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7864 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7867 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7869 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7870 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7871 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7877 MockHttpCache cache; in TEST_F() local
7882 // Attempt to populate the cache. in TEST_F()
7883 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7885 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7886 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7887 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7892 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7894 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7895 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7896 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7900 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7902 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7903 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
7904 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7910 MockHttpCache cache; in TEST_F() local
7915 // Attempt to populate the cache. in TEST_F()
7916 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7918 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7919 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7920 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7931 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, nullptr); in TEST_F()
7933 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7934 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7935 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7937 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, nullptr); in TEST_F()
7939 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7940 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7941 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7946 MockHttpCache cache; in TEST_F() local
7951 // Attempt to populate the cache. in TEST_F()
7952 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7954 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7955 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7956 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7961 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7963 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7964 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7965 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7968 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7970 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
7971 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7972 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
7978 MockHttpCache cache; in TEST_F() local
7983 // Attempt to populate the cache. in TEST_F()
7984 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7986 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
7987 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
7988 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
7993 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
7995 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
7996 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
7997 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8001 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8003 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8004 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
8005 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8011 MockHttpCache cache; in TEST_F() local
8013 // Populate the cache. in TEST_F()
8014 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
8015 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8023 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8024 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8030 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8033 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8038 MockHttpCache cache; in TEST_F() local
8040 // Test that we skip the cache for range GET requests. Eventually, we will in TEST_F()
8041 // want to cache these, but we'll still have cases where skipping the cache in TEST_F()
8044 RunTransactionTest(cache.http_cache(), kRangeGET_Transaction); in TEST_F()
8046 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8047 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8048 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
8051 transaction.request_headers = "If-None-Match: foo\r\n"; in TEST_F()
8052 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8054 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8055 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8056 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
8059 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n"; in TEST_F()
8060 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8062 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8063 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8064 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
8067 // Test that we skip the cache for range requests that include a validation
8070 MockHttpCache cache; in TEST_F() local
8073 transaction.request_headers = "If-None-Match: foo\r\n" in TEST_F()
8075 "Range: bytes = 40-49\r\n"; in TEST_F()
8076 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8078 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8079 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8080 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
8083 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n" in TEST_F()
8085 "Range: bytes = 40-49\r\n"; in TEST_F()
8086 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8088 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8089 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8090 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
8092 transaction.request_headers = "If-Range: bla\r\n" in TEST_F()
8094 "Range: bytes = 40-49\r\n"; in TEST_F()
8095 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8097 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8098 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8099 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
8103 MockHttpCache cache; in TEST_F() local
8106 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
8114 MockHttpCache cache; in TEST_F() local
8117 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, in TEST_F()
8125 MockHttpCache cache; in TEST_F() local
8129 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; in TEST_F()
8130 RunTransactionTestWithLog(cache.http_cache(), transaction, in TEST_F()
8138 MockHttpCache cache; in TEST_F() local
8142 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; in TEST_F()
8143 RunTransactionTestWithLog(cache.http_cache(), transaction, in TEST_F()
8152 MockHttpCache cache; in TEST_F() local
8154 // Write to the cache. in TEST_F()
8159 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8161 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8162 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8163 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8166 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8168 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8169 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8170 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8176 MockHttpCache cache; in TEST_F() local
8178 // Write to the cache. in TEST_F()
8182 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8184 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8185 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8186 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8193 MockHttpCache cache; in TEST_F() local
8196 // Attempt to write to the cache (40-49). in TEST_F()
8198 transaction.response_headers = "Content-Length: 10\n" in TEST_F()
8199 "Cache-Control: max-age=3600\n" in TEST_F()
8201 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8204 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8205 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8206 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8209 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8213 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8214 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8215 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8220 MockHttpCache cache; in TEST_F() local
8221 cache.FailConditionalizations(); in TEST_F()
8224 // Write to the cache (40-49). in TEST_F()
8226 transaction.response_headers = "Content-Length: 10\n" in TEST_F()
8228 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8231 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8232 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8233 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8236 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8240 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8241 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8242 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8248 MockHttpCache cache; in TEST_F() local
8249 cache.FailConditionalizations(); in TEST_F()
8251 // Write to the cache (40-49). in TEST_F()
8253 transaction.response_headers = "Content-Length: 10\n" in TEST_F()
8255 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8259 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8270 MockHttpCache cache; in TEST_F() local
8271 cache.disk_cache()->set_support_in_memory_entry_data(use_memory_entry_data); in TEST_F()
8272 cache.FailConditionalizations(); in TEST_F()
8275 // Write to the cache (40-49). in TEST_F()
8278 "Content-Length: 10\n" in TEST_F()
8280 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8283 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8284 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8285 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8288 // Don't ask for a range. The cache will attempt to use the cached data but in TEST_F()
8293 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8296 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8297 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8298 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8301 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8302 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8304 // The cache entry isn't really useful, since when in TEST_F()
8305 // &RangeTransactionServer::RangeHandler gets a non-range request, in TEST_F()
8307 // Last-Modified or caching headers, with a Date in 2007 (so no heuristic in TEST_F()
8308 // freshness), so it's both expired and not conditionalizable --- so in in TEST_F()
8310 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8311 EXPECT_EQ(3, cache.disk_cache()->create_count()); in TEST_F()
8313 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
8314 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8320 // require the cache to modify the range to ask, result in a network request
8323 MockHttpCache cache; in TEST_F() local
8324 cache.FailConditionalizations(); in TEST_F()
8327 // Write to the cache (40-49). in TEST_F()
8329 transaction.response_headers = "Content-Length: 10\n" in TEST_F()
8331 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8334 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8335 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8336 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8340 // cache would normally mix data from three sources. After deleting the entry, in TEST_F()
8342 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; in TEST_F()
8343 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; in TEST_F()
8345 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8348 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8349 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8350 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8353 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8354 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8355 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
8356 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8359 // Tests that we cache partial responses that lack content-length.
8361 MockHttpCache cache; in TEST_F() local
8364 // Attempt to write to the cache (40-49). in TEST_F()
8368 "Accept-Ranges: bytes\n" in TEST_F()
8369 "Content-Range: bytes 40-49/80\n"; in TEST_F()
8371 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8373 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8374 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8375 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8379 base::BindRepeating(&RangeTransactionServer::RangeHandler); in TEST_F()
8380 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8384 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8385 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8386 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8391 // Tests that we can cache range requests and fetch random blocks from the
8392 // cache and the network.
8394 MockHttpCache cache; in TEST_F() local
8398 // Write to the cache (40-49). in TEST_F()
8399 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8403 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8404 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8405 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8407 // Read from the cache (40-49). in TEST_F()
8408 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8412 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8413 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8414 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8417 base::RunLoop().RunUntilIdle(); in TEST_F()
8419 // Write to the cache (30-39). in TEST_F()
8421 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; in TEST_F()
8422 transaction.data = "rg: 30-39 "; in TEST_F()
8423 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8426 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8427 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
8428 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8431 base::RunLoop().RunUntilIdle(); in TEST_F()
8433 // Write and read from the cache (20-59). in TEST_F()
8434 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; in TEST_F()
8435 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; in TEST_F()
8438 cache.http_cache(), transaction, &headers, in TEST_F()
8442 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
8443 EXPECT_EQ(3, cache.disk_cache()->open_count()); in TEST_F()
8444 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8451 // Tests recovery on cache read error on range request. in TEST_F()
8452 MockHttpCache cache; in TEST_F() local
8456 // Write to the cache (40-49). in TEST_F()
8457 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8461 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8462 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8463 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8465 cache.disk_cache()->set_soft_failures_one_instance(MockDiskEntry::FAIL_ALL); in TEST_F()
8467 // Try to read from the cache (40-49), which will fail quickly enough to in TEST_F()
8470 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8474 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8475 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8476 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8481 // Tests that range requests with no-store get correct content-length
8484 MockHttpCache cache; in TEST_F() local
8487 std::string response_headers = base::StrCat( in TEST_F()
8488 {kRangeGET_TransactionOK.response_headers, "Cache-Control: no-store\n"}); in TEST_F()
8493 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8496 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8497 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8498 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8503 // Tests a 304 setting no-store on existing 206 entry.
8505 MockHttpCache cache; in TEST_F() local
8508 std::string response_headers = base::StrCat( in TEST_F()
8509 {kRangeGET_TransactionOK.response_headers, "Cache-Control: max-age=0\n"}); in TEST_F()
8514 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8517 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8518 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8519 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8521 response_headers = base::StrCat( in TEST_F()
8522 {kRangeGET_TransactionOK.response_headers, "Cache-Control: no-store\n"}); in TEST_F()
8524 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8527 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8528 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8529 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8531 // Fetch again, this one should be from newly created cache entry, due to in TEST_F()
8532 // earlier no-store. in TEST_F()
8534 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8535 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8536 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8537 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8543 // Tests that we can cache range requests and fetch random blocks from the
8544 // cache and the network, with synchronous responses.
8546 MockHttpCache cache; in TEST_F() local
8552 // Write to the cache (40-49). in TEST_F()
8554 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8557 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8558 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8559 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8561 // Read from the cache (40-49). in TEST_F()
8562 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8565 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8566 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8567 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8570 base::RunLoop().RunUntilIdle(); in TEST_F()
8572 // Write to the cache (30-39). in TEST_F()
8573 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; in TEST_F()
8574 transaction.data = "rg: 30-39 "; in TEST_F()
8575 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8578 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8579 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8580 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8583 base::RunLoop().RunUntilIdle(); in TEST_F()
8585 // Write and read from the cache (20-59). in TEST_F()
8586 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; in TEST_F()
8587 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; in TEST_F()
8590 cache.http_cache(), transaction, &headers, in TEST_F()
8594 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
8595 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
8596 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8606 MockHttpCache cache; in TEST_F() local
8611 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8617 *cache.http_cache()->GenerateCacheKeyForRequest(&request); in TEST_F()
8618 ASSERT_TRUE(cache.OpenBackendEntry(cache_key, &entry)); in TEST_F()
8619 entry->CancelSparseIO(); in TEST_F()
8622 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8625 entry->CancelSparseIO(); in TEST_F()
8628 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8630 entry->Close(); in TEST_F()
8635 MockHttpCache cache; in TEST_F() local
8638 // Write to the cache (40-49). in TEST_F()
8641 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" in TEST_F()
8644 "Accept-Ranges: bytes\n" in TEST_F()
8645 "Content-Length: 10\n"; in TEST_F()
8647 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8650 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8651 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8652 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8654 // Read from the cache (40-49). in TEST_F()
8658 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), transaction, in TEST_F()
8663 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8664 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8665 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8670 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), transaction, in TEST_F()
8675 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8676 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8677 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8685 MockHttpCache cache; in TEST_F() local
8688 // Write to the cache (40-49). in TEST_F()
8691 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" in TEST_F()
8694 "Accept-Ranges: bytes\n" in TEST_F()
8695 "Content-Length: 10\n"; in TEST_F()
8697 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8700 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8701 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8702 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8704 // Read from the cache (40-49). in TEST_F()
8705 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8708 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8709 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8710 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8717 MockHttpCache cache; in TEST_F() local
8721 // Write to the cache (40-49). in TEST_F()
8722 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8726 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8727 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8728 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8730 // Read from the cache (40-49). in TEST_F()
8735 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8738 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8739 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8740 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8747 MockHttpCache cache; in TEST_F() local
8751 // Write to the cache (40-49). in TEST_F()
8752 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
8756 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8757 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8758 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8760 // Attempt to read from the cache (40-49). in TEST_F()
8765 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8768 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8769 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8770 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8773 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
8774 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8775 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8776 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8781 // Tests that when a server returns 206 with a sub-range of the requested range,
8782 // and there is nothing stored in the cache, the returned response is passed to
8787 MockHttpCache cache; in TEST_F() local
8790 // Request a large range (40-59). The server sends 40-49. in TEST_F()
8792 transaction.request_headers = "Range: bytes = 40-59\r\n" EXTRA_HEADER; in TEST_F()
8794 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
8796 "Accept-Ranges: bytes\n" in TEST_F()
8797 "Content-Length: 10\n" in TEST_F()
8798 "Content-Range: bytes 40-49/80\n"; in TEST_F()
8800 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8803 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8804 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8805 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8808 // Tests that when a server returns 206 with a sub-range of the requested range,
8809 // and there was an entry stored in the cache, the cache gets out of the way.
8811 MockHttpCache cache; in TEST_F() local
8814 // Write to the cache (70-79). in TEST_F()
8816 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; in TEST_F()
8817 transaction.data = "rg: 70-79 "; in TEST_F()
8818 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8821 // Request a large range (40-79). The cache will ask the server for 40-59. in TEST_F()
8822 // The server returns 40-49. The cache should consider the server confused and in TEST_F()
8824 transaction.request_headers = "Range: bytes = 40-79\r\n" EXTRA_HEADER; in TEST_F()
8826 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
8828 "Accept-Ranges: bytes\n" in TEST_F()
8829 "Content-Length: 10\n" in TEST_F()
8830 "Content-Range: bytes 40-49/80\n"; in TEST_F()
8832 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8834 // Two new network requests were issued, one from the cache and another after in TEST_F()
8837 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8838 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8839 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8842 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8843 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
8844 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8845 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8848 // Tests that when a server returns 206 with a sub-range of the requested range,
8849 // and there was an entry stored in the cache, the cache gets out of the way,
8852 MockHttpCache cache; in TEST_F() local
8855 // Write to the cache (70-79). in TEST_F()
8857 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; in TEST_F()
8858 transaction.data = "rg: 70-79 "; in TEST_F()
8859 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8862 // Don't ask for a range. The cache will ask the server for 0-69. in TEST_F()
8863 // The server returns 40-49. The cache should consider the server confused and in TEST_F()
8867 transaction.request_headers = "X-Return-Default-Range:\r\n" EXTRA_HEADER; in TEST_F()
8869 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8872 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8873 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8874 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8877 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8878 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
8879 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8880 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8884 // nothing stored in the cache, the returned response is passed to the caller
8890 MockHttpCache cache; in TEST_F() local
8893 // Request a large range (30-59). The server sends (40-49). in TEST_F()
8895 transaction.request_headers = "Range: bytes = 30-59\r\n" EXTRA_HEADER; in TEST_F()
8897 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
8899 "Accept-Ranges: bytes\n" in TEST_F()
8900 "Content-Length: 10\n" in TEST_F()
8901 "Content-Range: bytes 40-49/80\n"; in TEST_F()
8903 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8906 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8907 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8908 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8911 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8912 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8913 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8914 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8918 // an entry stored in the cache, the cache gets out of the way.
8920 MockHttpCache cache; in TEST_F() local
8923 // Write to the cache (70-79). in TEST_F()
8925 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; in TEST_F()
8926 transaction.data = "rg: 70-79 "; in TEST_F()
8927 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8930 // Request a large range (30-79). The cache will ask the server for 30-69. in TEST_F()
8931 // The server returns 40-49. The cache should consider the server confused and in TEST_F()
8933 transaction.request_headers = "Range: bytes = 30-79\r\n" EXTRA_HEADER; in TEST_F()
8935 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
8937 "Accept-Ranges: bytes\n" in TEST_F()
8938 "Content-Length: 10\n" in TEST_F()
8939 "Content-Range: bytes 40-49/80\n"; in TEST_F()
8941 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8944 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
8945 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8946 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8949 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8950 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
8951 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8952 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
8955 // Tests that when a caller asks for a range beyond EOF, with an empty cache,
8958 MockHttpCache cache; in TEST_F() local
8961 // Request a large range (70-99). The server sends 70-79. in TEST_F()
8963 transaction.request_headers = "Range: bytes = 70-99\r\n" EXTRA_HEADER; in TEST_F()
8964 transaction.data = "rg: 70-79 "; in TEST_F()
8965 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8968 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
8969 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
8970 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8972 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
8973 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8977 // the cache automatically fixes the request.
8979 MockHttpCache cache; in TEST_F() local
8982 // Write to the cache (40-49). in TEST_F()
8984 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8986 // Request a large range (70-99). The server sends 70-79. in TEST_F()
8987 transaction.request_headers = "Range: bytes = 70-99\r\n" EXTRA_HEADER; in TEST_F()
8988 transaction.data = "rg: 70-79 "; in TEST_F()
8989 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
8992 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8993 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
8994 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
8997 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
8998 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
8999 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
9000 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9003 // Tests that when a caller asks for a not-satisfiable range, the server's
9006 MockHttpCache cache; in TEST_F() local
9009 // Request a range beyond EOF (80-99). in TEST_F()
9011 transaction.request_headers = "Range: bytes = 80-99\r\n" EXTRA_HEADER; in TEST_F()
9014 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9017 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9018 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9019 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9022 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
9023 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9026 // Tests that we cache 301s for range requests.
9028 MockHttpCache cache; in TEST_F() local
9035 // Write to the cache. in TEST_F()
9036 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
9037 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9038 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9039 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9041 // Read from the cache. in TEST_F()
9042 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
9043 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9044 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9045 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9048 // Tests that we can cache range requests when the start or end is unknown.
9051 MockHttpCache cache; in TEST_F() local
9055 // Write to the cache (70-79). in TEST_F()
9057 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; in TEST_F()
9058 transaction.data = "rg: 70-79 "; in TEST_F()
9059 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9062 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9063 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9064 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9067 base::RunLoop().RunUntilIdle(); in TEST_F()
9069 // Write and read from the cache (60-79). in TEST_F()
9070 transaction.request_headers = "Range: bytes = 60-\r\n" EXTRA_HEADER; in TEST_F()
9071 transaction.data = "rg: 60-69 rg: 70-79 "; in TEST_F()
9072 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9075 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9076 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9077 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9082 // Tests that we can cache range requests when the start or end is unknown.
9084 // We'll also verify that synchronous cache responses work as intended.
9086 MockHttpCache cache; in TEST_F() local
9095 // Write to the cache (70-79). in TEST_F()
9096 transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER; in TEST_F()
9097 transaction.data = "rg: 70-79 "; in TEST_F()
9098 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9101 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9102 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9103 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9106 base::RunLoop().RunUntilIdle(); in TEST_F()
9108 // Write and read from the cache (60-79). in TEST_F()
9109 transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER; in TEST_F()
9110 transaction.data = "rg: 60-69 rg: 70-79 "; in TEST_F()
9111 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9114 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9115 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9116 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9124 MockHttpCache cache; in TEST_F() local
9129 "Cache-Control: max-age=10000\n" in TEST_F()
9130 "Content-Length: 0\n", in TEST_F()
9136 // Write the empty resource to the cache. in TEST_F()
9137 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9140 "HTTP/1.1 200 OK\nCache-Control: max-age=10000\nContent-Length: 0\n", in TEST_F()
9142 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9143 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9144 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9147 base::RunLoop().RunUntilIdle(); in TEST_F()
9149 // Write and read from the cache. This used to trigger a DCHECK in TEST_F()
9151 transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER; in TEST_F()
9152 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9155 "HTTP/1.1 200 OK\nCache-Control: max-age=10000\nContent-Length: 0\n", in TEST_F()
9157 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9158 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9159 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9163 // cache 302, which is notably bodiless.
9165 MockHttpCache cache; in TEST_F() local
9171 "Cache-Control: max-age=0\n" in TEST_F()
9172 "Content-Length: 0\n" in TEST_F()
9176 transaction.request_headers = "Range: bytes = 0-\r\n" EXTRA_HEADER; in TEST_F()
9181 // Write the empty resource to the cache. in TEST_F()
9182 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9186 "Cache-Control: max-age=0\n" in TEST_F()
9187 "Content-Length: 0\n" in TEST_F()
9190 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9191 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9192 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9195 base::RunLoop().RunUntilIdle(); in TEST_F()
9197 // Try to read from the cache. This should send a network request to in TEST_F()
9200 "Cache-Control: max-age=0\n" in TEST_F()
9201 "Content-Length: 0\n" in TEST_F()
9203 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9207 "Cache-Control: max-age=0\n" in TEST_F()
9208 "Content-Length: 0\n" in TEST_F()
9211 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9212 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9214 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9218 // cache 302, which is notably bodiless, where the 302 is replaced with an
9221 MockHttpCache cache; in TEST_F() local
9227 "Cache-Control: max-age=0\n" in TEST_F()
9228 "Content-Length: 0\n" in TEST_F()
9236 // Write the empty resource to the cache. in TEST_F()
9237 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9241 "Cache-Control: max-age=0\n" in TEST_F()
9242 "Content-Length: 0\n" in TEST_F()
9245 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9246 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9247 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9250 base::RunLoop().RunUntilIdle(); in TEST_F()
9252 // Try to read from the cache. This should send a network request to in TEST_F()
9255 base::BindRepeating(&RangeTransactionServer::RangeHandler); in TEST_F()
9256 transaction.request_headers = "Range: bytes = -30\r\n" EXTRA_HEADER; in TEST_F()
9258 transaction.data = "rg: 50-59 rg: 60-69 rg: 70-79 "; in TEST_F()
9260 transaction.response_headers = "Content-Length: 10\n"; in TEST_F()
9261 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9265 "Content-Range: bytes 50-79/80\n" in TEST_F()
9266 "Content-Length: 30\n", in TEST_F()
9268 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9269 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9271 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9277 MockHttpCache cache; in TEST_F() local
9287 transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER; in TEST_F()
9289 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9291 // We just bypass the cache. in TEST_F()
9293 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9294 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9295 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9297 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
9298 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9303 // Tests that we can handle non-range requests when we have cached a range.
9305 MockHttpCache cache; in TEST_F() local
9312 // Write to the cache (40-49). in TEST_F()
9314 cache.http_cache(), kRangeGET_TransactionOK, &headers, in TEST_F()
9318 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9319 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9320 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9323 // Write and read from the cache (0-79), when not asked for a range. in TEST_F()
9327 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), transaction, in TEST_F()
9332 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
9333 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9334 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9340 // Tests that we can handle non-range requests when we have cached the first
9343 MockHttpCache cache; in TEST_F() local
9353 // Write to the cache (0-9). in TEST_F()
9354 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
9355 transaction.data = "rg: 00-09 "; in TEST_F()
9356 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), transaction, in TEST_F()
9362 // Write to the cache (70-79). in TEST_F()
9363 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; in TEST_F()
9364 transaction.data = "rg: 70-79 "; in TEST_F()
9365 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), transaction, in TEST_F()
9370 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9371 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9372 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9375 // Read from the cache (0-9), write and read from cache (10 - 79). in TEST_F()
9379 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), transaction, in TEST_F()
9384 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
9385 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
9386 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9395 MockHttpCache cache; in TEST_F() local
9399 // Write to the cache (0-9). in TEST_F()
9401 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
9402 transaction.data = "rg: 00-09 "; in TEST_F()
9403 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9406 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9407 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9408 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9422 cache.http_cache(), transaction2, &headers, in TEST_F()
9426 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
9427 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9428 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9432 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
9433 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9440 MockHttpCache cache; in TEST_F() local
9443 // Create a disk cache entry that stores 206 headers while not being sparse. in TEST_F()
9445 ASSERT_TRUE(cache.CreateBackendEntry(request.CacheKey(), &entry, nullptr)); in TEST_F()
9452 response.headers = base::MakeRefCounted<HttpResponseHeaders>( in TEST_F()
9456 auto buf(base::MakeRefCounted<IOBufferWithSize>(500)); in TEST_F()
9457 int len = static_cast<int>(base::strlcpy(buf->data(), in TEST_F()
9460 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); in TEST_F()
9462 entry->Close(); in TEST_F()
9468 cache.http_cache(), kSimpleGET_Transaction, &headers, in TEST_F()
9476 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9477 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9478 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9485 MockHttpCache cache; in TEST_F() local
9488 // Create a disk cache entry that stores 206 headers while not being sparse. in TEST_F()
9491 ASSERT_TRUE(cache.CreateBackendEntry(request.CacheKey(), &entry, nullptr)); in TEST_F()
9498 response.headers = base::MakeRefCounted<HttpResponseHeaders>( in TEST_F()
9502 auto buf = base::MakeRefCounted<IOBufferWithSize>(500); in TEST_F()
9503 int len = static_cast<int>(base::strlcpy(buf->data(), in TEST_F()
9506 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); in TEST_F()
9508 entry->Close(); in TEST_F()
9512 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
9517 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9518 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9519 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9526 MockHttpCache cache; in TEST_F() local
9529 // Create a disk cache entry that stores 206 headers. in TEST_F()
9531 ASSERT_TRUE(cache.CreateBackendEntry(request.CacheKey(), &entry, nullptr)); in TEST_F()
9536 raw_headers.append("Content-Length: 80\n"); in TEST_F()
9539 response.headers = base::MakeRefCounted<HttpResponseHeaders>( in TEST_F()
9543 auto buf = base::MakeRefCounted<IOBufferWithSize>(500); in TEST_F()
9544 int len = static_cast<int>(base::strlcpy(buf->data(), in TEST_F()
9547 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); in TEST_F()
9549 entry->Close(); in TEST_F()
9553 RunTransactionTestWithResponse(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
9561 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9562 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9563 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9568 MockHttpCache cache; in TEST_F() local
9575 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
9576 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9577 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9578 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9588 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); in TEST_F()
9592 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9593 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9594 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9597 base::RunLoop().RunUntilIdle(); in TEST_F()
9601 transaction3.request_headers = "Range: bytes = 80-90\r\n" EXTRA_HEADER; in TEST_F()
9604 RunTransactionTestWithResponse(cache.http_cache(), transaction3, &headers); in TEST_F()
9605 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
9607 EXPECT_EQ(std::string::npos, headers.find("Content-Range:")); in TEST_F()
9608 EXPECT_EQ(std::string::npos, headers.find("Content-Length: 80")); in TEST_F()
9611 base::RunLoop().RunUntilIdle(); in TEST_F()
9614 RunTransactionTest(cache.http_cache(), transaction2); in TEST_F()
9615 EXPECT_EQ(3, cache.disk_cache()->open_count()); in TEST_F()
9618 base::RunLoop().RunUntilIdle(); in TEST_F()
9623 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); in TEST_F()
9625 EXPECT_EQ(4, cache.network_layer()->transaction_count()); in TEST_F()
9626 EXPECT_EQ(4, cache.disk_cache()->open_count()); in TEST_F()
9627 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9629 RunTransactionTest(cache.http_cache(), transaction2); in TEST_F()
9630 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9637 MockHttpCache cache; in TEST_F() local
9641 // Write to the cache (70-79). in TEST_F()
9643 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; in TEST_F()
9644 transaction.data = "rg: 70-79 "; in TEST_F()
9645 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9648 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9649 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9650 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9661 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); in TEST_F()
9667 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9668 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9669 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9677 MockHttpCache cache; in TEST_F() local
9681 // Write to the cache (40-49). in TEST_F()
9682 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
9686 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9687 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9688 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9690 // A weird request should not delete this entry. Ask for bytes 120-. in TEST_F()
9692 transaction.request_headers = "Range: bytes = 120-\r\n" EXTRA_HEADER; in TEST_F()
9694 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9697 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9698 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9699 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9701 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
9702 EXPECT_EQ(2, cache.disk_cache()->open_count()); in TEST_F()
9703 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9710 MockHttpCache cache; in TEST_F() local
9716 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
9719 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
9721 rv = c->callback.WaitForResult(); in TEST_F()
9723 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9724 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9725 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9729 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
9730 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
9732 rv = c->callback.WaitForResult(); in TEST_F()
9733 EXPECT_EQ(buf->size(), rv); in TEST_F()
9740 ASSERT_TRUE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
9741 entry->Close(); in TEST_F()
9748 MockHttpCache cache; in TEST_F() local
9754 int rv = cache.CreateTransaction(&context->trans); in TEST_F()
9757 rv = context->trans->Start(&request, context->callback.callback(), in TEST_F()
9760 rv = context->callback.WaitForResult(); in TEST_F()
9762 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9763 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9764 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9768 base::MakeRefCounted<IOBufferWithSize>(5); in TEST_F()
9769 rv = context->trans->Read(buf.get(), buf->size(), in TEST_F()
9770 context->callback.callback()); in TEST_F()
9777 base::RunLoop().RunUntilIdle(); in TEST_F()
9780 VerifyTruncatedFlag(&cache, request.CacheKey(), false, 0); in TEST_F()
9787 MockHttpCache cache; in TEST_F() local
9790 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
9795 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
9798 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
9800 rv = c->callback.WaitForResult(); in TEST_F()
9802 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9803 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9804 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9806 // Make sure that we revalidate the entry and read from the cache (a single in TEST_F()
9809 base::MakeRefCounted<IOBufferWithSize>(5); in TEST_F()
9810 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
9811 EXPECT_EQ(5, c->callback.GetResult(rv)); in TEST_F()
9812 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
9822 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
9824 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9825 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9826 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9833 MockHttpCache cache; in TEST_F() local
9836 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
9841 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
9844 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
9846 rv = c->callback.WaitForResult(); in TEST_F()
9848 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9849 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9850 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9852 // Make sure that we revalidate the entry and read from the cache (a single in TEST_F()
9855 base::MakeRefCounted<IOBufferWithSize>(5); in TEST_F()
9856 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
9857 EXPECT_EQ(5, c->callback.GetResult(rv)); in TEST_F()
9858 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
9869 rv = cache.CreateTransaction(&c->trans); in TEST_F()
9872 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
9876 base::RunLoop().RunUntilIdle(); in TEST_F()
9883 base::RunLoop().RunUntilIdle(); in TEST_F()
9885 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9886 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9887 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9893 MockHttpCache cache; in TEST_F() local
9898 transaction.response_headers = "Content-Range: bytes 40-49/45\n" in TEST_F()
9899 "Content-Length: 10\n"; in TEST_F()
9901 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9908 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9909 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9910 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9915 EXPECT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
9920 // Tests that we reject a range that doesn't match the content-length.
9922 MockHttpCache cache; in TEST_F() local
9927 transaction.response_headers = "Content-Range: bytes 40-49/80\n" in TEST_F()
9928 "Content-Length: 20\n"; in TEST_F()
9930 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9937 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9938 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9939 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9944 EXPECT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
9952 MockHttpCache cache; in TEST_F() local
9957 transaction.request_headers = "Range: bytes = 50-59\r\n" EXTRA_HEADER; in TEST_F()
9959 response_headers.append("Content-Range: bytes 50-59/160\n"); in TEST_F()
9962 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
9965 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
9966 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
9967 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9974 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
9978 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
9979 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9980 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
9983 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
9984 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
9985 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
9991 // We need a real sparse cache for this test. in TEST_F()
9992 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(1024 * 1024)); in TEST_F() local
9997 transaction.request_headers = "Range: bytes = 4294967288-4294967297\r\n" in TEST_F()
10001 "Content-Range: bytes 4294967288-4294967297/4294967299\n" in TEST_F()
10002 "Content-Length: 10\n"; in TEST_F()
10004 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
10011 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10016 ASSERT_TRUE(cache.OpenBackendEntry(request.CacheKey(), &en)); in TEST_F()
10017 en->Close(); in TEST_F()
10022 // Tests that we don't crash with a range request if the disk cache was not
10026 factory->set_fail(true); in TEST_F()
10027 factory->FinishCreation(); // We'll complete synchronously. in TEST_F()
10028 MockHttpCache cache(std::move(factory)); in TEST_F() local
10032 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
10033 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10038 // Tests that we handle byte range requests that skip the cache.
10040 MockHttpCache cache; in TEST_F() local
10044 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; in TEST_F()
10046 transaction.data = "rg: 70-79 "; in TEST_F()
10049 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
10052 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10053 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10054 EXPECT_EQ(0, cache.disk_cache()->create_count()); in TEST_F()
10059 // Tests that we don't crash when after reading from the cache we issue a
10062 MockHttpCache cache; in TEST_F() local
10065 transaction.request_headers = "Range: bytes = 40-\r\n" EXTRA_HEADER; in TEST_F()
10069 // Write to the cache. in TEST_F()
10070 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
10072 // And now read from the cache and the network. in TEST_F()
10077 RunTransactionTestWithLog(cache.http_cache(), transaction, in TEST_F()
10080 EXPECT_EQ(3, cache.network_layer()->transaction_count()); in TEST_F()
10081 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10082 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10090 MockHttpCache cache; in TEST_F() local
10092 // First, check with an empty cache (WRITE mode). in TEST_F()
10094 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; in TEST_F()
10095 transaction.data = "rg: 40-"; // Less than expected. in TEST_F()
10098 headers.append("Content-Range: bytes 40-49/80\n"); in TEST_F()
10103 // Write to the cache. in TEST_F()
10104 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
10106 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10107 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10108 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10112 transaction.request_headers = "Range: bytes = 60-69\r\n" EXTRA_HEADER; in TEST_F()
10113 transaction.data = "rg: 60-"; // Less than expected. in TEST_F()
10115 headers.append("Content-Range: bytes 60-69/80\n"); in TEST_F()
10118 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
10120 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10121 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10122 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10128 MockHttpCache cache; in TEST_F() local
10131 // Write to the cache (40-49). in TEST_F()
10132 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
10133 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10134 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10135 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10137 // Force this transaction to read from the cache. in TEST_F()
10145 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
10149 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
10156 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10157 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10158 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10165 MockHttpCache cache; in TEST_F() local
10167 ASSERT_TRUE(cache.CreateBackendEntry( in TEST_F()
10171 response.headers = base::MakeRefCounted<HttpResponseHeaders>( in TEST_F()
10185 entry->Close(); in TEST_F()
10196 base::MakeRefCounted<HttpResponseHeaders>("HTTP/1.1 200 OK"); in TEST_F()
10199 base::Pickle pickle; in TEST_F()
10211 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); in TEST_F()
10217 MockHttpCache cache; in TEST_F() local
10222 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10225 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10227 c->result = c->callback.WaitForResult(); in TEST_F()
10229 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10230 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10231 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10237 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
10239 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10240 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10241 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
10245 // does not have content-length and strong validators.
10247 MockHttpCache cache; in TEST_F() local
10252 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10255 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10257 rv = c->callback.WaitForResult(); in TEST_F()
10259 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10260 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10261 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10265 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
10266 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10268 rv = c->callback.WaitForResult(); in TEST_F()
10269 EXPECT_EQ(buf->size(), rv); in TEST_F()
10274 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
10276 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10277 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10278 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
10282 // has an "Accept-Ranges: none" header.
10284 MockHttpCache cache; in TEST_F() local
10288 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
10289 "Content-Length: 22\n" in TEST_F()
10290 "Accept-Ranges: none\n" in TEST_F()
10296 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10299 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10301 rv = c->callback.WaitForResult(); in TEST_F()
10303 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10304 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10305 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10309 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
10310 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10312 rv = c->callback.WaitForResult(); in TEST_F()
10313 EXPECT_EQ(buf->size(), rv); in TEST_F()
10318 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
10320 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10321 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10322 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
10329 MockHttpCache cache; in TEST_F() local
10333 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
10334 "Content-Length: 22\n" in TEST_F()
10340 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10343 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10345 rv = c->callback.WaitForResult(); in TEST_F()
10347 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10348 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10349 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10353 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
10354 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10356 rv = c->callback.WaitForResult(); in TEST_F()
10357 EXPECT_EQ(buf->size(), rv); in TEST_F()
10360 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10362 EXPECT_FALSE(c->callback.have_result()); in TEST_F()
10365 c->trans.reset(); in TEST_F()
10371 EXPECT_FALSE(c->callback.have_result()); in TEST_F()
10373 base::RunLoop().RunUntilIdle(); in TEST_F()
10374 VerifyTruncatedFlag(&cache, request.CacheKey(), true, 0); in TEST_F()
10380 MockHttpCache cache; in TEST_F() local
10384 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
10385 "Content-Length: 22\n" in TEST_F()
10392 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10395 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10397 rv = c->callback.WaitForResult(); in TEST_F()
10399 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10400 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
10401 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10405 base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
10406 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10408 rv = c->callback.WaitForResult(); in TEST_F()
10409 EXPECT_EQ(buf->size(), rv); in TEST_F()
10412 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10414 EXPECT_FALSE(c->callback.have_result()); in TEST_F()
10419 c->trans.reset(); in TEST_F()
10426 EXPECT_FALSE(c->callback.have_result()); in TEST_F()
10431 base::RunLoop().RunUntilIdle(); in TEST_F()
10433 ASSERT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
10438 MockHttpCache cache; in TEST_F() local
10442 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
10443 "Content-Length: 22\n" in TEST_F()
10448 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10451 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10452 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
10456 base::MakeRefCounted<IOBufferWithSize>(22); in TEST_F()
10457 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10458 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); in TEST_F()
10461 c->trans.reset(); in TEST_F()
10464 VerifyTruncatedFlag(&cache, request.CacheKey(), false, 0); in TEST_F()
10469 MockHttpCache cache; in TEST_F() local
10472 transaction.request_headers = "Range: bytes = 0-19\r\n" EXTRA_HEADER; in TEST_F()
10477 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
10481 rv = trans->Start(request.get(), cb.callback(), NetLogWithSource()); in TEST_F()
10484 auto buf = base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
10485 rv = trans->Read(buf.get(), 10, cb.callback()); in TEST_F()
10490 VerifyTruncatedFlag(&cache, request->CacheKey(), false, 0); in TEST_F()
10496 MockHttpCache cache; in TEST_F() local
10499 transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; in TEST_F()
10504 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
10508 rv = trans->Start(request.get(), cb.callback(), NetLogWithSource()); in TEST_F()
10511 auto buf = base::MakeRefCounted<IOBufferWithSize>(10); in TEST_F()
10512 rv = trans->Read(buf.get(), 10, cb.callback()); in TEST_F()
10517 VerifyTruncatedFlag(&cache, request->CacheKey(), false, 0); in TEST_F()
10522 MockHttpCache cache; in TEST_F() local
10526 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10528 "Accept-Ranges: bytes\n" in TEST_F()
10529 "Content-Length: 80\n"); in TEST_F()
10530 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10536 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
10541 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10542 "Accept-Ranges: bytes\n" in TEST_F()
10544 "Content-Length: 80\n"); in TEST_F()
10547 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10548 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10549 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10553 VerifyTruncatedFlag(&cache, request.CacheKey(), false, 80); in TEST_F()
10556 // Tests the handling of no-store when revalidating a truncated entry.
10558 MockHttpCache cache; in TEST_F() local
10562 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10564 "Accept-Ranges: bytes\n" in TEST_F()
10565 "Content-Length: 80\n"); in TEST_F()
10566 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10573 response_headers += ("Cache-Control: no-store\n"); in TEST_F()
10579 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
10584 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10585 "Accept-Ranges: bytes\n" in TEST_F()
10586 "Cache-Control: no-store\n" in TEST_F()
10588 "Content-Length: 80\n"); in TEST_F()
10591 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10592 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10593 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10598 EXPECT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
10602 // Tests cancelling a request after the server sent no-store.
10604 MockHttpCache cache; in TEST_F() local
10608 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10610 "Accept-Ranges: bytes\n" in TEST_F()
10611 "Content-Length: 80\n"); in TEST_F()
10612 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10619 response_headers += ("Cache-Control: no-store\n"); in TEST_F()
10627 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10635 ASSERT_THAT(cache.CreateTransaction(&pending->trans), IsOk()); in TEST_F()
10637 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10639 pending->trans->Start(&request, pending->callback.callback(), in TEST_F()
10641 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
10645 base::MakeRefCounted<IOBufferWithSize>(5); in TEST_F()
10646 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); in TEST_F()
10647 EXPECT_EQ(5, c->callback.GetResult(rv)); in TEST_F()
10654 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10655 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10656 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10658 base::RunLoop().RunUntilIdle(); in TEST_F()
10664 MockHttpCache cache; in TEST_F() local
10667 // Content-length will be intentionally bad. in TEST_F()
10669 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10671 "Accept-Ranges: bytes\n" in TEST_F()
10672 "Content-Length: 50\n"); in TEST_F()
10673 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10681 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
10689 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10690 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10691 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10696 ASSERT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
10702 MockHttpCache cache; in TEST_F() local
10707 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" in TEST_F()
10709 "Cache-Control: max-age= 36000\n" in TEST_F()
10710 "Accept-Ranges: bytes\n" in TEST_F()
10711 "Content-Length: 80\n"); in TEST_F()
10712 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10721 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10725 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10726 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
10729 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10730 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10731 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10738 MockHttpCache cache; in TEST_F() local
10742 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
10744 "Accept-Ranges: bytes\n" in TEST_F()
10745 "Content-Length: 80\n"); in TEST_F()
10746 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10750 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" in TEST_F()
10756 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10760 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10761 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
10763 const HttpResponseInfo* response = c->trans->GetResponseInfo(); in TEST_F()
10765 ASSERT_EQ(401, response->headers->response_code()); in TEST_F()
10766 rv = c->trans->RestartWithAuth(AuthCredentials(), c->callback.callback()); in TEST_F()
10767 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
10768 response = c->trans->GetResponseInfo(); in TEST_F()
10770 ASSERT_EQ(200, response->headers->response_code()); in TEST_F()
10772 ReadAndVerifyTransaction(c->trans.get(), transaction); in TEST_F()
10774 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10778 ASSERT_TRUE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
10779 entry->Close(); in TEST_F()
10787 MockHttpCache cache; in TEST_F() local
10789 // Cache 0-9, so that we have data to read before failing. in TEST_F()
10791 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
10792 transaction.data = "rg: 00-09 "; in TEST_F()
10794 // Write to the cache. in TEST_F()
10795 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
10796 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10798 // And now read from the cache and the network. 10-19 will get a in TEST_F()
10799 // 401, but will have already returned 0-9. in TEST_F()
10800 // We do not set X-Require-Mock-Auth because that causes the mock in TEST_F()
10803 "Range: bytes = 0-79\r\n" in TEST_F()
10804 "X-Require-Mock-Auth-Alt: dummy\r\n" EXTRA_HEADER; in TEST_F()
10807 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10812 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10814 rv = c->callback.WaitForResult(); in TEST_F()
10816 rv = ReadTransaction(c->trans.get(), &content); in TEST_F()
10820 // Tests that we cache a 200 response to the validation request.
10822 MockHttpCache cache; in TEST_F() local
10826 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" in TEST_F()
10828 "Accept-Ranges: bytes\n" in TEST_F()
10829 "Content-Length: 80\n"); in TEST_F()
10830 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10838 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); in TEST_F()
10840 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10841 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10842 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10846 VerifyTruncatedFlag(&cache, request.CacheKey(), false, 11); in TEST_F()
10852 MockHttpCache cache; in TEST_F() local
10856 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" in TEST_F()
10858 "Accept-Ranges: bytes\n" in TEST_F()
10859 "Content-Length: 80\n"); in TEST_F()
10860 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10867 int rv = cache.CreateTransaction(&c->trans); in TEST_F()
10870 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); in TEST_F()
10871 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); in TEST_F()
10873 // Read 20 bytes from the cache, and 10 from the net. in TEST_F()
10874 auto buf = base::MakeRefCounted<IOBufferWithSize>(100); in TEST_F()
10875 rv = c->trans->Read(buf.get(), 20, c->callback.callback()); in TEST_F()
10876 EXPECT_EQ(20, c->callback.GetResult(rv)); in TEST_F()
10877 rv = c->trans->Read(buf.get(), 10, c->callback.callback()); in TEST_F()
10878 EXPECT_EQ(10, c->callback.GetResult(rv)); in TEST_F()
10884 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
10885 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10886 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
10889 VerifyTruncatedFlag(&cache, request.CacheKey(), true, 30); in TEST_F()
10894 MockHttpCache cache; in TEST_F() local
10897 // Content-length will be intentionally bogus. in TEST_F()
10899 "Last-Modified: something\n" in TEST_F()
10901 "Accept-Ranges: bytes\n" in TEST_F()
10902 "Content-Length: 10\n"); in TEST_F()
10903 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
10907 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, in TEST_F()
10911 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
10912 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
10913 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
10919 MockHttpCache cache; in TEST_F() local
10933 TestTransactionConsumer c1(DEFAULT_PRIORITY, cache.http_cache()), in TEST_F()
10934 c2(DEFAULT_PRIORITY, cache.http_cache()), in TEST_F()
10935 c3(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
10945 base::RunLoop().Run(); in TEST_F()
10957 MockHttpCache cache; in TEST_F() local
10962 // write to the cache in TEST_F()
10963 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); in TEST_F()
10965 // force this transaction to validate the cache in TEST_F()
10968 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
10970 // read from the cache in TEST_F()
10971 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); in TEST_F()
10975 MockHttpCache cache; in TEST_F() local
10984 // Write to the cache. in TEST_F()
10987 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
10989 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
10994 const HttpResponseInfo* info = trans->GetResponseInfo(); in TEST_F()
10997 EXPECT_EQ(info->headers->response_code(), 301); in TEST_F()
11000 info->headers->EnumerateHeader(nullptr, "Location", &location); in TEST_F()
11004 trans->DoneReading(); in TEST_F()
11007 // read the response body -- want to test that it is still getting cached. in TEST_F()
11009 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11010 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11011 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11013 // Active entries in the cache are not retired synchronously. Make in TEST_F()
11016 base::RunLoop().RunUntilIdle(); in TEST_F()
11018 // Read from the cache. in TEST_F()
11021 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
11023 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
11028 const HttpResponseInfo* info = trans->GetResponseInfo(); in TEST_F()
11031 EXPECT_EQ(info->headers->response_code(), 301); in TEST_F()
11034 info->headers->EnumerateHeader(nullptr, "Location", &location); in TEST_F()
11038 trans->DoneReading(); in TEST_F()
11041 // read the response body -- want to test that it is still getting cached. in TEST_F()
11043 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11044 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11045 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11048 // Verify that no-cache resources are stored in cache, but are not fetched from
11049 // cache during normal loads.
11052 MockHttpCache cache; in TEST_F() local
11053 cache.disk_cache()->set_support_in_memory_entry_data(use_memory_entry_data); in TEST_F()
11056 transaction.response_headers = "cache-control: no-cache\n"; in TEST_F()
11059 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11061 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11062 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11063 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11066 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11068 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
11070 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11071 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
11073 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11074 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11079 EXPECT_TRUE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
11080 entry->Close(); in TEST_F()
11084 // Verify that no-cache resources are stored in cache and fetched from cache
11087 MockHttpCache cache; in TEST_F() local
11090 transaction.response_headers = "cache-control: no-cache\n"; in TEST_F()
11093 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11095 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11096 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11097 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11101 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11103 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11104 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11105 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11109 EXPECT_TRUE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
11110 entry->Close(); in TEST_F()
11114 MockHttpCache cache; in TEST_F() local
11117 transaction.response_headers = "cache-control: no-store\n"; in TEST_F()
11120 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11122 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11123 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11124 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11127 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11129 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
11130 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11131 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
11135 EXPECT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
11140 // is cachable, but when it is validated, no-store is received causing the in TEST_F()
11142 MockHttpCache cache; in TEST_F() local
11147 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11149 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11150 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11151 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11155 transaction.response_headers = "cache-control: no-store\n"; in TEST_F()
11156 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11158 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
11159 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11160 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11164 EXPECT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
11170 // a good thing to verify that we still destroy the cache entry. in TEST_F()
11171 MockHttpCache cache; in TEST_F() local
11176 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11178 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11179 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11180 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11184 transaction.response_headers = "cache-control: no-store\n"; in TEST_F()
11186 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11188 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
11189 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11190 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11194 EXPECT_FALSE(cache.OpenBackendEntry(request.CacheKey(), &entry)); in TEST_F()
11197 // Ensure that we don't cache requests served over bad HTTPS.
11199 MockHttpCache cache; in TEST_F() local
11205 // write to the cache in TEST_F()
11206 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11215 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
11217 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
11223 // Ensure that we don't crash by if left-behind transactions.
11225 auto cache = std::make_unique<MockHttpCache>(); in TEST_F() local
11228 EXPECT_THAT(cache->CreateTransaction(&trans), IsOk()); in TEST_F()
11230 cache.reset(); in TEST_F()
11236 MockHttpCache cache; in TEST_F() local
11238 // write to the cache in TEST_F()
11239 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
11242 cache.http_cache()->set_mode(HttpCache::DISABLE); in TEST_F()
11244 // force this transaction to write to the cache again in TEST_F()
11247 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11249 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
11250 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11251 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11260 MockHttpCache cache; in TEST_F() local
11270 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. in TEST_F()
11281 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
11287 RunTransactionTest(cache.http_cache(), request); in TEST_F()
11289 // Request |kUrl| again, this time validating the cache and getting in TEST_F()
11302 base::Time request_time = base::Time() + base::Hours(1234); in TEST_F()
11303 base::Time response_time = base::Time() + base::Hours(1235); in TEST_F()
11309 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); in TEST_F()
11319 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
11327 MockHttpCache cache; in TEST_P() local
11336 // result in a cache miss. in TEST_P()
11340 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11344 // The second request should result in a cache hit. in TEST_P()
11345 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11349 // Now request with b.com as the subframe origin. It should result in a cache in TEST_P()
11354 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11358 // The second request should result in a cache hit. in TEST_P()
11359 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11364 // still result in a cache hit. in TEST_P()
11368 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11373 // anything to be added to the cache when the NIK makes use of the frame site. in TEST_P()
11374 // Note that we will use `site_b` as the top-level site so that this resource in TEST_P()
11375 // won't be in the cache at first regardless of the NIK partitioning scheme. in TEST_P()
11396 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11400 // On the second request, expect a cache miss if the NIK uses the frame site. in TEST_P()
11401 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11430 RunTransactionTestWithRequest(cache.http_cache(), kSimplePOST_Transaction, in TEST_P()
11436 base::HistogramTester histograms; in TEST_F()
11437 MockHttpCache cache; in TEST_F() local
11446 transaction.response_headers = "Content-Type: text/css\n"; in TEST_F()
11450 // Requesting with the same top-frame site should not count as third-party in TEST_F()
11457 RunTransactionTestWithRequest(cache.http_cache(), transaction, trans_info, in TEST_F()
11464 // Requesting with a different top-frame site should count as third-party in TEST_F()
11471 RunTransactionTestWithRequest(cache.http_cache(), transaction, trans_info, in TEST_F()
11479 base::HistogramTester histograms; in TEST_F()
11480 MockHttpCache cache; in TEST_F() local
11489 transaction.response_headers = "Content-Type: application/javascript\n"; in TEST_F()
11493 // Requesting with the same top-frame site should not count as third-party in TEST_F()
11500 RunTransactionTestWithRequest(cache.http_cache(), transaction, trans_info, in TEST_F()
11507 // Requesting with a different top-frame site should count as third-party in TEST_F()
11514 RunTransactionTestWithRequest(cache.http_cache(), transaction, trans_info, in TEST_F()
11522 base::HistogramTester histograms; in TEST_F()
11523 MockHttpCache cache; in TEST_F() local
11532 transaction.response_headers = "Content-Type: font/otf\n"; in TEST_F()
11536 // Requesting with the same top-frame site should not count as third-party in TEST_F()
11543 RunTransactionTestWithRequest(cache.http_cache(), transaction, trans_info, in TEST_F()
11550 // Requesting with a different top-frame site should count as third-party in TEST_F()
11557 RunTransactionTestWithRequest(cache.http_cache(), transaction, trans_info, in TEST_F()
11565 MockHttpCache cache; in TEST_P() local
11573 // added to the cache. in TEST_P()
11577 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11581 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11586 // result in a cache miss since the cached resource has a different top frame in TEST_P()
11592 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11596 // The second request should result in a cache hit. in TEST_P()
11597 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11602 // it should not be a cache hit. in TEST_P()
11605 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11609 // Same request again should be a cache hit. in TEST_P()
11610 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11614 // Now request with b.com as the top frame origin. It should be a cache miss. in TEST_P()
11618 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11622 // The second request should be a cache hit. in TEST_P()
11623 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11627 // Another request for a.com should still result in a cache hit. in TEST_P()
11630 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11635 // a cache hit. in TEST_P()
11640 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11644 // On the second request, it still shouldn't result in a cache hit. in TEST_P()
11645 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11664 RunTransactionTestWithRequest(cache.http_cache(), kSimplePOST_Transaction, in TEST_P()
11674 MockHttpCache cache; in TEST_F() local
11684 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
11688 // Subsequent requests with the same NIK and different NIK will be a cache hit in TEST_F()
11690 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
11698 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
11705 base::test::ScopedFeatureList feature_list; in TEST_F()
11716 MockHttpCache cache; in TEST_P() local
11727 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11732 // should be a cache hit. in TEST_P()
11737 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11741 // Request with a different registrable domain. It should be a cache miss. in TEST_P()
11747 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_P()
11753 base::test::ScopedFeatureList feature_list; in TEST_F()
11757 MockHttpCache cache; in TEST_F() local
11760 // A request without a top frame is added to the cache normally. in TEST_F()
11764 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
11768 // The second request should result in a cache hit. in TEST_F()
11769 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
11779 RunTransactionTestWithRequest(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
11785 MockHttpCache cache; in TEST_F() local
11787 // Write a simple vary transaction to the cache. in TEST_F()
11790 transaction.request_headers = "accept-encoding: gzip\r\n"; in TEST_F()
11792 "Vary: accept-encoding\n" in TEST_F()
11793 "Cache-Control: max-age=10000\n"; in TEST_F()
11794 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11799 transaction.request_headers = "accept-encoding: foo\r\n"; in TEST_F()
11801 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11806 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11810 MockHttpCache cache; in TEST_F() local
11812 // Write a simple vary:* transaction to the cache. in TEST_F()
11815 transaction.request_headers = "accept-encoding: gzip\r\n"; in TEST_F()
11818 "Cache-Control: max-age=10000\n"; in TEST_F()
11819 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11825 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11830 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11836 MockHttpCache cache; in TEST_F() local
11837 base::SimpleTestClock clock; in TEST_F()
11838 cache.http_cache()->SetClockForTesting(&clock); in TEST_F()
11839 cache.network_layer()->SetClock(&clock); in TEST_F()
11843 transaction.response_headers = "Cache-Control: max-age=100\n"; in TEST_F()
11844 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11847 clock.Advance(base::Seconds(101)); in TEST_F()
11849 // Skipping cache validation should still return a response. in TEST_F()
11851 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11853 // If the cache entry is checked for validitiy, it should fail. in TEST_F()
11856 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11860 MockHttpCache cache; in TEST_F() local
11862 // Put the resource in the cache. in TEST_F()
11863 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
11866 // cache and network access. in TEST_F()
11868 // DevTools relies on this combination of flags for "disable cache" mode in TEST_F()
11869 // when a resource is only supposed to be loaded from cache. in TEST_F()
11872 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11878 MockHttpCache cache; in TEST_F() local
11884 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
11886 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
11889 auto buf = base::MakeRefCounted<IOBufferWithSize>(256); in TEST_F()
11890 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
11894 trans->DoneReading(); in TEST_F()
11898 base::RunLoop().RunUntilIdle(); in TEST_F()
11900 // Read from the cache. in TEST_F()
11901 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
11903 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11904 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11905 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11908 // Tests that we don't mark entries as truncated and release the cache
11912 MockHttpCache cache; in TEST_F() local
11920 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
11922 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
11925 trans->DoneReading(); in TEST_F()
11929 base::RunLoop().RunUntilIdle(); in TEST_F()
11931 // Read from the cache. This should not deadlock. in TEST_F()
11932 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
11934 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
11935 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
11936 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
11941 MockHttpCache cache; in TEST_F() local
11947 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
11949 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
11952 auto buf = base::MakeRefCounted<IOBufferWithSize>(256); in TEST_F()
11953 rv = trans->Read(buf.get(), 10, callback.callback()); in TEST_F()
11956 trans->StopCaching(); in TEST_F()
11959 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
11961 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
11966 base::RunLoop().RunUntilIdle(); in TEST_F()
11969 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
11971 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
11972 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
11973 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
11979 MockHttpCache cache; in TEST_F() local
11985 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
11987 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
11990 auto buf = base::MakeRefCounted<IOBufferWithSize>(256); in TEST_F()
11991 rv = trans->Read(buf.get(), 10, callback.callback()); in TEST_F()
11994 trans->StopCaching(); in TEST_F()
11997 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
11999 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
12003 trans->DoneReading(); in TEST_F()
12007 base::RunLoop().RunUntilIdle(); in TEST_F()
12010 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
12012 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12013 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
12014 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
12019 MockHttpCache cache; in TEST_F() local
12028 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
12030 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
12033 trans->StopCaching(); in TEST_F()
12038 base::RunLoop().RunUntilIdle(); in TEST_F()
12041 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
12043 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12044 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
12045 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
12050 MockHttpCache cache; in TEST_F() local
12056 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
12061 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" in TEST_F()
12062 "Content-Length: 42\n" in TEST_F()
12065 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
12068 auto buf = base::MakeRefCounted<IOBufferWithSize>(256); in TEST_F()
12069 rv = trans->Read(buf.get(), 10, callback.callback()); in TEST_F()
12072 trans->StopCaching(); in TEST_F()
12075 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
12077 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
12082 // VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, true, 0); in TEST_F()
12084 cache.disk_cache()->IsDiskEntryDoomed(request.CacheKey()); in TEST_F()
12089 MockHttpCache cache; in TEST_F() local
12097 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12099 "Accept-Ranges: bytes\n" in TEST_F()
12100 "Content-Length: 80\n"); in TEST_F()
12101 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
12106 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); in TEST_F()
12108 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
12111 auto buf = base::MakeRefCounted<IOBufferWithSize>(256); in TEST_F()
12112 rv = trans->Read(buf.get(), 10, callback.callback()); in TEST_F()
12116 trans->StopCaching(); in TEST_F()
12119 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
12121 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
12123 rv = trans->Read(buf.get(), 256, callback.callback()); in TEST_F()
12128 VerifyTruncatedFlag(&cache, request.CacheKey(), false, 80); in TEST_F()
12151 // CacheInitializer callbacks. These are used to initialize the cache
12154 // Initializes a cache containing a truncated entry containing the first 20
12156 static void SetupTruncatedCacheEntry(MockHttpCache* cache);
12158 // Initializes a cache containing a sparse entry. The first 10 bytes are
12159 // present in the cache.
12160 static void SetupPrefixSparseCacheEntry(MockHttpCache* cache);
12162 // Initializes a cache containing a sparse entry. The 10 bytes at offset
12163 // 99990 are present in the cache.
12164 static void SetupInfixSparseCacheEntry(MockHttpCache* cache);
12192 if (!request->extra_headers.GetHeader(net::HttpRequestHeaders::kIfRange, in LargeResourceTransactionHandler()
12197 *response_headers = base::StringPrintf("Content-Length: %" PRId64 in LargeResourceTransactionHandler()
12200 "Accept-Ranges: bytes\n", in LargeResourceTransactionHandler()
12205 // From this point on, we should be processing a valid byte-range request. in LargeResourceTransactionHandler()
12209 EXPECT_TRUE(request->extra_headers.GetHeader(net::HttpRequestHeaders::kRange, in LargeResourceTransactionHandler()
12219 range.HasLastBytePosition() ? range.last_byte_position() : kTotalSize - 1; in LargeResourceTransactionHandler()
12222 *response_headers = base::StringPrintf( in LargeResourceTransactionHandler()
12223 "Content-Range: bytes %" PRId64 "-%" PRId64 "/%" PRId64 in LargeResourceTransactionHandler()
12225 "Content-Length: %" PRId64 "\n", in LargeResourceTransactionHandler()
12227 last_byte_position - range.first_byte_position() + 1); in LargeResourceTransactionHandler()
12241 int num = std::min(static_cast<int64_t>(buf_len), content_length - offset); in LargeBufferReader()
12252 void HttpCacheHugeResourceTest::SetupTruncatedCacheEntry(MockHttpCache* cache) { in SetupTruncatedCacheEntry() argument
12254 std::string cached_headers = base::StringPrintf( in SetupTruncatedCacheEntry()
12256 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in SetupTruncatedCacheEntry()
12258 "Accept-Ranges: bytes\n" in SetupTruncatedCacheEntry()
12259 "Content-Length: %" PRId64 "\n", in SetupTruncatedCacheEntry()
12261 CreateTruncatedEntry(cached_headers, cache); in SetupTruncatedCacheEntry()
12266 MockHttpCache* cache) { in SetupPrefixSparseCacheEntry() argument
12269 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in SetupPrefixSparseCacheEntry()
12271 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in SetupPrefixSparseCacheEntry()
12273 "Accept-Ranges: bytes\n" in SetupPrefixSparseCacheEntry()
12274 "Content-Range: bytes 0-9/5000000000\n" in SetupPrefixSparseCacheEntry()
12275 "Content-Length: 10\n"; in SetupPrefixSparseCacheEntry()
12278 RunTransactionTestWithResponse(cache->http_cache(), transaction, &headers); in SetupPrefixSparseCacheEntry()
12284 MockHttpCache* cache) { in SetupInfixSparseCacheEntry() argument
12287 transaction.request_headers = "Range: bytes = 99990-99999\r\n" EXTRA_HEADER; in SetupInfixSparseCacheEntry()
12289 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in SetupInfixSparseCacheEntry()
12291 "Accept-Ranges: bytes\n" in SetupInfixSparseCacheEntry()
12292 "Content-Range: bytes 99990-99999/5000000000\n" in SetupInfixSparseCacheEntry()
12293 "Content-Length: 10\n"; in SetupInfixSparseCacheEntry()
12296 RunTransactionTestWithResponse(cache->http_cache(), transaction, &headers); in SetupInfixSparseCacheEntry()
12330 // fetched via GET. Various combinations of cache state and when StopCaching()
12340 MockHttpCache cache; in TEST_P() local
12341 (*cache_initializer)(&cache); in TEST_P()
12345 transaction.handler = base::BindRepeating(&LargeResourceTransactionHandler); in TEST_P()
12346 transaction.read_handler = base::BindRepeating(&LargeBufferReader); in TEST_P()
12352 int rv = cache.http_cache()->CreateTransaction(net::DEFAULT_PRIORITY, in TEST_P()
12359 http_transaction->SetBeforeNetworkStartCallback(base::BindOnce( in TEST_P()
12363 rv = http_transaction->Start(&request, callback.callback(), in TEST_P()
12369 http_transaction->StopCaching(); in TEST_P()
12374 http_transaction->GetResponseInfo()->headers->GetContentLength()); in TEST_P()
12380 base::MakeRefCounted<net::IOBufferWithSize>(kBufferSize); in TEST_P()
12381 rv = http_transaction->Read(buf.get(), kBufferSize, callback.callback()); in TEST_P()
12386 http_transaction->StopCaching(); in TEST_P()
12394 http_transaction->StopCaching(); in TEST_P()
12406 // a Content-Length header.
12408 MockHttpCache cache; in TEST_F() local
12413 transaction.response_headers = "Cache-Control: max-age=10000\n" in TEST_F()
12414 "Content-Length: 100\n"; in TEST_F()
12415 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
12418 // Read from the cache. in TEST_F()
12419 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
12421 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12422 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
12423 EXPECT_EQ(2, cache.disk_cache()->create_count()); in TEST_F()
12429 MockHttpCache cache; in TEST_F() local
12434 transaction.response_headers = "Cache-Control: max-age=10000\n" in TEST_F()
12435 "Content-Length: 100\n" in TEST_F()
12437 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
12442 VerifyTruncatedFlag(&cache, request.CacheKey(), true, 0); in TEST_F()
12445 // Make sure that calling SetPriority on a cache transaction passes on
12448 MockHttpCache cache; in TEST_F() local
12452 ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk()); in TEST_F()
12455 trans->SetPriority(LOW); in TEST_F()
12457 EXPECT_FALSE(cache.network_layer()->last_transaction()); in TEST_F()
12459 cache.network_layer()->last_create_transaction_priority()); in TEST_F()
12464 trans->Start(&info, callback.callback(), NetLogWithSource())); in TEST_F()
12466 EXPECT_TRUE(cache.network_layer()->last_transaction()); in TEST_F()
12467 if (cache.network_layer()->last_transaction()) { in TEST_F()
12468 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority()); in TEST_F()
12469 EXPECT_EQ(LOW, cache.network_layer()->last_transaction()->priority()); in TEST_F()
12472 trans->SetPriority(HIGHEST); in TEST_F()
12474 if (cache.network_layer()->last_transaction()) { in TEST_F()
12475 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority()); in TEST_F()
12476 EXPECT_EQ(HIGHEST, cache.network_layer()->last_transaction()->priority()); in TEST_F()
12482 // Make sure that calling SetWebSocketHandshakeStreamCreateHelper on a cache
12485 MockHttpCache cache; in TEST_F() local
12490 ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk()); in TEST_F()
12492 EXPECT_FALSE(cache.network_layer()->last_transaction()); in TEST_F()
12497 trans->Start(&info, callback.callback(), NetLogWithSource())); in TEST_F()
12499 ASSERT_TRUE(cache.network_layer()->last_transaction()); in TEST_F()
12500 EXPECT_FALSE(cache.network_layer()->last_transaction()-> in TEST_F()
12502 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper); in TEST_F()
12504 cache.network_layer()->last_transaction()-> in TEST_F()
12509 // Make sure that a cache transaction passes on its priority to
12510 // newly-created network transactions.
12512 MockHttpCache cache; in TEST_F() local
12516 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12518 "Accept-Ranges: bytes\n" in TEST_F()
12519 "Content-Length: 80\n"); in TEST_F()
12520 CreateTruncatedEntry(raw_headers, &cache); in TEST_F()
12529 ASSERT_THAT(cache.http_cache()->CreateTransaction(MEDIUM, &trans), IsOk()); in TEST_F()
12531 cache.network_layer()->last_create_transaction_priority()); in TEST_F()
12536 trans->Start(&info, callback.callback(), NetLogWithSource())); in TEST_F()
12539 EXPECT_EQ(MEDIUM, cache.network_layer()->last_create_transaction_priority()); in TEST_F()
12541 trans->SetPriority(HIGHEST); in TEST_F()
12546 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority()); in TEST_F()
12553 void RunTransactionAndGetNetworkBytes(MockHttpCache* cache, in RunTransactionAndGetNetworkBytes() argument
12558 cache->http_cache(), trans_info, MockHttpRequest(trans_info), nullptr, in RunTransactionAndGetNetworkBytes()
12565 MockHttpCache cache; in TEST_F() local
12569 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12573 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12579 MockHttpCache cache; in TEST_F() local
12583 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12589 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12595 MockHttpCache cache; in TEST_F() local
12601 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
12603 "Cache-Control: max-age=0\n" in TEST_F()
12607 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12615 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12623 MockHttpCache cache; in TEST_F() local
12627 // Read bytes 40-49 from the network. in TEST_F()
12629 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12633 // Read bytes 40-49 from the cache. in TEST_F()
12634 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12637 base::RunLoop().RunUntilIdle(); in TEST_F()
12639 // Read bytes 30-39 from the network. in TEST_F()
12640 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; in TEST_F()
12641 transaction.data = "rg: 30-39 "; in TEST_F()
12642 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12645 base::RunLoop().RunUntilIdle(); in TEST_F()
12647 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. in TEST_F()
12648 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; in TEST_F()
12649 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; in TEST_F()
12650 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received); in TEST_F()
12666 cache_.http_cache()->SetClockForTesting(&clock_); in HttpCachePrefetchValidationTest()
12667 cache_.network_layer()->SetClock(&clock_); in HttpCachePrefetchValidationTest()
12669 transaction_.response_headers = "Cache-Control: max-age=100\n"; in HttpCachePrefetchValidationTest()
12679 void AdvanceTime(int seconds) { clock_.Advance(base::Seconds(seconds)); } in AdvanceTime()
12685 // the cache.
12687 return cache_.network_layer()->transaction_count(); in transaction_count()
12693 base::SimpleTestClock clock_;
12766 MockHttpCache cache; in TEST_F() local
12772 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12774 "Cache-Control: max-age=0,stale-while-revalidate=86400\n"; in TEST_F()
12776 // Write to the cache. in TEST_F()
12777 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); in TEST_F()
12779 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12784 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12786 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12791 MockHttpCache cache; in TEST_F() local
12792 base::SimpleTestClock clock; in TEST_F()
12793 cache.http_cache()->SetClockForTesting(&clock); in TEST_F()
12794 cache.network_layer()->SetClock(&clock); in TEST_F()
12795 clock.Advance(base::Seconds(10)); in TEST_F()
12802 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12804 "Cache-Control: max-age=0,stale-while-revalidate=86400\n"; in TEST_F()
12806 // Write to the cache. in TEST_F()
12807 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); in TEST_F()
12809 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12814 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12816 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12822 clock.Advance(base::Seconds(1)); in TEST_F()
12825 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12827 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12832 MockHttpCache cache; in TEST_F() local
12833 base::SimpleTestClock clock; in TEST_F()
12834 cache.http_cache()->SetClockForTesting(&clock); in TEST_F()
12835 cache.network_layer()->SetClock(&clock); in TEST_F()
12836 clock.Advance(base::Seconds(10)); in TEST_F()
12843 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12845 "Cache-Control: max-age=0,stale-while-revalidate=86400\n"; in TEST_F()
12847 // Write to the cache. in TEST_F()
12848 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); in TEST_F()
12850 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12855 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12857 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12860 base::Time revalidation_timeout = response_info.stale_revalidate_timeout; in TEST_F()
12861 clock.Advance(base::Seconds(1)); in TEST_F()
12866 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12868 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12878 // Write 304 to the cache. in TEST_F()
12880 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12882 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12888 MockHttpCache cache; in TEST_F() local
12895 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12897 "Cache-Control: max-age=0,stale-while-revalidate=1800\n"; in TEST_F()
12899 // Write to the cache. in TEST_F()
12900 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); in TEST_F()
12902 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12907 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12909 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12914 MockHttpCache cache; in TEST_F() local
12915 base::SimpleTestClock clock; in TEST_F()
12916 cache.http_cache()->SetClockForTesting(&clock); in TEST_F()
12917 cache.network_layer()->SetClock(&clock); in TEST_F()
12918 clock.Advance(base::Seconds(10)); in TEST_F()
12925 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" in TEST_F()
12927 "Cache-Control: max-age=0,stale-while-revalidate=86400\n"; in TEST_F()
12929 // Write to the cache. in TEST_F()
12930 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); in TEST_F()
12932 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12936 cache.disk_cache()->set_soft_failures_mask(MockDiskEntry::FAIL_WRITE); in TEST_F()
12939 cache.http_cache(), stale_while_revalidate_transaction, &response_info); in TEST_F()
12941 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
12944 // Tests that we allow multiple simultaneous, non-overlapping transactions to
12947 MockHttpCache cache; in TEST_F() local
12949 // Create a transaction for bytes 0-9. in TEST_F()
12952 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; in TEST_F()
12953 transaction.data = "rg: 00-09 "; in TEST_F()
12958 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
12963 trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
12966 // kRangeGET_TransactionOK requests 40-49) should not be blocked by in TEST_F()
12968 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); in TEST_F()
12982 MockHttpCache cache; in TEST_F() local
12989 RunTransactionTest(cache.http_cache(), transaction); in TEST_F()
12990 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
12991 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
12992 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
13004 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); in TEST_F()
13008 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); in TEST_F()
13014 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
13015 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
13016 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
13019 // Makes sure that a request stops using the cache when the response headers
13020 // with "Cache-Control: no-store" arrives. That means that another request for
13024 MockHttpCache cache; in TEST_F() local
13026 mock_transaction.response_headers = "Cache-Control: no-store\n"; in TEST_F()
13030 first->result = cache.CreateTransaction(&first->trans); in TEST_F()
13031 ASSERT_THAT(first->result, IsOk()); in TEST_F()
13032 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); in TEST_F()
13033 first->result = first->trans->Start(&request, first->callback.callback(), in TEST_F()
13035 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState()); in TEST_F()
13037 base::RunLoop().RunUntilIdle(); in TEST_F()
13038 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); in TEST_F()
13039 ASSERT_TRUE(first->trans->GetResponseInfo()); in TEST_F()
13040 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue( in TEST_F()
13041 "Cache-Control", "no-store")); in TEST_F()
13046 second->result = cache.CreateTransaction(&second->trans); in TEST_F()
13047 ASSERT_THAT(second->result, IsOk()); in TEST_F()
13048 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); in TEST_F()
13049 second->result = second->trans->Start(&request, second->callback.callback(), in TEST_F()
13053 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); in TEST_F()
13054 base::RunLoop().RunUntilIdle(); in TEST_F()
13055 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); in TEST_F()
13056 ASSERT_TRUE(second->trans->GetResponseInfo()); in TEST_F()
13057 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( in TEST_F()
13058 "Cache-Control", "no-store")); in TEST_F()
13059 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); in TEST_F()
13062 // Tests that serving a response entirely from cache replays the previous
13074 MockHttpCache cache; in TEST_F() local
13082 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13085 // The request should have hit the network and a cache entry created. in TEST_F()
13086 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
13087 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
13088 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
13093 EXPECT_TRUE(cert->EqualsIncludingChain(response_info.ssl_info.cert.get())); in TEST_F()
13096 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13100 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
13101 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
13102 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
13106 EXPECT_TRUE(cert->EqualsIncludingChain(response_info.ssl_info.cert.get())); in TEST_F()
13127 MockHttpCache cache; in TEST_F() local
13135 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13138 // The request should have hit the network and a cache entry created. in TEST_F()
13139 EXPECT_EQ(1, cache.network_layer()->transaction_count()); in TEST_F()
13140 EXPECT_EQ(0, cache.disk_cache()->open_count()); in TEST_F()
13141 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
13146 EXPECT_TRUE(cert1->EqualsIncludingChain(response_info.ssl_info.cert.get())); in TEST_F()
13155 transaction.request_headers = "Cache-Control: max-age=0\r\n"; in TEST_F()
13156 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13160 EXPECT_EQ(2, cache.network_layer()->transaction_count()); in TEST_F()
13161 EXPECT_EQ(1, cache.disk_cache()->open_count()); in TEST_F()
13162 EXPECT_EQ(1, cache.disk_cache()->create_count()); in TEST_F()
13167 EXPECT_TRUE(cert2->EqualsIncludingChain(response_info.ssl_info.cert.get())); in TEST_F()
13171 MockHttpCache cache; in TEST_F() local
13174 RunTransactionTestWithResponseInfo(cache.http_cache(), kRangeGET_Transaction, in TEST_F()
13183 MockHttpCache cache; in TEST_F() local
13186 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
13196 MockHttpCache cache; in TEST_F() local
13197 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); in TEST_F()
13200 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, in TEST_F()
13209 MockHttpCache cache; in TEST_F() local
13210 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); in TEST_F()
13217 RunTransactionTestWithResponseInfo(cache.http_cache(), still_valid, in TEST_F()
13227 MockHttpCache cache; in TEST_F() local
13228 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); in TEST_F()
13234 RunTransactionTestWithResponseInfo(cache.http_cache(), update, in TEST_F()
13243 MockHttpCache cache; in TEST_F() local
13244 cache.FailConditionalizations(); in TEST_F()
13245 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); in TEST_F()
13248 RunTransactionTestWithResponseInfo(cache.http_cache(), in TEST_F()
13258 base::test::ScopedFeatureList feature_list; in TEST_F()
13261 MockHttpCache cache; in TEST_F() local
13304 return base::BindRepeating(&TestCompletionCallbackForHttpCache::SetResult, in callback()
13305 base::Unretained(this)); in callback()
13321 MockHttpCache cache; in TEST_F() local
13324 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13326 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13327 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13331 cache.backend(); in TEST_F()
13339 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13342 int rv = DoomEntry(cache.http_cache(), m_transaction.url, transaction.get()); in TEST_F()
13344 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13345 rv = OpenEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13361 MockHttpCache cache; in TEST_F() local
13364 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13366 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13367 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13371 cache.backend(); in TEST_F()
13379 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13382 int rv = DoomEntry(cache.http_cache(), m_transaction.url, transaction.get()); in TEST_F()
13384 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13385 rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13401 MockHttpCache cache; in TEST_F() local
13404 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13406 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13407 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13411 cache.backend(); in TEST_F()
13417 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13420 int rv = DoomEntry(cache.http_cache(), m_transaction.url, transaction.get()); in TEST_F()
13422 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13423 rv = DoomEntry(cache.http_cache(), m_transaction.url, transaction.get()); in TEST_F()
13437 MockHttpCache cache; in TEST_F() local
13440 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13442 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13443 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13447 cache.backend(); in TEST_F()
13456 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13459 int rv = OpenEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13462 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13463 rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13480 MockHttpCache cache; in TEST_F() local
13483 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13485 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13486 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13490 cache.backend(); in TEST_F()
13499 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13502 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13505 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13506 rv = OpenEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13523 MockHttpCache cache; in TEST_F() local
13526 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13528 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13529 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13533 cache.backend(); in TEST_F()
13542 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13545 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13548 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13549 rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13565 MockHttpCache cache; in TEST_F() local
13568 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13570 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13571 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13575 cache.backend(); in TEST_F()
13585 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13588 rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13605 MockHttpCache cache; in TEST_F() local
13608 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13610 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13611 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13615 cache.backend(); in TEST_F()
13626 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13629 rv = DoomEntry(cache.http_cache(), m_transaction.url, transaction.get()); in TEST_F()
13643 MockHttpCache cache; in TEST_F() local
13646 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13648 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13649 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13653 cache.backend(); in TEST_F()
13663 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13666 rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13680 ASSERT_EQ(entry1->disk_entry, entry2->disk_entry); in TEST_F()
13684 MockHttpCache cache; in TEST_F() local
13687 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13689 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13690 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13694 cache.backend(); in TEST_F()
13703 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13706 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13709 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13710 rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13727 MockHttpCache cache; in TEST_F() local
13730 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13732 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13733 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13737 cache.backend(); in TEST_F()
13748 int rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry0, in TEST_F()
13757 DeactivateEntry(cache.http_cache(), entry0); in TEST_F()
13760 rv = OpenEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13763 rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13777 ASSERT_EQ(entry1->disk_entry, entry2->disk_entry); in TEST_F()
13781 MockHttpCache cache; in TEST_F() local
13784 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13786 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13787 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13791 cache.backend(); in TEST_F()
13800 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13803 int rv = OpenEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13806 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13807 rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13824 MockHttpCache cache; in TEST_F() local
13827 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13829 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13830 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13834 cache.backend(); in TEST_F()
13844 int rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13847 rv = CreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13864 MockHttpCache cache; in TEST_F() local
13867 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13869 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13870 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13874 cache.backend(); in TEST_F()
13884 int rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13887 rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13904 MockHttpCache cache; in TEST_F() local
13907 std::make_unique<Transaction>(DEFAULT_PRIORITY, cache.http_cache()); in TEST_F()
13909 transaction->SetIOCallBackForTest(cb.callback()); in TEST_F()
13910 transaction->SetCacheIOCallBackForTest(cb.callback()); in TEST_F()
13914 cache.backend(); in TEST_F()
13923 cache.disk_cache()->set_force_fail_callback_later(true); in TEST_F()
13926 int rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry1, in TEST_F()
13929 cache.disk_cache()->set_force_fail_callback_later(false); in TEST_F()
13930 rv = OpenOrCreateEntry(cache.http_cache(), m_transaction.url, &entry2, in TEST_F()
13947 MockHttpCache cache; in TEST_F() local
13952 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13957 // The second request result in a cache hit and the response used without in TEST_F()
13961 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13968 MockHttpCache cache; in TEST_F() local
13973 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13978 // The second request should result in a cache hit and the response used in TEST_F()
13982 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
13989 MockHttpCache cache; in TEST_F() local
13994 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" in TEST_F()
13995 "Cache-Control: max-age=0\n"; in TEST_F()
13998 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14003 // On the second request, the cache should be revalidated. Change the aliases in TEST_F()
14006 transaction.response_headers = "Cache-Control: max-age=10000\n"; in TEST_F()
14008 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14014 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14021 MockHttpCache cache; in TEST_F() local
14025 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14030 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14036 MockHttpCache cache; in TEST_F() local
14041 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14048 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14054 MockHttpCache cache; in TEST_F() local
14059 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14066 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14072 MockHttpCache cache; in TEST_F() local
14076 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14080 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14086 MockHttpCache cache; in TEST_F() local
14094 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n" in TEST_F()
14095 "Cross-Origin-Resource-Policy: cross-origin\n", in TEST_F()
14102 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", in TEST_F()
14106 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14109 // On the second request, the cache is revalidated. in TEST_F()
14111 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; in TEST_F()
14114 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, in TEST_F()
14119 response.headers->GetNormalizedHeader("Cross-Origin-Resource-Policy", in TEST_F()
14122 EXPECT_EQ(304, response.headers->response_code()); in TEST_F()
14123 EXPECT_EQ("cross-origin", response_corp_header); in TEST_F()