Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1762 // The second request is queued after the first one. | 1762 // The second request is queued after the first one. |
| 1763 | 1763 |
| 1764 c2.callback.WaitForResult(); | 1764 c2.callback.WaitForResult(); |
| 1765 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction); | 1765 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction); |
| 1766 | 1766 |
| 1767 // Complete the first transaction. | 1767 // Complete the first transaction. |
| 1768 c1.callback.WaitForResult(); | 1768 c1.callback.WaitForResult(); |
| 1769 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); | 1769 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); |
| 1770 } | 1770 } |
| 1771 | 1771 |
| 1772 // Tests that a (simulated) timeout allows transactions waiting on the cache | |
| 1773 // lock to continue but read only transactions to error out. | |
| 1774 TEST(HttpCache, SimpleGET_WriterTimeoutReadOnlyError) { | |
| 1775 MockHttpCache cache; | |
| 1776 | |
| 1777 // Simulate timeout. | |
| 1778 cache.BypassCacheLock(); | |
|
asanka
2017/02/07 22:56:03
This method is poorly named :-(
shivanisha
2017/02/08 19:14:13
Updated to SimulateCacheLockTimeout for clarity an
| |
| 1779 | |
| 1780 MockHttpRequest request(kSimpleGET_Transaction); | |
| 1781 Context c1, c2; | |
| 1782 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk()); | |
| 1783 ASSERT_EQ(ERR_IO_PENDING, c1.trans->Start(&request, c1.callback.callback(), | |
| 1784 NetLogWithSource())); | |
| 1785 | |
| 1786 // Using load flags similar to MetadataWriter. | |
|
asanka
2017/02/07 22:56:03
There are two things to test:
1) That HttpCache::
shivanisha
2017/02/08 19:14:13
Done.
The new test added for WriteMetadata_* grou
| |
| 1787 request.load_flags = | |
| 1788 LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION | LOAD_SKIP_VARY_CHECK; | |
| 1789 ASSERT_THAT(cache.CreateTransaction(&c2.trans), IsOk()); | |
| 1790 ASSERT_EQ(ERR_IO_PENDING, c2.trans->Start(&request, c2.callback.callback(), | |
| 1791 NetLogWithSource())); | |
| 1792 | |
| 1793 // The second request is queued after the first one. | |
| 1794 int res = c2.callback.WaitForResult(); | |
| 1795 ASSERT_EQ(ERR_CACHE_MISS, res); | |
| 1796 | |
| 1797 // Complete the first transaction. | |
| 1798 c1.callback.WaitForResult(); | |
| 1799 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); | |
| 1800 } | |
| 1801 | |
| 1772 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { | 1802 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { |
| 1773 MockHttpCache cache; | 1803 MockHttpCache cache; |
| 1774 | 1804 |
| 1775 // write to the cache | 1805 // write to the cache |
| 1776 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1806 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 1777 | 1807 |
| 1778 MockHttpRequest request(kSimpleGET_Transaction); | 1808 MockHttpRequest request(kSimpleGET_Transaction); |
| 1779 TestCompletionCallback callback; | 1809 TestCompletionCallback callback; |
| 1780 | 1810 |
| 1781 std::unique_ptr<HttpTransaction> trans; | 1811 std::unique_ptr<HttpTransaction> trans; |
| (...skipping 6472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8254 RunTransactionTestWithResponseInfo(cache.http_cache(), | 8284 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 8255 kTypicalGET_Transaction, &response_info); | 8285 kTypicalGET_Transaction, &response_info); |
| 8256 | 8286 |
| 8257 EXPECT_FALSE(response_info.was_cached); | 8287 EXPECT_FALSE(response_info.was_cached); |
| 8258 EXPECT_TRUE(response_info.network_accessed); | 8288 EXPECT_TRUE(response_info.network_accessed); |
| 8259 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | 8289 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
| 8260 response_info.cache_entry_status); | 8290 response_info.cache_entry_status); |
| 8261 } | 8291 } |
| 8262 | 8292 |
| 8263 } // namespace net | 8293 } // namespace net |
| OLD | NEW |