| Index: net/http/http_cache_unittest.cc
|
| ===================================================================
|
| --- net/http/http_cache_unittest.cc (revision 147972)
|
| +++ net/http/http_cache_unittest.cc (working copy)
|
| @@ -24,6 +24,7 @@
|
| #include "net/http/http_response_headers.h"
|
| #include "net/http/http_response_info.h"
|
| #include "net/http/http_transaction.h"
|
| +#include "net/http/http_transaction_delegate.h"
|
| #include "net/http/http_transaction_unittest.h"
|
| #include "net/http/http_util.h"
|
| #include "net/http/mock_http_cache.h"
|
| @@ -59,6 +60,32 @@
|
| //-----------------------------------------------------------------------------
|
| // helpers
|
|
|
| +class TestHttpTransactionDelegate : public net::HttpTransactionDelegate {
|
| + public:
|
| + TestHttpTransactionDelegate(int num_actions_to_observe)
|
| + : num_remaining_actions_to_observe_(num_actions_to_observe),
|
| + action_in_progress_(false){
|
| + }
|
| + virtual ~TestHttpTransactionDelegate() {
|
| + EXPECT_EQ(num_remaining_actions_to_observe_, 0);
|
| + EXPECT_EQ(action_in_progress_, false);
|
| + }
|
| + virtual void OnCacheActionStart() {
|
| + EXPECT_EQ(action_in_progress_, false);
|
| + EXPECT_GT(num_remaining_actions_to_observe_, 0);
|
| + num_remaining_actions_to_observe_--;
|
| + action_in_progress_ = true;
|
| + }
|
| + virtual void OnCacheActionFinish() {
|
| + EXPECT_EQ(action_in_progress_, true);
|
| + action_in_progress_ = false;
|
| + }
|
| +
|
| + private:
|
| + int num_remaining_actions_to_observe_;
|
| + bool action_in_progress_;
|
| +};
|
| +
|
| void ReadAndVerifyTransaction(net::HttpTransaction* trans,
|
| const MockTransaction& trans_info) {
|
| std::string content;
|
| @@ -69,17 +96,25 @@
|
| EXPECT_EQ(expected, content);
|
| }
|
|
|
| -void RunTransactionTestWithRequestAndLog(net::HttpCache* cache,
|
| - const MockTransaction& trans_info,
|
| - const MockHttpRequest& request,
|
| - net::HttpResponseInfo* response_info,
|
| - const net::BoundNetLog& net_log) {
|
| +static const int kNoDelegateTransactionCheck = -1;
|
| +
|
| +void RunTransactionTestWithRequestAndLogAndNumDelegateTransactions(
|
| + net::HttpCache* cache,
|
| + const MockTransaction& trans_info,
|
| + const MockHttpRequest& request,
|
| + net::HttpResponseInfo* response_info,
|
| + const net::BoundNetLog& net_log,
|
| + int num_delegate_transactions) {
|
| net::TestCompletionCallback callback;
|
|
|
| // write to the cache
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache->CreateTransaction(&trans);
|
| + scoped_ptr<TestHttpTransactionDelegate> delegate;
|
| + if (num_delegate_transactions != kNoDelegateTransactionCheck) {
|
| + delegate.reset(new TestHttpTransactionDelegate(num_delegate_transactions));
|
| + }
|
| + int rv = cache->CreateTransaction(&trans, delegate.get());
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -101,17 +136,28 @@
|
| const MockTransaction& trans_info,
|
| const MockHttpRequest& request,
|
| net::HttpResponseInfo* response_info) {
|
| - RunTransactionTestWithRequestAndLog(cache, trans_info, request,
|
| - response_info, net::BoundNetLog());
|
| + RunTransactionTestWithRequestAndLogAndNumDelegateTransactions(
|
| + cache, trans_info, request, response_info, net::BoundNetLog(),
|
| + kNoDelegateTransactionCheck);
|
| }
|
|
|
| void RunTransactionTestWithLog(net::HttpCache* cache,
|
| const MockTransaction& trans_info,
|
| const net::BoundNetLog& log) {
|
| - RunTransactionTestWithRequestAndLog(
|
| - cache, trans_info, MockHttpRequest(trans_info), NULL, log);
|
| + RunTransactionTestWithRequestAndLogAndNumDelegateTransactions(
|
| + cache, trans_info, MockHttpRequest(trans_info), NULL, log,
|
| + kNoDelegateTransactionCheck);
|
| }
|
|
|
| +void RunTransactionTestWithNumDelegateTransactions(
|
| + net::HttpCache* cache,
|
| + const MockTransaction& trans_info,
|
| + int num_delegate_transactions) {
|
| + RunTransactionTestWithRequestAndLogAndNumDelegateTransactions(
|
| + cache, trans_info, MockHttpRequest(trans_info), NULL, net::BoundNetLog(),
|
| + num_delegate_transactions);
|
| +}
|
| +
|
| void RunTransactionTest(net::HttpCache* cache,
|
| const MockTransaction& trans_info) {
|
| RunTransactionTestWithLog(cache, trans_info, net::BoundNetLog());
|
| @@ -396,7 +442,7 @@
|
| MockHttpCache cache;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
| }
|
| @@ -500,7 +546,7 @@
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
|
|
| scoped_ptr<Context> c(new Context());
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -545,7 +591,7 @@
|
|
|
| // Now fail to read from the cache.
|
| scoped_ptr<Context> c(new Context());
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
| @@ -645,7 +691,7 @@
|
| net::TestCompletionCallback callback;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -871,7 +917,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
| EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState());
|
|
|
| @@ -939,7 +985,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| MockHttpRequest* this_request = &request;
|
| @@ -1024,7 +1070,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| MockHttpRequest* this_request = &request;
|
| @@ -1072,7 +1118,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->result = c->trans->Start(
|
| @@ -1119,7 +1165,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->result = c->trans->Start(
|
| @@ -1179,7 +1225,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->result = c->trans->Start(
|
| @@ -1230,7 +1276,7 @@
|
|
|
| Context* c = new Context();
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->result = c->trans->Start(
|
| @@ -1260,7 +1306,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->result = c->trans->Start(
|
| @@ -1302,7 +1348,7 @@
|
| net::TestCompletionCallback callback;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
|
| if (rv == net::ERR_IO_PENDING)
|
| @@ -1337,7 +1383,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache->http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->result = c->trans->Start(
|
| @@ -1376,7 +1422,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
| }
|
|
|
| @@ -1422,7 +1468,7 @@
|
| context_list.push_back(new Context());
|
| Context* c = context_list[i];
|
|
|
| - c->result = cache.http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
| }
|
|
|
| @@ -1468,7 +1514,7 @@
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
|
|
| scoped_ptr<Context> c(new Context());
|
| - c->result = cache->http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -1506,7 +1552,7 @@
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
|
|
| scoped_ptr<Context> c(new Context());
|
| - c->result = cache->http_cache()->CreateTransaction(&c->trans);
|
| + c->result = cache->http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, c->result);
|
|
|
| c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -2192,7 +2238,7 @@
|
| net::TestCompletionCallback callback;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -3253,7 +3299,7 @@
|
| MockHttpRequest request(kRangeGET_TransactionOK);
|
|
|
| Context* c = new Context();
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3292,7 +3338,7 @@
|
| request.load_flags |= net::LOAD_VALIDATE_CACHE;
|
|
|
| Context* c = new Context();
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3337,7 +3383,7 @@
|
| request.load_flags |= net::LOAD_VALIDATE_CACHE;
|
|
|
| Context* c = new Context();
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3364,7 +3410,7 @@
|
| // active entry (no open or create).
|
|
|
| c = new Context();
|
| - rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3645,7 +3691,7 @@
|
| net::TestCompletionCallback callback;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -3723,7 +3769,7 @@
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
|
|
| Context* c = new Context();
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3753,7 +3799,7 @@
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
|
|
| Context* c = new Context();
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3796,7 +3842,7 @@
|
| MockHttpRequest request(transaction);
|
|
|
| Context* c = new Context();
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3839,7 +3885,7 @@
|
| MockHttpRequest request(transaction);
|
|
|
| scoped_ptr<Context> c(new Context());
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -3899,7 +3945,7 @@
|
| MockHttpRequest request(transaction);
|
|
|
| scoped_ptr<Context> c(new Context());
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| @@ -4043,7 +4089,7 @@
|
| MockHttpRequest request(transaction);
|
| Context* c = new Context();
|
|
|
| - int rv = cache.http_cache()->CreateTransaction(&c->trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&c->trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| // Queue another request to this transaction. We have to start this request
|
| @@ -4051,7 +4097,8 @@
|
| // otherwise it will just create a new entry without being queued to the first
|
| // request.
|
| Context* pending = new Context();
|
| - EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&pending->trans));
|
| + EXPECT_EQ(net::OK,
|
| + cache.http_cache()->CreateTransaction(&pending->trans, NULL));
|
|
|
| rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
|
| EXPECT_EQ(net::ERR_IO_PENDING,
|
| @@ -4135,7 +4182,7 @@
|
| "rg: 50-59 rg: 60-69 rg: 70-79 ";
|
|
|
| scoped_ptr<Context> c(new Context);
|
| - EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
|
| + EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans, NULL));
|
|
|
| MockHttpRequest request(transaction);
|
| int rv = c->trans->Start(
|
| @@ -4207,7 +4254,7 @@
|
|
|
| MockHttpRequest request(transaction);
|
| Context* c = new Context();
|
| - EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
|
| + EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans, NULL));
|
|
|
| int rv = c->trans->Start(
|
| &request, c->callback.callback(), net::BoundNetLog());
|
| @@ -4335,7 +4382,7 @@
|
| // write to the cache
|
| {
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -4363,7 +4410,7 @@
|
| // read from the cache
|
| {
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -4488,7 +4535,7 @@
|
| net::TestCompletionCallback callback;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
| ASSERT_TRUE(trans.get());
|
|
|
| @@ -4503,7 +4550,7 @@
|
| MockHttpCache* cache = new MockHttpCache;
|
|
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache->http_cache()->CreateTransaction(&trans);
|
| + int rv = cache->http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| delete cache;
|
| @@ -4741,7 +4788,7 @@
|
|
|
| {
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| MockHttpRequest request(kSimpleGET_Transaction);
|
| @@ -4775,7 +4822,7 @@
|
|
|
| {
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
|
| @@ -4813,7 +4860,7 @@
|
|
|
| {
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| // Force a response that can be resumed.
|
| @@ -4870,7 +4917,7 @@
|
| {
|
| // Now make a regular request.
|
| scoped_ptr<net::HttpTransaction> trans;
|
| - int rv = cache.http_cache()->CreateTransaction(&trans);
|
| + int rv = cache.http_cache()->CreateTransaction(&trans, NULL);
|
| EXPECT_EQ(net::OK, rv);
|
|
|
| rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
|
| @@ -4949,3 +4996,20 @@
|
| EXPECT_TRUE(truncated);
|
| entry->Close();
|
| }
|
| +
|
| +TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit_TransactionDelegate) {
|
| + MockHttpCache cache;
|
| +
|
| + // write to the cache
|
| + RunTransactionTestWithNumDelegateTransactions(cache.http_cache(),
|
| + kSimpleGET_Transaction,
|
| + 8);
|
| +
|
| + // force this transaction to read from the cache
|
| + MockTransaction transaction(kSimpleGET_Transaction);
|
| + transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
|
| +
|
| + RunTransactionTestWithNumDelegateTransactions(cache.http_cache(),
|
| + kSimpleGET_Transaction,
|
| + 5);
|
| +}
|
|
|