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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 net::WebSocketHandshakeStreamBase* CreateSpdyStream( | 527 net::WebSocketHandshakeStreamBase* CreateSpdyStream( |
528 const base::WeakPtr<net::SpdySession>& session, | 528 const base::WeakPtr<net::SpdySession>& session, |
529 bool use_relative_url) override { | 529 bool use_relative_url) override { |
530 return NULL; | 530 return NULL; |
531 } | 531 } |
532 }; | 532 }; |
533 | 533 |
534 // Returns true if |entry| is not one of the log types paid attention to in this | 534 // Returns true if |entry| is not one of the log types paid attention to in this |
535 // test. Note that TYPE_HTTP_CACHE_WRITE_INFO and TYPE_HTTP_CACHE_*_DATA are | 535 // test. Note that TYPE_HTTP_CACHE_WRITE_INFO and TYPE_HTTP_CACHE_*_DATA are |
536 // ignored. | 536 // ignored. |
537 bool ShouldIgnoreLogEntry(const net::CapturingNetLog::CapturedEntry& entry) { | 537 bool ShouldIgnoreLogEntry(const net::TestNetLog::CapturedEntry& entry) { |
538 switch (entry.type) { | 538 switch (entry.type) { |
539 case net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND: | 539 case net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND: |
540 case net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: | 540 case net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: |
541 case net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: | 541 case net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: |
542 case net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: | 542 case net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: |
543 case net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: | 543 case net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: |
544 case net::NetLog::TYPE_HTTP_CACHE_READ_INFO: | 544 case net::NetLog::TYPE_HTTP_CACHE_READ_INFO: |
545 return false; | 545 return false; |
546 default: | 546 default: |
547 return true; | 547 return true; |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 // Modifies |entries| to only include log entries created by the cache layer and | 551 // Modifies |entries| to only include log entries created by the cache layer and |
552 // asserted on in these tests. | 552 // asserted on in these tests. |
553 void FilterLogEntries(net::CapturingNetLog::CapturedEntryList* entries) { | 553 void FilterLogEntries(net::TestNetLog::CapturedEntryList* entries) { |
554 entries->erase(std::remove_if(entries->begin(), entries->end(), | 554 entries->erase(std::remove_if(entries->begin(), entries->end(), |
555 &ShouldIgnoreLogEntry), | 555 &ShouldIgnoreLogEntry), |
556 entries->end()); | 556 entries->end()); |
557 } | 557 } |
558 | 558 |
559 bool LogContainsEventType(const net::CapturingBoundNetLog& log, | 559 bool LogContainsEventType(const net::BoundTestNetLog& log, |
560 net::NetLog::EventType expected) { | 560 net::NetLog::EventType expected) { |
561 net::CapturingNetLog::CapturedEntryList entries; | 561 net::TestNetLog::CapturedEntryList entries; |
562 log.GetEntries(&entries); | 562 log.GetEntries(&entries); |
563 for (size_t i = 0; i < entries.size(); i++) { | 563 for (size_t i = 0; i < entries.size(); i++) { |
564 if (entries[i].type == expected) | 564 if (entries[i].type == expected) |
565 return true; | 565 return true; |
566 } | 566 } |
567 return false; | 567 return false; |
568 } | 568 } |
569 | 569 |
570 } // namespace | 570 } // namespace |
571 | 571 |
(...skipping 14 matching lines...) Expand all Loading... |
586 | 586 |
587 disk_cache::Backend* backend; | 587 disk_cache::Backend* backend; |
588 net::TestCompletionCallback cb; | 588 net::TestCompletionCallback cb; |
589 // This will lazily initialize the backend. | 589 // This will lazily initialize the backend. |
590 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); | 590 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); |
591 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 591 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
592 } | 592 } |
593 | 593 |
594 TEST(HttpCache, SimpleGET) { | 594 TEST(HttpCache, SimpleGET) { |
595 MockHttpCache cache; | 595 MockHttpCache cache; |
596 net::CapturingBoundNetLog log; | 596 net::BoundTestNetLog log; |
597 net::LoadTimingInfo load_timing_info; | 597 net::LoadTimingInfo load_timing_info; |
598 | 598 |
599 // Write to the cache. | 599 // Write to the cache. |
600 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 600 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
601 log.bound(), &load_timing_info); | 601 log.bound(), &load_timing_info); |
602 | 602 |
603 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 603 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
604 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 604 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
605 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 605 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
606 TestLoadTimingNetworkRequest(load_timing_info); | 606 TestLoadTimingNetworkRequest(load_timing_info); |
607 } | 607 } |
608 | 608 |
609 TEST(HttpCache, SimpleGETNoDiskCache) { | 609 TEST(HttpCache, SimpleGETNoDiskCache) { |
610 MockHttpCache cache; | 610 MockHttpCache cache; |
611 | 611 |
612 cache.disk_cache()->set_fail_requests(); | 612 cache.disk_cache()->set_fail_requests(); |
613 | 613 |
614 net::CapturingBoundNetLog log; | 614 net::BoundTestNetLog log; |
615 net::LoadTimingInfo load_timing_info; | 615 net::LoadTimingInfo load_timing_info; |
616 | 616 |
617 // Read from the network, and don't use the cache. | 617 // Read from the network, and don't use the cache. |
618 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 618 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
619 log.bound(), &load_timing_info); | 619 log.bound(), &load_timing_info); |
620 | 620 |
621 // Check that the NetLog was filled as expected. | 621 // Check that the NetLog was filled as expected. |
622 // (We attempted to both Open and Create entries, but both failed). | 622 // (We attempted to both Open and Create entries, but both failed). |
623 net::CapturingNetLog::CapturedEntryList entries; | 623 net::TestNetLog::CapturedEntryList entries; |
624 log.GetEntries(&entries); | 624 log.GetEntries(&entries); |
625 FilterLogEntries(&entries); | 625 FilterLogEntries(&entries); |
626 | 626 |
627 EXPECT_EQ(6u, entries.size()); | 627 EXPECT_EQ(6u, entries.size()); |
628 EXPECT_TRUE(net::LogContainsBeginEvent( | 628 EXPECT_TRUE(net::LogContainsBeginEvent( |
629 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 629 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
630 EXPECT_TRUE(net::LogContainsEndEvent( | 630 EXPECT_TRUE(net::LogContainsEndEvent( |
631 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 631 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
632 EXPECT_TRUE(net::LogContainsBeginEvent( | 632 EXPECT_TRUE(net::LogContainsBeginEvent( |
633 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 633 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 770 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
771 | 771 |
772 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 772 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
773 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 773 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
774 EXPECT_EQ(3, cache.disk_cache()->create_count()); | 774 EXPECT_EQ(3, cache.disk_cache()->create_count()); |
775 } | 775 } |
776 | 776 |
777 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { | 777 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { |
778 MockHttpCache cache; | 778 MockHttpCache cache; |
779 | 779 |
780 net::CapturingBoundNetLog log; | 780 net::BoundTestNetLog log; |
781 net::LoadTimingInfo load_timing_info; | 781 net::LoadTimingInfo load_timing_info; |
782 | 782 |
783 // Write to the cache. | 783 // Write to the cache. |
784 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 784 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
785 log.bound(), &load_timing_info); | 785 log.bound(), &load_timing_info); |
786 | 786 |
787 // Check that the NetLog was filled as expected. | 787 // Check that the NetLog was filled as expected. |
788 net::CapturingNetLog::CapturedEntryList entries; | 788 net::TestNetLog::CapturedEntryList entries; |
789 log.GetEntries(&entries); | 789 log.GetEntries(&entries); |
790 FilterLogEntries(&entries); | 790 FilterLogEntries(&entries); |
791 | 791 |
792 EXPECT_EQ(8u, entries.size()); | 792 EXPECT_EQ(8u, entries.size()); |
793 EXPECT_TRUE(net::LogContainsBeginEvent( | 793 EXPECT_TRUE(net::LogContainsBeginEvent( |
794 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 794 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
795 EXPECT_TRUE(net::LogContainsEndEvent( | 795 EXPECT_TRUE(net::LogContainsEndEvent( |
796 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 796 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
797 EXPECT_TRUE(net::LogContainsBeginEvent( | 797 EXPECT_TRUE(net::LogContainsBeginEvent( |
798 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 798 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 transaction.request_headers = "Foo: bar\r\n"; | 933 transaction.request_headers = "Foo: bar\r\n"; |
934 transaction.response_headers = "Cache-Control: max-age=10000\n" | 934 transaction.response_headers = "Cache-Control: max-age=10000\n" |
935 "Vary: Foo\n"; | 935 "Vary: Foo\n"; |
936 AddMockTransaction(&transaction); | 936 AddMockTransaction(&transaction); |
937 RunTransactionTest(cache.http_cache(), transaction); | 937 RunTransactionTest(cache.http_cache(), transaction); |
938 | 938 |
939 // Attempt to read from the cache... this is a vary mismatch that must reach | 939 // Attempt to read from the cache... this is a vary mismatch that must reach |
940 // the network again. | 940 // the network again. |
941 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; | 941 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; |
942 transaction.request_headers = "Foo: none\r\n"; | 942 transaction.request_headers = "Foo: none\r\n"; |
943 net::CapturingBoundNetLog log; | 943 net::BoundTestNetLog log; |
944 net::LoadTimingInfo load_timing_info; | 944 net::LoadTimingInfo load_timing_info; |
945 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 945 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
946 &load_timing_info); | 946 &load_timing_info); |
947 | 947 |
948 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 948 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
949 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 949 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
950 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 950 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
951 TestLoadTimingNetworkRequest(load_timing_info); | 951 TestLoadTimingNetworkRequest(load_timing_info); |
952 RemoveMockTransaction(&transaction); | 952 RemoveMockTransaction(&transaction); |
953 } | 953 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 TEST(HttpCache, SimpleGET_LoadBypassCache) { | 1128 TEST(HttpCache, SimpleGET_LoadBypassCache) { |
1129 MockHttpCache cache; | 1129 MockHttpCache cache; |
1130 | 1130 |
1131 // Write to the cache. | 1131 // Write to the cache. |
1132 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1132 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1133 | 1133 |
1134 // Force this transaction to write to the cache again. | 1134 // Force this transaction to write to the cache again. |
1135 MockTransaction transaction(kSimpleGET_Transaction); | 1135 MockTransaction transaction(kSimpleGET_Transaction); |
1136 transaction.load_flags |= net::LOAD_BYPASS_CACHE; | 1136 transaction.load_flags |= net::LOAD_BYPASS_CACHE; |
1137 | 1137 |
1138 net::CapturingBoundNetLog log; | 1138 net::BoundTestNetLog log; |
1139 net::LoadTimingInfo load_timing_info; | 1139 net::LoadTimingInfo load_timing_info; |
1140 | 1140 |
1141 // Write to the cache. | 1141 // Write to the cache. |
1142 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 1142 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
1143 &load_timing_info); | 1143 &load_timing_info); |
1144 | 1144 |
1145 // Check that the NetLog was filled as expected. | 1145 // Check that the NetLog was filled as expected. |
1146 net::CapturingNetLog::CapturedEntryList entries; | 1146 net::TestNetLog::CapturedEntryList entries; |
1147 log.GetEntries(&entries); | 1147 log.GetEntries(&entries); |
1148 FilterLogEntries(&entries); | 1148 FilterLogEntries(&entries); |
1149 | 1149 |
1150 EXPECT_EQ(8u, entries.size()); | 1150 EXPECT_EQ(8u, entries.size()); |
1151 EXPECT_TRUE(net::LogContainsBeginEvent( | 1151 EXPECT_TRUE(net::LogContainsBeginEvent( |
1152 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1152 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
1153 EXPECT_TRUE(net::LogContainsEndEvent( | 1153 EXPECT_TRUE(net::LogContainsEndEvent( |
1154 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1154 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
1155 EXPECT_TRUE(net::LogContainsBeginEvent( | 1155 EXPECT_TRUE(net::LogContainsBeginEvent( |
1156 entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); | 1156 entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1212 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1213 | 1213 |
1214 // Read from the cache. | 1214 // Read from the cache. |
1215 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1215 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1216 | 1216 |
1217 // Force this transaction to validate the cache. | 1217 // Force this transaction to validate the cache. |
1218 MockTransaction transaction(kSimpleGET_Transaction); | 1218 MockTransaction transaction(kSimpleGET_Transaction); |
1219 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 1219 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
1220 | 1220 |
1221 net::HttpResponseInfo response_info; | 1221 net::HttpResponseInfo response_info; |
1222 net::CapturingBoundNetLog log; | 1222 net::BoundTestNetLog log; |
1223 net::LoadTimingInfo load_timing_info; | 1223 net::LoadTimingInfo load_timing_info; |
1224 RunTransactionTestWithResponseInfoAndGetTiming( | 1224 RunTransactionTestWithResponseInfoAndGetTiming( |
1225 cache.http_cache(), transaction, &response_info, log.bound(), | 1225 cache.http_cache(), transaction, &response_info, log.bound(), |
1226 &load_timing_info); | 1226 &load_timing_info); |
1227 | 1227 |
1228 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1228 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1229 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1229 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1230 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1230 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1231 EXPECT_TRUE(response_info.network_accessed); | 1231 EXPECT_TRUE(response_info.network_accessed); |
1232 TestLoadTimingNetworkRequest(load_timing_info); | 1232 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 | 2005 |
2006 // write to the cache | 2006 // write to the cache |
2007 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); | 2007 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
2008 | 2008 |
2009 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2009 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2010 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2010 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2011 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2011 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2012 | 2012 |
2013 // Get the same URL again, but this time we expect it to result | 2013 // Get the same URL again, but this time we expect it to result |
2014 // in a conditional request. | 2014 // in a conditional request. |
2015 net::CapturingBoundNetLog log; | 2015 net::BoundTestNetLog log; |
2016 net::LoadTimingInfo load_timing_info; | 2016 net::LoadTimingInfo load_timing_info; |
2017 RunTransactionTestAndGetTiming(cache.http_cache(), kTypicalGET_Transaction, | 2017 RunTransactionTestAndGetTiming(cache.http_cache(), kTypicalGET_Transaction, |
2018 log.bound(), &load_timing_info); | 2018 log.bound(), &load_timing_info); |
2019 | 2019 |
2020 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2020 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2021 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2021 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2022 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2022 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2023 TestLoadTimingNetworkRequest(load_timing_info); | 2023 TestLoadTimingNetworkRequest(load_timing_info); |
2024 } | 2024 } |
2025 | 2025 |
(...skipping 18 matching lines...) Expand all Loading... |
2044 RunTransactionTest(cache.http_cache(), transaction); | 2044 RunTransactionTest(cache.http_cache(), transaction); |
2045 | 2045 |
2046 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2046 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2047 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2047 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2048 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2048 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2049 | 2049 |
2050 // Get the same URL again, but this time we expect it to result | 2050 // Get the same URL again, but this time we expect it to result |
2051 // in a conditional request. | 2051 // in a conditional request. |
2052 transaction.load_flags = net::LOAD_VALIDATE_CACHE; | 2052 transaction.load_flags = net::LOAD_VALIDATE_CACHE; |
2053 transaction.handler = ETagGet_ConditionalRequest_Handler; | 2053 transaction.handler = ETagGet_ConditionalRequest_Handler; |
2054 net::CapturingBoundNetLog log; | 2054 net::BoundTestNetLog log; |
2055 net::LoadTimingInfo load_timing_info; | 2055 net::LoadTimingInfo load_timing_info; |
2056 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2056 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
2057 &load_timing_info); | 2057 &load_timing_info); |
2058 | 2058 |
2059 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2059 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2060 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2060 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2061 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2061 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2062 TestLoadTimingNetworkRequest(load_timing_info); | 2062 TestLoadTimingNetworkRequest(load_timing_info); |
2063 } | 2063 } |
2064 | 2064 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2119 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 2119 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
2120 "Etag: \"foopy\"\n" | 2120 "Etag: \"foopy\"\n" |
2121 "Cache-Control: max-age=0\n" | 2121 "Cache-Control: max-age=0\n" |
2122 "Vary: Foo\n"; | 2122 "Vary: Foo\n"; |
2123 AddMockTransaction(&transaction); | 2123 AddMockTransaction(&transaction); |
2124 RunTransactionTest(cache.http_cache(), transaction); | 2124 RunTransactionTest(cache.http_cache(), transaction); |
2125 | 2125 |
2126 // Read from the cache. | 2126 // Read from the cache. |
2127 RevalidationServer server; | 2127 RevalidationServer server; |
2128 transaction.handler = server.Handler; | 2128 transaction.handler = server.Handler; |
2129 net::CapturingBoundNetLog log; | 2129 net::BoundTestNetLog log; |
2130 net::LoadTimingInfo load_timing_info; | 2130 net::LoadTimingInfo load_timing_info; |
2131 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2131 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
2132 &load_timing_info); | 2132 &load_timing_info); |
2133 | 2133 |
2134 EXPECT_TRUE(server.EtagUsed()); | 2134 EXPECT_TRUE(server.EtagUsed()); |
2135 EXPECT_TRUE(server.LastModifiedUsed()); | 2135 EXPECT_TRUE(server.LastModifiedUsed()); |
2136 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2136 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2137 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2137 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2138 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2138 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2139 TestLoadTimingNetworkRequest(load_timing_info); | 2139 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 13 matching lines...) Expand all Loading... |
2153 "Etag: \"foopy\"\n" | 2153 "Etag: \"foopy\"\n" |
2154 "Cache-Control: max-age=0\n" | 2154 "Cache-Control: max-age=0\n" |
2155 "Vary: Foo\n"; | 2155 "Vary: Foo\n"; |
2156 AddMockTransaction(&transaction); | 2156 AddMockTransaction(&transaction); |
2157 RunTransactionTest(cache.http_cache(), transaction); | 2157 RunTransactionTest(cache.http_cache(), transaction); |
2158 | 2158 |
2159 // Read from the cache and revalidate the entry. | 2159 // Read from the cache and revalidate the entry. |
2160 RevalidationServer server; | 2160 RevalidationServer server; |
2161 transaction.handler = server.Handler; | 2161 transaction.handler = server.Handler; |
2162 transaction.request_headers = "Foo: none\r\n"; | 2162 transaction.request_headers = "Foo: none\r\n"; |
2163 net::CapturingBoundNetLog log; | 2163 net::BoundTestNetLog log; |
2164 net::LoadTimingInfo load_timing_info; | 2164 net::LoadTimingInfo load_timing_info; |
2165 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2165 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
2166 &load_timing_info); | 2166 &load_timing_info); |
2167 | 2167 |
2168 EXPECT_TRUE(server.EtagUsed()); | 2168 EXPECT_TRUE(server.EtagUsed()); |
2169 EXPECT_FALSE(server.LastModifiedUsed()); | 2169 EXPECT_FALSE(server.LastModifiedUsed()); |
2170 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2170 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2171 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2171 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2172 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2172 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2173 TestLoadTimingNetworkRequest(load_timing_info); | 2173 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 12 matching lines...) Expand all Loading... |
2186 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 2186 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
2187 "Cache-Control: max-age=0\n" | 2187 "Cache-Control: max-age=0\n" |
2188 "Vary: Foo\n"; | 2188 "Vary: Foo\n"; |
2189 AddMockTransaction(&transaction); | 2189 AddMockTransaction(&transaction); |
2190 RunTransactionTest(cache.http_cache(), transaction); | 2190 RunTransactionTest(cache.http_cache(), transaction); |
2191 | 2191 |
2192 // Read from the cache and don't revalidate the entry. | 2192 // Read from the cache and don't revalidate the entry. |
2193 RevalidationServer server; | 2193 RevalidationServer server; |
2194 transaction.handler = server.Handler; | 2194 transaction.handler = server.Handler; |
2195 transaction.request_headers = "Foo: none\r\n"; | 2195 transaction.request_headers = "Foo: none\r\n"; |
2196 net::CapturingBoundNetLog log; | 2196 net::BoundTestNetLog log; |
2197 net::LoadTimingInfo load_timing_info; | 2197 net::LoadTimingInfo load_timing_info; |
2198 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2198 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
2199 &load_timing_info); | 2199 &load_timing_info); |
2200 | 2200 |
2201 EXPECT_FALSE(server.EtagUsed()); | 2201 EXPECT_FALSE(server.EtagUsed()); |
2202 EXPECT_FALSE(server.LastModifiedUsed()); | 2202 EXPECT_FALSE(server.LastModifiedUsed()); |
2203 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2203 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2204 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2204 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2205 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2205 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2206 TestLoadTimingNetworkRequest(load_timing_info); | 2206 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3804 RunTransactionTest(cache.http_cache(), transaction); | 3804 RunTransactionTest(cache.http_cache(), transaction); |
3805 | 3805 |
3806 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3806 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3807 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3807 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3808 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3808 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3809 } | 3809 } |
3810 | 3810 |
3811 TEST(HttpCache, SimpleGET_DoesntLogHeaders) { | 3811 TEST(HttpCache, SimpleGET_DoesntLogHeaders) { |
3812 MockHttpCache cache; | 3812 MockHttpCache cache; |
3813 | 3813 |
3814 net::CapturingBoundNetLog log; | 3814 net::BoundTestNetLog log; |
3815 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, | 3815 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, |
3816 log.bound()); | 3816 log.bound()); |
3817 | 3817 |
3818 EXPECT_FALSE(LogContainsEventType( | 3818 EXPECT_FALSE(LogContainsEventType( |
3819 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3819 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
3820 } | 3820 } |
3821 | 3821 |
3822 TEST(HttpCache, RangeGET_LogsHeaders) { | 3822 TEST(HttpCache, RangeGET_LogsHeaders) { |
3823 MockHttpCache cache; | 3823 MockHttpCache cache; |
3824 | 3824 |
3825 net::CapturingBoundNetLog log; | 3825 net::BoundTestNetLog log; |
3826 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, | 3826 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, |
3827 log.bound()); | 3827 log.bound()); |
3828 | 3828 |
3829 EXPECT_TRUE(LogContainsEventType( | 3829 EXPECT_TRUE(LogContainsEventType( |
3830 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3830 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
3831 } | 3831 } |
3832 | 3832 |
3833 TEST(HttpCache, ExternalValidation_LogsHeaders) { | 3833 TEST(HttpCache, ExternalValidation_LogsHeaders) { |
3834 MockHttpCache cache; | 3834 MockHttpCache cache; |
3835 | 3835 |
3836 net::CapturingBoundNetLog log; | 3836 net::BoundTestNetLog log; |
3837 MockTransaction transaction(kSimpleGET_Transaction); | 3837 MockTransaction transaction(kSimpleGET_Transaction); |
3838 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; | 3838 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; |
3839 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 3839 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
3840 | 3840 |
3841 EXPECT_TRUE(LogContainsEventType( | 3841 EXPECT_TRUE(LogContainsEventType( |
3842 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3842 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
3843 } | 3843 } |
3844 | 3844 |
3845 TEST(HttpCache, SpecialHeaders_LogsHeaders) { | 3845 TEST(HttpCache, SpecialHeaders_LogsHeaders) { |
3846 MockHttpCache cache; | 3846 MockHttpCache cache; |
3847 | 3847 |
3848 net::CapturingBoundNetLog log; | 3848 net::BoundTestNetLog log; |
3849 MockTransaction transaction(kSimpleGET_Transaction); | 3849 MockTransaction transaction(kSimpleGET_Transaction); |
3850 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; | 3850 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; |
3851 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 3851 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
3852 | 3852 |
3853 EXPECT_TRUE(LogContainsEventType( | 3853 EXPECT_TRUE(LogContainsEventType( |
3854 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); | 3854 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
3855 } | 3855 } |
3856 | 3856 |
3857 // Tests that receiving 206 for a regular request is handled correctly. | 3857 // Tests that receiving 206 for a regular request is handled correctly. |
3858 TEST(HttpCache, GET_Crazy206) { | 3858 TEST(HttpCache, GET_Crazy206) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3955 MockHttpCache cache; | 3955 MockHttpCache cache; |
3956 cache.FailConditionalizations(); | 3956 cache.FailConditionalizations(); |
3957 | 3957 |
3958 // Write to the cache (40-49). | 3958 // Write to the cache (40-49). |
3959 ScopedMockTransaction transaction(kRangeGET_TransactionOK); | 3959 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
3960 transaction.response_headers = "Content-Length: 10\n" | 3960 transaction.response_headers = "Content-Length: 10\n" |
3961 "ETag: \"foo\"\n"; | 3961 "ETag: \"foo\"\n"; |
3962 RunTransactionTest(cache.http_cache(), transaction); | 3962 RunTransactionTest(cache.http_cache(), transaction); |
3963 | 3963 |
3964 // Now verify that the cached data is not used. | 3964 // Now verify that the cached data is not used. |
3965 net::CapturingBoundNetLog log; | 3965 net::BoundTestNetLog log; |
3966 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, | 3966 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, |
3967 log.bound()); | 3967 log.bound()); |
3968 | 3968 |
3969 EXPECT_TRUE(LogContainsEventType( | 3969 EXPECT_TRUE(LogContainsEventType( |
3970 log, net::NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST)); | 3970 log, net::NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST)); |
3971 } | 3971 } |
3972 | 3972 |
3973 // Tests that a failure to conditionalize a regular request (no range) with a | 3973 // Tests that a failure to conditionalize a regular request (no range) with a |
3974 // sparse entry results in a full response. | 3974 // sparse entry results in a full response. |
3975 TEST(HttpCache, GET_NoConditionalization) { | 3975 TEST(HttpCache, GET_NoConditionalization) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4117 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4117 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
4118 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 4118 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
4119 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4119 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4120 | 4120 |
4121 // Make sure we are done with the previous transaction. | 4121 // Make sure we are done with the previous transaction. |
4122 base::MessageLoop::current()->RunUntilIdle(); | 4122 base::MessageLoop::current()->RunUntilIdle(); |
4123 | 4123 |
4124 // Write and read from the cache (20-59). | 4124 // Write and read from the cache (20-59). |
4125 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 4125 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
4126 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 4126 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
4127 net::CapturingBoundNetLog log; | 4127 net::BoundTestNetLog log; |
4128 net::LoadTimingInfo load_timing_info; | 4128 net::LoadTimingInfo load_timing_info; |
4129 RunTransactionTestWithResponseAndGetTiming( | 4129 RunTransactionTestWithResponseAndGetTiming( |
4130 cache.http_cache(), transaction, &headers, log.bound(), | 4130 cache.http_cache(), transaction, &headers, log.bound(), |
4131 &load_timing_info); | 4131 &load_timing_info); |
4132 | 4132 |
4133 Verify206Response(headers, 20, 59); | 4133 Verify206Response(headers, 20, 59); |
4134 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 4134 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
4135 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 4135 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
4136 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4136 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4137 TestLoadTimingNetworkRequest(load_timing_info); | 4137 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4177 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4177 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
4178 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4178 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4179 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4179 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4180 | 4180 |
4181 // Make sure we are done with the previous transaction. | 4181 // Make sure we are done with the previous transaction. |
4182 base::MessageLoop::current()->RunUntilIdle(); | 4182 base::MessageLoop::current()->RunUntilIdle(); |
4183 | 4183 |
4184 // Write and read from the cache (20-59). | 4184 // Write and read from the cache (20-59). |
4185 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 4185 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
4186 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 4186 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
4187 net::CapturingBoundNetLog log; | 4187 net::BoundTestNetLog log; |
4188 net::LoadTimingInfo load_timing_info; | 4188 net::LoadTimingInfo load_timing_info; |
4189 RunTransactionTestWithResponseAndGetTiming( | 4189 RunTransactionTestWithResponseAndGetTiming( |
4190 cache.http_cache(), transaction, &headers, log.bound(), | 4190 cache.http_cache(), transaction, &headers, log.bound(), |
4191 &load_timing_info); | 4191 &load_timing_info); |
4192 | 4192 |
4193 Verify206Response(headers, 20, 59); | 4193 Verify206Response(headers, 20, 59); |
4194 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 4194 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
4195 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 4195 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
4196 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4196 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4197 TestLoadTimingNetworkRequest(load_timing_info); | 4197 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 16 matching lines...) Expand all Loading... |
4214 "Content-Length: 10\n"; | 4214 "Content-Length: 10\n"; |
4215 AddMockTransaction(&transaction); | 4215 AddMockTransaction(&transaction); |
4216 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4216 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
4217 | 4217 |
4218 Verify206Response(headers, 40, 49); | 4218 Verify206Response(headers, 40, 49); |
4219 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4219 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4220 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4220 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
4221 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4221 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4222 | 4222 |
4223 // Read from the cache (40-49). | 4223 // Read from the cache (40-49). |
4224 net::CapturingBoundNetLog log; | 4224 net::BoundTestNetLog log; |
4225 net::LoadTimingInfo load_timing_info; | 4225 net::LoadTimingInfo load_timing_info; |
4226 RunTransactionTestWithResponseAndGetTiming( | 4226 RunTransactionTestWithResponseAndGetTiming( |
4227 cache.http_cache(), transaction, &headers, log.bound(), | 4227 cache.http_cache(), transaction, &headers, log.bound(), |
4228 &load_timing_info); | 4228 &load_timing_info); |
4229 | 4229 |
4230 Verify206Response(headers, 40, 49); | 4230 Verify206Response(headers, 40, 49); |
4231 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4231 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4232 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4232 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4233 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4233 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4234 TestLoadTimingCachedResponse(load_timing_info); | 4234 TestLoadTimingCachedResponse(load_timing_info); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4713 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4713 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
4714 | 4714 |
4715 RemoveMockTransaction(&transaction); | 4715 RemoveMockTransaction(&transaction); |
4716 } | 4716 } |
4717 | 4717 |
4718 // Tests that we can handle non-range requests when we have cached a range. | 4718 // Tests that we can handle non-range requests when we have cached a range. |
4719 TEST(HttpCache, GET_Previous206) { | 4719 TEST(HttpCache, GET_Previous206) { |
4720 MockHttpCache cache; | 4720 MockHttpCache cache; |
4721 AddMockTransaction(&kRangeGET_TransactionOK); | 4721 AddMockTransaction(&kRangeGET_TransactionOK); |
4722 std::string headers; | 4722 std::string headers; |
4723 net::CapturingBoundNetLog log; | 4723 net::BoundTestNetLog log; |
4724 net::LoadTimingInfo load_timing_info; | 4724 net::LoadTimingInfo load_timing_info; |
4725 | 4725 |
4726 // Write to the cache (40-49). | 4726 // Write to the cache (40-49). |
4727 RunTransactionTestWithResponseAndGetTiming( | 4727 RunTransactionTestWithResponseAndGetTiming( |
4728 cache.http_cache(), kRangeGET_TransactionOK, &headers, log.bound(), | 4728 cache.http_cache(), kRangeGET_TransactionOK, &headers, log.bound(), |
4729 &load_timing_info); | 4729 &load_timing_info); |
4730 | 4730 |
4731 Verify206Response(headers, 40, 49); | 4731 Verify206Response(headers, 40, 49); |
4732 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4732 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4733 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4733 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 18 matching lines...) Expand all Loading... |
4752 } | 4752 } |
4753 | 4753 |
4754 // Tests that we can handle non-range requests when we have cached the first | 4754 // Tests that we can handle non-range requests when we have cached the first |
4755 // part of the object and the server replies with 304 (Not Modified). | 4755 // part of the object and the server replies with 304 (Not Modified). |
4756 TEST(HttpCache, GET_Previous206_NotModified) { | 4756 TEST(HttpCache, GET_Previous206_NotModified) { |
4757 MockHttpCache cache; | 4757 MockHttpCache cache; |
4758 | 4758 |
4759 MockTransaction transaction(kRangeGET_TransactionOK); | 4759 MockTransaction transaction(kRangeGET_TransactionOK); |
4760 AddMockTransaction(&transaction); | 4760 AddMockTransaction(&transaction); |
4761 std::string headers; | 4761 std::string headers; |
4762 net::CapturingBoundNetLog log; | 4762 net::BoundTestNetLog log; |
4763 net::LoadTimingInfo load_timing_info; | 4763 net::LoadTimingInfo load_timing_info; |
4764 | 4764 |
4765 // Write to the cache (0-9). | 4765 // Write to the cache (0-9). |
4766 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | 4766 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; |
4767 transaction.data = "rg: 00-09 "; | 4767 transaction.data = "rg: 00-09 "; |
4768 RunTransactionTestWithResponseAndGetTiming( | 4768 RunTransactionTestWithResponseAndGetTiming( |
4769 cache.http_cache(), transaction, &headers, log.bound(), | 4769 cache.http_cache(), transaction, &headers, log.bound(), |
4770 &load_timing_info); | 4770 &load_timing_info); |
4771 Verify206Response(headers, 0, 9); | 4771 Verify206Response(headers, 0, 9); |
4772 TestLoadTimingNetworkRequest(load_timing_info); | 4772 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4822 // Now we'll issue a request without any range that should result first in a | 4822 // Now we'll issue a request without any range that should result first in a |
4823 // 206 (when revalidating), and then in a weird standard answer: the test | 4823 // 206 (when revalidating), and then in a weird standard answer: the test |
4824 // server will not modify the response so we'll get the default range... a | 4824 // server will not modify the response so we'll get the default range... a |
4825 // real server will answer with 200. | 4825 // real server will answer with 200. |
4826 MockTransaction transaction2(kRangeGET_TransactionOK); | 4826 MockTransaction transaction2(kRangeGET_TransactionOK); |
4827 transaction2.request_headers = EXTRA_HEADER; | 4827 transaction2.request_headers = EXTRA_HEADER; |
4828 transaction2.load_flags |= net::LOAD_VALIDATE_CACHE; | 4828 transaction2.load_flags |= net::LOAD_VALIDATE_CACHE; |
4829 transaction2.data = "Not a range"; | 4829 transaction2.data = "Not a range"; |
4830 RangeTransactionServer handler; | 4830 RangeTransactionServer handler; |
4831 handler.set_modified(true); | 4831 handler.set_modified(true); |
4832 net::CapturingBoundNetLog log; | 4832 net::BoundTestNetLog log; |
4833 net::LoadTimingInfo load_timing_info; | 4833 net::LoadTimingInfo load_timing_info; |
4834 RunTransactionTestWithResponseAndGetTiming( | 4834 RunTransactionTestWithResponseAndGetTiming( |
4835 cache.http_cache(), transaction2, &headers, log.bound(), | 4835 cache.http_cache(), transaction2, &headers, log.bound(), |
4836 &load_timing_info); | 4836 &load_timing_info); |
4837 | 4837 |
4838 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 4838 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
4839 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4839 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4840 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4840 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4841 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4841 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4842 TestLoadTimingNetworkRequest(load_timing_info); | 4842 TestLoadTimingNetworkRequest(load_timing_info); |
(...skipping 27 matching lines...) Expand all Loading... |
4870 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 4870 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
4871 int len = static_cast<int>(base::strlcpy(buf->data(), | 4871 int len = static_cast<int>(base::strlcpy(buf->data(), |
4872 kRangeGET_TransactionOK.data, 500)); | 4872 kRangeGET_TransactionOK.data, 500)); |
4873 net::TestCompletionCallback cb; | 4873 net::TestCompletionCallback cb; |
4874 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); | 4874 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
4875 EXPECT_EQ(len, cb.GetResult(rv)); | 4875 EXPECT_EQ(len, cb.GetResult(rv)); |
4876 entry->Close(); | 4876 entry->Close(); |
4877 | 4877 |
4878 // Now see that we don't use the stored entry. | 4878 // Now see that we don't use the stored entry. |
4879 std::string headers; | 4879 std::string headers; |
4880 net::CapturingBoundNetLog log; | 4880 net::BoundTestNetLog log; |
4881 net::LoadTimingInfo load_timing_info; | 4881 net::LoadTimingInfo load_timing_info; |
4882 RunTransactionTestWithResponseAndGetTiming( | 4882 RunTransactionTestWithResponseAndGetTiming( |
4883 cache.http_cache(), kSimpleGET_Transaction, &headers, log.bound(), | 4883 cache.http_cache(), kSimpleGET_Transaction, &headers, log.bound(), |
4884 &load_timing_info); | 4884 &load_timing_info); |
4885 | 4885 |
4886 // We are expecting a 200. | 4886 // We are expecting a 200. |
4887 std::string expected_headers(kSimpleGET_Transaction.status); | 4887 std::string expected_headers(kSimpleGET_Transaction.status); |
4888 expected_headers.append("\n"); | 4888 expected_headers.append("\n"); |
4889 expected_headers.append(kSimpleGET_Transaction.response_headers); | 4889 expected_headers.append(kSimpleGET_Transaction.response_headers); |
4890 EXPECT_EQ(expected_headers, headers); | 4890 EXPECT_EQ(expected_headers, headers); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5438 transaction.test_mode = TEST_MODE_SYNC_NET_START; | 5438 transaction.test_mode = TEST_MODE_SYNC_NET_START; |
5439 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 5439 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
5440 | 5440 |
5441 // Write to the cache. | 5441 // Write to the cache. |
5442 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 5442 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
5443 | 5443 |
5444 // And now read from the cache and the network. | 5444 // And now read from the cache and the network. |
5445 RangeTransactionServer handler; | 5445 RangeTransactionServer handler; |
5446 handler.set_bad_200(true); | 5446 handler.set_bad_200(true); |
5447 transaction.data = "Not a range"; | 5447 transaction.data = "Not a range"; |
5448 net::CapturingBoundNetLog log; | 5448 net::BoundTestNetLog log; |
5449 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 5449 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
5450 | 5450 |
5451 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 5451 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
5452 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5452 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
5453 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5453 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
5454 EXPECT_TRUE(LogContainsEventType( | 5454 EXPECT_TRUE(LogContainsEventType( |
5455 log, net::NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)); | 5455 log, net::NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)); |
5456 } | 5456 } |
5457 | 5457 |
5458 // Tests that when the server gives us less data than expected, we don't keep | 5458 // Tests that when the server gives us less data than expected, we don't keep |
(...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7917 | 7917 |
7918 // Here the second transaction proceeds without reading the first body. | 7918 // Here the second transaction proceeds without reading the first body. |
7919 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7919 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
7920 base::MessageLoop::current()->RunUntilIdle(); | 7920 base::MessageLoop::current()->RunUntilIdle(); |
7921 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7921 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); |
7922 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7922 ASSERT_TRUE(second->trans->GetResponseInfo()); |
7923 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7923 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
7924 "Cache-Control", "no-store")); | 7924 "Cache-Control", "no-store")); |
7925 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7925 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
7926 } | 7926 } |
OLD | NEW |