summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 01:08:28 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 01:08:28 +0000
commit3b9cca4c8d1d88590b42e44f37dbc7aadd6fca48 (patch)
tree61004acabf785df070a77a97792211b5d9def0c0 /net
parent764a7d4695cb6edc453a1960953a26a8978c6f96 (diff)
downloadchromium_src-3b9cca4c8d1d88590b42e44f37dbc7aadd6fca48.zip
chromium_src-3b9cca4c8d1d88590b42e44f37dbc7aadd6fca48.tar.gz
chromium_src-3b9cca4c8d1d88590b42e44f37dbc7aadd6fca48.tar.bz2
Bypass the host cache when you refresh a page.
BUG=13163 TEST=HttpNetworkTransactionTest.BypassHostCacheOnRefresh, HostResolverTest.BypassCache Review URL: http://codereview.chromium.org/125154 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_network_transaction.cc7
-rw-r--r--net/http/http_network_transaction_unittest.cc52
2 files changed, 53 insertions, 6 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index f4a7879..2383c38 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -577,16 +577,11 @@ int HttpNetworkTransaction::DoInitConnection() {
// that we resolve to.
resolve_info.set_referrer(request_->referrer);
-// TODO(eroman): Enable this!
-// Needs some unit-tests before turning on.
-// http://crbug.com/13163
-#if 0
// If the user is refreshing the page, bypass the host cache.
if (request_->load_flags & LOAD_BYPASS_CACHE ||
request_->load_flags & LOAD_DISABLE_CACHE) {
- resolve_info.allow_cached_response = false;
+ resolve_info.set_allow_cached_response(false);
}
-#endif
int rv = connection_.Init(connection_group, resolve_info, request_->priority,
&io_callback_);
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 59bfffc..778bd8f 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -3104,4 +3104,56 @@ TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) {
EXPECT_TRUE(resolution_observer.did_complete_with_expected_referrer());
}
+// Make sure that when the load flags contain LOAD_BYPASS_CACHE, the resolver's
+// host cache is bypassed.
+TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) {
+ SessionDependencies session_deps;
+ scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
+ CreateSession(&session_deps), &session_deps.socket_factory));
+
+ // Warm up the host cache so it has an entry for "www.google.com" (by doing
+ // a synchronous lookup.)
+ AddressList addrlist;
+ int rv = session_deps.host_resolver.Resolve(
+ HostResolver::RequestInfo("www.google.com", 80), &addrlist, NULL, NULL);
+ EXPECT_EQ(OK, rv);
+
+ // Verify that it was added to host cache, by doing a subsequent async lookup
+ // and confirming it completes synchronously.
+ TestCompletionCallback resolve_callback;
+ rv = session_deps.host_resolver.Resolve(
+ HostResolver::RequestInfo("www.google.com", 80), &addrlist,
+ &resolve_callback, NULL);
+ EXPECT_EQ(OK, rv);
+
+ // Inject a failure the next time that "www.google.com" is resolved. This way
+ // we can tell if the next lookup hit the cache, or the "network".
+ // (cache --> success, "network" --> failure).
+ scoped_refptr<RuleBasedHostMapper> host_mapper(new RuleBasedHostMapper());
+ ScopedHostMapper scoped_host_mapper(host_mapper.get());
+ host_mapper->AddSimulatedFailure("www.google.com");
+
+ // Connect up a mock socket which will fail with ERR_UNEXPECTED during the
+ // first read -- this won't be reached as the host resolution will fail first.
+ MockRead data_reads[] = { MockRead(false, ERR_UNEXPECTED) };
+ StaticMockSocket data(data_reads, NULL);
+ session_deps.socket_factory.AddMockSocket(&data);
+
+ // Issue a request, asking to bypass the cache(s).
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.load_flags = LOAD_BYPASS_CACHE;
+ request.url = GURL("http://www.google.com/");
+
+ // Run the request.
+ TestCompletionCallback callback;
+ rv = trans->Start(&request, &callback);
+ ASSERT_EQ(ERR_IO_PENDING, rv);
+ rv = callback.WaitForResult();
+
+ // If we bypassed the cache, we would have gotten a failure while resolving
+ // "www.google.com".
+ EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
+}
+
} // namespace net