| 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 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1281 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 // All requests are waiting for the active entry. | 1284 // All requests are waiting for the active entry. |
| 1285 for (int i = 0; i < kNumTransactions; ++i) { | 1285 for (int i = 0; i < kNumTransactions; ++i) { |
| 1286 Context* c = context_list[i]; | 1286 Context* c = context_list[i]; |
| 1287 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); | 1287 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 // Allow all requests to move from the Create queue to the active entry. | 1290 // Allow all requests to move from the Create queue to the active entry. |
| 1291 base::MessageLoop::current()->RunUntilIdle(); | 1291 base::RunLoop().RunUntilIdle(); |
| 1292 | 1292 |
| 1293 // The first request should be a writer at this point, and the subsequent | 1293 // The first request should be a writer at this point, and the subsequent |
| 1294 // requests should be pending. | 1294 // requests should be pending. |
| 1295 | 1295 |
| 1296 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1296 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1297 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1297 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1298 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1298 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1299 | 1299 |
| 1300 // All requests depend on the writer, and the writer is between Start and | 1300 // All requests depend on the writer, and the writer is between Start and |
| 1301 // Read, i.e. idle. | 1301 // Read, i.e. idle. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 | 1346 |
| 1347 MockHttpRequest* this_request = &request; | 1347 MockHttpRequest* this_request = &request; |
| 1348 if (i == 1 || i == 2) | 1348 if (i == 1 || i == 2) |
| 1349 this_request = &reader_request; | 1349 this_request = &reader_request; |
| 1350 | 1350 |
| 1351 c->result = | 1351 c->result = |
| 1352 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); | 1352 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); |
| 1353 } | 1353 } |
| 1354 | 1354 |
| 1355 // Allow all requests to move from the Create queue to the active entry. | 1355 // Allow all requests to move from the Create queue to the active entry. |
| 1356 base::MessageLoop::current()->RunUntilIdle(); | 1356 base::RunLoop().RunUntilIdle(); |
| 1357 | 1357 |
| 1358 // The first request should be a writer at this point, and the subsequent | 1358 // The first request should be a writer at this point, and the subsequent |
| 1359 // requests should be pending. | 1359 // requests should be pending. |
| 1360 | 1360 |
| 1361 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1361 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1362 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1362 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1363 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1363 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1364 | 1364 |
| 1365 Context* c = context_list[0]; | 1365 Context* c = context_list[0]; |
| 1366 ASSERT_EQ(ERR_IO_PENDING, c->result); | 1366 ASSERT_EQ(ERR_IO_PENDING, c->result); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 Context* c = context_list[i]; | 1473 Context* c = context_list[i]; |
| 1474 | 1474 |
| 1475 c->result = cache.CreateTransaction(&c->trans); | 1475 c->result = cache.CreateTransaction(&c->trans); |
| 1476 ASSERT_EQ(OK, c->result); | 1476 ASSERT_EQ(OK, c->result); |
| 1477 | 1477 |
| 1478 c->result = | 1478 c->result = |
| 1479 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1479 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 1480 } | 1480 } |
| 1481 | 1481 |
| 1482 // Allow all requests to move from the Create queue to the active entry. | 1482 // Allow all requests to move from the Create queue to the active entry. |
| 1483 base::MessageLoop::current()->RunUntilIdle(); | 1483 base::RunLoop().RunUntilIdle(); |
| 1484 | 1484 |
| 1485 // The first request should be a writer at this point, and the subsequent | 1485 // The first request should be a writer at this point, and the subsequent |
| 1486 // requests should be pending. | 1486 // requests should be pending. |
| 1487 | 1487 |
| 1488 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1488 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1489 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1489 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1490 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1490 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1491 | 1491 |
| 1492 // Now, make sure that the second request asks for the entry not to be stored. | 1492 // Now, make sure that the second request asks for the entry not to be stored. |
| 1493 request_handler.set_no_store(true); | 1493 request_handler.set_no_store(true); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1520 Context* c = context_list[i]; | 1520 Context* c = context_list[i]; |
| 1521 | 1521 |
| 1522 c->result = cache.CreateTransaction(&c->trans); | 1522 c->result = cache.CreateTransaction(&c->trans); |
| 1523 ASSERT_EQ(OK, c->result); | 1523 ASSERT_EQ(OK, c->result); |
| 1524 | 1524 |
| 1525 c->result = | 1525 c->result = |
| 1526 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1526 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 1527 } | 1527 } |
| 1528 | 1528 |
| 1529 // Allow all requests to move from the Create queue to the active entry. | 1529 // Allow all requests to move from the Create queue to the active entry. |
| 1530 base::MessageLoop::current()->RunUntilIdle(); | 1530 base::RunLoop().RunUntilIdle(); |
| 1531 | 1531 |
| 1532 // The first request should be a writer at this point, and the subsequent | 1532 // The first request should be a writer at this point, and the subsequent |
| 1533 // requests should be pending. | 1533 // requests should be pending. |
| 1534 | 1534 |
| 1535 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1535 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1536 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1536 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1537 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1537 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1538 | 1538 |
| 1539 for (int i = 0; i < kNumTransactions; ++i) { | 1539 for (int i = 0; i < kNumTransactions; ++i) { |
| 1540 Context* c = context_list[i]; | 1540 Context* c = context_list[i]; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 ASSERT_EQ(OK, c->result); | 1634 ASSERT_EQ(OK, c->result); |
| 1635 | 1635 |
| 1636 c->result = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1636 c->result = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 1637 EXPECT_EQ(ERR_IO_PENDING, c->result); | 1637 EXPECT_EQ(ERR_IO_PENDING, c->result); |
| 1638 | 1638 |
| 1639 // Release the reference that the mock disk cache keeps for this entry, so | 1639 // Release the reference that the mock disk cache keeps for this entry, so |
| 1640 // that we test that the http cache handles the cancellation correctly. | 1640 // that we test that the http cache handles the cancellation correctly. |
| 1641 cache.disk_cache()->ReleaseAll(); | 1641 cache.disk_cache()->ReleaseAll(); |
| 1642 delete c; | 1642 delete c; |
| 1643 | 1643 |
| 1644 base::MessageLoop::current()->RunUntilIdle(); | 1644 base::RunLoop().RunUntilIdle(); |
| 1645 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1645 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1646 } | 1646 } |
| 1647 | 1647 |
| 1648 // Tests that we delete/create entries even if multiple requests are queued. | 1648 // Tests that we delete/create entries even if multiple requests are queued. |
| 1649 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { | 1649 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { |
| 1650 MockHttpCache cache; | 1650 MockHttpCache cache; |
| 1651 | 1651 |
| 1652 MockHttpRequest request(kSimpleGET_Transaction); | 1652 MockHttpRequest request(kSimpleGET_Transaction); |
| 1653 request.load_flags = LOAD_BYPASS_CACHE; | 1653 request.load_flags = LOAD_BYPASS_CACHE; |
| 1654 | 1654 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 1735 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 1736 rv = trans->Read(buf.get(), 256, callback.callback()); | 1736 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 1737 EXPECT_EQ(ERR_IO_PENDING, rv); | 1737 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1738 | 1738 |
| 1739 // Test that destroying the transaction while it is reading from the cache | 1739 // Test that destroying the transaction while it is reading from the cache |
| 1740 // works properly. | 1740 // works properly. |
| 1741 trans.reset(); | 1741 trans.reset(); |
| 1742 | 1742 |
| 1743 // Make sure we pump any pending events, which should include a call to | 1743 // Make sure we pump any pending events, which should include a call to |
| 1744 // HttpCache::Transaction::OnCacheReadCompleted. | 1744 // HttpCache::Transaction::OnCacheReadCompleted. |
| 1745 base::MessageLoop::current()->RunUntilIdle(); | 1745 base::RunLoop().RunUntilIdle(); |
| 1746 } | 1746 } |
| 1747 | 1747 |
| 1748 // Tests that we can delete the HttpCache and deal with queued transactions | 1748 // Tests that we can delete the HttpCache and deal with queued transactions |
| 1749 // ("waiting for the backend" as opposed to Active or Doomed entries). | 1749 // ("waiting for the backend" as opposed to Active or Doomed entries). |
| 1750 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) { | 1750 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) { |
| 1751 std::unique_ptr<MockHttpCache> cache( | 1751 std::unique_ptr<MockHttpCache> cache( |
| 1752 new MockHttpCache(base::WrapUnique(new MockBackendNoCbFactory()))); | 1752 new MockHttpCache(base::WrapUnique(new MockBackendNoCbFactory()))); |
| 1753 | 1753 |
| 1754 MockHttpRequest request(kSimpleGET_Transaction); | 1754 MockHttpRequest request(kSimpleGET_Transaction); |
| 1755 | 1755 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 } | 1804 } |
| 1805 | 1805 |
| 1806 context_list[0]->result = context_list[0]->trans->Start( | 1806 context_list[0]->result = context_list[0]->trans->Start( |
| 1807 &request0, context_list[0]->callback.callback(), BoundNetLog()); | 1807 &request0, context_list[0]->callback.callback(), BoundNetLog()); |
| 1808 context_list[1]->result = context_list[1]->trans->Start( | 1808 context_list[1]->result = context_list[1]->trans->Start( |
| 1809 &request1, context_list[1]->callback.callback(), BoundNetLog()); | 1809 &request1, context_list[1]->callback.callback(), BoundNetLog()); |
| 1810 context_list[2]->result = context_list[2]->trans->Start( | 1810 context_list[2]->result = context_list[2]->trans->Start( |
| 1811 &request2, context_list[2]->callback.callback(), BoundNetLog()); | 1811 &request2, context_list[2]->callback.callback(), BoundNetLog()); |
| 1812 | 1812 |
| 1813 // Just to make sure that everything is still pending. | 1813 // Just to make sure that everything is still pending. |
| 1814 base::MessageLoop::current()->RunUntilIdle(); | 1814 base::RunLoop().RunUntilIdle(); |
| 1815 | 1815 |
| 1816 // The first request should be creating the disk cache. | 1816 // The first request should be creating the disk cache. |
| 1817 EXPECT_FALSE(context_list[0]->callback.have_result()); | 1817 EXPECT_FALSE(context_list[0]->callback.have_result()); |
| 1818 | 1818 |
| 1819 factory->FinishCreation(); | 1819 factory->FinishCreation(); |
| 1820 | 1820 |
| 1821 base::MessageLoop::current()->RunUntilIdle(); | 1821 base::RunLoop().RunUntilIdle(); |
| 1822 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 1822 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 1823 EXPECT_EQ(3, cache.disk_cache()->create_count()); | 1823 EXPECT_EQ(3, cache.disk_cache()->create_count()); |
| 1824 | 1824 |
| 1825 for (int i = 0; i < kNumTransactions; ++i) { | 1825 for (int i = 0; i < kNumTransactions; ++i) { |
| 1826 EXPECT_TRUE(context_list[i]->callback.have_result()); | 1826 EXPECT_TRUE(context_list[i]->callback.have_result()); |
| 1827 delete context_list[i]; | 1827 delete context_list[i]; |
| 1828 } | 1828 } |
| 1829 } | 1829 } |
| 1830 | 1830 |
| 1831 // Tests that we can cancel requests that are queued waiting for the backend | 1831 // Tests that we can cancel requests that are queued waiting for the backend |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1850 } | 1850 } |
| 1851 | 1851 |
| 1852 context_list[0]->result = context_list[0]->trans->Start( | 1852 context_list[0]->result = context_list[0]->trans->Start( |
| 1853 &request0, context_list[0]->callback.callback(), BoundNetLog()); | 1853 &request0, context_list[0]->callback.callback(), BoundNetLog()); |
| 1854 context_list[1]->result = context_list[1]->trans->Start( | 1854 context_list[1]->result = context_list[1]->trans->Start( |
| 1855 &request1, context_list[1]->callback.callback(), BoundNetLog()); | 1855 &request1, context_list[1]->callback.callback(), BoundNetLog()); |
| 1856 context_list[2]->result = context_list[2]->trans->Start( | 1856 context_list[2]->result = context_list[2]->trans->Start( |
| 1857 &request2, context_list[2]->callback.callback(), BoundNetLog()); | 1857 &request2, context_list[2]->callback.callback(), BoundNetLog()); |
| 1858 | 1858 |
| 1859 // Just to make sure that everything is still pending. | 1859 // Just to make sure that everything is still pending. |
| 1860 base::MessageLoop::current()->RunUntilIdle(); | 1860 base::RunLoop().RunUntilIdle(); |
| 1861 | 1861 |
| 1862 // The first request should be creating the disk cache. | 1862 // The first request should be creating the disk cache. |
| 1863 EXPECT_FALSE(context_list[0]->callback.have_result()); | 1863 EXPECT_FALSE(context_list[0]->callback.have_result()); |
| 1864 | 1864 |
| 1865 // Cancel a request from the pending queue. | 1865 // Cancel a request from the pending queue. |
| 1866 delete context_list[1]; | 1866 delete context_list[1]; |
| 1867 context_list[1] = NULL; | 1867 context_list[1] = NULL; |
| 1868 | 1868 |
| 1869 // Cancel the request that is creating the entry. | 1869 // Cancel the request that is creating the entry. |
| 1870 delete context_list[0]; | 1870 delete context_list[0]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1891 | 1891 |
| 1892 MockHttpRequest request(kSimpleGET_Transaction); | 1892 MockHttpRequest request(kSimpleGET_Transaction); |
| 1893 | 1893 |
| 1894 std::unique_ptr<Context> c(new Context()); | 1894 std::unique_ptr<Context> c(new Context()); |
| 1895 c->result = cache->CreateTransaction(&c->trans); | 1895 c->result = cache->CreateTransaction(&c->trans); |
| 1896 ASSERT_EQ(OK, c->result); | 1896 ASSERT_EQ(OK, c->result); |
| 1897 | 1897 |
| 1898 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1898 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 1899 | 1899 |
| 1900 // Just to make sure that everything is still pending. | 1900 // Just to make sure that everything is still pending. |
| 1901 base::MessageLoop::current()->RunUntilIdle(); | 1901 base::RunLoop().RunUntilIdle(); |
| 1902 | 1902 |
| 1903 // The request should be creating the disk cache. | 1903 // The request should be creating the disk cache. |
| 1904 EXPECT_FALSE(c->callback.have_result()); | 1904 EXPECT_FALSE(c->callback.have_result()); |
| 1905 | 1905 |
| 1906 // We cannot call FinishCreation because the factory itself will go away with | 1906 // We cannot call FinishCreation because the factory itself will go away with |
| 1907 // the cache, so grab the callback and attempt to use it. | 1907 // the cache, so grab the callback and attempt to use it. |
| 1908 CompletionCallback callback = factory->callback(); | 1908 CompletionCallback callback = factory->callback(); |
| 1909 std::unique_ptr<disk_cache::Backend>* backend = factory->backend(); | 1909 std::unique_ptr<disk_cache::Backend>* backend = factory->backend(); |
| 1910 | 1910 |
| 1911 cache.reset(); | 1911 cache.reset(); |
| 1912 base::MessageLoop::current()->RunUntilIdle(); | 1912 base::RunLoop().RunUntilIdle(); |
| 1913 | 1913 |
| 1914 backend->reset(); | 1914 backend->reset(); |
| 1915 callback.Run(ERR_ABORTED); | 1915 callback.Run(ERR_ABORTED); |
| 1916 } | 1916 } |
| 1917 | 1917 |
| 1918 // Tests that we can delete the cache while creating the backend, from within | 1918 // Tests that we can delete the cache while creating the backend, from within |
| 1919 // one of the callbacks. | 1919 // one of the callbacks. |
| 1920 TEST(HttpCache, DeleteCacheWaitingForBackend2) { | 1920 TEST(HttpCache, DeleteCacheWaitingForBackend2) { |
| 1921 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 1921 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
| 1922 MockHttpCache* cache = new MockHttpCache(base::WrapUnique(factory)); | 1922 MockHttpCache* cache = new MockHttpCache(base::WrapUnique(factory)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1934 ASSERT_EQ(OK, c->result); | 1934 ASSERT_EQ(OK, c->result); |
| 1935 | 1935 |
| 1936 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1936 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 1937 | 1937 |
| 1938 // And another direct backend request. | 1938 // And another direct backend request. |
| 1939 TestCompletionCallback cb2; | 1939 TestCompletionCallback cb2; |
| 1940 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); | 1940 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); |
| 1941 EXPECT_EQ(ERR_IO_PENDING, rv); | 1941 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1942 | 1942 |
| 1943 // Just to make sure that everything is still pending. | 1943 // Just to make sure that everything is still pending. |
| 1944 base::MessageLoop::current()->RunUntilIdle(); | 1944 base::RunLoop().RunUntilIdle(); |
| 1945 | 1945 |
| 1946 // The request should be queued. | 1946 // The request should be queued. |
| 1947 EXPECT_FALSE(c->callback.have_result()); | 1947 EXPECT_FALSE(c->callback.have_result()); |
| 1948 | 1948 |
| 1949 // Generate the callback. | 1949 // Generate the callback. |
| 1950 factory->FinishCreation(); | 1950 factory->FinishCreation(); |
| 1951 rv = cb.WaitForResult(); | 1951 rv = cb.WaitForResult(); |
| 1952 | 1952 |
| 1953 // The cache should be gone by now. | 1953 // The cache should be gone by now. |
| 1954 base::MessageLoop::current()->RunUntilIdle(); | 1954 base::RunLoop().RunUntilIdle(); |
| 1955 EXPECT_EQ(OK, c->callback.GetResult(c->result)); | 1955 EXPECT_EQ(OK, c->callback.GetResult(c->result)); |
| 1956 EXPECT_FALSE(cb2.have_result()); | 1956 EXPECT_FALSE(cb2.have_result()); |
| 1957 } | 1957 } |
| 1958 | 1958 |
| 1959 // Fails only on bots. crbug.com/533640 | 1959 // Fails only on bots. crbug.com/533640 |
| 1960 #if defined(OS_ANDROID) | 1960 #if defined(OS_ANDROID) |
| 1961 #define MAYBE_TypicalGET_ConditionalRequest \ | 1961 #define MAYBE_TypicalGET_ConditionalRequest \ |
| 1962 DISABLED_TypicalGET_ConditionalRequest | 1962 DISABLED_TypicalGET_ConditionalRequest |
| 1963 #else | 1963 #else |
| 1964 #define MAYBE_TypicalGET_ConditionalRequest TypicalGET_ConditionalRequest | 1964 #define MAYBE_TypicalGET_ConditionalRequest TypicalGET_ConditionalRequest |
| (...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3348 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3348 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3349 RemoveMockTransaction(&transaction); | 3349 RemoveMockTransaction(&transaction); |
| 3350 | 3350 |
| 3351 EXPECT_NE(std::string::npos, headers.find("HTTP/1.1 200 OK\n")); | 3351 EXPECT_NE(std::string::npos, headers.find("HTTP/1.1 200 OK\n")); |
| 3352 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3352 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3353 | 3353 |
| 3354 MockTransaction transaction2(kTypicalGET_Transaction); | 3354 MockTransaction transaction2(kTypicalGET_Transaction); |
| 3355 AddMockTransaction(&transaction2); | 3355 AddMockTransaction(&transaction2); |
| 3356 | 3356 |
| 3357 // Make sure we are done with the previous transaction. | 3357 // Make sure we are done with the previous transaction. |
| 3358 base::MessageLoop::current()->RunUntilIdle(); | 3358 base::RunLoop().RunUntilIdle(); |
| 3359 | 3359 |
| 3360 // Load from the cache. | 3360 // Load from the cache. |
| 3361 transaction2.load_flags |= LOAD_ONLY_FROM_CACHE; | 3361 transaction2.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 3362 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 3362 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 3363 | 3363 |
| 3364 EXPECT_NE(std::string::npos, headers.find("Foo: bar\n")); | 3364 EXPECT_NE(std::string::npos, headers.find("Foo: bar\n")); |
| 3365 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3365 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3366 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3366 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 3367 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3367 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3368 RemoveMockTransaction(&transaction2); | 3368 RemoveMockTransaction(&transaction2); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3388 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3388 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3389 RemoveMockTransaction(&transaction); | 3389 RemoveMockTransaction(&transaction); |
| 3390 | 3390 |
| 3391 EXPECT_NE(std::string::npos, headers.find("HTTP/1.1 304 Not Modified\n")); | 3391 EXPECT_NE(std::string::npos, headers.find("HTTP/1.1 304 Not Modified\n")); |
| 3392 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3392 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3393 | 3393 |
| 3394 MockTransaction transaction2(kTypicalGET_Transaction); | 3394 MockTransaction transaction2(kTypicalGET_Transaction); |
| 3395 AddMockTransaction(&transaction2); | 3395 AddMockTransaction(&transaction2); |
| 3396 | 3396 |
| 3397 // Make sure we are done with the previous transaction. | 3397 // Make sure we are done with the previous transaction. |
| 3398 base::MessageLoop::current()->RunUntilIdle(); | 3398 base::RunLoop().RunUntilIdle(); |
| 3399 | 3399 |
| 3400 // Load from the cache. | 3400 // Load from the cache. |
| 3401 transaction2.load_flags |= LOAD_ONLY_FROM_CACHE; | 3401 transaction2.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 3402 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 3402 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 3403 | 3403 |
| 3404 EXPECT_NE(std::string::npos, headers.find("Foo: bar\n")); | 3404 EXPECT_NE(std::string::npos, headers.find("Foo: bar\n")); |
| 3405 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3405 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3406 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3406 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 3407 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3407 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3408 RemoveMockTransaction(&transaction2); | 3408 RemoveMockTransaction(&transaction2); |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4082 // Read from the cache (40-49). | 4082 // Read from the cache (40-49). |
| 4083 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 4083 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 4084 &headers); | 4084 &headers); |
| 4085 | 4085 |
| 4086 Verify206Response(headers, 40, 49); | 4086 Verify206Response(headers, 40, 49); |
| 4087 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4087 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4088 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4088 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4089 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4089 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4090 | 4090 |
| 4091 // Make sure we are done with the previous transaction. | 4091 // Make sure we are done with the previous transaction. |
| 4092 base::MessageLoop::current()->RunUntilIdle(); | 4092 base::RunLoop().RunUntilIdle(); |
| 4093 | 4093 |
| 4094 // Write to the cache (30-39). | 4094 // Write to the cache (30-39). |
| 4095 MockTransaction transaction(kRangeGET_TransactionOK); | 4095 MockTransaction transaction(kRangeGET_TransactionOK); |
| 4096 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; | 4096 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; |
| 4097 transaction.data = "rg: 30-39 "; | 4097 transaction.data = "rg: 30-39 "; |
| 4098 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4098 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4099 | 4099 |
| 4100 Verify206Response(headers, 30, 39); | 4100 Verify206Response(headers, 30, 39); |
| 4101 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4101 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4102 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 4102 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 4103 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4103 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4104 | 4104 |
| 4105 // Make sure we are done with the previous transaction. | 4105 // Make sure we are done with the previous transaction. |
| 4106 base::MessageLoop::current()->RunUntilIdle(); | 4106 base::RunLoop().RunUntilIdle(); |
| 4107 | 4107 |
| 4108 // Write and read from the cache (20-59). | 4108 // Write and read from the cache (20-59). |
| 4109 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 4109 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
| 4110 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 4110 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
| 4111 BoundTestNetLog log; | 4111 BoundTestNetLog log; |
| 4112 LoadTimingInfo load_timing_info; | 4112 LoadTimingInfo load_timing_info; |
| 4113 RunTransactionTestWithResponseAndGetTiming( | 4113 RunTransactionTestWithResponseAndGetTiming( |
| 4114 cache.http_cache(), transaction, &headers, log.bound(), | 4114 cache.http_cache(), transaction, &headers, log.bound(), |
| 4115 &load_timing_info); | 4115 &load_timing_info); |
| 4116 | 4116 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4149 | 4149 |
| 4150 // Read from the cache (40-49). | 4150 // Read from the cache (40-49). |
| 4151 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4151 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4152 | 4152 |
| 4153 Verify206Response(headers, 40, 49); | 4153 Verify206Response(headers, 40, 49); |
| 4154 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4154 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4155 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4155 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4156 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4156 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4157 | 4157 |
| 4158 // Make sure we are done with the previous transaction. | 4158 // Make sure we are done with the previous transaction. |
| 4159 base::MessageLoop::current()->RunUntilIdle(); | 4159 base::RunLoop().RunUntilIdle(); |
| 4160 | 4160 |
| 4161 // Write to the cache (30-39). | 4161 // Write to the cache (30-39). |
| 4162 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; | 4162 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; |
| 4163 transaction.data = "rg: 30-39 "; | 4163 transaction.data = "rg: 30-39 "; |
| 4164 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4164 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4165 | 4165 |
| 4166 Verify206Response(headers, 30, 39); | 4166 Verify206Response(headers, 30, 39); |
| 4167 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4167 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4168 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4168 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4169 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4169 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4170 | 4170 |
| 4171 // Make sure we are done with the previous transaction. | 4171 // Make sure we are done with the previous transaction. |
| 4172 base::MessageLoop::current()->RunUntilIdle(); | 4172 base::RunLoop().RunUntilIdle(); |
| 4173 | 4173 |
| 4174 // Write and read from the cache (20-59). | 4174 // Write and read from the cache (20-59). |
| 4175 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 4175 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
| 4176 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 4176 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
| 4177 BoundTestNetLog log; | 4177 BoundTestNetLog log; |
| 4178 LoadTimingInfo load_timing_info; | 4178 LoadTimingInfo load_timing_info; |
| 4179 RunTransactionTestWithResponseAndGetTiming( | 4179 RunTransactionTestWithResponseAndGetTiming( |
| 4180 cache.http_cache(), transaction, &headers, log.bound(), | 4180 cache.http_cache(), transaction, &headers, log.bound(), |
| 4181 &load_timing_info); | 4181 &load_timing_info); |
| 4182 | 4182 |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4649 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; | 4649 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; |
| 4650 transaction.data = "rg: 70-79 "; | 4650 transaction.data = "rg: 70-79 "; |
| 4651 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4651 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4652 | 4652 |
| 4653 Verify206Response(headers, 70, 79); | 4653 Verify206Response(headers, 70, 79); |
| 4654 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4654 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4655 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4655 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4656 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4656 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4657 | 4657 |
| 4658 // Make sure we are done with the previous transaction. | 4658 // Make sure we are done with the previous transaction. |
| 4659 base::MessageLoop::current()->RunUntilIdle(); | 4659 base::RunLoop().RunUntilIdle(); |
| 4660 | 4660 |
| 4661 // Write and read from the cache (60-79). | 4661 // Write and read from the cache (60-79). |
| 4662 transaction.request_headers = "Range: bytes = 60-\r\n" EXTRA_HEADER; | 4662 transaction.request_headers = "Range: bytes = 60-\r\n" EXTRA_HEADER; |
| 4663 transaction.data = "rg: 60-69 rg: 70-79 "; | 4663 transaction.data = "rg: 60-69 rg: 70-79 "; |
| 4664 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4664 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4665 | 4665 |
| 4666 Verify206Response(headers, 60, 79); | 4666 Verify206Response(headers, 60, 79); |
| 4667 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4667 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4668 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4668 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4669 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4669 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4688 transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER; | 4688 transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER; |
| 4689 transaction.data = "rg: 70-79 "; | 4689 transaction.data = "rg: 70-79 "; |
| 4690 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4690 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4691 | 4691 |
| 4692 Verify206Response(headers, 70, 79); | 4692 Verify206Response(headers, 70, 79); |
| 4693 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4693 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4694 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4694 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4695 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4695 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4696 | 4696 |
| 4697 // Make sure we are done with the previous transaction. | 4697 // Make sure we are done with the previous transaction. |
| 4698 base::MessageLoop::current()->RunUntilIdle(); | 4698 base::RunLoop().RunUntilIdle(); |
| 4699 | 4699 |
| 4700 // Write and read from the cache (60-79). | 4700 // Write and read from the cache (60-79). |
| 4701 transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER; | 4701 transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER; |
| 4702 transaction.data = "rg: 60-69 rg: 70-79 "; | 4702 transaction.data = "rg: 60-69 rg: 70-79 "; |
| 4703 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4703 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4704 | 4704 |
| 4705 Verify206Response(headers, 60, 79); | 4705 Verify206Response(headers, 60, 79); |
| 4706 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4706 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4707 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4707 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4708 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4708 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5034 handler.set_not_modified(true); | 5034 handler.set_not_modified(true); |
| 5035 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 5035 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 5036 | 5036 |
| 5037 // We are expecting a 206. | 5037 // We are expecting a 206. |
| 5038 Verify206Response(headers, 40, 49); | 5038 Verify206Response(headers, 40, 49); |
| 5039 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5039 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 5040 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5040 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5041 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5041 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5042 | 5042 |
| 5043 // The last transaction has finished so make sure the entry is deactivated. | 5043 // The last transaction has finished so make sure the entry is deactivated. |
| 5044 base::MessageLoop::current()->RunUntilIdle(); | 5044 base::RunLoop().RunUntilIdle(); |
| 5045 | 5045 |
| 5046 // Make a request for an invalid range. | 5046 // Make a request for an invalid range. |
| 5047 MockTransaction transaction3(kRangeGET_TransactionOK); | 5047 MockTransaction transaction3(kRangeGET_TransactionOK); |
| 5048 transaction3.request_headers = "Range: bytes = 80-90\r\n" EXTRA_HEADER; | 5048 transaction3.request_headers = "Range: bytes = 80-90\r\n" EXTRA_HEADER; |
| 5049 transaction3.data = transaction.data; | 5049 transaction3.data = transaction.data; |
| 5050 transaction3.load_flags = LOAD_PREFERRING_CACHE; | 5050 transaction3.load_flags = LOAD_PREFERRING_CACHE; |
| 5051 RunTransactionTestWithResponse(cache.http_cache(), transaction3, &headers); | 5051 RunTransactionTestWithResponse(cache.http_cache(), transaction3, &headers); |
| 5052 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 5052 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 5053 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 ")); | 5053 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 ")); |
| 5054 EXPECT_EQ(std::string::npos, headers.find("Content-Range:")); | 5054 EXPECT_EQ(std::string::npos, headers.find("Content-Range:")); |
| 5055 EXPECT_EQ(std::string::npos, headers.find("Content-Length: 80")); | 5055 EXPECT_EQ(std::string::npos, headers.find("Content-Length: 80")); |
| 5056 | 5056 |
| 5057 // Make sure the entry is deactivated. | 5057 // Make sure the entry is deactivated. |
| 5058 base::MessageLoop::current()->RunUntilIdle(); | 5058 base::RunLoop().RunUntilIdle(); |
| 5059 | 5059 |
| 5060 // Even though the request was invalid, we should have the entry. | 5060 // Even though the request was invalid, we should have the entry. |
| 5061 RunTransactionTest(cache.http_cache(), transaction2); | 5061 RunTransactionTest(cache.http_cache(), transaction2); |
| 5062 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 5062 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
| 5063 | 5063 |
| 5064 // Make sure the entry is deactivated. | 5064 // Make sure the entry is deactivated. |
| 5065 base::MessageLoop::current()->RunUntilIdle(); | 5065 base::RunLoop().RunUntilIdle(); |
| 5066 | 5066 |
| 5067 // Now we should receive a range from the server and drop the stored entry. | 5067 // Now we should receive a range from the server and drop the stored entry. |
| 5068 handler.set_not_modified(false); | 5068 handler.set_not_modified(false); |
| 5069 transaction2.request_headers = kRangeGET_TransactionOK.request_headers; | 5069 transaction2.request_headers = kRangeGET_TransactionOK.request_headers; |
| 5070 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 5070 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 5071 Verify206Response(headers, 40, 49); | 5071 Verify206Response(headers, 40, 49); |
| 5072 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 5072 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
| 5073 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 5073 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
| 5074 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5074 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5075 | 5075 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5283 // active entry (no open or create). | 5283 // active entry (no open or create). |
| 5284 | 5284 |
| 5285 c = new Context(); | 5285 c = new Context(); |
| 5286 rv = cache.CreateTransaction(&c->trans); | 5286 rv = cache.CreateTransaction(&c->trans); |
| 5287 ASSERT_EQ(OK, rv); | 5287 ASSERT_EQ(OK, rv); |
| 5288 | 5288 |
| 5289 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5289 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); |
| 5290 EXPECT_EQ(ERR_IO_PENDING, rv); | 5290 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5291 | 5291 |
| 5292 MockDiskEntry::IgnoreCallbacks(true); | 5292 MockDiskEntry::IgnoreCallbacks(true); |
| 5293 base::MessageLoop::current()->RunUntilIdle(); | 5293 base::RunLoop().RunUntilIdle(); |
| 5294 MockDiskEntry::IgnoreCallbacks(false); | 5294 MockDiskEntry::IgnoreCallbacks(false); |
| 5295 | 5295 |
| 5296 // The new transaction is waiting for the query range callback. | 5296 // The new transaction is waiting for the query range callback. |
| 5297 delete c; | 5297 delete c; |
| 5298 | 5298 |
| 5299 // And we should not crash when the callback is delivered. | 5299 // And we should not crash when the callback is delivered. |
| 5300 base::MessageLoop::current()->RunUntilIdle(); | 5300 base::RunLoop().RunUntilIdle(); |
| 5301 | 5301 |
| 5302 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5302 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 5303 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5303 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5304 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5304 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5305 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5305 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5306 } | 5306 } |
| 5307 | 5307 |
| 5308 // Tests that an invalid range response results in no cached entry. | 5308 // Tests that an invalid range response results in no cached entry. |
| 5309 TEST(HttpCache, RangeGET_InvalidResponse1) { | 5309 TEST(HttpCache, RangeGET_InvalidResponse1) { |
| 5310 MockHttpCache cache; | 5310 MockHttpCache cache; |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6002 EXPECT_EQ(5, c->callback.GetResult(rv)); | 6002 EXPECT_EQ(5, c->callback.GetResult(rv)); |
| 6003 | 6003 |
| 6004 // Cancel the requests. | 6004 // Cancel the requests. |
| 6005 delete c; | 6005 delete c; |
| 6006 delete pending; | 6006 delete pending; |
| 6007 | 6007 |
| 6008 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6008 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6009 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 6009 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 6010 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 6010 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 6011 | 6011 |
| 6012 base::MessageLoop::current()->RunUntilIdle(); | 6012 base::RunLoop().RunUntilIdle(); |
| 6013 RemoveMockTransaction(&transaction); | 6013 RemoveMockTransaction(&transaction); |
| 6014 } | 6014 } |
| 6015 | 6015 |
| 6016 // Tests that we delete truncated entries if the server changes its mind midway. | 6016 // Tests that we delete truncated entries if the server changes its mind midway. |
| 6017 TEST(HttpCache, GET_IncompleteResource2) { | 6017 TEST(HttpCache, GET_IncompleteResource2) { |
| 6018 MockHttpCache cache; | 6018 MockHttpCache cache; |
| 6019 AddMockTransaction(&kRangeGET_TransactionOK); | 6019 AddMockTransaction(&kRangeGET_TransactionOK); |
| 6020 | 6020 |
| 6021 // Content-length will be intentionally bad. | 6021 // Content-length will be intentionally bad. |
| 6022 std::string raw_headers("HTTP/1.1 200 OK\n" | 6022 std::string raw_headers("HTTP/1.1 200 OK\n" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6358 // Destroy transaction when going out of scope. We have not actually | 6358 // Destroy transaction when going out of scope. We have not actually |
| 6359 // read the response body -- want to test that it is still getting cached. | 6359 // read the response body -- want to test that it is still getting cached. |
| 6360 } | 6360 } |
| 6361 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6361 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6362 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 6362 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 6363 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6363 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6364 | 6364 |
| 6365 // Active entries in the cache are not retired synchronously. Make | 6365 // Active entries in the cache are not retired synchronously. Make |
| 6366 // sure the next run hits the MockHttpCache and open_count is | 6366 // sure the next run hits the MockHttpCache and open_count is |
| 6367 // correct. | 6367 // correct. |
| 6368 base::MessageLoop::current()->RunUntilIdle(); | 6368 base::RunLoop().RunUntilIdle(); |
| 6369 | 6369 |
| 6370 // Read from the cache. | 6370 // Read from the cache. |
| 6371 { | 6371 { |
| 6372 std::unique_ptr<HttpTransaction> trans; | 6372 std::unique_ptr<HttpTransaction> trans; |
| 6373 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); | 6373 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); |
| 6374 | 6374 |
| 6375 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6375 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 6376 if (rv == ERR_IO_PENDING) | 6376 if (rv == ERR_IO_PENDING) |
| 6377 rv = callback.WaitForResult(); | 6377 rv = callback.WaitForResult(); |
| 6378 ASSERT_EQ(OK, rv); | 6378 ASSERT_EQ(OK, rv); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6683 memset(buf->data(), 0, buf->size()); | 6683 memset(buf->data(), 0, buf->size()); |
| 6684 base::strlcpy(buf->data(), "Hi there", buf->size()); | 6684 base::strlcpy(buf->data(), "Hi there", buf->size()); |
| 6685 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), | 6685 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
| 6686 DEFAULT_PRIORITY, response.response_time, | 6686 DEFAULT_PRIORITY, response.response_time, |
| 6687 buf.get(), buf->size()); | 6687 buf.get(), buf->size()); |
| 6688 | 6688 |
| 6689 // Release the buffer before the operation takes place. | 6689 // Release the buffer before the operation takes place. |
| 6690 buf = NULL; | 6690 buf = NULL; |
| 6691 | 6691 |
| 6692 // Makes sure we finish pending operations. | 6692 // Makes sure we finish pending operations. |
| 6693 base::MessageLoop::current()->RunUntilIdle(); | 6693 base::RunLoop().RunUntilIdle(); |
| 6694 | 6694 |
| 6695 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 6695 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
| 6696 &response); | 6696 &response); |
| 6697 ASSERT_TRUE(response.metadata.get() != NULL); | 6697 ASSERT_TRUE(response.metadata.get() != NULL); |
| 6698 EXPECT_EQ(50, response.metadata->size()); | 6698 EXPECT_EQ(50, response.metadata->size()); |
| 6699 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there")); | 6699 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there")); |
| 6700 | 6700 |
| 6701 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6701 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6702 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 6702 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 6703 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6703 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6717 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(50)); | 6717 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(50)); |
| 6718 memset(buf->data(), 0, buf->size()); | 6718 memset(buf->data(), 0, buf->size()); |
| 6719 base::strlcpy(buf->data(), "Hi there", buf->size()); | 6719 base::strlcpy(buf->data(), "Hi there", buf->size()); |
| 6720 base::Time expected_time = response.response_time - | 6720 base::Time expected_time = response.response_time - |
| 6721 base::TimeDelta::FromMilliseconds(20); | 6721 base::TimeDelta::FromMilliseconds(20); |
| 6722 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), | 6722 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
| 6723 DEFAULT_PRIORITY, expected_time, buf.get(), | 6723 DEFAULT_PRIORITY, expected_time, buf.get(), |
| 6724 buf->size()); | 6724 buf->size()); |
| 6725 | 6725 |
| 6726 // Makes sure we finish pending operations. | 6726 // Makes sure we finish pending operations. |
| 6727 base::MessageLoop::current()->RunUntilIdle(); | 6727 base::RunLoop().RunUntilIdle(); |
| 6728 | 6728 |
| 6729 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 6729 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
| 6730 &response); | 6730 &response); |
| 6731 EXPECT_TRUE(response.metadata.get() == NULL); | 6731 EXPECT_TRUE(response.metadata.get() == NULL); |
| 6732 | 6732 |
| 6733 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6733 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6734 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 6734 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 6735 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6735 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6736 } | 6736 } |
| 6737 | 6737 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6748 | 6748 |
| 6749 // Write meta data to the same entry. | 6749 // Write meta data to the same entry. |
| 6750 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(50)); | 6750 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(50)); |
| 6751 memset(buf->data(), 0, buf->size()); | 6751 memset(buf->data(), 0, buf->size()); |
| 6752 base::strlcpy(buf->data(), "Hi there", buf->size()); | 6752 base::strlcpy(buf->data(), "Hi there", buf->size()); |
| 6753 cache.http_cache()->WriteMetadata(GURL(kTypicalGET_Transaction.url), | 6753 cache.http_cache()->WriteMetadata(GURL(kTypicalGET_Transaction.url), |
| 6754 DEFAULT_PRIORITY, response.response_time, | 6754 DEFAULT_PRIORITY, response.response_time, |
| 6755 buf.get(), buf->size()); | 6755 buf.get(), buf->size()); |
| 6756 | 6756 |
| 6757 // Makes sure we finish pending operations. | 6757 // Makes sure we finish pending operations. |
| 6758 base::MessageLoop::current()->RunUntilIdle(); | 6758 base::RunLoop().RunUntilIdle(); |
| 6759 | 6759 |
| 6760 // Start with a READ mode transaction. | 6760 // Start with a READ mode transaction. |
| 6761 MockTransaction trans1(kTypicalGET_Transaction); | 6761 MockTransaction trans1(kTypicalGET_Transaction); |
| 6762 trans1.load_flags = LOAD_ONLY_FROM_CACHE; | 6762 trans1.load_flags = LOAD_ONLY_FROM_CACHE; |
| 6763 | 6763 |
| 6764 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); | 6764 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); |
| 6765 ASSERT_TRUE(response.metadata.get() != NULL); | 6765 ASSERT_TRUE(response.metadata.get() != NULL); |
| 6766 EXPECT_EQ(50, response.metadata->size()); | 6766 EXPECT_EQ(50, response.metadata->size()); |
| 6767 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there")); | 6767 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there")); |
| 6768 | 6768 |
| 6769 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6769 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6770 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 6770 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 6771 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6771 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6772 base::MessageLoop::current()->RunUntilIdle(); | 6772 base::RunLoop().RunUntilIdle(); |
| 6773 | 6773 |
| 6774 // Now make sure that the entry is re-validated with the server. | 6774 // Now make sure that the entry is re-validated with the server. |
| 6775 trans1.load_flags = LOAD_VALIDATE_CACHE; | 6775 trans1.load_flags = LOAD_VALIDATE_CACHE; |
| 6776 trans1.status = "HTTP/1.1 304 Not Modified"; | 6776 trans1.status = "HTTP/1.1 304 Not Modified"; |
| 6777 AddMockTransaction(&trans1); | 6777 AddMockTransaction(&trans1); |
| 6778 | 6778 |
| 6779 response.metadata = NULL; | 6779 response.metadata = NULL; |
| 6780 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); | 6780 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); |
| 6781 EXPECT_TRUE(response.metadata.get() != NULL); | 6781 EXPECT_TRUE(response.metadata.get() != NULL); |
| 6782 | 6782 |
| 6783 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 6783 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 6784 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 6784 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
| 6785 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6785 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6786 base::MessageLoop::current()->RunUntilIdle(); | 6786 base::RunLoop().RunUntilIdle(); |
| 6787 RemoveMockTransaction(&trans1); | 6787 RemoveMockTransaction(&trans1); |
| 6788 | 6788 |
| 6789 // Now return 200 when validating the entry so the metadata will be lost. | 6789 // Now return 200 when validating the entry so the metadata will be lost. |
| 6790 MockTransaction trans2(kTypicalGET_Transaction); | 6790 MockTransaction trans2(kTypicalGET_Transaction); |
| 6791 trans2.load_flags = LOAD_VALIDATE_CACHE; | 6791 trans2.load_flags = LOAD_VALIDATE_CACHE; |
| 6792 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 6792 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
| 6793 EXPECT_TRUE(response.metadata.get() == NULL); | 6793 EXPECT_TRUE(response.metadata.get() == NULL); |
| 6794 | 6794 |
| 6795 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 6795 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 6796 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 6796 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6813 | 6813 |
| 6814 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 6814 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 6815 rv = trans->Read(buf.get(), 256, callback.callback()); | 6815 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6816 EXPECT_GT(callback.GetResult(rv), 0); | 6816 EXPECT_GT(callback.GetResult(rv), 0); |
| 6817 | 6817 |
| 6818 // Now make sure that the entry is preserved. | 6818 // Now make sure that the entry is preserved. |
| 6819 trans->DoneReading(); | 6819 trans->DoneReading(); |
| 6820 } | 6820 } |
| 6821 | 6821 |
| 6822 // Make sure that the ActiveEntry is gone. | 6822 // Make sure that the ActiveEntry is gone. |
| 6823 base::MessageLoop::current()->RunUntilIdle(); | 6823 base::RunLoop().RunUntilIdle(); |
| 6824 | 6824 |
| 6825 // Read from the cache. | 6825 // Read from the cache. |
| 6826 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 6826 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 6827 | 6827 |
| 6828 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6828 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6829 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 6829 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 6830 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6830 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6831 } | 6831 } |
| 6832 | 6832 |
| 6833 // Tests that we don't mark entries as truncated and release the cache | 6833 // Tests that we don't mark entries as truncated and release the cache |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6844 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); | 6844 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); |
| 6845 | 6845 |
| 6846 MockHttpRequest request(transaction); | 6846 MockHttpRequest request(transaction); |
| 6847 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6847 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 6848 EXPECT_EQ(OK, callback.GetResult(rv)); | 6848 EXPECT_EQ(OK, callback.GetResult(rv)); |
| 6849 | 6849 |
| 6850 trans->DoneReading(); | 6850 trans->DoneReading(); |
| 6851 // Leave the transaction around. | 6851 // Leave the transaction around. |
| 6852 | 6852 |
| 6853 // Make sure that the ActiveEntry is gone. | 6853 // Make sure that the ActiveEntry is gone. |
| 6854 base::MessageLoop::current()->RunUntilIdle(); | 6854 base::RunLoop().RunUntilIdle(); |
| 6855 | 6855 |
| 6856 // Read from the cache. This should not deadlock. | 6856 // Read from the cache. This should not deadlock. |
| 6857 RunTransactionTest(cache.http_cache(), transaction); | 6857 RunTransactionTest(cache.http_cache(), transaction); |
| 6858 | 6858 |
| 6859 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6859 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6860 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 6860 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 6861 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6861 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6862 } | 6862 } |
| 6863 | 6863 |
| 6864 // Tests that we stop caching when told. | 6864 // Tests that we stop caching when told. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6881 trans->StopCaching(); | 6881 trans->StopCaching(); |
| 6882 | 6882 |
| 6883 // We should be able to keep reading. | 6883 // We should be able to keep reading. |
| 6884 rv = trans->Read(buf.get(), 256, callback.callback()); | 6884 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6885 EXPECT_GT(callback.GetResult(rv), 0); | 6885 EXPECT_GT(callback.GetResult(rv), 0); |
| 6886 rv = trans->Read(buf.get(), 256, callback.callback()); | 6886 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6887 EXPECT_EQ(0, callback.GetResult(rv)); | 6887 EXPECT_EQ(0, callback.GetResult(rv)); |
| 6888 } | 6888 } |
| 6889 | 6889 |
| 6890 // Make sure that the ActiveEntry is gone. | 6890 // Make sure that the ActiveEntry is gone. |
| 6891 base::MessageLoop::current()->RunUntilIdle(); | 6891 base::RunLoop().RunUntilIdle(); |
| 6892 | 6892 |
| 6893 // Verify that the entry is gone. | 6893 // Verify that the entry is gone. |
| 6894 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 6894 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 6895 | 6895 |
| 6896 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 6896 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 6897 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 6897 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 6898 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 6898 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 6899 } | 6899 } |
| 6900 | 6900 |
| 6901 // Tests that we stop caching when told, even if DoneReading is called | 6901 // Tests that we stop caching when told, even if DoneReading is called |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6922 rv = trans->Read(buf.get(), 256, callback.callback()); | 6922 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6923 EXPECT_GT(callback.GetResult(rv), 0); | 6923 EXPECT_GT(callback.GetResult(rv), 0); |
| 6924 rv = trans->Read(buf.get(), 256, callback.callback()); | 6924 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6925 EXPECT_EQ(0, callback.GetResult(rv)); | 6925 EXPECT_EQ(0, callback.GetResult(rv)); |
| 6926 | 6926 |
| 6927 // We should be able to call DoneReading. | 6927 // We should be able to call DoneReading. |
| 6928 trans->DoneReading(); | 6928 trans->DoneReading(); |
| 6929 } | 6929 } |
| 6930 | 6930 |
| 6931 // Make sure that the ActiveEntry is gone. | 6931 // Make sure that the ActiveEntry is gone. |
| 6932 base::MessageLoop::current()->RunUntilIdle(); | 6932 base::RunLoop().RunUntilIdle(); |
| 6933 | 6933 |
| 6934 // Verify that the entry is gone. | 6934 // Verify that the entry is gone. |
| 6935 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 6935 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 6936 | 6936 |
| 6937 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 6937 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 6938 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 6938 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 6939 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 6939 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 6940 } | 6940 } |
| 6941 | 6941 |
| 6942 // Tests that we stop caching when told, when using auth. | 6942 // Tests that we stop caching when told, when using auth. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6957 | 6957 |
| 6958 trans->StopCaching(); | 6958 trans->StopCaching(); |
| 6959 | 6959 |
| 6960 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 6960 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 6961 rv = trans->Read(buf.get(), 10, callback.callback()); | 6961 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 6962 EXPECT_EQ(callback.GetResult(rv), 10); | 6962 EXPECT_EQ(callback.GetResult(rv), 10); |
| 6963 } | 6963 } |
| 6964 RemoveMockTransaction(&mock_transaction); | 6964 RemoveMockTransaction(&mock_transaction); |
| 6965 | 6965 |
| 6966 // Make sure that the ActiveEntry is gone. | 6966 // Make sure that the ActiveEntry is gone. |
| 6967 base::MessageLoop::current()->RunUntilIdle(); | 6967 base::RunLoop().RunUntilIdle(); |
| 6968 | 6968 |
| 6969 // Verify that the entry is gone. | 6969 // Verify that the entry is gone. |
| 6970 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 6970 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 6971 | 6971 |
| 6972 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 6972 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 6973 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 6973 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 6974 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 6974 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 6975 } | 6975 } |
| 6976 | 6976 |
| 6977 // Tests that when we are told to stop caching we don't throw away valid data. | 6977 // Tests that when we are told to stop caching we don't throw away valid data. |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7279 // Read bytes 40-49 from the network. | 7279 // Read bytes 40-49 from the network. |
| 7280 int64_t sent, received; | 7280 int64_t sent, received; |
| 7281 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); | 7281 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); |
| 7282 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); | 7282 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); |
| 7283 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); | 7283 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); |
| 7284 | 7284 |
| 7285 // Read bytes 40-49 from the cache. | 7285 // Read bytes 40-49 from the cache. |
| 7286 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); | 7286 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); |
| 7287 EXPECT_EQ(0, sent); | 7287 EXPECT_EQ(0, sent); |
| 7288 EXPECT_EQ(0, received); | 7288 EXPECT_EQ(0, received); |
| 7289 base::MessageLoop::current()->RunUntilIdle(); | 7289 base::RunLoop().RunUntilIdle(); |
| 7290 | 7290 |
| 7291 // Read bytes 30-39 from the network. | 7291 // Read bytes 30-39 from the network. |
| 7292 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; | 7292 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; |
| 7293 transaction.data = "rg: 30-39 "; | 7293 transaction.data = "rg: 30-39 "; |
| 7294 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); | 7294 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); |
| 7295 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); | 7295 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); |
| 7296 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); | 7296 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); |
| 7297 base::MessageLoop::current()->RunUntilIdle(); | 7297 base::RunLoop().RunUntilIdle(); |
| 7298 | 7298 |
| 7299 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. | 7299 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. |
| 7300 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 7300 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
| 7301 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 7301 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
| 7302 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); | 7302 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); |
| 7303 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes * 2, sent); | 7303 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes * 2, sent); |
| 7304 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes * 2, received); | 7304 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes * 2, received); |
| 7305 | 7305 |
| 7306 RemoveMockTransaction(&kRangeGET_TransactionOK); | 7306 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 7307 } | 7307 } |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7601 MockHttpRequest request(mock_transaction); | 7601 MockHttpRequest request(mock_transaction); |
| 7602 | 7602 |
| 7603 std::unique_ptr<Context> first(new Context); | 7603 std::unique_ptr<Context> first(new Context); |
| 7604 first->result = cache.CreateTransaction(&first->trans); | 7604 first->result = cache.CreateTransaction(&first->trans); |
| 7605 ASSERT_EQ(OK, first->result); | 7605 ASSERT_EQ(OK, first->result); |
| 7606 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); | 7606 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); |
| 7607 first->result = | 7607 first->result = |
| 7608 first->trans->Start(&request, first->callback.callback(), BoundNetLog()); | 7608 first->trans->Start(&request, first->callback.callback(), BoundNetLog()); |
| 7609 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState()); | 7609 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState()); |
| 7610 | 7610 |
| 7611 base::MessageLoop::current()->RunUntilIdle(); | 7611 base::RunLoop().RunUntilIdle(); |
| 7612 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); | 7612 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); |
| 7613 ASSERT_TRUE(first->trans->GetResponseInfo()); | 7613 ASSERT_TRUE(first->trans->GetResponseInfo()); |
| 7614 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue( | 7614 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7615 "Cache-Control", "no-store")); | 7615 "Cache-Control", "no-store")); |
| 7616 // Here we have read the response header but not read the response body yet. | 7616 // Here we have read the response header but not read the response body yet. |
| 7617 | 7617 |
| 7618 // Let us create the second (read) transaction. | 7618 // Let us create the second (read) transaction. |
| 7619 std::unique_ptr<Context> second(new Context); | 7619 std::unique_ptr<Context> second(new Context); |
| 7620 second->result = cache.CreateTransaction(&second->trans); | 7620 second->result = cache.CreateTransaction(&second->trans); |
| 7621 ASSERT_EQ(OK, second->result); | 7621 ASSERT_EQ(OK, second->result); |
| 7622 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7622 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7623 second->result = second->trans->Start(&request, second->callback.callback(), | 7623 second->result = second->trans->Start(&request, second->callback.callback(), |
| 7624 BoundNetLog()); | 7624 BoundNetLog()); |
| 7625 | 7625 |
| 7626 // Here the second transaction proceeds without reading the first body. | 7626 // Here the second transaction proceeds without reading the first body. |
| 7627 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7627 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
| 7628 base::MessageLoop::current()->RunUntilIdle(); | 7628 base::RunLoop().RunUntilIdle(); |
| 7629 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7629 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7630 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7630 ASSERT_TRUE(second->trans->GetResponseInfo()); |
| 7631 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7631 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7632 "Cache-Control", "no-store")); | 7632 "Cache-Control", "no-store")); |
| 7633 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7633 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
| 7634 } | 7634 } |
| 7635 | 7635 |
| 7636 // Tests that serving a response entirely from cache replays the previous | 7636 // Tests that serving a response entirely from cache replays the previous |
| 7637 // SSLInfo. | 7637 // SSLInfo. |
| 7638 TEST(HttpCache, CachePreservesSSLInfo) { | 7638 TEST(HttpCache, CachePreservesSSLInfo) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7735 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 7735 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 7736 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 7736 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 7737 EXPECT_TRUE(response_info.was_cached); | 7737 EXPECT_TRUE(response_info.was_cached); |
| 7738 | 7738 |
| 7739 // The new SSL state is reported. | 7739 // The new SSL state is reported. |
| 7740 EXPECT_EQ(status2, response_info.ssl_info.connection_status); | 7740 EXPECT_EQ(status2, response_info.ssl_info.connection_status); |
| 7741 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); | 7741 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); |
| 7742 } | 7742 } |
| 7743 | 7743 |
| 7744 } // namespace net | 7744 } // namespace net |
| OLD | NEW |