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

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

Issue 12886022: Implement offline mode behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Setup OfflinePolicy for all started requests. Created 7 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 | 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) 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 // Re-run transaction; make sure the result came from the network, 871 // Re-run transaction; make sure the result came from the network,
872 // not the cache. 872 // not the cache.
873 transaction.data = "Changed data."; 873 transaction.data = "Changed data.";
874 AddMockTransaction(&transaction); 874 AddMockTransaction(&transaction);
875 net::HttpResponseInfo response_info; 875 net::HttpResponseInfo response_info;
876 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, 876 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
877 &response_info); 877 &response_info);
878 878
879 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 879 EXPECT_EQ(2, cache.network_layer()->transaction_count());
880 EXPECT_FALSE(response_info.server_data_unavailable); 880 EXPECT_FALSE(response_info.server_data_unavailable);
881 EXPECT_TRUE(response_info.network_accessed);
881 882
882 RemoveMockTransaction(&transaction); 883 RemoveMockTransaction(&transaction);
883 } 884 }
884 885
885 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on 886 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on
886 // offline failure 887 // offline failure
887 TEST(HttpCache, SimpleGET_CacheOverride_Offline) { 888 TEST(HttpCache, SimpleGET_CacheOverride_Offline) {
888 MockHttpCache cache; 889 MockHttpCache cache;
889 890
890 // Prime cache. 891 // Prime cache.
(...skipping 19 matching lines...) Expand all
910 net::DEFAULT_PRIORITY, &trans, NULL); 911 net::DEFAULT_PRIORITY, &trans, NULL);
911 EXPECT_EQ(net::OK, rv); 912 EXPECT_EQ(net::OK, rv);
912 ASSERT_TRUE(trans.get()); 913 ASSERT_TRUE(trans.get());
913 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 914 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
914 EXPECT_EQ(net::OK, callback.GetResult(rv)); 915 EXPECT_EQ(net::OK, callback.GetResult(rv));
915 916
916 const net::HttpResponseInfo* response_info = trans->GetResponseInfo(); 917 const net::HttpResponseInfo* response_info = trans->GetResponseInfo();
917 ASSERT_TRUE(response_info); 918 ASSERT_TRUE(response_info);
918 EXPECT_TRUE(response_info->server_data_unavailable); 919 EXPECT_TRUE(response_info->server_data_unavailable);
919 EXPECT_TRUE(response_info->was_cached); 920 EXPECT_TRUE(response_info->was_cached);
921 EXPECT_FALSE(response_info->network_accessed);
920 ReadAndVerifyTransaction(trans.get(), transaction); 922 ReadAndVerifyTransaction(trans.get(), transaction);
921 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 923 EXPECT_EQ(2, cache.network_layer()->transaction_count());
922 924
923 RemoveMockTransaction(&transaction); 925 RemoveMockTransaction(&transaction);
924 } 926 }
925 927
926 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on 928 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on
927 // non-offline failure failure 929 // non-offline failure.
928 TEST(HttpCache, SimpleGET_CacheOverride_NonOffline) { 930 TEST(HttpCache, SimpleGET_CacheOverride_NonOffline) {
929 MockHttpCache cache; 931 MockHttpCache cache;
930 932
931 // Prime cache. 933 // Prime cache.
932 MockTransaction transaction(kSimpleGET_Transaction); 934 MockTransaction transaction(kSimpleGET_Transaction);
933 transaction.load_flags |= net::LOAD_FROM_CACHE_IF_OFFLINE; 935 transaction.load_flags |= net::LOAD_FROM_CACHE_IF_OFFLINE;
934 transaction.response_headers = "Cache-Control: no-cache\n"; 936 transaction.response_headers = "Cache-Control: no-cache\n";
935 937
936 AddMockTransaction(&transaction); 938 AddMockTransaction(&transaction);
937 RunTransactionTest(cache.http_cache(), transaction); 939 RunTransactionTest(cache.http_cache(), transaction);
938 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 940 EXPECT_EQ(1, cache.network_layer()->transaction_count());
939 EXPECT_EQ(1, cache.disk_cache()->create_count()); 941 EXPECT_EQ(1, cache.disk_cache()->create_count());
940 RemoveMockTransaction(&transaction); 942 RemoveMockTransaction(&transaction);
941 943
942 // Network failure with non-offline error; should fail with that error. 944 // Network failure with non-offline error; should fail with that error.
943 transaction.return_code = net::ERR_PROXY_CONNECTION_FAILED; 945 transaction.return_code = net::ERR_PROXY_CONNECTION_FAILED;
944 AddMockTransaction(&transaction); 946 AddMockTransaction(&transaction);
945 947
946 net::HttpResponseInfo response_info2; 948 net::HttpResponseInfo response_info2;
947 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, 949 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
948 &response_info2); 950 &response_info2);
949 951
950 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 952 EXPECT_EQ(2, cache.network_layer()->transaction_count());
951 EXPECT_FALSE(response_info2.server_data_unavailable); 953 EXPECT_FALSE(response_info2.server_data_unavailable);
952 954
953 RemoveMockTransaction(&transaction); 955 RemoveMockTransaction(&transaction);
954 } 956 }
955 957
958 // Confirm if we have an empty cache, a read is marked as network verified.
959 TEST(HttpCache, SimpleGET_NetworkAccessed_Network) {
960 MockHttpCache cache;
961
962 // write to the cache
963 net::HttpResponseInfo response_info;
964 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
965 &response_info);
966
967 EXPECT_EQ(1, cache.network_layer()->transaction_count());
968 EXPECT_EQ(0, cache.disk_cache()->open_count());
969 EXPECT_EQ(1, cache.disk_cache()->create_count());
970 EXPECT_TRUE(response_info.network_accessed);
971 }
972
973 // Confirm if we have a fresh entry in cache, it isn't marked as
974 // network verified.
975 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) {
976 MockHttpCache cache;
977
978 // Prime cache.
979 MockTransaction transaction(kSimpleGET_Transaction);
980
981 RunTransactionTest(cache.http_cache(), transaction);
982 EXPECT_EQ(1, cache.network_layer()->transaction_count());
983 EXPECT_EQ(1, cache.disk_cache()->create_count());
984
985 // Re-run transaction; make sure we don't mark the network as accessed.
986 net::HttpResponseInfo response_info;
987 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
988 &response_info);
989
990 EXPECT_EQ(1, cache.network_layer()->transaction_count());
991 EXPECT_FALSE(response_info.server_data_unavailable);
992 EXPECT_FALSE(response_info.network_accessed);
993 }
994
956 TEST(HttpCache, SimpleGET_LoadBypassCache) { 995 TEST(HttpCache, SimpleGET_LoadBypassCache) {
957 MockHttpCache cache; 996 MockHttpCache cache;
958 997
959 // Write to the cache. 998 // Write to the cache.
960 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 999 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
961 1000
962 // Force this transaction to write to the cache again. 1001 // Force this transaction to write to the cache again.
963 MockTransaction transaction(kSimpleGET_Transaction); 1002 MockTransaction transaction(kSimpleGET_Transaction);
964 transaction.load_flags |= net::LOAD_BYPASS_CACHE; 1003 transaction.load_flags |= net::LOAD_BYPASS_CACHE;
965 1004
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 // write to the cache 1076 // write to the cache
1038 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1077 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1039 1078
1040 // read from the cache 1079 // read from the cache
1041 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1080 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1042 1081
1043 // force this transaction to validate the cache 1082 // force this transaction to validate the cache
1044 MockTransaction transaction(kSimpleGET_Transaction); 1083 MockTransaction transaction(kSimpleGET_Transaction);
1045 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; 1084 transaction.load_flags |= net::LOAD_VALIDATE_CACHE;
1046 1085
1047 RunTransactionTest(cache.http_cache(), transaction); 1086 net::HttpResponseInfo response_info;
1087 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
1088 &response_info);
1048 1089
1049 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1090 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1050 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1091 EXPECT_EQ(1, cache.disk_cache()->open_count());
1051 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1092 EXPECT_EQ(1, cache.disk_cache()->create_count());
1093 EXPECT_TRUE(response_info.network_accessed);
1052 } 1094 }
1053 1095
1054 TEST(HttpCache, SimpleGET_LoadValidateCache_Implicit) { 1096 TEST(HttpCache, SimpleGET_LoadValidateCache_Implicit) {
1055 MockHttpCache cache; 1097 MockHttpCache cache;
1056 1098
1057 // write to the cache 1099 // write to the cache
1058 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1100 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1059 1101
1060 // read from the cache 1102 // read from the cache
1061 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1103 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
(...skipping 4717 matching lines...) Expand 10 before | Expand all | Expand 10 after
5779 trans->SetPriority(net::HIGHEST); 5821 trans->SetPriority(net::HIGHEST);
5780 // Should trigger a new network transaction and pick up the new 5822 // Should trigger a new network transaction and pick up the new
5781 // priority. 5823 // priority.
5782 ReadAndVerifyTransaction(trans.get(), transaction); 5824 ReadAndVerifyTransaction(trans.get(), transaction);
5783 5825
5784 EXPECT_EQ(net::HIGHEST, 5826 EXPECT_EQ(net::HIGHEST,
5785 cache.network_layer()->last_create_transaction_priority()); 5827 cache.network_layer()->last_create_transaction_priority());
5786 5828
5787 RemoveMockTransaction(&kRangeGET_TransactionOK); 5829 RemoveMockTransaction(&kRangeGET_TransactionOK);
5788 } 5830 }
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