Index: net/http/http_cache_unittest.cc |
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc |
index 22255760841199705d355c0e4112f129a481b9af..d2d52b760ba8603b9d47ff48eb13770bc42ed9f4 100644 |
--- a/net/http/http_cache_unittest.cc |
+++ b/net/http/http_cache_unittest.cc |
@@ -155,7 +155,7 @@ void RunTransactionTestWithRequestAndLogAndDelegate( |
rv = trans->Start(&request, callback.callback(), net_log); |
if (rv == net::ERR_IO_PENDING) |
rv = callback.WaitForResult(); |
- ASSERT_EQ(net::OK, rv); |
+ ASSERT_EQ(trans_info.error_return, rv); |
const net::HttpResponseInfo* response = trans->GetResponseInfo(); |
ASSERT_TRUE(response); |
@@ -1203,6 +1203,64 @@ TEST(HttpCache, SimpleGET_DoomWithPending) { |
} |
} |
+// Tests that LOAD_CACHE_RETURN_IF_OFFLINE returns proper responses on |
+// network success, offline failure, and non-offline failure. |
rvargas (doing something else)
2013/03/05 02:58:19
sounds like three different tests.
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
|
+TEST(HttpCache, SimpleGET_CacheOverride) { |
rvargas (doing something else)
2013/03/05 02:58:19
could you move this next to a test that goes over
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
|
+ MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(1024 * 1024)); |
rvargas (doing something else)
2013/03/05 02:58:19
why a real cache?
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Naivete': I copy-pasted from the wrong test. Fixe
|
+ |
+ MockTransaction transaction(kSimpleGET_Transaction); |
+ transaction.load_flags |= net::LOAD_CACHE_RETURN_IF_OFFLINE; |
+ transaction.response_headers = "Cache-Control: no-cache\n"; |
+ |
+ // Regular network test; should behave as normal. |
+ AddMockTransaction(&transaction); |
+ net::HttpResponseInfo response_info; |
+ RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, |
+ &response_info); |
+ |
+ EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
+ EXPECT_FALSE(response_info.was_cache_override); |
+ |
+ RemoveMockTransaction(&transaction); |
+ |
+ // Network failure with offline error; should return cache entry above + |
+ // flag signalling stale data. |
+ transaction.error_return = net::ERR_NAME_NOT_RESOLVED; |
+ AddMockTransaction(&transaction); |
+ |
+ MockHttpRequest request(transaction); |
+ net::TestCompletionCallback callback; |
+ scoped_ptr<net::HttpTransaction> trans; |
+ int rv = cache.http_cache()->CreateTransaction(&trans, NULL); |
+ EXPECT_EQ(net::OK, rv); |
+ ASSERT_TRUE(trans.get()); |
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
+ if (rv == net::ERR_IO_PENDING) |
+ rv = callback.WaitForResult(); |
rvargas (doing something else)
2013/03/05 02:58:19
GetResult(rv)
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
|
+ EXPECT_EQ(net::OK, rv); |
+ |
+ const net::HttpResponseInfo* response_info1 = trans->GetResponseInfo(); |
+ ASSERT_TRUE(response_info1); |
+ EXPECT_TRUE(response_info1->was_cache_override); |
+ ReadAndVerifyTransaction(trans.get(), transaction); |
+ EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
+ |
+ RemoveMockTransaction(&transaction); |
+ |
+ // Network failure with non-offline error; should fail with that error. |
+ transaction.error_return = net::ERR_PROXY_CONNECTION_FAILED; |
+ AddMockTransaction(&transaction); |
+ |
+ net::HttpResponseInfo response_info2; |
+ RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, |
+ &response_info2); |
+ |
+ EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
+ EXPECT_FALSE(response_info2.was_cache_override); |
+ |
+ RemoveMockTransaction(&transaction); |
+} |
+ |
// This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. |
// We may attempt to delete an entry synchronously with the act of adding a new |
// transaction to said entry. |