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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 4403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4414 | 4414 |
4415 // And we should not crash when the callback is delivered. | 4415 // And we should not crash when the callback is delivered. |
4416 base::MessageLoop::current()->RunUntilIdle(); | 4416 base::MessageLoop::current()->RunUntilIdle(); |
4417 | 4417 |
4418 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4418 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
4419 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4419 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4420 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4420 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4421 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4421 RemoveMockTransaction(&kRangeGET_TransactionOK); |
4422 } | 4422 } |
4423 | 4423 |
| 4424 // Tests that we allow multiple simultaneous, non-overlapping transactions to |
| 4425 // take place on a sparse entry. |
| 4426 TEST(HttpCache, RangeGET_MultipleRequests) { |
| 4427 MockHttpCache cache; |
| 4428 |
| 4429 // Create a transaction for bytes 0-9. |
| 4430 MockHttpRequest request(kRangeGET_TransactionOK); |
| 4431 MockTransaction transaction(kRangeGET_TransactionOK); |
| 4432 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; |
| 4433 transaction.data = "rg: 00-09 "; |
| 4434 AddMockTransaction(&transaction); |
| 4435 |
| 4436 net::TestCompletionCallback callback; |
| 4437 scoped_ptr<net::HttpTransaction> trans; |
| 4438 int rv = cache.http_cache()->CreateTransaction(net::DEFAULT_PRIORITY, &trans); |
| 4439 EXPECT_EQ(net::OK, rv); |
| 4440 ASSERT_TRUE(trans.get()); |
| 4441 |
| 4442 // Start our transaction. |
| 4443 trans->Start(&request, callback.callback(), net::BoundNetLog()); |
| 4444 |
| 4445 // A second transaction on a different part of the file (the default |
| 4446 // kRangeGET_TransactionOK requests 40-49) should not be blocked by |
| 4447 // the already pending transaction. |
| 4448 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 4449 |
| 4450 // Let the first transaction complete. |
| 4451 callback.WaitForResult(); |
| 4452 |
| 4453 RemoveMockTransaction(&transaction); |
| 4454 } |
| 4455 |
4424 // Tests that an invalid range response results in no cached entry. | 4456 // Tests that an invalid range response results in no cached entry. |
4425 TEST(HttpCache, RangeGET_InvalidResponse1) { | 4457 TEST(HttpCache, RangeGET_InvalidResponse1) { |
4426 MockHttpCache cache; | 4458 MockHttpCache cache; |
4427 std::string headers; | 4459 std::string headers; |
4428 | 4460 |
4429 MockTransaction transaction(kRangeGET_TransactionOK); | 4461 MockTransaction transaction(kRangeGET_TransactionOK); |
4430 transaction.handler = NULL; | 4462 transaction.handler = NULL; |
4431 transaction.response_headers = "Content-Range: bytes 40-49/45\n" | 4463 transaction.response_headers = "Content-Range: bytes 40-49/45\n" |
4432 "Content-Length: 10\n"; | 4464 "Content-Length: 10\n"; |
4433 AddMockTransaction(&transaction); | 4465 AddMockTransaction(&transaction); |
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6409 base::MessageLoop::current()->RunUntilIdle(); | 6441 base::MessageLoop::current()->RunUntilIdle(); |
6410 | 6442 |
6411 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. | 6443 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. |
6412 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 6444 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
6413 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 6445 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
6414 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); | 6446 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); |
6415 EXPECT_EQ(range_response_size * 2, received_bytes); | 6447 EXPECT_EQ(range_response_size * 2, received_bytes); |
6416 | 6448 |
6417 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6449 RemoveMockTransaction(&kRangeGET_TransactionOK); |
6418 } | 6450 } |
OLD | NEW |