Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Unified Diff: net/http/http_cache_unittest.cc

Issue 2519473002: Fixes the cache lock issue. (Closed)
Patch Set: Feedback addressed Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_response_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_unittest.cc
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 60c7ed7c8d75d286465b15c12b4806d86acc6b87..98e4c49921eab1dbad98d768d26f5aad58efd2ff 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -157,24 +157,22 @@ void RunTransactionTestBase(HttpCache* cache,
int64_t* sent_bytes,
int64_t* received_bytes,
IPEndPoint* remote_endpoint) {
- TestCompletionCallback callback;
-
// write to the cache
-
- std::unique_ptr<HttpTransaction> trans;
- int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans);
+ std::unique_ptr<Context> c;
+ c.reset(new Context());
+ int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
EXPECT_THAT(rv, IsOk());
- ASSERT_TRUE(trans.get());
+ ASSERT_TRUE(c->trans.get());
- rv = trans->Start(&request, callback.callback(), net_log);
+ rv = c->trans->Start(&request, c->callback.callback(), net_log);
if (rv == ERR_IO_PENDING)
- rv = callback.WaitForResult();
+ rv = c->callback.WaitForResult();
ASSERT_EQ(trans_info.return_code, rv);
if (OK != rv)
return;
- const HttpResponseInfo* response = trans->GetResponseInfo();
+ const HttpResponseInfo* response = c->trans->GetResponseInfo();
ASSERT_TRUE(response);
if (response_info)
@@ -185,18 +183,18 @@ void RunTransactionTestBase(HttpCache* cache,
// ID.
EXPECT_TRUE(net_log.net_log());
*load_timing_info = LoadTimingInfo();
- trans->GetLoadTimingInfo(load_timing_info);
+ c->trans->GetLoadTimingInfo(load_timing_info);
}
if (remote_endpoint)
- ASSERT_TRUE(trans->GetRemoteEndpoint(remote_endpoint));
+ ASSERT_TRUE(c->trans->GetRemoteEndpoint(remote_endpoint));
- ReadAndVerifyTransaction(trans.get(), trans_info);
+ ReadAndVerifyTransaction(c->trans.get(), trans_info);
if (sent_bytes)
- *sent_bytes = trans->GetTotalSentBytes();
+ *sent_bytes = c->trans->GetTotalSentBytes();
if (received_bytes)
- *received_bytes = trans->GetTotalReceivedBytes();
+ *received_bytes = c->trans->GetTotalReceivedBytes();
}
void RunTransactionTestWithRequest(HttpCache* cache,
@@ -572,14 +570,6 @@ struct Response {
const char* body;
};
-struct Context {
- Context() : result(ERR_IO_PENDING) {}
-
- int result;
- TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
-};
-
class FakeWebSocketHandshakeStreamCreateHelper
: public WebSocketHandshakeStreamBase::CreateHelper {
public:
@@ -641,9 +631,10 @@ bool LogContainsEventType(const BoundTestNetLog& log,
TEST(HttpCache, CreateThenDestroy) {
MockHttpCache cache;
- std::unique_ptr<HttpTransaction> trans;
- EXPECT_THAT(cache.CreateTransaction(&trans), IsOk());
- ASSERT_TRUE(trans.get());
+ Context* c = new Context();
+ EXPECT_THAT(cache.CreateTransaction(&c->trans), IsOk());
+ ASSERT_TRUE(c->trans.get());
+ delete c;
}
TEST(HttpCache, GetBackend) {
@@ -732,18 +723,20 @@ TEST(HttpCache, ReleaseBuffer) {
RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
MockHttpRequest request(kSimpleGET_Transaction);
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ Context* c = new Context();
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
const int kBufferSize = 10;
scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
ReleaseBufferCompletionCallback cb(buffer.get());
- int rv = trans->Start(&request, cb.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, cb.callback(), NetLogWithSource());
EXPECT_THAT(cb.GetResult(rv), IsOk());
- rv = trans->Read(buffer.get(), kBufferSize, cb.callback());
+ rv = c->trans->Read(buffer.get(), kBufferSize, cb.callback());
EXPECT_EQ(kBufferSize, cb.GetResult(rv));
+
+ delete c;
}
TEST(HttpCache, SimpleGETWithDiskFailures) {
@@ -920,18 +913,16 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
transaction.load_flags |= LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
MockHttpRequest request(transaction);
- TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv =
+ c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
if (rv == ERR_IO_PENDING)
- rv = callback.WaitForResult();
+ rv = c->callback.WaitForResult();
ASSERT_THAT(rv, IsError(ERR_CACHE_MISS));
- trans.reset();
-
EXPECT_EQ(0, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
EXPECT_EQ(0, cache.disk_cache()->create_count());
@@ -1038,20 +1029,21 @@ TEST(HttpCache, SimpleGET_CacheSignal_Failure) {
AddMockTransaction(&transaction);
MockHttpRequest request(transaction);
- TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
+ Context* c = new Context();
+ int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
EXPECT_THAT(rv, IsOk());
- ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, callback.callback(), NetLogWithSource());
- EXPECT_THAT(callback.GetResult(rv), IsError(ERR_FAILED));
+ ASSERT_TRUE(c->trans.get());
+ rv = c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
+ EXPECT_THAT(c->callback.GetResult(rv), IsError(ERR_FAILED));
- const HttpResponseInfo* response_info = trans->GetResponseInfo();
+ const HttpResponseInfo* response_info = c->trans->GetResponseInfo();
ASSERT_TRUE(response_info);
EXPECT_TRUE(response_info->was_cached);
EXPECT_EQ(2, cache.network_layer()->transaction_count());
RemoveMockTransaction(&transaction);
+
+ delete c;
}
// Confirm if we have an empty cache, a read is marked as network verified.
@@ -1342,8 +1334,9 @@ TEST(HttpCache, SimpleGET_ManyReaders) {
// Allow all requests to move from the Create queue to the active entry.
base::RunLoop().RunUntilIdle();
- // The first request should be a writer at this point, and the subsequent
- // requests should be pending.
+ // At the end of Start: [0] should be in shared_writers->all_writers_,
+ // [3] and [4] should also be in all_writers_ since its a case of validation
+ // match/skip, [1] and [2] should be in pending_queue.
EXPECT_EQ(1, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
@@ -1419,11 +1412,12 @@ TEST(HttpCache, SimpleGET_RacingReaders) {
c->result = c->callback.WaitForResult();
ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
- // Now we have 2 active readers and two queued transactions.
-
+ // after [0] completes reading and writing, [3] and [4] should be added to
+ // entry->readers from shared writers and pending queue should be
+ // processed to add [1] and [2] to readers as well. They are all waiting for
+ // their consumer to invoke Read.
EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState());
- EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE,
- context_list[3]->trans->GetLoadState());
+ EXPECT_EQ(LOAD_STATE_IDLE, context_list[3]->trans->GetLoadState());
c = context_list[1];
ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
@@ -1537,9 +1531,9 @@ TEST(HttpCache, FastNoStoreGET_DoneWithPending) {
// The first request should be a writer at this point, and the subsequent
// requests should be pending.
- EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(3, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
- EXPECT_EQ(1, cache.disk_cache()->create_count());
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
// Now, make sure that the second request asks for the entry not to be stored.
request_handler.set_no_store(true);
@@ -1582,7 +1576,8 @@ TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
base::RunLoop().RunUntilIdle();
// The first request should be a writer at this point, and the subsequent
- // requests should be pending.
+ // requests should have been added to SharedWriters, skipped validation and
+ // completed the start state machine of HttpCache::Transaction.
EXPECT_EQ(1, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
@@ -1605,11 +1600,11 @@ TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
}
- // We should have had to re-open the disk entry.
-
- EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ // 2nd transaction will reuse the network transaction as they are both part of
+ // SharedWriters. Similarly it will be part of the same entry.
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
- EXPECT_EQ(2, cache.disk_cache()->create_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
for (int i = 1; i < kNumTransactions; ++i) {
Context* c = context_list[i];
@@ -2960,15 +2955,13 @@ TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) {
MockHttpRequest request(transaction);
TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
- ASSERT_TRUE(trans.get());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
+ ASSERT_TRUE(c->trans.get());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS));
- trans.reset();
-
EXPECT_EQ(0, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
EXPECT_EQ(0, cache.disk_cache()->create_count());
@@ -3215,15 +3208,13 @@ TEST(HttpCache, SimpleHEAD_LoadOnlyFromCache_Miss) {
MockHttpRequest request(transaction);
TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
- ASSERT_TRUE(trans.get());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
+ ASSERT_TRUE(c->trans.get());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS));
- trans.reset();
-
EXPECT_EQ(0, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
EXPECT_EQ(0, cache.disk_cache()->create_count());
@@ -5610,17 +5601,17 @@ TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) {
MockHttpRequest request(transaction);
TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
+ std::unique_ptr<Context> c(new Context());
+ int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
EXPECT_THAT(rv, IsOk());
- ASSERT_TRUE(trans.get());
+ ASSERT_TRUE(c->trans.get());
- rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_THAT(rv, IsError(ERR_CACHE_MISS));
- trans.reset();
+ c.reset();
EXPECT_EQ(1, cache.network_layer()->transaction_count());
EXPECT_EQ(1, cache.disk_cache()->open_count());
@@ -5841,10 +5832,77 @@ TEST(HttpCache, SetTruncatedFlag) {
// notification from the transaction destructor (see http://crbug.com/31723).
EXPECT_FALSE(c->callback.have_result());
- // Verify that the entry is marked as incomplete.
VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, true, 0);
}
+// Tests that we mark an entry as incomplete when the request is cancelled,
+// but not if there are multiple transactions reading.
+TEST(HttpCache, SetTruncatedFlagShared) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction transaction(kSimpleGET_Transaction);
+ transaction.response_headers =
+ "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
+ "Content-Length: 22\n"
+ "Etag: \"foopy\"\n";
+ MockHttpRequest request(transaction);
+
+ std::vector<std::unique_ptr<Context>> contexts(2);
+
+ for (auto& c : contexts) {
+ c.reset(new Context());
+ }
+
+ for (auto& c : contexts) {
+ int rv = cache.CreateTransaction(&c->trans);
+ ASSERT_THAT(rv, IsOk());
+ }
+
+ for (auto& c : contexts) {
+ int rv =
+ c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
+ if (rv == ERR_IO_PENDING)
+ rv = c->callback.WaitForResult();
+ }
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Make sure that the entry has some data stored.
+ for (auto& c : contexts) {
+ scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10));
+ int rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
+ if (rv == ERR_IO_PENDING)
+ rv = c->callback.WaitForResult();
+ EXPECT_EQ(buf->size(), rv);
+ }
+
+ // We want to cancel the request when the transaction is busy.
+ scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10));
+ Context* c = contexts[0].get();
+ int rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+ EXPECT_FALSE(c->callback.have_result());
+
+ MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL);
+
+ // Destroy the transaction.
+ c->trans.reset();
+ MockHttpCache::SetTestMode(0);
+
+ // Make sure that we don't invoke the callback. We may have an issue if the
+ // UrlRequestJob is killed directly (without cancelling the UrlRequest) so we
+ // could end up with the transaction being deleted twice if we send any
+ // notification from the transaction destructor (see http://crbug.com/31723).
+ EXPECT_FALSE(c->callback.have_result());
+
+ // Verify that the entry is not marked as incomplete since SharedWriters
+ // enables response writing to complete even if transaction is destroyed
+ // mid-way.
+ VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, false, 0);
+}
+
// Tests that we don't mark an entry as truncated when we read everything.
TEST(HttpCache, DontSetTruncatedFlag) {
MockHttpCache cache;
@@ -5883,21 +5941,19 @@ TEST(HttpCache, RangeGET_DontTruncate) {
transaction.request_headers = "Range: bytes = 0-19\r\n" EXTRA_HEADER;
std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction));
- std::unique_ptr<HttpTransaction> trans;
+ std::unique_ptr<Context> c(new Context());
- int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
+ int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
EXPECT_THAT(rv, IsOk());
TestCompletionCallback cb;
- rv = trans->Start(request.get(), cb.callback(), NetLogWithSource());
+ rv = c->trans->Start(request.get(), cb.callback(), NetLogWithSource());
EXPECT_EQ(0, cb.GetResult(rv));
scoped_refptr<IOBuffer> buf(new IOBuffer(10));
- rv = trans->Read(buf.get(), 10, cb.callback());
+ rv = c->trans->Read(buf.get(), 10, cb.callback());
EXPECT_EQ(10, cb.GetResult(rv));
- // Should not trigger any DCHECK.
- trans.reset();
VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0);
}
@@ -5910,21 +5966,20 @@ TEST(HttpCache, RangeGET_DontTruncate2) {
transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER;
std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction));
- std::unique_ptr<HttpTransaction> trans;
+ std::unique_ptr<Context> c(new Context());
- int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
+ int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
EXPECT_THAT(rv, IsOk());
- TestCompletionCallback cb;
- rv = trans->Start(request.get(), cb.callback(), NetLogWithSource());
- EXPECT_EQ(0, cb.GetResult(rv));
+ rv = c->trans->Start(request.get(), c->callback.callback(),
+ NetLogWithSource());
+ EXPECT_EQ(0, c->callback.GetResult(rv));
scoped_refptr<IOBuffer> buf(new IOBuffer(10));
- rv = trans->Read(buf.get(), 10, cb.callback());
- EXPECT_EQ(10, cb.GetResult(rv));
+ rv = c->trans->Read(buf.get(), 10, c->callback.callback());
+ EXPECT_EQ(10, c->callback.GetResult(rv));
// Should not trigger any DCHECK.
- trans.reset();
VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0);
}
@@ -6388,15 +6443,15 @@ TEST(HttpCache, CachedRedirect) {
// Write to the cache.
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_THAT(rv, IsOk());
- const HttpResponseInfo* info = trans->GetResponseInfo();
+ const HttpResponseInfo* info = c->trans->GetResponseInfo();
ASSERT_TRUE(info);
EXPECT_EQ(info->headers->response_code(), 301);
@@ -6406,7 +6461,7 @@ TEST(HttpCache, CachedRedirect) {
EXPECT_EQ(location, "http://www.bar.com/");
// Mark the transaction as completed so it is cached.
- trans->DoneReading();
+ c->trans->DoneReading();
// Destroy transaction when going out of scope. We have not actually
// read the response body -- want to test that it is still getting cached.
@@ -6422,15 +6477,15 @@ TEST(HttpCache, CachedRedirect) {
// Read from the cache.
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_THAT(rv, IsOk());
- const HttpResponseInfo* info = trans->GetResponseInfo();
+ const HttpResponseInfo* info = c->trans->GetResponseInfo();
ASSERT_TRUE(info);
EXPECT_EQ(info->headers->response_code(), 301);
@@ -6440,7 +6495,7 @@ TEST(HttpCache, CachedRedirect) {
EXPECT_EQ(location, "http://www.bar.com/");
// Mark the transaction as completed so it is cached.
- trans->DoneReading();
+ c->trans->DoneReading();
// Destroy transaction when going out of scope. We have not actually
// read the response body -- want to test that it is still getting cached.
@@ -6601,14 +6656,14 @@ TEST(HttpCache, SimpleGET_SSLError) {
transaction.load_flags |= LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
MockHttpRequest request(transaction);
- TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv =
+ c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
if (rv == ERR_IO_PENDING)
- rv = callback.WaitForResult();
+ rv = c->callback.WaitForResult();
ASSERT_THAT(rv, IsError(ERR_CACHE_MISS));
}
@@ -6616,11 +6671,10 @@ TEST(HttpCache, SimpleGET_SSLError) {
TEST(HttpCache, OutlivedTransactions) {
MockHttpCache* cache = new MockHttpCache;
- std::unique_ptr<HttpTransaction> trans;
- EXPECT_THAT(cache->CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ EXPECT_THAT(cache->CreateTransaction(&c->trans), IsOk());
delete cache;
- trans.reset();
}
// Test that the disabled mode works.
@@ -6963,19 +7017,19 @@ TEST(HttpCache, FilterCompletion) {
TestCompletionCallback callback;
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
MockHttpRequest request(kSimpleGET_Transaction);
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
EXPECT_THAT(callback.GetResult(rv), IsOk());
scoped_refptr<IOBuffer> buf(new IOBuffer(256));
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
// Now make sure that the entry is preserved.
- trans->DoneReading();
+ c->trans->DoneReading();
}
// Make sure that the ActiveEntry is gone.
@@ -6999,14 +7053,14 @@ TEST(HttpCache, DoneReading) {
ScopedMockTransaction transaction(kSimpleGET_Transaction);
transaction.data = "";
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
MockHttpRequest request(transaction);
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
EXPECT_THAT(callback.GetResult(rv), IsOk());
- trans->DoneReading();
+ c->trans->DoneReading();
// Leave the transaction around.
// Make sure that the ActiveEntry is gone.
@@ -7023,27 +7077,27 @@ TEST(HttpCache, DoneReading) {
// Tests that we stop caching when told.
TEST(HttpCache, StopCachingDeletesEntry) {
MockHttpCache cache;
- TestCompletionCallback callback;
MockHttpRequest request(kSimpleGET_Transaction);
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
- EXPECT_THAT(callback.GetResult(rv), IsOk());
+ int rv =
+ c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
+ EXPECT_THAT(c->callback.GetResult(rv), IsOk());
scoped_refptr<IOBuffer> buf(new IOBuffer(256));
- rv = trans->Read(buf.get(), 10, callback.callback());
- EXPECT_EQ(10, callback.GetResult(rv));
+ rv = c->trans->Read(buf.get(), 10, c->callback.callback());
+ EXPECT_EQ(10, c->callback.GetResult(rv));
- trans->StopCaching();
+ c->trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf.get(), 256, callback.callback());
- EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf.get(), 256, callback.callback());
- EXPECT_EQ(0, callback.GetResult(rv));
+ rv = c->trans->Read(buf.get(), 256, c->callback.callback());
+ EXPECT_GT(c->callback.GetResult(rv), 0);
+ rv = c->trans->Read(buf.get(), 256, c->callback.callback());
+ EXPECT_EQ(0, c->callback.GetResult(rv));
}
// Make sure that the ActiveEntry is gone.
@@ -7065,26 +7119,26 @@ TEST(HttpCache, StopCachingThenDoneReadingDeletesEntry) {
MockHttpRequest request(kSimpleGET_Transaction);
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
EXPECT_THAT(callback.GetResult(rv), IsOk());
scoped_refptr<IOBuffer> buf(new IOBuffer(256));
- rv = trans->Read(buf.get(), 10, callback.callback());
+ rv = c->trans->Read(buf.get(), 10, callback.callback());
EXPECT_EQ(10, callback.GetResult(rv));
- trans->StopCaching();
+ c->trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_EQ(0, callback.GetResult(rv));
// We should be able to call DoneReading.
- trans->DoneReading();
+ c->trans->DoneReading();
}
// Make sure that the ActiveEntry is gone.
@@ -7108,16 +7162,16 @@ TEST(HttpCache, StopCachingWithAuthDeletesEntry) {
MockHttpRequest request(mock_transaction);
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
EXPECT_THAT(callback.GetResult(rv), IsOk());
- trans->StopCaching();
+ c->trans->StopCaching();
scoped_refptr<IOBuffer> buf(new IOBuffer(256));
- rv = trans->Read(buf.get(), 10, callback.callback());
+ rv = c->trans->Read(buf.get(), 10, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 10);
}
RemoveMockTransaction(&mock_transaction);
@@ -7140,8 +7194,8 @@ TEST(HttpCache, StopCachingSavesEntry) {
MockHttpRequest request(kSimpleGET_Transaction);
{
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
// Force a response that can be resumed.
ScopedMockTransaction mock_transaction(kSimpleGET_Transaction);
@@ -7150,19 +7204,19 @@ TEST(HttpCache, StopCachingSavesEntry) {
"Content-Length: 42\n"
"Etag: \"foo\"\n";
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
EXPECT_THAT(callback.GetResult(rv), IsOk());
scoped_refptr<IOBuffer> buf(new IOBuffer(256));
- rv = trans->Read(buf.get(), 10, callback.callback());
+ rv = c->trans->Read(buf.get(), 10, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 10);
- trans->StopCaching();
+ c->trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 0);
}
@@ -7188,25 +7242,25 @@ TEST(HttpCache, StopCachingTruncatedEntry) {
{
// Now make a regular request.
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
+ std::unique_ptr<Context> c(new Context());
+ ASSERT_THAT(cache.CreateTransaction(&c->trans), IsOk());
- int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
+ int rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
EXPECT_THAT(callback.GetResult(rv), IsOk());
scoped_refptr<IOBuffer> buf(new IOBuffer(256));
- rv = trans->Read(buf.get(), 10, callback.callback());
+ rv = c->trans->Read(buf.get(), 10, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 10);
// This is actually going to do nothing.
- trans->StopCaching();
+ c->trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf.get(), 256, callback.callback());
+ rv = c->trans->Read(buf.get(), 256, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 0);
}
@@ -7433,41 +7487,40 @@ TEST_P(HttpCacheHugeResourceTest,
MockHttpRequest request(transaction);
net::TestCompletionCallback callback;
- std::unique_ptr<net::HttpTransaction> http_transaction;
- int rv = cache.http_cache()->CreateTransaction(net::DEFAULT_PRIORITY,
- &http_transaction);
+ std::unique_ptr<Context> c(new Context());
+ int rv =
+ cache.http_cache()->CreateTransaction(net::DEFAULT_PRIORITY, &c->trans);
ASSERT_EQ(net::OK, rv);
- ASSERT_TRUE(http_transaction.get());
+ ASSERT_TRUE(c->trans.get());
bool network_transaction_started = false;
if (stop_caching_phase == TransactionPhase::AFTER_NETWORK_READ) {
- http_transaction->SetBeforeNetworkStartCallback(
+ c->trans->SetBeforeNetworkStartCallback(
base::Bind(&SetFlagOnBeforeNetworkStart, &network_transaction_started));
}
- rv = http_transaction->Start(&request, callback.callback(),
- NetLogWithSource());
+ rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
rv = callback.GetResult(rv);
ASSERT_EQ(net::OK, rv);
if (stop_caching_phase == TransactionPhase::BEFORE_FIRST_READ)
- http_transaction->StopCaching();
+ c->trans->StopCaching();
int64_t total_bytes_received = 0;
EXPECT_EQ(kTotalSize,
- http_transaction->GetResponseInfo()->headers->GetContentLength());
+ c->trans->GetResponseInfo()->headers->GetContentLength());
do {
// This test simulates reading gigabytes of data. Buffer size is set to 10MB
// to reduce the number of reads and speed up the test.
const int kBufferSize = 1024 * 1024 * 10;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufferSize));
- rv = http_transaction->Read(buf.get(), kBufferSize, callback.callback());
+ rv = c->trans->Read(buf.get(), kBufferSize, callback.callback());
rv = callback.GetResult(rv);
if (stop_caching_phase == TransactionPhase::AFTER_FIRST_READ &&
total_bytes_received == 0) {
- http_transaction->StopCaching();
+ c->trans->StopCaching();
}
if (rv > 0)
@@ -7475,7 +7528,7 @@ TEST_P(HttpCacheHugeResourceTest,
if (network_transaction_started &&
stop_caching_phase == TransactionPhase::AFTER_NETWORK_READ) {
- http_transaction->StopCaching();
+ c->trans->StopCaching();
network_transaction_started = false;
}
} while (rv > 0);
@@ -7530,11 +7583,11 @@ TEST(HttpCache, TruncatedByContentLength2) {
TEST(HttpCache, SetPriority) {
MockHttpCache cache;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk());
+ std::unique_ptr<Context> c(new Context);
+ ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &c->trans), IsOk());
// Shouldn't crash, but doesn't do anything either.
- trans->SetPriority(LOW);
+ c->trans->SetPriority(LOW);
EXPECT_FALSE(cache.network_layer()->last_transaction());
EXPECT_EQ(DEFAULT_PRIORITY,
@@ -7544,7 +7597,7 @@ TEST(HttpCache, SetPriority) {
info.url = GURL(kSimpleGET_Transaction.url);
TestCompletionCallback callback;
EXPECT_EQ(ERR_IO_PENDING,
- trans->Start(&info, callback.callback(), NetLogWithSource()));
+ c->trans->Start(&info, callback.callback(), NetLogWithSource()));
EXPECT_TRUE(cache.network_layer()->last_transaction());
if (cache.network_layer()->last_transaction()) {
@@ -7552,7 +7605,7 @@ TEST(HttpCache, SetPriority) {
EXPECT_EQ(LOW, cache.network_layer()->last_transaction()->priority());
}
- trans->SetPriority(HIGHEST);
+ c->trans->SetPriority(HIGHEST);
if (cache.network_layer()->last_transaction()) {
EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority());
@@ -7568,8 +7621,8 @@ TEST(HttpCache, SetWebSocketHandshakeStreamCreateHelper) {
MockHttpCache cache;
FakeWebSocketHandshakeStreamCreateHelper create_helper;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk());
+ std::unique_ptr<Context> c(new Context);
+ ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &c->trans), IsOk());
EXPECT_FALSE(cache.network_layer()->last_transaction());
@@ -7577,12 +7630,12 @@ TEST(HttpCache, SetWebSocketHandshakeStreamCreateHelper) {
info.url = GURL(kSimpleGET_Transaction.url);
TestCompletionCallback callback;
EXPECT_EQ(ERR_IO_PENDING,
- trans->Start(&info, callback.callback(), NetLogWithSource()));
+ c->trans->Start(&info, callback.callback(), NetLogWithSource()));
ASSERT_TRUE(cache.network_layer()->last_transaction());
EXPECT_FALSE(cache.network_layer()->last_transaction()->
websocket_handshake_stream_create_helper());
- trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper);
+ c->trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper);
EXPECT_EQ(&create_helper,
cache.network_layer()->last_transaction()->
websocket_handshake_stream_create_helper());
@@ -7608,23 +7661,23 @@ TEST(HttpCache, SetPriorityNewTransaction) {
transaction.request_headers = EXTRA_HEADER;
transaction.data = kFullRangeData;
- std::unique_ptr<HttpTransaction> trans;
- ASSERT_THAT(cache.http_cache()->CreateTransaction(MEDIUM, &trans), IsOk());
+ std::unique_ptr<Context> c(new Context);
+ ASSERT_THAT(cache.http_cache()->CreateTransaction(MEDIUM, &c->trans), IsOk());
EXPECT_EQ(DEFAULT_PRIORITY,
cache.network_layer()->last_create_transaction_priority());
MockHttpRequest info(transaction);
TestCompletionCallback callback;
EXPECT_EQ(ERR_IO_PENDING,
- trans->Start(&info, callback.callback(), NetLogWithSource()));
+ c->trans->Start(&info, callback.callback(), NetLogWithSource()));
EXPECT_THAT(callback.WaitForResult(), IsOk());
EXPECT_EQ(MEDIUM, cache.network_layer()->last_create_transaction_priority());
- trans->SetPriority(HIGHEST);
+ c->trans->SetPriority(HIGHEST);
// Should trigger a new network transaction and pick up the new
// priority.
- ReadAndVerifyTransaction(trans.get(), transaction);
+ ReadAndVerifyTransaction(c->trans.get(), transaction);
EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority());
@@ -8003,13 +8056,13 @@ TEST(HttpCache, RangeGET_MultipleRequests) {
AddMockTransaction(&transaction);
TestCompletionCallback callback;
- std::unique_ptr<HttpTransaction> trans;
- int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
+ std::unique_ptr<Context> c(new Context);
+ int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
EXPECT_THAT(rv, IsOk());
- ASSERT_TRUE(trans.get());
+ ASSERT_TRUE(c->trans.get());
// Start our transaction.
- trans->Start(&request, callback.callback(), NetLogWithSource());
+ c->trans->Start(&request, callback.callback(), NetLogWithSource());
// A second transaction on a different part of the file (the default
// kRangeGET_TransactionOK requests 40-49) should not be blocked by
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_response_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698