OLD | NEW |
---|---|
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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "net/base/cache_type.h" | 13 #include "net/base/cache_type.h" |
14 #include "net/base/cert_status_flags.h" | 14 #include "net/base/cert_status_flags.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/base/net_log_unittest.h" | 18 #include "net/base/net_log_unittest.h" |
19 #include "net/base/ssl_cert_request_info.h" | 19 #include "net/base/ssl_cert_request_info.h" |
20 #include "net/disk_cache/disk_cache.h" | 20 #include "net/disk_cache/disk_cache.h" |
21 #include "net/http/http_byte_range.h" | 21 #include "net/http/http_byte_range.h" |
22 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
23 #include "net/http/http_request_info.h" | 23 #include "net/http/http_request_info.h" |
24 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
25 #include "net/http/http_response_info.h" | 25 #include "net/http/http_response_info.h" |
26 #include "net/http/http_transaction.h" | 26 #include "net/http/http_transaction.h" |
27 #include "net/http/http_transaction_delegate.h" | |
27 #include "net/http/http_transaction_unittest.h" | 28 #include "net/http/http_transaction_unittest.h" |
28 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
29 #include "net/http/mock_http_cache.h" | 30 #include "net/http/mock_http_cache.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 using base::Time; | 33 using base::Time; |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase { | 37 class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase { |
(...skipping 15 matching lines...) Expand all Loading... | |
52 | 53 |
53 MockHttpCache* cache_; | 54 MockHttpCache* cache_; |
54 net::CompletionCallback callback_; | 55 net::CompletionCallback callback_; |
55 | 56 |
56 DISALLOW_COPY_AND_ASSIGN(DeleteCacheCompletionCallback); | 57 DISALLOW_COPY_AND_ASSIGN(DeleteCacheCompletionCallback); |
57 }; | 58 }; |
58 | 59 |
59 //----------------------------------------------------------------------------- | 60 //----------------------------------------------------------------------------- |
60 // helpers | 61 // helpers |
61 | 62 |
63 class TestHttpTransactionDelegate : public net::HttpTransactionDelegate { | |
64 public: | |
65 TestHttpTransactionDelegate(int num_actions_to_observe) | |
66 : num_remaining_actions_to_observe_(num_actions_to_observe), | |
67 action_in_progress_(false) { | |
68 } | |
69 virtual ~TestHttpTransactionDelegate() { | |
70 EXPECT_EQ(num_remaining_actions_to_observe_, 0); | |
willchan no longer on Chromium
2012/07/26 20:03:38
You've got the params reversed. Should be expected
tburkard
2012/07/26 20:52:31
Done.
| |
71 EXPECT_EQ(action_in_progress_, false); | |
72 } | |
73 virtual void OnCacheActionStart() { | |
74 EXPECT_EQ(action_in_progress_, false); | |
75 EXPECT_GT(num_remaining_actions_to_observe_, 0); | |
76 num_remaining_actions_to_observe_--; | |
77 action_in_progress_ = true; | |
78 } | |
79 virtual void OnCacheActionFinish() { | |
80 EXPECT_EQ(action_in_progress_, true); | |
willchan no longer on Chromium
2012/07/26 20:03:38
EXPECT_TRUE.
tburkard
2012/07/26 20:52:31
Done.
| |
81 action_in_progress_ = false; | |
82 } | |
83 | |
84 private: | |
85 int num_remaining_actions_to_observe_; | |
86 bool action_in_progress_; | |
87 }; | |
88 | |
62 void ReadAndVerifyTransaction(net::HttpTransaction* trans, | 89 void ReadAndVerifyTransaction(net::HttpTransaction* trans, |
63 const MockTransaction& trans_info) { | 90 const MockTransaction& trans_info) { |
64 std::string content; | 91 std::string content; |
65 int rv = ReadTransaction(trans, &content); | 92 int rv = ReadTransaction(trans, &content); |
66 | 93 |
67 EXPECT_EQ(net::OK, rv); | 94 EXPECT_EQ(net::OK, rv); |
68 std::string expected(trans_info.data); | 95 std::string expected(trans_info.data); |
69 EXPECT_EQ(expected, content); | 96 EXPECT_EQ(expected, content); |
70 } | 97 } |
71 | 98 |
72 void RunTransactionTestWithRequestAndLog(net::HttpCache* cache, | 99 static const int kNoDelegateTransactionCheck = -1; |
73 const MockTransaction& trans_info, | 100 |
74 const MockHttpRequest& request, | 101 void RunTransactionTestWithRequestAndLogAndDelegate( |
75 net::HttpResponseInfo* response_info, | 102 net::HttpCache* cache, |
76 const net::BoundNetLog& net_log) { | 103 const MockTransaction& trans_info, |
104 const MockHttpRequest& request, | |
105 net::HttpResponseInfo* response_info, | |
106 const net::BoundNetLog& net_log, | |
107 int num_delegate_actions) { | |
77 net::TestCompletionCallback callback; | 108 net::TestCompletionCallback callback; |
78 | 109 |
79 // write to the cache | 110 // write to the cache |
80 | 111 |
81 scoped_ptr<net::HttpTransaction> trans; | 112 scoped_ptr<net::HttpTransaction> trans; |
82 int rv = cache->CreateTransaction(&trans); | 113 scoped_ptr<TestHttpTransactionDelegate> delegate; |
114 if (num_delegate_actions != kNoDelegateTransactionCheck) { | |
115 delegate.reset(new TestHttpTransactionDelegate(num_delegate_actions)); | |
116 } | |
117 int rv = cache->CreateTransaction(&trans, delegate.get()); | |
83 EXPECT_EQ(net::OK, rv); | 118 EXPECT_EQ(net::OK, rv); |
84 ASSERT_TRUE(trans.get()); | 119 ASSERT_TRUE(trans.get()); |
85 | 120 |
86 rv = trans->Start(&request, callback.callback(), net_log); | 121 rv = trans->Start(&request, callback.callback(), net_log); |
87 if (rv == net::ERR_IO_PENDING) | 122 if (rv == net::ERR_IO_PENDING) |
88 rv = callback.WaitForResult(); | 123 rv = callback.WaitForResult(); |
89 ASSERT_EQ(net::OK, rv); | 124 ASSERT_EQ(net::OK, rv); |
90 | 125 |
91 const net::HttpResponseInfo* response = trans->GetResponseInfo(); | 126 const net::HttpResponseInfo* response = trans->GetResponseInfo(); |
92 ASSERT_TRUE(response); | 127 ASSERT_TRUE(response); |
93 | 128 |
94 if (response_info) | 129 if (response_info) |
95 *response_info = *response; | 130 *response_info = *response; |
96 | 131 |
97 ReadAndVerifyTransaction(trans.get(), trans_info); | 132 ReadAndVerifyTransaction(trans.get(), trans_info); |
98 } | 133 } |
99 | 134 |
100 void RunTransactionTestWithRequest(net::HttpCache* cache, | 135 void RunTransactionTestWithRequest(net::HttpCache* cache, |
101 const MockTransaction& trans_info, | 136 const MockTransaction& trans_info, |
102 const MockHttpRequest& request, | 137 const MockHttpRequest& request, |
103 net::HttpResponseInfo* response_info) { | 138 net::HttpResponseInfo* response_info) { |
104 RunTransactionTestWithRequestAndLog(cache, trans_info, request, | 139 RunTransactionTestWithRequestAndLogAndDelegate( |
105 response_info, net::BoundNetLog()); | 140 cache, trans_info, request, response_info, net::BoundNetLog(), |
141 kNoDelegateTransactionCheck); | |
106 } | 142 } |
107 | 143 |
108 void RunTransactionTestWithLog(net::HttpCache* cache, | 144 void RunTransactionTestWithLog(net::HttpCache* cache, |
109 const MockTransaction& trans_info, | 145 const MockTransaction& trans_info, |
110 const net::BoundNetLog& log) { | 146 const net::BoundNetLog& log) { |
111 RunTransactionTestWithRequestAndLog( | 147 RunTransactionTestWithRequestAndLogAndDelegate( |
112 cache, trans_info, MockHttpRequest(trans_info), NULL, log); | 148 cache, trans_info, MockHttpRequest(trans_info), NULL, log, |
149 kNoDelegateTransactionCheck); | |
150 } | |
151 | |
152 void RunTransactionTestWithDelegate(net::HttpCache* cache, | |
153 const MockTransaction& trans_info, | |
154 int num_delegate_actions) { | |
155 RunTransactionTestWithRequestAndLogAndDelegate( | |
156 cache, trans_info, MockHttpRequest(trans_info), NULL, net::BoundNetLog(), | |
157 num_delegate_actions); | |
113 } | 158 } |
114 | 159 |
115 void RunTransactionTest(net::HttpCache* cache, | 160 void RunTransactionTest(net::HttpCache* cache, |
116 const MockTransaction& trans_info) { | 161 const MockTransaction& trans_info) { |
117 RunTransactionTestWithLog(cache, trans_info, net::BoundNetLog()); | 162 RunTransactionTestWithLog(cache, trans_info, net::BoundNetLog()); |
118 } | 163 } |
119 | 164 |
120 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, | 165 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, |
121 const MockTransaction& trans_info, | 166 const MockTransaction& trans_info, |
122 net::HttpResponseInfo* response) { | 167 net::HttpResponseInfo* response) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 } // namespace | 434 } // namespace |
390 | 435 |
391 | 436 |
392 //----------------------------------------------------------------------------- | 437 //----------------------------------------------------------------------------- |
393 // Tests. | 438 // Tests. |
394 | 439 |
395 TEST(HttpCache, CreateThenDestroy) { | 440 TEST(HttpCache, CreateThenDestroy) { |
396 MockHttpCache cache; | 441 MockHttpCache cache; |
397 | 442 |
398 scoped_ptr<net::HttpTransaction> trans; | 443 scoped_ptr<net::HttpTransaction> trans; |
399 int rv = cache.http_cache()->CreateTransaction(&trans); | 444 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
400 EXPECT_EQ(net::OK, rv); | 445 EXPECT_EQ(net::OK, rv); |
401 ASSERT_TRUE(trans.get()); | 446 ASSERT_TRUE(trans.get()); |
402 } | 447 } |
403 | 448 |
404 TEST(HttpCache, GetBackend) { | 449 TEST(HttpCache, GetBackend) { |
405 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0)); | 450 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0)); |
406 | 451 |
407 disk_cache::Backend* backend; | 452 disk_cache::Backend* backend; |
408 net::TestCompletionCallback cb; | 453 net::TestCompletionCallback cb; |
409 // This will lazily initialize the backend. | 454 // This will lazily initialize the backend. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 } | 538 } |
494 | 539 |
495 // Tests that disk failures after the transaction has started don't cause the | 540 // Tests that disk failures after the transaction has started don't cause the |
496 // request to fail. | 541 // request to fail. |
497 TEST(HttpCache, SimpleGETWithDiskFailures2) { | 542 TEST(HttpCache, SimpleGETWithDiskFailures2) { |
498 MockHttpCache cache; | 543 MockHttpCache cache; |
499 | 544 |
500 MockHttpRequest request(kSimpleGET_Transaction); | 545 MockHttpRequest request(kSimpleGET_Transaction); |
501 | 546 |
502 scoped_ptr<Context> c(new Context()); | 547 scoped_ptr<Context> c(new Context()); |
503 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 548 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
504 EXPECT_EQ(net::OK, rv); | 549 EXPECT_EQ(net::OK, rv); |
505 | 550 |
506 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 551 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
507 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 552 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
508 rv = c->callback.WaitForResult(); | 553 rv = c->callback.WaitForResult(); |
509 | 554 |
510 // Start failing request now. | 555 // Start failing request now. |
511 cache.disk_cache()->set_soft_failures(true); | 556 cache.disk_cache()->set_soft_failures(true); |
512 | 557 |
513 // We have to open the entry again to propagate the failure flag. | 558 // We have to open the entry again to propagate the failure flag. |
(...skipping 24 matching lines...) Expand all Loading... | |
538 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 583 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
539 | 584 |
540 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 585 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
541 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 586 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
542 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 587 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
543 | 588 |
544 cache.disk_cache()->set_soft_failures(true); | 589 cache.disk_cache()->set_soft_failures(true); |
545 | 590 |
546 // Now fail to read from the cache. | 591 // Now fail to read from the cache. |
547 scoped_ptr<Context> c(new Context()); | 592 scoped_ptr<Context> c(new Context()); |
548 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 593 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
549 EXPECT_EQ(net::OK, rv); | 594 EXPECT_EQ(net::OK, rv); |
550 | 595 |
551 MockHttpRequest request(kSimpleGET_Transaction); | 596 MockHttpRequest request(kSimpleGET_Transaction); |
552 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 597 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
553 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 598 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
554 | 599 |
555 // Now verify that the entry was removed from the cache. | 600 // Now verify that the entry was removed from the cache. |
556 cache.disk_cache()->set_soft_failures(false); | 601 cache.disk_cache()->set_soft_failures(false); |
557 | 602 |
558 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 603 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 MockHttpCache cache; | 683 MockHttpCache cache; |
639 | 684 |
640 // force this transaction to read from the cache | 685 // force this transaction to read from the cache |
641 MockTransaction transaction(kSimpleGET_Transaction); | 686 MockTransaction transaction(kSimpleGET_Transaction); |
642 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 687 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
643 | 688 |
644 MockHttpRequest request(transaction); | 689 MockHttpRequest request(transaction); |
645 net::TestCompletionCallback callback; | 690 net::TestCompletionCallback callback; |
646 | 691 |
647 scoped_ptr<net::HttpTransaction> trans; | 692 scoped_ptr<net::HttpTransaction> trans; |
648 int rv = cache.http_cache()->CreateTransaction(&trans); | 693 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
649 EXPECT_EQ(net::OK, rv); | 694 EXPECT_EQ(net::OK, rv); |
650 ASSERT_TRUE(trans.get()); | 695 ASSERT_TRUE(trans.get()); |
651 | 696 |
652 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 697 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
653 if (rv == net::ERR_IO_PENDING) | 698 if (rv == net::ERR_IO_PENDING) |
654 rv = callback.WaitForResult(); | 699 rv = callback.WaitForResult(); |
655 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 700 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
656 | 701 |
657 trans.reset(); | 702 trans.reset(); |
658 | 703 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 | 909 |
865 MockHttpRequest request(kSimpleGET_Transaction); | 910 MockHttpRequest request(kSimpleGET_Transaction); |
866 | 911 |
867 std::vector<Context*> context_list; | 912 std::vector<Context*> context_list; |
868 const int kNumTransactions = 5; | 913 const int kNumTransactions = 5; |
869 | 914 |
870 for (int i = 0; i < kNumTransactions; ++i) { | 915 for (int i = 0; i < kNumTransactions; ++i) { |
871 context_list.push_back(new Context()); | 916 context_list.push_back(new Context()); |
872 Context* c = context_list[i]; | 917 Context* c = context_list[i]; |
873 | 918 |
874 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 919 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
875 EXPECT_EQ(net::OK, c->result); | 920 EXPECT_EQ(net::OK, c->result); |
876 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); | 921 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); |
877 | 922 |
878 c->result = c->trans->Start( | 923 c->result = c->trans->Start( |
879 &request, c->callback.callback(), net::BoundNetLog()); | 924 &request, c->callback.callback(), net::BoundNetLog()); |
880 } | 925 } |
881 | 926 |
882 // All requests are waiting for the active entry. | 927 // All requests are waiting for the active entry. |
883 for (int i = 0; i < kNumTransactions; ++i) { | 928 for (int i = 0; i < kNumTransactions; ++i) { |
884 Context* c = context_list[i]; | 929 Context* c = context_list[i]; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 MockHttpRequest reader_request(kSimpleGET_Transaction); | 977 MockHttpRequest reader_request(kSimpleGET_Transaction); |
933 reader_request.load_flags = net::LOAD_ONLY_FROM_CACHE; | 978 reader_request.load_flags = net::LOAD_ONLY_FROM_CACHE; |
934 | 979 |
935 std::vector<Context*> context_list; | 980 std::vector<Context*> context_list; |
936 const int kNumTransactions = 5; | 981 const int kNumTransactions = 5; |
937 | 982 |
938 for (int i = 0; i < kNumTransactions; ++i) { | 983 for (int i = 0; i < kNumTransactions; ++i) { |
939 context_list.push_back(new Context()); | 984 context_list.push_back(new Context()); |
940 Context* c = context_list[i]; | 985 Context* c = context_list[i]; |
941 | 986 |
942 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 987 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
943 EXPECT_EQ(net::OK, c->result); | 988 EXPECT_EQ(net::OK, c->result); |
944 | 989 |
945 MockHttpRequest* this_request = &request; | 990 MockHttpRequest* this_request = &request; |
946 if (i == 1 || i == 2) | 991 if (i == 1 || i == 2) |
947 this_request = &reader_request; | 992 this_request = &reader_request; |
948 | 993 |
949 c->result = c->trans->Start( | 994 c->result = c->trans->Start( |
950 this_request, c->callback.callback(), net::BoundNetLog()); | 995 this_request, c->callback.callback(), net::BoundNetLog()); |
951 } | 996 } |
952 | 997 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 MockHttpRequest writer_request(kSimpleGET_Transaction); | 1062 MockHttpRequest writer_request(kSimpleGET_Transaction); |
1018 writer_request.load_flags = net::LOAD_BYPASS_CACHE; | 1063 writer_request.load_flags = net::LOAD_BYPASS_CACHE; |
1019 | 1064 |
1020 ScopedVector<Context> context_list; | 1065 ScopedVector<Context> context_list; |
1021 const int kNumTransactions = 4; | 1066 const int kNumTransactions = 4; |
1022 | 1067 |
1023 for (int i = 0; i < kNumTransactions; ++i) { | 1068 for (int i = 0; i < kNumTransactions; ++i) { |
1024 context_list.push_back(new Context()); | 1069 context_list.push_back(new Context()); |
1025 Context* c = context_list[i]; | 1070 Context* c = context_list[i]; |
1026 | 1071 |
1027 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1072 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1028 EXPECT_EQ(net::OK, c->result); | 1073 EXPECT_EQ(net::OK, c->result); |
1029 | 1074 |
1030 MockHttpRequest* this_request = &request; | 1075 MockHttpRequest* this_request = &request; |
1031 if (i == 3) | 1076 if (i == 3) |
1032 this_request = &writer_request; | 1077 this_request = &writer_request; |
1033 | 1078 |
1034 c->result = c->trans->Start( | 1079 c->result = c->trans->Start( |
1035 this_request, c->callback.callback(), net::BoundNetLog()); | 1080 this_request, c->callback.callback(), net::BoundNetLog()); |
1036 } | 1081 } |
1037 | 1082 |
(...skipping 27 matching lines...) Expand all Loading... | |
1065 FastTransactionServer request_handler; | 1110 FastTransactionServer request_handler; |
1066 AddMockTransaction(&kFastNoStoreGET_Transaction); | 1111 AddMockTransaction(&kFastNoStoreGET_Transaction); |
1067 | 1112 |
1068 std::vector<Context*> context_list; | 1113 std::vector<Context*> context_list; |
1069 const int kNumTransactions = 3; | 1114 const int kNumTransactions = 3; |
1070 | 1115 |
1071 for (int i = 0; i < kNumTransactions; ++i) { | 1116 for (int i = 0; i < kNumTransactions; ++i) { |
1072 context_list.push_back(new Context()); | 1117 context_list.push_back(new Context()); |
1073 Context* c = context_list[i]; | 1118 Context* c = context_list[i]; |
1074 | 1119 |
1075 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1120 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1076 EXPECT_EQ(net::OK, c->result); | 1121 EXPECT_EQ(net::OK, c->result); |
1077 | 1122 |
1078 c->result = c->trans->Start( | 1123 c->result = c->trans->Start( |
1079 &request, c->callback.callback(), net::BoundNetLog()); | 1124 &request, c->callback.callback(), net::BoundNetLog()); |
1080 } | 1125 } |
1081 | 1126 |
1082 // Allow all requests to move from the Create queue to the active entry. | 1127 // Allow all requests to move from the Create queue to the active entry. |
1083 MessageLoop::current()->RunAllPending(); | 1128 MessageLoop::current()->RunAllPending(); |
1084 | 1129 |
1085 // The first request should be a writer at this point, and the subsequent | 1130 // The first request should be a writer at this point, and the subsequent |
(...skipping 26 matching lines...) Expand all Loading... | |
1112 | 1157 |
1113 MockHttpRequest request(kSimpleGET_Transaction); | 1158 MockHttpRequest request(kSimpleGET_Transaction); |
1114 | 1159 |
1115 std::vector<Context*> context_list; | 1160 std::vector<Context*> context_list; |
1116 const int kNumTransactions = 2; | 1161 const int kNumTransactions = 2; |
1117 | 1162 |
1118 for (int i = 0; i < kNumTransactions; ++i) { | 1163 for (int i = 0; i < kNumTransactions; ++i) { |
1119 context_list.push_back(new Context()); | 1164 context_list.push_back(new Context()); |
1120 Context* c = context_list[i]; | 1165 Context* c = context_list[i]; |
1121 | 1166 |
1122 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1167 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1123 EXPECT_EQ(net::OK, c->result); | 1168 EXPECT_EQ(net::OK, c->result); |
1124 | 1169 |
1125 c->result = c->trans->Start( | 1170 c->result = c->trans->Start( |
1126 &request, c->callback.callback(), net::BoundNetLog()); | 1171 &request, c->callback.callback(), net::BoundNetLog()); |
1127 } | 1172 } |
1128 | 1173 |
1129 // Allow all requests to move from the Create queue to the active entry. | 1174 // Allow all requests to move from the Create queue to the active entry. |
1130 MessageLoop::current()->RunAllPending(); | 1175 MessageLoop::current()->RunAllPending(); |
1131 | 1176 |
1132 // The first request should be a writer at this point, and the subsequent | 1177 // 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 Loading... | |
1172 | 1217 |
1173 MockHttpRequest request(kSimpleGET_Transaction); | 1218 MockHttpRequest request(kSimpleGET_Transaction); |
1174 | 1219 |
1175 std::vector<Context*> context_list; | 1220 std::vector<Context*> context_list; |
1176 const int kNumTransactions = 5; | 1221 const int kNumTransactions = 5; |
1177 | 1222 |
1178 for (int i = 0; i < kNumTransactions; i++) { | 1223 for (int i = 0; i < kNumTransactions; i++) { |
1179 context_list.push_back(new Context()); | 1224 context_list.push_back(new Context()); |
1180 Context* c = context_list[i]; | 1225 Context* c = context_list[i]; |
1181 | 1226 |
1182 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1227 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1183 EXPECT_EQ(net::OK, c->result); | 1228 EXPECT_EQ(net::OK, c->result); |
1184 | 1229 |
1185 c->result = c->trans->Start( | 1230 c->result = c->trans->Start( |
1186 &request, c->callback.callback(), net::BoundNetLog()); | 1231 &request, c->callback.callback(), net::BoundNetLog()); |
1187 } | 1232 } |
1188 | 1233 |
1189 // The first request should be creating the disk cache entry and the others | 1234 // The first request should be creating the disk cache entry and the others |
1190 // should be pending. | 1235 // should be pending. |
1191 | 1236 |
1192 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1237 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
(...skipping 30 matching lines...) Expand all Loading... | |
1223 } | 1268 } |
1224 | 1269 |
1225 // Tests that we can cancel a single request to open a disk cache entry. | 1270 // Tests that we can cancel a single request to open a disk cache entry. |
1226 TEST(HttpCache, SimpleGET_CancelCreate) { | 1271 TEST(HttpCache, SimpleGET_CancelCreate) { |
1227 MockHttpCache cache; | 1272 MockHttpCache cache; |
1228 | 1273 |
1229 MockHttpRequest request(kSimpleGET_Transaction); | 1274 MockHttpRequest request(kSimpleGET_Transaction); |
1230 | 1275 |
1231 Context* c = new Context(); | 1276 Context* c = new Context(); |
1232 | 1277 |
1233 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1278 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1234 EXPECT_EQ(net::OK, c->result); | 1279 EXPECT_EQ(net::OK, c->result); |
1235 | 1280 |
1236 c->result = c->trans->Start( | 1281 c->result = c->trans->Start( |
1237 &request, c->callback.callback(), net::BoundNetLog()); | 1282 &request, c->callback.callback(), net::BoundNetLog()); |
1238 EXPECT_EQ(net::ERR_IO_PENDING, c->result); | 1283 EXPECT_EQ(net::ERR_IO_PENDING, c->result); |
1239 | 1284 |
1240 // Release the reference that the mock disk cache keeps for this entry, so | 1285 // 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. | 1286 // that we test that the http cache handles the cancellation correctly. |
1242 cache.disk_cache()->ReleaseAll(); | 1287 cache.disk_cache()->ReleaseAll(); |
1243 delete c; | 1288 delete c; |
1244 | 1289 |
1245 MessageLoop::current()->RunAllPending(); | 1290 MessageLoop::current()->RunAllPending(); |
1246 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1291 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1247 } | 1292 } |
1248 | 1293 |
1249 // Tests that we delete/create entries even if multiple requests are queued. | 1294 // Tests that we delete/create entries even if multiple requests are queued. |
1250 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { | 1295 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { |
1251 MockHttpCache cache; | 1296 MockHttpCache cache; |
1252 | 1297 |
1253 MockHttpRequest request(kSimpleGET_Transaction); | 1298 MockHttpRequest request(kSimpleGET_Transaction); |
1254 request.load_flags = net::LOAD_BYPASS_CACHE; | 1299 request.load_flags = net::LOAD_BYPASS_CACHE; |
1255 | 1300 |
1256 std::vector<Context*> context_list; | 1301 std::vector<Context*> context_list; |
1257 const int kNumTransactions = 5; | 1302 const int kNumTransactions = 5; |
1258 | 1303 |
1259 for (int i = 0; i < kNumTransactions; i++) { | 1304 for (int i = 0; i < kNumTransactions; i++) { |
1260 context_list.push_back(new Context()); | 1305 context_list.push_back(new Context()); |
1261 Context* c = context_list[i]; | 1306 Context* c = context_list[i]; |
1262 | 1307 |
1263 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1308 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1264 EXPECT_EQ(net::OK, c->result); | 1309 EXPECT_EQ(net::OK, c->result); |
1265 | 1310 |
1266 c->result = c->trans->Start( | 1311 c->result = c->trans->Start( |
1267 &request, c->callback.callback(), net::BoundNetLog()); | 1312 &request, c->callback.callback(), net::BoundNetLog()); |
1268 } | 1313 } |
1269 | 1314 |
1270 // The first request should be deleting the disk cache entry and the others | 1315 // The first request should be deleting the disk cache entry and the others |
1271 // should be pending. | 1316 // should be pending. |
1272 | 1317 |
1273 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1318 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
(...skipping 21 matching lines...) Expand all Loading... | |
1295 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { | 1340 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { |
1296 MockHttpCache cache; | 1341 MockHttpCache cache; |
1297 | 1342 |
1298 // write to the cache | 1343 // write to the cache |
1299 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1344 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1300 | 1345 |
1301 MockHttpRequest request(kSimpleGET_Transaction); | 1346 MockHttpRequest request(kSimpleGET_Transaction); |
1302 net::TestCompletionCallback callback; | 1347 net::TestCompletionCallback callback; |
1303 | 1348 |
1304 scoped_ptr<net::HttpTransaction> trans; | 1349 scoped_ptr<net::HttpTransaction> trans; |
1305 int rv = cache.http_cache()->CreateTransaction(&trans); | 1350 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
1306 EXPECT_EQ(net::OK, rv); | 1351 EXPECT_EQ(net::OK, rv); |
1307 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 1352 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
1308 if (rv == net::ERR_IO_PENDING) | 1353 if (rv == net::ERR_IO_PENDING) |
1309 rv = callback.WaitForResult(); | 1354 rv = callback.WaitForResult(); |
1310 ASSERT_EQ(net::OK, rv); | 1355 ASSERT_EQ(net::OK, rv); |
1311 | 1356 |
1312 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 1357 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
1313 rv = trans->Read(buf, 256, callback.callback()); | 1358 rv = trans->Read(buf, 256, callback.callback()); |
1314 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1359 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
1315 | 1360 |
(...skipping 14 matching lines...) Expand all Loading... | |
1330 | 1375 |
1331 MockHttpRequest request(kSimpleGET_Transaction); | 1376 MockHttpRequest request(kSimpleGET_Transaction); |
1332 | 1377 |
1333 std::vector<Context*> context_list; | 1378 std::vector<Context*> context_list; |
1334 const int kNumTransactions = 5; | 1379 const int kNumTransactions = 5; |
1335 | 1380 |
1336 for (int i = 0; i < kNumTransactions; i++) { | 1381 for (int i = 0; i < kNumTransactions; i++) { |
1337 context_list.push_back(new Context()); | 1382 context_list.push_back(new Context()); |
1338 Context* c = context_list[i]; | 1383 Context* c = context_list[i]; |
1339 | 1384 |
1340 c->result = cache->http_cache()->CreateTransaction(&c->trans); | 1385 c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL); |
1341 EXPECT_EQ(net::OK, c->result); | 1386 EXPECT_EQ(net::OK, c->result); |
1342 | 1387 |
1343 c->result = c->trans->Start( | 1388 c->result = c->trans->Start( |
1344 &request, c->callback.callback(), net::BoundNetLog()); | 1389 &request, c->callback.callback(), net::BoundNetLog()); |
1345 } | 1390 } |
1346 | 1391 |
1347 // The first request should be creating the disk cache entry and the others | 1392 // The first request should be creating the disk cache entry and the others |
1348 // should be pending. | 1393 // should be pending. |
1349 | 1394 |
1350 EXPECT_EQ(0, cache->network_layer()->transaction_count()); | 1395 EXPECT_EQ(0, cache->network_layer()->transaction_count()); |
(...skipping 18 matching lines...) Expand all Loading... | |
1369 MockHttpRequest request1(kTypicalGET_Transaction); | 1414 MockHttpRequest request1(kTypicalGET_Transaction); |
1370 MockHttpRequest request2(kETagGET_Transaction); | 1415 MockHttpRequest request2(kETagGET_Transaction); |
1371 | 1416 |
1372 std::vector<Context*> context_list; | 1417 std::vector<Context*> context_list; |
1373 const int kNumTransactions = 3; | 1418 const int kNumTransactions = 3; |
1374 | 1419 |
1375 for (int i = 0; i < kNumTransactions; i++) { | 1420 for (int i = 0; i < kNumTransactions; i++) { |
1376 context_list.push_back(new Context()); | 1421 context_list.push_back(new Context()); |
1377 Context* c = context_list[i]; | 1422 Context* c = context_list[i]; |
1378 | 1423 |
1379 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1424 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1380 EXPECT_EQ(net::OK, c->result); | 1425 EXPECT_EQ(net::OK, c->result); |
1381 } | 1426 } |
1382 | 1427 |
1383 context_list[0]->result = context_list[0]->trans->Start( | 1428 context_list[0]->result = context_list[0]->trans->Start( |
1384 &request0, context_list[0]->callback.callback(), net::BoundNetLog()); | 1429 &request0, context_list[0]->callback.callback(), net::BoundNetLog()); |
1385 context_list[1]->result = context_list[1]->trans->Start( | 1430 context_list[1]->result = context_list[1]->trans->Start( |
1386 &request1, context_list[1]->callback.callback(), net::BoundNetLog()); | 1431 &request1, context_list[1]->callback.callback(), net::BoundNetLog()); |
1387 context_list[2]->result = context_list[2]->trans->Start( | 1432 context_list[2]->result = context_list[2]->trans->Start( |
1388 &request2, context_list[2]->callback.callback(), net::BoundNetLog()); | 1433 &request2, context_list[2]->callback.callback(), net::BoundNetLog()); |
1389 | 1434 |
(...skipping 25 matching lines...) Expand all Loading... | |
1415 MockHttpRequest request1(kTypicalGET_Transaction); | 1460 MockHttpRequest request1(kTypicalGET_Transaction); |
1416 MockHttpRequest request2(kETagGET_Transaction); | 1461 MockHttpRequest request2(kETagGET_Transaction); |
1417 | 1462 |
1418 std::vector<Context*> context_list; | 1463 std::vector<Context*> context_list; |
1419 const int kNumTransactions = 3; | 1464 const int kNumTransactions = 3; |
1420 | 1465 |
1421 for (int i = 0; i < kNumTransactions; i++) { | 1466 for (int i = 0; i < kNumTransactions; i++) { |
1422 context_list.push_back(new Context()); | 1467 context_list.push_back(new Context()); |
1423 Context* c = context_list[i]; | 1468 Context* c = context_list[i]; |
1424 | 1469 |
1425 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1470 c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
1426 EXPECT_EQ(net::OK, c->result); | 1471 EXPECT_EQ(net::OK, c->result); |
1427 } | 1472 } |
1428 | 1473 |
1429 context_list[0]->result = context_list[0]->trans->Start( | 1474 context_list[0]->result = context_list[0]->trans->Start( |
1430 &request0, context_list[0]->callback.callback(), net::BoundNetLog()); | 1475 &request0, context_list[0]->callback.callback(), net::BoundNetLog()); |
1431 context_list[1]->result = context_list[1]->trans->Start( | 1476 context_list[1]->result = context_list[1]->trans->Start( |
1432 &request1, context_list[1]->callback.callback(), net::BoundNetLog()); | 1477 &request1, context_list[1]->callback.callback(), net::BoundNetLog()); |
1433 context_list[2]->result = context_list[2]->trans->Start( | 1478 context_list[2]->result = context_list[2]->trans->Start( |
1434 &request2, context_list[2]->callback.callback(), net::BoundNetLog()); | 1479 &request2, context_list[2]->callback.callback(), net::BoundNetLog()); |
1435 | 1480 |
(...skipping 25 matching lines...) Expand all Loading... | |
1461 } | 1506 } |
1462 | 1507 |
1463 // Tests that we can delete the cache while creating the backend. | 1508 // Tests that we can delete the cache while creating the backend. |
1464 TEST(HttpCache, DeleteCacheWaitingForBackend) { | 1509 TEST(HttpCache, DeleteCacheWaitingForBackend) { |
1465 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 1510 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
1466 scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory)); | 1511 scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory)); |
1467 | 1512 |
1468 MockHttpRequest request(kSimpleGET_Transaction); | 1513 MockHttpRequest request(kSimpleGET_Transaction); |
1469 | 1514 |
1470 scoped_ptr<Context> c(new Context()); | 1515 scoped_ptr<Context> c(new Context()); |
1471 c->result = cache->http_cache()->CreateTransaction(&c->trans); | 1516 c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL); |
1472 EXPECT_EQ(net::OK, c->result); | 1517 EXPECT_EQ(net::OK, c->result); |
1473 | 1518 |
1474 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 1519 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1475 | 1520 |
1476 // Just to make sure that everything is still pending. | 1521 // Just to make sure that everything is still pending. |
1477 MessageLoop::current()->RunAllPending(); | 1522 MessageLoop::current()->RunAllPending(); |
1478 | 1523 |
1479 // The request should be creating the disk cache. | 1524 // The request should be creating the disk cache. |
1480 EXPECT_FALSE(c->callback.have_result()); | 1525 EXPECT_FALSE(c->callback.have_result()); |
1481 | 1526 |
(...skipping 17 matching lines...) Expand all Loading... | |
1499 | 1544 |
1500 DeleteCacheCompletionCallback cb(cache); | 1545 DeleteCacheCompletionCallback cb(cache); |
1501 disk_cache::Backend* backend; | 1546 disk_cache::Backend* backend; |
1502 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); | 1547 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); |
1503 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1548 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
1504 | 1549 |
1505 // Now let's queue a regular transaction | 1550 // Now let's queue a regular transaction |
1506 MockHttpRequest request(kSimpleGET_Transaction); | 1551 MockHttpRequest request(kSimpleGET_Transaction); |
1507 | 1552 |
1508 scoped_ptr<Context> c(new Context()); | 1553 scoped_ptr<Context> c(new Context()); |
1509 c->result = cache->http_cache()->CreateTransaction(&c->trans); | 1554 c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL); |
1510 EXPECT_EQ(net::OK, c->result); | 1555 EXPECT_EQ(net::OK, c->result); |
1511 | 1556 |
1512 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 1557 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1513 | 1558 |
1514 // And another direct backend request. | 1559 // And another direct backend request. |
1515 net::TestCompletionCallback cb2; | 1560 net::TestCompletionCallback cb2; |
1516 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); | 1561 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); |
1517 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1562 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
1518 | 1563 |
1519 // Just to make sure that everything is still pending. | 1564 // Just to make sure that everything is still pending. |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2185 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) { | 2230 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) { |
2186 MockHttpCache cache; | 2231 MockHttpCache cache; |
2187 | 2232 |
2188 MockTransaction transaction(kSimplePOST_Transaction); | 2233 MockTransaction transaction(kSimplePOST_Transaction); |
2189 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 2234 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
2190 | 2235 |
2191 MockHttpRequest request(transaction); | 2236 MockHttpRequest request(transaction); |
2192 net::TestCompletionCallback callback; | 2237 net::TestCompletionCallback callback; |
2193 | 2238 |
2194 scoped_ptr<net::HttpTransaction> trans; | 2239 scoped_ptr<net::HttpTransaction> trans; |
2195 int rv = cache.http_cache()->CreateTransaction(&trans); | 2240 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
2196 EXPECT_EQ(net::OK, rv); | 2241 EXPECT_EQ(net::OK, rv); |
2197 ASSERT_TRUE(trans.get()); | 2242 ASSERT_TRUE(trans.get()); |
2198 | 2243 |
2199 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 2244 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
2200 ASSERT_EQ(net::ERR_CACHE_MISS, callback.GetResult(rv)); | 2245 ASSERT_EQ(net::ERR_CACHE_MISS, callback.GetResult(rv)); |
2201 | 2246 |
2202 trans.reset(); | 2247 trans.reset(); |
2203 | 2248 |
2204 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 2249 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
2205 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2250 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3246 } | 3291 } |
3247 | 3292 |
3248 // Tests that we don't delete a sparse entry when we cancel a request. | 3293 // Tests that we don't delete a sparse entry when we cancel a request. |
3249 TEST(HttpCache, RangeGET_Cancel) { | 3294 TEST(HttpCache, RangeGET_Cancel) { |
3250 MockHttpCache cache; | 3295 MockHttpCache cache; |
3251 AddMockTransaction(&kRangeGET_TransactionOK); | 3296 AddMockTransaction(&kRangeGET_TransactionOK); |
3252 | 3297 |
3253 MockHttpRequest request(kRangeGET_TransactionOK); | 3298 MockHttpRequest request(kRangeGET_TransactionOK); |
3254 | 3299 |
3255 Context* c = new Context(); | 3300 Context* c = new Context(); |
3256 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3301 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3257 EXPECT_EQ(net::OK, rv); | 3302 EXPECT_EQ(net::OK, rv); |
3258 | 3303 |
3259 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3304 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3260 if (rv == net::ERR_IO_PENDING) | 3305 if (rv == net::ERR_IO_PENDING) |
3261 rv = c->callback.WaitForResult(); | 3306 rv = c->callback.WaitForResult(); |
3262 | 3307 |
3263 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3308 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3264 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3309 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3265 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3310 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3266 | 3311 |
(...skipping 18 matching lines...) Expand all Loading... | |
3285 // cancelling the previous one. | 3330 // cancelling the previous one. |
3286 TEST(HttpCache, RangeGET_Cancel2) { | 3331 TEST(HttpCache, RangeGET_Cancel2) { |
3287 MockHttpCache cache; | 3332 MockHttpCache cache; |
3288 AddMockTransaction(&kRangeGET_TransactionOK); | 3333 AddMockTransaction(&kRangeGET_TransactionOK); |
3289 | 3334 |
3290 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 3335 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
3291 MockHttpRequest request(kRangeGET_TransactionOK); | 3336 MockHttpRequest request(kRangeGET_TransactionOK); |
3292 request.load_flags |= net::LOAD_VALIDATE_CACHE; | 3337 request.load_flags |= net::LOAD_VALIDATE_CACHE; |
3293 | 3338 |
3294 Context* c = new Context(); | 3339 Context* c = new Context(); |
3295 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3340 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3296 EXPECT_EQ(net::OK, rv); | 3341 EXPECT_EQ(net::OK, rv); |
3297 | 3342 |
3298 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3343 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3299 if (rv == net::ERR_IO_PENDING) | 3344 if (rv == net::ERR_IO_PENDING) |
3300 rv = c->callback.WaitForResult(); | 3345 rv = c->callback.WaitForResult(); |
3301 | 3346 |
3302 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3347 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3303 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3348 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3304 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3349 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3305 | 3350 |
(...skipping 24 matching lines...) Expand all Loading... | |
3330 // a row, making sure that the second is waiting for the entry to be ready. | 3375 // a row, making sure that the second is waiting for the entry to be ready. |
3331 TEST(HttpCache, RangeGET_Cancel3) { | 3376 TEST(HttpCache, RangeGET_Cancel3) { |
3332 MockHttpCache cache; | 3377 MockHttpCache cache; |
3333 AddMockTransaction(&kRangeGET_TransactionOK); | 3378 AddMockTransaction(&kRangeGET_TransactionOK); |
3334 | 3379 |
3335 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 3380 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
3336 MockHttpRequest request(kRangeGET_TransactionOK); | 3381 MockHttpRequest request(kRangeGET_TransactionOK); |
3337 request.load_flags |= net::LOAD_VALIDATE_CACHE; | 3382 request.load_flags |= net::LOAD_VALIDATE_CACHE; |
3338 | 3383 |
3339 Context* c = new Context(); | 3384 Context* c = new Context(); |
3340 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3385 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3341 EXPECT_EQ(net::OK, rv); | 3386 EXPECT_EQ(net::OK, rv); |
3342 | 3387 |
3343 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3388 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3344 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 3389 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
3345 rv = c->callback.WaitForResult(); | 3390 rv = c->callback.WaitForResult(); |
3346 | 3391 |
3347 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3392 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3348 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3393 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3349 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3394 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3350 | 3395 |
3351 // Make sure that we revalidate the entry and read from the cache (a single | 3396 // Make sure that we revalidate the entry and read from the cache (a single |
3352 // read will return while waiting for the network). | 3397 // read will return while waiting for the network). |
3353 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); | 3398 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); |
3354 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 3399 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); |
3355 EXPECT_EQ(5, c->callback.GetResult(rv)); | 3400 EXPECT_EQ(5, c->callback.GetResult(rv)); |
3356 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 3401 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); |
3357 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 3402 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
3358 | 3403 |
3359 // Destroy the transaction before completing the read. | 3404 // Destroy the transaction before completing the read. |
3360 delete c; | 3405 delete c; |
3361 | 3406 |
3362 // We have the read and the delete (OnProcessPendingQueue) waiting on the | 3407 // 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 | 3408 // message loop. This means that a new transaction will just reuse the same |
3364 // active entry (no open or create). | 3409 // active entry (no open or create). |
3365 | 3410 |
3366 c = new Context(); | 3411 c = new Context(); |
3367 rv = cache.http_cache()->CreateTransaction(&c->trans); | 3412 rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3368 EXPECT_EQ(net::OK, rv); | 3413 EXPECT_EQ(net::OK, rv); |
3369 | 3414 |
3370 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3415 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3371 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 3416 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
3372 | 3417 |
3373 MockDiskEntry::IgnoreCallbacks(true); | 3418 MockDiskEntry::IgnoreCallbacks(true); |
3374 MessageLoop::current()->RunAllPending(); | 3419 MessageLoop::current()->RunAllPending(); |
3375 MockDiskEntry::IgnoreCallbacks(false); | 3420 MockDiskEntry::IgnoreCallbacks(false); |
3376 | 3421 |
3377 // The new transaction is waiting for the query range callback. | 3422 // The new transaction is waiting for the query range callback. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3638 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3683 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3639 | 3684 |
3640 // Force this transaction to read from the cache. | 3685 // Force this transaction to read from the cache. |
3641 MockTransaction transaction(kRangeGET_TransactionOK); | 3686 MockTransaction transaction(kRangeGET_TransactionOK); |
3642 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 3687 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
3643 | 3688 |
3644 MockHttpRequest request(transaction); | 3689 MockHttpRequest request(transaction); |
3645 net::TestCompletionCallback callback; | 3690 net::TestCompletionCallback callback; |
3646 | 3691 |
3647 scoped_ptr<net::HttpTransaction> trans; | 3692 scoped_ptr<net::HttpTransaction> trans; |
3648 int rv = cache.http_cache()->CreateTransaction(&trans); | 3693 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
3649 EXPECT_EQ(net::OK, rv); | 3694 EXPECT_EQ(net::OK, rv); |
3650 ASSERT_TRUE(trans.get()); | 3695 ASSERT_TRUE(trans.get()); |
3651 | 3696 |
3652 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 3697 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
3653 if (rv == net::ERR_IO_PENDING) | 3698 if (rv == net::ERR_IO_PENDING) |
3654 rv = callback.WaitForResult(); | 3699 rv = callback.WaitForResult(); |
3655 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 3700 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
3656 | 3701 |
3657 trans.reset(); | 3702 trans.reset(); |
3658 | 3703 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3716 } | 3761 } |
3717 | 3762 |
3718 // Tests that we delete an entry when the request is cancelled before starting | 3763 // Tests that we delete an entry when the request is cancelled before starting |
3719 // to read from the network. | 3764 // to read from the network. |
3720 TEST(HttpCache, DoomOnDestruction) { | 3765 TEST(HttpCache, DoomOnDestruction) { |
3721 MockHttpCache cache; | 3766 MockHttpCache cache; |
3722 | 3767 |
3723 MockHttpRequest request(kSimpleGET_Transaction); | 3768 MockHttpRequest request(kSimpleGET_Transaction); |
3724 | 3769 |
3725 Context* c = new Context(); | 3770 Context* c = new Context(); |
3726 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3771 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3727 EXPECT_EQ(net::OK, rv); | 3772 EXPECT_EQ(net::OK, rv); |
3728 | 3773 |
3729 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3774 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3730 if (rv == net::ERR_IO_PENDING) | 3775 if (rv == net::ERR_IO_PENDING) |
3731 c->result = c->callback.WaitForResult(); | 3776 c->result = c->callback.WaitForResult(); |
3732 | 3777 |
3733 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3778 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3734 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3779 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3735 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3780 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3736 | 3781 |
3737 // Destroy the transaction. We only have the headers so we should delete this | 3782 // Destroy the transaction. We only have the headers so we should delete this |
3738 // entry. | 3783 // entry. |
3739 delete c; | 3784 delete c; |
3740 | 3785 |
3741 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 3786 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
3742 | 3787 |
3743 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3788 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3744 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3789 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3745 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3790 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
3746 } | 3791 } |
3747 | 3792 |
3748 // Tests that we delete an entry when the request is cancelled if the response | 3793 // Tests that we delete an entry when the request is cancelled if the response |
3749 // does not have content-length and strong validators. | 3794 // does not have content-length and strong validators. |
3750 TEST(HttpCache, DoomOnDestruction2) { | 3795 TEST(HttpCache, DoomOnDestruction2) { |
3751 MockHttpCache cache; | 3796 MockHttpCache cache; |
3752 | 3797 |
3753 MockHttpRequest request(kSimpleGET_Transaction); | 3798 MockHttpRequest request(kSimpleGET_Transaction); |
3754 | 3799 |
3755 Context* c = new Context(); | 3800 Context* c = new Context(); |
3756 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3801 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3757 EXPECT_EQ(net::OK, rv); | 3802 EXPECT_EQ(net::OK, rv); |
3758 | 3803 |
3759 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3804 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3760 if (rv == net::ERR_IO_PENDING) | 3805 if (rv == net::ERR_IO_PENDING) |
3761 rv = c->callback.WaitForResult(); | 3806 rv = c->callback.WaitForResult(); |
3762 | 3807 |
3763 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3808 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3764 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3809 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3765 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3810 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3766 | 3811 |
(...skipping 22 matching lines...) Expand all Loading... | |
3789 MockTransaction transaction(kSimpleGET_Transaction); | 3834 MockTransaction transaction(kSimpleGET_Transaction); |
3790 transaction.response_headers = | 3835 transaction.response_headers = |
3791 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 3836 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
3792 "Content-Length: 22\n" | 3837 "Content-Length: 22\n" |
3793 "Accept-Ranges: none\n" | 3838 "Accept-Ranges: none\n" |
3794 "Etag: \"foopy\"\n"; | 3839 "Etag: \"foopy\"\n"; |
3795 AddMockTransaction(&transaction); | 3840 AddMockTransaction(&transaction); |
3796 MockHttpRequest request(transaction); | 3841 MockHttpRequest request(transaction); |
3797 | 3842 |
3798 Context* c = new Context(); | 3843 Context* c = new Context(); |
3799 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3844 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3800 EXPECT_EQ(net::OK, rv); | 3845 EXPECT_EQ(net::OK, rv); |
3801 | 3846 |
3802 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3847 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3803 if (rv == net::ERR_IO_PENDING) | 3848 if (rv == net::ERR_IO_PENDING) |
3804 rv = c->callback.WaitForResult(); | 3849 rv = c->callback.WaitForResult(); |
3805 | 3850 |
3806 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3851 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3807 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3852 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3808 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3853 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3809 | 3854 |
(...skipping 22 matching lines...) Expand all Loading... | |
3832 | 3877 |
3833 MockTransaction transaction(kSimpleGET_Transaction); | 3878 MockTransaction transaction(kSimpleGET_Transaction); |
3834 transaction.response_headers = | 3879 transaction.response_headers = |
3835 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 3880 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
3836 "Content-Length: 22\n" | 3881 "Content-Length: 22\n" |
3837 "Etag: \"foopy\"\n"; | 3882 "Etag: \"foopy\"\n"; |
3838 AddMockTransaction(&transaction); | 3883 AddMockTransaction(&transaction); |
3839 MockHttpRequest request(transaction); | 3884 MockHttpRequest request(transaction); |
3840 | 3885 |
3841 scoped_ptr<Context> c(new Context()); | 3886 scoped_ptr<Context> c(new Context()); |
3842 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3887 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3843 EXPECT_EQ(net::OK, rv); | 3888 EXPECT_EQ(net::OK, rv); |
3844 | 3889 |
3845 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3890 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3846 if (rv == net::ERR_IO_PENDING) | 3891 if (rv == net::ERR_IO_PENDING) |
3847 rv = c->callback.WaitForResult(); | 3892 rv = c->callback.WaitForResult(); |
3848 | 3893 |
3849 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3894 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3850 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3895 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3851 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3896 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3852 | 3897 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3892 | 3937 |
3893 MockTransaction transaction(kSimpleGET_Transaction); | 3938 MockTransaction transaction(kSimpleGET_Transaction); |
3894 transaction.response_headers = | 3939 transaction.response_headers = |
3895 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 3940 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
3896 "Content-Length: 22\n" | 3941 "Content-Length: 22\n" |
3897 "Etag: \"foopy\"\n"; | 3942 "Etag: \"foopy\"\n"; |
3898 AddMockTransaction(&transaction); | 3943 AddMockTransaction(&transaction); |
3899 MockHttpRequest request(transaction); | 3944 MockHttpRequest request(transaction); |
3900 | 3945 |
3901 scoped_ptr<Context> c(new Context()); | 3946 scoped_ptr<Context> c(new Context()); |
3902 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3947 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
3903 EXPECT_EQ(net::OK, rv); | 3948 EXPECT_EQ(net::OK, rv); |
3904 | 3949 |
3905 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 3950 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
3906 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 3951 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
3907 | 3952 |
3908 // Read everything. | 3953 // Read everything. |
3909 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22)); | 3954 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22)); |
3910 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 3955 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); |
3911 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); | 3956 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); |
3912 | 3957 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4036 std::string response_headers(transaction.response_headers); | 4081 std::string response_headers(transaction.response_headers); |
4037 response_headers += ("Cache-Control: no-store\n"); | 4082 response_headers += ("Cache-Control: no-store\n"); |
4038 transaction.response_headers = response_headers.c_str(); | 4083 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 " | 4084 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 "; | 4085 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
4041 AddMockTransaction(&transaction); | 4086 AddMockTransaction(&transaction); |
4042 | 4087 |
4043 MockHttpRequest request(transaction); | 4088 MockHttpRequest request(transaction); |
4044 Context* c = new Context(); | 4089 Context* c = new Context(); |
4045 | 4090 |
4046 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 4091 int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL); |
4047 EXPECT_EQ(net::OK, rv); | 4092 EXPECT_EQ(net::OK, rv); |
4048 | 4093 |
4049 // Queue another request to this transaction. We have to start this request | 4094 // 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, | 4095 // 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 | 4096 // otherwise it will just create a new entry without being queued to the first |
4052 // request. | 4097 // request. |
4053 Context* pending = new Context(); | 4098 Context* pending = new Context(); |
4054 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&pending->trans)); | 4099 EXPECT_EQ(net::OK, |
4100 cache.http_cache()->CreateTransaction(&pending->trans, NULL)); | |
4055 | 4101 |
4056 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4102 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
4057 EXPECT_EQ(net::ERR_IO_PENDING, | 4103 EXPECT_EQ(net::ERR_IO_PENDING, |
4058 pending->trans->Start(&request, pending->callback.callback(), | 4104 pending->trans->Start(&request, pending->callback.callback(), |
4059 net::BoundNetLog())); | 4105 net::BoundNetLog())); |
4060 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 4106 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
4061 | 4107 |
4062 // Make sure that the entry has some data stored. | 4108 // Make sure that the entry has some data stored. |
4063 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); | 4109 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); |
4064 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4110 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4128 CreateTruncatedEntry(raw_headers, &cache); | 4174 CreateTruncatedEntry(raw_headers, &cache); |
4129 | 4175 |
4130 // Now make a regular request. | 4176 // Now make a regular request. |
4131 std::string headers; | 4177 std::string headers; |
4132 MockTransaction transaction(kRangeGET_TransactionOK); | 4178 MockTransaction transaction(kRangeGET_TransactionOK); |
4133 transaction.request_headers = EXTRA_HEADER; | 4179 transaction.request_headers = EXTRA_HEADER; |
4134 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 4180 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 "; | 4181 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
4136 | 4182 |
4137 scoped_ptr<Context> c(new Context); | 4183 scoped_ptr<Context> c(new Context); |
4138 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); | 4184 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans, NULL)); |
4139 | 4185 |
4140 MockHttpRequest request(transaction); | 4186 MockHttpRequest request(transaction); |
4141 int rv = c->trans->Start( | 4187 int rv = c->trans->Start( |
4142 &request, c->callback.callback(), net::BoundNetLog()); | 4188 &request, c->callback.callback(), net::BoundNetLog()); |
4143 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 4189 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
4144 | 4190 |
4145 // We should have checked with the server before finishing Start(). | 4191 // We should have checked with the server before finishing Start(). |
4146 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4192 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4147 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4193 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4148 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4194 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4200 "Accept-Ranges: bytes\n" | 4246 "Accept-Ranges: bytes\n" |
4201 "Content-Length: 80\n"); | 4247 "Content-Length: 80\n"); |
4202 CreateTruncatedEntry(raw_headers, &cache); | 4248 CreateTruncatedEntry(raw_headers, &cache); |
4203 | 4249 |
4204 // Now make a regular request. | 4250 // Now make a regular request. |
4205 MockTransaction transaction(kRangeGET_TransactionOK); | 4251 MockTransaction transaction(kRangeGET_TransactionOK); |
4206 transaction.request_headers = EXTRA_HEADER; | 4252 transaction.request_headers = EXTRA_HEADER; |
4207 | 4253 |
4208 MockHttpRequest request(transaction); | 4254 MockHttpRequest request(transaction); |
4209 Context* c = new Context(); | 4255 Context* c = new Context(); |
4210 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); | 4256 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans, NULL)); |
4211 | 4257 |
4212 int rv = c->trans->Start( | 4258 int rv = c->trans->Start( |
4213 &request, c->callback.callback(), net::BoundNetLog()); | 4259 &request, c->callback.callback(), net::BoundNetLog()); |
4214 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 4260 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
4215 | 4261 |
4216 // Read 20 bytes from the cache, and 10 from the net. | 4262 // Read 20 bytes from the cache, and 10 from the net. |
4217 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); | 4263 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); |
4218 rv = c->trans->Read(buf, 20, c->callback.callback()); | 4264 rv = c->trans->Read(buf, 20, c->callback.callback()); |
4219 EXPECT_EQ(20, c->callback.GetResult(rv)); | 4265 EXPECT_EQ(20, c->callback.GetResult(rv)); |
4220 rv = c->trans->Read(buf, 10, c->callback.callback()); | 4266 rv = c->trans->Read(buf, 10, c->callback.callback()); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4328 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction); | 4374 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction); |
4329 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently"; | 4375 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently"; |
4330 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; | 4376 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; |
4331 | 4377 |
4332 MockHttpRequest request(kTestTransaction); | 4378 MockHttpRequest request(kTestTransaction); |
4333 net::TestCompletionCallback callback; | 4379 net::TestCompletionCallback callback; |
4334 | 4380 |
4335 // write to the cache | 4381 // write to the cache |
4336 { | 4382 { |
4337 scoped_ptr<net::HttpTransaction> trans; | 4383 scoped_ptr<net::HttpTransaction> trans; |
4338 int rv = cache.http_cache()->CreateTransaction(&trans); | 4384 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4339 EXPECT_EQ(net::OK, rv); | 4385 EXPECT_EQ(net::OK, rv); |
4340 ASSERT_TRUE(trans.get()); | 4386 ASSERT_TRUE(trans.get()); |
4341 | 4387 |
4342 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4388 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
4343 if (rv == net::ERR_IO_PENDING) | 4389 if (rv == net::ERR_IO_PENDING) |
4344 rv = callback.WaitForResult(); | 4390 rv = callback.WaitForResult(); |
4345 ASSERT_EQ(net::OK, rv); | 4391 ASSERT_EQ(net::OK, rv); |
4346 | 4392 |
4347 const net::HttpResponseInfo* info = trans->GetResponseInfo(); | 4393 const net::HttpResponseInfo* info = trans->GetResponseInfo(); |
4348 ASSERT_TRUE(info); | 4394 ASSERT_TRUE(info); |
4349 | 4395 |
4350 EXPECT_EQ(info->headers->response_code(), 301); | 4396 EXPECT_EQ(info->headers->response_code(), 301); |
4351 | 4397 |
4352 std::string location; | 4398 std::string location; |
4353 info->headers->EnumerateHeader(NULL, "Location", &location); | 4399 info->headers->EnumerateHeader(NULL, "Location", &location); |
4354 EXPECT_EQ(location, "http://www.bar.com/"); | 4400 EXPECT_EQ(location, "http://www.bar.com/"); |
4355 | 4401 |
4356 // Destroy transaction when going out of scope. We have not actually | 4402 // 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. | 4403 // read the response body -- want to test that it is still getting cached. |
4358 } | 4404 } |
4359 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4405 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4360 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4406 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
4361 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4407 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4362 | 4408 |
4363 // read from the cache | 4409 // read from the cache |
4364 { | 4410 { |
4365 scoped_ptr<net::HttpTransaction> trans; | 4411 scoped_ptr<net::HttpTransaction> trans; |
4366 int rv = cache.http_cache()->CreateTransaction(&trans); | 4412 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4367 EXPECT_EQ(net::OK, rv); | 4413 EXPECT_EQ(net::OK, rv); |
4368 ASSERT_TRUE(trans.get()); | 4414 ASSERT_TRUE(trans.get()); |
4369 | 4415 |
4370 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4416 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
4371 if (rv == net::ERR_IO_PENDING) | 4417 if (rv == net::ERR_IO_PENDING) |
4372 rv = callback.WaitForResult(); | 4418 rv = callback.WaitForResult(); |
4373 ASSERT_EQ(net::OK, rv); | 4419 ASSERT_EQ(net::OK, rv); |
4374 | 4420 |
4375 const net::HttpResponseInfo* info = trans->GetResponseInfo(); | 4421 const net::HttpResponseInfo* info = trans->GetResponseInfo(); |
4376 ASSERT_TRUE(info); | 4422 ASSERT_TRUE(info); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4481 // write to the cache | 4527 // write to the cache |
4482 RunTransactionTest(cache.http_cache(), transaction); | 4528 RunTransactionTest(cache.http_cache(), transaction); |
4483 | 4529 |
4484 // Test that it was not cached. | 4530 // Test that it was not cached. |
4485 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 4531 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
4486 | 4532 |
4487 MockHttpRequest request(transaction); | 4533 MockHttpRequest request(transaction); |
4488 net::TestCompletionCallback callback; | 4534 net::TestCompletionCallback callback; |
4489 | 4535 |
4490 scoped_ptr<net::HttpTransaction> trans; | 4536 scoped_ptr<net::HttpTransaction> trans; |
4491 int rv = cache.http_cache()->CreateTransaction(&trans); | 4537 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4492 EXPECT_EQ(net::OK, rv); | 4538 EXPECT_EQ(net::OK, rv); |
4493 ASSERT_TRUE(trans.get()); | 4539 ASSERT_TRUE(trans.get()); |
4494 | 4540 |
4495 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4541 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
4496 if (rv == net::ERR_IO_PENDING) | 4542 if (rv == net::ERR_IO_PENDING) |
4497 rv = callback.WaitForResult(); | 4543 rv = callback.WaitForResult(); |
4498 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 4544 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
4499 } | 4545 } |
4500 | 4546 |
4501 // Ensure that we don't crash by if left-behind transactions. | 4547 // Ensure that we don't crash by if left-behind transactions. |
4502 TEST(HttpCache, OutlivedTransactions) { | 4548 TEST(HttpCache, OutlivedTransactions) { |
4503 MockHttpCache* cache = new MockHttpCache; | 4549 MockHttpCache* cache = new MockHttpCache; |
4504 | 4550 |
4505 scoped_ptr<net::HttpTransaction> trans; | 4551 scoped_ptr<net::HttpTransaction> trans; |
4506 int rv = cache->http_cache()->CreateTransaction(&trans); | 4552 int rv = cache->http_cache()->CreateTransaction(&trans, NULL); |
4507 EXPECT_EQ(net::OK, rv); | 4553 EXPECT_EQ(net::OK, rv); |
4508 | 4554 |
4509 delete cache; | 4555 delete cache; |
4510 trans.reset(); | 4556 trans.reset(); |
4511 } | 4557 } |
4512 | 4558 |
4513 // Test that the disabled mode works. | 4559 // Test that the disabled mode works. |
4514 TEST(HttpCache, CacheDisabledMode) { | 4560 TEST(HttpCache, CacheDisabledMode) { |
4515 MockHttpCache cache; | 4561 MockHttpCache cache; |
4516 | 4562 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4734 } | 4780 } |
4735 | 4781 |
4736 // Tests that we don't mark entries as truncated when a filter detects the end | 4782 // Tests that we don't mark entries as truncated when a filter detects the end |
4737 // of the stream. | 4783 // of the stream. |
4738 TEST(HttpCache, FilterCompletion) { | 4784 TEST(HttpCache, FilterCompletion) { |
4739 MockHttpCache cache; | 4785 MockHttpCache cache; |
4740 net::TestCompletionCallback callback; | 4786 net::TestCompletionCallback callback; |
4741 | 4787 |
4742 { | 4788 { |
4743 scoped_ptr<net::HttpTransaction> trans; | 4789 scoped_ptr<net::HttpTransaction> trans; |
4744 int rv = cache.http_cache()->CreateTransaction(&trans); | 4790 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4745 EXPECT_EQ(net::OK, rv); | 4791 EXPECT_EQ(net::OK, rv); |
4746 | 4792 |
4747 MockHttpRequest request(kSimpleGET_Transaction); | 4793 MockHttpRequest request(kSimpleGET_Transaction); |
4748 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4794 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
4749 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 4795 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
4750 | 4796 |
4751 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 4797 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
4752 rv = trans->Read(buf, 256, callback.callback()); | 4798 rv = trans->Read(buf, 256, callback.callback()); |
4753 EXPECT_GT(callback.GetResult(rv), 0); | 4799 EXPECT_GT(callback.GetResult(rv), 0); |
4754 | 4800 |
(...skipping 13 matching lines...) Expand all Loading... | |
4768 } | 4814 } |
4769 | 4815 |
4770 // Tests that we stop cachining when told. | 4816 // Tests that we stop cachining when told. |
4771 TEST(HttpCache, StopCachingDeletesEntry) { | 4817 TEST(HttpCache, StopCachingDeletesEntry) { |
4772 MockHttpCache cache; | 4818 MockHttpCache cache; |
4773 net::TestCompletionCallback callback; | 4819 net::TestCompletionCallback callback; |
4774 MockHttpRequest request(kSimpleGET_Transaction); | 4820 MockHttpRequest request(kSimpleGET_Transaction); |
4775 | 4821 |
4776 { | 4822 { |
4777 scoped_ptr<net::HttpTransaction> trans; | 4823 scoped_ptr<net::HttpTransaction> trans; |
4778 int rv = cache.http_cache()->CreateTransaction(&trans); | 4824 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4779 EXPECT_EQ(net::OK, rv); | 4825 EXPECT_EQ(net::OK, rv); |
4780 | 4826 |
4781 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4827 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
4782 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 4828 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
4783 | 4829 |
4784 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 4830 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
4785 rv = trans->Read(buf, 10, callback.callback()); | 4831 rv = trans->Read(buf, 10, callback.callback()); |
4786 EXPECT_EQ(callback.GetResult(rv), 10); | 4832 EXPECT_EQ(callback.GetResult(rv), 10); |
4787 | 4833 |
4788 trans->StopCaching(); | 4834 trans->StopCaching(); |
(...skipping 17 matching lines...) Expand all Loading... | |
4806 } | 4852 } |
4807 | 4853 |
4808 // Tests that when we are told to stop caching we don't throw away valid data. | 4854 // Tests that when we are told to stop caching we don't throw away valid data. |
4809 TEST(HttpCache, StopCachingSavesEntry) { | 4855 TEST(HttpCache, StopCachingSavesEntry) { |
4810 MockHttpCache cache; | 4856 MockHttpCache cache; |
4811 net::TestCompletionCallback callback; | 4857 net::TestCompletionCallback callback; |
4812 MockHttpRequest request(kSimpleGET_Transaction); | 4858 MockHttpRequest request(kSimpleGET_Transaction); |
4813 | 4859 |
4814 { | 4860 { |
4815 scoped_ptr<net::HttpTransaction> trans; | 4861 scoped_ptr<net::HttpTransaction> trans; |
4816 int rv = cache.http_cache()->CreateTransaction(&trans); | 4862 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4817 EXPECT_EQ(net::OK, rv); | 4863 EXPECT_EQ(net::OK, rv); |
4818 | 4864 |
4819 // Force a response that can be resumed. | 4865 // Force a response that can be resumed. |
4820 MockTransaction mock_transaction(kSimpleGET_Transaction); | 4866 MockTransaction mock_transaction(kSimpleGET_Transaction); |
4821 AddMockTransaction(&mock_transaction); | 4867 AddMockTransaction(&mock_transaction); |
4822 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" | 4868 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" |
4823 "Content-Length: 42\n" | 4869 "Content-Length: 42\n" |
4824 "Etag: \"foo\"\n"; | 4870 "Etag: \"foo\"\n"; |
4825 | 4871 |
4826 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4872 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4863 std::string raw_headers("HTTP/1.1 200 OK\n" | 4909 std::string raw_headers("HTTP/1.1 200 OK\n" |
4864 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 4910 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
4865 "ETag: \"foo\"\n" | 4911 "ETag: \"foo\"\n" |
4866 "Accept-Ranges: bytes\n" | 4912 "Accept-Ranges: bytes\n" |
4867 "Content-Length: 80\n"); | 4913 "Content-Length: 80\n"); |
4868 CreateTruncatedEntry(raw_headers, &cache); | 4914 CreateTruncatedEntry(raw_headers, &cache); |
4869 | 4915 |
4870 { | 4916 { |
4871 // Now make a regular request. | 4917 // Now make a regular request. |
4872 scoped_ptr<net::HttpTransaction> trans; | 4918 scoped_ptr<net::HttpTransaction> trans; |
4873 int rv = cache.http_cache()->CreateTransaction(&trans); | 4919 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
4874 EXPECT_EQ(net::OK, rv); | 4920 EXPECT_EQ(net::OK, rv); |
4875 | 4921 |
4876 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 4922 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
4877 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 4923 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
4878 | 4924 |
4879 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 4925 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
4880 rv = trans->Read(buf, 10, callback.callback()); | 4926 rv = trans->Read(buf, 10, callback.callback()); |
4881 EXPECT_EQ(callback.GetResult(rv), 10); | 4927 EXPECT_EQ(callback.GetResult(rv), 10); |
4882 | 4928 |
4883 // This is actually going to do nothing. | 4929 // This is actually going to do nothing. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4942 | 4988 |
4943 // Verify that the entry is marked as incomplete. | 4989 // Verify that the entry is marked as incomplete. |
4944 disk_cache::Entry* entry; | 4990 disk_cache::Entry* entry; |
4945 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 4991 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
4946 net::HttpResponseInfo response; | 4992 net::HttpResponseInfo response; |
4947 bool truncated = false; | 4993 bool truncated = false; |
4948 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 4994 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
4949 EXPECT_TRUE(truncated); | 4995 EXPECT_TRUE(truncated); |
4950 entry->Close(); | 4996 entry->Close(); |
4951 } | 4997 } |
4998 | |
4999 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit_TransactionDelegate) { | |
5000 MockHttpCache cache; | |
5001 | |
5002 // Write to the cache. | |
5003 RunTransactionTestWithDelegate(cache.http_cache(), | |
5004 kSimpleGET_Transaction, | |
5005 8); | |
5006 | |
5007 // Force this transaction to read from the cache. | |
5008 MockTransaction transaction(kSimpleGET_Transaction); | |
5009 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | |
5010 | |
5011 RunTransactionTestWithDelegate(cache.http_cache(), | |
5012 kSimpleGET_Transaction, | |
5013 5); | |
5014 } | |
OLD | NEW |