| 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 25 matching lines...) Expand all Loading... |
| 36 #include "net/http/http_byte_range.h" | 36 #include "net/http/http_byte_range.h" |
| 37 #include "net/http/http_cache_transaction.h" | 37 #include "net/http/http_cache_transaction.h" |
| 38 #include "net/http/http_request_headers.h" | 38 #include "net/http/http_request_headers.h" |
| 39 #include "net/http/http_request_info.h" | 39 #include "net/http/http_request_info.h" |
| 40 #include "net/http/http_response_headers.h" | 40 #include "net/http/http_response_headers.h" |
| 41 #include "net/http/http_response_info.h" | 41 #include "net/http/http_response_info.h" |
| 42 #include "net/http/http_transaction.h" | 42 #include "net/http/http_transaction.h" |
| 43 #include "net/http/http_transaction_test_util.h" | 43 #include "net/http/http_transaction_test_util.h" |
| 44 #include "net/http/http_util.h" | 44 #include "net/http/http_util.h" |
| 45 #include "net/http/mock_http_cache.h" | 45 #include "net/http/mock_http_cache.h" |
| 46 #include "net/log/net_log_event_type.h" |
| 46 #include "net/log/test_net_log.h" | 47 #include "net/log/test_net_log.h" |
| 47 #include "net/log/test_net_log_entry.h" | 48 #include "net/log/test_net_log_entry.h" |
| 48 #include "net/log/test_net_log_util.h" | 49 #include "net/log/test_net_log_util.h" |
| 49 #include "net/socket/client_socket_handle.h" | 50 #include "net/socket/client_socket_handle.h" |
| 50 #include "net/ssl/ssl_cert_request_info.h" | 51 #include "net/ssl/ssl_cert_request_info.h" |
| 51 #include "net/ssl/ssl_connection_status_flags.h" | 52 #include "net/ssl/ssl_connection_status_flags.h" |
| 52 #include "net/test/cert_test_util.h" | 53 #include "net/test/cert_test_util.h" |
| 53 #include "net/test/gtest_util.h" | 54 #include "net/test/gtest_util.h" |
| 54 #include "net/test/test_data_directory.h" | 55 #include "net/test/test_data_directory.h" |
| 55 #include "net/websockets/websocket_handshake_stream_base.h" | 56 #include "net/websockets/websocket_handshake_stream_base.h" |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 return NULL; | 586 return NULL; |
| 586 } | 587 } |
| 587 WebSocketHandshakeStreamBase* CreateSpdyStream( | 588 WebSocketHandshakeStreamBase* CreateSpdyStream( |
| 588 const base::WeakPtr<SpdySession>& session, | 589 const base::WeakPtr<SpdySession>& session, |
| 589 bool use_relative_url) override { | 590 bool use_relative_url) override { |
| 590 return NULL; | 591 return NULL; |
| 591 } | 592 } |
| 592 }; | 593 }; |
| 593 | 594 |
| 594 // Returns true if |entry| is not one of the log types paid attention to in this | 595 // Returns true if |entry| is not one of the log types paid attention to in this |
| 595 // test. Note that TYPE_HTTP_CACHE_WRITE_INFO and TYPE_HTTP_CACHE_*_DATA are | 596 // test. Note that HTTP_CACHE_WRITE_INFO and HTTP_CACHE_*_DATA are |
| 596 // ignored. | 597 // ignored. |
| 597 bool ShouldIgnoreLogEntry(const TestNetLogEntry& entry) { | 598 bool ShouldIgnoreLogEntry(const TestNetLogEntry& entry) { |
| 598 switch (entry.type) { | 599 switch (entry.type) { |
| 599 case NetLog::TYPE_HTTP_CACHE_GET_BACKEND: | 600 case NetLogEventType::HTTP_CACHE_GET_BACKEND: |
| 600 case NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: | 601 case NetLogEventType::HTTP_CACHE_OPEN_ENTRY: |
| 601 case NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: | 602 case NetLogEventType::HTTP_CACHE_CREATE_ENTRY: |
| 602 case NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: | 603 case NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY: |
| 603 case NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: | 604 case NetLogEventType::HTTP_CACHE_DOOM_ENTRY: |
| 604 case NetLog::TYPE_HTTP_CACHE_READ_INFO: | 605 case NetLogEventType::HTTP_CACHE_READ_INFO: |
| 605 return false; | 606 return false; |
| 606 default: | 607 default: |
| 607 return true; | 608 return true; |
| 608 } | 609 } |
| 609 } | 610 } |
| 610 | 611 |
| 611 // Modifies |entries| to only include log entries created by the cache layer and | 612 // Modifies |entries| to only include log entries created by the cache layer and |
| 612 // asserted on in these tests. | 613 // asserted on in these tests. |
| 613 void FilterLogEntries(TestNetLogEntry::List* entries) { | 614 void FilterLogEntries(TestNetLogEntry::List* entries) { |
| 614 entries->erase(std::remove_if(entries->begin(), entries->end(), | 615 entries->erase(std::remove_if(entries->begin(), entries->end(), |
| 615 &ShouldIgnoreLogEntry), | 616 &ShouldIgnoreLogEntry), |
| 616 entries->end()); | 617 entries->end()); |
| 617 } | 618 } |
| 618 | 619 |
| 619 bool LogContainsEventType(const BoundTestNetLog& log, | 620 bool LogContainsEventType(const BoundTestNetLog& log, |
| 620 NetLog::EventType expected) { | 621 NetLogEventType expected) { |
| 621 TestNetLogEntry::List entries; | 622 TestNetLogEntry::List entries; |
| 622 log.GetEntries(&entries); | 623 log.GetEntries(&entries); |
| 623 for (size_t i = 0; i < entries.size(); i++) { | 624 for (size_t i = 0; i < entries.size(); i++) { |
| 624 if (entries[i].type == expected) | 625 if (entries[i].type == expected) |
| 625 return true; | 626 return true; |
| 626 } | 627 } |
| 627 return false; | 628 return false; |
| 628 } | 629 } |
| 629 | 630 |
| 630 } // namespace | 631 } // namespace |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 679 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
| 679 log.bound(), &load_timing_info); | 680 log.bound(), &load_timing_info); |
| 680 | 681 |
| 681 // Check that the NetLog was filled as expected. | 682 // Check that the NetLog was filled as expected. |
| 682 // (We attempted to both Open and Create entries, but both failed). | 683 // (We attempted to both Open and Create entries, but both failed). |
| 683 TestNetLogEntry::List entries; | 684 TestNetLogEntry::List entries; |
| 684 log.GetEntries(&entries); | 685 log.GetEntries(&entries); |
| 685 FilterLogEntries(&entries); | 686 FilterLogEntries(&entries); |
| 686 | 687 |
| 687 EXPECT_EQ(6u, entries.size()); | 688 EXPECT_EQ(6u, entries.size()); |
| 689 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, |
| 690 NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 688 EXPECT_TRUE( | 691 EXPECT_TRUE( |
| 689 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 692 LogContainsEndEvent(entries, 1, NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 693 EXPECT_TRUE(LogContainsBeginEvent(entries, 2, |
| 694 NetLogEventType::HTTP_CACHE_OPEN_ENTRY)); |
| 690 EXPECT_TRUE( | 695 EXPECT_TRUE( |
| 691 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 696 LogContainsEndEvent(entries, 3, NetLogEventType::HTTP_CACHE_OPEN_ENTRY)); |
| 692 EXPECT_TRUE( | 697 EXPECT_TRUE(LogContainsBeginEvent(entries, 4, |
| 693 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 698 NetLogEventType::HTTP_CACHE_CREATE_ENTRY)); |
| 694 EXPECT_TRUE( | 699 EXPECT_TRUE(LogContainsEndEvent(entries, 5, |
| 695 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 700 NetLogEventType::HTTP_CACHE_CREATE_ENTRY)); |
| 696 EXPECT_TRUE( | |
| 697 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | |
| 698 EXPECT_TRUE( | |
| 699 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | |
| 700 | 701 |
| 701 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 702 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 702 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 703 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 703 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 704 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 704 TestLoadTimingNetworkRequest(load_timing_info); | 705 TestLoadTimingNetworkRequest(load_timing_info); |
| 705 } | 706 } |
| 706 | 707 |
| 707 TEST(HttpCache, SimpleGETNoDiskCache2) { | 708 TEST(HttpCache, SimpleGETNoDiskCache2) { |
| 708 // This will initialize a cache object with NULL backend. | 709 // This will initialize a cache object with NULL backend. |
| 709 std::unique_ptr<MockBlockingBackendFactory> factory( | 710 std::unique_ptr<MockBlockingBackendFactory> factory( |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 // Write to the cache. | 845 // Write to the cache. |
| 845 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 846 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
| 846 log.bound(), &load_timing_info); | 847 log.bound(), &load_timing_info); |
| 847 | 848 |
| 848 // Check that the NetLog was filled as expected. | 849 // Check that the NetLog was filled as expected. |
| 849 TestNetLogEntry::List entries; | 850 TestNetLogEntry::List entries; |
| 850 log.GetEntries(&entries); | 851 log.GetEntries(&entries); |
| 851 FilterLogEntries(&entries); | 852 FilterLogEntries(&entries); |
| 852 | 853 |
| 853 EXPECT_EQ(8u, entries.size()); | 854 EXPECT_EQ(8u, entries.size()); |
| 855 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, |
| 856 NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 854 EXPECT_TRUE( | 857 EXPECT_TRUE( |
| 855 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 858 LogContainsEndEvent(entries, 1, NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 859 EXPECT_TRUE(LogContainsBeginEvent(entries, 2, |
| 860 NetLogEventType::HTTP_CACHE_OPEN_ENTRY)); |
| 856 EXPECT_TRUE( | 861 EXPECT_TRUE( |
| 857 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 862 LogContainsEndEvent(entries, 3, NetLogEventType::HTTP_CACHE_OPEN_ENTRY)); |
| 858 EXPECT_TRUE( | 863 EXPECT_TRUE(LogContainsBeginEvent(entries, 4, |
| 859 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 864 NetLogEventType::HTTP_CACHE_CREATE_ENTRY)); |
| 860 EXPECT_TRUE( | 865 EXPECT_TRUE(LogContainsEndEvent(entries, 5, |
| 861 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 866 NetLogEventType::HTTP_CACHE_CREATE_ENTRY)); |
| 862 EXPECT_TRUE( | 867 EXPECT_TRUE(LogContainsBeginEvent(entries, 6, |
| 863 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 868 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY)); |
| 864 EXPECT_TRUE( | 869 EXPECT_TRUE(LogContainsEndEvent(entries, 7, |
| 865 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 870 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY)); |
| 866 EXPECT_TRUE( | |
| 867 LogContainsBeginEvent(entries, 6, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | |
| 868 EXPECT_TRUE( | |
| 869 LogContainsEndEvent(entries, 7, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | |
| 870 | 871 |
| 871 TestLoadTimingNetworkRequest(load_timing_info); | 872 TestLoadTimingNetworkRequest(load_timing_info); |
| 872 | 873 |
| 873 // Force this transaction to read from the cache. | 874 // Force this transaction to read from the cache. |
| 874 MockTransaction transaction(kSimpleGET_Transaction); | 875 MockTransaction transaction(kSimpleGET_Transaction); |
| 875 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; | 876 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 876 | 877 |
| 877 log.Clear(); | 878 log.Clear(); |
| 878 | 879 |
| 879 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 880 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
| 880 &load_timing_info); | 881 &load_timing_info); |
| 881 | 882 |
| 882 // Check that the NetLog was filled as expected. | 883 // Check that the NetLog was filled as expected. |
| 883 log.GetEntries(&entries); | 884 log.GetEntries(&entries); |
| 884 FilterLogEntries(&entries); | 885 FilterLogEntries(&entries); |
| 885 | 886 |
| 886 EXPECT_EQ(8u, entries.size()); | 887 EXPECT_EQ(8u, entries.size()); |
| 888 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, |
| 889 NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 887 EXPECT_TRUE( | 890 EXPECT_TRUE( |
| 888 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 891 LogContainsEndEvent(entries, 1, NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 892 EXPECT_TRUE(LogContainsBeginEvent(entries, 2, |
| 893 NetLogEventType::HTTP_CACHE_OPEN_ENTRY)); |
| 889 EXPECT_TRUE( | 894 EXPECT_TRUE( |
| 890 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 895 LogContainsEndEvent(entries, 3, NetLogEventType::HTTP_CACHE_OPEN_ENTRY)); |
| 896 EXPECT_TRUE(LogContainsBeginEvent(entries, 4, |
| 897 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY)); |
| 898 EXPECT_TRUE(LogContainsEndEvent(entries, 5, |
| 899 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY)); |
| 891 EXPECT_TRUE( | 900 EXPECT_TRUE( |
| 892 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 901 LogContainsBeginEvent(entries, 6, NetLogEventType::HTTP_CACHE_READ_INFO)); |
| 893 EXPECT_TRUE( | 902 EXPECT_TRUE( |
| 894 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 903 LogContainsEndEvent(entries, 7, NetLogEventType::HTTP_CACHE_READ_INFO)); |
| 895 EXPECT_TRUE( | |
| 896 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | |
| 897 EXPECT_TRUE( | |
| 898 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | |
| 899 EXPECT_TRUE( | |
| 900 LogContainsBeginEvent(entries, 6, NetLog::TYPE_HTTP_CACHE_READ_INFO)); | |
| 901 EXPECT_TRUE( | |
| 902 LogContainsEndEvent(entries, 7, NetLog::TYPE_HTTP_CACHE_READ_INFO)); | |
| 903 | 904 |
| 904 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 905 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 905 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 906 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 906 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 907 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 907 TestLoadTimingCachedResponse(load_timing_info); | 908 TestLoadTimingCachedResponse(load_timing_info); |
| 908 } | 909 } |
| 909 | 910 |
| 910 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { | 911 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { |
| 911 MockHttpCache cache; | 912 MockHttpCache cache; |
| 912 | 913 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 // Write to the cache. | 1106 // Write to the cache. |
| 1106 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 1107 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
| 1107 &load_timing_info); | 1108 &load_timing_info); |
| 1108 | 1109 |
| 1109 // Check that the NetLog was filled as expected. | 1110 // Check that the NetLog was filled as expected. |
| 1110 TestNetLogEntry::List entries; | 1111 TestNetLogEntry::List entries; |
| 1111 log.GetEntries(&entries); | 1112 log.GetEntries(&entries); |
| 1112 FilterLogEntries(&entries); | 1113 FilterLogEntries(&entries); |
| 1113 | 1114 |
| 1114 EXPECT_EQ(8u, entries.size()); | 1115 EXPECT_EQ(8u, entries.size()); |
| 1116 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, |
| 1117 NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 1115 EXPECT_TRUE( | 1118 EXPECT_TRUE( |
| 1116 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1119 LogContainsEndEvent(entries, 1, NetLogEventType::HTTP_CACHE_GET_BACKEND)); |
| 1120 EXPECT_TRUE(LogContainsBeginEvent(entries, 2, |
| 1121 NetLogEventType::HTTP_CACHE_DOOM_ENTRY)); |
| 1117 EXPECT_TRUE( | 1122 EXPECT_TRUE( |
| 1118 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1123 LogContainsEndEvent(entries, 3, NetLogEventType::HTTP_CACHE_DOOM_ENTRY)); |
| 1119 EXPECT_TRUE( | 1124 EXPECT_TRUE(LogContainsBeginEvent(entries, 4, |
| 1120 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); | 1125 NetLogEventType::HTTP_CACHE_CREATE_ENTRY)); |
| 1121 EXPECT_TRUE( | 1126 EXPECT_TRUE(LogContainsEndEvent(entries, 5, |
| 1122 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); | 1127 NetLogEventType::HTTP_CACHE_CREATE_ENTRY)); |
| 1123 EXPECT_TRUE( | 1128 EXPECT_TRUE(LogContainsBeginEvent(entries, 6, |
| 1124 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1129 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY)); |
| 1125 EXPECT_TRUE( | 1130 EXPECT_TRUE(LogContainsEndEvent(entries, 7, |
| 1126 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1131 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY)); |
| 1127 EXPECT_TRUE( | |
| 1128 LogContainsBeginEvent(entries, 6, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | |
| 1129 EXPECT_TRUE( | |
| 1130 LogContainsEndEvent(entries, 7, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | |
| 1131 | 1132 |
| 1132 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1133 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1133 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1134 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1134 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 1135 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 1135 TestLoadTimingNetworkRequest(load_timing_info); | 1136 TestLoadTimingNetworkRequest(load_timing_info); |
| 1136 } | 1137 } |
| 1137 | 1138 |
| 1138 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { | 1139 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { |
| 1139 MockHttpCache cache; | 1140 MockHttpCache cache; |
| 1140 | 1141 |
| (...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3790 } | 3791 } |
| 3791 | 3792 |
| 3792 TEST(HttpCache, SimpleGET_DoesntLogHeaders) { | 3793 TEST(HttpCache, SimpleGET_DoesntLogHeaders) { |
| 3793 MockHttpCache cache; | 3794 MockHttpCache cache; |
| 3794 | 3795 |
| 3795 BoundTestNetLog log; | 3796 BoundTestNetLog log; |
| 3796 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, | 3797 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, |
| 3797 log.bound()); | 3798 log.bound()); |
| 3798 | 3799 |
| 3799 EXPECT_FALSE(LogContainsEventType( | 3800 EXPECT_FALSE(LogContainsEventType( |
| 3800 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3801 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3801 } | 3802 } |
| 3802 | 3803 |
| 3803 TEST(HttpCache, RangeGET_LogsHeaders) { | 3804 TEST(HttpCache, RangeGET_LogsHeaders) { |
| 3804 MockHttpCache cache; | 3805 MockHttpCache cache; |
| 3805 | 3806 |
| 3806 BoundTestNetLog log; | 3807 BoundTestNetLog log; |
| 3807 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, | 3808 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, |
| 3808 log.bound()); | 3809 log.bound()); |
| 3809 | 3810 |
| 3810 EXPECT_TRUE(LogContainsEventType( | 3811 EXPECT_TRUE(LogContainsEventType( |
| 3811 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3812 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3812 } | 3813 } |
| 3813 | 3814 |
| 3814 TEST(HttpCache, ExternalValidation_LogsHeaders) { | 3815 TEST(HttpCache, ExternalValidation_LogsHeaders) { |
| 3815 MockHttpCache cache; | 3816 MockHttpCache cache; |
| 3816 | 3817 |
| 3817 BoundTestNetLog log; | 3818 BoundTestNetLog log; |
| 3818 MockTransaction transaction(kSimpleGET_Transaction); | 3819 MockTransaction transaction(kSimpleGET_Transaction); |
| 3819 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; | 3820 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; |
| 3820 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 3821 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
| 3821 | 3822 |
| 3822 EXPECT_TRUE(LogContainsEventType( | 3823 EXPECT_TRUE(LogContainsEventType( |
| 3823 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3824 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3824 } | 3825 } |
| 3825 | 3826 |
| 3826 TEST(HttpCache, SpecialHeaders_LogsHeaders) { | 3827 TEST(HttpCache, SpecialHeaders_LogsHeaders) { |
| 3827 MockHttpCache cache; | 3828 MockHttpCache cache; |
| 3828 | 3829 |
| 3829 BoundTestNetLog log; | 3830 BoundTestNetLog log; |
| 3830 MockTransaction transaction(kSimpleGET_Transaction); | 3831 MockTransaction transaction(kSimpleGET_Transaction); |
| 3831 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; | 3832 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; |
| 3832 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 3833 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
| 3833 | 3834 |
| 3834 EXPECT_TRUE(LogContainsEventType( | 3835 EXPECT_TRUE(LogContainsEventType( |
| 3835 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3836 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3836 } | 3837 } |
| 3837 | 3838 |
| 3838 // Tests that receiving 206 for a regular request is handled correctly. | 3839 // Tests that receiving 206 for a regular request is handled correctly. |
| 3839 TEST(HttpCache, GET_Crazy206) { | 3840 TEST(HttpCache, GET_Crazy206) { |
| 3840 MockHttpCache cache; | 3841 MockHttpCache cache; |
| 3841 | 3842 |
| 3842 // Write to the cache. | 3843 // Write to the cache. |
| 3843 MockTransaction transaction(kRangeGET_TransactionOK); | 3844 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3844 AddMockTransaction(&transaction); | 3845 AddMockTransaction(&transaction); |
| 3845 transaction.request_headers = EXTRA_HEADER; | 3846 transaction.request_headers = EXTRA_HEADER; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3941 transaction.response_headers = "Content-Length: 10\n" | 3942 transaction.response_headers = "Content-Length: 10\n" |
| 3942 "ETag: \"foo\"\n"; | 3943 "ETag: \"foo\"\n"; |
| 3943 RunTransactionTest(cache.http_cache(), transaction); | 3944 RunTransactionTest(cache.http_cache(), transaction); |
| 3944 | 3945 |
| 3945 // Now verify that the cached data is not used. | 3946 // Now verify that the cached data is not used. |
| 3946 BoundTestNetLog log; | 3947 BoundTestNetLog log; |
| 3947 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, | 3948 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, |
| 3948 log.bound()); | 3949 log.bound()); |
| 3949 | 3950 |
| 3950 EXPECT_TRUE(LogContainsEventType( | 3951 EXPECT_TRUE(LogContainsEventType( |
| 3951 log, NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST)); | 3952 log, NetLogEventType::HTTP_CACHE_RESTART_PARTIAL_REQUEST)); |
| 3952 } | 3953 } |
| 3953 | 3954 |
| 3954 // Tests that a failure to conditionalize a regular request (no range) with a | 3955 // Tests that a failure to conditionalize a regular request (no range) with a |
| 3955 // sparse entry results in a full response. | 3956 // sparse entry results in a full response. |
| 3956 TEST(HttpCache, GET_NoConditionalization) { | 3957 TEST(HttpCache, GET_NoConditionalization) { |
| 3957 MockHttpCache cache; | 3958 MockHttpCache cache; |
| 3958 cache.FailConditionalizations(); | 3959 cache.FailConditionalizations(); |
| 3959 std::string headers; | 3960 std::string headers; |
| 3960 | 3961 |
| 3961 // Write to the cache (40-49). | 3962 // Write to the cache (40-49). |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5491 RangeTransactionServer handler; | 5492 RangeTransactionServer handler; |
| 5492 handler.set_bad_200(true); | 5493 handler.set_bad_200(true); |
| 5493 transaction.data = "Not a range"; | 5494 transaction.data = "Not a range"; |
| 5494 BoundTestNetLog log; | 5495 BoundTestNetLog log; |
| 5495 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 5496 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
| 5496 | 5497 |
| 5497 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 5498 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 5498 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5499 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5499 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5500 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5500 EXPECT_TRUE(LogContainsEventType( | 5501 EXPECT_TRUE(LogContainsEventType( |
| 5501 log, NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)); | 5502 log, NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)); |
| 5502 } | 5503 } |
| 5503 | 5504 |
| 5504 // Tests that when the server gives us less data than expected, we don't keep | 5505 // Tests that when the server gives us less data than expected, we don't keep |
| 5505 // asking for more data. | 5506 // asking for more data. |
| 5506 TEST(HttpCache, RangeGET_FastFlakyServer2) { | 5507 TEST(HttpCache, RangeGET_FastFlakyServer2) { |
| 5507 MockHttpCache cache; | 5508 MockHttpCache cache; |
| 5508 | 5509 |
| 5509 // First, check with an empty cache (WRITE mode). | 5510 // First, check with an empty cache (WRITE mode). |
| 5510 MockTransaction transaction(kRangeGET_TransactionOK); | 5511 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5511 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; | 5512 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; |
| (...skipping 2584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8096 RunTransactionTestWithResponseInfo(cache.http_cache(), | 8097 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 8097 kTypicalGET_Transaction, &response_info); | 8098 kTypicalGET_Transaction, &response_info); |
| 8098 | 8099 |
| 8099 EXPECT_FALSE(response_info.was_cached); | 8100 EXPECT_FALSE(response_info.was_cached); |
| 8100 EXPECT_TRUE(response_info.network_accessed); | 8101 EXPECT_TRUE(response_info.network_accessed); |
| 8101 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | 8102 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
| 8102 response_info.cache_entry_status); | 8103 response_info.cache_entry_status); |
| 8103 } | 8104 } |
| 8104 | 8105 |
| 8105 } // namespace net | 8106 } // namespace net |
| OLD | NEW |