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

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

Issue 8990001: base::Bind: Convert most of net/http. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang. Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 EXPECT_EQ(net::OK, rv); 67 EXPECT_EQ(net::OK, rv);
68 std::string expected(trans_info.data); 68 std::string expected(trans_info.data);
69 EXPECT_EQ(expected, content); 69 EXPECT_EQ(expected, content);
70 } 70 }
71 71
72 void RunTransactionTestWithRequestAndLog(net::HttpCache* cache, 72 void RunTransactionTestWithRequestAndLog(net::HttpCache* cache,
73 const MockTransaction& trans_info, 73 const MockTransaction& trans_info,
74 const MockHttpRequest& request, 74 const MockHttpRequest& request,
75 net::HttpResponseInfo* response_info, 75 net::HttpResponseInfo* response_info,
76 const net::BoundNetLog& net_log) { 76 const net::BoundNetLog& net_log) {
77 TestOldCompletionCallback callback; 77 net::TestCompletionCallback callback;
78 78
79 // write to the cache 79 // write to the cache
80 80
81 scoped_ptr<net::HttpTransaction> trans; 81 scoped_ptr<net::HttpTransaction> trans;
82 int rv = cache->CreateTransaction(&trans); 82 int rv = cache->CreateTransaction(&trans);
83 EXPECT_EQ(net::OK, rv); 83 EXPECT_EQ(net::OK, rv);
84 ASSERT_TRUE(trans.get()); 84 ASSERT_TRUE(trans.get());
85 85
86 rv = trans->Start(&request, &callback, net_log); 86 rv = trans->Start(&request, callback.callback(), net_log);
87 if (rv == net::ERR_IO_PENDING) 87 if (rv == net::ERR_IO_PENDING)
88 rv = callback.WaitForResult(); 88 rv = callback.WaitForResult();
89 ASSERT_EQ(net::OK, rv); 89 ASSERT_EQ(net::OK, rv);
90 90
91 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 91 const net::HttpResponseInfo* response = trans->GetResponseInfo();
92 ASSERT_TRUE(response); 92 ASSERT_TRUE(response);
93 93
94 if (response_info) 94 if (response_info)
95 *response_info = *response; 95 *response_info = *response;
96 96
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 const char* status; 376 const char* status;
377 const char* headers; 377 const char* headers;
378 const char* body; 378 const char* body;
379 }; 379 };
380 380
381 struct Context { 381 struct Context {
382 Context() : result(net::ERR_IO_PENDING) {} 382 Context() : result(net::ERR_IO_PENDING) {}
383 383
384 int result; 384 int result;
385 TestOldCompletionCallback callback; 385 net::TestCompletionCallback callback;
386 scoped_ptr<net::HttpTransaction> trans; 386 scoped_ptr<net::HttpTransaction> trans;
387 }; 387 };
388 388
389 } // namespace 389 } // namespace
390 390
391 391
392 //----------------------------------------------------------------------------- 392 //-----------------------------------------------------------------------------
393 // Tests. 393 // Tests.
394 394
395 TEST(HttpCache, CreateThenDestroy) { 395 TEST(HttpCache, CreateThenDestroy) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // request to fail. 496 // request to fail.
497 TEST(HttpCache, SimpleGETWithDiskFailures2) { 497 TEST(HttpCache, SimpleGETWithDiskFailures2) {
498 MockHttpCache cache; 498 MockHttpCache cache;
499 499
500 MockHttpRequest request(kSimpleGET_Transaction); 500 MockHttpRequest request(kSimpleGET_Transaction);
501 501
502 scoped_ptr<Context> c(new Context()); 502 scoped_ptr<Context> c(new Context());
503 int rv = cache.http_cache()->CreateTransaction(&c->trans); 503 int rv = cache.http_cache()->CreateTransaction(&c->trans);
504 EXPECT_EQ(net::OK, rv); 504 EXPECT_EQ(net::OK, rv);
505 505
506 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 506 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
507 EXPECT_EQ(net::ERR_IO_PENDING, rv); 507 EXPECT_EQ(net::ERR_IO_PENDING, rv);
508 rv = c->callback.WaitForResult(); 508 rv = c->callback.WaitForResult();
509 509
510 // Start failing request now. 510 // Start failing request now.
511 cache.disk_cache()->set_soft_failures(true); 511 cache.disk_cache()->set_soft_failures(true);
512 512
513 // We have to open the entry again to propagate the failure flag. 513 // We have to open the entry again to propagate the failure flag.
514 disk_cache::Entry* en; 514 disk_cache::Entry* en;
515 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en)); 515 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en));
516 en->Close(); 516 en->Close();
(...skipping 25 matching lines...) Expand all
542 EXPECT_EQ(1, cache.disk_cache()->create_count()); 542 EXPECT_EQ(1, cache.disk_cache()->create_count());
543 543
544 cache.disk_cache()->set_soft_failures(true); 544 cache.disk_cache()->set_soft_failures(true);
545 545
546 // Now fail to read from the cache. 546 // Now fail to read from the cache.
547 scoped_ptr<Context> c(new Context()); 547 scoped_ptr<Context> c(new Context());
548 int rv = cache.http_cache()->CreateTransaction(&c->trans); 548 int rv = cache.http_cache()->CreateTransaction(&c->trans);
549 EXPECT_EQ(net::OK, rv); 549 EXPECT_EQ(net::OK, rv);
550 550
551 MockHttpRequest request(kSimpleGET_Transaction); 551 MockHttpRequest request(kSimpleGET_Transaction);
552 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 552 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
553 EXPECT_EQ(net::ERR_CACHE_READ_FAILURE, c->callback.GetResult(rv)); 553 EXPECT_EQ(net::ERR_CACHE_READ_FAILURE, c->callback.GetResult(rv));
554 } 554 }
555 555
556 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { 556 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
557 MockHttpCache cache; 557 MockHttpCache cache;
558 558
559 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); 559 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
560 560
561 // This prevents a number of write events from being logged. 561 // This prevents a number of write events from being logged.
562 log.SetLogLevel(net::NetLog::LOG_BASIC); 562 log.SetLogLevel(net::NetLog::LOG_BASIC);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 622 }
623 623
624 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { 624 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
625 MockHttpCache cache; 625 MockHttpCache cache;
626 626
627 // force this transaction to read from the cache 627 // force this transaction to read from the cache
628 MockTransaction transaction(kSimpleGET_Transaction); 628 MockTransaction transaction(kSimpleGET_Transaction);
629 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 629 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
630 630
631 MockHttpRequest request(transaction); 631 MockHttpRequest request(transaction);
632 TestOldCompletionCallback callback; 632 net::TestCompletionCallback callback;
633 633
634 scoped_ptr<net::HttpTransaction> trans; 634 scoped_ptr<net::HttpTransaction> trans;
635 int rv = cache.http_cache()->CreateTransaction(&trans); 635 int rv = cache.http_cache()->CreateTransaction(&trans);
636 EXPECT_EQ(net::OK, rv); 636 EXPECT_EQ(net::OK, rv);
637 ASSERT_TRUE(trans.get()); 637 ASSERT_TRUE(trans.get());
638 638
639 rv = trans->Start(&request, &callback, net::BoundNetLog()); 639 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
640 if (rv == net::ERR_IO_PENDING) 640 if (rv == net::ERR_IO_PENDING)
641 rv = callback.WaitForResult(); 641 rv = callback.WaitForResult();
642 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 642 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
643 643
644 trans.reset(); 644 trans.reset();
645 645
646 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 646 EXPECT_EQ(0, cache.network_layer()->transaction_count());
647 EXPECT_EQ(0, cache.disk_cache()->open_count()); 647 EXPECT_EQ(0, cache.disk_cache()->open_count());
648 EXPECT_EQ(0, cache.disk_cache()->create_count()); 648 EXPECT_EQ(0, cache.disk_cache()->create_count());
649 } 649 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 const int kNumTransactions = 5; 855 const int kNumTransactions = 5;
856 856
857 for (int i = 0; i < kNumTransactions; ++i) { 857 for (int i = 0; i < kNumTransactions; ++i) {
858 context_list.push_back(new Context()); 858 context_list.push_back(new Context());
859 Context* c = context_list[i]; 859 Context* c = context_list[i];
860 860
861 c->result = cache.http_cache()->CreateTransaction(&c->trans); 861 c->result = cache.http_cache()->CreateTransaction(&c->trans);
862 EXPECT_EQ(net::OK, c->result); 862 EXPECT_EQ(net::OK, c->result);
863 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); 863 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState());
864 864
865 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 865 c->result = c->trans->Start(
866 &request, c->callback.callback(), net::BoundNetLog());
866 } 867 }
867 868
868 // All requests are waiting for the active entry. 869 // All requests are waiting for the active entry.
869 for (int i = 0; i < kNumTransactions; ++i) { 870 for (int i = 0; i < kNumTransactions; ++i) {
870 Context* c = context_list[i]; 871 Context* c = context_list[i];
871 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); 872 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
872 } 873 }
873 874
874 // Allow all requests to move from the Create queue to the active entry. 875 // Allow all requests to move from the Create queue to the active entry.
875 MessageLoop::current()->RunAllPending(); 876 MessageLoop::current()->RunAllPending();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 context_list.push_back(new Context()); 926 context_list.push_back(new Context());
926 Context* c = context_list[i]; 927 Context* c = context_list[i];
927 928
928 c->result = cache.http_cache()->CreateTransaction(&c->trans); 929 c->result = cache.http_cache()->CreateTransaction(&c->trans);
929 EXPECT_EQ(net::OK, c->result); 930 EXPECT_EQ(net::OK, c->result);
930 931
931 MockHttpRequest* this_request = &request; 932 MockHttpRequest* this_request = &request;
932 if (i == 1 || i == 2) 933 if (i == 1 || i == 2)
933 this_request = &reader_request; 934 this_request = &reader_request;
934 935
935 c->result = c->trans->Start(this_request, &c->callback, net::BoundNetLog()); 936 c->result = c->trans->Start(
937 this_request, c->callback.callback(), net::BoundNetLog());
936 } 938 }
937 939
938 // Allow all requests to move from the Create queue to the active entry. 940 // Allow all requests to move from the Create queue to the active entry.
939 MessageLoop::current()->RunAllPending(); 941 MessageLoop::current()->RunAllPending();
940 942
941 // The first request should be a writer at this point, and the subsequent 943 // The first request should be a writer at this point, and the subsequent
942 // requests should be pending. 944 // requests should be pending.
943 945
944 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 946 EXPECT_EQ(1, cache.network_layer()->transaction_count());
945 EXPECT_EQ(0, cache.disk_cache()->open_count()); 947 EXPECT_EQ(0, cache.disk_cache()->open_count());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 context_list.push_back(new Context()); 1011 context_list.push_back(new Context());
1010 Context* c = context_list[i]; 1012 Context* c = context_list[i];
1011 1013
1012 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1014 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1013 EXPECT_EQ(net::OK, c->result); 1015 EXPECT_EQ(net::OK, c->result);
1014 1016
1015 MockHttpRequest* this_request = &request; 1017 MockHttpRequest* this_request = &request;
1016 if (i == 3) 1018 if (i == 3)
1017 this_request = &writer_request; 1019 this_request = &writer_request;
1018 1020
1019 c->result = c->trans->Start(this_request, &c->callback, net::BoundNetLog()); 1021 c->result = c->trans->Start(
1022 this_request, c->callback.callback(), net::BoundNetLog());
1020 } 1023 }
1021 1024
1022 // The first request should be a writer at this point, and the two subsequent 1025 // The first request should be a writer at this point, and the two subsequent
1023 // requests should be pending. The last request doomed the first entry. 1026 // requests should be pending. The last request doomed the first entry.
1024 1027
1025 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1028 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1026 1029
1027 // Cancel the first queued transaction. 1030 // Cancel the first queued transaction.
1028 delete context_list[1]; 1031 delete context_list[1];
1029 context_list.get()[1] = NULL; 1032 context_list.get()[1] = NULL;
(...skipping 22 matching lines...) Expand all
1052 std::vector<Context*> context_list; 1055 std::vector<Context*> context_list;
1053 const int kNumTransactions = 3; 1056 const int kNumTransactions = 3;
1054 1057
1055 for (int i = 0; i < kNumTransactions; ++i) { 1058 for (int i = 0; i < kNumTransactions; ++i) {
1056 context_list.push_back(new Context()); 1059 context_list.push_back(new Context());
1057 Context* c = context_list[i]; 1060 Context* c = context_list[i];
1058 1061
1059 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1062 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1060 EXPECT_EQ(net::OK, c->result); 1063 EXPECT_EQ(net::OK, c->result);
1061 1064
1062 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1065 c->result = c->trans->Start(
1066 &request, c->callback.callback(), net::BoundNetLog());
1063 } 1067 }
1064 1068
1065 // Allow all requests to move from the Create queue to the active entry. 1069 // Allow all requests to move from the Create queue to the active entry.
1066 MessageLoop::current()->RunAllPending(); 1070 MessageLoop::current()->RunAllPending();
1067 1071
1068 // The first request should be a writer at this point, and the subsequent 1072 // The first request should be a writer at this point, and the subsequent
1069 // requests should be pending. 1073 // requests should be pending.
1070 1074
1071 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1075 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1072 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1076 EXPECT_EQ(0, cache.disk_cache()->open_count());
(...skipping 25 matching lines...) Expand all
1098 std::vector<Context*> context_list; 1102 std::vector<Context*> context_list;
1099 const int kNumTransactions = 2; 1103 const int kNumTransactions = 2;
1100 1104
1101 for (int i = 0; i < kNumTransactions; ++i) { 1105 for (int i = 0; i < kNumTransactions; ++i) {
1102 context_list.push_back(new Context()); 1106 context_list.push_back(new Context());
1103 Context* c = context_list[i]; 1107 Context* c = context_list[i];
1104 1108
1105 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1109 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1106 EXPECT_EQ(net::OK, c->result); 1110 EXPECT_EQ(net::OK, c->result);
1107 1111
1108 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1112 c->result = c->trans->Start(
1113 &request, c->callback.callback(), net::BoundNetLog());
1109 } 1114 }
1110 1115
1111 // Allow all requests to move from the Create queue to the active entry. 1116 // Allow all requests to move from the Create queue to the active entry.
1112 MessageLoop::current()->RunAllPending(); 1117 MessageLoop::current()->RunAllPending();
1113 1118
1114 // The first request should be a writer at this point, and the subsequent 1119 // The first request should be a writer at this point, and the subsequent
1115 // requests should be pending. 1120 // requests should be pending.
1116 1121
1117 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1122 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1118 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1123 EXPECT_EQ(0, cache.disk_cache()->open_count());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 std::vector<Context*> context_list; 1162 std::vector<Context*> context_list;
1158 const int kNumTransactions = 5; 1163 const int kNumTransactions = 5;
1159 1164
1160 for (int i = 0; i < kNumTransactions; i++) { 1165 for (int i = 0; i < kNumTransactions; i++) {
1161 context_list.push_back(new Context()); 1166 context_list.push_back(new Context());
1162 Context* c = context_list[i]; 1167 Context* c = context_list[i];
1163 1168
1164 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1169 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1165 EXPECT_EQ(net::OK, c->result); 1170 EXPECT_EQ(net::OK, c->result);
1166 1171
1167 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1172 c->result = c->trans->Start(
1173 &request, c->callback.callback(), net::BoundNetLog());
1168 } 1174 }
1169 1175
1170 // The first request should be creating the disk cache entry and the others 1176 // The first request should be creating the disk cache entry and the others
1171 // should be pending. 1177 // should be pending.
1172 1178
1173 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 1179 EXPECT_EQ(0, cache.network_layer()->transaction_count());
1174 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1180 EXPECT_EQ(0, cache.disk_cache()->open_count());
1175 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1181 EXPECT_EQ(1, cache.disk_cache()->create_count());
1176 1182
1177 // Cancel a request from the pending queue. 1183 // Cancel a request from the pending queue.
(...skipping 29 matching lines...) Expand all
1207 TEST(HttpCache, SimpleGET_CancelCreate) { 1213 TEST(HttpCache, SimpleGET_CancelCreate) {
1208 MockHttpCache cache; 1214 MockHttpCache cache;
1209 1215
1210 MockHttpRequest request(kSimpleGET_Transaction); 1216 MockHttpRequest request(kSimpleGET_Transaction);
1211 1217
1212 Context* c = new Context(); 1218 Context* c = new Context();
1213 1219
1214 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1220 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1215 EXPECT_EQ(net::OK, c->result); 1221 EXPECT_EQ(net::OK, c->result);
1216 1222
1217 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1223 c->result = c->trans->Start(
1224 &request, c->callback.callback(), net::BoundNetLog());
1218 EXPECT_EQ(net::ERR_IO_PENDING, c->result); 1225 EXPECT_EQ(net::ERR_IO_PENDING, c->result);
1219 1226
1220 // Release the reference that the mock disk cache keeps for this entry, so 1227 // Release the reference that the mock disk cache keeps for this entry, so
1221 // that we test that the http cache handles the cancelation correctly. 1228 // that we test that the http cache handles the cancellation correctly.
1222 cache.disk_cache()->ReleaseAll(); 1229 cache.disk_cache()->ReleaseAll();
1223 delete c; 1230 delete c;
1224 1231
1225 MessageLoop::current()->RunAllPending(); 1232 MessageLoop::current()->RunAllPending();
1226 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1233 EXPECT_EQ(1, cache.disk_cache()->create_count());
1227 } 1234 }
1228 1235
1229 // Tests that we delete/create entries even if multiple requests are queued. 1236 // Tests that we delete/create entries even if multiple requests are queued.
1230 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { 1237 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) {
1231 MockHttpCache cache; 1238 MockHttpCache cache;
1232 1239
1233 MockHttpRequest request(kSimpleGET_Transaction); 1240 MockHttpRequest request(kSimpleGET_Transaction);
1234 request.load_flags = net::LOAD_BYPASS_CACHE; 1241 request.load_flags = net::LOAD_BYPASS_CACHE;
1235 1242
1236 std::vector<Context*> context_list; 1243 std::vector<Context*> context_list;
1237 const int kNumTransactions = 5; 1244 const int kNumTransactions = 5;
1238 1245
1239 for (int i = 0; i < kNumTransactions; i++) { 1246 for (int i = 0; i < kNumTransactions; i++) {
1240 context_list.push_back(new Context()); 1247 context_list.push_back(new Context());
1241 Context* c = context_list[i]; 1248 Context* c = context_list[i];
1242 1249
1243 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1250 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1244 EXPECT_EQ(net::OK, c->result); 1251 EXPECT_EQ(net::OK, c->result);
1245 1252
1246 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1253 c->result = c->trans->Start(
1254 &request, c->callback.callback(), net::BoundNetLog());
1247 } 1255 }
1248 1256
1249 // The first request should be deleting the disk cache entry and the others 1257 // The first request should be deleting the disk cache entry and the others
1250 // should be pending. 1258 // should be pending.
1251 1259
1252 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 1260 EXPECT_EQ(0, cache.network_layer()->transaction_count());
1253 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1261 EXPECT_EQ(0, cache.disk_cache()->open_count());
1254 EXPECT_EQ(0, cache.disk_cache()->create_count()); 1262 EXPECT_EQ(0, cache.disk_cache()->create_count());
1255 1263
1256 // Complete the transactions. 1264 // Complete the transactions.
(...skipping 14 matching lines...) Expand all
1271 } 1279 }
1272 } 1280 }
1273 1281
1274 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { 1282 TEST(HttpCache, SimpleGET_AbandonedCacheRead) {
1275 MockHttpCache cache; 1283 MockHttpCache cache;
1276 1284
1277 // write to the cache 1285 // write to the cache
1278 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1286 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1279 1287
1280 MockHttpRequest request(kSimpleGET_Transaction); 1288 MockHttpRequest request(kSimpleGET_Transaction);
1281 TestOldCompletionCallback callback; 1289 net::TestCompletionCallback callback;
1282 1290
1283 scoped_ptr<net::HttpTransaction> trans; 1291 scoped_ptr<net::HttpTransaction> trans;
1284 int rv = cache.http_cache()->CreateTransaction(&trans); 1292 int rv = cache.http_cache()->CreateTransaction(&trans);
1285 EXPECT_EQ(net::OK, rv); 1293 EXPECT_EQ(net::OK, rv);
1286 rv = trans->Start(&request, &callback, net::BoundNetLog()); 1294 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
1287 if (rv == net::ERR_IO_PENDING) 1295 if (rv == net::ERR_IO_PENDING)
1288 rv = callback.WaitForResult(); 1296 rv = callback.WaitForResult();
1289 ASSERT_EQ(net::OK, rv); 1297 ASSERT_EQ(net::OK, rv);
1290 1298
1291 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 1299 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
1292 rv = trans->Read(buf, 256, &callback); 1300 rv = trans->Read(buf, 256, callback.callback());
1293 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1301 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1294 1302
1295 // Test that destroying the transaction while it is reading from the cache 1303 // Test that destroying the transaction while it is reading from the cache
1296 // works properly. 1304 // works properly.
1297 trans.reset(); 1305 trans.reset();
1298 1306
1299 // Make sure we pump any pending events, which should include a call to 1307 // Make sure we pump any pending events, which should include a call to
1300 // HttpCache::Transaction::OnCacheReadCompleted. 1308 // HttpCache::Transaction::OnCacheReadCompleted.
1301 MessageLoop::current()->RunAllPending(); 1309 MessageLoop::current()->RunAllPending();
1302 } 1310 }
1303 1311
1304 // Tests that we can delete the HttpCache and deal with queued transactions 1312 // Tests that we can delete the HttpCache and deal with queued transactions
1305 // ("waiting for the backend" as opposed to Active or Doomed entries). 1313 // ("waiting for the backend" as opposed to Active or Doomed entries).
1306 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) { 1314 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) {
1307 scoped_ptr<MockHttpCache> cache(new MockHttpCache( 1315 scoped_ptr<MockHttpCache> cache(new MockHttpCache(
1308 new MockBackendNoCbFactory())); 1316 new MockBackendNoCbFactory()));
1309 1317
1310 MockHttpRequest request(kSimpleGET_Transaction); 1318 MockHttpRequest request(kSimpleGET_Transaction);
1311 1319
1312 std::vector<Context*> context_list; 1320 std::vector<Context*> context_list;
1313 const int kNumTransactions = 5; 1321 const int kNumTransactions = 5;
1314 1322
1315 for (int i = 0; i < kNumTransactions; i++) { 1323 for (int i = 0; i < kNumTransactions; i++) {
1316 context_list.push_back(new Context()); 1324 context_list.push_back(new Context());
1317 Context* c = context_list[i]; 1325 Context* c = context_list[i];
1318 1326
1319 c->result = cache->http_cache()->CreateTransaction(&c->trans); 1327 c->result = cache->http_cache()->CreateTransaction(&c->trans);
1320 EXPECT_EQ(net::OK, c->result); 1328 EXPECT_EQ(net::OK, c->result);
1321 1329
1322 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1330 c->result = c->trans->Start(
1331 &request, c->callback.callback(), net::BoundNetLog());
1323 } 1332 }
1324 1333
1325 // The first request should be creating the disk cache entry and the others 1334 // The first request should be creating the disk cache entry and the others
1326 // should be pending. 1335 // should be pending.
1327 1336
1328 EXPECT_EQ(0, cache->network_layer()->transaction_count()); 1337 EXPECT_EQ(0, cache->network_layer()->transaction_count());
1329 EXPECT_EQ(0, cache->disk_cache()->open_count()); 1338 EXPECT_EQ(0, cache->disk_cache()->open_count());
1330 EXPECT_EQ(0, cache->disk_cache()->create_count()); 1339 EXPECT_EQ(0, cache->disk_cache()->create_count());
1331 1340
1332 cache.reset(); 1341 cache.reset();
(...skipping 19 matching lines...) Expand all
1352 1361
1353 for (int i = 0; i < kNumTransactions; i++) { 1362 for (int i = 0; i < kNumTransactions; i++) {
1354 context_list.push_back(new Context()); 1363 context_list.push_back(new Context());
1355 Context* c = context_list[i]; 1364 Context* c = context_list[i];
1356 1365
1357 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1366 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1358 EXPECT_EQ(net::OK, c->result); 1367 EXPECT_EQ(net::OK, c->result);
1359 } 1368 }
1360 1369
1361 context_list[0]->result = context_list[0]->trans->Start( 1370 context_list[0]->result = context_list[0]->trans->Start(
1362 &request0, &context_list[0]->callback, net::BoundNetLog()); 1371 &request0, context_list[0]->callback.callback(), net::BoundNetLog());
1363 context_list[1]->result = context_list[1]->trans->Start( 1372 context_list[1]->result = context_list[1]->trans->Start(
1364 &request1, &context_list[1]->callback, net::BoundNetLog()); 1373 &request1, context_list[1]->callback.callback(), net::BoundNetLog());
1365 context_list[2]->result = context_list[2]->trans->Start( 1374 context_list[2]->result = context_list[2]->trans->Start(
1366 &request2, &context_list[2]->callback, net::BoundNetLog()); 1375 &request2, context_list[2]->callback.callback(), net::BoundNetLog());
1367 1376
1368 // Just to make sure that everything is still pending. 1377 // Just to make sure that everything is still pending.
1369 MessageLoop::current()->RunAllPending(); 1378 MessageLoop::current()->RunAllPending();
1370 1379
1371 // The first request should be creating the disk cache. 1380 // The first request should be creating the disk cache.
1372 EXPECT_FALSE(context_list[0]->callback.have_result()); 1381 EXPECT_FALSE(context_list[0]->callback.have_result());
1373 1382
1374 factory->FinishCreation(); 1383 factory->FinishCreation();
1375 1384
1376 MessageLoop::current()->RunAllPending(); 1385 MessageLoop::current()->RunAllPending();
(...skipping 21 matching lines...) Expand all
1398 1407
1399 for (int i = 0; i < kNumTransactions; i++) { 1408 for (int i = 0; i < kNumTransactions; i++) {
1400 context_list.push_back(new Context()); 1409 context_list.push_back(new Context());
1401 Context* c = context_list[i]; 1410 Context* c = context_list[i];
1402 1411
1403 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1412 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1404 EXPECT_EQ(net::OK, c->result); 1413 EXPECT_EQ(net::OK, c->result);
1405 } 1414 }
1406 1415
1407 context_list[0]->result = context_list[0]->trans->Start( 1416 context_list[0]->result = context_list[0]->trans->Start(
1408 &request0, &context_list[0]->callback, net::BoundNetLog()); 1417 &request0, context_list[0]->callback.callback(), net::BoundNetLog());
1409 context_list[1]->result = context_list[1]->trans->Start( 1418 context_list[1]->result = context_list[1]->trans->Start(
1410 &request1, &context_list[1]->callback, net::BoundNetLog()); 1419 &request1, context_list[1]->callback.callback(), net::BoundNetLog());
1411 context_list[2]->result = context_list[2]->trans->Start( 1420 context_list[2]->result = context_list[2]->trans->Start(
1412 &request2, &context_list[2]->callback, net::BoundNetLog()); 1421 &request2, context_list[2]->callback.callback(), net::BoundNetLog());
1413 1422
1414 // Just to make sure that everything is still pending. 1423 // Just to make sure that everything is still pending.
1415 MessageLoop::current()->RunAllPending(); 1424 MessageLoop::current()->RunAllPending();
1416 1425
1417 // The first request should be creating the disk cache. 1426 // The first request should be creating the disk cache.
1418 EXPECT_FALSE(context_list[0]->callback.have_result()); 1427 EXPECT_FALSE(context_list[0]->callback.have_result());
1419 1428
1420 // Cancel a request from the pending queue. 1429 // Cancel a request from the pending queue.
1421 delete context_list[1]; 1430 delete context_list[1];
1422 context_list[1] = NULL; 1431 context_list[1] = NULL;
(...skipping 19 matching lines...) Expand all
1442 TEST(HttpCache, DeleteCacheWaitingForBackend) { 1451 TEST(HttpCache, DeleteCacheWaitingForBackend) {
1443 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 1452 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
1444 scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory)); 1453 scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory));
1445 1454
1446 MockHttpRequest request(kSimpleGET_Transaction); 1455 MockHttpRequest request(kSimpleGET_Transaction);
1447 1456
1448 scoped_ptr<Context> c(new Context()); 1457 scoped_ptr<Context> c(new Context());
1449 c->result = cache->http_cache()->CreateTransaction(&c->trans); 1458 c->result = cache->http_cache()->CreateTransaction(&c->trans);
1450 EXPECT_EQ(net::OK, c->result); 1459 EXPECT_EQ(net::OK, c->result);
1451 1460
1452 c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1461 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
1453 1462
1454 // Just to make sure that everything is still pending. 1463 // Just to make sure that everything is still pending.
1455 MessageLoop::current()->RunAllPending(); 1464 MessageLoop::current()->RunAllPending();
1456 1465
1457 // The request should be creating the disk cache. 1466 // The request should be creating the disk cache.
1458 EXPECT_FALSE(c->callback.have_result()); 1467 EXPECT_FALSE(c->callback.have_result());
1459 1468
1460 // We cannot call FinishCreation because the factory itself will go away with 1469 // We cannot call FinishCreation because the factory itself will go away with
1461 // the cache, so grab the callback and attempt to use it. 1470 // the cache, so grab the callback and attempt to use it.
1462 net::CompletionCallback callback = factory->callback(); 1471 net::CompletionCallback callback = factory->callback();
(...skipping 17 matching lines...) Expand all
1480 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); 1489 int rv = cache->http_cache()->GetBackend(&backend, cb.callback());
1481 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1490 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1482 1491
1483 // Now let's queue a regular transaction 1492 // Now let's queue a regular transaction
1484 MockHttpRequest request(kSimpleGET_Transaction); 1493 MockHttpRequest request(kSimpleGET_Transaction);
1485 1494
1486 scoped_ptr<Context> c(new Context()); 1495 scoped_ptr<Context> c(new Context());
1487 c->result = cache->http_cache()->CreateTransaction(&c->trans); 1496 c->result = cache->http_cache()->CreateTransaction(&c->trans);
1488 EXPECT_EQ(net::OK, c->result); 1497 EXPECT_EQ(net::OK, c->result);
1489 1498
1490 c->trans->Start(&request, &c->callback, net::BoundNetLog()); 1499 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
1491 1500
1492 // And another direct backend request. 1501 // And another direct backend request.
1493 net::TestCompletionCallback cb2; 1502 net::TestCompletionCallback cb2;
1494 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); 1503 rv = cache->http_cache()->GetBackend(&backend, cb2.callback());
1495 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1504 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1496 1505
1497 // Just to make sure that everything is still pending. 1506 // Just to make sure that everything is still pending.
1498 MessageLoop::current()->RunAllPending(); 1507 MessageLoop::current()->RunAllPending();
1499 1508
1500 // The request should be queued. 1509 // The request should be queued.
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 MockHttpCache cache; 2174 MockHttpCache cache;
2166 2175
2167 // Test that we skip the cache for POST requests. Eventually, we will want 2176 // Test that we skip the cache for POST requests. Eventually, we will want
2168 // to cache these, but we'll still have cases where skipping the cache makes 2177 // to cache these, but we'll still have cases where skipping the cache makes
2169 // sense, so we want to make sure that it works properly. 2178 // sense, so we want to make sure that it works properly.
2170 2179
2171 MockTransaction transaction(kSimplePOST_Transaction); 2180 MockTransaction transaction(kSimplePOST_Transaction);
2172 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 2181 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
2173 2182
2174 MockHttpRequest request(transaction); 2183 MockHttpRequest request(transaction);
2175 TestOldCompletionCallback callback; 2184 net::TestCompletionCallback callback;
2176 2185
2177 scoped_ptr<net::HttpTransaction> trans; 2186 scoped_ptr<net::HttpTransaction> trans;
2178 int rv = cache.http_cache()->CreateTransaction(&trans); 2187 int rv = cache.http_cache()->CreateTransaction(&trans);
2179 EXPECT_EQ(net::OK, rv); 2188 EXPECT_EQ(net::OK, rv);
2180 ASSERT_TRUE(trans.get()); 2189 ASSERT_TRUE(trans.get());
2181 2190
2182 rv = trans->Start(&request, &callback, net::BoundNetLog()); 2191 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
2183 if (rv == net::ERR_IO_PENDING) 2192 if (rv == net::ERR_IO_PENDING)
2184 rv = callback.WaitForResult(); 2193 rv = callback.WaitForResult();
2185 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 2194 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
2186 2195
2187 trans.reset(); 2196 trans.reset();
2188 2197
2189 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 2198 EXPECT_EQ(0, cache.network_layer()->transaction_count());
2190 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2199 EXPECT_EQ(0, cache.disk_cache()->open_count());
2191 EXPECT_EQ(0, cache.disk_cache()->create_count()); 2200 EXPECT_EQ(0, cache.disk_cache()->create_count());
2192 } 2201 }
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
3077 TEST(HttpCache, RangeGET_Cancel) { 3086 TEST(HttpCache, RangeGET_Cancel) {
3078 MockHttpCache cache; 3087 MockHttpCache cache;
3079 AddMockTransaction(&kRangeGET_TransactionOK); 3088 AddMockTransaction(&kRangeGET_TransactionOK);
3080 3089
3081 MockHttpRequest request(kRangeGET_TransactionOK); 3090 MockHttpRequest request(kRangeGET_TransactionOK);
3082 3091
3083 Context* c = new Context(); 3092 Context* c = new Context();
3084 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3093 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3085 EXPECT_EQ(net::OK, rv); 3094 EXPECT_EQ(net::OK, rv);
3086 3095
3087 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3096 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3088 if (rv == net::ERR_IO_PENDING) 3097 if (rv == net::ERR_IO_PENDING)
3089 rv = c->callback.WaitForResult(); 3098 rv = c->callback.WaitForResult();
3090 3099
3091 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3100 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3092 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3101 EXPECT_EQ(0, cache.disk_cache()->open_count());
3093 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3102 EXPECT_EQ(1, cache.disk_cache()->create_count());
3094 3103
3095 // Make sure that the entry has some data stored. 3104 // Make sure that the entry has some data stored.
3096 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); 3105 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
3097 rv = c->trans->Read(buf, buf->size(), &c->callback); 3106 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3098 if (rv == net::ERR_IO_PENDING) 3107 if (rv == net::ERR_IO_PENDING)
3099 rv = c->callback.WaitForResult(); 3108 rv = c->callback.WaitForResult();
3100 EXPECT_EQ(buf->size(), rv); 3109 EXPECT_EQ(buf->size(), rv);
3101 3110
3102 // Destroy the transaction. 3111 // Destroy the transaction.
3103 delete c; 3112 delete c;
3104 3113
3105 // Verify that the entry has not been deleted. 3114 // Verify that the entry has not been deleted.
3106 disk_cache::Entry* entry; 3115 disk_cache::Entry* entry;
3107 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); 3116 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry));
3108 entry->Close(); 3117 entry->Close();
3109 RemoveMockTransaction(&kRangeGET_TransactionOK); 3118 RemoveMockTransaction(&kRangeGET_TransactionOK);
3110 } 3119 }
3111 3120
3112 // Tests that we don't delete a sparse entry when we start a new request after 3121 // Tests that we don't delete a sparse entry when we start a new request after
3113 // cancelling the previous one. 3122 // cancelling the previous one.
3114 TEST(HttpCache, RangeGET_Cancel2) { 3123 TEST(HttpCache, RangeGET_Cancel2) {
3115 MockHttpCache cache; 3124 MockHttpCache cache;
3116 AddMockTransaction(&kRangeGET_TransactionOK); 3125 AddMockTransaction(&kRangeGET_TransactionOK);
3117 3126
3118 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 3127 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
3119 MockHttpRequest request(kRangeGET_TransactionOK); 3128 MockHttpRequest request(kRangeGET_TransactionOK);
3120 request.load_flags |= net::LOAD_VALIDATE_CACHE; 3129 request.load_flags |= net::LOAD_VALIDATE_CACHE;
3121 3130
3122 Context* c = new Context(); 3131 Context* c = new Context();
3123 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3132 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3124 EXPECT_EQ(net::OK, rv); 3133 EXPECT_EQ(net::OK, rv);
3125 3134
3126 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3135 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3127 if (rv == net::ERR_IO_PENDING) 3136 if (rv == net::ERR_IO_PENDING)
3128 rv = c->callback.WaitForResult(); 3137 rv = c->callback.WaitForResult();
3129 3138
3130 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3139 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3131 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3140 EXPECT_EQ(1, cache.disk_cache()->open_count());
3132 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3141 EXPECT_EQ(1, cache.disk_cache()->create_count());
3133 3142
3134 // Make sure that we revalidate the entry and read from the cache (a single 3143 // Make sure that we revalidate the entry and read from the cache (a single
3135 // read will return while waiting for the network). 3144 // read will return while waiting for the network).
3136 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); 3145 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
3137 rv = c->trans->Read(buf, buf->size(), &c->callback); 3146 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3138 EXPECT_EQ(5, c->callback.GetResult(rv)); 3147 EXPECT_EQ(5, c->callback.GetResult(rv));
3139 rv = c->trans->Read(buf, buf->size(), &c->callback); 3148 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3140 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3149 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3141 3150
3142 // Destroy the transaction before completing the read. 3151 // Destroy the transaction before completing the read.
3143 delete c; 3152 delete c;
3144 3153
3145 // We have the read and the delete (OnProcessPendingQueue) waiting on the 3154 // We have the read and the delete (OnProcessPendingQueue) waiting on the
3146 // message loop. This means that a new transaction will just reuse the same 3155 // message loop. This means that a new transaction will just reuse the same
3147 // active entry (no open or create). 3156 // active entry (no open or create).
3148 3157
3149 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 3158 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
(...skipping 11 matching lines...) Expand all
3161 AddMockTransaction(&kRangeGET_TransactionOK); 3170 AddMockTransaction(&kRangeGET_TransactionOK);
3162 3171
3163 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 3172 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
3164 MockHttpRequest request(kRangeGET_TransactionOK); 3173 MockHttpRequest request(kRangeGET_TransactionOK);
3165 request.load_flags |= net::LOAD_VALIDATE_CACHE; 3174 request.load_flags |= net::LOAD_VALIDATE_CACHE;
3166 3175
3167 Context* c = new Context(); 3176 Context* c = new Context();
3168 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3177 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3169 EXPECT_EQ(net::OK, rv); 3178 EXPECT_EQ(net::OK, rv);
3170 3179
3171 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3180 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3172 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3181 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3173 rv = c->callback.WaitForResult(); 3182 rv = c->callback.WaitForResult();
3174 3183
3175 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3184 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3176 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3185 EXPECT_EQ(1, cache.disk_cache()->open_count());
3177 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3186 EXPECT_EQ(1, cache.disk_cache()->create_count());
3178 3187
3179 // Make sure that we revalidate the entry and read from the cache (a single 3188 // Make sure that we revalidate the entry and read from the cache (a single
3180 // read will return while waiting for the network). 3189 // read will return while waiting for the network).
3181 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); 3190 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
3182 rv = c->trans->Read(buf, buf->size(), &c->callback); 3191 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3183 EXPECT_EQ(5, c->callback.GetResult(rv)); 3192 EXPECT_EQ(5, c->callback.GetResult(rv));
3184 rv = c->trans->Read(buf, buf->size(), &c->callback); 3193 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3185 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3194 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3186 3195
3187 // Destroy the transaction before completing the read. 3196 // Destroy the transaction before completing the read.
3188 delete c; 3197 delete c;
3189 3198
3190 // We have the read and the delete (OnProcessPendingQueue) waiting on the 3199 // We have the read and the delete (OnProcessPendingQueue) waiting on the
3191 // message loop. This means that a new transaction will just reuse the same 3200 // message loop. This means that a new transaction will just reuse the same
3192 // active entry (no open or create). 3201 // active entry (no open or create).
3193 3202
3194 c = new Context(); 3203 c = new Context();
3195 rv = cache.http_cache()->CreateTransaction(&c->trans); 3204 rv = cache.http_cache()->CreateTransaction(&c->trans);
3196 EXPECT_EQ(net::OK, rv); 3205 EXPECT_EQ(net::OK, rv);
3197 3206
3198 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3207 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3199 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3208 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3200 3209
3201 MockDiskEntry::IgnoreCallbacks(true); 3210 MockDiskEntry::IgnoreCallbacks(true);
3202 MessageLoop::current()->RunAllPending(); 3211 MessageLoop::current()->RunAllPending();
3203 MockDiskEntry::IgnoreCallbacks(false); 3212 MockDiskEntry::IgnoreCallbacks(false);
3204 3213
3205 // The new transaction is waiting for the query range callback. 3214 // The new transaction is waiting for the query range callback.
3206 delete c; 3215 delete c;
3207 3216
3208 // And we should not crash when the callback is delivered. 3217 // And we should not crash when the callback is delivered.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
3463 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 3472 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
3464 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3473 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3465 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3474 EXPECT_EQ(0, cache.disk_cache()->open_count());
3466 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3475 EXPECT_EQ(1, cache.disk_cache()->create_count());
3467 3476
3468 // Force this transaction to read from the cache. 3477 // Force this transaction to read from the cache.
3469 MockTransaction transaction(kRangeGET_TransactionOK); 3478 MockTransaction transaction(kRangeGET_TransactionOK);
3470 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 3479 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
3471 3480
3472 MockHttpRequest request(transaction); 3481 MockHttpRequest request(transaction);
3473 TestOldCompletionCallback callback; 3482 net::TestCompletionCallback callback;
3474 3483
3475 scoped_ptr<net::HttpTransaction> trans; 3484 scoped_ptr<net::HttpTransaction> trans;
3476 int rv = cache.http_cache()->CreateTransaction(&trans); 3485 int rv = cache.http_cache()->CreateTransaction(&trans);
3477 EXPECT_EQ(net::OK, rv); 3486 EXPECT_EQ(net::OK, rv);
3478 ASSERT_TRUE(trans.get()); 3487 ASSERT_TRUE(trans.get());
3479 3488
3480 rv = trans->Start(&request, &callback, net::BoundNetLog()); 3489 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
3481 if (rv == net::ERR_IO_PENDING) 3490 if (rv == net::ERR_IO_PENDING)
3482 rv = callback.WaitForResult(); 3491 rv = callback.WaitForResult();
3483 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 3492 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
3484 3493
3485 trans.reset(); 3494 trans.reset();
3486 3495
3487 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3496 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3488 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3497 EXPECT_EQ(1, cache.disk_cache()->open_count());
3489 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3498 EXPECT_EQ(1, cache.disk_cache()->create_count());
3490 3499
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3547 // to read from the network. 3556 // to read from the network.
3548 TEST(HttpCache, DoomOnDestruction) { 3557 TEST(HttpCache, DoomOnDestruction) {
3549 MockHttpCache cache; 3558 MockHttpCache cache;
3550 3559
3551 MockHttpRequest request(kSimpleGET_Transaction); 3560 MockHttpRequest request(kSimpleGET_Transaction);
3552 3561
3553 Context* c = new Context(); 3562 Context* c = new Context();
3554 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3563 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3555 EXPECT_EQ(net::OK, rv); 3564 EXPECT_EQ(net::OK, rv);
3556 3565
3557 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3566 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3558 if (rv == net::ERR_IO_PENDING) 3567 if (rv == net::ERR_IO_PENDING)
3559 c->result = c->callback.WaitForResult(); 3568 c->result = c->callback.WaitForResult();
3560 3569
3561 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3570 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3562 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3571 EXPECT_EQ(0, cache.disk_cache()->open_count());
3563 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3572 EXPECT_EQ(1, cache.disk_cache()->create_count());
3564 3573
3565 // Destroy the transaction. We only have the headers so we should delete this 3574 // Destroy the transaction. We only have the headers so we should delete this
3566 // entry. 3575 // entry.
3567 delete c; 3576 delete c;
3568 3577
3569 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 3578 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
3570 3579
3571 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3580 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3572 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3581 EXPECT_EQ(0, cache.disk_cache()->open_count());
3573 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3582 EXPECT_EQ(2, cache.disk_cache()->create_count());
3574 } 3583 }
3575 3584
3576 // Tests that we delete an entry when the request is cancelled if the response 3585 // Tests that we delete an entry when the request is cancelled if the response
3577 // does not have content-length and strong validators. 3586 // does not have content-length and strong validators.
3578 TEST(HttpCache, DoomOnDestruction2) { 3587 TEST(HttpCache, DoomOnDestruction2) {
3579 MockHttpCache cache; 3588 MockHttpCache cache;
3580 3589
3581 MockHttpRequest request(kSimpleGET_Transaction); 3590 MockHttpRequest request(kSimpleGET_Transaction);
3582 3591
3583 Context* c = new Context(); 3592 Context* c = new Context();
3584 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3593 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3585 EXPECT_EQ(net::OK, rv); 3594 EXPECT_EQ(net::OK, rv);
3586 3595
3587 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3596 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3588 if (rv == net::ERR_IO_PENDING) 3597 if (rv == net::ERR_IO_PENDING)
3589 rv = c->callback.WaitForResult(); 3598 rv = c->callback.WaitForResult();
3590 3599
3591 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3600 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3592 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3601 EXPECT_EQ(0, cache.disk_cache()->open_count());
3593 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3602 EXPECT_EQ(1, cache.disk_cache()->create_count());
3594 3603
3595 // Make sure that the entry has some data stored. 3604 // Make sure that the entry has some data stored.
3596 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); 3605 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
3597 rv = c->trans->Read(buf, buf->size(), &c->callback); 3606 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3598 if (rv == net::ERR_IO_PENDING) 3607 if (rv == net::ERR_IO_PENDING)
3599 rv = c->callback.WaitForResult(); 3608 rv = c->callback.WaitForResult();
3600 EXPECT_EQ(buf->size(), rv); 3609 EXPECT_EQ(buf->size(), rv);
3601 3610
3602 // Destroy the transaction. 3611 // Destroy the transaction.
3603 delete c; 3612 delete c;
3604 3613
3605 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 3614 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
3606 3615
3607 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3616 EXPECT_EQ(2, cache.network_layer()->transaction_count());
(...skipping 12 matching lines...) Expand all
3620 "Content-Length: 22\n" 3629 "Content-Length: 22\n"
3621 "Accept-Ranges: none\n" 3630 "Accept-Ranges: none\n"
3622 "Etag: foopy\n"; 3631 "Etag: foopy\n";
3623 AddMockTransaction(&transaction); 3632 AddMockTransaction(&transaction);
3624 MockHttpRequest request(transaction); 3633 MockHttpRequest request(transaction);
3625 3634
3626 Context* c = new Context(); 3635 Context* c = new Context();
3627 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3636 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3628 EXPECT_EQ(net::OK, rv); 3637 EXPECT_EQ(net::OK, rv);
3629 3638
3630 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3639 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3631 if (rv == net::ERR_IO_PENDING) 3640 if (rv == net::ERR_IO_PENDING)
3632 rv = c->callback.WaitForResult(); 3641 rv = c->callback.WaitForResult();
3633 3642
3634 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3643 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3635 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3644 EXPECT_EQ(0, cache.disk_cache()->open_count());
3636 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3645 EXPECT_EQ(1, cache.disk_cache()->create_count());
3637 3646
3638 // Make sure that the entry has some data stored. 3647 // Make sure that the entry has some data stored.
3639 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); 3648 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
3640 rv = c->trans->Read(buf, buf->size(), &c->callback); 3649 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3641 if (rv == net::ERR_IO_PENDING) 3650 if (rv == net::ERR_IO_PENDING)
3642 rv = c->callback.WaitForResult(); 3651 rv = c->callback.WaitForResult();
3643 EXPECT_EQ(buf->size(), rv); 3652 EXPECT_EQ(buf->size(), rv);
3644 3653
3645 // Destroy the transaction. 3654 // Destroy the transaction.
3646 delete c; 3655 delete c;
3647 3656
3648 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 3657 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
3649 3658
3650 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3659 EXPECT_EQ(2, cache.network_layer()->transaction_count());
(...skipping 12 matching lines...) Expand all
3663 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 3672 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
3664 "Content-Length: 22\n" 3673 "Content-Length: 22\n"
3665 "Etag: foopy\n"; 3674 "Etag: foopy\n";
3666 AddMockTransaction(&transaction); 3675 AddMockTransaction(&transaction);
3667 MockHttpRequest request(transaction); 3676 MockHttpRequest request(transaction);
3668 3677
3669 scoped_ptr<Context> c(new Context()); 3678 scoped_ptr<Context> c(new Context());
3670 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3679 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3671 EXPECT_EQ(net::OK, rv); 3680 EXPECT_EQ(net::OK, rv);
3672 3681
3673 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3682 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3674 if (rv == net::ERR_IO_PENDING) 3683 if (rv == net::ERR_IO_PENDING)
3675 rv = c->callback.WaitForResult(); 3684 rv = c->callback.WaitForResult();
3676 3685
3677 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3686 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3678 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3687 EXPECT_EQ(0, cache.disk_cache()->open_count());
3679 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3688 EXPECT_EQ(1, cache.disk_cache()->create_count());
3680 3689
3681 // Make sure that the entry has some data stored. 3690 // Make sure that the entry has some data stored.
3682 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); 3691 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
3683 rv = c->trans->Read(buf, buf->size(), &c->callback); 3692 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3684 if (rv == net::ERR_IO_PENDING) 3693 if (rv == net::ERR_IO_PENDING)
3685 rv = c->callback.WaitForResult(); 3694 rv = c->callback.WaitForResult();
3686 EXPECT_EQ(buf->size(), rv); 3695 EXPECT_EQ(buf->size(), rv);
3687 3696
3688 // We want to cancel the request when the transaction is busy. 3697 // We want to cancel the request when the transaction is busy.
3689 rv = c->trans->Read(buf, buf->size(), &c->callback); 3698 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3690 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3699 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3691 EXPECT_FALSE(c->callback.have_result()); 3700 EXPECT_FALSE(c->callback.have_result());
3692 3701
3693 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL); 3702 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL);
3694 3703
3695 // Destroy the transaction. 3704 // Destroy the transaction.
3696 c->trans.reset(); 3705 c->trans.reset();
3697 MockHttpCache::SetTestMode(0); 3706 MockHttpCache::SetTestMode(0);
3698 3707
3699 // Make sure that we don't invoke the callback. We may have an issue if the 3708 // Make sure that we don't invoke the callback. We may have an issue if the
(...skipping 23 matching lines...) Expand all
3723 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 3732 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
3724 "Content-Length: 22\n" 3733 "Content-Length: 22\n"
3725 "Etag: foopy\n"; 3734 "Etag: foopy\n";
3726 AddMockTransaction(&transaction); 3735 AddMockTransaction(&transaction);
3727 MockHttpRequest request(transaction); 3736 MockHttpRequest request(transaction);
3728 3737
3729 scoped_ptr<Context> c(new Context()); 3738 scoped_ptr<Context> c(new Context());
3730 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3739 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3731 EXPECT_EQ(net::OK, rv); 3740 EXPECT_EQ(net::OK, rv);
3732 3741
3733 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3742 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3734 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 3743 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
3735 3744
3736 // Read everything. 3745 // Read everything.
3737 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22)); 3746 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22));
3738 rv = c->trans->Read(buf, buf->size(), &c->callback); 3747 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3739 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); 3748 EXPECT_EQ(buf->size(), c->callback.GetResult(rv));
3740 3749
3741 // Destroy the transaction. 3750 // Destroy the transaction.
3742 c->trans.reset(); 3751 c->trans.reset();
3743 3752
3744 // Verify that the entry is not marked as truncated. 3753 // Verify that the entry is not marked as truncated.
3745 disk_cache::Entry* entry; 3754 disk_cache::Entry* entry;
3746 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); 3755 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
3747 net::HttpResponseInfo response; 3756 net::HttpResponseInfo response;
3748 bool truncated = true; 3757 bool truncated = true;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3854 std::string headers; 3863 std::string headers;
3855 MockTransaction transaction(kRangeGET_TransactionOK); 3864 MockTransaction transaction(kRangeGET_TransactionOK);
3856 transaction.request_headers = EXTRA_HEADER; 3865 transaction.request_headers = EXTRA_HEADER;
3857 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " 3866 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
3858 "rg: 50-59 rg: 60-69 rg: 70-79 "; 3867 "rg: 50-59 rg: 60-69 rg: 70-79 ";
3859 3868
3860 scoped_ptr<Context> c(new Context); 3869 scoped_ptr<Context> c(new Context);
3861 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); 3870 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
3862 3871
3863 MockHttpRequest request(transaction); 3872 MockHttpRequest request(transaction);
3864 int rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3873 int rv = c->trans->Start(
3874 &request, c->callback.callback(), net::BoundNetLog());
3865 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 3875 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
3866 3876
3867 // We should have checked with the server before finishing Start(). 3877 // We should have checked with the server before finishing Start().
3868 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3878 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3869 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3879 EXPECT_EQ(1, cache.disk_cache()->open_count());
3870 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3880 EXPECT_EQ(1, cache.disk_cache()->create_count());
3871 3881
3872 RemoveMockTransaction(&kRangeGET_TransactionOK); 3882 RemoveMockTransaction(&kRangeGET_TransactionOK);
3873 } 3883 }
3874 3884
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 CreateTruncatedEntry(raw_headers, &cache); 3934 CreateTruncatedEntry(raw_headers, &cache);
3925 3935
3926 // Now make a regular request. 3936 // Now make a regular request.
3927 MockTransaction transaction(kRangeGET_TransactionOK); 3937 MockTransaction transaction(kRangeGET_TransactionOK);
3928 transaction.request_headers = EXTRA_HEADER; 3938 transaction.request_headers = EXTRA_HEADER;
3929 3939
3930 MockHttpRequest request(transaction); 3940 MockHttpRequest request(transaction);
3931 Context* c = new Context(); 3941 Context* c = new Context();
3932 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); 3942 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
3933 3943
3934 int rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); 3944 int rv = c->trans->Start(
3945 &request, c->callback.callback(), net::BoundNetLog());
3935 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 3946 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
3936 3947
3937 // Read 20 bytes from the cache, and 10 from the net. 3948 // Read 20 bytes from the cache, and 10 from the net.
3938 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); 3949 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100));
3939 rv = c->trans->Read(buf, 20, &c->callback); 3950 rv = c->trans->Read(buf, 20, c->callback.callback());
3940 EXPECT_EQ(20, c->callback.GetResult(rv)); 3951 EXPECT_EQ(20, c->callback.GetResult(rv));
3941 rv = c->trans->Read(buf, 10, &c->callback); 3952 rv = c->trans->Read(buf, 10, c->callback.callback());
3942 EXPECT_EQ(10, c->callback.GetResult(rv)); 3953 EXPECT_EQ(10, c->callback.GetResult(rv));
3943 3954
3944 // At this point, we are already reading so canceling the request should leave 3955 // At this point, we are already reading so canceling the request should leave
3945 // a truncated one. 3956 // a truncated one.
3946 delete c; 3957 delete c;
3947 3958
3948 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3959 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3949 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3960 EXPECT_EQ(1, cache.disk_cache()->open_count());
3950 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3961 EXPECT_EQ(1, cache.disk_cache()->create_count());
3951 3962
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
4044 } 4055 }
4045 4056
4046 TEST(HttpCache, CachedRedirect) { 4057 TEST(HttpCache, CachedRedirect) {
4047 MockHttpCache cache; 4058 MockHttpCache cache;
4048 4059
4049 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction); 4060 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction);
4050 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently"; 4061 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently";
4051 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; 4062 kTestTransaction.response_headers = "Location: http://www.bar.com/\n";
4052 4063
4053 MockHttpRequest request(kTestTransaction); 4064 MockHttpRequest request(kTestTransaction);
4054 TestOldCompletionCallback callback; 4065 net::TestCompletionCallback callback;
4055 4066
4056 // write to the cache 4067 // write to the cache
4057 { 4068 {
4058 scoped_ptr<net::HttpTransaction> trans; 4069 scoped_ptr<net::HttpTransaction> trans;
4059 int rv = cache.http_cache()->CreateTransaction(&trans); 4070 int rv = cache.http_cache()->CreateTransaction(&trans);
4060 EXPECT_EQ(net::OK, rv); 4071 EXPECT_EQ(net::OK, rv);
4061 ASSERT_TRUE(trans.get()); 4072 ASSERT_TRUE(trans.get());
4062 4073
4063 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4074 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4064 if (rv == net::ERR_IO_PENDING) 4075 if (rv == net::ERR_IO_PENDING)
4065 rv = callback.WaitForResult(); 4076 rv = callback.WaitForResult();
4066 ASSERT_EQ(net::OK, rv); 4077 ASSERT_EQ(net::OK, rv);
4067 4078
4068 const net::HttpResponseInfo* info = trans->GetResponseInfo(); 4079 const net::HttpResponseInfo* info = trans->GetResponseInfo();
4069 ASSERT_TRUE(info); 4080 ASSERT_TRUE(info);
4070 4081
4071 EXPECT_EQ(info->headers->response_code(), 301); 4082 EXPECT_EQ(info->headers->response_code(), 301);
4072 4083
4073 std::string location; 4084 std::string location;
4074 info->headers->EnumerateHeader(NULL, "Location", &location); 4085 info->headers->EnumerateHeader(NULL, "Location", &location);
4075 EXPECT_EQ(location, "http://www.bar.com/"); 4086 EXPECT_EQ(location, "http://www.bar.com/");
4076 4087
4077 // Destroy transaction when going out of scope. We have not actually 4088 // Destroy transaction when going out of scope. We have not actually
4078 // read the response body -- want to test that it is still getting cached. 4089 // read the response body -- want to test that it is still getting cached.
4079 } 4090 }
4080 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 4091 EXPECT_EQ(1, cache.network_layer()->transaction_count());
4081 EXPECT_EQ(0, cache.disk_cache()->open_count()); 4092 EXPECT_EQ(0, cache.disk_cache()->open_count());
4082 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4093 EXPECT_EQ(1, cache.disk_cache()->create_count());
4083 4094
4084 // read from the cache 4095 // read from the cache
4085 { 4096 {
4086 scoped_ptr<net::HttpTransaction> trans; 4097 scoped_ptr<net::HttpTransaction> trans;
4087 int rv = cache.http_cache()->CreateTransaction(&trans); 4098 int rv = cache.http_cache()->CreateTransaction(&trans);
4088 EXPECT_EQ(net::OK, rv); 4099 EXPECT_EQ(net::OK, rv);
4089 ASSERT_TRUE(trans.get()); 4100 ASSERT_TRUE(trans.get());
4090 4101
4091 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4102 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4092 if (rv == net::ERR_IO_PENDING) 4103 if (rv == net::ERR_IO_PENDING)
4093 rv = callback.WaitForResult(); 4104 rv = callback.WaitForResult();
4094 ASSERT_EQ(net::OK, rv); 4105 ASSERT_EQ(net::OK, rv);
4095 4106
4096 const net::HttpResponseInfo* info = trans->GetResponseInfo(); 4107 const net::HttpResponseInfo* info = trans->GetResponseInfo();
4097 ASSERT_TRUE(info); 4108 ASSERT_TRUE(info);
4098 4109
4099 EXPECT_EQ(info->headers->response_code(), 301); 4110 EXPECT_EQ(info->headers->response_code(), 301);
4100 4111
4101 std::string location; 4112 std::string location;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
4199 transaction.cert_status = net::CERT_STATUS_REVOKED; 4210 transaction.cert_status = net::CERT_STATUS_REVOKED;
4200 ScopedMockTransaction scoped_transaction(transaction); 4211 ScopedMockTransaction scoped_transaction(transaction);
4201 4212
4202 // write to the cache 4213 // write to the cache
4203 RunTransactionTest(cache.http_cache(), transaction); 4214 RunTransactionTest(cache.http_cache(), transaction);
4204 4215
4205 // Test that it was not cached. 4216 // Test that it was not cached.
4206 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 4217 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
4207 4218
4208 MockHttpRequest request(transaction); 4219 MockHttpRequest request(transaction);
4209 TestOldCompletionCallback callback; 4220 net::TestCompletionCallback callback;
4210 4221
4211 scoped_ptr<net::HttpTransaction> trans; 4222 scoped_ptr<net::HttpTransaction> trans;
4212 int rv = cache.http_cache()->CreateTransaction(&trans); 4223 int rv = cache.http_cache()->CreateTransaction(&trans);
4213 EXPECT_EQ(net::OK, rv); 4224 EXPECT_EQ(net::OK, rv);
4214 ASSERT_TRUE(trans.get()); 4225 ASSERT_TRUE(trans.get());
4215 4226
4216 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4227 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4217 if (rv == net::ERR_IO_PENDING) 4228 if (rv == net::ERR_IO_PENDING)
4218 rv = callback.WaitForResult(); 4229 rv = callback.WaitForResult();
4219 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 4230 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
4220 } 4231 }
4221 4232
4222 // Ensure that we don't crash by if left-behind transactions. 4233 // Ensure that we don't crash by if left-behind transactions.
4223 TEST(HttpCache, OutlivedTransactions) { 4234 TEST(HttpCache, OutlivedTransactions) {
4224 MockHttpCache* cache = new MockHttpCache; 4235 MockHttpCache* cache = new MockHttpCache;
4225 4236
4226 scoped_ptr<net::HttpTransaction> trans; 4237 scoped_ptr<net::HttpTransaction> trans;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
4451 4462
4452 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 4463 EXPECT_EQ(3, cache.network_layer()->transaction_count());
4453 EXPECT_EQ(4, cache.disk_cache()->open_count()); 4464 EXPECT_EQ(4, cache.disk_cache()->open_count());
4454 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4465 EXPECT_EQ(1, cache.disk_cache()->create_count());
4455 } 4466 }
4456 4467
4457 // Tests that we don't mark entries as truncated when a filter detects the end 4468 // Tests that we don't mark entries as truncated when a filter detects the end
4458 // of the stream. 4469 // of the stream.
4459 TEST(HttpCache, FilterCompletion) { 4470 TEST(HttpCache, FilterCompletion) {
4460 MockHttpCache cache; 4471 MockHttpCache cache;
4461 TestOldCompletionCallback callback; 4472 net::TestCompletionCallback callback;
4462 4473
4463 { 4474 {
4464 scoped_ptr<net::HttpTransaction> trans; 4475 scoped_ptr<net::HttpTransaction> trans;
4465 int rv = cache.http_cache()->CreateTransaction(&trans); 4476 int rv = cache.http_cache()->CreateTransaction(&trans);
4466 EXPECT_EQ(net::OK, rv); 4477 EXPECT_EQ(net::OK, rv);
4467 4478
4468 MockHttpRequest request(kSimpleGET_Transaction); 4479 MockHttpRequest request(kSimpleGET_Transaction);
4469 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4480 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4470 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4481 EXPECT_EQ(net::OK, callback.GetResult(rv));
4471 4482
4472 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4483 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4473 rv = trans->Read(buf, 256, &callback); 4484 rv = trans->Read(buf, 256, callback.callback());
4474 EXPECT_GT(callback.GetResult(rv), 0); 4485 EXPECT_GT(callback.GetResult(rv), 0);
4475 4486
4476 // Now make sure that the entry is preserved. 4487 // Now make sure that the entry is preserved.
4477 trans->DoneReading(); 4488 trans->DoneReading();
4478 } 4489 }
4479 4490
4480 // Make sure that the ActiveEntry is gone. 4491 // Make sure that the ActiveEntry is gone.
4481 MessageLoop::current()->RunAllPending(); 4492 MessageLoop::current()->RunAllPending();
4482 4493
4483 // Read from the cache. 4494 // Read from the cache.
4484 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 4495 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
4485 4496
4486 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 4497 EXPECT_EQ(1, cache.network_layer()->transaction_count());
4487 EXPECT_EQ(1, cache.disk_cache()->open_count()); 4498 EXPECT_EQ(1, cache.disk_cache()->open_count());
4488 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4499 EXPECT_EQ(1, cache.disk_cache()->create_count());
4489 } 4500 }
4490 4501
4491 // Tests that we stop cachining when told. 4502 // Tests that we stop cachining when told.
4492 TEST(HttpCache, StopCachingDeletesEntry) { 4503 TEST(HttpCache, StopCachingDeletesEntry) {
4493 MockHttpCache cache; 4504 MockHttpCache cache;
4494 TestOldCompletionCallback callback; 4505 net::TestCompletionCallback callback;
4495 MockHttpRequest request(kSimpleGET_Transaction); 4506 MockHttpRequest request(kSimpleGET_Transaction);
4496 4507
4497 { 4508 {
4498 scoped_ptr<net::HttpTransaction> trans; 4509 scoped_ptr<net::HttpTransaction> trans;
4499 int rv = cache.http_cache()->CreateTransaction(&trans); 4510 int rv = cache.http_cache()->CreateTransaction(&trans);
4500 EXPECT_EQ(net::OK, rv); 4511 EXPECT_EQ(net::OK, rv);
4501 4512
4502 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4513 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4503 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4514 EXPECT_EQ(net::OK, callback.GetResult(rv));
4504 4515
4505 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4516 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4506 rv = trans->Read(buf, 10, &callback); 4517 rv = trans->Read(buf, 10, callback.callback());
4507 EXPECT_EQ(callback.GetResult(rv), 10); 4518 EXPECT_EQ(callback.GetResult(rv), 10);
4508 4519
4509 trans->StopCaching(); 4520 trans->StopCaching();
4510 4521
4511 // We should be able to keep reading. 4522 // We should be able to keep reading.
4512 rv = trans->Read(buf, 256, &callback); 4523 rv = trans->Read(buf, 256, callback.callback());
4513 EXPECT_GT(callback.GetResult(rv), 0); 4524 EXPECT_GT(callback.GetResult(rv), 0);
4514 rv = trans->Read(buf, 256, &callback); 4525 rv = trans->Read(buf, 256, callback.callback());
4515 EXPECT_EQ(callback.GetResult(rv), 0); 4526 EXPECT_EQ(callback.GetResult(rv), 0);
4516 } 4527 }
4517 4528
4518 // Make sure that the ActiveEntry is gone. 4529 // Make sure that the ActiveEntry is gone.
4519 MessageLoop::current()->RunAllPending(); 4530 MessageLoop::current()->RunAllPending();
4520 4531
4521 // Verify that the entry is gone. 4532 // Verify that the entry is gone.
4522 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 4533 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
4523 4534
4524 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 4535 EXPECT_EQ(2, cache.network_layer()->transaction_count());
4525 EXPECT_EQ(0, cache.disk_cache()->open_count()); 4536 EXPECT_EQ(0, cache.disk_cache()->open_count());
4526 EXPECT_EQ(2, cache.disk_cache()->create_count()); 4537 EXPECT_EQ(2, cache.disk_cache()->create_count());
4527 } 4538 }
4528 4539
4529 // Tests that when we are told to stop caching we don't throw away valid data. 4540 // Tests that when we are told to stop caching we don't throw away valid data.
4530 TEST(HttpCache, StopCachingSavesEntry) { 4541 TEST(HttpCache, StopCachingSavesEntry) {
4531 MockHttpCache cache; 4542 MockHttpCache cache;
4532 TestOldCompletionCallback callback; 4543 net::TestCompletionCallback callback;
4533 MockHttpRequest request(kSimpleGET_Transaction); 4544 MockHttpRequest request(kSimpleGET_Transaction);
4534 4545
4535 { 4546 {
4536 scoped_ptr<net::HttpTransaction> trans; 4547 scoped_ptr<net::HttpTransaction> trans;
4537 int rv = cache.http_cache()->CreateTransaction(&trans); 4548 int rv = cache.http_cache()->CreateTransaction(&trans);
4538 EXPECT_EQ(net::OK, rv); 4549 EXPECT_EQ(net::OK, rv);
4539 4550
4540 // Force a response that can be resumed. 4551 // Force a response that can be resumed.
4541 MockTransaction mock_transaction(kSimpleGET_Transaction); 4552 MockTransaction mock_transaction(kSimpleGET_Transaction);
4542 AddMockTransaction(&mock_transaction); 4553 AddMockTransaction(&mock_transaction);
4543 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" 4554 mock_transaction.response_headers = "Cache-Control: max-age=10000\n"
4544 "Content-Length: 42\n" 4555 "Content-Length: 42\n"
4545 "Etag: foo\n"; 4556 "Etag: foo\n";
4546 4557
4547 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4558 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4548 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4559 EXPECT_EQ(net::OK, callback.GetResult(rv));
4549 4560
4550 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4561 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4551 rv = trans->Read(buf, 10, &callback); 4562 rv = trans->Read(buf, 10, callback.callback());
4552 EXPECT_EQ(callback.GetResult(rv), 10); 4563 EXPECT_EQ(callback.GetResult(rv), 10);
4553 4564
4554 trans->StopCaching(); 4565 trans->StopCaching();
4555 4566
4556 // We should be able to keep reading. 4567 // We should be able to keep reading.
4557 rv = trans->Read(buf, 256, &callback); 4568 rv = trans->Read(buf, 256, callback.callback());
4558 EXPECT_GT(callback.GetResult(rv), 0); 4569 EXPECT_GT(callback.GetResult(rv), 0);
4559 rv = trans->Read(buf, 256, &callback); 4570 rv = trans->Read(buf, 256, callback.callback());
4560 EXPECT_EQ(callback.GetResult(rv), 0); 4571 EXPECT_EQ(callback.GetResult(rv), 0);
4561 4572
4562 RemoveMockTransaction(&mock_transaction); 4573 RemoveMockTransaction(&mock_transaction);
4563 } 4574 }
4564 4575
4565 // Verify that the entry is marked as incomplete. 4576 // Verify that the entry is marked as incomplete.
4566 disk_cache::Entry* entry; 4577 disk_cache::Entry* entry;
4567 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); 4578 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
4568 net::HttpResponseInfo response; 4579 net::HttpResponseInfo response;
4569 bool truncated = false; 4580 bool truncated = false;
4570 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 4581 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
4571 EXPECT_TRUE(truncated); 4582 EXPECT_TRUE(truncated);
4572 entry->Close(); 4583 entry->Close();
4573 } 4584 }
4574 4585
4575 // Tests that we handle truncated enries when StopCaching is called. 4586 // Tests that we handle truncated enries when StopCaching is called.
4576 TEST(HttpCache, StopCachingTruncatedEntry) { 4587 TEST(HttpCache, StopCachingTruncatedEntry) {
4577 MockHttpCache cache; 4588 MockHttpCache cache;
4578 TestOldCompletionCallback callback; 4589 net::TestCompletionCallback callback;
4579 MockHttpRequest request(kRangeGET_TransactionOK); 4590 MockHttpRequest request(kRangeGET_TransactionOK);
4580 request.extra_headers.Clear(); 4591 request.extra_headers.Clear();
4581 request.extra_headers.AddHeaderFromString(EXTRA_HEADER); 4592 request.extra_headers.AddHeaderFromString(EXTRA_HEADER);
4582 AddMockTransaction(&kRangeGET_TransactionOK); 4593 AddMockTransaction(&kRangeGET_TransactionOK);
4583 4594
4584 std::string raw_headers("HTTP/1.1 200 OK\n" 4595 std::string raw_headers("HTTP/1.1 200 OK\n"
4585 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 4596 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
4586 "ETag: \"foo\"\n" 4597 "ETag: \"foo\"\n"
4587 "Accept-Ranges: bytes\n" 4598 "Accept-Ranges: bytes\n"
4588 "Content-Length: 80\n"); 4599 "Content-Length: 80\n");
4589 CreateTruncatedEntry(raw_headers, &cache); 4600 CreateTruncatedEntry(raw_headers, &cache);
4590 4601
4591 { 4602 {
4592 // Now make a regular request. 4603 // Now make a regular request.
4593 scoped_ptr<net::HttpTransaction> trans; 4604 scoped_ptr<net::HttpTransaction> trans;
4594 int rv = cache.http_cache()->CreateTransaction(&trans); 4605 int rv = cache.http_cache()->CreateTransaction(&trans);
4595 EXPECT_EQ(net::OK, rv); 4606 EXPECT_EQ(net::OK, rv);
4596 4607
4597 rv = trans->Start(&request, &callback, net::BoundNetLog()); 4608 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4598 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4609 EXPECT_EQ(net::OK, callback.GetResult(rv));
4599 4610
4600 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4611 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4601 rv = trans->Read(buf, 10, &callback); 4612 rv = trans->Read(buf, 10, callback.callback());
4602 EXPECT_EQ(callback.GetResult(rv), 10); 4613 EXPECT_EQ(callback.GetResult(rv), 10);
4603 4614
4604 // This is actually going to do nothing. 4615 // This is actually going to do nothing.
4605 trans->StopCaching(); 4616 trans->StopCaching();
4606 4617
4607 // We should be able to keep reading. 4618 // We should be able to keep reading.
4608 rv = trans->Read(buf, 256, &callback); 4619 rv = trans->Read(buf, 256, callback.callback());
4609 EXPECT_GT(callback.GetResult(rv), 0); 4620 EXPECT_GT(callback.GetResult(rv), 0);
4610 rv = trans->Read(buf, 256, &callback); 4621 rv = trans->Read(buf, 256, callback.callback());
4611 EXPECT_GT(callback.GetResult(rv), 0); 4622 EXPECT_GT(callback.GetResult(rv), 0);
4612 rv = trans->Read(buf, 256, &callback); 4623 rv = trans->Read(buf, 256, callback.callback());
4613 EXPECT_EQ(callback.GetResult(rv), 0); 4624 EXPECT_EQ(callback.GetResult(rv), 0);
4614 } 4625 }
4615 4626
4616 // Verify that the disk entry was updated. 4627 // Verify that the disk entry was updated.
4617 disk_cache::Entry* entry; 4628 disk_cache::Entry* entry;
4618 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); 4629 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry));
4619 EXPECT_EQ(80, entry->GetDataSize(1)); 4630 EXPECT_EQ(80, entry->GetDataSize(1));
4620 bool truncated = true; 4631 bool truncated = true;
4621 net::HttpResponseInfo response; 4632 net::HttpResponseInfo response;
4622 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 4633 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
4623 EXPECT_FALSE(truncated); 4634 EXPECT_FALSE(truncated);
4624 entry->Close(); 4635 entry->Close();
4625 4636
4626 RemoveMockTransaction(&kRangeGET_TransactionOK); 4637 RemoveMockTransaction(&kRangeGET_TransactionOK);
4627 } 4638 }
4628 4639
4629 // Tests that we detect truncated resources from the net when there is 4640 // Tests that we detect truncated resources from the net when there is
4630 // a Content-Length header. 4641 // a Content-Length header.
4631 TEST(HttpCache, TruncatedByContentLength) { 4642 TEST(HttpCache, TruncatedByContentLength) {
4632 MockHttpCache cache; 4643 MockHttpCache cache;
4633 TestOldCompletionCallback callback; 4644 net::TestCompletionCallback callback;
4634 4645
4635 MockTransaction transaction(kSimpleGET_Transaction); 4646 MockTransaction transaction(kSimpleGET_Transaction);
4636 AddMockTransaction(&transaction); 4647 AddMockTransaction(&transaction);
4637 transaction.response_headers = "Cache-Control: max-age=10000\n" 4648 transaction.response_headers = "Cache-Control: max-age=10000\n"
4638 "Content-Length: 100\n"; 4649 "Content-Length: 100\n";
4639 RunTransactionTest(cache.http_cache(), transaction); 4650 RunTransactionTest(cache.http_cache(), transaction);
4640 RemoveMockTransaction(&transaction); 4651 RemoveMockTransaction(&transaction);
4641 4652
4642 // Read from the cache. 4653 // Read from the cache.
4643 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 4654 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
4644 4655
4645 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 4656 EXPECT_EQ(2, cache.network_layer()->transaction_count());
4646 EXPECT_EQ(0, cache.disk_cache()->open_count()); 4657 EXPECT_EQ(0, cache.disk_cache()->open_count());
4647 EXPECT_EQ(2, cache.disk_cache()->create_count()); 4658 EXPECT_EQ(2, cache.disk_cache()->create_count());
4648 } 4659 }
4649 4660
4650 // Tests that we actually flag entries as truncated when we detect an error 4661 // Tests that we actually flag entries as truncated when we detect an error
4651 // from the net. 4662 // from the net.
4652 TEST(HttpCache, TruncatedByContentLength2) { 4663 TEST(HttpCache, TruncatedByContentLength2) {
4653 MockHttpCache cache; 4664 MockHttpCache cache;
4654 TestOldCompletionCallback callback; 4665 net::TestCompletionCallback callback;
4655 4666
4656 MockTransaction transaction(kSimpleGET_Transaction); 4667 MockTransaction transaction(kSimpleGET_Transaction);
4657 AddMockTransaction(&transaction); 4668 AddMockTransaction(&transaction);
4658 transaction.response_headers = "Cache-Control: max-age=10000\n" 4669 transaction.response_headers = "Cache-Control: max-age=10000\n"
4659 "Content-Length: 100\n" 4670 "Content-Length: 100\n"
4660 "Etag: foo\n"; 4671 "Etag: foo\n";
4661 RunTransactionTest(cache.http_cache(), transaction); 4672 RunTransactionTest(cache.http_cache(), transaction);
4662 RemoveMockTransaction(&transaction); 4673 RemoveMockTransaction(&transaction);
4663 4674
4664 // Verify that the entry is marked as incomplete. 4675 // Verify that the entry is marked as incomplete.
4665 disk_cache::Entry* entry; 4676 disk_cache::Entry* entry;
4666 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); 4677 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
4667 net::HttpResponseInfo response; 4678 net::HttpResponseInfo response;
4668 bool truncated = false; 4679 bool truncated = false;
4669 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 4680 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
4670 EXPECT_TRUE(truncated); 4681 EXPECT_TRUE(truncated);
4671 entry->Close(); 4682 entry->Close();
4672 } 4683 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698