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

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

Issue 10736066: Adding histograms showing fraction of page load times (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 net::TestCompletionCallback 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, NULL);
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.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);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } // namespace 389 } // namespace
390 390
391 391
392 //----------------------------------------------------------------------------- 392 //-----------------------------------------------------------------------------
393 // Tests. 393 // Tests.
394 394
395 TEST(HttpCache, CreateThenDestroy) { 395 TEST(HttpCache, CreateThenDestroy) {
396 MockHttpCache cache; 396 MockHttpCache cache;
397 397
398 scoped_ptr<net::HttpTransaction> trans; 398 scoped_ptr<net::HttpTransaction> trans;
399 int rv = cache.http_cache()->CreateTransaction(&trans); 399 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
400 EXPECT_EQ(net::OK, rv); 400 EXPECT_EQ(net::OK, rv);
401 ASSERT_TRUE(trans.get()); 401 ASSERT_TRUE(trans.get());
402 } 402 }
403 403
404 TEST(HttpCache, GetBackend) { 404 TEST(HttpCache, GetBackend) {
405 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0)); 405 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0));
406 406
407 disk_cache::Backend* backend; 407 disk_cache::Backend* backend;
408 net::TestCompletionCallback cb; 408 net::TestCompletionCallback cb;
409 // This will lazily initialize the backend. 409 // This will lazily initialize the backend.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 } 493 }
494 494
495 // Tests that disk failures after the transaction has started don't cause the 495 // Tests that disk failures after the transaction has started don't cause the
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, NULL);
504 EXPECT_EQ(net::OK, rv); 504 EXPECT_EQ(net::OK, rv);
505 505
506 rv = c->trans->Start(&request, c->callback.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.
(...skipping 24 matching lines...) Expand all
538 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 538 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
539 539
540 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 540 EXPECT_EQ(1, cache.network_layer()->transaction_count());
541 EXPECT_EQ(0, cache.disk_cache()->open_count()); 541 EXPECT_EQ(0, cache.disk_cache()->open_count());
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, NULL);
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.callback(), net::BoundNetLog()); 552 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
553 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 553 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
554 554
555 // Now verify that the entry was removed from the cache. 555 // Now verify that the entry was removed from the cache.
556 cache.disk_cache()->set_soft_failures(false); 556 cache.disk_cache()->set_soft_failures(false);
557 557
558 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 558 EXPECT_EQ(2, cache.network_layer()->transaction_count());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 MockHttpCache cache; 638 MockHttpCache cache;
639 639
640 // force this transaction to read from the cache 640 // force this transaction to read from the cache
641 MockTransaction transaction(kSimpleGET_Transaction); 641 MockTransaction transaction(kSimpleGET_Transaction);
642 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 642 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
643 643
644 MockHttpRequest request(transaction); 644 MockHttpRequest request(transaction);
645 net::TestCompletionCallback callback; 645 net::TestCompletionCallback callback;
646 646
647 scoped_ptr<net::HttpTransaction> trans; 647 scoped_ptr<net::HttpTransaction> trans;
648 int rv = cache.http_cache()->CreateTransaction(&trans); 648 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
649 EXPECT_EQ(net::OK, rv); 649 EXPECT_EQ(net::OK, rv);
650 ASSERT_TRUE(trans.get()); 650 ASSERT_TRUE(trans.get());
651 651
652 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 652 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
653 if (rv == net::ERR_IO_PENDING) 653 if (rv == net::ERR_IO_PENDING)
654 rv = callback.WaitForResult(); 654 rv = callback.WaitForResult();
655 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 655 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
656 656
657 trans.reset(); 657 trans.reset();
658 658
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 864
865 MockHttpRequest request(kSimpleGET_Transaction); 865 MockHttpRequest request(kSimpleGET_Transaction);
866 866
867 std::vector<Context*> context_list; 867 std::vector<Context*> context_list;
868 const int kNumTransactions = 5; 868 const int kNumTransactions = 5;
869 869
870 for (int i = 0; i < kNumTransactions; ++i) { 870 for (int i = 0; i < kNumTransactions; ++i) {
871 context_list.push_back(new Context()); 871 context_list.push_back(new Context());
872 Context* c = context_list[i]; 872 Context* c = context_list[i];
873 873
874 c->result = cache.http_cache()->CreateTransaction(&c->trans); 874 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
875 EXPECT_EQ(net::OK, c->result); 875 EXPECT_EQ(net::OK, c->result);
876 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); 876 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState());
877 877
878 c->result = c->trans->Start( 878 c->result = c->trans->Start(
879 &request, c->callback.callback(), net::BoundNetLog()); 879 &request, c->callback.callback(), net::BoundNetLog());
880 } 880 }
881 881
882 // All requests are waiting for the active entry. 882 // All requests are waiting for the active entry.
883 for (int i = 0; i < kNumTransactions; ++i) { 883 for (int i = 0; i < kNumTransactions; ++i) {
884 Context* c = context_list[i]; 884 Context* c = context_list[i];
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 MockHttpRequest reader_request(kSimpleGET_Transaction); 932 MockHttpRequest reader_request(kSimpleGET_Transaction);
933 reader_request.load_flags = net::LOAD_ONLY_FROM_CACHE; 933 reader_request.load_flags = net::LOAD_ONLY_FROM_CACHE;
934 934
935 std::vector<Context*> context_list; 935 std::vector<Context*> context_list;
936 const int kNumTransactions = 5; 936 const int kNumTransactions = 5;
937 937
938 for (int i = 0; i < kNumTransactions; ++i) { 938 for (int i = 0; i < kNumTransactions; ++i) {
939 context_list.push_back(new Context()); 939 context_list.push_back(new Context());
940 Context* c = context_list[i]; 940 Context* c = context_list[i];
941 941
942 c->result = cache.http_cache()->CreateTransaction(&c->trans); 942 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
943 EXPECT_EQ(net::OK, c->result); 943 EXPECT_EQ(net::OK, c->result);
944 944
945 MockHttpRequest* this_request = &request; 945 MockHttpRequest* this_request = &request;
946 if (i == 1 || i == 2) 946 if (i == 1 || i == 2)
947 this_request = &reader_request; 947 this_request = &reader_request;
948 948
949 c->result = c->trans->Start( 949 c->result = c->trans->Start(
950 this_request, c->callback.callback(), net::BoundNetLog()); 950 this_request, c->callback.callback(), net::BoundNetLog());
951 } 951 }
952 952
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 MockHttpRequest writer_request(kSimpleGET_Transaction); 1017 MockHttpRequest writer_request(kSimpleGET_Transaction);
1018 writer_request.load_flags = net::LOAD_BYPASS_CACHE; 1018 writer_request.load_flags = net::LOAD_BYPASS_CACHE;
1019 1019
1020 ScopedVector<Context> context_list; 1020 ScopedVector<Context> context_list;
1021 const int kNumTransactions = 4; 1021 const int kNumTransactions = 4;
1022 1022
1023 for (int i = 0; i < kNumTransactions; ++i) { 1023 for (int i = 0; i < kNumTransactions; ++i) {
1024 context_list.push_back(new Context()); 1024 context_list.push_back(new Context());
1025 Context* c = context_list[i]; 1025 Context* c = context_list[i];
1026 1026
1027 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1027 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1028 EXPECT_EQ(net::OK, c->result); 1028 EXPECT_EQ(net::OK, c->result);
1029 1029
1030 MockHttpRequest* this_request = &request; 1030 MockHttpRequest* this_request = &request;
1031 if (i == 3) 1031 if (i == 3)
1032 this_request = &writer_request; 1032 this_request = &writer_request;
1033 1033
1034 c->result = c->trans->Start( 1034 c->result = c->trans->Start(
1035 this_request, c->callback.callback(), net::BoundNetLog()); 1035 this_request, c->callback.callback(), net::BoundNetLog());
1036 } 1036 }
1037 1037
(...skipping 27 matching lines...) Expand all
1065 FastTransactionServer request_handler; 1065 FastTransactionServer request_handler;
1066 AddMockTransaction(&kFastNoStoreGET_Transaction); 1066 AddMockTransaction(&kFastNoStoreGET_Transaction);
1067 1067
1068 std::vector<Context*> context_list; 1068 std::vector<Context*> context_list;
1069 const int kNumTransactions = 3; 1069 const int kNumTransactions = 3;
1070 1070
1071 for (int i = 0; i < kNumTransactions; ++i) { 1071 for (int i = 0; i < kNumTransactions; ++i) {
1072 context_list.push_back(new Context()); 1072 context_list.push_back(new Context());
1073 Context* c = context_list[i]; 1073 Context* c = context_list[i];
1074 1074
1075 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1075 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1076 EXPECT_EQ(net::OK, c->result); 1076 EXPECT_EQ(net::OK, c->result);
1077 1077
1078 c->result = c->trans->Start( 1078 c->result = c->trans->Start(
1079 &request, c->callback.callback(), net::BoundNetLog()); 1079 &request, c->callback.callback(), net::BoundNetLog());
1080 } 1080 }
1081 1081
1082 // Allow all requests to move from the Create queue to the active entry. 1082 // Allow all requests to move from the Create queue to the active entry.
1083 MessageLoop::current()->RunAllPending(); 1083 MessageLoop::current()->RunAllPending();
1084 1084
1085 // The first request should be a writer at this point, and the subsequent 1085 // The first request should be a writer at this point, and the subsequent
(...skipping 26 matching lines...) Expand all
1112 1112
1113 MockHttpRequest request(kSimpleGET_Transaction); 1113 MockHttpRequest request(kSimpleGET_Transaction);
1114 1114
1115 std::vector<Context*> context_list; 1115 std::vector<Context*> context_list;
1116 const int kNumTransactions = 2; 1116 const int kNumTransactions = 2;
1117 1117
1118 for (int i = 0; i < kNumTransactions; ++i) { 1118 for (int i = 0; i < kNumTransactions; ++i) {
1119 context_list.push_back(new Context()); 1119 context_list.push_back(new Context());
1120 Context* c = context_list[i]; 1120 Context* c = context_list[i];
1121 1121
1122 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1122 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1123 EXPECT_EQ(net::OK, c->result); 1123 EXPECT_EQ(net::OK, c->result);
1124 1124
1125 c->result = c->trans->Start( 1125 c->result = c->trans->Start(
1126 &request, c->callback.callback(), net::BoundNetLog()); 1126 &request, c->callback.callback(), net::BoundNetLog());
1127 } 1127 }
1128 1128
1129 // Allow all requests to move from the Create queue to the active entry. 1129 // Allow all requests to move from the Create queue to the active entry.
1130 MessageLoop::current()->RunAllPending(); 1130 MessageLoop::current()->RunAllPending();
1131 1131
1132 // The first request should be a writer at this point, and the subsequent 1132 // The first request should be a writer at this point, and the subsequent
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 1172
1173 MockHttpRequest request(kSimpleGET_Transaction); 1173 MockHttpRequest request(kSimpleGET_Transaction);
1174 1174
1175 std::vector<Context*> context_list; 1175 std::vector<Context*> context_list;
1176 const int kNumTransactions = 5; 1176 const int kNumTransactions = 5;
1177 1177
1178 for (int i = 0; i < kNumTransactions; i++) { 1178 for (int i = 0; i < kNumTransactions; i++) {
1179 context_list.push_back(new Context()); 1179 context_list.push_back(new Context());
1180 Context* c = context_list[i]; 1180 Context* c = context_list[i];
1181 1181
1182 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1182 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1183 EXPECT_EQ(net::OK, c->result); 1183 EXPECT_EQ(net::OK, c->result);
1184 1184
1185 c->result = c->trans->Start( 1185 c->result = c->trans->Start(
1186 &request, c->callback.callback(), net::BoundNetLog()); 1186 &request, c->callback.callback(), net::BoundNetLog());
1187 } 1187 }
1188 1188
1189 // The first request should be creating the disk cache entry and the others 1189 // The first request should be creating the disk cache entry and the others
1190 // should be pending. 1190 // should be pending.
1191 1191
1192 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 1192 EXPECT_EQ(0, cache.network_layer()->transaction_count());
(...skipping 30 matching lines...) Expand all
1223 } 1223 }
1224 1224
1225 // Tests that we can cancel a single request to open a disk cache entry. 1225 // Tests that we can cancel a single request to open a disk cache entry.
1226 TEST(HttpCache, SimpleGET_CancelCreate) { 1226 TEST(HttpCache, SimpleGET_CancelCreate) {
1227 MockHttpCache cache; 1227 MockHttpCache cache;
1228 1228
1229 MockHttpRequest request(kSimpleGET_Transaction); 1229 MockHttpRequest request(kSimpleGET_Transaction);
1230 1230
1231 Context* c = new Context(); 1231 Context* c = new Context();
1232 1232
1233 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1233 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1234 EXPECT_EQ(net::OK, c->result); 1234 EXPECT_EQ(net::OK, c->result);
1235 1235
1236 c->result = c->trans->Start( 1236 c->result = c->trans->Start(
1237 &request, c->callback.callback(), net::BoundNetLog()); 1237 &request, c->callback.callback(), net::BoundNetLog());
1238 EXPECT_EQ(net::ERR_IO_PENDING, c->result); 1238 EXPECT_EQ(net::ERR_IO_PENDING, c->result);
1239 1239
1240 // Release the reference that the mock disk cache keeps for this entry, so 1240 // Release the reference that the mock disk cache keeps for this entry, so
1241 // that we test that the http cache handles the cancellation correctly. 1241 // that we test that the http cache handles the cancellation correctly.
1242 cache.disk_cache()->ReleaseAll(); 1242 cache.disk_cache()->ReleaseAll();
1243 delete c; 1243 delete c;
1244 1244
1245 MessageLoop::current()->RunAllPending(); 1245 MessageLoop::current()->RunAllPending();
1246 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1246 EXPECT_EQ(1, cache.disk_cache()->create_count());
1247 } 1247 }
1248 1248
1249 // Tests that we delete/create entries even if multiple requests are queued. 1249 // Tests that we delete/create entries even if multiple requests are queued.
1250 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { 1250 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) {
1251 MockHttpCache cache; 1251 MockHttpCache cache;
1252 1252
1253 MockHttpRequest request(kSimpleGET_Transaction); 1253 MockHttpRequest request(kSimpleGET_Transaction);
1254 request.load_flags = net::LOAD_BYPASS_CACHE; 1254 request.load_flags = net::LOAD_BYPASS_CACHE;
1255 1255
1256 std::vector<Context*> context_list; 1256 std::vector<Context*> context_list;
1257 const int kNumTransactions = 5; 1257 const int kNumTransactions = 5;
1258 1258
1259 for (int i = 0; i < kNumTransactions; i++) { 1259 for (int i = 0; i < kNumTransactions; i++) {
1260 context_list.push_back(new Context()); 1260 context_list.push_back(new Context());
1261 Context* c = context_list[i]; 1261 Context* c = context_list[i];
1262 1262
1263 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1263 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1264 EXPECT_EQ(net::OK, c->result); 1264 EXPECT_EQ(net::OK, c->result);
1265 1265
1266 c->result = c->trans->Start( 1266 c->result = c->trans->Start(
1267 &request, c->callback.callback(), net::BoundNetLog()); 1267 &request, c->callback.callback(), net::BoundNetLog());
1268 } 1268 }
1269 1269
1270 // The first request should be deleting the disk cache entry and the others 1270 // The first request should be deleting the disk cache entry and the others
1271 // should be pending. 1271 // should be pending.
1272 1272
1273 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 1273 EXPECT_EQ(0, cache.network_layer()->transaction_count());
(...skipping 21 matching lines...) Expand all
1295 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { 1295 TEST(HttpCache, SimpleGET_AbandonedCacheRead) {
1296 MockHttpCache cache; 1296 MockHttpCache cache;
1297 1297
1298 // write to the cache 1298 // write to the cache
1299 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1299 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1300 1300
1301 MockHttpRequest request(kSimpleGET_Transaction); 1301 MockHttpRequest request(kSimpleGET_Transaction);
1302 net::TestCompletionCallback callback; 1302 net::TestCompletionCallback callback;
1303 1303
1304 scoped_ptr<net::HttpTransaction> trans; 1304 scoped_ptr<net::HttpTransaction> trans;
1305 int rv = cache.http_cache()->CreateTransaction(&trans); 1305 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
1306 EXPECT_EQ(net::OK, rv); 1306 EXPECT_EQ(net::OK, rv);
1307 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 1307 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
1308 if (rv == net::ERR_IO_PENDING) 1308 if (rv == net::ERR_IO_PENDING)
1309 rv = callback.WaitForResult(); 1309 rv = callback.WaitForResult();
1310 ASSERT_EQ(net::OK, rv); 1310 ASSERT_EQ(net::OK, rv);
1311 1311
1312 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 1312 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
1313 rv = trans->Read(buf, 256, callback.callback()); 1313 rv = trans->Read(buf, 256, callback.callback());
1314 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1314 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1315 1315
(...skipping 14 matching lines...) Expand all
1330 1330
1331 MockHttpRequest request(kSimpleGET_Transaction); 1331 MockHttpRequest request(kSimpleGET_Transaction);
1332 1332
1333 std::vector<Context*> context_list; 1333 std::vector<Context*> context_list;
1334 const int kNumTransactions = 5; 1334 const int kNumTransactions = 5;
1335 1335
1336 for (int i = 0; i < kNumTransactions; i++) { 1336 for (int i = 0; i < kNumTransactions; i++) {
1337 context_list.push_back(new Context()); 1337 context_list.push_back(new Context());
1338 Context* c = context_list[i]; 1338 Context* c = context_list[i];
1339 1339
1340 c->result = cache->http_cache()->CreateTransaction(&c->trans); 1340 c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL);
1341 EXPECT_EQ(net::OK, c->result); 1341 EXPECT_EQ(net::OK, c->result);
1342 1342
1343 c->result = c->trans->Start( 1343 c->result = c->trans->Start(
1344 &request, c->callback.callback(), net::BoundNetLog()); 1344 &request, c->callback.callback(), net::BoundNetLog());
1345 } 1345 }
1346 1346
1347 // The first request should be creating the disk cache entry and the others 1347 // The first request should be creating the disk cache entry and the others
1348 // should be pending. 1348 // should be pending.
1349 1349
1350 EXPECT_EQ(0, cache->network_layer()->transaction_count()); 1350 EXPECT_EQ(0, cache->network_layer()->transaction_count());
(...skipping 18 matching lines...) Expand all
1369 MockHttpRequest request1(kTypicalGET_Transaction); 1369 MockHttpRequest request1(kTypicalGET_Transaction);
1370 MockHttpRequest request2(kETagGET_Transaction); 1370 MockHttpRequest request2(kETagGET_Transaction);
1371 1371
1372 std::vector<Context*> context_list; 1372 std::vector<Context*> context_list;
1373 const int kNumTransactions = 3; 1373 const int kNumTransactions = 3;
1374 1374
1375 for (int i = 0; i < kNumTransactions; i++) { 1375 for (int i = 0; i < kNumTransactions; i++) {
1376 context_list.push_back(new Context()); 1376 context_list.push_back(new Context());
1377 Context* c = context_list[i]; 1377 Context* c = context_list[i];
1378 1378
1379 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1379 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1380 EXPECT_EQ(net::OK, c->result); 1380 EXPECT_EQ(net::OK, c->result);
1381 } 1381 }
1382 1382
1383 context_list[0]->result = context_list[0]->trans->Start( 1383 context_list[0]->result = context_list[0]->trans->Start(
1384 &request0, context_list[0]->callback.callback(), net::BoundNetLog()); 1384 &request0, context_list[0]->callback.callback(), net::BoundNetLog());
1385 context_list[1]->result = context_list[1]->trans->Start( 1385 context_list[1]->result = context_list[1]->trans->Start(
1386 &request1, context_list[1]->callback.callback(), net::BoundNetLog()); 1386 &request1, context_list[1]->callback.callback(), net::BoundNetLog());
1387 context_list[2]->result = context_list[2]->trans->Start( 1387 context_list[2]->result = context_list[2]->trans->Start(
1388 &request2, context_list[2]->callback.callback(), net::BoundNetLog()); 1388 &request2, context_list[2]->callback.callback(), net::BoundNetLog());
1389 1389
(...skipping 25 matching lines...) Expand all
1415 MockHttpRequest request1(kTypicalGET_Transaction); 1415 MockHttpRequest request1(kTypicalGET_Transaction);
1416 MockHttpRequest request2(kETagGET_Transaction); 1416 MockHttpRequest request2(kETagGET_Transaction);
1417 1417
1418 std::vector<Context*> context_list; 1418 std::vector<Context*> context_list;
1419 const int kNumTransactions = 3; 1419 const int kNumTransactions = 3;
1420 1420
1421 for (int i = 0; i < kNumTransactions; i++) { 1421 for (int i = 0; i < kNumTransactions; i++) {
1422 context_list.push_back(new Context()); 1422 context_list.push_back(new Context());
1423 Context* c = context_list[i]; 1423 Context* c = context_list[i];
1424 1424
1425 c->result = cache.http_cache()->CreateTransaction(&c->trans); 1425 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
1426 EXPECT_EQ(net::OK, c->result); 1426 EXPECT_EQ(net::OK, c->result);
1427 } 1427 }
1428 1428
1429 context_list[0]->result = context_list[0]->trans->Start( 1429 context_list[0]->result = context_list[0]->trans->Start(
1430 &request0, context_list[0]->callback.callback(), net::BoundNetLog()); 1430 &request0, context_list[0]->callback.callback(), net::BoundNetLog());
1431 context_list[1]->result = context_list[1]->trans->Start( 1431 context_list[1]->result = context_list[1]->trans->Start(
1432 &request1, context_list[1]->callback.callback(), net::BoundNetLog()); 1432 &request1, context_list[1]->callback.callback(), net::BoundNetLog());
1433 context_list[2]->result = context_list[2]->trans->Start( 1433 context_list[2]->result = context_list[2]->trans->Start(
1434 &request2, context_list[2]->callback.callback(), net::BoundNetLog()); 1434 &request2, context_list[2]->callback.callback(), net::BoundNetLog());
1435 1435
(...skipping 25 matching lines...) Expand all
1461 } 1461 }
1462 1462
1463 // Tests that we can delete the cache while creating the backend. 1463 // Tests that we can delete the cache while creating the backend.
1464 TEST(HttpCache, DeleteCacheWaitingForBackend) { 1464 TEST(HttpCache, DeleteCacheWaitingForBackend) {
1465 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 1465 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
1466 scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory)); 1466 scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory));
1467 1467
1468 MockHttpRequest request(kSimpleGET_Transaction); 1468 MockHttpRequest request(kSimpleGET_Transaction);
1469 1469
1470 scoped_ptr<Context> c(new Context()); 1470 scoped_ptr<Context> c(new Context());
1471 c->result = cache->http_cache()->CreateTransaction(&c->trans); 1471 c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL);
1472 EXPECT_EQ(net::OK, c->result); 1472 EXPECT_EQ(net::OK, c->result);
1473 1473
1474 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 1474 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
1475 1475
1476 // Just to make sure that everything is still pending. 1476 // Just to make sure that everything is still pending.
1477 MessageLoop::current()->RunAllPending(); 1477 MessageLoop::current()->RunAllPending();
1478 1478
1479 // The request should be creating the disk cache. 1479 // The request should be creating the disk cache.
1480 EXPECT_FALSE(c->callback.have_result()); 1480 EXPECT_FALSE(c->callback.have_result());
1481 1481
(...skipping 17 matching lines...) Expand all
1499 1499
1500 DeleteCacheCompletionCallback cb(cache); 1500 DeleteCacheCompletionCallback cb(cache);
1501 disk_cache::Backend* backend; 1501 disk_cache::Backend* backend;
1502 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); 1502 int rv = cache->http_cache()->GetBackend(&backend, cb.callback());
1503 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1503 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1504 1504
1505 // Now let's queue a regular transaction 1505 // Now let's queue a regular transaction
1506 MockHttpRequest request(kSimpleGET_Transaction); 1506 MockHttpRequest request(kSimpleGET_Transaction);
1507 1507
1508 scoped_ptr<Context> c(new Context()); 1508 scoped_ptr<Context> c(new Context());
1509 c->result = cache->http_cache()->CreateTransaction(&c->trans); 1509 c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL);
1510 EXPECT_EQ(net::OK, c->result); 1510 EXPECT_EQ(net::OK, c->result);
1511 1511
1512 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 1512 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
1513 1513
1514 // And another direct backend request. 1514 // And another direct backend request.
1515 net::TestCompletionCallback cb2; 1515 net::TestCompletionCallback cb2;
1516 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); 1516 rv = cache->http_cache()->GetBackend(&backend, cb2.callback());
1517 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1517 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1518 1518
1519 // Just to make sure that everything is still pending. 1519 // Just to make sure that everything is still pending.
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) { 2185 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) {
2186 MockHttpCache cache; 2186 MockHttpCache cache;
2187 2187
2188 MockTransaction transaction(kSimplePOST_Transaction); 2188 MockTransaction transaction(kSimplePOST_Transaction);
2189 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 2189 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
2190 2190
2191 MockHttpRequest request(transaction); 2191 MockHttpRequest request(transaction);
2192 net::TestCompletionCallback callback; 2192 net::TestCompletionCallback callback;
2193 2193
2194 scoped_ptr<net::HttpTransaction> trans; 2194 scoped_ptr<net::HttpTransaction> trans;
2195 int rv = cache.http_cache()->CreateTransaction(&trans); 2195 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
2196 EXPECT_EQ(net::OK, rv); 2196 EXPECT_EQ(net::OK, rv);
2197 ASSERT_TRUE(trans.get()); 2197 ASSERT_TRUE(trans.get());
2198 2198
2199 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 2199 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
2200 ASSERT_EQ(net::ERR_CACHE_MISS, callback.GetResult(rv)); 2200 ASSERT_EQ(net::ERR_CACHE_MISS, callback.GetResult(rv));
2201 2201
2202 trans.reset(); 2202 trans.reset();
2203 2203
2204 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 2204 EXPECT_EQ(0, cache.network_layer()->transaction_count());
2205 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2205 EXPECT_EQ(0, cache.disk_cache()->open_count());
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
3246 } 3246 }
3247 3247
3248 // Tests that we don't delete a sparse entry when we cancel a request. 3248 // Tests that we don't delete a sparse entry when we cancel a request.
3249 TEST(HttpCache, RangeGET_Cancel) { 3249 TEST(HttpCache, RangeGET_Cancel) {
3250 MockHttpCache cache; 3250 MockHttpCache cache;
3251 AddMockTransaction(&kRangeGET_TransactionOK); 3251 AddMockTransaction(&kRangeGET_TransactionOK);
3252 3252
3253 MockHttpRequest request(kRangeGET_TransactionOK); 3253 MockHttpRequest request(kRangeGET_TransactionOK);
3254 3254
3255 Context* c = new Context(); 3255 Context* c = new Context();
3256 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3256 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3257 EXPECT_EQ(net::OK, rv); 3257 EXPECT_EQ(net::OK, rv);
3258 3258
3259 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3259 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3260 if (rv == net::ERR_IO_PENDING) 3260 if (rv == net::ERR_IO_PENDING)
3261 rv = c->callback.WaitForResult(); 3261 rv = c->callback.WaitForResult();
3262 3262
3263 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3263 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3264 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3264 EXPECT_EQ(0, cache.disk_cache()->open_count());
3265 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3265 EXPECT_EQ(1, cache.disk_cache()->create_count());
3266 3266
(...skipping 18 matching lines...) Expand all
3285 // cancelling the previous one. 3285 // cancelling the previous one.
3286 TEST(HttpCache, RangeGET_Cancel2) { 3286 TEST(HttpCache, RangeGET_Cancel2) {
3287 MockHttpCache cache; 3287 MockHttpCache cache;
3288 AddMockTransaction(&kRangeGET_TransactionOK); 3288 AddMockTransaction(&kRangeGET_TransactionOK);
3289 3289
3290 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 3290 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
3291 MockHttpRequest request(kRangeGET_TransactionOK); 3291 MockHttpRequest request(kRangeGET_TransactionOK);
3292 request.load_flags |= net::LOAD_VALIDATE_CACHE; 3292 request.load_flags |= net::LOAD_VALIDATE_CACHE;
3293 3293
3294 Context* c = new Context(); 3294 Context* c = new Context();
3295 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3295 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3296 EXPECT_EQ(net::OK, rv); 3296 EXPECT_EQ(net::OK, rv);
3297 3297
3298 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3298 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3299 if (rv == net::ERR_IO_PENDING) 3299 if (rv == net::ERR_IO_PENDING)
3300 rv = c->callback.WaitForResult(); 3300 rv = c->callback.WaitForResult();
3301 3301
3302 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3302 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3303 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3303 EXPECT_EQ(1, cache.disk_cache()->open_count());
3304 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3304 EXPECT_EQ(1, cache.disk_cache()->create_count());
3305 3305
(...skipping 24 matching lines...) Expand all
3330 // a row, making sure that the second is waiting for the entry to be ready. 3330 // a row, making sure that the second is waiting for the entry to be ready.
3331 TEST(HttpCache, RangeGET_Cancel3) { 3331 TEST(HttpCache, RangeGET_Cancel3) {
3332 MockHttpCache cache; 3332 MockHttpCache cache;
3333 AddMockTransaction(&kRangeGET_TransactionOK); 3333 AddMockTransaction(&kRangeGET_TransactionOK);
3334 3334
3335 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 3335 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
3336 MockHttpRequest request(kRangeGET_TransactionOK); 3336 MockHttpRequest request(kRangeGET_TransactionOK);
3337 request.load_flags |= net::LOAD_VALIDATE_CACHE; 3337 request.load_flags |= net::LOAD_VALIDATE_CACHE;
3338 3338
3339 Context* c = new Context(); 3339 Context* c = new Context();
3340 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3340 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3341 EXPECT_EQ(net::OK, rv); 3341 EXPECT_EQ(net::OK, rv);
3342 3342
3343 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3343 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3344 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3344 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3345 rv = c->callback.WaitForResult(); 3345 rv = c->callback.WaitForResult();
3346 3346
3347 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3347 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3348 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3348 EXPECT_EQ(1, cache.disk_cache()->open_count());
3349 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3349 EXPECT_EQ(1, cache.disk_cache()->create_count());
3350 3350
3351 // Make sure that we revalidate the entry and read from the cache (a single 3351 // Make sure that we revalidate the entry and read from the cache (a single
3352 // read will return while waiting for the network). 3352 // read will return while waiting for the network).
3353 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); 3353 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
3354 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); 3354 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3355 EXPECT_EQ(5, c->callback.GetResult(rv)); 3355 EXPECT_EQ(5, c->callback.GetResult(rv));
3356 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); 3356 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3357 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3357 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3358 3358
3359 // Destroy the transaction before completing the read. 3359 // Destroy the transaction before completing the read.
3360 delete c; 3360 delete c;
3361 3361
3362 // We have the read and the delete (OnProcessPendingQueue) waiting on the 3362 // We have the read and the delete (OnProcessPendingQueue) waiting on the
3363 // message loop. This means that a new transaction will just reuse the same 3363 // message loop. This means that a new transaction will just reuse the same
3364 // active entry (no open or create). 3364 // active entry (no open or create).
3365 3365
3366 c = new Context(); 3366 c = new Context();
3367 rv = cache.http_cache()->CreateTransaction(&c->trans); 3367 rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3368 EXPECT_EQ(net::OK, rv); 3368 EXPECT_EQ(net::OK, rv);
3369 3369
3370 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3370 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3371 EXPECT_EQ(net::ERR_IO_PENDING, rv); 3371 EXPECT_EQ(net::ERR_IO_PENDING, rv);
3372 3372
3373 MockDiskEntry::IgnoreCallbacks(true); 3373 MockDiskEntry::IgnoreCallbacks(true);
3374 MessageLoop::current()->RunAllPending(); 3374 MessageLoop::current()->RunAllPending();
3375 MockDiskEntry::IgnoreCallbacks(false); 3375 MockDiskEntry::IgnoreCallbacks(false);
3376 3376
3377 // The new transaction is waiting for the query range callback. 3377 // The new transaction is waiting for the query range callback.
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
3638 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3638 EXPECT_EQ(1, cache.disk_cache()->create_count());
3639 3639
3640 // Force this transaction to read from the cache. 3640 // Force this transaction to read from the cache.
3641 MockTransaction transaction(kRangeGET_TransactionOK); 3641 MockTransaction transaction(kRangeGET_TransactionOK);
3642 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 3642 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
3643 3643
3644 MockHttpRequest request(transaction); 3644 MockHttpRequest request(transaction);
3645 net::TestCompletionCallback callback; 3645 net::TestCompletionCallback callback;
3646 3646
3647 scoped_ptr<net::HttpTransaction> trans; 3647 scoped_ptr<net::HttpTransaction> trans;
3648 int rv = cache.http_cache()->CreateTransaction(&trans); 3648 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
3649 EXPECT_EQ(net::OK, rv); 3649 EXPECT_EQ(net::OK, rv);
3650 ASSERT_TRUE(trans.get()); 3650 ASSERT_TRUE(trans.get());
3651 3651
3652 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 3652 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
3653 if (rv == net::ERR_IO_PENDING) 3653 if (rv == net::ERR_IO_PENDING)
3654 rv = callback.WaitForResult(); 3654 rv = callback.WaitForResult();
3655 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 3655 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
3656 3656
3657 trans.reset(); 3657 trans.reset();
3658 3658
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 } 3716 }
3717 3717
3718 // Tests that we delete an entry when the request is cancelled before starting 3718 // Tests that we delete an entry when the request is cancelled before starting
3719 // to read from the network. 3719 // to read from the network.
3720 TEST(HttpCache, DoomOnDestruction) { 3720 TEST(HttpCache, DoomOnDestruction) {
3721 MockHttpCache cache; 3721 MockHttpCache cache;
3722 3722
3723 MockHttpRequest request(kSimpleGET_Transaction); 3723 MockHttpRequest request(kSimpleGET_Transaction);
3724 3724
3725 Context* c = new Context(); 3725 Context* c = new Context();
3726 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3726 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3727 EXPECT_EQ(net::OK, rv); 3727 EXPECT_EQ(net::OK, rv);
3728 3728
3729 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3729 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3730 if (rv == net::ERR_IO_PENDING) 3730 if (rv == net::ERR_IO_PENDING)
3731 c->result = c->callback.WaitForResult(); 3731 c->result = c->callback.WaitForResult();
3732 3732
3733 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3733 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3734 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3734 EXPECT_EQ(0, cache.disk_cache()->open_count());
3735 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3735 EXPECT_EQ(1, cache.disk_cache()->create_count());
3736 3736
3737 // Destroy the transaction. We only have the headers so we should delete this 3737 // Destroy the transaction. We only have the headers so we should delete this
3738 // entry. 3738 // entry.
3739 delete c; 3739 delete c;
3740 3740
3741 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 3741 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
3742 3742
3743 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3743 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3744 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3744 EXPECT_EQ(0, cache.disk_cache()->open_count());
3745 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3745 EXPECT_EQ(2, cache.disk_cache()->create_count());
3746 } 3746 }
3747 3747
3748 // Tests that we delete an entry when the request is cancelled if the response 3748 // Tests that we delete an entry when the request is cancelled if the response
3749 // does not have content-length and strong validators. 3749 // does not have content-length and strong validators.
3750 TEST(HttpCache, DoomOnDestruction2) { 3750 TEST(HttpCache, DoomOnDestruction2) {
3751 MockHttpCache cache; 3751 MockHttpCache cache;
3752 3752
3753 MockHttpRequest request(kSimpleGET_Transaction); 3753 MockHttpRequest request(kSimpleGET_Transaction);
3754 3754
3755 Context* c = new Context(); 3755 Context* c = new Context();
3756 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3756 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3757 EXPECT_EQ(net::OK, rv); 3757 EXPECT_EQ(net::OK, rv);
3758 3758
3759 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3759 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3760 if (rv == net::ERR_IO_PENDING) 3760 if (rv == net::ERR_IO_PENDING)
3761 rv = c->callback.WaitForResult(); 3761 rv = c->callback.WaitForResult();
3762 3762
3763 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3763 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3764 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3764 EXPECT_EQ(0, cache.disk_cache()->open_count());
3765 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3765 EXPECT_EQ(1, cache.disk_cache()->create_count());
3766 3766
(...skipping 22 matching lines...) Expand all
3789 MockTransaction transaction(kSimpleGET_Transaction); 3789 MockTransaction transaction(kSimpleGET_Transaction);
3790 transaction.response_headers = 3790 transaction.response_headers =
3791 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 3791 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
3792 "Content-Length: 22\n" 3792 "Content-Length: 22\n"
3793 "Accept-Ranges: none\n" 3793 "Accept-Ranges: none\n"
3794 "Etag: foopy\n"; 3794 "Etag: foopy\n";
3795 AddMockTransaction(&transaction); 3795 AddMockTransaction(&transaction);
3796 MockHttpRequest request(transaction); 3796 MockHttpRequest request(transaction);
3797 3797
3798 Context* c = new Context(); 3798 Context* c = new Context();
3799 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3799 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3800 EXPECT_EQ(net::OK, rv); 3800 EXPECT_EQ(net::OK, rv);
3801 3801
3802 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3802 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3803 if (rv == net::ERR_IO_PENDING) 3803 if (rv == net::ERR_IO_PENDING)
3804 rv = c->callback.WaitForResult(); 3804 rv = c->callback.WaitForResult();
3805 3805
3806 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3806 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3807 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3807 EXPECT_EQ(0, cache.disk_cache()->open_count());
3808 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3808 EXPECT_EQ(1, cache.disk_cache()->create_count());
3809 3809
(...skipping 22 matching lines...) Expand all
3832 3832
3833 MockTransaction transaction(kSimpleGET_Transaction); 3833 MockTransaction transaction(kSimpleGET_Transaction);
3834 transaction.response_headers = 3834 transaction.response_headers =
3835 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 3835 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
3836 "Content-Length: 22\n" 3836 "Content-Length: 22\n"
3837 "Etag: foopy\n"; 3837 "Etag: foopy\n";
3838 AddMockTransaction(&transaction); 3838 AddMockTransaction(&transaction);
3839 MockHttpRequest request(transaction); 3839 MockHttpRequest request(transaction);
3840 3840
3841 scoped_ptr<Context> c(new Context()); 3841 scoped_ptr<Context> c(new Context());
3842 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3842 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3843 EXPECT_EQ(net::OK, rv); 3843 EXPECT_EQ(net::OK, rv);
3844 3844
3845 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3845 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3846 if (rv == net::ERR_IO_PENDING) 3846 if (rv == net::ERR_IO_PENDING)
3847 rv = c->callback.WaitForResult(); 3847 rv = c->callback.WaitForResult();
3848 3848
3849 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3849 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3850 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3850 EXPECT_EQ(0, cache.disk_cache()->open_count());
3851 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3851 EXPECT_EQ(1, cache.disk_cache()->create_count());
3852 3852
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3892 3892
3893 MockTransaction transaction(kSimpleGET_Transaction); 3893 MockTransaction transaction(kSimpleGET_Transaction);
3894 transaction.response_headers = 3894 transaction.response_headers =
3895 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 3895 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
3896 "Content-Length: 22\n" 3896 "Content-Length: 22\n"
3897 "Etag: foopy\n"; 3897 "Etag: foopy\n";
3898 AddMockTransaction(&transaction); 3898 AddMockTransaction(&transaction);
3899 MockHttpRequest request(transaction); 3899 MockHttpRequest request(transaction);
3900 3900
3901 scoped_ptr<Context> c(new Context()); 3901 scoped_ptr<Context> c(new Context());
3902 int rv = cache.http_cache()->CreateTransaction(&c->trans); 3902 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
3903 EXPECT_EQ(net::OK, rv); 3903 EXPECT_EQ(net::OK, rv);
3904 3904
3905 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 3905 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
3906 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 3906 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
3907 3907
3908 // Read everything. 3908 // Read everything.
3909 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22)); 3909 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22));
3910 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); 3910 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
3911 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); 3911 EXPECT_EQ(buf->size(), c->callback.GetResult(rv));
3912 3912
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4036 std::string response_headers(transaction.response_headers); 4036 std::string response_headers(transaction.response_headers);
4037 response_headers += ("Cache-Control: no-store\n"); 4037 response_headers += ("Cache-Control: no-store\n");
4038 transaction.response_headers = response_headers.c_str(); 4038 transaction.response_headers = response_headers.c_str();
4039 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " 4039 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
4040 "rg: 50-59 rg: 60-69 rg: 70-79 "; 4040 "rg: 50-59 rg: 60-69 rg: 70-79 ";
4041 AddMockTransaction(&transaction); 4041 AddMockTransaction(&transaction);
4042 4042
4043 MockHttpRequest request(transaction); 4043 MockHttpRequest request(transaction);
4044 Context* c = new Context(); 4044 Context* c = new Context();
4045 4045
4046 int rv = cache.http_cache()->CreateTransaction(&c->trans); 4046 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
4047 EXPECT_EQ(net::OK, rv); 4047 EXPECT_EQ(net::OK, rv);
4048 4048
4049 // Queue another request to this transaction. We have to start this request 4049 // Queue another request to this transaction. We have to start this request
4050 // before the first one gets the response from the server and dooms the entry, 4050 // before the first one gets the response from the server and dooms the entry,
4051 // otherwise it will just create a new entry without being queued to the first 4051 // otherwise it will just create a new entry without being queued to the first
4052 // request. 4052 // request.
4053 Context* pending = new Context(); 4053 Context* pending = new Context();
4054 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&pending->trans)); 4054 EXPECT_EQ(net::OK,
4055 cache.http_cache()->CreateTransaction(&pending->trans, NULL));
4055 4056
4056 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); 4057 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
4057 EXPECT_EQ(net::ERR_IO_PENDING, 4058 EXPECT_EQ(net::ERR_IO_PENDING,
4058 pending->trans->Start(&request, pending->callback.callback(), 4059 pending->trans->Start(&request, pending->callback.callback(),
4059 net::BoundNetLog())); 4060 net::BoundNetLog()));
4060 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 4061 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
4061 4062
4062 // Make sure that the entry has some data stored. 4063 // Make sure that the entry has some data stored.
4063 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); 4064 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
4064 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); 4065 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 CreateTruncatedEntry(raw_headers, &cache); 4129 CreateTruncatedEntry(raw_headers, &cache);
4129 4130
4130 // Now make a regular request. 4131 // Now make a regular request.
4131 std::string headers; 4132 std::string headers;
4132 MockTransaction transaction(kRangeGET_TransactionOK); 4133 MockTransaction transaction(kRangeGET_TransactionOK);
4133 transaction.request_headers = EXTRA_HEADER; 4134 transaction.request_headers = EXTRA_HEADER;
4134 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " 4135 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
4135 "rg: 50-59 rg: 60-69 rg: 70-79 "; 4136 "rg: 50-59 rg: 60-69 rg: 70-79 ";
4136 4137
4137 scoped_ptr<Context> c(new Context); 4138 scoped_ptr<Context> c(new Context);
4138 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); 4139 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans, NULL));
4139 4140
4140 MockHttpRequest request(transaction); 4141 MockHttpRequest request(transaction);
4141 int rv = c->trans->Start( 4142 int rv = c->trans->Start(
4142 &request, c->callback.callback(), net::BoundNetLog()); 4143 &request, c->callback.callback(), net::BoundNetLog());
4143 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 4144 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
4144 4145
4145 // We should have checked with the server before finishing Start(). 4146 // We should have checked with the server before finishing Start().
4146 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 4147 EXPECT_EQ(1, cache.network_layer()->transaction_count());
4147 EXPECT_EQ(1, cache.disk_cache()->open_count()); 4148 EXPECT_EQ(1, cache.disk_cache()->open_count());
4148 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4149 EXPECT_EQ(1, cache.disk_cache()->create_count());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4200 "Accept-Ranges: bytes\n" 4201 "Accept-Ranges: bytes\n"
4201 "Content-Length: 80\n"); 4202 "Content-Length: 80\n");
4202 CreateTruncatedEntry(raw_headers, &cache); 4203 CreateTruncatedEntry(raw_headers, &cache);
4203 4204
4204 // Now make a regular request. 4205 // Now make a regular request.
4205 MockTransaction transaction(kRangeGET_TransactionOK); 4206 MockTransaction transaction(kRangeGET_TransactionOK);
4206 transaction.request_headers = EXTRA_HEADER; 4207 transaction.request_headers = EXTRA_HEADER;
4207 4208
4208 MockHttpRequest request(transaction); 4209 MockHttpRequest request(transaction);
4209 Context* c = new Context(); 4210 Context* c = new Context();
4210 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); 4211 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans, NULL));
4211 4212
4212 int rv = c->trans->Start( 4213 int rv = c->trans->Start(
4213 &request, c->callback.callback(), net::BoundNetLog()); 4214 &request, c->callback.callback(), net::BoundNetLog());
4214 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); 4215 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
4215 4216
4216 // Read 20 bytes from the cache, and 10 from the net. 4217 // Read 20 bytes from the cache, and 10 from the net.
4217 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); 4218 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100));
4218 rv = c->trans->Read(buf, 20, c->callback.callback()); 4219 rv = c->trans->Read(buf, 20, c->callback.callback());
4219 EXPECT_EQ(20, c->callback.GetResult(rv)); 4220 EXPECT_EQ(20, c->callback.GetResult(rv));
4220 rv = c->trans->Read(buf, 10, c->callback.callback()); 4221 rv = c->trans->Read(buf, 10, c->callback.callback());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
4328 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction); 4329 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction);
4329 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently"; 4330 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently";
4330 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; 4331 kTestTransaction.response_headers = "Location: http://www.bar.com/\n";
4331 4332
4332 MockHttpRequest request(kTestTransaction); 4333 MockHttpRequest request(kTestTransaction);
4333 net::TestCompletionCallback callback; 4334 net::TestCompletionCallback callback;
4334 4335
4335 // write to the cache 4336 // write to the cache
4336 { 4337 {
4337 scoped_ptr<net::HttpTransaction> trans; 4338 scoped_ptr<net::HttpTransaction> trans;
4338 int rv = cache.http_cache()->CreateTransaction(&trans); 4339 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4339 EXPECT_EQ(net::OK, rv); 4340 EXPECT_EQ(net::OK, rv);
4340 ASSERT_TRUE(trans.get()); 4341 ASSERT_TRUE(trans.get());
4341 4342
4342 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4343 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4343 if (rv == net::ERR_IO_PENDING) 4344 if (rv == net::ERR_IO_PENDING)
4344 rv = callback.WaitForResult(); 4345 rv = callback.WaitForResult();
4345 ASSERT_EQ(net::OK, rv); 4346 ASSERT_EQ(net::OK, rv);
4346 4347
4347 const net::HttpResponseInfo* info = trans->GetResponseInfo(); 4348 const net::HttpResponseInfo* info = trans->GetResponseInfo();
4348 ASSERT_TRUE(info); 4349 ASSERT_TRUE(info);
4349 4350
4350 EXPECT_EQ(info->headers->response_code(), 301); 4351 EXPECT_EQ(info->headers->response_code(), 301);
4351 4352
4352 std::string location; 4353 std::string location;
4353 info->headers->EnumerateHeader(NULL, "Location", &location); 4354 info->headers->EnumerateHeader(NULL, "Location", &location);
4354 EXPECT_EQ(location, "http://www.bar.com/"); 4355 EXPECT_EQ(location, "http://www.bar.com/");
4355 4356
4356 // Destroy transaction when going out of scope. We have not actually 4357 // Destroy transaction when going out of scope. We have not actually
4357 // read the response body -- want to test that it is still getting cached. 4358 // read the response body -- want to test that it is still getting cached.
4358 } 4359 }
4359 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 4360 EXPECT_EQ(1, cache.network_layer()->transaction_count());
4360 EXPECT_EQ(0, cache.disk_cache()->open_count()); 4361 EXPECT_EQ(0, cache.disk_cache()->open_count());
4361 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4362 EXPECT_EQ(1, cache.disk_cache()->create_count());
4362 4363
4363 // read from the cache 4364 // read from the cache
4364 { 4365 {
4365 scoped_ptr<net::HttpTransaction> trans; 4366 scoped_ptr<net::HttpTransaction> trans;
4366 int rv = cache.http_cache()->CreateTransaction(&trans); 4367 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4367 EXPECT_EQ(net::OK, rv); 4368 EXPECT_EQ(net::OK, rv);
4368 ASSERT_TRUE(trans.get()); 4369 ASSERT_TRUE(trans.get());
4369 4370
4370 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4371 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4371 if (rv == net::ERR_IO_PENDING) 4372 if (rv == net::ERR_IO_PENDING)
4372 rv = callback.WaitForResult(); 4373 rv = callback.WaitForResult();
4373 ASSERT_EQ(net::OK, rv); 4374 ASSERT_EQ(net::OK, rv);
4374 4375
4375 const net::HttpResponseInfo* info = trans->GetResponseInfo(); 4376 const net::HttpResponseInfo* info = trans->GetResponseInfo();
4376 ASSERT_TRUE(info); 4377 ASSERT_TRUE(info);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
4481 // write to the cache 4482 // write to the cache
4482 RunTransactionTest(cache.http_cache(), transaction); 4483 RunTransactionTest(cache.http_cache(), transaction);
4483 4484
4484 // Test that it was not cached. 4485 // Test that it was not cached.
4485 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 4486 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
4486 4487
4487 MockHttpRequest request(transaction); 4488 MockHttpRequest request(transaction);
4488 net::TestCompletionCallback callback; 4489 net::TestCompletionCallback callback;
4489 4490
4490 scoped_ptr<net::HttpTransaction> trans; 4491 scoped_ptr<net::HttpTransaction> trans;
4491 int rv = cache.http_cache()->CreateTransaction(&trans); 4492 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4492 EXPECT_EQ(net::OK, rv); 4493 EXPECT_EQ(net::OK, rv);
4493 ASSERT_TRUE(trans.get()); 4494 ASSERT_TRUE(trans.get());
4494 4495
4495 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4496 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4496 if (rv == net::ERR_IO_PENDING) 4497 if (rv == net::ERR_IO_PENDING)
4497 rv = callback.WaitForResult(); 4498 rv = callback.WaitForResult();
4498 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 4499 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
4499 } 4500 }
4500 4501
4501 // Ensure that we don't crash by if left-behind transactions. 4502 // Ensure that we don't crash by if left-behind transactions.
4502 TEST(HttpCache, OutlivedTransactions) { 4503 TEST(HttpCache, OutlivedTransactions) {
4503 MockHttpCache* cache = new MockHttpCache; 4504 MockHttpCache* cache = new MockHttpCache;
4504 4505
4505 scoped_ptr<net::HttpTransaction> trans; 4506 scoped_ptr<net::HttpTransaction> trans;
4506 int rv = cache->http_cache()->CreateTransaction(&trans); 4507 int rv = cache->http_cache()->CreateTransaction(&trans, NULL);
4507 EXPECT_EQ(net::OK, rv); 4508 EXPECT_EQ(net::OK, rv);
4508 4509
4509 delete cache; 4510 delete cache;
4510 trans.reset(); 4511 trans.reset();
4511 } 4512 }
4512 4513
4513 // Test that the disabled mode works. 4514 // Test that the disabled mode works.
4514 TEST(HttpCache, CacheDisabledMode) { 4515 TEST(HttpCache, CacheDisabledMode) {
4515 MockHttpCache cache; 4516 MockHttpCache cache;
4516 4517
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4734 } 4735 }
4735 4736
4736 // Tests that we don't mark entries as truncated when a filter detects the end 4737 // Tests that we don't mark entries as truncated when a filter detects the end
4737 // of the stream. 4738 // of the stream.
4738 TEST(HttpCache, FilterCompletion) { 4739 TEST(HttpCache, FilterCompletion) {
4739 MockHttpCache cache; 4740 MockHttpCache cache;
4740 net::TestCompletionCallback callback; 4741 net::TestCompletionCallback callback;
4741 4742
4742 { 4743 {
4743 scoped_ptr<net::HttpTransaction> trans; 4744 scoped_ptr<net::HttpTransaction> trans;
4744 int rv = cache.http_cache()->CreateTransaction(&trans); 4745 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4745 EXPECT_EQ(net::OK, rv); 4746 EXPECT_EQ(net::OK, rv);
4746 4747
4747 MockHttpRequest request(kSimpleGET_Transaction); 4748 MockHttpRequest request(kSimpleGET_Transaction);
4748 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4749 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4749 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4750 EXPECT_EQ(net::OK, callback.GetResult(rv));
4750 4751
4751 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4752 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4752 rv = trans->Read(buf, 256, callback.callback()); 4753 rv = trans->Read(buf, 256, callback.callback());
4753 EXPECT_GT(callback.GetResult(rv), 0); 4754 EXPECT_GT(callback.GetResult(rv), 0);
4754 4755
(...skipping 13 matching lines...) Expand all
4768 } 4769 }
4769 4770
4770 // Tests that we stop cachining when told. 4771 // Tests that we stop cachining when told.
4771 TEST(HttpCache, StopCachingDeletesEntry) { 4772 TEST(HttpCache, StopCachingDeletesEntry) {
4772 MockHttpCache cache; 4773 MockHttpCache cache;
4773 net::TestCompletionCallback callback; 4774 net::TestCompletionCallback callback;
4774 MockHttpRequest request(kSimpleGET_Transaction); 4775 MockHttpRequest request(kSimpleGET_Transaction);
4775 4776
4776 { 4777 {
4777 scoped_ptr<net::HttpTransaction> trans; 4778 scoped_ptr<net::HttpTransaction> trans;
4778 int rv = cache.http_cache()->CreateTransaction(&trans); 4779 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4779 EXPECT_EQ(net::OK, rv); 4780 EXPECT_EQ(net::OK, rv);
4780 4781
4781 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4782 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4782 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4783 EXPECT_EQ(net::OK, callback.GetResult(rv));
4783 4784
4784 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4785 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4785 rv = trans->Read(buf, 10, callback.callback()); 4786 rv = trans->Read(buf, 10, callback.callback());
4786 EXPECT_EQ(callback.GetResult(rv), 10); 4787 EXPECT_EQ(callback.GetResult(rv), 10);
4787 4788
4788 trans->StopCaching(); 4789 trans->StopCaching();
(...skipping 17 matching lines...) Expand all
4806 } 4807 }
4807 4808
4808 // Tests that when we are told to stop caching we don't throw away valid data. 4809 // Tests that when we are told to stop caching we don't throw away valid data.
4809 TEST(HttpCache, StopCachingSavesEntry) { 4810 TEST(HttpCache, StopCachingSavesEntry) {
4810 MockHttpCache cache; 4811 MockHttpCache cache;
4811 net::TestCompletionCallback callback; 4812 net::TestCompletionCallback callback;
4812 MockHttpRequest request(kSimpleGET_Transaction); 4813 MockHttpRequest request(kSimpleGET_Transaction);
4813 4814
4814 { 4815 {
4815 scoped_ptr<net::HttpTransaction> trans; 4816 scoped_ptr<net::HttpTransaction> trans;
4816 int rv = cache.http_cache()->CreateTransaction(&trans); 4817 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4817 EXPECT_EQ(net::OK, rv); 4818 EXPECT_EQ(net::OK, rv);
4818 4819
4819 // Force a response that can be resumed. 4820 // Force a response that can be resumed.
4820 MockTransaction mock_transaction(kSimpleGET_Transaction); 4821 MockTransaction mock_transaction(kSimpleGET_Transaction);
4821 AddMockTransaction(&mock_transaction); 4822 AddMockTransaction(&mock_transaction);
4822 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" 4823 mock_transaction.response_headers = "Cache-Control: max-age=10000\n"
4823 "Content-Length: 42\n" 4824 "Content-Length: 42\n"
4824 "Etag: foo\n"; 4825 "Etag: foo\n";
4825 4826
4826 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4827 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4863 std::string raw_headers("HTTP/1.1 200 OK\n" 4864 std::string raw_headers("HTTP/1.1 200 OK\n"
4864 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 4865 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
4865 "ETag: \"foo\"\n" 4866 "ETag: \"foo\"\n"
4866 "Accept-Ranges: bytes\n" 4867 "Accept-Ranges: bytes\n"
4867 "Content-Length: 80\n"); 4868 "Content-Length: 80\n");
4868 CreateTruncatedEntry(raw_headers, &cache); 4869 CreateTruncatedEntry(raw_headers, &cache);
4869 4870
4870 { 4871 {
4871 // Now make a regular request. 4872 // Now make a regular request.
4872 scoped_ptr<net::HttpTransaction> trans; 4873 scoped_ptr<net::HttpTransaction> trans;
4873 int rv = cache.http_cache()->CreateTransaction(&trans); 4874 int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
4874 EXPECT_EQ(net::OK, rv); 4875 EXPECT_EQ(net::OK, rv);
4875 4876
4876 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 4877 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
4877 EXPECT_EQ(net::OK, callback.GetResult(rv)); 4878 EXPECT_EQ(net::OK, callback.GetResult(rv));
4878 4879
4879 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 4880 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
4880 rv = trans->Read(buf, 10, callback.callback()); 4881 rv = trans->Read(buf, 10, callback.callback());
4881 EXPECT_EQ(callback.GetResult(rv), 10); 4882 EXPECT_EQ(callback.GetResult(rv), 10);
4882 4883
4883 // This is actually going to do nothing. 4884 // This is actually going to do nothing.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4941 RemoveMockTransaction(&transaction); 4942 RemoveMockTransaction(&transaction);
4942 4943
4943 // Verify that the entry is marked as incomplete. 4944 // Verify that the entry is marked as incomplete.
4944 disk_cache::Entry* entry; 4945 disk_cache::Entry* entry;
4945 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); 4946 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
4946 net::HttpResponseInfo response; 4947 net::HttpResponseInfo response;
4947 bool truncated = false; 4948 bool truncated = false;
4948 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 4949 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
4949 EXPECT_TRUE(truncated); 4950 EXPECT_TRUE(truncated);
4950 entry->Close(); 4951 entry->Close();
4951 } 4952 }
rvargas (doing something else) 2012/07/23 22:22:36 We need a unit test for the delegate.
tburkard 2012/07/24 01:03:12 Since this is just instrumentation for testing, I
rvargas (doing something else) 2012/07/24 03:10:38 I have to disagree. This is a change in the interf
tburkard 2012/07/24 22:23:26 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698