| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 EXPECT_THAT(rv, IsOk()); | 144 EXPECT_THAT(rv, IsOk()); |
| 145 std::string expected(trans_info.data); | 145 std::string expected(trans_info.data); |
| 146 EXPECT_EQ(expected, content); | 146 EXPECT_EQ(expected, content); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void RunTransactionTestBase(HttpCache* cache, | 149 void RunTransactionTestBase(HttpCache* cache, |
| 150 const MockTransaction& trans_info, | 150 const MockTransaction& trans_info, |
| 151 const MockHttpRequest& request, | 151 const MockHttpRequest& request, |
| 152 HttpResponseInfo* response_info, | 152 HttpResponseInfo* response_info, |
| 153 const BoundNetLog& net_log, | 153 const NetLogWithSource& net_log, |
| 154 LoadTimingInfo* load_timing_info, | 154 LoadTimingInfo* load_timing_info, |
| 155 int64_t* sent_bytes, | 155 int64_t* sent_bytes, |
| 156 int64_t* received_bytes, | 156 int64_t* received_bytes, |
| 157 IPEndPoint* remote_endpoint) { | 157 IPEndPoint* remote_endpoint) { |
| 158 TestCompletionCallback callback; | 158 TestCompletionCallback callback; |
| 159 | 159 |
| 160 // write to the cache | 160 // write to the cache |
| 161 | 161 |
| 162 std::unique_ptr<HttpTransaction> trans; | 162 std::unique_ptr<HttpTransaction> trans; |
| 163 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans); | 163 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 *sent_bytes = trans->GetTotalSentBytes(); | 195 *sent_bytes = trans->GetTotalSentBytes(); |
| 196 if (received_bytes) | 196 if (received_bytes) |
| 197 *received_bytes = trans->GetTotalReceivedBytes(); | 197 *received_bytes = trans->GetTotalReceivedBytes(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void RunTransactionTestWithRequest(HttpCache* cache, | 200 void RunTransactionTestWithRequest(HttpCache* cache, |
| 201 const MockTransaction& trans_info, | 201 const MockTransaction& trans_info, |
| 202 const MockHttpRequest& request, | 202 const MockHttpRequest& request, |
| 203 HttpResponseInfo* response_info) { | 203 HttpResponseInfo* response_info) { |
| 204 RunTransactionTestBase(cache, trans_info, request, response_info, | 204 RunTransactionTestBase(cache, trans_info, request, response_info, |
| 205 BoundNetLog(), nullptr, nullptr, nullptr, nullptr); | 205 NetLogWithSource(), nullptr, nullptr, nullptr, |
| 206 nullptr); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void RunTransactionTestAndGetTiming(HttpCache* cache, | 209 void RunTransactionTestAndGetTiming(HttpCache* cache, |
| 209 const MockTransaction& trans_info, | 210 const MockTransaction& trans_info, |
| 210 const BoundNetLog& log, | 211 const NetLogWithSource& log, |
| 211 LoadTimingInfo* load_timing_info) { | 212 LoadTimingInfo* load_timing_info) { |
| 212 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 213 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), |
| 213 nullptr, log, load_timing_info, nullptr, nullptr, | 214 nullptr, log, load_timing_info, nullptr, nullptr, |
| 214 nullptr); | 215 nullptr); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void RunTransactionTestAndGetTimingAndConnectedSocketAddress( | 218 void RunTransactionTestAndGetTimingAndConnectedSocketAddress( |
| 218 HttpCache* cache, | 219 HttpCache* cache, |
| 219 const MockTransaction& trans_info, | 220 const MockTransaction& trans_info, |
| 220 const BoundNetLog& log, | 221 const NetLogWithSource& log, |
| 221 LoadTimingInfo* load_timing_info, | 222 LoadTimingInfo* load_timing_info, |
| 222 IPEndPoint* remote_endpoint) { | 223 IPEndPoint* remote_endpoint) { |
| 223 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 224 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), |
| 224 nullptr, log, load_timing_info, nullptr, nullptr, | 225 nullptr, log, load_timing_info, nullptr, nullptr, |
| 225 remote_endpoint); | 226 remote_endpoint); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void RunTransactionTest(HttpCache* cache, const MockTransaction& trans_info) { | 229 void RunTransactionTest(HttpCache* cache, const MockTransaction& trans_info) { |
| 229 RunTransactionTestAndGetTiming(cache, trans_info, BoundNetLog(), nullptr); | 230 RunTransactionTestAndGetTiming(cache, trans_info, NetLogWithSource(), |
| 231 nullptr); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void RunTransactionTestWithLog(HttpCache* cache, | 234 void RunTransactionTestWithLog(HttpCache* cache, |
| 233 const MockTransaction& trans_info, | 235 const MockTransaction& trans_info, |
| 234 const BoundNetLog& log) { | 236 const NetLogWithSource& log) { |
| 235 RunTransactionTestAndGetTiming(cache, trans_info, log, nullptr); | 237 RunTransactionTestAndGetTiming(cache, trans_info, log, nullptr); |
| 236 } | 238 } |
| 237 | 239 |
| 238 void RunTransactionTestWithResponseInfo(HttpCache* cache, | 240 void RunTransactionTestWithResponseInfo(HttpCache* cache, |
| 239 const MockTransaction& trans_info, | 241 const MockTransaction& trans_info, |
| 240 HttpResponseInfo* response) { | 242 HttpResponseInfo* response) { |
| 241 RunTransactionTestWithRequest(cache, trans_info, MockHttpRequest(trans_info), | 243 RunTransactionTestWithRequest(cache, trans_info, MockHttpRequest(trans_info), |
| 242 response); | 244 response); |
| 243 } | 245 } |
| 244 | 246 |
| 245 void RunTransactionTestWithResponseInfoAndGetTiming( | 247 void RunTransactionTestWithResponseInfoAndGetTiming( |
| 246 HttpCache* cache, | 248 HttpCache* cache, |
| 247 const MockTransaction& trans_info, | 249 const MockTransaction& trans_info, |
| 248 HttpResponseInfo* response, | 250 HttpResponseInfo* response, |
| 249 const BoundNetLog& log, | 251 const NetLogWithSource& log, |
| 250 LoadTimingInfo* load_timing_info) { | 252 LoadTimingInfo* load_timing_info) { |
| 251 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 253 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), |
| 252 response, log, load_timing_info, nullptr, nullptr, | 254 response, log, load_timing_info, nullptr, nullptr, |
| 253 nullptr); | 255 nullptr); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void RunTransactionTestWithResponse(HttpCache* cache, | 258 void RunTransactionTestWithResponse(HttpCache* cache, |
| 257 const MockTransaction& trans_info, | 259 const MockTransaction& trans_info, |
| 258 std::string* response_headers) { | 260 std::string* response_headers) { |
| 259 HttpResponseInfo response; | 261 HttpResponseInfo response; |
| 260 RunTransactionTestWithResponseInfo(cache, trans_info, &response); | 262 RunTransactionTestWithResponseInfo(cache, trans_info, &response); |
| 261 response.headers->GetNormalizedHeaders(response_headers); | 263 response.headers->GetNormalizedHeaders(response_headers); |
| 262 } | 264 } |
| 263 | 265 |
| 264 void RunTransactionTestWithResponseAndGetTiming( | 266 void RunTransactionTestWithResponseAndGetTiming( |
| 265 HttpCache* cache, | 267 HttpCache* cache, |
| 266 const MockTransaction& trans_info, | 268 const MockTransaction& trans_info, |
| 267 std::string* response_headers, | 269 std::string* response_headers, |
| 268 const BoundNetLog& log, | 270 const NetLogWithSource& log, |
| 269 LoadTimingInfo* load_timing_info) { | 271 LoadTimingInfo* load_timing_info) { |
| 270 HttpResponseInfo response; | 272 HttpResponseInfo response; |
| 271 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 273 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), |
| 272 &response, log, load_timing_info, nullptr, nullptr, | 274 &response, log, load_timing_info, nullptr, nullptr, |
| 273 nullptr); | 275 nullptr); |
| 274 response.headers->GetNormalizedHeaders(response_headers); | 276 response.headers->GetNormalizedHeaders(response_headers); |
| 275 } | 277 } |
| 276 | 278 |
| 277 // This class provides a handler for kFastNoStoreGET_Transaction so that the | 279 // This class provides a handler for kFastNoStoreGET_Transaction so that the |
| 278 // no-store header can be included on demand. | 280 // no-store header can be included on demand. |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 730 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 729 | 731 |
| 730 MockHttpRequest request(kSimpleGET_Transaction); | 732 MockHttpRequest request(kSimpleGET_Transaction); |
| 731 std::unique_ptr<HttpTransaction> trans; | 733 std::unique_ptr<HttpTransaction> trans; |
| 732 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 734 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 733 | 735 |
| 734 const int kBufferSize = 10; | 736 const int kBufferSize = 10; |
| 735 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); | 737 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); |
| 736 ReleaseBufferCompletionCallback cb(buffer.get()); | 738 ReleaseBufferCompletionCallback cb(buffer.get()); |
| 737 | 739 |
| 738 int rv = trans->Start(&request, cb.callback(), BoundNetLog()); | 740 int rv = trans->Start(&request, cb.callback(), NetLogWithSource()); |
| 739 EXPECT_THAT(cb.GetResult(rv), IsOk()); | 741 EXPECT_THAT(cb.GetResult(rv), IsOk()); |
| 740 | 742 |
| 741 rv = trans->Read(buffer.get(), kBufferSize, cb.callback()); | 743 rv = trans->Read(buffer.get(), kBufferSize, cb.callback()); |
| 742 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); | 744 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); |
| 743 } | 745 } |
| 744 | 746 |
| 745 TEST(HttpCache, SimpleGETWithDiskFailures) { | 747 TEST(HttpCache, SimpleGETWithDiskFailures) { |
| 746 MockHttpCache cache; | 748 MockHttpCache cache; |
| 747 | 749 |
| 748 cache.disk_cache()->set_soft_failures(true); | 750 cache.disk_cache()->set_soft_failures(true); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 766 // request to fail. | 768 // request to fail. |
| 767 TEST(HttpCache, SimpleGETWithDiskFailures2) { | 769 TEST(HttpCache, SimpleGETWithDiskFailures2) { |
| 768 MockHttpCache cache; | 770 MockHttpCache cache; |
| 769 | 771 |
| 770 MockHttpRequest request(kSimpleGET_Transaction); | 772 MockHttpRequest request(kSimpleGET_Transaction); |
| 771 | 773 |
| 772 std::unique_ptr<Context> c(new Context()); | 774 std::unique_ptr<Context> c(new Context()); |
| 773 int rv = cache.CreateTransaction(&c->trans); | 775 int rv = cache.CreateTransaction(&c->trans); |
| 774 ASSERT_THAT(rv, IsOk()); | 776 ASSERT_THAT(rv, IsOk()); |
| 775 | 777 |
| 776 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 778 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 777 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 779 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 778 rv = c->callback.WaitForResult(); | 780 rv = c->callback.WaitForResult(); |
| 779 | 781 |
| 780 // Start failing request now. | 782 // Start failing request now. |
| 781 cache.disk_cache()->set_soft_failures(true); | 783 cache.disk_cache()->set_soft_failures(true); |
| 782 | 784 |
| 783 // We have to open the entry again to propagate the failure flag. | 785 // We have to open the entry again to propagate the failure flag. |
| 784 disk_cache::Entry* en; | 786 disk_cache::Entry* en; |
| 785 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en)); | 787 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en)); |
| 786 en->Close(); | 788 en->Close(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 812 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 814 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 813 | 815 |
| 814 cache.disk_cache()->set_soft_failures(true); | 816 cache.disk_cache()->set_soft_failures(true); |
| 815 | 817 |
| 816 // Now fail to read from the cache. | 818 // Now fail to read from the cache. |
| 817 std::unique_ptr<Context> c(new Context()); | 819 std::unique_ptr<Context> c(new Context()); |
| 818 int rv = cache.CreateTransaction(&c->trans); | 820 int rv = cache.CreateTransaction(&c->trans); |
| 819 ASSERT_THAT(rv, IsOk()); | 821 ASSERT_THAT(rv, IsOk()); |
| 820 | 822 |
| 821 MockHttpRequest request(kSimpleGET_Transaction); | 823 MockHttpRequest request(kSimpleGET_Transaction); |
| 822 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 824 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 823 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 825 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 824 | 826 |
| 825 // Now verify that the entry was removed from the cache. | 827 // Now verify that the entry was removed from the cache. |
| 826 cache.disk_cache()->set_soft_failures(false); | 828 cache.disk_cache()->set_soft_failures(false); |
| 827 | 829 |
| 828 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 830 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 829 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 831 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 830 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 832 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 831 | 833 |
| 832 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 834 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 // force this transaction to read from the cache | 916 // force this transaction to read from the cache |
| 915 MockTransaction transaction(kSimpleGET_Transaction); | 917 MockTransaction transaction(kSimpleGET_Transaction); |
| 916 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; | 918 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 917 | 919 |
| 918 MockHttpRequest request(transaction); | 920 MockHttpRequest request(transaction); |
| 919 TestCompletionCallback callback; | 921 TestCompletionCallback callback; |
| 920 | 922 |
| 921 std::unique_ptr<HttpTransaction> trans; | 923 std::unique_ptr<HttpTransaction> trans; |
| 922 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 924 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 923 | 925 |
| 924 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 926 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 925 if (rv == ERR_IO_PENDING) | 927 if (rv == ERR_IO_PENDING) |
| 926 rv = callback.WaitForResult(); | 928 rv = callback.WaitForResult(); |
| 927 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS)); | 929 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 928 | 930 |
| 929 trans.reset(); | 931 trans.reset(); |
| 930 | 932 |
| 931 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 933 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
| 932 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 934 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 933 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 935 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 934 } | 936 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 // Network failure with error; should fail but have was_cached set. | 1034 // Network failure with error; should fail but have was_cached set. |
| 1033 transaction.return_code = ERR_FAILED; | 1035 transaction.return_code = ERR_FAILED; |
| 1034 AddMockTransaction(&transaction); | 1036 AddMockTransaction(&transaction); |
| 1035 | 1037 |
| 1036 MockHttpRequest request(transaction); | 1038 MockHttpRequest request(transaction); |
| 1037 TestCompletionCallback callback; | 1039 TestCompletionCallback callback; |
| 1038 std::unique_ptr<HttpTransaction> trans; | 1040 std::unique_ptr<HttpTransaction> trans; |
| 1039 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); | 1041 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 1040 EXPECT_THAT(rv, IsOk()); | 1042 EXPECT_THAT(rv, IsOk()); |
| 1041 ASSERT_TRUE(trans.get()); | 1043 ASSERT_TRUE(trans.get()); |
| 1042 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 1044 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 1043 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_FAILED)); | 1045 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_FAILED)); |
| 1044 | 1046 |
| 1045 const HttpResponseInfo* response_info = trans->GetResponseInfo(); | 1047 const HttpResponseInfo* response_info = trans->GetResponseInfo(); |
| 1046 ASSERT_TRUE(response_info); | 1048 ASSERT_TRUE(response_info); |
| 1047 EXPECT_TRUE(response_info->was_cached); | 1049 EXPECT_TRUE(response_info->was_cached); |
| 1048 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1050 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1049 | 1051 |
| 1050 RemoveMockTransaction(&transaction); | 1052 RemoveMockTransaction(&transaction); |
| 1051 } | 1053 } |
| 1052 | 1054 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 | 1277 |
| 1276 for (int i = 0; i < kNumTransactions; ++i) { | 1278 for (int i = 0; i < kNumTransactions; ++i) { |
| 1277 context_list.push_back(new Context()); | 1279 context_list.push_back(new Context()); |
| 1278 Context* c = context_list[i]; | 1280 Context* c = context_list[i]; |
| 1279 | 1281 |
| 1280 c->result = cache.CreateTransaction(&c->trans); | 1282 c->result = cache.CreateTransaction(&c->trans); |
| 1281 ASSERT_THAT(c->result, IsOk()); | 1283 ASSERT_THAT(c->result, IsOk()); |
| 1282 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); | 1284 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); |
| 1283 | 1285 |
| 1284 c->result = | 1286 c->result = |
| 1285 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1287 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1286 } | 1288 } |
| 1287 | 1289 |
| 1288 // All requests are waiting for the active entry. | 1290 // All requests are waiting for the active entry. |
| 1289 for (int i = 0; i < kNumTransactions; ++i) { | 1291 for (int i = 0; i < kNumTransactions; ++i) { |
| 1290 Context* c = context_list[i]; | 1292 Context* c = context_list[i]; |
| 1291 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); | 1293 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); |
| 1292 } | 1294 } |
| 1293 | 1295 |
| 1294 // Allow all requests to move from the Create queue to the active entry. | 1296 // Allow all requests to move from the Create queue to the active entry. |
| 1295 base::RunLoop().RunUntilIdle(); | 1297 base::RunLoop().RunUntilIdle(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 context_list.push_back(new Context()); | 1347 context_list.push_back(new Context()); |
| 1346 Context* c = context_list[i]; | 1348 Context* c = context_list[i]; |
| 1347 | 1349 |
| 1348 c->result = cache.CreateTransaction(&c->trans); | 1350 c->result = cache.CreateTransaction(&c->trans); |
| 1349 ASSERT_THAT(c->result, IsOk()); | 1351 ASSERT_THAT(c->result, IsOk()); |
| 1350 | 1352 |
| 1351 MockHttpRequest* this_request = &request; | 1353 MockHttpRequest* this_request = &request; |
| 1352 if (i == 1 || i == 2) | 1354 if (i == 1 || i == 2) |
| 1353 this_request = &reader_request; | 1355 this_request = &reader_request; |
| 1354 | 1356 |
| 1355 c->result = | 1357 c->result = c->trans->Start(this_request, c->callback.callback(), |
| 1356 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); | 1358 NetLogWithSource()); |
| 1357 } | 1359 } |
| 1358 | 1360 |
| 1359 // Allow all requests to move from the Create queue to the active entry. | 1361 // Allow all requests to move from the Create queue to the active entry. |
| 1360 base::RunLoop().RunUntilIdle(); | 1362 base::RunLoop().RunUntilIdle(); |
| 1361 | 1363 |
| 1362 // The first request should be a writer at this point, and the subsequent | 1364 // The first request should be a writer at this point, and the subsequent |
| 1363 // requests should be pending. | 1365 // requests should be pending. |
| 1364 | 1366 |
| 1365 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1367 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1366 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1368 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 context_list.push_back(base::WrapUnique(new Context())); | 1431 context_list.push_back(base::WrapUnique(new Context())); |
| 1430 Context* c = context_list[i].get(); | 1432 Context* c = context_list[i].get(); |
| 1431 | 1433 |
| 1432 c->result = cache.CreateTransaction(&c->trans); | 1434 c->result = cache.CreateTransaction(&c->trans); |
| 1433 ASSERT_THAT(c->result, IsOk()); | 1435 ASSERT_THAT(c->result, IsOk()); |
| 1434 | 1436 |
| 1435 MockHttpRequest* this_request = &request; | 1437 MockHttpRequest* this_request = &request; |
| 1436 if (i == 3) | 1438 if (i == 3) |
| 1437 this_request = &writer_request; | 1439 this_request = &writer_request; |
| 1438 | 1440 |
| 1439 c->result = | 1441 c->result = c->trans->Start(this_request, c->callback.callback(), |
| 1440 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); | 1442 NetLogWithSource()); |
| 1441 } | 1443 } |
| 1442 | 1444 |
| 1443 // The first request should be a writer at this point, and the two subsequent | 1445 // The first request should be a writer at this point, and the two subsequent |
| 1444 // requests should be pending. The last request doomed the first entry. | 1446 // requests should be pending. The last request doomed the first entry. |
| 1445 | 1447 |
| 1446 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1448 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1447 | 1449 |
| 1448 // Cancel the first queued transaction. | 1450 // Cancel the first queued transaction. |
| 1449 context_list[1].reset(); | 1451 context_list[1].reset(); |
| 1450 | 1452 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1473 const int kNumTransactions = 3; | 1475 const int kNumTransactions = 3; |
| 1474 | 1476 |
| 1475 for (int i = 0; i < kNumTransactions; ++i) { | 1477 for (int i = 0; i < kNumTransactions; ++i) { |
| 1476 context_list.push_back(new Context()); | 1478 context_list.push_back(new Context()); |
| 1477 Context* c = context_list[i]; | 1479 Context* c = context_list[i]; |
| 1478 | 1480 |
| 1479 c->result = cache.CreateTransaction(&c->trans); | 1481 c->result = cache.CreateTransaction(&c->trans); |
| 1480 ASSERT_THAT(c->result, IsOk()); | 1482 ASSERT_THAT(c->result, IsOk()); |
| 1481 | 1483 |
| 1482 c->result = | 1484 c->result = |
| 1483 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1485 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1484 } | 1486 } |
| 1485 | 1487 |
| 1486 // Allow all requests to move from the Create queue to the active entry. | 1488 // Allow all requests to move from the Create queue to the active entry. |
| 1487 base::RunLoop().RunUntilIdle(); | 1489 base::RunLoop().RunUntilIdle(); |
| 1488 | 1490 |
| 1489 // The first request should be a writer at this point, and the subsequent | 1491 // The first request should be a writer at this point, and the subsequent |
| 1490 // requests should be pending. | 1492 // requests should be pending. |
| 1491 | 1493 |
| 1492 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1494 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1493 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1495 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1520 const int kNumTransactions = 2; | 1522 const int kNumTransactions = 2; |
| 1521 | 1523 |
| 1522 for (int i = 0; i < kNumTransactions; ++i) { | 1524 for (int i = 0; i < kNumTransactions; ++i) { |
| 1523 context_list.push_back(new Context()); | 1525 context_list.push_back(new Context()); |
| 1524 Context* c = context_list[i]; | 1526 Context* c = context_list[i]; |
| 1525 | 1527 |
| 1526 c->result = cache.CreateTransaction(&c->trans); | 1528 c->result = cache.CreateTransaction(&c->trans); |
| 1527 ASSERT_THAT(c->result, IsOk()); | 1529 ASSERT_THAT(c->result, IsOk()); |
| 1528 | 1530 |
| 1529 c->result = | 1531 c->result = |
| 1530 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1532 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1531 } | 1533 } |
| 1532 | 1534 |
| 1533 // Allow all requests to move from the Create queue to the active entry. | 1535 // Allow all requests to move from the Create queue to the active entry. |
| 1534 base::RunLoop().RunUntilIdle(); | 1536 base::RunLoop().RunUntilIdle(); |
| 1535 | 1537 |
| 1536 // The first request should be a writer at this point, and the subsequent | 1538 // The first request should be a writer at this point, and the subsequent |
| 1537 // requests should be pending. | 1539 // requests should be pending. |
| 1538 | 1540 |
| 1539 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1541 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 1540 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1542 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 const int kNumTransactions = 5; | 1582 const int kNumTransactions = 5; |
| 1581 | 1583 |
| 1582 for (int i = 0; i < kNumTransactions; i++) { | 1584 for (int i = 0; i < kNumTransactions; i++) { |
| 1583 context_list.push_back(new Context()); | 1585 context_list.push_back(new Context()); |
| 1584 Context* c = context_list[i]; | 1586 Context* c = context_list[i]; |
| 1585 | 1587 |
| 1586 c->result = cache.CreateTransaction(&c->trans); | 1588 c->result = cache.CreateTransaction(&c->trans); |
| 1587 ASSERT_THAT(c->result, IsOk()); | 1589 ASSERT_THAT(c->result, IsOk()); |
| 1588 | 1590 |
| 1589 c->result = | 1591 c->result = |
| 1590 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1592 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1591 } | 1593 } |
| 1592 | 1594 |
| 1593 // The first request should be creating the disk cache entry and the others | 1595 // The first request should be creating the disk cache entry and the others |
| 1594 // should be pending. | 1596 // should be pending. |
| 1595 | 1597 |
| 1596 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1598 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
| 1597 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1599 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1598 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1600 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1599 | 1601 |
| 1600 // Cancel a request from the pending queue. | 1602 // Cancel a request from the pending queue. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1630 TEST(HttpCache, SimpleGET_CancelCreate) { | 1632 TEST(HttpCache, SimpleGET_CancelCreate) { |
| 1631 MockHttpCache cache; | 1633 MockHttpCache cache; |
| 1632 | 1634 |
| 1633 MockHttpRequest request(kSimpleGET_Transaction); | 1635 MockHttpRequest request(kSimpleGET_Transaction); |
| 1634 | 1636 |
| 1635 Context* c = new Context(); | 1637 Context* c = new Context(); |
| 1636 | 1638 |
| 1637 c->result = cache.CreateTransaction(&c->trans); | 1639 c->result = cache.CreateTransaction(&c->trans); |
| 1638 ASSERT_THAT(c->result, IsOk()); | 1640 ASSERT_THAT(c->result, IsOk()); |
| 1639 | 1641 |
| 1640 c->result = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1642 c->result = |
| 1643 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1641 EXPECT_THAT(c->result, IsError(ERR_IO_PENDING)); | 1644 EXPECT_THAT(c->result, IsError(ERR_IO_PENDING)); |
| 1642 | 1645 |
| 1643 // Release the reference that the mock disk cache keeps for this entry, so | 1646 // Release the reference that the mock disk cache keeps for this entry, so |
| 1644 // that we test that the http cache handles the cancellation correctly. | 1647 // that we test that the http cache handles the cancellation correctly. |
| 1645 cache.disk_cache()->ReleaseAll(); | 1648 cache.disk_cache()->ReleaseAll(); |
| 1646 delete c; | 1649 delete c; |
| 1647 | 1650 |
| 1648 base::RunLoop().RunUntilIdle(); | 1651 base::RunLoop().RunUntilIdle(); |
| 1649 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1652 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1650 } | 1653 } |
| 1651 | 1654 |
| 1652 // Tests that we delete/create entries even if multiple requests are queued. | 1655 // Tests that we delete/create entries even if multiple requests are queued. |
| 1653 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { | 1656 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { |
| 1654 MockHttpCache cache; | 1657 MockHttpCache cache; |
| 1655 | 1658 |
| 1656 MockHttpRequest request(kSimpleGET_Transaction); | 1659 MockHttpRequest request(kSimpleGET_Transaction); |
| 1657 request.load_flags = LOAD_BYPASS_CACHE; | 1660 request.load_flags = LOAD_BYPASS_CACHE; |
| 1658 | 1661 |
| 1659 std::vector<Context*> context_list; | 1662 std::vector<Context*> context_list; |
| 1660 const int kNumTransactions = 5; | 1663 const int kNumTransactions = 5; |
| 1661 | 1664 |
| 1662 for (int i = 0; i < kNumTransactions; i++) { | 1665 for (int i = 0; i < kNumTransactions; i++) { |
| 1663 context_list.push_back(new Context()); | 1666 context_list.push_back(new Context()); |
| 1664 Context* c = context_list[i]; | 1667 Context* c = context_list[i]; |
| 1665 | 1668 |
| 1666 c->result = cache.CreateTransaction(&c->trans); | 1669 c->result = cache.CreateTransaction(&c->trans); |
| 1667 ASSERT_THAT(c->result, IsOk()); | 1670 ASSERT_THAT(c->result, IsOk()); |
| 1668 | 1671 |
| 1669 c->result = | 1672 c->result = |
| 1670 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1673 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1671 } | 1674 } |
| 1672 | 1675 |
| 1673 // The first request should be deleting the disk cache entry and the others | 1676 // The first request should be deleting the disk cache entry and the others |
| 1674 // should be pending. | 1677 // should be pending. |
| 1675 | 1678 |
| 1676 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1679 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
| 1677 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1680 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1678 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1681 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 1679 | 1682 |
| 1680 // Complete the transactions. | 1683 // Complete the transactions. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1697 | 1700 |
| 1698 // Tests that a (simulated) timeout allows transactions waiting on the cache | 1701 // Tests that a (simulated) timeout allows transactions waiting on the cache |
| 1699 // lock to continue. | 1702 // lock to continue. |
| 1700 TEST(HttpCache, SimpleGET_WriterTimeout) { | 1703 TEST(HttpCache, SimpleGET_WriterTimeout) { |
| 1701 MockHttpCache cache; | 1704 MockHttpCache cache; |
| 1702 cache.BypassCacheLock(); | 1705 cache.BypassCacheLock(); |
| 1703 | 1706 |
| 1704 MockHttpRequest request(kSimpleGET_Transaction); | 1707 MockHttpRequest request(kSimpleGET_Transaction); |
| 1705 Context c1, c2; | 1708 Context c1, c2; |
| 1706 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk()); | 1709 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk()); |
| 1707 ASSERT_EQ(ERR_IO_PENDING, | 1710 ASSERT_EQ(ERR_IO_PENDING, c1.trans->Start(&request, c1.callback.callback(), |
| 1708 c1.trans->Start(&request, c1.callback.callback(), BoundNetLog())); | 1711 NetLogWithSource())); |
| 1709 ASSERT_THAT(cache.CreateTransaction(&c2.trans), IsOk()); | 1712 ASSERT_THAT(cache.CreateTransaction(&c2.trans), IsOk()); |
| 1710 ASSERT_EQ(ERR_IO_PENDING, | 1713 ASSERT_EQ(ERR_IO_PENDING, c2.trans->Start(&request, c2.callback.callback(), |
| 1711 c2.trans->Start(&request, c2.callback.callback(), BoundNetLog())); | 1714 NetLogWithSource())); |
| 1712 | 1715 |
| 1713 // The second request is queued after the first one. | 1716 // The second request is queued after the first one. |
| 1714 | 1717 |
| 1715 c2.callback.WaitForResult(); | 1718 c2.callback.WaitForResult(); |
| 1716 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction); | 1719 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction); |
| 1717 | 1720 |
| 1718 // Complete the first transaction. | 1721 // Complete the first transaction. |
| 1719 c1.callback.WaitForResult(); | 1722 c1.callback.WaitForResult(); |
| 1720 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); | 1723 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); |
| 1721 } | 1724 } |
| 1722 | 1725 |
| 1723 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { | 1726 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { |
| 1724 MockHttpCache cache; | 1727 MockHttpCache cache; |
| 1725 | 1728 |
| 1726 // write to the cache | 1729 // write to the cache |
| 1727 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1730 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 1728 | 1731 |
| 1729 MockHttpRequest request(kSimpleGET_Transaction); | 1732 MockHttpRequest request(kSimpleGET_Transaction); |
| 1730 TestCompletionCallback callback; | 1733 TestCompletionCallback callback; |
| 1731 | 1734 |
| 1732 std::unique_ptr<HttpTransaction> trans; | 1735 std::unique_ptr<HttpTransaction> trans; |
| 1733 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 1736 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 1734 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 1737 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 1735 if (rv == ERR_IO_PENDING) | 1738 if (rv == ERR_IO_PENDING) |
| 1736 rv = callback.WaitForResult(); | 1739 rv = callback.WaitForResult(); |
| 1737 ASSERT_THAT(rv, IsOk()); | 1740 ASSERT_THAT(rv, IsOk()); |
| 1738 | 1741 |
| 1739 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 1742 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 1740 rv = trans->Read(buf.get(), 256, callback.callback()); | 1743 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 1741 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1744 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1742 | 1745 |
| 1743 // Test that destroying the transaction while it is reading from the cache | 1746 // Test that destroying the transaction while it is reading from the cache |
| 1744 // works properly. | 1747 // works properly. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1761 const int kNumTransactions = 5; | 1764 const int kNumTransactions = 5; |
| 1762 | 1765 |
| 1763 for (int i = 0; i < kNumTransactions; i++) { | 1766 for (int i = 0; i < kNumTransactions; i++) { |
| 1764 context_list.push_back(new Context()); | 1767 context_list.push_back(new Context()); |
| 1765 Context* c = context_list[i]; | 1768 Context* c = context_list[i]; |
| 1766 | 1769 |
| 1767 c->result = cache->CreateTransaction(&c->trans); | 1770 c->result = cache->CreateTransaction(&c->trans); |
| 1768 ASSERT_THAT(c->result, IsOk()); | 1771 ASSERT_THAT(c->result, IsOk()); |
| 1769 | 1772 |
| 1770 c->result = | 1773 c->result = |
| 1771 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1774 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1772 } | 1775 } |
| 1773 | 1776 |
| 1774 // The first request should be creating the disk cache entry and the others | 1777 // The first request should be creating the disk cache entry and the others |
| 1775 // should be pending. | 1778 // should be pending. |
| 1776 | 1779 |
| 1777 EXPECT_EQ(0, cache->network_layer()->transaction_count()); | 1780 EXPECT_EQ(0, cache->network_layer()->transaction_count()); |
| 1778 EXPECT_EQ(0, cache->disk_cache()->open_count()); | 1781 EXPECT_EQ(0, cache->disk_cache()->open_count()); |
| 1779 EXPECT_EQ(0, cache->disk_cache()->create_count()); | 1782 EXPECT_EQ(0, cache->disk_cache()->create_count()); |
| 1780 | 1783 |
| 1781 cache.reset(); | 1784 cache.reset(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1801 | 1804 |
| 1802 for (int i = 0; i < kNumTransactions; i++) { | 1805 for (int i = 0; i < kNumTransactions; i++) { |
| 1803 context_list.push_back(new Context()); | 1806 context_list.push_back(new Context()); |
| 1804 Context* c = context_list[i]; | 1807 Context* c = context_list[i]; |
| 1805 | 1808 |
| 1806 c->result = cache.CreateTransaction(&c->trans); | 1809 c->result = cache.CreateTransaction(&c->trans); |
| 1807 ASSERT_THAT(c->result, IsOk()); | 1810 ASSERT_THAT(c->result, IsOk()); |
| 1808 } | 1811 } |
| 1809 | 1812 |
| 1810 context_list[0]->result = context_list[0]->trans->Start( | 1813 context_list[0]->result = context_list[0]->trans->Start( |
| 1811 &request0, context_list[0]->callback.callback(), BoundNetLog()); | 1814 &request0, context_list[0]->callback.callback(), NetLogWithSource()); |
| 1812 context_list[1]->result = context_list[1]->trans->Start( | 1815 context_list[1]->result = context_list[1]->trans->Start( |
| 1813 &request1, context_list[1]->callback.callback(), BoundNetLog()); | 1816 &request1, context_list[1]->callback.callback(), NetLogWithSource()); |
| 1814 context_list[2]->result = context_list[2]->trans->Start( | 1817 context_list[2]->result = context_list[2]->trans->Start( |
| 1815 &request2, context_list[2]->callback.callback(), BoundNetLog()); | 1818 &request2, context_list[2]->callback.callback(), NetLogWithSource()); |
| 1816 | 1819 |
| 1817 // Just to make sure that everything is still pending. | 1820 // Just to make sure that everything is still pending. |
| 1818 base::RunLoop().RunUntilIdle(); | 1821 base::RunLoop().RunUntilIdle(); |
| 1819 | 1822 |
| 1820 // The first request should be creating the disk cache. | 1823 // The first request should be creating the disk cache. |
| 1821 EXPECT_FALSE(context_list[0]->callback.have_result()); | 1824 EXPECT_FALSE(context_list[0]->callback.have_result()); |
| 1822 | 1825 |
| 1823 factory->FinishCreation(); | 1826 factory->FinishCreation(); |
| 1824 | 1827 |
| 1825 base::RunLoop().RunUntilIdle(); | 1828 base::RunLoop().RunUntilIdle(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1847 | 1850 |
| 1848 for (int i = 0; i < kNumTransactions; i++) { | 1851 for (int i = 0; i < kNumTransactions; i++) { |
| 1849 context_list.push_back(new Context()); | 1852 context_list.push_back(new Context()); |
| 1850 Context* c = context_list[i]; | 1853 Context* c = context_list[i]; |
| 1851 | 1854 |
| 1852 c->result = cache.CreateTransaction(&c->trans); | 1855 c->result = cache.CreateTransaction(&c->trans); |
| 1853 ASSERT_THAT(c->result, IsOk()); | 1856 ASSERT_THAT(c->result, IsOk()); |
| 1854 } | 1857 } |
| 1855 | 1858 |
| 1856 context_list[0]->result = context_list[0]->trans->Start( | 1859 context_list[0]->result = context_list[0]->trans->Start( |
| 1857 &request0, context_list[0]->callback.callback(), BoundNetLog()); | 1860 &request0, context_list[0]->callback.callback(), NetLogWithSource()); |
| 1858 context_list[1]->result = context_list[1]->trans->Start( | 1861 context_list[1]->result = context_list[1]->trans->Start( |
| 1859 &request1, context_list[1]->callback.callback(), BoundNetLog()); | 1862 &request1, context_list[1]->callback.callback(), NetLogWithSource()); |
| 1860 context_list[2]->result = context_list[2]->trans->Start( | 1863 context_list[2]->result = context_list[2]->trans->Start( |
| 1861 &request2, context_list[2]->callback.callback(), BoundNetLog()); | 1864 &request2, context_list[2]->callback.callback(), NetLogWithSource()); |
| 1862 | 1865 |
| 1863 // Just to make sure that everything is still pending. | 1866 // Just to make sure that everything is still pending. |
| 1864 base::RunLoop().RunUntilIdle(); | 1867 base::RunLoop().RunUntilIdle(); |
| 1865 | 1868 |
| 1866 // The first request should be creating the disk cache. | 1869 // The first request should be creating the disk cache. |
| 1867 EXPECT_FALSE(context_list[0]->callback.have_result()); | 1870 EXPECT_FALSE(context_list[0]->callback.have_result()); |
| 1868 | 1871 |
| 1869 // Cancel a request from the pending queue. | 1872 // Cancel a request from the pending queue. |
| 1870 delete context_list[1]; | 1873 delete context_list[1]; |
| 1871 context_list[1] = NULL; | 1874 context_list[1] = NULL; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1892 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 1895 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
| 1893 std::unique_ptr<MockHttpCache> cache( | 1896 std::unique_ptr<MockHttpCache> cache( |
| 1894 new MockHttpCache(base::WrapUnique(factory))); | 1897 new MockHttpCache(base::WrapUnique(factory))); |
| 1895 | 1898 |
| 1896 MockHttpRequest request(kSimpleGET_Transaction); | 1899 MockHttpRequest request(kSimpleGET_Transaction); |
| 1897 | 1900 |
| 1898 std::unique_ptr<Context> c(new Context()); | 1901 std::unique_ptr<Context> c(new Context()); |
| 1899 c->result = cache->CreateTransaction(&c->trans); | 1902 c->result = cache->CreateTransaction(&c->trans); |
| 1900 ASSERT_THAT(c->result, IsOk()); | 1903 ASSERT_THAT(c->result, IsOk()); |
| 1901 | 1904 |
| 1902 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1905 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1903 | 1906 |
| 1904 // Just to make sure that everything is still pending. | 1907 // Just to make sure that everything is still pending. |
| 1905 base::RunLoop().RunUntilIdle(); | 1908 base::RunLoop().RunUntilIdle(); |
| 1906 | 1909 |
| 1907 // The request should be creating the disk cache. | 1910 // The request should be creating the disk cache. |
| 1908 EXPECT_FALSE(c->callback.have_result()); | 1911 EXPECT_FALSE(c->callback.have_result()); |
| 1909 | 1912 |
| 1910 // We cannot call FinishCreation because the factory itself will go away with | 1913 // We cannot call FinishCreation because the factory itself will go away with |
| 1911 // the cache, so grab the callback and attempt to use it. | 1914 // the cache, so grab the callback and attempt to use it. |
| 1912 CompletionCallback callback = factory->callback(); | 1915 CompletionCallback callback = factory->callback(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1930 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); | 1933 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); |
| 1931 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1934 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1932 | 1935 |
| 1933 // Now let's queue a regular transaction | 1936 // Now let's queue a regular transaction |
| 1934 MockHttpRequest request(kSimpleGET_Transaction); | 1937 MockHttpRequest request(kSimpleGET_Transaction); |
| 1935 | 1938 |
| 1936 std::unique_ptr<Context> c(new Context()); | 1939 std::unique_ptr<Context> c(new Context()); |
| 1937 c->result = cache->CreateTransaction(&c->trans); | 1940 c->result = cache->CreateTransaction(&c->trans); |
| 1938 ASSERT_THAT(c->result, IsOk()); | 1941 ASSERT_THAT(c->result, IsOk()); |
| 1939 | 1942 |
| 1940 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 1943 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 1941 | 1944 |
| 1942 // And another direct backend request. | 1945 // And another direct backend request. |
| 1943 TestCompletionCallback cb2; | 1946 TestCompletionCallback cb2; |
| 1944 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); | 1947 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); |
| 1945 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1948 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1946 | 1949 |
| 1947 // Just to make sure that everything is still pending. | 1950 // Just to make sure that everything is still pending. |
| 1948 base::RunLoop().RunUntilIdle(); | 1951 base::RunLoop().RunUntilIdle(); |
| 1949 | 1952 |
| 1950 // The request should be queued. | 1953 // The request should be queued. |
| (...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2908 MockTransaction transaction(kSimplePOST_Transaction); | 2911 MockTransaction transaction(kSimplePOST_Transaction); |
| 2909 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; | 2912 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 2910 | 2913 |
| 2911 MockHttpRequest request(transaction); | 2914 MockHttpRequest request(transaction); |
| 2912 TestCompletionCallback callback; | 2915 TestCompletionCallback callback; |
| 2913 | 2916 |
| 2914 std::unique_ptr<HttpTransaction> trans; | 2917 std::unique_ptr<HttpTransaction> trans; |
| 2915 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 2918 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 2916 ASSERT_TRUE(trans.get()); | 2919 ASSERT_TRUE(trans.get()); |
| 2917 | 2920 |
| 2918 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 2921 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 2919 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS)); | 2922 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS)); |
| 2920 | 2923 |
| 2921 trans.reset(); | 2924 trans.reset(); |
| 2922 | 2925 |
| 2923 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 2926 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
| 2924 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2927 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2925 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2928 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 2926 } | 2929 } |
| 2927 | 2930 |
| 2928 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) { | 2931 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3163 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; | 3166 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 3164 transaction.method = "HEAD"; | 3167 transaction.method = "HEAD"; |
| 3165 | 3168 |
| 3166 MockHttpRequest request(transaction); | 3169 MockHttpRequest request(transaction); |
| 3167 TestCompletionCallback callback; | 3170 TestCompletionCallback callback; |
| 3168 | 3171 |
| 3169 std::unique_ptr<HttpTransaction> trans; | 3172 std::unique_ptr<HttpTransaction> trans; |
| 3170 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 3173 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 3171 ASSERT_TRUE(trans.get()); | 3174 ASSERT_TRUE(trans.get()); |
| 3172 | 3175 |
| 3173 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 3176 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 3174 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS)); | 3177 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS)); |
| 3175 | 3178 |
| 3176 trans.reset(); | 3179 trans.reset(); |
| 3177 | 3180 |
| 3178 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 3181 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
| 3179 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3182 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3180 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3183 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 3181 RemoveMockTransaction(&transaction); | 3184 RemoveMockTransaction(&transaction); |
| 3182 } | 3185 } |
| 3183 | 3186 |
| (...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5166 TEST(HttpCache, MAYBE_RangeGET_Cancel) { | 5169 TEST(HttpCache, MAYBE_RangeGET_Cancel) { |
| 5167 MockHttpCache cache; | 5170 MockHttpCache cache; |
| 5168 AddMockTransaction(&kRangeGET_TransactionOK); | 5171 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5169 | 5172 |
| 5170 MockHttpRequest request(kRangeGET_TransactionOK); | 5173 MockHttpRequest request(kRangeGET_TransactionOK); |
| 5171 | 5174 |
| 5172 Context* c = new Context(); | 5175 Context* c = new Context(); |
| 5173 int rv = cache.CreateTransaction(&c->trans); | 5176 int rv = cache.CreateTransaction(&c->trans); |
| 5174 ASSERT_THAT(rv, IsOk()); | 5177 ASSERT_THAT(rv, IsOk()); |
| 5175 | 5178 |
| 5176 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5179 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5177 if (rv == ERR_IO_PENDING) | 5180 if (rv == ERR_IO_PENDING) |
| 5178 rv = c->callback.WaitForResult(); | 5181 rv = c->callback.WaitForResult(); |
| 5179 | 5182 |
| 5180 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5183 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5181 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 5184 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 5182 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5185 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5183 | 5186 |
| 5184 // Make sure that the entry has some data stored. | 5187 // Make sure that the entry has some data stored. |
| 5185 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); | 5188 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); |
| 5186 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5189 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5211 AddMockTransaction(&kRangeGET_TransactionOK); | 5214 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5212 | 5215 |
| 5213 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 5216 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 5214 MockHttpRequest request(kRangeGET_TransactionOK); | 5217 MockHttpRequest request(kRangeGET_TransactionOK); |
| 5215 request.load_flags |= LOAD_VALIDATE_CACHE; | 5218 request.load_flags |= LOAD_VALIDATE_CACHE; |
| 5216 | 5219 |
| 5217 Context* c = new Context(); | 5220 Context* c = new Context(); |
| 5218 int rv = cache.CreateTransaction(&c->trans); | 5221 int rv = cache.CreateTransaction(&c->trans); |
| 5219 ASSERT_THAT(rv, IsOk()); | 5222 ASSERT_THAT(rv, IsOk()); |
| 5220 | 5223 |
| 5221 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5224 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5222 if (rv == ERR_IO_PENDING) | 5225 if (rv == ERR_IO_PENDING) |
| 5223 rv = c->callback.WaitForResult(); | 5226 rv = c->callback.WaitForResult(); |
| 5224 | 5227 |
| 5225 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5228 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 5226 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5229 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5227 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5230 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5228 | 5231 |
| 5229 // Make sure that we revalidate the entry and read from the cache (a single | 5232 // Make sure that we revalidate the entry and read from the cache (a single |
| 5230 // read will return while waiting for the network). | 5233 // read will return while waiting for the network). |
| 5231 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); | 5234 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5256 AddMockTransaction(&kRangeGET_TransactionOK); | 5259 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5257 | 5260 |
| 5258 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 5261 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 5259 MockHttpRequest request(kRangeGET_TransactionOK); | 5262 MockHttpRequest request(kRangeGET_TransactionOK); |
| 5260 request.load_flags |= LOAD_VALIDATE_CACHE; | 5263 request.load_flags |= LOAD_VALIDATE_CACHE; |
| 5261 | 5264 |
| 5262 Context* c = new Context(); | 5265 Context* c = new Context(); |
| 5263 int rv = cache.CreateTransaction(&c->trans); | 5266 int rv = cache.CreateTransaction(&c->trans); |
| 5264 ASSERT_THAT(rv, IsOk()); | 5267 ASSERT_THAT(rv, IsOk()); |
| 5265 | 5268 |
| 5266 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5269 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5267 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 5270 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 5268 rv = c->callback.WaitForResult(); | 5271 rv = c->callback.WaitForResult(); |
| 5269 | 5272 |
| 5270 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5273 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 5271 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5274 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5272 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5275 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5273 | 5276 |
| 5274 // Make sure that we revalidate the entry and read from the cache (a single | 5277 // Make sure that we revalidate the entry and read from the cache (a single |
| 5275 // read will return while waiting for the network). | 5278 // read will return while waiting for the network). |
| 5276 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); | 5279 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); |
| 5277 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5280 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 5278 EXPECT_EQ(5, c->callback.GetResult(rv)); | 5281 EXPECT_EQ(5, c->callback.GetResult(rv)); |
| 5279 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5282 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 5280 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 5283 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 5281 | 5284 |
| 5282 // Destroy the transaction before completing the read. | 5285 // Destroy the transaction before completing the read. |
| 5283 delete c; | 5286 delete c; |
| 5284 | 5287 |
| 5285 // We have the read and the delete (OnProcessPendingQueue) waiting on the | 5288 // We have the read and the delete (OnProcessPendingQueue) waiting on the |
| 5286 // message loop. This means that a new transaction will just reuse the same | 5289 // message loop. This means that a new transaction will just reuse the same |
| 5287 // active entry (no open or create). | 5290 // active entry (no open or create). |
| 5288 | 5291 |
| 5289 c = new Context(); | 5292 c = new Context(); |
| 5290 rv = cache.CreateTransaction(&c->trans); | 5293 rv = cache.CreateTransaction(&c->trans); |
| 5291 ASSERT_THAT(rv, IsOk()); | 5294 ASSERT_THAT(rv, IsOk()); |
| 5292 | 5295 |
| 5293 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5296 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5294 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 5297 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 5295 | 5298 |
| 5296 MockDiskEntry::IgnoreCallbacks(true); | 5299 MockDiskEntry::IgnoreCallbacks(true); |
| 5297 base::RunLoop().RunUntilIdle(); | 5300 base::RunLoop().RunUntilIdle(); |
| 5298 MockDiskEntry::IgnoreCallbacks(false); | 5301 MockDiskEntry::IgnoreCallbacks(false); |
| 5299 | 5302 |
| 5300 // The new transaction is waiting for the query range callback. | 5303 // The new transaction is waiting for the query range callback. |
| 5301 delete c; | 5304 delete c; |
| 5302 | 5305 |
| 5303 // And we should not crash when the callback is delivered. | 5306 // And we should not crash when the callback is delivered. |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5559 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; | 5562 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 5560 | 5563 |
| 5561 MockHttpRequest request(transaction); | 5564 MockHttpRequest request(transaction); |
| 5562 TestCompletionCallback callback; | 5565 TestCompletionCallback callback; |
| 5563 | 5566 |
| 5564 std::unique_ptr<HttpTransaction> trans; | 5567 std::unique_ptr<HttpTransaction> trans; |
| 5565 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); | 5568 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 5566 EXPECT_THAT(rv, IsOk()); | 5569 EXPECT_THAT(rv, IsOk()); |
| 5567 ASSERT_TRUE(trans.get()); | 5570 ASSERT_TRUE(trans.get()); |
| 5568 | 5571 |
| 5569 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 5572 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5570 if (rv == ERR_IO_PENDING) | 5573 if (rv == ERR_IO_PENDING) |
| 5571 rv = callback.WaitForResult(); | 5574 rv = callback.WaitForResult(); |
| 5572 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS)); | 5575 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 5573 | 5576 |
| 5574 trans.reset(); | 5577 trans.reset(); |
| 5575 | 5578 |
| 5576 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5579 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5577 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5580 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5578 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5581 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5579 | 5582 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5636 // to read from the network. | 5639 // to read from the network. |
| 5637 TEST(HttpCache, DoomOnDestruction) { | 5640 TEST(HttpCache, DoomOnDestruction) { |
| 5638 MockHttpCache cache; | 5641 MockHttpCache cache; |
| 5639 | 5642 |
| 5640 MockHttpRequest request(kSimpleGET_Transaction); | 5643 MockHttpRequest request(kSimpleGET_Transaction); |
| 5641 | 5644 |
| 5642 Context* c = new Context(); | 5645 Context* c = new Context(); |
| 5643 int rv = cache.CreateTransaction(&c->trans); | 5646 int rv = cache.CreateTransaction(&c->trans); |
| 5644 ASSERT_THAT(rv, IsOk()); | 5647 ASSERT_THAT(rv, IsOk()); |
| 5645 | 5648 |
| 5646 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5649 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5647 if (rv == ERR_IO_PENDING) | 5650 if (rv == ERR_IO_PENDING) |
| 5648 c->result = c->callback.WaitForResult(); | 5651 c->result = c->callback.WaitForResult(); |
| 5649 | 5652 |
| 5650 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5653 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5651 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 5654 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 5652 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5655 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5653 | 5656 |
| 5654 // Destroy the transaction. We only have the headers so we should delete this | 5657 // Destroy the transaction. We only have the headers so we should delete this |
| 5655 // entry. | 5658 // entry. |
| 5656 delete c; | 5659 delete c; |
| 5657 | 5660 |
| 5658 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 5661 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 5659 | 5662 |
| 5660 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5663 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 5661 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 5664 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 5662 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 5665 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 5663 } | 5666 } |
| 5664 | 5667 |
| 5665 // Tests that we delete an entry when the request is cancelled if the response | 5668 // Tests that we delete an entry when the request is cancelled if the response |
| 5666 // does not have content-length and strong validators. | 5669 // does not have content-length and strong validators. |
| 5667 TEST(HttpCache, DoomOnDestruction2) { | 5670 TEST(HttpCache, DoomOnDestruction2) { |
| 5668 MockHttpCache cache; | 5671 MockHttpCache cache; |
| 5669 | 5672 |
| 5670 MockHttpRequest request(kSimpleGET_Transaction); | 5673 MockHttpRequest request(kSimpleGET_Transaction); |
| 5671 | 5674 |
| 5672 Context* c = new Context(); | 5675 Context* c = new Context(); |
| 5673 int rv = cache.CreateTransaction(&c->trans); | 5676 int rv = cache.CreateTransaction(&c->trans); |
| 5674 ASSERT_THAT(rv, IsOk()); | 5677 ASSERT_THAT(rv, IsOk()); |
| 5675 | 5678 |
| 5676 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5679 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5677 if (rv == ERR_IO_PENDING) | 5680 if (rv == ERR_IO_PENDING) |
| 5678 rv = c->callback.WaitForResult(); | 5681 rv = c->callback.WaitForResult(); |
| 5679 | 5682 |
| 5680 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5683 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5681 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 5684 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 5682 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5685 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5683 | 5686 |
| 5684 // Make sure that the entry has some data stored. | 5687 // Make sure that the entry has some data stored. |
| 5685 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); | 5688 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); |
| 5686 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5689 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5709 "Content-Length: 22\n" | 5712 "Content-Length: 22\n" |
| 5710 "Accept-Ranges: none\n" | 5713 "Accept-Ranges: none\n" |
| 5711 "Etag: \"foopy\"\n"; | 5714 "Etag: \"foopy\"\n"; |
| 5712 AddMockTransaction(&transaction); | 5715 AddMockTransaction(&transaction); |
| 5713 MockHttpRequest request(transaction); | 5716 MockHttpRequest request(transaction); |
| 5714 | 5717 |
| 5715 Context* c = new Context(); | 5718 Context* c = new Context(); |
| 5716 int rv = cache.CreateTransaction(&c->trans); | 5719 int rv = cache.CreateTransaction(&c->trans); |
| 5717 ASSERT_THAT(rv, IsOk()); | 5720 ASSERT_THAT(rv, IsOk()); |
| 5718 | 5721 |
| 5719 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5722 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5720 if (rv == ERR_IO_PENDING) | 5723 if (rv == ERR_IO_PENDING) |
| 5721 rv = c->callback.WaitForResult(); | 5724 rv = c->callback.WaitForResult(); |
| 5722 | 5725 |
| 5723 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5726 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5724 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 5727 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 5725 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5728 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5726 | 5729 |
| 5727 // Make sure that the entry has some data stored. | 5730 // Make sure that the entry has some data stored. |
| 5728 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); | 5731 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); |
| 5729 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5732 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5752 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 5755 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
| 5753 "Content-Length: 22\n" | 5756 "Content-Length: 22\n" |
| 5754 "Etag: \"foopy\"\n"; | 5757 "Etag: \"foopy\"\n"; |
| 5755 MockHttpRequest request(transaction); | 5758 MockHttpRequest request(transaction); |
| 5756 | 5759 |
| 5757 std::unique_ptr<Context> c(new Context()); | 5760 std::unique_ptr<Context> c(new Context()); |
| 5758 | 5761 |
| 5759 int rv = cache.CreateTransaction(&c->trans); | 5762 int rv = cache.CreateTransaction(&c->trans); |
| 5760 ASSERT_THAT(rv, IsOk()); | 5763 ASSERT_THAT(rv, IsOk()); |
| 5761 | 5764 |
| 5762 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5765 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5763 if (rv == ERR_IO_PENDING) | 5766 if (rv == ERR_IO_PENDING) |
| 5764 rv = c->callback.WaitForResult(); | 5767 rv = c->callback.WaitForResult(); |
| 5765 | 5768 |
| 5766 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5769 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5767 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 5770 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 5768 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5771 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5769 | 5772 |
| 5770 // Make sure that the entry has some data stored. | 5773 // Make sure that the entry has some data stored. |
| 5771 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); | 5774 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); |
| 5772 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5775 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5804 transaction.response_headers = | 5807 transaction.response_headers = |
| 5805 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 5808 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
| 5806 "Content-Length: 22\n" | 5809 "Content-Length: 22\n" |
| 5807 "Etag: \"foopy\"\n"; | 5810 "Etag: \"foopy\"\n"; |
| 5808 MockHttpRequest request(transaction); | 5811 MockHttpRequest request(transaction); |
| 5809 | 5812 |
| 5810 std::unique_ptr<Context> c(new Context()); | 5813 std::unique_ptr<Context> c(new Context()); |
| 5811 int rv = cache.CreateTransaction(&c->trans); | 5814 int rv = cache.CreateTransaction(&c->trans); |
| 5812 ASSERT_THAT(rv, IsOk()); | 5815 ASSERT_THAT(rv, IsOk()); |
| 5813 | 5816 |
| 5814 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 5817 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5815 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 5818 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 5816 | 5819 |
| 5817 // Read everything. | 5820 // Read everything. |
| 5818 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(22)); | 5821 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(22)); |
| 5819 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5822 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 5820 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); | 5823 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); |
| 5821 | 5824 |
| 5822 // Destroy the transaction. | 5825 // Destroy the transaction. |
| 5823 c->trans.reset(); | 5826 c->trans.reset(); |
| 5824 | 5827 |
| 5825 // Verify that the entry is not marked as truncated. | 5828 // Verify that the entry is not marked as truncated. |
| 5826 VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, false, 0); | 5829 VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, false, 0); |
| 5827 } | 5830 } |
| 5828 | 5831 |
| 5829 // Tests that sparse entries don't set the truncate flag. | 5832 // Tests that sparse entries don't set the truncate flag. |
| 5830 TEST(HttpCache, RangeGET_DontTruncate) { | 5833 TEST(HttpCache, RangeGET_DontTruncate) { |
| 5831 MockHttpCache cache; | 5834 MockHttpCache cache; |
| 5832 | 5835 |
| 5833 ScopedMockTransaction transaction(kRangeGET_TransactionOK); | 5836 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 5834 transaction.request_headers = "Range: bytes = 0-19\r\n" EXTRA_HEADER; | 5837 transaction.request_headers = "Range: bytes = 0-19\r\n" EXTRA_HEADER; |
| 5835 | 5838 |
| 5836 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction)); | 5839 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction)); |
| 5837 std::unique_ptr<HttpTransaction> trans; | 5840 std::unique_ptr<HttpTransaction> trans; |
| 5838 | 5841 |
| 5839 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); | 5842 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 5840 EXPECT_THAT(rv, IsOk()); | 5843 EXPECT_THAT(rv, IsOk()); |
| 5841 | 5844 |
| 5842 TestCompletionCallback cb; | 5845 TestCompletionCallback cb; |
| 5843 rv = trans->Start(request.get(), cb.callback(), BoundNetLog()); | 5846 rv = trans->Start(request.get(), cb.callback(), NetLogWithSource()); |
| 5844 EXPECT_EQ(0, cb.GetResult(rv)); | 5847 EXPECT_EQ(0, cb.GetResult(rv)); |
| 5845 | 5848 |
| 5846 scoped_refptr<IOBuffer> buf(new IOBuffer(10)); | 5849 scoped_refptr<IOBuffer> buf(new IOBuffer(10)); |
| 5847 rv = trans->Read(buf.get(), 10, cb.callback()); | 5850 rv = trans->Read(buf.get(), 10, cb.callback()); |
| 5848 EXPECT_EQ(10, cb.GetResult(rv)); | 5851 EXPECT_EQ(10, cb.GetResult(rv)); |
| 5849 | 5852 |
| 5850 // Should not trigger any DCHECK. | 5853 // Should not trigger any DCHECK. |
| 5851 trans.reset(); | 5854 trans.reset(); |
| 5852 VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0); | 5855 VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0); |
| 5853 } | 5856 } |
| 5854 | 5857 |
| 5855 // Tests that sparse entries don't set the truncate flag (when the byte range | 5858 // Tests that sparse entries don't set the truncate flag (when the byte range |
| 5856 // starts after 0). | 5859 // starts after 0). |
| 5857 TEST(HttpCache, RangeGET_DontTruncate2) { | 5860 TEST(HttpCache, RangeGET_DontTruncate2) { |
| 5858 MockHttpCache cache; | 5861 MockHttpCache cache; |
| 5859 | 5862 |
| 5860 ScopedMockTransaction transaction(kRangeGET_TransactionOK); | 5863 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 5861 transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; | 5864 transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; |
| 5862 | 5865 |
| 5863 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction)); | 5866 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction)); |
| 5864 std::unique_ptr<HttpTransaction> trans; | 5867 std::unique_ptr<HttpTransaction> trans; |
| 5865 | 5868 |
| 5866 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); | 5869 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 5867 EXPECT_THAT(rv, IsOk()); | 5870 EXPECT_THAT(rv, IsOk()); |
| 5868 | 5871 |
| 5869 TestCompletionCallback cb; | 5872 TestCompletionCallback cb; |
| 5870 rv = trans->Start(request.get(), cb.callback(), BoundNetLog()); | 5873 rv = trans->Start(request.get(), cb.callback(), NetLogWithSource()); |
| 5871 EXPECT_EQ(0, cb.GetResult(rv)); | 5874 EXPECT_EQ(0, cb.GetResult(rv)); |
| 5872 | 5875 |
| 5873 scoped_refptr<IOBuffer> buf(new IOBuffer(10)); | 5876 scoped_refptr<IOBuffer> buf(new IOBuffer(10)); |
| 5874 rv = trans->Read(buf.get(), 10, cb.callback()); | 5877 rv = trans->Read(buf.get(), 10, cb.callback()); |
| 5875 EXPECT_EQ(10, cb.GetResult(rv)); | 5878 EXPECT_EQ(10, cb.GetResult(rv)); |
| 5876 | 5879 |
| 5877 // Should not trigger any DCHECK. | 5880 // Should not trigger any DCHECK. |
| 5878 trans.reset(); | 5881 trans.reset(); |
| 5879 VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0); | 5882 VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0); |
| 5880 } | 5883 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5987 int rv = cache.CreateTransaction(&c->trans); | 5990 int rv = cache.CreateTransaction(&c->trans); |
| 5988 ASSERT_THAT(rv, IsOk()); | 5991 ASSERT_THAT(rv, IsOk()); |
| 5989 | 5992 |
| 5990 // Queue another request to this transaction. We have to start this request | 5993 // Queue another request to this transaction. We have to start this request |
| 5991 // before the first one gets the response from the server and dooms the entry, | 5994 // before the first one gets the response from the server and dooms the entry, |
| 5992 // otherwise it will just create a new entry without being queued to the first | 5995 // otherwise it will just create a new entry without being queued to the first |
| 5993 // request. | 5996 // request. |
| 5994 Context* pending = new Context(); | 5997 Context* pending = new Context(); |
| 5995 ASSERT_THAT(cache.CreateTransaction(&pending->trans), IsOk()); | 5998 ASSERT_THAT(cache.CreateTransaction(&pending->trans), IsOk()); |
| 5996 | 5999 |
| 5997 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 6000 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 5998 EXPECT_EQ(ERR_IO_PENDING, | 6001 EXPECT_EQ(ERR_IO_PENDING, |
| 5999 pending->trans->Start(&request, pending->callback.callback(), | 6002 pending->trans->Start(&request, pending->callback.callback(), |
| 6000 BoundNetLog())); | 6003 NetLogWithSource())); |
| 6001 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 6004 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 6002 | 6005 |
| 6003 // Make sure that the entry has some data stored. | 6006 // Make sure that the entry has some data stored. |
| 6004 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); | 6007 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); |
| 6005 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 6008 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 6006 EXPECT_EQ(5, c->callback.GetResult(rv)); | 6009 EXPECT_EQ(5, c->callback.GetResult(rv)); |
| 6007 | 6010 |
| 6008 // Cancel the requests. | 6011 // Cancel the requests. |
| 6009 delete c; | 6012 delete c; |
| 6010 delete pending; | 6013 delete pending; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6072 std::string headers; | 6075 std::string headers; |
| 6073 MockTransaction transaction(kRangeGET_TransactionOK); | 6076 MockTransaction transaction(kRangeGET_TransactionOK); |
| 6074 transaction.request_headers = EXTRA_HEADER; | 6077 transaction.request_headers = EXTRA_HEADER; |
| 6075 transaction.data = kFullRangeData; | 6078 transaction.data = kFullRangeData; |
| 6076 | 6079 |
| 6077 std::unique_ptr<Context> c(new Context); | 6080 std::unique_ptr<Context> c(new Context); |
| 6078 int rv = cache.CreateTransaction(&c->trans); | 6081 int rv = cache.CreateTransaction(&c->trans); |
| 6079 ASSERT_THAT(rv, IsOk()); | 6082 ASSERT_THAT(rv, IsOk()); |
| 6080 | 6083 |
| 6081 MockHttpRequest request(transaction); | 6084 MockHttpRequest request(transaction); |
| 6082 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 6085 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 6083 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 6086 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 6084 | 6087 |
| 6085 // We should have checked with the server before finishing Start(). | 6088 // We should have checked with the server before finishing Start(). |
| 6086 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6089 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6087 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 6090 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 6088 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6091 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6089 | 6092 |
| 6090 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6093 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 6091 } | 6094 } |
| 6092 | 6095 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6107 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" | 6110 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" |
| 6108 EXTRA_HEADER; | 6111 EXTRA_HEADER; |
| 6109 transaction.data = kFullRangeData; | 6112 transaction.data = kFullRangeData; |
| 6110 RangeTransactionServer handler; | 6113 RangeTransactionServer handler; |
| 6111 | 6114 |
| 6112 std::unique_ptr<Context> c(new Context); | 6115 std::unique_ptr<Context> c(new Context); |
| 6113 int rv = cache.CreateTransaction(&c->trans); | 6116 int rv = cache.CreateTransaction(&c->trans); |
| 6114 ASSERT_THAT(rv, IsOk()); | 6117 ASSERT_THAT(rv, IsOk()); |
| 6115 | 6118 |
| 6116 MockHttpRequest request(transaction); | 6119 MockHttpRequest request(transaction); |
| 6117 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 6120 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 6118 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 6121 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 6119 | 6122 |
| 6120 const HttpResponseInfo* response = c->trans->GetResponseInfo(); | 6123 const HttpResponseInfo* response = c->trans->GetResponseInfo(); |
| 6121 ASSERT_TRUE(response); | 6124 ASSERT_TRUE(response); |
| 6122 ASSERT_EQ(401, response->headers->response_code()); | 6125 ASSERT_EQ(401, response->headers->response_code()); |
| 6123 rv = c->trans->RestartWithAuth(AuthCredentials(), c->callback.callback()); | 6126 rv = c->trans->RestartWithAuth(AuthCredentials(), c->callback.callback()); |
| 6124 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 6127 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 6125 response = c->trans->GetResponseInfo(); | 6128 response = c->trans->GetResponseInfo(); |
| 6126 ASSERT_TRUE(response); | 6129 ASSERT_TRUE(response); |
| 6127 ASSERT_EQ(200, response->headers->response_code()); | 6130 ASSERT_EQ(200, response->headers->response_code()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6159 transaction.request_headers = | 6162 transaction.request_headers = |
| 6160 "Range: bytes = 0-79\r\n" | 6163 "Range: bytes = 0-79\r\n" |
| 6161 "X-Require-Mock-Auth-Alt: dummy\r\n" EXTRA_HEADER; | 6164 "X-Require-Mock-Auth-Alt: dummy\r\n" EXTRA_HEADER; |
| 6162 | 6165 |
| 6163 std::unique_ptr<Context> c(new Context); | 6166 std::unique_ptr<Context> c(new Context); |
| 6164 int rv = cache.CreateTransaction(&c->trans); | 6167 int rv = cache.CreateTransaction(&c->trans); |
| 6165 ASSERT_THAT(rv, IsOk()); | 6168 ASSERT_THAT(rv, IsOk()); |
| 6166 | 6169 |
| 6167 MockHttpRequest request(transaction); | 6170 MockHttpRequest request(transaction); |
| 6168 | 6171 |
| 6169 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 6172 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 6170 if (rv == ERR_IO_PENDING) | 6173 if (rv == ERR_IO_PENDING) |
| 6171 rv = c->callback.WaitForResult(); | 6174 rv = c->callback.WaitForResult(); |
| 6172 std::string content; | 6175 std::string content; |
| 6173 rv = ReadTransaction(c->trans.get(), &content); | 6176 rv = ReadTransaction(c->trans.get(), &content); |
| 6174 EXPECT_THAT(rv, IsError(ERR_CACHE_AUTH_FAILURE_AFTER_READ)); | 6177 EXPECT_THAT(rv, IsError(ERR_CACHE_AUTH_FAILURE_AFTER_READ)); |
| 6175 } | 6178 } |
| 6176 | 6179 |
| 6177 // Tests that we cache a 200 response to the validation request. | 6180 // Tests that we cache a 200 response to the validation request. |
| 6178 TEST(HttpCache, GET_IncompleteResource4) { | 6181 TEST(HttpCache, GET_IncompleteResource4) { |
| 6179 MockHttpCache cache; | 6182 MockHttpCache cache; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6216 CreateTruncatedEntry(raw_headers, &cache); | 6219 CreateTruncatedEntry(raw_headers, &cache); |
| 6217 | 6220 |
| 6218 // Now make a regular request. | 6221 // Now make a regular request. |
| 6219 transaction.request_headers = EXTRA_HEADER; | 6222 transaction.request_headers = EXTRA_HEADER; |
| 6220 | 6223 |
| 6221 MockHttpRequest request(transaction); | 6224 MockHttpRequest request(transaction); |
| 6222 Context* c = new Context(); | 6225 Context* c = new Context(); |
| 6223 int rv = cache.CreateTransaction(&c->trans); | 6226 int rv = cache.CreateTransaction(&c->trans); |
| 6224 ASSERT_THAT(rv, IsOk()); | 6227 ASSERT_THAT(rv, IsOk()); |
| 6225 | 6228 |
| 6226 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); | 6229 rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 6227 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); | 6230 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); |
| 6228 | 6231 |
| 6229 // Read 20 bytes from the cache, and 10 from the net. | 6232 // Read 20 bytes from the cache, and 10 from the net. |
| 6230 scoped_refptr<IOBuffer> buf(new IOBuffer(100)); | 6233 scoped_refptr<IOBuffer> buf(new IOBuffer(100)); |
| 6231 rv = c->trans->Read(buf.get(), 20, c->callback.callback()); | 6234 rv = c->trans->Read(buf.get(), 20, c->callback.callback()); |
| 6232 EXPECT_EQ(20, c->callback.GetResult(rv)); | 6235 EXPECT_EQ(20, c->callback.GetResult(rv)); |
| 6233 rv = c->trans->Read(buf.get(), 10, c->callback.callback()); | 6236 rv = c->trans->Read(buf.get(), 10, c->callback.callback()); |
| 6234 EXPECT_EQ(10, c->callback.GetResult(rv)); | 6237 EXPECT_EQ(10, c->callback.GetResult(rv)); |
| 6235 | 6238 |
| 6236 // At this point, we are already reading so canceling the request should leave | 6239 // At this point, we are already reading so canceling the request should leave |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6283 TEST_MODE_SYNC_CACHE_WRITE); | 6286 TEST_MODE_SYNC_CACHE_WRITE); |
| 6284 | 6287 |
| 6285 MockHttpRequest r1(transaction), | 6288 MockHttpRequest r1(transaction), |
| 6286 r2(transaction), | 6289 r2(transaction), |
| 6287 r3(transaction); | 6290 r3(transaction); |
| 6288 | 6291 |
| 6289 TestTransactionConsumer c1(DEFAULT_PRIORITY, cache.http_cache()), | 6292 TestTransactionConsumer c1(DEFAULT_PRIORITY, cache.http_cache()), |
| 6290 c2(DEFAULT_PRIORITY, cache.http_cache()), | 6293 c2(DEFAULT_PRIORITY, cache.http_cache()), |
| 6291 c3(DEFAULT_PRIORITY, cache.http_cache()); | 6294 c3(DEFAULT_PRIORITY, cache.http_cache()); |
| 6292 | 6295 |
| 6293 c1.Start(&r1, BoundNetLog()); | 6296 c1.Start(&r1, NetLogWithSource()); |
| 6294 | 6297 |
| 6295 r2.load_flags |= LOAD_ONLY_FROM_CACHE; | 6298 r2.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 6296 c2.Start(&r2, BoundNetLog()); | 6299 c2.Start(&r2, NetLogWithSource()); |
| 6297 | 6300 |
| 6298 r3.load_flags |= LOAD_ONLY_FROM_CACHE; | 6301 r3.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 6299 c3.Start(&r3, BoundNetLog()); | 6302 c3.Start(&r3, NetLogWithSource()); |
| 6300 | 6303 |
| 6301 base::RunLoop().Run(); | 6304 base::RunLoop().Run(); |
| 6302 | 6305 |
| 6303 EXPECT_TRUE(c1.is_done()); | 6306 EXPECT_TRUE(c1.is_done()); |
| 6304 EXPECT_TRUE(c2.is_done()); | 6307 EXPECT_TRUE(c2.is_done()); |
| 6305 EXPECT_TRUE(c3.is_done()); | 6308 EXPECT_TRUE(c3.is_done()); |
| 6306 | 6309 |
| 6307 EXPECT_THAT(c1.error(), IsOk()); | 6310 EXPECT_THAT(c1.error(), IsOk()); |
| 6308 EXPECT_THAT(c2.error(), IsOk()); | 6311 EXPECT_THAT(c2.error(), IsOk()); |
| 6309 EXPECT_THAT(c3.error(), IsOk()); | 6312 EXPECT_THAT(c3.error(), IsOk()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 6335 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; | 6338 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; |
| 6336 | 6339 |
| 6337 MockHttpRequest request(kTestTransaction); | 6340 MockHttpRequest request(kTestTransaction); |
| 6338 TestCompletionCallback callback; | 6341 TestCompletionCallback callback; |
| 6339 | 6342 |
| 6340 // Write to the cache. | 6343 // Write to the cache. |
| 6341 { | 6344 { |
| 6342 std::unique_ptr<HttpTransaction> trans; | 6345 std::unique_ptr<HttpTransaction> trans; |
| 6343 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6346 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6344 | 6347 |
| 6345 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6348 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6346 if (rv == ERR_IO_PENDING) | 6349 if (rv == ERR_IO_PENDING) |
| 6347 rv = callback.WaitForResult(); | 6350 rv = callback.WaitForResult(); |
| 6348 ASSERT_THAT(rv, IsOk()); | 6351 ASSERT_THAT(rv, IsOk()); |
| 6349 | 6352 |
| 6350 const HttpResponseInfo* info = trans->GetResponseInfo(); | 6353 const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 6351 ASSERT_TRUE(info); | 6354 ASSERT_TRUE(info); |
| 6352 | 6355 |
| 6353 EXPECT_EQ(info->headers->response_code(), 301); | 6356 EXPECT_EQ(info->headers->response_code(), 301); |
| 6354 | 6357 |
| 6355 std::string location; | 6358 std::string location; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6369 // Active entries in the cache are not retired synchronously. Make | 6372 // Active entries in the cache are not retired synchronously. Make |
| 6370 // sure the next run hits the MockHttpCache and open_count is | 6373 // sure the next run hits the MockHttpCache and open_count is |
| 6371 // correct. | 6374 // correct. |
| 6372 base::RunLoop().RunUntilIdle(); | 6375 base::RunLoop().RunUntilIdle(); |
| 6373 | 6376 |
| 6374 // Read from the cache. | 6377 // Read from the cache. |
| 6375 { | 6378 { |
| 6376 std::unique_ptr<HttpTransaction> trans; | 6379 std::unique_ptr<HttpTransaction> trans; |
| 6377 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6380 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6378 | 6381 |
| 6379 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6382 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6380 if (rv == ERR_IO_PENDING) | 6383 if (rv == ERR_IO_PENDING) |
| 6381 rv = callback.WaitForResult(); | 6384 rv = callback.WaitForResult(); |
| 6382 ASSERT_THAT(rv, IsOk()); | 6385 ASSERT_THAT(rv, IsOk()); |
| 6383 | 6386 |
| 6384 const HttpResponseInfo* info = trans->GetResponseInfo(); | 6387 const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 6385 ASSERT_TRUE(info); | 6388 ASSERT_TRUE(info); |
| 6386 | 6389 |
| 6387 EXPECT_EQ(info->headers->response_code(), 301); | 6390 EXPECT_EQ(info->headers->response_code(), 301); |
| 6388 | 6391 |
| 6389 std::string location; | 6392 std::string location; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6550 | 6553 |
| 6551 // Test that it was not cached. | 6554 // Test that it was not cached. |
| 6552 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; | 6555 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; |
| 6553 | 6556 |
| 6554 MockHttpRequest request(transaction); | 6557 MockHttpRequest request(transaction); |
| 6555 TestCompletionCallback callback; | 6558 TestCompletionCallback callback; |
| 6556 | 6559 |
| 6557 std::unique_ptr<HttpTransaction> trans; | 6560 std::unique_ptr<HttpTransaction> trans; |
| 6558 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6561 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6559 | 6562 |
| 6560 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6563 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6561 if (rv == ERR_IO_PENDING) | 6564 if (rv == ERR_IO_PENDING) |
| 6562 rv = callback.WaitForResult(); | 6565 rv = callback.WaitForResult(); |
| 6563 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS)); | 6566 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 6564 } | 6567 } |
| 6565 | 6568 |
| 6566 // Ensure that we don't crash by if left-behind transactions. | 6569 // Ensure that we don't crash by if left-behind transactions. |
| 6567 TEST(HttpCache, OutlivedTransactions) { | 6570 TEST(HttpCache, OutlivedTransactions) { |
| 6568 MockHttpCache* cache = new MockHttpCache; | 6571 MockHttpCache* cache = new MockHttpCache; |
| 6569 | 6572 |
| 6570 std::unique_ptr<HttpTransaction> trans; | 6573 std::unique_ptr<HttpTransaction> trans; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6805 // of the stream. | 6808 // of the stream. |
| 6806 TEST(HttpCache, FilterCompletion) { | 6809 TEST(HttpCache, FilterCompletion) { |
| 6807 MockHttpCache cache; | 6810 MockHttpCache cache; |
| 6808 TestCompletionCallback callback; | 6811 TestCompletionCallback callback; |
| 6809 | 6812 |
| 6810 { | 6813 { |
| 6811 std::unique_ptr<HttpTransaction> trans; | 6814 std::unique_ptr<HttpTransaction> trans; |
| 6812 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6815 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6813 | 6816 |
| 6814 MockHttpRequest request(kSimpleGET_Transaction); | 6817 MockHttpRequest request(kSimpleGET_Transaction); |
| 6815 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6818 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6816 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 6819 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6817 | 6820 |
| 6818 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 6821 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 6819 rv = trans->Read(buf.get(), 256, callback.callback()); | 6822 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6820 EXPECT_GT(callback.GetResult(rv), 0); | 6823 EXPECT_GT(callback.GetResult(rv), 0); |
| 6821 | 6824 |
| 6822 // Now make sure that the entry is preserved. | 6825 // Now make sure that the entry is preserved. |
| 6823 trans->DoneReading(); | 6826 trans->DoneReading(); |
| 6824 } | 6827 } |
| 6825 | 6828 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6841 MockHttpCache cache; | 6844 MockHttpCache cache; |
| 6842 TestCompletionCallback callback; | 6845 TestCompletionCallback callback; |
| 6843 | 6846 |
| 6844 ScopedMockTransaction transaction(kSimpleGET_Transaction); | 6847 ScopedMockTransaction transaction(kSimpleGET_Transaction); |
| 6845 transaction.data = ""; | 6848 transaction.data = ""; |
| 6846 | 6849 |
| 6847 std::unique_ptr<HttpTransaction> trans; | 6850 std::unique_ptr<HttpTransaction> trans; |
| 6848 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6851 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6849 | 6852 |
| 6850 MockHttpRequest request(transaction); | 6853 MockHttpRequest request(transaction); |
| 6851 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6854 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6852 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 6855 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6853 | 6856 |
| 6854 trans->DoneReading(); | 6857 trans->DoneReading(); |
| 6855 // Leave the transaction around. | 6858 // Leave the transaction around. |
| 6856 | 6859 |
| 6857 // Make sure that the ActiveEntry is gone. | 6860 // Make sure that the ActiveEntry is gone. |
| 6858 base::RunLoop().RunUntilIdle(); | 6861 base::RunLoop().RunUntilIdle(); |
| 6859 | 6862 |
| 6860 // Read from the cache. This should not deadlock. | 6863 // Read from the cache. This should not deadlock. |
| 6861 RunTransactionTest(cache.http_cache(), transaction); | 6864 RunTransactionTest(cache.http_cache(), transaction); |
| 6862 | 6865 |
| 6863 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6866 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6864 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 6867 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 6865 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 6868 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 6866 } | 6869 } |
| 6867 | 6870 |
| 6868 // Tests that we stop caching when told. | 6871 // Tests that we stop caching when told. |
| 6869 TEST(HttpCache, StopCachingDeletesEntry) { | 6872 TEST(HttpCache, StopCachingDeletesEntry) { |
| 6870 MockHttpCache cache; | 6873 MockHttpCache cache; |
| 6871 TestCompletionCallback callback; | 6874 TestCompletionCallback callback; |
| 6872 MockHttpRequest request(kSimpleGET_Transaction); | 6875 MockHttpRequest request(kSimpleGET_Transaction); |
| 6873 | 6876 |
| 6874 { | 6877 { |
| 6875 std::unique_ptr<HttpTransaction> trans; | 6878 std::unique_ptr<HttpTransaction> trans; |
| 6876 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6879 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6877 | 6880 |
| 6878 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6881 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6879 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 6882 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6880 | 6883 |
| 6881 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 6884 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 6882 rv = trans->Read(buf.get(), 10, callback.callback()); | 6885 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 6883 EXPECT_EQ(10, callback.GetResult(rv)); | 6886 EXPECT_EQ(10, callback.GetResult(rv)); |
| 6884 | 6887 |
| 6885 trans->StopCaching(); | 6888 trans->StopCaching(); |
| 6886 | 6889 |
| 6887 // We should be able to keep reading. | 6890 // We should be able to keep reading. |
| 6888 rv = trans->Read(buf.get(), 256, callback.callback()); | 6891 rv = trans->Read(buf.get(), 256, callback.callback()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6906 // after StopCaching. | 6909 // after StopCaching. |
| 6907 TEST(HttpCache, StopCachingThenDoneReadingDeletesEntry) { | 6910 TEST(HttpCache, StopCachingThenDoneReadingDeletesEntry) { |
| 6908 MockHttpCache cache; | 6911 MockHttpCache cache; |
| 6909 TestCompletionCallback callback; | 6912 TestCompletionCallback callback; |
| 6910 MockHttpRequest request(kSimpleGET_Transaction); | 6913 MockHttpRequest request(kSimpleGET_Transaction); |
| 6911 | 6914 |
| 6912 { | 6915 { |
| 6913 std::unique_ptr<HttpTransaction> trans; | 6916 std::unique_ptr<HttpTransaction> trans; |
| 6914 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6917 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6915 | 6918 |
| 6916 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6919 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6917 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 6920 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6918 | 6921 |
| 6919 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 6922 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 6920 rv = trans->Read(buf.get(), 10, callback.callback()); | 6923 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 6921 EXPECT_EQ(10, callback.GetResult(rv)); | 6924 EXPECT_EQ(10, callback.GetResult(rv)); |
| 6922 | 6925 |
| 6923 trans->StopCaching(); | 6926 trans->StopCaching(); |
| 6924 | 6927 |
| 6925 // We should be able to keep reading. | 6928 // We should be able to keep reading. |
| 6926 rv = trans->Read(buf.get(), 256, callback.callback()); | 6929 rv = trans->Read(buf.get(), 256, callback.callback()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6949 TestCompletionCallback callback; | 6952 TestCompletionCallback callback; |
| 6950 MockTransaction mock_transaction(kSimpleGET_Transaction); | 6953 MockTransaction mock_transaction(kSimpleGET_Transaction); |
| 6951 mock_transaction.status = "HTTP/1.1 401 Unauthorized"; | 6954 mock_transaction.status = "HTTP/1.1 401 Unauthorized"; |
| 6952 AddMockTransaction(&mock_transaction); | 6955 AddMockTransaction(&mock_transaction); |
| 6953 MockHttpRequest request(mock_transaction); | 6956 MockHttpRequest request(mock_transaction); |
| 6954 | 6957 |
| 6955 { | 6958 { |
| 6956 std::unique_ptr<HttpTransaction> trans; | 6959 std::unique_ptr<HttpTransaction> trans; |
| 6957 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6960 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6958 | 6961 |
| 6959 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6962 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6960 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 6963 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6961 | 6964 |
| 6962 trans->StopCaching(); | 6965 trans->StopCaching(); |
| 6963 | 6966 |
| 6964 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 6967 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 6965 rv = trans->Read(buf.get(), 10, callback.callback()); | 6968 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 6966 EXPECT_EQ(callback.GetResult(rv), 10); | 6969 EXPECT_EQ(callback.GetResult(rv), 10); |
| 6967 } | 6970 } |
| 6968 RemoveMockTransaction(&mock_transaction); | 6971 RemoveMockTransaction(&mock_transaction); |
| 6969 | 6972 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 6988 std::unique_ptr<HttpTransaction> trans; | 6991 std::unique_ptr<HttpTransaction> trans; |
| 6989 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 6992 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 6990 | 6993 |
| 6991 // Force a response that can be resumed. | 6994 // Force a response that can be resumed. |
| 6992 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction); | 6995 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction); |
| 6993 AddMockTransaction(&mock_transaction); | 6996 AddMockTransaction(&mock_transaction); |
| 6994 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" | 6997 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" |
| 6995 "Content-Length: 42\n" | 6998 "Content-Length: 42\n" |
| 6996 "Etag: \"foo\"\n"; | 6999 "Etag: \"foo\"\n"; |
| 6997 | 7000 |
| 6998 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 7001 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 6999 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 7002 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7000 | 7003 |
| 7001 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 7004 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 7002 rv = trans->Read(buf.get(), 10, callback.callback()); | 7005 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 7003 EXPECT_EQ(callback.GetResult(rv), 10); | 7006 EXPECT_EQ(callback.GetResult(rv), 10); |
| 7004 | 7007 |
| 7005 trans->StopCaching(); | 7008 trans->StopCaching(); |
| 7006 | 7009 |
| 7007 // We should be able to keep reading. | 7010 // We should be able to keep reading. |
| 7008 rv = trans->Read(buf.get(), 256, callback.callback()); | 7011 rv = trans->Read(buf.get(), 256, callback.callback()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 7029 "ETag: \"foo\"\n" | 7032 "ETag: \"foo\"\n" |
| 7030 "Accept-Ranges: bytes\n" | 7033 "Accept-Ranges: bytes\n" |
| 7031 "Content-Length: 80\n"); | 7034 "Content-Length: 80\n"); |
| 7032 CreateTruncatedEntry(raw_headers, &cache); | 7035 CreateTruncatedEntry(raw_headers, &cache); |
| 7033 | 7036 |
| 7034 { | 7037 { |
| 7035 // Now make a regular request. | 7038 // Now make a regular request. |
| 7036 std::unique_ptr<HttpTransaction> trans; | 7039 std::unique_ptr<HttpTransaction> trans; |
| 7037 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); | 7040 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); |
| 7038 | 7041 |
| 7039 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 7042 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 7040 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 7043 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7041 | 7044 |
| 7042 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); | 7045 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
| 7043 rv = trans->Read(buf.get(), 10, callback.callback()); | 7046 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 7044 EXPECT_EQ(callback.GetResult(rv), 10); | 7047 EXPECT_EQ(callback.GetResult(rv), 10); |
| 7045 | 7048 |
| 7046 // This is actually going to do nothing. | 7049 // This is actually going to do nothing. |
| 7047 trans->StopCaching(); | 7050 trans->StopCaching(); |
| 7048 | 7051 |
| 7049 // We should be able to keep reading. | 7052 // We should be able to keep reading. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7284 ASSERT_EQ(net::OK, rv); | 7287 ASSERT_EQ(net::OK, rv); |
| 7285 ASSERT_TRUE(http_transaction.get()); | 7288 ASSERT_TRUE(http_transaction.get()); |
| 7286 | 7289 |
| 7287 bool network_transaction_started = false; | 7290 bool network_transaction_started = false; |
| 7288 if (stop_caching_phase == TransactionPhase::AFTER_NETWORK_READ) { | 7291 if (stop_caching_phase == TransactionPhase::AFTER_NETWORK_READ) { |
| 7289 http_transaction->SetBeforeNetworkStartCallback( | 7292 http_transaction->SetBeforeNetworkStartCallback( |
| 7290 base::Bind(&SetFlagOnBeforeNetworkStart, &network_transaction_started)); | 7293 base::Bind(&SetFlagOnBeforeNetworkStart, &network_transaction_started)); |
| 7291 } | 7294 } |
| 7292 | 7295 |
| 7293 rv = http_transaction->Start(&request, callback.callback(), | 7296 rv = http_transaction->Start(&request, callback.callback(), |
| 7294 net::BoundNetLog()); | 7297 NetLogWithSource()); |
| 7295 rv = callback.GetResult(rv); | 7298 rv = callback.GetResult(rv); |
| 7296 ASSERT_EQ(net::OK, rv); | 7299 ASSERT_EQ(net::OK, rv); |
| 7297 | 7300 |
| 7298 if (stop_caching_phase == TransactionPhase::BEFORE_FIRST_READ) | 7301 if (stop_caching_phase == TransactionPhase::BEFORE_FIRST_READ) |
| 7299 http_transaction->StopCaching(); | 7302 http_transaction->StopCaching(); |
| 7300 | 7303 |
| 7301 int64_t total_bytes_received = 0; | 7304 int64_t total_bytes_received = 0; |
| 7302 | 7305 |
| 7303 EXPECT_EQ(kTotalSize, | 7306 EXPECT_EQ(kTotalSize, |
| 7304 http_transaction->GetResponseInfo()->headers->GetContentLength()); | 7307 http_transaction->GetResponseInfo()->headers->GetContentLength()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7382 trans->SetPriority(LOW); | 7385 trans->SetPriority(LOW); |
| 7383 | 7386 |
| 7384 EXPECT_FALSE(cache.network_layer()->last_transaction()); | 7387 EXPECT_FALSE(cache.network_layer()->last_transaction()); |
| 7385 EXPECT_EQ(DEFAULT_PRIORITY, | 7388 EXPECT_EQ(DEFAULT_PRIORITY, |
| 7386 cache.network_layer()->last_create_transaction_priority()); | 7389 cache.network_layer()->last_create_transaction_priority()); |
| 7387 | 7390 |
| 7388 HttpRequestInfo info; | 7391 HttpRequestInfo info; |
| 7389 info.url = GURL(kSimpleGET_Transaction.url); | 7392 info.url = GURL(kSimpleGET_Transaction.url); |
| 7390 TestCompletionCallback callback; | 7393 TestCompletionCallback callback; |
| 7391 EXPECT_EQ(ERR_IO_PENDING, | 7394 EXPECT_EQ(ERR_IO_PENDING, |
| 7392 trans->Start(&info, callback.callback(), BoundNetLog())); | 7395 trans->Start(&info, callback.callback(), NetLogWithSource())); |
| 7393 | 7396 |
| 7394 EXPECT_TRUE(cache.network_layer()->last_transaction()); | 7397 EXPECT_TRUE(cache.network_layer()->last_transaction()); |
| 7395 if (cache.network_layer()->last_transaction()) { | 7398 if (cache.network_layer()->last_transaction()) { |
| 7396 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority()); | 7399 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority()); |
| 7397 EXPECT_EQ(LOW, cache.network_layer()->last_transaction()->priority()); | 7400 EXPECT_EQ(LOW, cache.network_layer()->last_transaction()->priority()); |
| 7398 } | 7401 } |
| 7399 | 7402 |
| 7400 trans->SetPriority(HIGHEST); | 7403 trans->SetPriority(HIGHEST); |
| 7401 | 7404 |
| 7402 if (cache.network_layer()->last_transaction()) { | 7405 if (cache.network_layer()->last_transaction()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7415 FakeWebSocketHandshakeStreamCreateHelper create_helper; | 7418 FakeWebSocketHandshakeStreamCreateHelper create_helper; |
| 7416 std::unique_ptr<HttpTransaction> trans; | 7419 std::unique_ptr<HttpTransaction> trans; |
| 7417 ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk()); | 7420 ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk()); |
| 7418 | 7421 |
| 7419 EXPECT_FALSE(cache.network_layer()->last_transaction()); | 7422 EXPECT_FALSE(cache.network_layer()->last_transaction()); |
| 7420 | 7423 |
| 7421 HttpRequestInfo info; | 7424 HttpRequestInfo info; |
| 7422 info.url = GURL(kSimpleGET_Transaction.url); | 7425 info.url = GURL(kSimpleGET_Transaction.url); |
| 7423 TestCompletionCallback callback; | 7426 TestCompletionCallback callback; |
| 7424 EXPECT_EQ(ERR_IO_PENDING, | 7427 EXPECT_EQ(ERR_IO_PENDING, |
| 7425 trans->Start(&info, callback.callback(), BoundNetLog())); | 7428 trans->Start(&info, callback.callback(), NetLogWithSource())); |
| 7426 | 7429 |
| 7427 ASSERT_TRUE(cache.network_layer()->last_transaction()); | 7430 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
| 7428 EXPECT_FALSE(cache.network_layer()->last_transaction()-> | 7431 EXPECT_FALSE(cache.network_layer()->last_transaction()-> |
| 7429 websocket_handshake_stream_create_helper()); | 7432 websocket_handshake_stream_create_helper()); |
| 7430 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper); | 7433 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper); |
| 7431 EXPECT_EQ(&create_helper, | 7434 EXPECT_EQ(&create_helper, |
| 7432 cache.network_layer()->last_transaction()-> | 7435 cache.network_layer()->last_transaction()-> |
| 7433 websocket_handshake_stream_create_helper()); | 7436 websocket_handshake_stream_create_helper()); |
| 7434 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 7437 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 7435 } | 7438 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7454 transaction.data = kFullRangeData; | 7457 transaction.data = kFullRangeData; |
| 7455 | 7458 |
| 7456 std::unique_ptr<HttpTransaction> trans; | 7459 std::unique_ptr<HttpTransaction> trans; |
| 7457 ASSERT_THAT(cache.http_cache()->CreateTransaction(MEDIUM, &trans), IsOk()); | 7460 ASSERT_THAT(cache.http_cache()->CreateTransaction(MEDIUM, &trans), IsOk()); |
| 7458 EXPECT_EQ(DEFAULT_PRIORITY, | 7461 EXPECT_EQ(DEFAULT_PRIORITY, |
| 7459 cache.network_layer()->last_create_transaction_priority()); | 7462 cache.network_layer()->last_create_transaction_priority()); |
| 7460 | 7463 |
| 7461 MockHttpRequest info(transaction); | 7464 MockHttpRequest info(transaction); |
| 7462 TestCompletionCallback callback; | 7465 TestCompletionCallback callback; |
| 7463 EXPECT_EQ(ERR_IO_PENDING, | 7466 EXPECT_EQ(ERR_IO_PENDING, |
| 7464 trans->Start(&info, callback.callback(), BoundNetLog())); | 7467 trans->Start(&info, callback.callback(), NetLogWithSource())); |
| 7465 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 7468 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 7466 | 7469 |
| 7467 EXPECT_EQ(MEDIUM, cache.network_layer()->last_create_transaction_priority()); | 7470 EXPECT_EQ(MEDIUM, cache.network_layer()->last_create_transaction_priority()); |
| 7468 | 7471 |
| 7469 trans->SetPriority(HIGHEST); | 7472 trans->SetPriority(HIGHEST); |
| 7470 // Should trigger a new network transaction and pick up the new | 7473 // Should trigger a new network transaction and pick up the new |
| 7471 // priority. | 7474 // priority. |
| 7472 ReadAndVerifyTransaction(trans.get(), transaction); | 7475 ReadAndVerifyTransaction(trans.get(), transaction); |
| 7473 | 7476 |
| 7474 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority()); | 7477 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority()); |
| 7475 | 7478 |
| 7476 RemoveMockTransaction(&kRangeGET_TransactionOK); | 7479 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 7477 } | 7480 } |
| 7478 | 7481 |
| 7479 namespace { | 7482 namespace { |
| 7480 | 7483 |
| 7481 void RunTransactionAndGetNetworkBytes(MockHttpCache& cache, | 7484 void RunTransactionAndGetNetworkBytes(MockHttpCache& cache, |
| 7482 const MockTransaction& trans_info, | 7485 const MockTransaction& trans_info, |
| 7483 int64_t* sent_bytes, | 7486 int64_t* sent_bytes, |
| 7484 int64_t* received_bytes) { | 7487 int64_t* received_bytes) { |
| 7485 RunTransactionTestBase(cache.http_cache(), trans_info, | 7488 RunTransactionTestBase( |
| 7486 MockHttpRequest(trans_info), nullptr, BoundNetLog(), | 7489 cache.http_cache(), trans_info, MockHttpRequest(trans_info), nullptr, |
| 7487 nullptr, sent_bytes, received_bytes, nullptr); | 7490 NetLogWithSource(), nullptr, sent_bytes, received_bytes, nullptr); |
| 7488 } | 7491 } |
| 7489 | 7492 |
| 7490 } // namespace | 7493 } // namespace |
| 7491 | 7494 |
| 7492 TEST(HttpCache, NetworkBytesCacheMissAndThenHit) { | 7495 TEST(HttpCache, NetworkBytesCacheMissAndThenHit) { |
| 7493 MockHttpCache cache; | 7496 MockHttpCache cache; |
| 7494 | 7497 |
| 7495 MockTransaction transaction(kSimpleGET_Transaction); | 7498 MockTransaction transaction(kSimpleGET_Transaction); |
| 7496 int64_t sent, received; | 7499 int64_t sent, received; |
| 7497 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); | 7500 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7845 transaction.data = "rg: 00-09 "; | 7848 transaction.data = "rg: 00-09 "; |
| 7846 AddMockTransaction(&transaction); | 7849 AddMockTransaction(&transaction); |
| 7847 | 7850 |
| 7848 TestCompletionCallback callback; | 7851 TestCompletionCallback callback; |
| 7849 std::unique_ptr<HttpTransaction> trans; | 7852 std::unique_ptr<HttpTransaction> trans; |
| 7850 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); | 7853 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 7851 EXPECT_THAT(rv, IsOk()); | 7854 EXPECT_THAT(rv, IsOk()); |
| 7852 ASSERT_TRUE(trans.get()); | 7855 ASSERT_TRUE(trans.get()); |
| 7853 | 7856 |
| 7854 // Start our transaction. | 7857 // Start our transaction. |
| 7855 trans->Start(&request, callback.callback(), BoundNetLog()); | 7858 trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 7856 | 7859 |
| 7857 // A second transaction on a different part of the file (the default | 7860 // A second transaction on a different part of the file (the default |
| 7858 // kRangeGET_TransactionOK requests 40-49) should not be blocked by | 7861 // kRangeGET_TransactionOK requests 40-49) should not be blocked by |
| 7859 // the already pending transaction. | 7862 // the already pending transaction. |
| 7860 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 7863 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 7861 | 7864 |
| 7862 // Let the first transaction complete. | 7865 // Let the first transaction complete. |
| 7863 callback.WaitForResult(); | 7866 callback.WaitForResult(); |
| 7864 | 7867 |
| 7865 RemoveMockTransaction(&transaction); | 7868 RemoveMockTransaction(&transaction); |
| 7866 } | 7869 } |
| 7867 | 7870 |
| 7868 // Makes sure that a request stops using the cache when the response headers | 7871 // Makes sure that a request stops using the cache when the response headers |
| 7869 // with "Cache-Control: no-store" arrives. That means that another request for | 7872 // with "Cache-Control: no-store" arrives. That means that another request for |
| 7870 // the same URL can be processed before the response body of the original | 7873 // the same URL can be processed before the response body of the original |
| 7871 // request arrives. | 7874 // request arrives. |
| 7872 TEST(HttpCache, NoStoreResponseShouldNotBlockFollowingRequests) { | 7875 TEST(HttpCache, NoStoreResponseShouldNotBlockFollowingRequests) { |
| 7873 MockHttpCache cache; | 7876 MockHttpCache cache; |
| 7874 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction); | 7877 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction); |
| 7875 mock_transaction.response_headers = "Cache-Control: no-store\n"; | 7878 mock_transaction.response_headers = "Cache-Control: no-store\n"; |
| 7876 MockHttpRequest request(mock_transaction); | 7879 MockHttpRequest request(mock_transaction); |
| 7877 | 7880 |
| 7878 std::unique_ptr<Context> first(new Context); | 7881 std::unique_ptr<Context> first(new Context); |
| 7879 first->result = cache.CreateTransaction(&first->trans); | 7882 first->result = cache.CreateTransaction(&first->trans); |
| 7880 ASSERT_THAT(first->result, IsOk()); | 7883 ASSERT_THAT(first->result, IsOk()); |
| 7881 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); | 7884 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); |
| 7882 first->result = | 7885 first->result = first->trans->Start(&request, first->callback.callback(), |
| 7883 first->trans->Start(&request, first->callback.callback(), BoundNetLog()); | 7886 NetLogWithSource()); |
| 7884 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState()); | 7887 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState()); |
| 7885 | 7888 |
| 7886 base::RunLoop().RunUntilIdle(); | 7889 base::RunLoop().RunUntilIdle(); |
| 7887 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); | 7890 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); |
| 7888 ASSERT_TRUE(first->trans->GetResponseInfo()); | 7891 ASSERT_TRUE(first->trans->GetResponseInfo()); |
| 7889 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue( | 7892 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7890 "Cache-Control", "no-store")); | 7893 "Cache-Control", "no-store")); |
| 7891 // Here we have read the response header but not read the response body yet. | 7894 // Here we have read the response header but not read the response body yet. |
| 7892 | 7895 |
| 7893 // Let us create the second (read) transaction. | 7896 // Let us create the second (read) transaction. |
| 7894 std::unique_ptr<Context> second(new Context); | 7897 std::unique_ptr<Context> second(new Context); |
| 7895 second->result = cache.CreateTransaction(&second->trans); | 7898 second->result = cache.CreateTransaction(&second->trans); |
| 7896 ASSERT_THAT(second->result, IsOk()); | 7899 ASSERT_THAT(second->result, IsOk()); |
| 7897 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7900 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7898 second->result = second->trans->Start(&request, second->callback.callback(), | 7901 second->result = second->trans->Start(&request, second->callback.callback(), |
| 7899 BoundNetLog()); | 7902 NetLogWithSource()); |
| 7900 | 7903 |
| 7901 // Here the second transaction proceeds without reading the first body. | 7904 // Here the second transaction proceeds without reading the first body. |
| 7902 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7905 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
| 7903 base::RunLoop().RunUntilIdle(); | 7906 base::RunLoop().RunUntilIdle(); |
| 7904 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7907 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7905 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7908 ASSERT_TRUE(second->trans->GetResponseInfo()); |
| 7906 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7909 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7907 "Cache-Control", "no-store")); | 7910 "Cache-Control", "no-store")); |
| 7908 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7911 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
| 7909 } | 7912 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8097 RunTransactionTestWithResponseInfo(cache.http_cache(), | 8100 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 8098 kTypicalGET_Transaction, &response_info); | 8101 kTypicalGET_Transaction, &response_info); |
| 8099 | 8102 |
| 8100 EXPECT_FALSE(response_info.was_cached); | 8103 EXPECT_FALSE(response_info.was_cached); |
| 8101 EXPECT_TRUE(response_info.network_accessed); | 8104 EXPECT_TRUE(response_info.network_accessed); |
| 8102 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | 8105 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
| 8103 response_info.cache_entry_status); | 8106 response_info.cache_entry_status); |
| 8104 } | 8107 } |
| 8105 | 8108 |
| 8106 } // namespace net | 8109 } // namespace net |
| OLD | NEW |