OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 5549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5560 | 5560 |
5561 // Force this transaction to read from the cache. | 5561 // Force this transaction to read from the cache. |
5562 MockTransaction transaction(kSimpleGET_Transaction); | 5562 MockTransaction transaction(kSimpleGET_Transaction); |
5563 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 5563 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
5564 | 5564 |
5565 RunTransactionTestWithDelegate(cache.http_cache(), | 5565 RunTransactionTestWithDelegate(cache.http_cache(), |
5566 kSimpleGET_Transaction, | 5566 kSimpleGET_Transaction, |
5567 5, | 5567 5, |
5568 0); | 5568 0); |
5569 } | 5569 } |
| 5570 |
| 5571 // Make sure that calling SetPriority on a cache transaction passes on |
| 5572 // its priority updates to its underlying network transaction. |
| 5573 TEST(HttpCache, SetPriority) { |
| 5574 MockHttpCache cache; |
| 5575 |
| 5576 scoped_ptr<net::HttpTransaction> trans; |
| 5577 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction( |
| 5578 net::IDLE, &trans, NULL)); |
| 5579 ASSERT_TRUE(trans.get()); |
| 5580 |
| 5581 // Shouldn't crash, but doesn't do anything either. |
| 5582 trans->SetPriority(net::LOW); |
| 5583 |
| 5584 EXPECT_FALSE(cache.network_layer()->last_transaction()); |
| 5585 EXPECT_EQ(net::DEFAULT_PRIORITY, |
| 5586 cache.network_layer()->last_create_transaction_priority()); |
| 5587 |
| 5588 net::HttpRequestInfo info; |
| 5589 info.url = GURL(kSimpleGET_Transaction.url); |
| 5590 net::TestCompletionCallback callback; |
| 5591 EXPECT_EQ(net::ERR_IO_PENDING, |
| 5592 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
| 5593 |
| 5594 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
| 5595 EXPECT_EQ(net::LOW, |
| 5596 cache.network_layer()->last_create_transaction_priority()); |
| 5597 EXPECT_EQ(net::LOW, |
| 5598 cache.network_layer()->last_transaction()->priority()); |
| 5599 |
| 5600 trans->SetPriority(net::HIGHEST); |
| 5601 EXPECT_EQ(net::LOW, |
| 5602 cache.network_layer()->last_create_transaction_priority()); |
| 5603 EXPECT_EQ(net::HIGHEST, |
| 5604 cache.network_layer()->last_transaction()->priority()); |
| 5605 |
| 5606 EXPECT_EQ(net::OK, callback.WaitForResult()); |
| 5607 } |
| 5608 |
| 5609 // Make sure that a cache transaction passes on its priority to |
| 5610 // newly-created network transactions. |
| 5611 TEST(HttpCache, SetPriorityNewTransaction) { |
| 5612 MockHttpCache cache; |
| 5613 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5614 |
| 5615 std::string raw_headers("HTTP/1.1 200 OK\n" |
| 5616 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5617 "ETag: \"foo\"\n" |
| 5618 "Accept-Ranges: bytes\n" |
| 5619 "Content-Length: 80\n"); |
| 5620 CreateTruncatedEntry(raw_headers, &cache); |
| 5621 |
| 5622 // Now make a regular request. |
| 5623 std::string headers; |
| 5624 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5625 transaction.request_headers = EXTRA_HEADER; |
| 5626 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 5627 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
| 5628 |
| 5629 scoped_ptr<net::HttpTransaction> trans; |
| 5630 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction( |
| 5631 net::MEDIUM, &trans, NULL)); |
| 5632 ASSERT_TRUE(trans.get()); |
| 5633 EXPECT_EQ(net::DEFAULT_PRIORITY, |
| 5634 cache.network_layer()->last_create_transaction_priority()); |
| 5635 |
| 5636 MockHttpRequest info(transaction); |
| 5637 net::TestCompletionCallback callback; |
| 5638 EXPECT_EQ(net::ERR_IO_PENDING, |
| 5639 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
| 5640 EXPECT_EQ(net::OK, callback.WaitForResult()); |
| 5641 |
| 5642 EXPECT_EQ(net::MEDIUM, |
| 5643 cache.network_layer()->last_create_transaction_priority()); |
| 5644 |
| 5645 trans->SetPriority(net::HIGHEST); |
| 5646 // Should trigger a new network transaction and pick up the new |
| 5647 // priority. |
| 5648 ReadAndVerifyTransaction(trans.get(), transaction); |
| 5649 |
| 5650 EXPECT_EQ(net::HIGHEST, |
| 5651 cache.network_layer()->last_create_transaction_priority()); |
| 5652 |
| 5653 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5654 } |
OLD | NEW |