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

Unified Diff: net/http/http_cache_unittest.cc

Issue 10736066: Adding histograms showing fraction of page load times (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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_network_layer.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
===================================================================
--- net/http/http_cache_unittest.cc (revision 148459)
+++ 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:
+ explicit TestHttpTransactionDelegate(int num_actions_to_observe)
+ : num_remaining_actions_to_observe_(num_actions_to_observe),
+ action_in_progress_(false) {
+ }
+ virtual ~TestHttpTransactionDelegate() {
+ EXPECT_EQ(0, num_remaining_actions_to_observe_);
+ EXPECT_FALSE(action_in_progress_);
+ }
+ virtual void OnCacheActionStart() {
+ EXPECT_FALSE(action_in_progress_);
+ EXPECT_GT(num_remaining_actions_to_observe_, 0);
+ num_remaining_actions_to_observe_--;
+ action_in_progress_ = true;
+ }
+ virtual void OnCacheActionFinish() {
+ EXPECT_TRUE(action_in_progress_);
+ 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) {
+const int kNoDelegateTransactionCheck = -1;
+
+void RunTransactionTestWithRequestAndLogAndDelegate(
+ net::HttpCache* cache,
+ const MockTransaction& trans_info,
+ const MockHttpRequest& request,
+ net::HttpResponseInfo* response_info,
+ const net::BoundNetLog& net_log,
+ int num_delegate_actions) {
net::TestCompletionCallback callback;
// write to the cache
+ scoped_ptr<TestHttpTransactionDelegate> delegate;
+ if (num_delegate_actions != kNoDelegateTransactionCheck) {
+ delegate.reset(new TestHttpTransactionDelegate(num_delegate_actions));
+ }
scoped_ptr<net::HttpTransaction> trans;
- int rv = cache->CreateTransaction(&trans);
+ int rv = cache->CreateTransaction(&trans, delegate.get());
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
@@ -101,17 +136,27 @@
const MockTransaction& trans_info,
const MockHttpRequest& request,
net::HttpResponseInfo* response_info) {
- RunTransactionTestWithRequestAndLog(cache, trans_info, request,
- response_info, net::BoundNetLog());
+ RunTransactionTestWithRequestAndLogAndDelegate(
+ 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);
+ RunTransactionTestWithRequestAndLogAndDelegate(
+ cache, trans_info, MockHttpRequest(trans_info), NULL, log,
+ kNoDelegateTransactionCheck);
}
+void RunTransactionTestWithDelegate(net::HttpCache* cache,
+ const MockTransaction& trans_info,
+ int num_delegate_actions) {
+ RunTransactionTestWithRequestAndLogAndDelegate(
+ cache, trans_info, MockHttpRequest(trans_info), NULL, net::BoundNetLog(),
+ num_delegate_actions);
+}
+
void RunTransactionTest(net::HttpCache* cache,
const MockTransaction& trans_info) {
RunTransactionTestWithLog(cache, trans_info, net::BoundNetLog());
@@ -396,7 +441,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 +545,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 +590,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 +690,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 +916,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 +984,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 +1069,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 +1117,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 +1164,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 +1224,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 +1275,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 +1305,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 +1347,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 +1382,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 +1421,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 +1467,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 +1513,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 +1551,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 +2237,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 +3298,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 +3337,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 +3382,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 +3409,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 +3690,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 +3768,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 +3798,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 +3841,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 +3884,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 +3944,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 +4088,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 +4096,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 +4181,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 +4253,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 +4381,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 +4409,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 +4534,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 +4549,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 +4787,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 +4821,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 +4859,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 +4916,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 +4995,20 @@
EXPECT_TRUE(truncated);
entry->Close();
}
+
+TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit_TransactionDelegate) {
+ MockHttpCache cache;
+
+ // Write to the cache.
+ RunTransactionTestWithDelegate(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;
+
+ RunTransactionTestWithDelegate(cache.http_cache(),
+ kSimpleGET_Transaction,
+ 5);
+}
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_network_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698