OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 private: | 478 private: |
479 static bool no_store; | 479 static bool no_store; |
480 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); | 480 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); |
481 }; | 481 }; |
482 | 482 |
483 // Static. | 483 // Static. |
484 void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request, | 484 void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request, |
485 std::string* response_status, | 485 std::string* response_status, |
486 std::string* response_headers, | 486 std::string* response_headers, |
487 std::string* response_data) { | 487 std::string* response_data) { |
488 if (request->extra_headers.empty()) | 488 if (request->extra_headers.empty()) { |
| 489 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); |
489 return; | 490 return; |
| 491 } |
490 | 492 |
491 std::vector<net::HttpByteRange> ranges; | 493 std::vector<net::HttpByteRange> ranges; |
492 if (!net::HttpUtil::ParseRanges(request->extra_headers, &ranges) || | 494 if (!net::HttpUtil::ParseRanges(request->extra_headers, &ranges) || |
493 ranges.size() != 1) | 495 ranges.size() != 1) |
494 return; | 496 return; |
495 // We can handle this range request. | 497 // We can handle this range request. |
496 net::HttpByteRange byte_range = ranges[0]; | 498 net::HttpByteRange byte_range = ranges[0]; |
497 EXPECT_TRUE(byte_range.ComputeBounds(80)); | 499 EXPECT_TRUE(byte_range.ComputeBounds(80)); |
498 int start = static_cast<int>(byte_range.first_byte_position()); | 500 int start = static_cast<int>(byte_range.first_byte_position()); |
499 int end = static_cast<int>(byte_range.last_byte_position()); | 501 int end = static_cast<int>(byte_range.last_byte_position()); |
500 | 502 |
501 EXPECT_LT(end, 80); | 503 EXPECT_LT(end, 80); |
502 | 504 |
503 std::string content_range = StringPrintf("Content-Range: bytes %d-%d/80\n", | 505 std::string content_range = StringPrintf("Content-Range: bytes %d-%d/80\n", |
504 start, end); | 506 start, end); |
505 response_headers->append(content_range); | 507 response_headers->append(content_range); |
506 | 508 |
507 if (request->extra_headers.find("If-None-Match") == std::string::npos) { | 509 if (request->extra_headers.find("If-None-Match") == std::string::npos) { |
508 EXPECT_EQ(9, end - start); | 510 EXPECT_EQ(9, (end - start) % 10); |
509 std::string data = StringPrintf("rg: %02d-%02d ", start, end); | 511 std::string data; |
| 512 for (int block_start = start; block_start < end; block_start += 10) |
| 513 StringAppendF(&data, "rg: %02d-%02d ", block_start, block_start + 9); |
510 *response_data = data; | 514 *response_data = data; |
| 515 |
| 516 if (end - start != 9) { |
| 517 // We also have to fix content-length. |
| 518 int len = end - start + 1; |
| 519 EXPECT_EQ(0, len % 10); |
| 520 std::string content_length = StringPrintf("Content-Length: %d\n", len); |
| 521 response_headers->replace(response_headers->find("Content-Length:"), |
| 522 content_length.size(), content_length); |
| 523 } |
511 } else { | 524 } else { |
512 response_status->assign("HTTP/1.1 304 Not Modified"); | 525 response_status->assign("HTTP/1.1 304 Not Modified"); |
513 response_data->clear(); | 526 response_data->clear(); |
514 } | 527 } |
515 } | 528 } |
516 | 529 |
517 const MockTransaction kRangeGET_TransactionOK = { | 530 const MockTransaction kRangeGET_TransactionOK = { |
518 "http://www.google.com/range", | 531 "http://www.google.com/range", |
519 "GET", | 532 "GET", |
520 "Range: bytes = 40-49\r\n", | 533 "Range: bytes = 40-49\r\n", |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT"; | 1640 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT"; |
1628 RunTransactionTest(cache.http_cache(), transaction); | 1641 RunTransactionTest(cache.http_cache(), transaction); |
1629 | 1642 |
1630 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 1643 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
1631 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1644 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1632 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1645 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
1633 } | 1646 } |
1634 | 1647 |
1635 TEST(HttpCache, GET_Crazy206) { | 1648 TEST(HttpCache, GET_Crazy206) { |
1636 MockHttpCache cache; | 1649 MockHttpCache cache; |
1637 AddMockTransaction(&kRangeGET_TransactionOK); | |
1638 | 1650 |
1639 // Test that receiving 206 for a regular request is handled correctly. | 1651 // Test that receiving 206 for a regular request is handled correctly. |
1640 | 1652 |
1641 // Write to the cache. | 1653 // Write to the cache. |
1642 MockTransaction transaction(kRangeGET_TransactionOK); | 1654 MockTransaction transaction(kRangeGET_TransactionOK); |
| 1655 AddMockTransaction(&transaction); |
1643 transaction.request_headers = ""; | 1656 transaction.request_headers = ""; |
| 1657 transaction.handler = NULL; |
1644 RunTransactionTest(cache.http_cache(), transaction); | 1658 RunTransactionTest(cache.http_cache(), transaction); |
1645 | 1659 |
1646 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1660 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1647 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1661 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1648 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1662 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1649 | 1663 |
1650 // This should read again from the net. | 1664 // This should read again from the net. |
1651 RunTransactionTest(cache.http_cache(), transaction); | 1665 RunTransactionTest(cache.http_cache(), transaction); |
1652 | 1666 |
1653 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1667 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1654 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1668 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1655 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1669 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1656 RemoveMockTransaction(&kRangeGET_TransactionOK); | 1670 RemoveMockTransaction(&transaction); |
1657 } | 1671 } |
1658 | 1672 |
1659 TEST(HttpCache, DISABLED_RangeGET_OK) { | 1673 TEST(HttpCache, DISABLED_RangeGET_OK) { |
1660 MockHttpCache cache; | 1674 MockHttpCache cache; |
1661 AddMockTransaction(&kRangeGET_TransactionOK); | 1675 AddMockTransaction(&kRangeGET_TransactionOK); |
1662 | 1676 |
1663 // Test that we can cache range requests and fetch random blocks from the | 1677 // Test that we can cache range requests and fetch random blocks from the |
1664 // cache and the network. | 1678 // cache and the network. |
1665 | 1679 |
1666 std::string headers; | 1680 std::string headers; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 | 1713 |
1700 // Make sure we are done with the previous transaction. | 1714 // Make sure we are done with the previous transaction. |
1701 MessageLoop::current()->RunAllPending(); | 1715 MessageLoop::current()->RunAllPending(); |
1702 | 1716 |
1703 // Write and read from the cache (20-59). | 1717 // Write and read from the cache (20-59). |
1704 transaction.request_headers = "Range: bytes = 20-59\r\n"; | 1718 transaction.request_headers = "Range: bytes = 20-59\r\n"; |
1705 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 1719 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
1706 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 1720 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
1707 | 1721 |
1708 EXPECT_TRUE(Verify206Response(headers, 20, 59)); | 1722 EXPECT_TRUE(Verify206Response(headers, 20, 59)); |
1709 EXPECT_EQ(6, cache.network_layer()->transaction_count()); | 1723 EXPECT_EQ(5, cache.network_layer()->transaction_count()); |
1710 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 1724 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
1711 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1725 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1712 | 1726 |
1713 RemoveMockTransaction(&kRangeGET_TransactionOK); | 1727 RemoveMockTransaction(&kRangeGET_TransactionOK); |
1714 } | 1728 } |
1715 | 1729 |
1716 TEST(HttpCache, DISABLED_UnknownRangeGET_1) { | 1730 TEST(HttpCache, DISABLED_UnknownRangeGET_1) { |
1717 MockHttpCache cache; | 1731 MockHttpCache cache; |
1718 AddMockTransaction(&kRangeGET_TransactionOK); | 1732 AddMockTransaction(&kRangeGET_TransactionOK); |
1719 | 1733 |
(...skipping 15 matching lines...) Expand all Loading... |
1735 | 1749 |
1736 // Make sure we are done with the previous transaction. | 1750 // Make sure we are done with the previous transaction. |
1737 MessageLoop::current()->RunAllPending(); | 1751 MessageLoop::current()->RunAllPending(); |
1738 | 1752 |
1739 // Write and read from the cache (60-79). | 1753 // Write and read from the cache (60-79). |
1740 transaction.request_headers = "Range: bytes = 60-\r\n"; | 1754 transaction.request_headers = "Range: bytes = 60-\r\n"; |
1741 transaction.data = "rg: 60-69 rg: 70-79 "; | 1755 transaction.data = "rg: 60-69 rg: 70-79 "; |
1742 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 1756 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
1743 | 1757 |
1744 EXPECT_TRUE(Verify206Response(headers, 60, 79)); | 1758 EXPECT_TRUE(Verify206Response(headers, 60, 79)); |
1745 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 1759 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1746 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1760 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1747 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1761 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1748 | 1762 |
1749 RemoveMockTransaction(&kRangeGET_TransactionOK); | 1763 RemoveMockTransaction(&kRangeGET_TransactionOK); |
1750 } | 1764 } |
1751 | 1765 |
1752 TEST(HttpCache, DISABLED_UnknownRangeGET_2) { | 1766 TEST(HttpCache, DISABLED_UnknownRangeGET_2) { |
1753 MockHttpCache cache; | 1767 MockHttpCache cache; |
1754 AddMockTransaction(&kRangeGET_TransactionOK); | |
1755 | 1768 |
1756 // Test that we can cache range requests when the start or end is unknown. | 1769 // Test that we can cache range requests when the start or end is unknown. |
1757 // We start with one request from a given point, followed by a suffix request. | 1770 // We start with one request from a given point, followed by a suffix request. |
| 1771 // We'll also verify that synchronous cache responses work as intended. |
1758 | 1772 |
1759 std::string headers; | 1773 std::string headers; |
1760 | 1774 |
| 1775 MockTransaction transaction(kRangeGET_TransactionOK); |
| 1776 transaction.test_mode = TEST_MODE_SYNC_CACHE_START | |
| 1777 TEST_MODE_SYNC_CACHE_READ; |
| 1778 AddMockTransaction(&transaction); |
| 1779 |
1761 // Write to the cache (70-79). | 1780 // Write to the cache (70-79). |
1762 MockTransaction transaction(kRangeGET_TransactionOK); | |
1763 transaction.request_headers = "Range: bytes = 70-\r\n"; | 1781 transaction.request_headers = "Range: bytes = 70-\r\n"; |
1764 transaction.data = "rg: 70-79 "; | 1782 transaction.data = "rg: 70-79 "; |
1765 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 1783 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
1766 | 1784 |
1767 EXPECT_TRUE(Verify206Response(headers, 70, 79)); | 1785 EXPECT_TRUE(Verify206Response(headers, 70, 79)); |
1768 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1786 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1769 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1787 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1770 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1788 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1771 | 1789 |
1772 // Make sure we are done with the previous transaction. | 1790 // Make sure we are done with the previous transaction. |
1773 MessageLoop::current()->RunAllPending(); | 1791 MessageLoop::current()->RunAllPending(); |
1774 | 1792 |
1775 // Write and read from the cache (60-79). | 1793 // Write and read from the cache (60-79). |
1776 transaction.request_headers = "Range: bytes = -20\r\n"; | 1794 transaction.request_headers = "Range: bytes = -20\r\n"; |
1777 transaction.data = "rg: 60-69 rg: 70-79 "; | 1795 transaction.data = "rg: 60-69 rg: 70-79 "; |
1778 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 1796 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
1779 | 1797 |
1780 EXPECT_TRUE(Verify206Response(headers, 60, 79)); | 1798 EXPECT_TRUE(Verify206Response(headers, 60, 79)); |
| 1799 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1800 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1801 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1802 |
| 1803 RemoveMockTransaction(&transaction); |
| 1804 } |
| 1805 |
| 1806 TEST(HttpCache, DISABLED_GET_Previous206) { |
| 1807 MockHttpCache cache; |
| 1808 AddMockTransaction(&kRangeGET_TransactionOK); |
| 1809 |
| 1810 // Test that we can handle non-range requests when we have cached a range. |
| 1811 |
| 1812 std::string headers; |
| 1813 |
| 1814 // Write to the cache (40-49). |
| 1815 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 1816 &headers); |
| 1817 |
| 1818 EXPECT_TRUE(Verify206Response(headers, 40, 49)); |
| 1819 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1820 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1821 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1822 |
| 1823 // Write and read from the cache (0-79), when not asked for a range. |
| 1824 MockTransaction transaction(kRangeGET_TransactionOK); |
| 1825 transaction.request_headers = ""; |
| 1826 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 1827 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
| 1828 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 1829 |
| 1830 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
1781 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 1831 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
1782 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1832 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1783 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1833 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1784 | 1834 |
1785 RemoveMockTransaction(&kRangeGET_TransactionOK); | 1835 RemoveMockTransaction(&kRangeGET_TransactionOK); |
1786 } | 1836 } |
1787 | 1837 |
| 1838 TEST(HttpCache, DISABLED_GET_Previous206_NotSparse) { |
| 1839 MockHttpCache cache; |
| 1840 |
| 1841 // Test that we can handle cached 206 responses that are not sparse. |
| 1842 |
| 1843 // Create a disk cache entry that stores 206 headers while not being sparse. |
| 1844 disk_cache::Entry* entry; |
| 1845 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kSimpleGET_Transaction.url, |
| 1846 &entry)); |
| 1847 |
| 1848 std::string raw_headers(kRangeGET_TransactionOK.status); |
| 1849 raw_headers.append("\n"); |
| 1850 raw_headers.append(kRangeGET_TransactionOK.response_headers); |
| 1851 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
| 1852 raw_headers.size()); |
| 1853 |
| 1854 net::HttpResponseInfo response; |
| 1855 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 1856 net::HttpCache::WriteResponseInfo(entry, &response, true); |
| 1857 |
| 1858 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
| 1859 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 1860 kRangeGET_TransactionOK.data, 500)); |
| 1861 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); |
| 1862 entry->Close(); |
| 1863 |
| 1864 // Now see that we don't use the stored entry. |
| 1865 std::string headers; |
| 1866 RunTransactionTestWithResponse(cache.http_cache(), kSimpleGET_Transaction, |
| 1867 &headers); |
| 1868 |
| 1869 // We are expecting a 200. |
| 1870 std::string expected_headers(kSimpleGET_Transaction.status); |
| 1871 expected_headers.append("\n"); |
| 1872 expected_headers.append(kSimpleGET_Transaction.response_headers); |
| 1873 EXPECT_EQ(expected_headers, headers); |
| 1874 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1875 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1876 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 1877 } |
| 1878 |
| 1879 TEST(HttpCache, DISABLED_GET_Previous206_NotSparse_2) { |
| 1880 MockHttpCache cache; |
| 1881 AddMockTransaction(&kRangeGET_TransactionOK); |
| 1882 |
| 1883 // Test that we can handle cached 206 responses that are not sparse. This time |
| 1884 // we issue a range request and expect to receive a range. |
| 1885 |
| 1886 // Create a disk cache entry that stores 206 headers while not being sparse. |
| 1887 disk_cache::Entry* entry; |
| 1888 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kRangeGET_TransactionOK.url, |
| 1889 &entry)); |
| 1890 |
| 1891 std::string raw_headers(kRangeGET_TransactionOK.status); |
| 1892 raw_headers.append("\n"); |
| 1893 raw_headers.append(kRangeGET_TransactionOK.response_headers); |
| 1894 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
| 1895 raw_headers.size()); |
| 1896 |
| 1897 net::HttpResponseInfo response; |
| 1898 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 1899 net::HttpCache::WriteResponseInfo(entry, &response, true); |
| 1900 |
| 1901 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
| 1902 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 1903 kRangeGET_TransactionOK.data, 500)); |
| 1904 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); |
| 1905 entry->Close(); |
| 1906 |
| 1907 // Now see that we don't use the stored entry. |
| 1908 std::string headers; |
| 1909 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 1910 &headers); |
| 1911 |
| 1912 // We are expecting a 206. |
| 1913 EXPECT_TRUE(Verify206Response(headers, 40, 49)); |
| 1914 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1915 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1916 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 1917 |
| 1918 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 1919 } |
| 1920 |
| 1921 TEST(HttpCache, DISABLED_RangeRequestResultsIn200) { |
| 1922 MockHttpCache cache; |
| 1923 AddMockTransaction(&kRangeGET_TransactionOK); |
| 1924 |
| 1925 // Test that we can handle a 200 response when dealing with sparse entries. |
| 1926 |
| 1927 std::string headers; |
| 1928 |
| 1929 // Write to the cache (70-79). |
| 1930 MockTransaction transaction(kRangeGET_TransactionOK); |
| 1931 transaction.request_headers = "Range: bytes = -10\r\n"; |
| 1932 transaction.data = "rg: 70-79 "; |
| 1933 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 1934 |
| 1935 EXPECT_TRUE(Verify206Response(headers, 70, 79)); |
| 1936 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1937 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1938 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1939 |
| 1940 // Now we'll issue a request that results in a plain 200 response, but to |
| 1941 // the to the same URL that we used to store sparse data, and making sure |
| 1942 // that we ask for a range. |
| 1943 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 1944 MockTransaction transaction2(kSimpleGET_Transaction); |
| 1945 transaction2.url = kRangeGET_TransactionOK.url; |
| 1946 transaction2.request_headers = kRangeGET_TransactionOK.request_headers; |
| 1947 AddMockTransaction(&transaction2); |
| 1948 |
| 1949 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 1950 |
| 1951 std::string expected_headers(kSimpleGET_Transaction.status); |
| 1952 expected_headers.append("\n"); |
| 1953 expected_headers.append(kSimpleGET_Transaction.response_headers); |
| 1954 EXPECT_EQ(expected_headers, headers); |
| 1955 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1956 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1957 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1958 |
| 1959 RemoveMockTransaction(&transaction2); |
| 1960 } |
| 1961 |
1788 TEST(HttpCache, SyncRead) { | 1962 TEST(HttpCache, SyncRead) { |
1789 MockHttpCache cache; | 1963 MockHttpCache cache; |
1790 | 1964 |
1791 // This test ensures that a read that completes synchronously does not cause | 1965 // This test ensures that a read that completes synchronously does not cause |
1792 // any problems. | 1966 // any problems. |
1793 | 1967 |
1794 ScopedMockTransaction transaction(kSimpleGET_Transaction); | 1968 ScopedMockTransaction transaction(kSimpleGET_Transaction); |
1795 transaction.test_mode |= (TEST_MODE_SYNC_CACHE_START | | 1969 transaction.test_mode |= (TEST_MODE_SYNC_CACHE_START | |
1796 TEST_MODE_SYNC_CACHE_READ); | 1970 TEST_MODE_SYNC_CACHE_READ); |
1797 | 1971 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 | 2211 |
2038 // force this transaction to write to the cache again | 2212 // force this transaction to write to the cache again |
2039 MockTransaction transaction(kSimpleGET_Transaction); | 2213 MockTransaction transaction(kSimpleGET_Transaction); |
2040 | 2214 |
2041 RunTransactionTest(cache.http_cache(), transaction); | 2215 RunTransactionTest(cache.http_cache(), transaction); |
2042 | 2216 |
2043 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2217 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2044 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2218 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2045 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2219 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2046 } | 2220 } |
OLD | NEW |