Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 TYPE_HTTP_CACHE_WRITE_INFO and TYPE_HTTP_CACHE_*_DATA are
eroman 2016/09/06 19:32:20 Please update these comments.
mikecirone 2016/09/07 21:35:41 Done.
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
688 EXPECT_TRUE( 689 EXPECT_TRUE(
689 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 690 LogContainsBeginEvent(entries, 0,
691 NetLogEventType::HTTP_CACHE_GET_BACKEND));
690 EXPECT_TRUE( 692 EXPECT_TRUE(
691 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 693 LogContainsEndEvent(entries, 1,
694 NetLogEventType::HTTP_CACHE_GET_BACKEND));
692 EXPECT_TRUE( 695 EXPECT_TRUE(
693 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 696 LogContainsBeginEvent(entries, 2,
697 NetLogEventType::HTTP_CACHE_OPEN_ENTRY));
694 EXPECT_TRUE( 698 EXPECT_TRUE(
695 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 699 LogContainsEndEvent(entries, 3,
700 NetLogEventType::HTTP_CACHE_OPEN_ENTRY));
696 EXPECT_TRUE( 701 EXPECT_TRUE(
697 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 702 LogContainsBeginEvent(entries, 4,
703 NetLogEventType::HTTP_CACHE_CREATE_ENTRY));
698 EXPECT_TRUE( 704 EXPECT_TRUE(
699 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 705 LogContainsEndEvent(entries, 5,
706 NetLogEventType::HTTP_CACHE_CREATE_ENTRY));
700 707
701 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 708 EXPECT_EQ(1, cache.network_layer()->transaction_count());
702 EXPECT_EQ(0, cache.disk_cache()->open_count()); 709 EXPECT_EQ(0, cache.disk_cache()->open_count());
703 EXPECT_EQ(0, cache.disk_cache()->create_count()); 710 EXPECT_EQ(0, cache.disk_cache()->create_count());
704 TestLoadTimingNetworkRequest(load_timing_info); 711 TestLoadTimingNetworkRequest(load_timing_info);
705 } 712 }
706 713
707 TEST(HttpCache, SimpleGETNoDiskCache2) { 714 TEST(HttpCache, SimpleGETNoDiskCache2) {
708 // This will initialize a cache object with NULL backend. 715 // This will initialize a cache object with NULL backend.
709 std::unique_ptr<MockBlockingBackendFactory> factory( 716 std::unique_ptr<MockBlockingBackendFactory> factory(
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, 852 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction,
846 log.bound(), &load_timing_info); 853 log.bound(), &load_timing_info);
847 854
848 // Check that the NetLog was filled as expected. 855 // Check that the NetLog was filled as expected.
849 TestNetLogEntry::List entries; 856 TestNetLogEntry::List entries;
850 log.GetEntries(&entries); 857 log.GetEntries(&entries);
851 FilterLogEntries(&entries); 858 FilterLogEntries(&entries);
852 859
853 EXPECT_EQ(8u, entries.size()); 860 EXPECT_EQ(8u, entries.size());
854 EXPECT_TRUE( 861 EXPECT_TRUE(
855 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 862 LogContainsBeginEvent(entries, 0,
863 NetLogEventType::HTTP_CACHE_GET_BACKEND));
856 EXPECT_TRUE( 864 EXPECT_TRUE(
857 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 865 LogContainsEndEvent(entries, 1,
866 NetLogEventType::HTTP_CACHE_GET_BACKEND));
858 EXPECT_TRUE( 867 EXPECT_TRUE(
859 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 868 LogContainsBeginEvent(entries, 2,
869 NetLogEventType::HTTP_CACHE_OPEN_ENTRY));
860 EXPECT_TRUE( 870 EXPECT_TRUE(
861 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 871 LogContainsEndEvent(entries, 3,
872 NetLogEventType::HTTP_CACHE_OPEN_ENTRY));
862 EXPECT_TRUE( 873 EXPECT_TRUE(
863 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 874 LogContainsBeginEvent(entries, 4,
875 NetLogEventType::HTTP_CACHE_CREATE_ENTRY));
864 EXPECT_TRUE( 876 EXPECT_TRUE(
865 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 877 LogContainsEndEvent(entries, 5,
878 NetLogEventType::HTTP_CACHE_CREATE_ENTRY));
866 EXPECT_TRUE( 879 EXPECT_TRUE(
867 LogContainsBeginEvent(entries, 6, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 880 LogContainsBeginEvent(entries, 6,
881 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY));
868 EXPECT_TRUE( 882 EXPECT_TRUE(
869 LogContainsEndEvent(entries, 7, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 883 LogContainsEndEvent(entries, 7,
884 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY));
870 885
871 TestLoadTimingNetworkRequest(load_timing_info); 886 TestLoadTimingNetworkRequest(load_timing_info);
872 887
873 // Force this transaction to read from the cache. 888 // Force this transaction to read from the cache.
874 MockTransaction transaction(kSimpleGET_Transaction); 889 MockTransaction transaction(kSimpleGET_Transaction);
875 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; 890 transaction.load_flags |= LOAD_ONLY_FROM_CACHE;
876 891
877 log.Clear(); 892 log.Clear();
878 893
879 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), 894 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
880 &load_timing_info); 895 &load_timing_info);
881 896
882 // Check that the NetLog was filled as expected. 897 // Check that the NetLog was filled as expected.
883 log.GetEntries(&entries); 898 log.GetEntries(&entries);
884 FilterLogEntries(&entries); 899 FilterLogEntries(&entries);
885 900
886 EXPECT_EQ(8u, entries.size()); 901 EXPECT_EQ(8u, entries.size());
887 EXPECT_TRUE( 902 EXPECT_TRUE(
888 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 903 LogContainsBeginEvent(entries, 0,
904 NetLogEventType::HTTP_CACHE_GET_BACKEND));
889 EXPECT_TRUE( 905 EXPECT_TRUE(
890 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 906 LogContainsEndEvent(entries, 1,
907 NetLogEventType::HTTP_CACHE_GET_BACKEND));
891 EXPECT_TRUE( 908 EXPECT_TRUE(
892 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 909 LogContainsBeginEvent(entries, 2,
910 NetLogEventType::HTTP_CACHE_OPEN_ENTRY));
893 EXPECT_TRUE( 911 EXPECT_TRUE(
894 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 912 LogContainsEndEvent(entries, 3,
913 NetLogEventType::HTTP_CACHE_OPEN_ENTRY));
895 EXPECT_TRUE( 914 EXPECT_TRUE(
896 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 915 LogContainsBeginEvent(entries, 4,
916 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY));
897 EXPECT_TRUE( 917 EXPECT_TRUE(
898 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 918 LogContainsEndEvent(entries, 5,
919 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY));
899 EXPECT_TRUE( 920 EXPECT_TRUE(
900 LogContainsBeginEvent(entries, 6, NetLog::TYPE_HTTP_CACHE_READ_INFO)); 921 LogContainsBeginEvent(entries, 6,
922 NetLogEventType::HTTP_CACHE_READ_INFO));
901 EXPECT_TRUE( 923 EXPECT_TRUE(
902 LogContainsEndEvent(entries, 7, NetLog::TYPE_HTTP_CACHE_READ_INFO)); 924 LogContainsEndEvent(entries, 7,
925 NetLogEventType::HTTP_CACHE_READ_INFO));
903 926
904 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 927 EXPECT_EQ(1, cache.network_layer()->transaction_count());
905 EXPECT_EQ(1, cache.disk_cache()->open_count()); 928 EXPECT_EQ(1, cache.disk_cache()->open_count());
906 EXPECT_EQ(1, cache.disk_cache()->create_count()); 929 EXPECT_EQ(1, cache.disk_cache()->create_count());
907 TestLoadTimingCachedResponse(load_timing_info); 930 TestLoadTimingCachedResponse(load_timing_info);
908 } 931 }
909 932
910 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { 933 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
911 MockHttpCache cache; 934 MockHttpCache cache;
912 935
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), 1129 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
1107 &load_timing_info); 1130 &load_timing_info);
1108 1131
1109 // Check that the NetLog was filled as expected. 1132 // Check that the NetLog was filled as expected.
1110 TestNetLogEntry::List entries; 1133 TestNetLogEntry::List entries;
1111 log.GetEntries(&entries); 1134 log.GetEntries(&entries);
1112 FilterLogEntries(&entries); 1135 FilterLogEntries(&entries);
1113 1136
1114 EXPECT_EQ(8u, entries.size()); 1137 EXPECT_EQ(8u, entries.size());
1115 EXPECT_TRUE( 1138 EXPECT_TRUE(
1116 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 1139 LogContainsBeginEvent(entries, 0,
1140 NetLogEventType::HTTP_CACHE_GET_BACKEND));
1117 EXPECT_TRUE( 1141 EXPECT_TRUE(
1118 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 1142 LogContainsEndEvent(entries, 1,
1143 NetLogEventType::HTTP_CACHE_GET_BACKEND));
1119 EXPECT_TRUE( 1144 EXPECT_TRUE(
1120 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); 1145 LogContainsBeginEvent(entries, 2,
1146 NetLogEventType::HTTP_CACHE_DOOM_ENTRY));
1121 EXPECT_TRUE( 1147 EXPECT_TRUE(
1122 LogContainsEndEvent(entries, 3, NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); 1148 LogContainsEndEvent(entries, 3,
1149 NetLogEventType::HTTP_CACHE_DOOM_ENTRY));
1123 EXPECT_TRUE( 1150 EXPECT_TRUE(
1124 LogContainsBeginEvent(entries, 4, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1151 LogContainsBeginEvent(entries, 4,
1152 NetLogEventType::HTTP_CACHE_CREATE_ENTRY));
1125 EXPECT_TRUE( 1153 EXPECT_TRUE(
1126 LogContainsEndEvent(entries, 5, NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1154 LogContainsEndEvent(entries, 5,
1155 NetLogEventType::HTTP_CACHE_CREATE_ENTRY));
1127 EXPECT_TRUE( 1156 EXPECT_TRUE(
1128 LogContainsBeginEvent(entries, 6, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 1157 LogContainsBeginEvent(entries, 6,
1158 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY));
1129 EXPECT_TRUE( 1159 EXPECT_TRUE(
1130 LogContainsEndEvent(entries, 7, NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 1160 LogContainsEndEvent(entries, 7,
1161 NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY));
1131 1162
1132 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1163 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1133 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1164 EXPECT_EQ(0, cache.disk_cache()->open_count());
1134 EXPECT_EQ(2, cache.disk_cache()->create_count()); 1165 EXPECT_EQ(2, cache.disk_cache()->create_count());
1135 TestLoadTimingNetworkRequest(load_timing_info); 1166 TestLoadTimingNetworkRequest(load_timing_info);
1136 } 1167 }
1137 1168
1138 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { 1169 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) {
1139 MockHttpCache cache; 1170 MockHttpCache cache;
1140 1171
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after
3790 } 3821 }
3791 3822
3792 TEST(HttpCache, SimpleGET_DoesntLogHeaders) { 3823 TEST(HttpCache, SimpleGET_DoesntLogHeaders) {
3793 MockHttpCache cache; 3824 MockHttpCache cache;
3794 3825
3795 BoundTestNetLog log; 3826 BoundTestNetLog log;
3796 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, 3827 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction,
3797 log.bound()); 3828 log.bound());
3798 3829
3799 EXPECT_FALSE(LogContainsEventType( 3830 EXPECT_FALSE(LogContainsEventType(
3800 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); 3831 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS));
3801 } 3832 }
3802 3833
3803 TEST(HttpCache, RangeGET_LogsHeaders) { 3834 TEST(HttpCache, RangeGET_LogsHeaders) {
3804 MockHttpCache cache; 3835 MockHttpCache cache;
3805 3836
3806 BoundTestNetLog log; 3837 BoundTestNetLog log;
3807 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, 3838 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction,
3808 log.bound()); 3839 log.bound());
3809 3840
3810 EXPECT_TRUE(LogContainsEventType( 3841 EXPECT_TRUE(LogContainsEventType(
3811 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); 3842 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS));
3812 } 3843 }
3813 3844
3814 TEST(HttpCache, ExternalValidation_LogsHeaders) { 3845 TEST(HttpCache, ExternalValidation_LogsHeaders) {
3815 MockHttpCache cache; 3846 MockHttpCache cache;
3816 3847
3817 BoundTestNetLog log; 3848 BoundTestNetLog log;
3818 MockTransaction transaction(kSimpleGET_Transaction); 3849 MockTransaction transaction(kSimpleGET_Transaction);
3819 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; 3850 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER;
3820 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); 3851 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound());
3821 3852
3822 EXPECT_TRUE(LogContainsEventType( 3853 EXPECT_TRUE(LogContainsEventType(
3823 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); 3854 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS));
3824 } 3855 }
3825 3856
3826 TEST(HttpCache, SpecialHeaders_LogsHeaders) { 3857 TEST(HttpCache, SpecialHeaders_LogsHeaders) {
3827 MockHttpCache cache; 3858 MockHttpCache cache;
3828 3859
3829 BoundTestNetLog log; 3860 BoundTestNetLog log;
3830 MockTransaction transaction(kSimpleGET_Transaction); 3861 MockTransaction transaction(kSimpleGET_Transaction);
3831 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; 3862 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER;
3832 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); 3863 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound());
3833 3864
3834 EXPECT_TRUE(LogContainsEventType( 3865 EXPECT_TRUE(LogContainsEventType(
3835 log, NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); 3866 log, NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS));
3836 } 3867 }
3837 3868
3838 // Tests that receiving 206 for a regular request is handled correctly. 3869 // Tests that receiving 206 for a regular request is handled correctly.
3839 TEST(HttpCache, GET_Crazy206) { 3870 TEST(HttpCache, GET_Crazy206) {
3840 MockHttpCache cache; 3871 MockHttpCache cache;
3841 3872
3842 // Write to the cache. 3873 // Write to the cache.
3843 MockTransaction transaction(kRangeGET_TransactionOK); 3874 MockTransaction transaction(kRangeGET_TransactionOK);
3844 AddMockTransaction(&transaction); 3875 AddMockTransaction(&transaction);
3845 transaction.request_headers = EXTRA_HEADER; 3876 transaction.request_headers = EXTRA_HEADER;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3941 transaction.response_headers = "Content-Length: 10\n" 3972 transaction.response_headers = "Content-Length: 10\n"
3942 "ETag: \"foo\"\n"; 3973 "ETag: \"foo\"\n";
3943 RunTransactionTest(cache.http_cache(), transaction); 3974 RunTransactionTest(cache.http_cache(), transaction);
3944 3975
3945 // Now verify that the cached data is not used. 3976 // Now verify that the cached data is not used.
3946 BoundTestNetLog log; 3977 BoundTestNetLog log;
3947 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, 3978 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK,
3948 log.bound()); 3979 log.bound());
3949 3980
3950 EXPECT_TRUE(LogContainsEventType( 3981 EXPECT_TRUE(LogContainsEventType(
3951 log, NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST)); 3982 log, NetLogEventType::HTTP_CACHE_RESTART_PARTIAL_REQUEST));
3952 } 3983 }
3953 3984
3954 // Tests that a failure to conditionalize a regular request (no range) with a 3985 // Tests that a failure to conditionalize a regular request (no range) with a
3955 // sparse entry results in a full response. 3986 // sparse entry results in a full response.
3956 TEST(HttpCache, GET_NoConditionalization) { 3987 TEST(HttpCache, GET_NoConditionalization) {
3957 MockHttpCache cache; 3988 MockHttpCache cache;
3958 cache.FailConditionalizations(); 3989 cache.FailConditionalizations();
3959 std::string headers; 3990 std::string headers;
3960 3991
3961 // Write to the cache (40-49). 3992 // Write to the cache (40-49).
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after
5491 RangeTransactionServer handler; 5522 RangeTransactionServer handler;
5492 handler.set_bad_200(true); 5523 handler.set_bad_200(true);
5493 transaction.data = "Not a range"; 5524 transaction.data = "Not a range";
5494 BoundTestNetLog log; 5525 BoundTestNetLog log;
5495 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); 5526 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound());
5496 5527
5497 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 5528 EXPECT_EQ(3, cache.network_layer()->transaction_count());
5498 EXPECT_EQ(1, cache.disk_cache()->open_count()); 5529 EXPECT_EQ(1, cache.disk_cache()->open_count());
5499 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5530 EXPECT_EQ(1, cache.disk_cache()->create_count());
5500 EXPECT_TRUE(LogContainsEventType( 5531 EXPECT_TRUE(LogContainsEventType(
5501 log, NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)); 5532 log, NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST));
5502 } 5533 }
5503 5534
5504 // Tests that when the server gives us less data than expected, we don't keep 5535 // Tests that when the server gives us less data than expected, we don't keep
5505 // asking for more data. 5536 // asking for more data.
5506 TEST(HttpCache, RangeGET_FastFlakyServer2) { 5537 TEST(HttpCache, RangeGET_FastFlakyServer2) {
5507 MockHttpCache cache; 5538 MockHttpCache cache;
5508 5539
5509 // First, check with an empty cache (WRITE mode). 5540 // First, check with an empty cache (WRITE mode).
5510 MockTransaction transaction(kRangeGET_TransactionOK); 5541 MockTransaction transaction(kRangeGET_TransactionOK);
5511 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; 5542 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER;
(...skipping 2584 matching lines...) Expand 10 before | Expand all | Expand 10 after
8096 RunTransactionTestWithResponseInfo(cache.http_cache(), 8127 RunTransactionTestWithResponseInfo(cache.http_cache(),
8097 kTypicalGET_Transaction, &response_info); 8128 kTypicalGET_Transaction, &response_info);
8098 8129
8099 EXPECT_FALSE(response_info.was_cached); 8130 EXPECT_FALSE(response_info.was_cached);
8100 EXPECT_TRUE(response_info.network_accessed); 8131 EXPECT_TRUE(response_info.network_accessed);
8101 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, 8132 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8102 response_info.cache_entry_status); 8133 response_info.cache_entry_status);
8103 } 8134 }
8104 8135
8105 } // namespace net 8136 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698