| 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 16 matching lines...) Expand all Loading... |
| 27 #include "net/http/http_byte_range.h" | 27 #include "net/http/http_byte_range.h" |
| 28 #include "net/http/http_cache_transaction.h" | 28 #include "net/http/http_cache_transaction.h" |
| 29 #include "net/http/http_request_headers.h" | 29 #include "net/http/http_request_headers.h" |
| 30 #include "net/http/http_request_info.h" | 30 #include "net/http/http_request_info.h" |
| 31 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_response_info.h" | 32 #include "net/http/http_response_info.h" |
| 33 #include "net/http/http_transaction.h" | 33 #include "net/http/http_transaction.h" |
| 34 #include "net/http/http_transaction_test_util.h" | 34 #include "net/http/http_transaction_test_util.h" |
| 35 #include "net/http/http_util.h" | 35 #include "net/http/http_util.h" |
| 36 #include "net/http/mock_http_cache.h" | 36 #include "net/http/mock_http_cache.h" |
| 37 #include "net/log/captured_net_log_entry.h" |
| 37 #include "net/log/net_log_unittest.h" | 38 #include "net/log/net_log_unittest.h" |
| 39 #include "net/log/test_net_log.h" |
| 38 #include "net/socket/client_socket_handle.h" | 40 #include "net/socket/client_socket_handle.h" |
| 39 #include "net/ssl/ssl_cert_request_info.h" | 41 #include "net/ssl/ssl_cert_request_info.h" |
| 40 #include "net/websockets/websocket_handshake_stream_base.h" | 42 #include "net/websockets/websocket_handshake_stream_base.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 44 |
| 43 using base::Time; | 45 using base::Time; |
| 44 | 46 |
| 45 namespace net { | 47 namespace net { |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 WebSocketHandshakeStreamBase* CreateSpdyStream( | 527 WebSocketHandshakeStreamBase* CreateSpdyStream( |
| 526 const base::WeakPtr<SpdySession>& session, | 528 const base::WeakPtr<SpdySession>& session, |
| 527 bool use_relative_url) override { | 529 bool use_relative_url) override { |
| 528 return NULL; | 530 return NULL; |
| 529 } | 531 } |
| 530 }; | 532 }; |
| 531 | 533 |
| 532 // 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 |
| 533 // 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 |
| 534 // ignored. | 536 // ignored. |
| 535 bool ShouldIgnoreLogEntry(const TestNetLog::CapturedEntry& entry) { | 537 bool ShouldIgnoreLogEntry(const CapturedNetLogEntry& entry) { |
| 536 switch (entry.type) { | 538 switch (entry.type) { |
| 537 case NetLog::TYPE_HTTP_CACHE_GET_BACKEND: | 539 case NetLog::TYPE_HTTP_CACHE_GET_BACKEND: |
| 538 case NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: | 540 case NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: |
| 539 case NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: | 541 case NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: |
| 540 case NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: | 542 case NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: |
| 541 case NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: | 543 case NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: |
| 542 case NetLog::TYPE_HTTP_CACHE_READ_INFO: | 544 case NetLog::TYPE_HTTP_CACHE_READ_INFO: |
| 543 return false; | 545 return false; |
| 544 default: | 546 default: |
| 545 return true; | 547 return true; |
| 546 } | 548 } |
| 547 } | 549 } |
| 548 | 550 |
| 549 // 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 |
| 550 // asserted on in these tests. | 552 // asserted on in these tests. |
| 551 void FilterLogEntries(TestNetLog::CapturedEntryList* entries) { | 553 void FilterLogEntries(CapturedNetLogEntry::List* entries) { |
| 552 entries->erase(std::remove_if(entries->begin(), entries->end(), | 554 entries->erase(std::remove_if(entries->begin(), entries->end(), |
| 553 &ShouldIgnoreLogEntry), | 555 &ShouldIgnoreLogEntry), |
| 554 entries->end()); | 556 entries->end()); |
| 555 } | 557 } |
| 556 | 558 |
| 557 bool LogContainsEventType(const BoundTestNetLog& log, | 559 bool LogContainsEventType(const BoundTestNetLog& log, |
| 558 NetLog::EventType expected) { | 560 NetLog::EventType expected) { |
| 559 TestNetLog::CapturedEntryList entries; | 561 CapturedNetLogEntry::List entries; |
| 560 log.GetEntries(&entries); | 562 log.GetEntries(&entries); |
| 561 for (size_t i = 0; i < entries.size(); i++) { | 563 for (size_t i = 0; i < entries.size(); i++) { |
| 562 if (entries[i].type == expected) | 564 if (entries[i].type == expected) |
| 563 return true; | 565 return true; |
| 564 } | 566 } |
| 565 return false; | 567 return false; |
| 566 } | 568 } |
| 567 | 569 |
| 568 } // namespace | 570 } // namespace |
| 569 | 571 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 613 |
| 612 BoundTestNetLog log; | 614 BoundTestNetLog log; |
| 613 LoadTimingInfo load_timing_info; | 615 LoadTimingInfo load_timing_info; |
| 614 | 616 |
| 615 // Read from the network, and don't use the cache. | 617 // Read from the network, and don't use the cache. |
| 616 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 618 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
| 617 log.bound(), &load_timing_info); | 619 log.bound(), &load_timing_info); |
| 618 | 620 |
| 619 // Check that the NetLog was filled as expected. | 621 // Check that the NetLog was filled as expected. |
| 620 // (We attempted to both Open and Create entries, but both failed). | 622 // (We attempted to both Open and Create entries, but both failed). |
| 621 TestNetLog::CapturedEntryList entries; | 623 CapturedNetLogEntry::List entries; |
| 622 log.GetEntries(&entries); | 624 log.GetEntries(&entries); |
| 623 FilterLogEntries(&entries); | 625 FilterLogEntries(&entries); |
| 624 | 626 |
| 625 EXPECT_EQ(6u, entries.size()); | 627 EXPECT_EQ(6u, entries.size()); |
| 626 EXPECT_TRUE( | 628 EXPECT_TRUE( |
| 627 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 629 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
| 628 EXPECT_TRUE( | 630 EXPECT_TRUE( |
| 629 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 631 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
| 630 EXPECT_TRUE( | 632 EXPECT_TRUE( |
| 631 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 633 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 MockHttpCache cache; | 778 MockHttpCache cache; |
| 777 | 779 |
| 778 BoundTestNetLog log; | 780 BoundTestNetLog log; |
| 779 LoadTimingInfo load_timing_info; | 781 LoadTimingInfo load_timing_info; |
| 780 | 782 |
| 781 // Write to the cache. | 783 // Write to the cache. |
| 782 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 784 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, |
| 783 log.bound(), &load_timing_info); | 785 log.bound(), &load_timing_info); |
| 784 | 786 |
| 785 // Check that the NetLog was filled as expected. | 787 // Check that the NetLog was filled as expected. |
| 786 TestNetLog::CapturedEntryList entries; | 788 CapturedNetLogEntry::List entries; |
| 787 log.GetEntries(&entries); | 789 log.GetEntries(&entries); |
| 788 FilterLogEntries(&entries); | 790 FilterLogEntries(&entries); |
| 789 | 791 |
| 790 EXPECT_EQ(8u, entries.size()); | 792 EXPECT_EQ(8u, entries.size()); |
| 791 EXPECT_TRUE( | 793 EXPECT_TRUE( |
| 792 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 794 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
| 793 EXPECT_TRUE( | 795 EXPECT_TRUE( |
| 794 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 796 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
| 795 EXPECT_TRUE( | 797 EXPECT_TRUE( |
| 796 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 798 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 transaction.load_flags |= LOAD_BYPASS_CACHE; | 1136 transaction.load_flags |= LOAD_BYPASS_CACHE; |
| 1135 | 1137 |
| 1136 BoundTestNetLog log; | 1138 BoundTestNetLog log; |
| 1137 LoadTimingInfo load_timing_info; | 1139 LoadTimingInfo load_timing_info; |
| 1138 | 1140 |
| 1139 // Write to the cache. | 1141 // Write to the cache. |
| 1140 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 1142 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), |
| 1141 &load_timing_info); | 1143 &load_timing_info); |
| 1142 | 1144 |
| 1143 // Check that the NetLog was filled as expected. | 1145 // Check that the NetLog was filled as expected. |
| 1144 TestNetLog::CapturedEntryList entries; | 1146 CapturedNetLogEntry::List entries; |
| 1145 log.GetEntries(&entries); | 1147 log.GetEntries(&entries); |
| 1146 FilterLogEntries(&entries); | 1148 FilterLogEntries(&entries); |
| 1147 | 1149 |
| 1148 EXPECT_EQ(8u, entries.size()); | 1150 EXPECT_EQ(8u, entries.size()); |
| 1149 EXPECT_TRUE( | 1151 EXPECT_TRUE( |
| 1150 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1152 LogContainsBeginEvent(entries, 0, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
| 1151 EXPECT_TRUE( | 1153 EXPECT_TRUE( |
| 1152 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1154 LogContainsEndEvent(entries, 1, NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
| 1153 EXPECT_TRUE( | 1155 EXPECT_TRUE( |
| 1154 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); | 1156 LogContainsBeginEvent(entries, 2, NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); |
| (...skipping 6744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7899 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7901 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
| 7900 base::MessageLoop::current()->RunUntilIdle(); | 7902 base::MessageLoop::current()->RunUntilIdle(); |
| 7901 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7903 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7902 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7904 ASSERT_TRUE(second->trans->GetResponseInfo()); |
| 7903 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7905 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7904 "Cache-Control", "no-store")); | 7906 "Cache-Control", "no-store")); |
| 7905 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7907 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
| 7906 } | 7908 } |
| 7907 | 7909 |
| 7908 } // namespace net | 7910 } // namespace net |
| OLD | NEW |