| 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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 response.response_time = base::Time::Now(); | 536 response.response_time = base::Time::Now(); |
| 537 response.request_time = base::Time::Now(); | 537 response.request_time = base::Time::Now(); |
| 538 response.headers = new net::HttpResponseHeaders(raw_headers); | 538 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 539 // Set the last argument for this to be an incomplete request. | 539 // Set the last argument for this to be an incomplete request. |
| 540 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); | 540 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); |
| 541 | 541 |
| 542 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); | 542 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); |
| 543 int len = static_cast<int>(base::strlcpy(buf->data(), | 543 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 544 "rg: 00-09 rg: 10-19 ", 100)); | 544 "rg: 00-09 rg: 10-19 ", 100)); |
| 545 net::TestCompletionCallback cb; | 545 net::TestCompletionCallback cb; |
| 546 int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true); | 546 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
| 547 EXPECT_EQ(len, cb.GetResult(rv)); | 547 EXPECT_EQ(len, cb.GetResult(rv)); |
| 548 entry->Close(); | 548 entry->Close(); |
| 549 } | 549 } |
| 550 | 550 |
| 551 // Helper to represent a network HTTP response. | 551 // Helper to represent a network HTTP response. |
| 552 struct Response { | 552 struct Response { |
| 553 // Set this response into |trans|. | 553 // Set this response into |trans|. |
| 554 void AssignTo(MockTransaction* trans) const { | 554 void AssignTo(MockTransaction* trans) const { |
| 555 trans->status = status; | 555 trans->status = status; |
| 556 trans->response_headers = headers; | 556 trans->response_headers = headers; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 675 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 676 | 676 |
| 677 MockHttpRequest request(kSimpleGET_Transaction); | 677 MockHttpRequest request(kSimpleGET_Transaction); |
| 678 scoped_ptr<net::HttpTransaction> trans; | 678 scoped_ptr<net::HttpTransaction> trans; |
| 679 int rv = cache.http_cache()->CreateTransaction( | 679 int rv = cache.http_cache()->CreateTransaction( |
| 680 net::DEFAULT_PRIORITY, &trans, NULL); | 680 net::DEFAULT_PRIORITY, &trans, NULL); |
| 681 ASSERT_EQ(net::OK, rv); | 681 ASSERT_EQ(net::OK, rv); |
| 682 | 682 |
| 683 const int kBufferSize = 10; | 683 const int kBufferSize = 10; |
| 684 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); | 684 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); |
| 685 net::ReleaseBufferCompletionCallback cb(buffer); | 685 net::ReleaseBufferCompletionCallback cb(buffer.get()); |
| 686 | 686 |
| 687 rv = trans->Start(&request, cb.callback(), net::BoundNetLog()); | 687 rv = trans->Start(&request, cb.callback(), net::BoundNetLog()); |
| 688 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 688 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 689 | 689 |
| 690 rv = trans->Read(buffer, kBufferSize, cb.callback()); | 690 rv = trans->Read(buffer.get(), kBufferSize, cb.callback()); |
| 691 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); | 691 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); |
| 692 } | 692 } |
| 693 | 693 |
| 694 TEST(HttpCache, SimpleGETWithDiskFailures) { | 694 TEST(HttpCache, SimpleGETWithDiskFailures) { |
| 695 MockHttpCache cache; | 695 MockHttpCache cache; |
| 696 | 696 |
| 697 cache.disk_cache()->set_soft_failures(true); | 697 cache.disk_cache()->set_soft_failures(true); |
| 698 | 698 |
| 699 // Read from the network, and fail to write to the cache. | 699 // Read from the network, and fail to write to the cache. |
| 700 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 700 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 scoped_ptr<net::HttpTransaction> trans; | 1741 scoped_ptr<net::HttpTransaction> trans; |
| 1742 int rv = cache.http_cache()->CreateTransaction( | 1742 int rv = cache.http_cache()->CreateTransaction( |
| 1743 net::DEFAULT_PRIORITY, &trans, NULL); | 1743 net::DEFAULT_PRIORITY, &trans, NULL); |
| 1744 EXPECT_EQ(net::OK, rv); | 1744 EXPECT_EQ(net::OK, rv); |
| 1745 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 1745 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
| 1746 if (rv == net::ERR_IO_PENDING) | 1746 if (rv == net::ERR_IO_PENDING) |
| 1747 rv = callback.WaitForResult(); | 1747 rv = callback.WaitForResult(); |
| 1748 ASSERT_EQ(net::OK, rv); | 1748 ASSERT_EQ(net::OK, rv); |
| 1749 | 1749 |
| 1750 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 1750 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 1751 rv = trans->Read(buf, 256, callback.callback()); | 1751 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 1752 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1752 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 1753 | 1753 |
| 1754 // Test that destroying the transaction while it is reading from the cache | 1754 // Test that destroying the transaction while it is reading from the cache |
| 1755 // works properly. | 1755 // works properly. |
| 1756 trans.reset(); | 1756 trans.reset(); |
| 1757 | 1757 |
| 1758 // Make sure we pump any pending events, which should include a call to | 1758 // Make sure we pump any pending events, which should include a call to |
| 1759 // HttpCache::Transaction::OnCacheReadCompleted. | 1759 // HttpCache::Transaction::OnCacheReadCompleted. |
| 1760 base::MessageLoop::current()->RunUntilIdle(); | 1760 base::MessageLoop::current()->RunUntilIdle(); |
| 1761 } | 1761 } |
| (...skipping 2117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3879 raw_headers.size()); | 3879 raw_headers.size()); |
| 3880 | 3880 |
| 3881 net::HttpResponseInfo response; | 3881 net::HttpResponseInfo response; |
| 3882 response.headers = new net::HttpResponseHeaders(raw_headers); | 3882 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 3883 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 3883 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
| 3884 | 3884 |
| 3885 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 3885 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
| 3886 int len = static_cast<int>(base::strlcpy(buf->data(), | 3886 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 3887 kRangeGET_TransactionOK.data, 500)); | 3887 kRangeGET_TransactionOK.data, 500)); |
| 3888 net::TestCompletionCallback cb; | 3888 net::TestCompletionCallback cb; |
| 3889 int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true); | 3889 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
| 3890 EXPECT_EQ(len, cb.GetResult(rv)); | 3890 EXPECT_EQ(len, cb.GetResult(rv)); |
| 3891 entry->Close(); | 3891 entry->Close(); |
| 3892 | 3892 |
| 3893 // Now see that we don't use the stored entry. | 3893 // Now see that we don't use the stored entry. |
| 3894 std::string headers; | 3894 std::string headers; |
| 3895 net::CapturingBoundNetLog log; | 3895 net::CapturingBoundNetLog log; |
| 3896 net::LoadTimingInfo load_timing_info; | 3896 net::LoadTimingInfo load_timing_info; |
| 3897 RunTransactionTestWithResponseAndGetTiming( | 3897 RunTransactionTestWithResponseAndGetTiming( |
| 3898 cache.http_cache(), kSimpleGET_Transaction, &headers, log.bound(), | 3898 cache.http_cache(), kSimpleGET_Transaction, &headers, log.bound(), |
| 3899 &load_timing_info); | 3899 &load_timing_info); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3927 raw_headers.size()); | 3927 raw_headers.size()); |
| 3928 | 3928 |
| 3929 net::HttpResponseInfo response; | 3929 net::HttpResponseInfo response; |
| 3930 response.headers = new net::HttpResponseHeaders(raw_headers); | 3930 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 3931 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 3931 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
| 3932 | 3932 |
| 3933 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 3933 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
| 3934 int len = static_cast<int>(base::strlcpy(buf->data(), | 3934 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 3935 kRangeGET_TransactionOK.data, 500)); | 3935 kRangeGET_TransactionOK.data, 500)); |
| 3936 net::TestCompletionCallback cb; | 3936 net::TestCompletionCallback cb; |
| 3937 int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true); | 3937 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
| 3938 EXPECT_EQ(len, cb.GetResult(rv)); | 3938 EXPECT_EQ(len, cb.GetResult(rv)); |
| 3939 entry->Close(); | 3939 entry->Close(); |
| 3940 | 3940 |
| 3941 // Now see that we don't use the stored entry. | 3941 // Now see that we don't use the stored entry. |
| 3942 std::string headers; | 3942 std::string headers; |
| 3943 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3943 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3944 &headers); | 3944 &headers); |
| 3945 | 3945 |
| 3946 // We are expecting a 206. | 3946 // We are expecting a 206. |
| 3947 Verify206Response(headers, 40, 49); | 3947 Verify206Response(headers, 40, 49); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3969 raw_headers.size()); | 3969 raw_headers.size()); |
| 3970 | 3970 |
| 3971 net::HttpResponseInfo response; | 3971 net::HttpResponseInfo response; |
| 3972 response.headers = new net::HttpResponseHeaders(raw_headers); | 3972 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 3973 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 3973 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
| 3974 | 3974 |
| 3975 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 3975 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
| 3976 int len = static_cast<int>(base::strlcpy(buf->data(), | 3976 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 3977 kRangeGET_TransactionOK.data, 500)); | 3977 kRangeGET_TransactionOK.data, 500)); |
| 3978 net::TestCompletionCallback cb; | 3978 net::TestCompletionCallback cb; |
| 3979 int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true); | 3979 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
| 3980 EXPECT_EQ(len, cb.GetResult(rv)); | 3980 EXPECT_EQ(len, cb.GetResult(rv)); |
| 3981 entry->Close(); | 3981 entry->Close(); |
| 3982 | 3982 |
| 3983 // Now see that we don't use the stored entry. | 3983 // Now see that we don't use the stored entry. |
| 3984 std::string headers; | 3984 std::string headers; |
| 3985 RunTransactionTestWithResponse(cache.http_cache(), kSimpleGET_Transaction, | 3985 RunTransactionTestWithResponse(cache.http_cache(), kSimpleGET_Transaction, |
| 3986 &headers); | 3986 &headers); |
| 3987 | 3987 |
| 3988 // We are expecting a 200. | 3988 // We are expecting a 200. |
| 3989 std::string expected_headers(kSimpleGET_Transaction.status); | 3989 std::string expected_headers(kSimpleGET_Transaction.status); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4153 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4153 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 4154 if (rv == net::ERR_IO_PENDING) | 4154 if (rv == net::ERR_IO_PENDING) |
| 4155 rv = c->callback.WaitForResult(); | 4155 rv = c->callback.WaitForResult(); |
| 4156 | 4156 |
| 4157 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4157 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4158 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4158 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4159 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4159 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4160 | 4160 |
| 4161 // Make sure that the entry has some data stored. | 4161 // Make sure that the entry has some data stored. |
| 4162 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); | 4162 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); |
| 4163 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4163 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4164 if (rv == net::ERR_IO_PENDING) | 4164 if (rv == net::ERR_IO_PENDING) |
| 4165 rv = c->callback.WaitForResult(); | 4165 rv = c->callback.WaitForResult(); |
| 4166 EXPECT_EQ(buf->size(), rv); | 4166 EXPECT_EQ(buf->size(), rv); |
| 4167 | 4167 |
| 4168 // Destroy the transaction. | 4168 // Destroy the transaction. |
| 4169 delete c; | 4169 delete c; |
| 4170 | 4170 |
| 4171 // Verify that the entry has not been deleted. | 4171 // Verify that the entry has not been deleted. |
| 4172 disk_cache::Entry* entry; | 4172 disk_cache::Entry* entry; |
| 4173 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 4173 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4194 if (rv == net::ERR_IO_PENDING) | 4194 if (rv == net::ERR_IO_PENDING) |
| 4195 rv = c->callback.WaitForResult(); | 4195 rv = c->callback.WaitForResult(); |
| 4196 | 4196 |
| 4197 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4197 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4198 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4198 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4199 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4199 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4200 | 4200 |
| 4201 // Make sure that we revalidate the entry and read from the cache (a single | 4201 // Make sure that we revalidate the entry and read from the cache (a single |
| 4202 // read will return while waiting for the network). | 4202 // read will return while waiting for the network). |
| 4203 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); | 4203 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); |
| 4204 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4204 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4205 EXPECT_EQ(5, c->callback.GetResult(rv)); | 4205 EXPECT_EQ(5, c->callback.GetResult(rv)); |
| 4206 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4206 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4207 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 4207 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 4208 | 4208 |
| 4209 // Destroy the transaction before completing the read. | 4209 // Destroy the transaction before completing the read. |
| 4210 delete c; | 4210 delete c; |
| 4211 | 4211 |
| 4212 // We have the read and the delete (OnProcessPendingQueue) waiting on the | 4212 // We have the read and the delete (OnProcessPendingQueue) waiting on the |
| 4213 // message loop. This means that a new transaction will just reuse the same | 4213 // message loop. This means that a new transaction will just reuse the same |
| 4214 // active entry (no open or create). | 4214 // active entry (no open or create). |
| 4215 | 4215 |
| 4216 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 4216 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4240 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 4240 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 4241 rv = c->callback.WaitForResult(); | 4241 rv = c->callback.WaitForResult(); |
| 4242 | 4242 |
| 4243 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4243 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4244 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4244 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4245 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4245 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4246 | 4246 |
| 4247 // Make sure that we revalidate the entry and read from the cache (a single | 4247 // Make sure that we revalidate the entry and read from the cache (a single |
| 4248 // read will return while waiting for the network). | 4248 // read will return while waiting for the network). |
| 4249 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); | 4249 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); |
| 4250 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4250 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4251 EXPECT_EQ(5, c->callback.GetResult(rv)); | 4251 EXPECT_EQ(5, c->callback.GetResult(rv)); |
| 4252 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4252 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4253 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 4253 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 4254 | 4254 |
| 4255 // Destroy the transaction before completing the read. | 4255 // Destroy the transaction before completing the read. |
| 4256 delete c; | 4256 delete c; |
| 4257 | 4257 |
| 4258 // We have the read and the delete (OnProcessPendingQueue) waiting on the | 4258 // We have the read and the delete (OnProcessPendingQueue) waiting on the |
| 4259 // message loop. This means that a new transaction will just reuse the same | 4259 // message loop. This means that a new transaction will just reuse the same |
| 4260 // active entry (no open or create). | 4260 // active entry (no open or create). |
| 4261 | 4261 |
| 4262 c = new Context(); | 4262 c = new Context(); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4659 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4659 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 4660 if (rv == net::ERR_IO_PENDING) | 4660 if (rv == net::ERR_IO_PENDING) |
| 4661 rv = c->callback.WaitForResult(); | 4661 rv = c->callback.WaitForResult(); |
| 4662 | 4662 |
| 4663 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4663 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4664 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4664 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4665 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4665 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4666 | 4666 |
| 4667 // Make sure that the entry has some data stored. | 4667 // Make sure that the entry has some data stored. |
| 4668 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); | 4668 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); |
| 4669 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4669 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4670 if (rv == net::ERR_IO_PENDING) | 4670 if (rv == net::ERR_IO_PENDING) |
| 4671 rv = c->callback.WaitForResult(); | 4671 rv = c->callback.WaitForResult(); |
| 4672 EXPECT_EQ(buf->size(), rv); | 4672 EXPECT_EQ(buf->size(), rv); |
| 4673 | 4673 |
| 4674 // Destroy the transaction. | 4674 // Destroy the transaction. |
| 4675 delete c; | 4675 delete c; |
| 4676 | 4676 |
| 4677 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 4677 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 4678 | 4678 |
| 4679 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4679 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4703 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4703 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 4704 if (rv == net::ERR_IO_PENDING) | 4704 if (rv == net::ERR_IO_PENDING) |
| 4705 rv = c->callback.WaitForResult(); | 4705 rv = c->callback.WaitForResult(); |
| 4706 | 4706 |
| 4707 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4707 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4708 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4708 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4709 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4709 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4710 | 4710 |
| 4711 // Make sure that the entry has some data stored. | 4711 // Make sure that the entry has some data stored. |
| 4712 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); | 4712 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); |
| 4713 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4713 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4714 if (rv == net::ERR_IO_PENDING) | 4714 if (rv == net::ERR_IO_PENDING) |
| 4715 rv = c->callback.WaitForResult(); | 4715 rv = c->callback.WaitForResult(); |
| 4716 EXPECT_EQ(buf->size(), rv); | 4716 EXPECT_EQ(buf->size(), rv); |
| 4717 | 4717 |
| 4718 // Destroy the transaction. | 4718 // Destroy the transaction. |
| 4719 delete c; | 4719 delete c; |
| 4720 | 4720 |
| 4721 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 4721 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 4722 | 4722 |
| 4723 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4723 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4753 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4753 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 4754 if (rv == net::ERR_IO_PENDING) | 4754 if (rv == net::ERR_IO_PENDING) |
| 4755 rv = c->callback.WaitForResult(); | 4755 rv = c->callback.WaitForResult(); |
| 4756 | 4756 |
| 4757 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4757 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4758 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4758 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4759 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4759 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4760 | 4760 |
| 4761 // Make sure that the entry has some data stored. | 4761 // Make sure that the entry has some data stored. |
| 4762 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); | 4762 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10)); |
| 4763 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4763 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4764 if (rv == net::ERR_IO_PENDING) | 4764 if (rv == net::ERR_IO_PENDING) |
| 4765 rv = c->callback.WaitForResult(); | 4765 rv = c->callback.WaitForResult(); |
| 4766 EXPECT_EQ(buf->size(), rv); | 4766 EXPECT_EQ(buf->size(), rv); |
| 4767 | 4767 |
| 4768 // We want to cancel the request when the transaction is busy. | 4768 // We want to cancel the request when the transaction is busy. |
| 4769 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4769 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4770 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 4770 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 4771 EXPECT_FALSE(c->callback.have_result()); | 4771 EXPECT_FALSE(c->callback.have_result()); |
| 4772 | 4772 |
| 4773 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL); | 4773 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL); |
| 4774 int num_delegate_callbacks_before_destruction = | 4774 int num_delegate_callbacks_before_destruction = |
| 4775 delegate->num_callbacks_observed(); | 4775 delegate->num_callbacks_observed(); |
| 4776 | 4776 |
| 4777 // Destroy the transaction. | 4777 // Destroy the transaction. |
| 4778 c->trans.reset(); | 4778 c->trans.reset(); |
| 4779 MockHttpCache::SetTestMode(0); | 4779 MockHttpCache::SetTestMode(0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4820 scoped_ptr<Context> c(new Context()); | 4820 scoped_ptr<Context> c(new Context()); |
| 4821 int rv = cache.http_cache()->CreateTransaction( | 4821 int rv = cache.http_cache()->CreateTransaction( |
| 4822 net::DEFAULT_PRIORITY, &c->trans, NULL); | 4822 net::DEFAULT_PRIORITY, &c->trans, NULL); |
| 4823 EXPECT_EQ(net::OK, rv); | 4823 EXPECT_EQ(net::OK, rv); |
| 4824 | 4824 |
| 4825 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4825 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 4826 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 4826 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
| 4827 | 4827 |
| 4828 // Read everything. | 4828 // Read everything. |
| 4829 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22)); | 4829 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22)); |
| 4830 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4830 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4831 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); | 4831 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); |
| 4832 | 4832 |
| 4833 // Destroy the transaction. | 4833 // Destroy the transaction. |
| 4834 c->trans.reset(); | 4834 c->trans.reset(); |
| 4835 | 4835 |
| 4836 // Verify that the entry is not marked as truncated. | 4836 // Verify that the entry is not marked as truncated. |
| 4837 disk_cache::Entry* entry; | 4837 disk_cache::Entry* entry; |
| 4838 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 4838 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
| 4839 net::HttpResponseInfo response; | 4839 net::HttpResponseInfo response; |
| 4840 bool truncated = true; | 4840 bool truncated = true; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4977 net::DEFAULT_PRIORITY, &pending->trans, NULL)); | 4977 net::DEFAULT_PRIORITY, &pending->trans, NULL)); |
| 4978 | 4978 |
| 4979 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 4979 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 4980 EXPECT_EQ(net::ERR_IO_PENDING, | 4980 EXPECT_EQ(net::ERR_IO_PENDING, |
| 4981 pending->trans->Start(&request, pending->callback.callback(), | 4981 pending->trans->Start(&request, pending->callback.callback(), |
| 4982 net::BoundNetLog())); | 4982 net::BoundNetLog())); |
| 4983 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 4983 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
| 4984 | 4984 |
| 4985 // Make sure that the entry has some data stored. | 4985 // Make sure that the entry has some data stored. |
| 4986 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); | 4986 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); |
| 4987 rv = c->trans->Read(buf, buf->size(), c->callback.callback()); | 4987 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
| 4988 EXPECT_EQ(5, c->callback.GetResult(rv)); | 4988 EXPECT_EQ(5, c->callback.GetResult(rv)); |
| 4989 | 4989 |
| 4990 // Cancel the requests. | 4990 // Cancel the requests. |
| 4991 delete c; | 4991 delete c; |
| 4992 delete pending; | 4992 delete pending; |
| 4993 | 4993 |
| 4994 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4994 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4995 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4995 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4996 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4996 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4997 | 4997 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5133 Context* c = new Context(); | 5133 Context* c = new Context(); |
| 5134 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction( | 5134 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction( |
| 5135 net::DEFAULT_PRIORITY, &c->trans, NULL)); | 5135 net::DEFAULT_PRIORITY, &c->trans, NULL)); |
| 5136 | 5136 |
| 5137 int rv = c->trans->Start( | 5137 int rv = c->trans->Start( |
| 5138 &request, c->callback.callback(), net::BoundNetLog()); | 5138 &request, c->callback.callback(), net::BoundNetLog()); |
| 5139 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5139 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
| 5140 | 5140 |
| 5141 // Read 20 bytes from the cache, and 10 from the net. | 5141 // Read 20 bytes from the cache, and 10 from the net. |
| 5142 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); | 5142 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); |
| 5143 rv = c->trans->Read(buf, 20, c->callback.callback()); | 5143 rv = c->trans->Read(buf.get(), 20, c->callback.callback()); |
| 5144 EXPECT_EQ(20, c->callback.GetResult(rv)); | 5144 EXPECT_EQ(20, c->callback.GetResult(rv)); |
| 5145 rv = c->trans->Read(buf, 10, c->callback.callback()); | 5145 rv = c->trans->Read(buf.get(), 10, c->callback.callback()); |
| 5146 EXPECT_EQ(10, c->callback.GetResult(rv)); | 5146 EXPECT_EQ(10, c->callback.GetResult(rv)); |
| 5147 | 5147 |
| 5148 // At this point, we are already reading so canceling the request should leave | 5148 // At this point, we are already reading so canceling the request should leave |
| 5149 // a truncated one. | 5149 // a truncated one. |
| 5150 delete c; | 5150 delete c; |
| 5151 | 5151 |
| 5152 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5152 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 5153 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5153 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5154 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5154 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5155 | 5155 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5546 // Trivial call. | 5546 // Trivial call. |
| 5547 cache.http_cache()->WriteMetadata(GURL("foo"), net::DEFAULT_PRIORITY, | 5547 cache.http_cache()->WriteMetadata(GURL("foo"), net::DEFAULT_PRIORITY, |
| 5548 Time::Now(), NULL, 0); | 5548 Time::Now(), NULL, 0); |
| 5549 | 5549 |
| 5550 // Write meta data to the same entry. | 5550 // Write meta data to the same entry. |
| 5551 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 5551 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
| 5552 memset(buf->data(), 0, buf->size()); | 5552 memset(buf->data(), 0, buf->size()); |
| 5553 base::strlcpy(buf->data(), "Hi there", buf->size()); | 5553 base::strlcpy(buf->data(), "Hi there", buf->size()); |
| 5554 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), | 5554 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
| 5555 net::DEFAULT_PRIORITY, | 5555 net::DEFAULT_PRIORITY, |
| 5556 response.response_time, buf, buf->size()); | 5556 response.response_time, |
| 5557 buf.get(), |
| 5558 buf->size()); |
| 5557 | 5559 |
| 5558 // Release the buffer before the operation takes place. | 5560 // Release the buffer before the operation takes place. |
| 5559 buf = NULL; | 5561 buf = NULL; |
| 5560 | 5562 |
| 5561 // Makes sure we finish pending operations. | 5563 // Makes sure we finish pending operations. |
| 5562 base::MessageLoop::current()->RunUntilIdle(); | 5564 base::MessageLoop::current()->RunUntilIdle(); |
| 5563 | 5565 |
| 5564 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 5566 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
| 5565 &response); | 5567 &response); |
| 5566 ASSERT_TRUE(response.metadata.get() != NULL); | 5568 ASSERT_TRUE(response.metadata.get() != NULL); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5583 EXPECT_TRUE(response.metadata.get() == NULL); | 5585 EXPECT_TRUE(response.metadata.get() == NULL); |
| 5584 | 5586 |
| 5585 // Attempt to write meta data to the same entry. | 5587 // Attempt to write meta data to the same entry. |
| 5586 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 5588 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
| 5587 memset(buf->data(), 0, buf->size()); | 5589 memset(buf->data(), 0, buf->size()); |
| 5588 base::strlcpy(buf->data(), "Hi there", buf->size()); | 5590 base::strlcpy(buf->data(), "Hi there", buf->size()); |
| 5589 base::Time expected_time = response.response_time - | 5591 base::Time expected_time = response.response_time - |
| 5590 base::TimeDelta::FromMilliseconds(20); | 5592 base::TimeDelta::FromMilliseconds(20); |
| 5591 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), | 5593 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
| 5592 net::DEFAULT_PRIORITY, | 5594 net::DEFAULT_PRIORITY, |
| 5593 expected_time, buf, buf->size()); | 5595 expected_time, |
| 5596 buf.get(), |
| 5597 buf->size()); |
| 5594 | 5598 |
| 5595 // Makes sure we finish pending operations. | 5599 // Makes sure we finish pending operations. |
| 5596 base::MessageLoop::current()->RunUntilIdle(); | 5600 base::MessageLoop::current()->RunUntilIdle(); |
| 5597 | 5601 |
| 5598 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 5602 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
| 5599 &response); | 5603 &response); |
| 5600 EXPECT_TRUE(response.metadata.get() == NULL); | 5604 EXPECT_TRUE(response.metadata.get() == NULL); |
| 5601 | 5605 |
| 5602 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5606 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5603 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 5607 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5614 RunTransactionTestWithResponseInfo(cache.http_cache(), | 5618 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 5615 kTypicalGET_Transaction, &response); | 5619 kTypicalGET_Transaction, &response); |
| 5616 EXPECT_TRUE(response.metadata.get() == NULL); | 5620 EXPECT_TRUE(response.metadata.get() == NULL); |
| 5617 | 5621 |
| 5618 // Write meta data to the same entry. | 5622 // Write meta data to the same entry. |
| 5619 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 5623 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
| 5620 memset(buf->data(), 0, buf->size()); | 5624 memset(buf->data(), 0, buf->size()); |
| 5621 base::strlcpy(buf->data(), "Hi there", buf->size()); | 5625 base::strlcpy(buf->data(), "Hi there", buf->size()); |
| 5622 cache.http_cache()->WriteMetadata(GURL(kTypicalGET_Transaction.url), | 5626 cache.http_cache()->WriteMetadata(GURL(kTypicalGET_Transaction.url), |
| 5623 net::DEFAULT_PRIORITY, | 5627 net::DEFAULT_PRIORITY, |
| 5624 response.response_time, buf, buf->size()); | 5628 response.response_time, |
| 5629 buf.get(), |
| 5630 buf->size()); |
| 5625 | 5631 |
| 5626 // Makes sure we finish pending operations. | 5632 // Makes sure we finish pending operations. |
| 5627 base::MessageLoop::current()->RunUntilIdle(); | 5633 base::MessageLoop::current()->RunUntilIdle(); |
| 5628 | 5634 |
| 5629 // Start with a READ mode transaction. | 5635 // Start with a READ mode transaction. |
| 5630 MockTransaction trans1(kTypicalGET_Transaction); | 5636 MockTransaction trans1(kTypicalGET_Transaction); |
| 5631 trans1.load_flags = net::LOAD_ONLY_FROM_CACHE; | 5637 trans1.load_flags = net::LOAD_ONLY_FROM_CACHE; |
| 5632 | 5638 |
| 5633 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); | 5639 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); |
| 5634 ASSERT_TRUE(response.metadata.get() != NULL); | 5640 ASSERT_TRUE(response.metadata.get() != NULL); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5676 scoped_ptr<net::HttpTransaction> trans; | 5682 scoped_ptr<net::HttpTransaction> trans; |
| 5677 int rv = cache.http_cache()->CreateTransaction( | 5683 int rv = cache.http_cache()->CreateTransaction( |
| 5678 net::DEFAULT_PRIORITY, &trans, NULL); | 5684 net::DEFAULT_PRIORITY, &trans, NULL); |
| 5679 EXPECT_EQ(net::OK, rv); | 5685 EXPECT_EQ(net::OK, rv); |
| 5680 | 5686 |
| 5681 MockHttpRequest request(kSimpleGET_Transaction); | 5687 MockHttpRequest request(kSimpleGET_Transaction); |
| 5682 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 5688 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
| 5683 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 5689 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5684 | 5690 |
| 5685 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 5691 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 5686 rv = trans->Read(buf, 256, callback.callback()); | 5692 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5687 EXPECT_GT(callback.GetResult(rv), 0); | 5693 EXPECT_GT(callback.GetResult(rv), 0); |
| 5688 | 5694 |
| 5689 // Now make sure that the entry is preserved. | 5695 // Now make sure that the entry is preserved. |
| 5690 trans->DoneReading(); | 5696 trans->DoneReading(); |
| 5691 } | 5697 } |
| 5692 | 5698 |
| 5693 // Make sure that the ActiveEntry is gone. | 5699 // Make sure that the ActiveEntry is gone. |
| 5694 base::MessageLoop::current()->RunUntilIdle(); | 5700 base::MessageLoop::current()->RunUntilIdle(); |
| 5695 | 5701 |
| 5696 // Read from the cache. | 5702 // Read from the cache. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5710 { | 5716 { |
| 5711 scoped_ptr<net::HttpTransaction> trans; | 5717 scoped_ptr<net::HttpTransaction> trans; |
| 5712 int rv = cache.http_cache()->CreateTransaction( | 5718 int rv = cache.http_cache()->CreateTransaction( |
| 5713 net::DEFAULT_PRIORITY, &trans, NULL); | 5719 net::DEFAULT_PRIORITY, &trans, NULL); |
| 5714 EXPECT_EQ(net::OK, rv); | 5720 EXPECT_EQ(net::OK, rv); |
| 5715 | 5721 |
| 5716 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 5722 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
| 5717 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 5723 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5718 | 5724 |
| 5719 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 5725 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 5720 rv = trans->Read(buf, 10, callback.callback()); | 5726 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 5721 EXPECT_EQ(callback.GetResult(rv), 10); | 5727 EXPECT_EQ(callback.GetResult(rv), 10); |
| 5722 | 5728 |
| 5723 trans->StopCaching(); | 5729 trans->StopCaching(); |
| 5724 | 5730 |
| 5725 // We should be able to keep reading. | 5731 // We should be able to keep reading. |
| 5726 rv = trans->Read(buf, 256, callback.callback()); | 5732 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5727 EXPECT_GT(callback.GetResult(rv), 0); | 5733 EXPECT_GT(callback.GetResult(rv), 0); |
| 5728 rv = trans->Read(buf, 256, callback.callback()); | 5734 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5729 EXPECT_EQ(callback.GetResult(rv), 0); | 5735 EXPECT_EQ(callback.GetResult(rv), 0); |
| 5730 } | 5736 } |
| 5731 | 5737 |
| 5732 // Make sure that the ActiveEntry is gone. | 5738 // Make sure that the ActiveEntry is gone. |
| 5733 base::MessageLoop::current()->RunUntilIdle(); | 5739 base::MessageLoop::current()->RunUntilIdle(); |
| 5734 | 5740 |
| 5735 // Verify that the entry is gone. | 5741 // Verify that the entry is gone. |
| 5736 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 5742 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 5737 | 5743 |
| 5738 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5744 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5756 MockTransaction mock_transaction(kSimpleGET_Transaction); | 5762 MockTransaction mock_transaction(kSimpleGET_Transaction); |
| 5757 AddMockTransaction(&mock_transaction); | 5763 AddMockTransaction(&mock_transaction); |
| 5758 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" | 5764 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" |
| 5759 "Content-Length: 42\n" | 5765 "Content-Length: 42\n" |
| 5760 "Etag: \"foo\"\n"; | 5766 "Etag: \"foo\"\n"; |
| 5761 | 5767 |
| 5762 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 5768 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
| 5763 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 5769 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5764 | 5770 |
| 5765 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 5771 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 5766 rv = trans->Read(buf, 10, callback.callback()); | 5772 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 5767 EXPECT_EQ(callback.GetResult(rv), 10); | 5773 EXPECT_EQ(callback.GetResult(rv), 10); |
| 5768 | 5774 |
| 5769 trans->StopCaching(); | 5775 trans->StopCaching(); |
| 5770 | 5776 |
| 5771 // We should be able to keep reading. | 5777 // We should be able to keep reading. |
| 5772 rv = trans->Read(buf, 256, callback.callback()); | 5778 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5773 EXPECT_GT(callback.GetResult(rv), 0); | 5779 EXPECT_GT(callback.GetResult(rv), 0); |
| 5774 rv = trans->Read(buf, 256, callback.callback()); | 5780 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5775 EXPECT_EQ(callback.GetResult(rv), 0); | 5781 EXPECT_EQ(callback.GetResult(rv), 0); |
| 5776 | 5782 |
| 5777 RemoveMockTransaction(&mock_transaction); | 5783 RemoveMockTransaction(&mock_transaction); |
| 5778 } | 5784 } |
| 5779 | 5785 |
| 5780 // Verify that the entry is marked as incomplete. | 5786 // Verify that the entry is marked as incomplete. |
| 5781 disk_cache::Entry* entry; | 5787 disk_cache::Entry* entry; |
| 5782 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 5788 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
| 5783 net::HttpResponseInfo response; | 5789 net::HttpResponseInfo response; |
| 5784 bool truncated = false; | 5790 bool truncated = false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5807 // Now make a regular request. | 5813 // Now make a regular request. |
| 5808 scoped_ptr<net::HttpTransaction> trans; | 5814 scoped_ptr<net::HttpTransaction> trans; |
| 5809 int rv = cache.http_cache()->CreateTransaction( | 5815 int rv = cache.http_cache()->CreateTransaction( |
| 5810 net::DEFAULT_PRIORITY, &trans, NULL); | 5816 net::DEFAULT_PRIORITY, &trans, NULL); |
| 5811 EXPECT_EQ(net::OK, rv); | 5817 EXPECT_EQ(net::OK, rv); |
| 5812 | 5818 |
| 5813 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 5819 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
| 5814 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 5820 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5815 | 5821 |
| 5816 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 5822 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 5817 rv = trans->Read(buf, 10, callback.callback()); | 5823 rv = trans->Read(buf.get(), 10, callback.callback()); |
| 5818 EXPECT_EQ(callback.GetResult(rv), 10); | 5824 EXPECT_EQ(callback.GetResult(rv), 10); |
| 5819 | 5825 |
| 5820 // This is actually going to do nothing. | 5826 // This is actually going to do nothing. |
| 5821 trans->StopCaching(); | 5827 trans->StopCaching(); |
| 5822 | 5828 |
| 5823 // We should be able to keep reading. | 5829 // We should be able to keep reading. |
| 5824 rv = trans->Read(buf, 256, callback.callback()); | 5830 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5825 EXPECT_GT(callback.GetResult(rv), 0); | 5831 EXPECT_GT(callback.GetResult(rv), 0); |
| 5826 rv = trans->Read(buf, 256, callback.callback()); | 5832 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5827 EXPECT_GT(callback.GetResult(rv), 0); | 5833 EXPECT_GT(callback.GetResult(rv), 0); |
| 5828 rv = trans->Read(buf, 256, callback.callback()); | 5834 rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5829 EXPECT_EQ(callback.GetResult(rv), 0); | 5835 EXPECT_EQ(callback.GetResult(rv), 0); |
| 5830 } | 5836 } |
| 5831 | 5837 |
| 5832 // Verify that the disk entry was updated. | 5838 // Verify that the disk entry was updated. |
| 5833 disk_cache::Entry* entry; | 5839 disk_cache::Entry* entry; |
| 5834 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 5840 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
| 5835 EXPECT_EQ(80, entry->GetDataSize(1)); | 5841 EXPECT_EQ(80, entry->GetDataSize(1)); |
| 5836 bool truncated = true; | 5842 bool truncated = true; |
| 5837 net::HttpResponseInfo response; | 5843 net::HttpResponseInfo response; |
| 5838 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 5844 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5983 trans->SetPriority(net::HIGHEST); | 5989 trans->SetPriority(net::HIGHEST); |
| 5984 // Should trigger a new network transaction and pick up the new | 5990 // Should trigger a new network transaction and pick up the new |
| 5985 // priority. | 5991 // priority. |
| 5986 ReadAndVerifyTransaction(trans.get(), transaction); | 5992 ReadAndVerifyTransaction(trans.get(), transaction); |
| 5987 | 5993 |
| 5988 EXPECT_EQ(net::HIGHEST, | 5994 EXPECT_EQ(net::HIGHEST, |
| 5989 cache.network_layer()->last_create_transaction_priority()); | 5995 cache.network_layer()->last_create_transaction_priority()); |
| 5990 | 5996 |
| 5991 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5997 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5992 } | 5998 } |
| OLD | NEW |