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

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

Issue 1084533002: Rename NetLogLogger and CapturingNetLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 <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
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::CapturingBoundNetLog& 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 613
614 net::CapturingBoundNetLog log; 614 net::CapturingBoundNetLog 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 MockHttpCache cache; 778 MockHttpCache cache;
779 779
780 net::CapturingBoundNetLog log; 780 net::CapturingBoundNetLog 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 transaction.load_flags |= net::LOAD_BYPASS_CACHE; 1136 transaction.load_flags |= net::LOAD_BYPASS_CACHE;
1137 1137
1138 net::CapturingBoundNetLog log; 1138 net::CapturingBoundNetLog 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 6760 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698