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

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

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_network_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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 "base/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "net/base/cache_type.h" 11 #include "net/base/cache_type.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
14 #include "net/base/load_log_unittest.h" 14 #include "net/base/net_log_unittest.h"
15 #include "net/base/ssl_cert_request_info.h" 15 #include "net/base/ssl_cert_request_info.h"
16 #include "net/disk_cache/disk_cache.h" 16 #include "net/disk_cache/disk_cache.h"
17 #include "net/http/http_byte_range.h" 17 #include "net/http/http_byte_range.h"
18 #include "net/http/http_request_info.h" 18 #include "net/http/http_request_info.h"
19 #include "net/http/http_response_headers.h" 19 #include "net/http/http_response_headers.h"
20 #include "net/http/http_response_info.h" 20 #include "net/http/http_response_info.h"
21 #include "net/http/http_transaction.h" 21 #include "net/http/http_transaction.h"
22 #include "net/http/http_transaction_unittest.h" 22 #include "net/http/http_transaction_unittest.h"
23 #include "net/http/http_util.h" 23 #include "net/http/http_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 578
579 EXPECT_EQ(net::OK, rv); 579 EXPECT_EQ(net::OK, rv);
580 std::string expected(trans_info.data); 580 std::string expected(trans_info.data);
581 EXPECT_EQ(expected, content); 581 EXPECT_EQ(expected, content);
582 } 582 }
583 583
584 void RunTransactionTestWithRequestAndLog(net::HttpCache* cache, 584 void RunTransactionTestWithRequestAndLog(net::HttpCache* cache,
585 const MockTransaction& trans_info, 585 const MockTransaction& trans_info,
586 const MockHttpRequest& request, 586 const MockHttpRequest& request,
587 net::HttpResponseInfo* response_info, 587 net::HttpResponseInfo* response_info,
588 net::LoadLog* load_log) { 588 const net::BoundNetLog& net_log) {
589 TestCompletionCallback callback; 589 TestCompletionCallback callback;
590 590
591 // write to the cache 591 // write to the cache
592 592
593 scoped_ptr<net::HttpTransaction> trans; 593 scoped_ptr<net::HttpTransaction> trans;
594 int rv = cache->CreateTransaction(&trans); 594 int rv = cache->CreateTransaction(&trans);
595 EXPECT_EQ(net::OK, rv); 595 EXPECT_EQ(net::OK, rv);
596 ASSERT_TRUE(trans.get()); 596 ASSERT_TRUE(trans.get());
597 597
598 rv = trans->Start(&request, &callback, load_log); 598 rv = trans->Start(&request, &callback, net_log);
599 if (rv == net::ERR_IO_PENDING) 599 if (rv == net::ERR_IO_PENDING)
600 rv = callback.WaitForResult(); 600 rv = callback.WaitForResult();
601 ASSERT_EQ(net::OK, rv); 601 ASSERT_EQ(net::OK, rv);
602 602
603 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 603 const net::HttpResponseInfo* response = trans->GetResponseInfo();
604 ASSERT_TRUE(response); 604 ASSERT_TRUE(response);
605 605
606 if (response_info) 606 if (response_info)
607 *response_info = *response; 607 *response_info = *response;
608 608
609 ReadAndVerifyTransaction(trans.get(), trans_info); 609 ReadAndVerifyTransaction(trans.get(), trans_info);
610 } 610 }
611 611
612 void RunTransactionTestWithRequest(net::HttpCache* cache, 612 void RunTransactionTestWithRequest(net::HttpCache* cache,
613 const MockTransaction& trans_info, 613 const MockTransaction& trans_info,
614 const MockHttpRequest& request, 614 const MockHttpRequest& request,
615 net::HttpResponseInfo* response_info) { 615 net::HttpResponseInfo* response_info) {
616 RunTransactionTestWithRequestAndLog(cache, trans_info, request, 616 RunTransactionTestWithRequestAndLog(cache, trans_info, request,
617 response_info, NULL); 617 response_info, NULL);
618 } 618 }
619 619
620 void RunTransactionTestWithLog(net::HttpCache* cache, 620 void RunTransactionTestWithLog(net::HttpCache* cache,
621 const MockTransaction& trans_info, 621 const MockTransaction& trans_info,
622 net::LoadLog* log) { 622 const net::BoundNetLog& log) {
623 RunTransactionTestWithRequestAndLog( 623 RunTransactionTestWithRequestAndLog(
624 cache, trans_info, MockHttpRequest(trans_info), NULL, log); 624 cache, trans_info, MockHttpRequest(trans_info), NULL, log);
625 } 625 }
626 626
627 void RunTransactionTest(net::HttpCache* cache, 627 void RunTransactionTest(net::HttpCache* cache,
628 const MockTransaction& trans_info) { 628 const MockTransaction& trans_info) {
629 RunTransactionTestWithLog(cache, trans_info, NULL); 629 RunTransactionTestWithLog(cache, trans_info, NULL);
630 } 630 }
631 631
632 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, 632 void RunTransactionTestWithResponseInfo(net::HttpCache* cache,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 906 EXPECT_EQ(1, cache.network_layer()->transaction_count());
907 EXPECT_EQ(0, cache.disk_cache()->open_count()); 907 EXPECT_EQ(0, cache.disk_cache()->open_count());
908 EXPECT_EQ(1, cache.disk_cache()->create_count()); 908 EXPECT_EQ(1, cache.disk_cache()->create_count());
909 } 909 }
910 910
911 TEST(HttpCache, SimpleGETNoDiskCache) { 911 TEST(HttpCache, SimpleGETNoDiskCache) {
912 MockHttpCache cache; 912 MockHttpCache cache;
913 913
914 cache.disk_cache()->set_fail_requests(); 914 cache.disk_cache()->set_fail_requests();
915 915
916 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 916 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
917 917
918 // Read from the network, and don't use the cache. 918 // Read from the network, and don't use the cache.
919 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); 919 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction,
920 log.bound());
920 921
921 // Check that the LoadLog was filled as expected. 922 // Check that the NetLog was filled as expected.
922 // (We attempted to both Open and Create entries, but both failed). 923 // (We attempted to both Open and Create entries, but both failed).
923 EXPECT_EQ(4u, log->entries().size()); 924 EXPECT_EQ(4u, log.entries().size());
924 EXPECT_TRUE(net::LogContainsBeginEvent( 925 EXPECT_TRUE(net::LogContainsBeginEvent(
925 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 926 log.entries(), 0, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
926 EXPECT_TRUE(net::LogContainsEndEvent( 927 EXPECT_TRUE(net::LogContainsEndEvent(
927 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 928 log.entries(), 1, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
928 EXPECT_TRUE(net::LogContainsBeginEvent( 929 EXPECT_TRUE(net::LogContainsBeginEvent(
929 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 930 log.entries(), 2, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
930 EXPECT_TRUE(net::LogContainsEndEvent( 931 EXPECT_TRUE(net::LogContainsEndEvent(
931 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 932 log.entries(), 3, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
932 933
933 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 934 EXPECT_EQ(1, cache.network_layer()->transaction_count());
934 EXPECT_EQ(0, cache.disk_cache()->open_count()); 935 EXPECT_EQ(0, cache.disk_cache()->open_count());
935 EXPECT_EQ(0, cache.disk_cache()->create_count()); 936 EXPECT_EQ(0, cache.disk_cache()->create_count());
936 } 937 }
937 938
938 TEST(HttpCache, SimpleGETWithDiskFailures) { 939 TEST(HttpCache, SimpleGETWithDiskFailures) {
939 MockHttpCache cache; 940 MockHttpCache cache;
940 941
941 cache.disk_cache()->set_soft_failures(true); 942 cache.disk_cache()->set_soft_failures(true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 991 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
991 992
992 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 993 EXPECT_EQ(2, cache.network_layer()->transaction_count());
993 EXPECT_EQ(1, cache.disk_cache()->open_count()); 994 EXPECT_EQ(1, cache.disk_cache()->open_count());
994 EXPECT_EQ(2, cache.disk_cache()->create_count()); 995 EXPECT_EQ(2, cache.disk_cache()->create_count());
995 } 996 }
996 997
997 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { 998 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
998 MockHttpCache cache; 999 MockHttpCache cache;
999 1000
1000 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 1001 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
1001 1002
1002 // write to the cache 1003 // write to the cache
1003 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); 1004 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction,
1005 log.bound());
1004 1006
1005 // Check that the LoadLog was filled as expected. 1007 // Check that the NetLog was filled as expected.
1006 EXPECT_EQ(6u, log->entries().size()); 1008 EXPECT_EQ(6u, log.entries().size());
1007 EXPECT_TRUE(net::LogContainsBeginEvent( 1009 EXPECT_TRUE(net::LogContainsBeginEvent(
1008 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 1010 log.entries(), 0, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
1009 EXPECT_TRUE(net::LogContainsEndEvent( 1011 EXPECT_TRUE(net::LogContainsEndEvent(
1010 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 1012 log.entries(), 1, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
1011 EXPECT_TRUE(net::LogContainsBeginEvent( 1013 EXPECT_TRUE(net::LogContainsBeginEvent(
1012 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1014 log.entries(), 2, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
1013 EXPECT_TRUE(net::LogContainsEndEvent( 1015 EXPECT_TRUE(net::LogContainsEndEvent(
1014 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1016 log.entries(), 3, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
1015 EXPECT_TRUE(net::LogContainsBeginEvent( 1017 EXPECT_TRUE(net::LogContainsBeginEvent(
1016 *log, 4, net::LoadLog::TYPE_HTTP_CACHE_WAITING)); 1018 log.entries(), 4, net::NetLog::TYPE_HTTP_CACHE_WAITING));
1017 EXPECT_TRUE(net::LogContainsEndEvent( 1019 EXPECT_TRUE(net::LogContainsEndEvent(
1018 *log, 5, net::LoadLog::TYPE_HTTP_CACHE_WAITING)); 1020 log.entries(), 5, net::NetLog::TYPE_HTTP_CACHE_WAITING));
1019 1021
1020 // force this transaction to read from the cache 1022 // force this transaction to read from the cache
1021 MockTransaction transaction(kSimpleGET_Transaction); 1023 MockTransaction transaction(kSimpleGET_Transaction);
1022 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 1024 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
1023 1025
1024 log = new net::LoadLog(net::LoadLog::kUnbounded); 1026 log.Clear();
1025 1027
1026 RunTransactionTestWithLog(cache.http_cache(), transaction, log); 1028 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound());
1027 1029
1028 // Check that the LoadLog was filled as expected. 1030 // Check that the NetLog was filled as expected.
1029 EXPECT_EQ(6u, log->entries().size()); 1031 EXPECT_EQ(6u, log.entries().size());
1030 EXPECT_TRUE(net::LogContainsBeginEvent( 1032 EXPECT_TRUE(net::LogContainsBeginEvent(
1031 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 1033 log.entries(), 0, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
1032 EXPECT_TRUE(net::LogContainsEndEvent( 1034 EXPECT_TRUE(net::LogContainsEndEvent(
1033 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 1035 log.entries(), 1, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
1034 EXPECT_TRUE(net::LogContainsBeginEvent( 1036 EXPECT_TRUE(net::LogContainsBeginEvent(
1035 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_WAITING)); 1037 log.entries(), 2, net::NetLog::TYPE_HTTP_CACHE_WAITING));
1036 EXPECT_TRUE(net::LogContainsEndEvent( 1038 EXPECT_TRUE(net::LogContainsEndEvent(
1037 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_WAITING)); 1039 log.entries(), 3, net::NetLog::TYPE_HTTP_CACHE_WAITING));
1038 EXPECT_TRUE(net::LogContainsBeginEvent( 1040 EXPECT_TRUE(net::LogContainsBeginEvent(
1039 *log, 4, net::LoadLog::TYPE_HTTP_CACHE_READ_INFO)); 1041 log.entries(), 4, net::NetLog::TYPE_HTTP_CACHE_READ_INFO));
1040 EXPECT_TRUE(net::LogContainsEndEvent( 1042 EXPECT_TRUE(net::LogContainsEndEvent(
1041 *log, 5, net::LoadLog::TYPE_HTTP_CACHE_READ_INFO)); 1043 log.entries(), 5, net::NetLog::TYPE_HTTP_CACHE_READ_INFO));
1042 1044
1043 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1045 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1044 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1046 EXPECT_EQ(1, cache.disk_cache()->open_count());
1045 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1047 EXPECT_EQ(1, cache.disk_cache()->create_count());
1046 } 1048 }
1047 1049
1048 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { 1050 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
1049 MockHttpCache cache; 1051 MockHttpCache cache;
1050 1052
1051 // force this transaction to read from the cache 1053 // force this transaction to read from the cache
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 TEST(HttpCache, SimpleGET_LoadBypassCache) { 1108 TEST(HttpCache, SimpleGET_LoadBypassCache) {
1107 MockHttpCache cache; 1109 MockHttpCache cache;
1108 1110
1109 // Write to the cache. 1111 // Write to the cache.
1110 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1112 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1111 1113
1112 // Force this transaction to write to the cache again. 1114 // Force this transaction to write to the cache again.
1113 MockTransaction transaction(kSimpleGET_Transaction); 1115 MockTransaction transaction(kSimpleGET_Transaction);
1114 transaction.load_flags |= net::LOAD_BYPASS_CACHE; 1116 transaction.load_flags |= net::LOAD_BYPASS_CACHE;
1115 1117
1116 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 1118 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
1117 1119
1118 RunTransactionTestWithLog(cache.http_cache(), transaction, log); 1120 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound());
1119 1121
1120 // Check that the LoadLog was filled as expected. 1122 // Check that the NetLog was filled as expected.
1121 EXPECT_EQ(6u, log->entries().size()); 1123 EXPECT_EQ(6u, log.entries().size());
1122 EXPECT_TRUE(net::LogContainsBeginEvent( 1124 EXPECT_TRUE(net::LogContainsBeginEvent(
1123 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); 1125 log.entries(), 0, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY));
1124 EXPECT_TRUE(net::LogContainsEndEvent( 1126 EXPECT_TRUE(net::LogContainsEndEvent(
1125 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); 1127 log.entries(), 1, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY));
1126 EXPECT_TRUE(net::LogContainsBeginEvent( 1128 EXPECT_TRUE(net::LogContainsBeginEvent(
1127 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1129 log.entries(), 2, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
1128 EXPECT_TRUE(net::LogContainsEndEvent( 1130 EXPECT_TRUE(net::LogContainsEndEvent(
1129 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1131 log.entries(), 3, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
1130 EXPECT_TRUE(net::LogContainsBeginEvent( 1132 EXPECT_TRUE(net::LogContainsBeginEvent(
1131 *log, 4, net::LoadLog::TYPE_HTTP_CACHE_WAITING)); 1133 log.entries(), 4, net::NetLog::TYPE_HTTP_CACHE_WAITING));
1132 EXPECT_TRUE(net::LogContainsEndEvent( 1134 EXPECT_TRUE(net::LogContainsEndEvent(
1133 *log, 5, net::LoadLog::TYPE_HTTP_CACHE_WAITING)); 1135 log.entries(), 5, net::NetLog::TYPE_HTTP_CACHE_WAITING));
1134 1136
1135 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1137 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1136 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1138 EXPECT_EQ(0, cache.disk_cache()->open_count());
1137 EXPECT_EQ(2, cache.disk_cache()->create_count()); 1139 EXPECT_EQ(2, cache.disk_cache()->create_count());
1138 } 1140 }
1139 1141
1140 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { 1142 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) {
1141 MockHttpCache cache; 1143 MockHttpCache cache;
1142 1144
1143 // write to the cache 1145 // write to the cache
(...skipping 3198 matching lines...) Expand 10 before | Expand all | Expand 10 after
4342 // Now return 200 when validating the entry so the metadata will be lost. 4344 // Now return 200 when validating the entry so the metadata will be lost.
4343 MockTransaction trans2(kTypicalGET_Transaction); 4345 MockTransaction trans2(kTypicalGET_Transaction);
4344 trans2.load_flags = net::LOAD_VALIDATE_CACHE; 4346 trans2.load_flags = net::LOAD_VALIDATE_CACHE;
4345 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); 4347 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response);
4346 EXPECT_TRUE(response.metadata.get() == NULL); 4348 EXPECT_TRUE(response.metadata.get() == NULL);
4347 4349
4348 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 4350 EXPECT_EQ(3, cache.network_layer()->transaction_count());
4349 EXPECT_EQ(4, cache.disk_cache()->open_count()); 4351 EXPECT_EQ(4, cache.disk_cache()->open_count());
4350 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4352 EXPECT_EQ(1, cache.disk_cache()->create_count());
4351 } 4353 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_network_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698