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