OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 | 1692 |
1693 EXPECT_EQ(5, cache.network_layer()->transaction_count()); | 1693 EXPECT_EQ(5, cache.network_layer()->transaction_count()); |
1694 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1694 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1695 EXPECT_EQ(5, cache.disk_cache()->create_count()); | 1695 EXPECT_EQ(5, cache.disk_cache()->create_count()); |
1696 | 1696 |
1697 for (int i = 0; i < kNumTransactions; ++i) { | 1697 for (int i = 0; i < kNumTransactions; ++i) { |
1698 delete context_list[i]; | 1698 delete context_list[i]; |
1699 } | 1699 } |
1700 } | 1700 } |
1701 | 1701 |
| 1702 // Tests that a (simulated) timeout allows transactions waiting on the cache |
| 1703 // lock to continue. |
| 1704 TEST(HttpCache, SimpleGET_WriterTimeout) { |
| 1705 MockHttpCache cache; |
| 1706 cache.BypassCacheLock(); |
| 1707 |
| 1708 MockHttpRequest request(kSimpleGET_Transaction); |
| 1709 Context c1, c2; |
| 1710 ASSERT_EQ(net::OK, cache.CreateTransaction(&c1.trans)); |
| 1711 ASSERT_EQ(net::ERR_IO_PENDING, |
| 1712 c1.trans->Start(&request, c1.callback.callback(), |
| 1713 net::BoundNetLog())); |
| 1714 ASSERT_EQ(net::OK, cache.CreateTransaction(&c2.trans)); |
| 1715 ASSERT_EQ(net::ERR_IO_PENDING, |
| 1716 c2.trans->Start(&request, c2.callback.callback(), |
| 1717 net::BoundNetLog())); |
| 1718 |
| 1719 // The second request is queued after the first one. |
| 1720 |
| 1721 c2.callback.WaitForResult(); |
| 1722 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction); |
| 1723 |
| 1724 // Complete the first transaction. |
| 1725 c1.callback.WaitForResult(); |
| 1726 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); |
| 1727 } |
| 1728 |
1702 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { | 1729 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { |
1703 MockHttpCache cache; | 1730 MockHttpCache cache; |
1704 | 1731 |
1705 // write to the cache | 1732 // write to the cache |
1706 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1733 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1707 | 1734 |
1708 MockHttpRequest request(kSimpleGET_Transaction); | 1735 MockHttpRequest request(kSimpleGET_Transaction); |
1709 net::TestCompletionCallback callback; | 1736 net::TestCompletionCallback callback; |
1710 | 1737 |
1711 scoped_ptr<net::HttpTransaction> trans; | 1738 scoped_ptr<net::HttpTransaction> trans; |
(...skipping 4697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6409 base::MessageLoop::current()->RunUntilIdle(); | 6436 base::MessageLoop::current()->RunUntilIdle(); |
6410 | 6437 |
6411 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. | 6438 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. |
6412 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 6439 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
6413 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 6440 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
6414 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); | 6441 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); |
6415 EXPECT_EQ(range_response_size * 2, received_bytes); | 6442 EXPECT_EQ(range_response_size * 2, received_bytes); |
6416 | 6443 |
6417 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6444 RemoveMockTransaction(&kRangeGET_TransactionOK); |
6418 } | 6445 } |
OLD | NEW |