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. Currently this is supported with a hack (see | |
4426 // comment in Transaction::DoAddToEntry in http_cache_transaction.cc), but a | |
rvargas (doing something else)
2014/05/29 19:58:52
If we expect this test to pass now and with a futu
rileya (GONE FROM CHROMIUM)
2014/05/29 20:15:03
Good point, removed.
| |
4427 // future, cleaner solution should still pass this test. | |
4428 TEST(HttpCache, RangeGET_MultipleRequests) { | |
4429 MockHttpCache cache; | |
4430 | |
4431 // Create a transaction for bytes 0-9. | |
4432 MockHttpRequest request(kRangeGET_TransactionOK); | |
4433 request.load_flags |= net::LOAD_VALIDATE_CACHE; | |
rvargas (doing something else)
2014/05/29 19:58:52
no need for this flag
rileya (GONE FROM CHROMIUM)
2014/05/29 20:15:03
Removed.
| |
4434 MockTransaction transaction(kRangeGET_TransactionOK); | |
4435 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | |
4436 transaction.data = "rg: 00-09"; | |
rvargas (doing something else)
2014/05/29 19:58:52
Should need an extra space at the end (to make it
rileya (GONE FROM CHROMIUM)
2014/05/29 20:15:03
Added.
| |
4437 transaction.handler = NULL; | |
rvargas (doing something else)
2014/05/29 19:58:52
why remove the server?
rileya (GONE FROM CHROMIUM)
2014/05/29 20:15:03
Another test elsewhere did this so I assumed it ha
| |
4438 AddMockTransaction(&transaction); | |
rvargas (doing something else)
2014/05/29 19:58:52
Should be paired with a RemoveMockTransaction()
rileya (GONE FROM CHROMIUM)
2014/05/29 20:15:03
Added.
| |
4439 | |
4440 net::TestCompletionCallback callback; | |
4441 scoped_ptr<net::HttpTransaction> trans; | |
4442 int rv = cache.http_cache()->CreateTransaction(net::DEFAULT_PRIORITY, &trans); | |
4443 EXPECT_EQ(net::OK, rv); | |
4444 ASSERT_TRUE(trans.get()); | |
4445 | |
4446 // Start our transaction. | |
4447 trans->Start(&request, callback.callback(), net::BoundNetLog()); | |
4448 | |
4449 // A second transaction on a different part of the file (the default | |
4450 // kRangeGET_TransactionOK requests 40-49) should not be blocked by | |
4451 // the already pending transaction. | |
4452 AddMockTransaction(&kRangeGET_TransactionOK); | |
rvargas (doing something else)
2014/05/29 19:58:52
This is not needed... transactions are keyed by th
rileya (GONE FROM CHROMIUM)
2014/05/29 20:15:03
Removed.
| |
4453 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | |
4454 | |
4455 // Let the first transaction complete. | |
4456 callback.WaitForResult(); | |
4457 } | |
4458 | |
4424 // Tests that an invalid range response results in no cached entry. | 4459 // Tests that an invalid range response results in no cached entry. |
4425 TEST(HttpCache, RangeGET_InvalidResponse1) { | 4460 TEST(HttpCache, RangeGET_InvalidResponse1) { |
4426 MockHttpCache cache; | 4461 MockHttpCache cache; |
4427 std::string headers; | 4462 std::string headers; |
4428 | 4463 |
4429 MockTransaction transaction(kRangeGET_TransactionOK); | 4464 MockTransaction transaction(kRangeGET_TransactionOK); |
4430 transaction.handler = NULL; | 4465 transaction.handler = NULL; |
4431 transaction.response_headers = "Content-Range: bytes 40-49/45\n" | 4466 transaction.response_headers = "Content-Range: bytes 40-49/45\n" |
4432 "Content-Length: 10\n"; | 4467 "Content-Length: 10\n"; |
4433 AddMockTransaction(&transaction); | 4468 AddMockTransaction(&transaction); |
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6409 base::MessageLoop::current()->RunUntilIdle(); | 6444 base::MessageLoop::current()->RunUntilIdle(); |
6410 | 6445 |
6411 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. | 6446 // 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; | 6447 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 "; | 6448 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
6414 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); | 6449 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); |
6415 EXPECT_EQ(range_response_size * 2, received_bytes); | 6450 EXPECT_EQ(range_response_size * 2, received_bytes); |
6416 | 6451 |
6417 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6452 RemoveMockTransaction(&kRangeGET_TransactionOK); |
6418 } | 6453 } |
OLD | NEW |