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 ASSERT_EQ(net::OK, cache.http_cache()->CreateTransaction( |
| 5578 net::IDLE, &trans, NULL)); |
| 5579 |
| 5580 // Shouldn't crash, but doesn't do anything either. |
| 5581 trans->SetPriority(net::LOW); |
| 5582 |
| 5583 ASSERT_FALSE(cache.network_layer()->last_transaction()); |
| 5584 |
| 5585 net::HttpRequestInfo info; |
| 5586 info.url = GURL(kSimpleGET_Transaction.url); |
| 5587 net::TestCompletionCallback callback; |
| 5588 EXPECT_EQ(net::ERR_IO_PENDING, |
| 5589 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
| 5590 |
| 5591 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
| 5592 EXPECT_EQ(net::LOW, |
| 5593 cache.network_layer()->last_transaction()->priority()); |
| 5594 |
| 5595 trans->SetPriority(net::HIGHEST); |
| 5596 EXPECT_EQ(net::HIGHEST, |
| 5597 cache.network_layer()->last_transaction()->priority()); |
| 5598 |
| 5599 EXPECT_EQ(net::OK, callback.WaitForResult()); |
| 5600 } |
| 5601 |
| 5602 // Make sure that a cache transaction passes on its priority to |
| 5603 // newly-created network transactions. |
| 5604 TEST(HttpCache, SetPriorityNewTransaction) { |
| 5605 MockHttpCache cache; |
| 5606 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5607 |
| 5608 std::string raw_headers("HTTP/1.1 200 OK\n" |
| 5609 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5610 "ETag: \"foo\"\n" |
| 5611 "Accept-Ranges: bytes\n" |
| 5612 "Content-Length: 80\n"); |
| 5613 CreateTruncatedEntry(raw_headers, &cache); |
| 5614 |
| 5615 // Now make a regular request. |
| 5616 std::string headers; |
| 5617 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5618 transaction.request_headers = EXTRA_HEADER; |
| 5619 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 5620 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
| 5621 |
| 5622 scoped_ptr<net::HttpTransaction> trans; |
| 5623 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction( |
| 5624 net::MEDIUM, &trans, NULL)); |
| 5625 ASSERT_TRUE(trans.get()); |
| 5626 |
| 5627 MockHttpRequest info(transaction); |
| 5628 net::TestCompletionCallback callback; |
| 5629 EXPECT_EQ(net::ERR_IO_PENDING, |
| 5630 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
| 5631 ASSERT_FALSE(cache.network_layer()->last_transaction()); |
| 5632 EXPECT_EQ(net::OK, callback.WaitForResult()); |
| 5633 |
| 5634 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
| 5635 EXPECT_EQ(net::MEDIUM, |
| 5636 cache.network_layer()->last_transaction()->priority()); |
| 5637 |
| 5638 trans->SetPriority(net::HIGHEST); |
| 5639 cache.network_layer()->ClearLastTransaction(); |
| 5640 // Should trigger a new network transaction and pick up the new |
| 5641 // priority. |
| 5642 ReadAndVerifyTransaction(trans.get(), transaction); |
| 5643 |
| 5644 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
| 5645 EXPECT_EQ(net::HIGHEST, |
| 5646 cache.network_layer()->last_transaction()->priority()); |
| 5647 |
| 5648 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5649 } |
OLD | NEW |