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

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

Issue 551135: Cleanup the unittest helpers in load_log_unittest.h.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Sync and merge conflicts Created 10 years, 11 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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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"
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 cache.disk_cache()->set_fail_requests(); 898 cache.disk_cache()->set_fail_requests();
899 899
900 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 900 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded));
901 901
902 // Read from the network, and don't use the cache. 902 // Read from the network, and don't use the cache.
903 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); 903 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log);
904 904
905 // Check that the LoadLog was filled as expected. 905 // Check that the LoadLog was filled as expected.
906 // (We attempted to both Open and Create entries, but both failed). 906 // (We attempted to both Open and Create entries, but both failed).
907 EXPECT_EQ(4u, log->entries().size()); 907 EXPECT_EQ(4u, log->entries().size());
908 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, 908 EXPECT_TRUE(net::LogContainsBeginEvent(
909 net::LoadLog::PHASE_BEGIN); 909 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
910 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, 910 EXPECT_TRUE(net::LogContainsEndEvent(
911 net::LoadLog::PHASE_END); 911 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
912 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, 912 EXPECT_TRUE(net::LogContainsBeginEvent(
913 net::LoadLog::PHASE_BEGIN); 913 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
914 net::ExpectLogContains(log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, 914 EXPECT_TRUE(net::LogContainsEndEvent(
915 net::LoadLog::PHASE_END); 915 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
916 916
917 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 917 EXPECT_EQ(1, cache.network_layer()->transaction_count());
918 EXPECT_EQ(0, cache.disk_cache()->open_count()); 918 EXPECT_EQ(0, cache.disk_cache()->open_count());
919 EXPECT_EQ(0, cache.disk_cache()->create_count()); 919 EXPECT_EQ(0, cache.disk_cache()->create_count());
920 } 920 }
921 921
922 TEST(HttpCache, SimpleGETWithDiskFailures) { 922 TEST(HttpCache, SimpleGETWithDiskFailures) {
923 MockHttpCache cache; 923 MockHttpCache cache;
924 924
925 cache.disk_cache()->set_soft_failures(true); 925 cache.disk_cache()->set_soft_failures(true);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { 981 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
982 MockHttpCache cache; 982 MockHttpCache cache;
983 983
984 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 984 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded));
985 985
986 // write to the cache 986 // write to the cache
987 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); 987 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log);
988 988
989 // Check that the LoadLog was filled as expected. 989 // Check that the LoadLog was filled as expected.
990 EXPECT_EQ(6u, log->entries().size()); 990 EXPECT_EQ(6u, log->entries().size());
991 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, 991 EXPECT_TRUE(net::LogContainsBeginEvent(
992 net::LoadLog::PHASE_BEGIN); 992 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
993 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, 993 EXPECT_TRUE(net::LogContainsEndEvent(
994 net::LoadLog::PHASE_END); 994 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
995 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, 995 EXPECT_TRUE(net::LogContainsBeginEvent(
996 net::LoadLog::PHASE_BEGIN); 996 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
997 net::ExpectLogContains(log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, 997 EXPECT_TRUE(net::LogContainsEndEvent(
998 net::LoadLog::PHASE_END); 998 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
999 net::ExpectLogContains(log, 4, net::LoadLog::TYPE_HTTP_CACHE_WAITING, 999 EXPECT_TRUE(net::LogContainsBeginEvent(
1000 net::LoadLog::PHASE_BEGIN); 1000 *log, 4, net::LoadLog::TYPE_HTTP_CACHE_WAITING));
1001 net::ExpectLogContains(log, 5, net::LoadLog::TYPE_HTTP_CACHE_WAITING, 1001 EXPECT_TRUE(net::LogContainsEndEvent(
1002 net::LoadLog::PHASE_END); 1002 *log, 5, net::LoadLog::TYPE_HTTP_CACHE_WAITING));
1003 1003
1004 // force this transaction to read from the cache 1004 // force this transaction to read from the cache
1005 MockTransaction transaction(kSimpleGET_Transaction); 1005 MockTransaction transaction(kSimpleGET_Transaction);
1006 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 1006 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
1007 1007
1008 log = new net::LoadLog(net::LoadLog::kUnbounded); 1008 log = new net::LoadLog(net::LoadLog::kUnbounded);
1009 1009
1010 RunTransactionTestWithLog(cache.http_cache(), transaction, log); 1010 RunTransactionTestWithLog(cache.http_cache(), transaction, log);
1011 1011
1012 // Check that the LoadLog was filled as expected. 1012 // Check that the LoadLog was filled as expected.
1013 EXPECT_EQ(6u, log->entries().size()); 1013 EXPECT_EQ(6u, log->entries().size());
1014 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, 1014 EXPECT_TRUE(net::LogContainsBeginEvent(
1015 net::LoadLog::PHASE_BEGIN); 1015 *log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
1016 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, 1016 EXPECT_TRUE(net::LogContainsEndEvent(
1017 net::LoadLog::PHASE_END); 1017 *log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
1018 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_WAITING, 1018 EXPECT_TRUE(net::LogContainsBeginEvent(
1019 net::LoadLog::PHASE_BEGIN); 1019 *log, 2, net::LoadLog::TYPE_HTTP_CACHE_WAITING));
1020 net::ExpectLogContains(log, 3, net::LoadLog::TYPE_HTTP_CACHE_WAITING, 1020 EXPECT_TRUE(net::LogContainsEndEvent(
1021 net::LoadLog::PHASE_END); 1021 *log, 3, net::LoadLog::TYPE_HTTP_CACHE_WAITING));
1022 net::ExpectLogContains(log, 4, net::LoadLog::TYPE_HTTP_CACHE_READ_INFO, 1022 EXPECT_TRUE(net::LogContainsBeginEvent(
1023 net::LoadLog::PHASE_BEGIN); 1023 *log, 4, net::LoadLog::TYPE_HTTP_CACHE_READ_INFO));
1024 net::ExpectLogContains(log, 5, net::LoadLog::TYPE_HTTP_CACHE_READ_INFO, 1024 EXPECT_TRUE(net::LogContainsEndEvent(
1025 net::LoadLog::PHASE_END); 1025 *log, 5, net::LoadLog::TYPE_HTTP_CACHE_READ_INFO));
1026 1026
1027 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1027 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1028 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1028 EXPECT_EQ(1, cache.disk_cache()->open_count());
1029 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1029 EXPECT_EQ(1, cache.disk_cache()->create_count());
1030 } 1030 }
1031 1031
1032 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { 1032 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
1033 MockHttpCache cache; 1033 MockHttpCache cache;
1034 1034
1035 // force this transaction to read from the cache 1035 // force this transaction to read from the cache
(...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 std::string headers; 4166 std::string headers;
4167 response.headers->GetNormalizedHeaders(&headers); 4167 response.headers->GetNormalizedHeaders(&headers);
4168 4168
4169 EXPECT_EQ("HTTP/1.1 200 OK\n" 4169 EXPECT_EQ("HTTP/1.1 200 OK\n"
4170 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 4170 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
4171 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 4171 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
4172 headers); 4172 headers);
4173 4173
4174 RemoveMockTransaction(&mock_network_response); 4174 RemoveMockTransaction(&mock_network_response);
4175 } 4175 }
OLDNEW
« no previous file with comments | « net/flip/flip_network_transaction_unittest.cc ('k') | net/proxy/init_proxy_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698