| 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 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 request.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 1632 request.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 1633 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); | 1633 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); |
| 1634 | 1634 |
| 1635 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1635 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1636 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1636 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1637 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1637 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1638 } | 1638 } |
| 1639 | 1639 |
| 1640 TEST(HttpCache, RangeGET_SkipsCache) { | 1640 TEST(HttpCache, RangeGET_SkipsCache) { |
| 1641 MockHttpCache cache; | 1641 MockHttpCache cache; |
| 1642 cache.http_cache()->set_enable_range_support(true); | |
| 1643 | 1642 |
| 1644 // Test that we skip the cache for range GET requests. Eventually, we will | 1643 // Test that we skip the cache for range GET requests. Eventually, we will |
| 1645 // want to cache these, but we'll still have cases where skipping the cache | 1644 // want to cache these, but we'll still have cases where skipping the cache |
| 1646 // makes sense, so we want to make sure that it works properly. | 1645 // makes sense, so we want to make sure that it works properly. |
| 1647 | 1646 |
| 1648 RunTransactionTest(cache.http_cache(), kRangeGET_Transaction); | 1647 RunTransactionTest(cache.http_cache(), kRangeGET_Transaction); |
| 1649 | 1648 |
| 1650 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1649 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1651 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1650 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1652 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1651 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1653 | 1652 |
| 1654 MockTransaction transaction(kSimpleGET_Transaction); | 1653 MockTransaction transaction(kSimpleGET_Transaction); |
| 1655 transaction.request_headers = "If-None-Match: foo"; | 1654 transaction.request_headers = "If-None-Match: foo"; |
| 1656 RunTransactionTest(cache.http_cache(), transaction); | 1655 RunTransactionTest(cache.http_cache(), transaction); |
| 1657 | 1656 |
| 1658 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1657 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1659 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1658 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1660 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1659 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1661 | 1660 |
| 1662 transaction.request_headers = | 1661 transaction.request_headers = |
| 1663 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT"; | 1662 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT"; |
| 1664 RunTransactionTest(cache.http_cache(), transaction); | 1663 RunTransactionTest(cache.http_cache(), transaction); |
| 1665 | 1664 |
| 1666 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 1665 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 1667 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1666 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1668 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1667 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1669 } | 1668 } |
| 1670 | 1669 |
| 1670 // Test that we skip the cache for range requests that include a validation |
| 1671 // header. |
| 1672 TEST(HttpCache, RangeGET_SkipsCache2) { |
| 1673 MockHttpCache cache; |
| 1674 cache.http_cache()->set_enable_range_support(true); |
| 1675 |
| 1676 MockTransaction transaction(kRangeGET_Transaction); |
| 1677 transaction.request_headers = "If-None-Match: foo\n" |
| 1678 "Range: bytes = 40-49\n"; |
| 1679 RunTransactionTest(cache.http_cache(), transaction); |
| 1680 |
| 1681 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1682 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1683 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1684 |
| 1685 transaction.request_headers = |
| 1686 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\n" |
| 1687 "Range: bytes = 40-49\n"; |
| 1688 RunTransactionTest(cache.http_cache(), transaction); |
| 1689 |
| 1690 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1691 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1692 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1693 |
| 1694 transaction.request_headers = "If-Range: bla\n" |
| 1695 "Range: bytes = 40-49\n"; |
| 1696 RunTransactionTest(cache.http_cache(), transaction); |
| 1697 |
| 1698 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 1699 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1700 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1701 } |
| 1702 |
| 1671 // Tests that receiving 206 for a regular request is handled correctly. | 1703 // Tests that receiving 206 for a regular request is handled correctly. |
| 1672 TEST(HttpCache, GET_Crazy206) { | 1704 TEST(HttpCache, GET_Crazy206) { |
| 1673 MockHttpCache cache; | 1705 MockHttpCache cache; |
| 1674 cache.http_cache()->set_enable_range_support(true); | 1706 cache.http_cache()->set_enable_range_support(true); |
| 1675 | 1707 |
| 1676 // Write to the cache. | 1708 // Write to the cache. |
| 1677 MockTransaction transaction(kRangeGET_TransactionOK); | 1709 MockTransaction transaction(kRangeGET_TransactionOK); |
| 1678 AddMockTransaction(&transaction); | 1710 AddMockTransaction(&transaction); |
| 1679 transaction.request_headers = ""; | 1711 transaction.request_headers = ""; |
| 1680 transaction.handler = NULL; | 1712 transaction.handler = NULL; |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2445 | 2477 |
| 2446 // force this transaction to write to the cache again | 2478 // force this transaction to write to the cache again |
| 2447 MockTransaction transaction(kSimpleGET_Transaction); | 2479 MockTransaction transaction(kSimpleGET_Transaction); |
| 2448 | 2480 |
| 2449 RunTransactionTest(cache.http_cache(), transaction); | 2481 RunTransactionTest(cache.http_cache(), transaction); |
| 2450 | 2482 |
| 2451 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2483 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2452 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2484 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2453 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2485 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2454 } | 2486 } |
| OLD | NEW |