Chromium Code Reviews| Index: net/http/http_cache_unittest.cc |
| diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc |
| index a3d83f4853399779b1dc214e239bc9823fbe3087..3c046c04cf6ca687a7f17f016eed21dfcdc00868 100644 |
| --- a/net/http/http_cache_unittest.cc |
| +++ b/net/http/http_cache_unittest.cc |
| @@ -58,6 +58,8 @@ using base::Time; |
| namespace net { |
| +using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus; |
| + |
| namespace { |
| // Tests the load timing values of a request that goes through a |
| @@ -1055,6 +1057,7 @@ TEST(HttpCache, SimpleGET_NetworkAccessed_Network) { |
| EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::NOT_IN_CACHE, response_info.cache_entry_status); |
| } |
| // Confirm if we have a fresh entry in cache, it isn't marked as |
| @@ -1077,6 +1080,7 @@ TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) { |
| EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| EXPECT_FALSE(response_info.server_data_unavailable); |
| EXPECT_FALSE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::USED, response_info.cache_entry_status); |
| } |
| TEST(HttpCache, SimpleGET_LoadBypassCache) { |
| @@ -8005,4 +8009,89 @@ TEST(HttpCache, RevalidationUpdatesSSLInfo) { |
| EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); |
| } |
| +TEST(HttpCache, CacheEntryStatusOther) { |
| + MockHttpCache cache; |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), kRangeGET_Transaction, |
| + &response_info); |
| + |
| + EXPECT_FALSE(response_info.was_cached); |
| + EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::OTHER, response_info.cache_entry_status); |
| +} |
| + |
| +TEST(HttpCache, CacheEntryStatusNotInCache) { |
| + MockHttpCache cache; |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
| + &response_info); |
| + |
| + EXPECT_FALSE(response_info.was_cached); |
| + EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::NOT_IN_CACHE, response_info.cache_entry_status); |
| +} |
| + |
| +TEST(HttpCache, CacheEntryStatusUsed) { |
| + MockHttpCache cache; |
| + RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
| + &response_info); |
| + |
| + EXPECT_TRUE(response_info.was_cached); |
| + EXPECT_FALSE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::USED, response_info.cache_entry_status); |
| +} |
| + |
| +TEST(HttpCache, CacheEntryStatusValidated) { |
| + MockHttpCache cache; |
| + RunTransactionTest(cache.http_cache(), kETagGET_Transaction); |
| + |
| + ScopedMockTransaction still_valid(kETagGET_Transaction); |
| + still_valid.load_flags = LOAD_VALIDATE_CACHE; // Force a validation. |
| + still_valid.handler = ETagGet_ConditionalRequest_Handler; |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), still_valid, |
| + &response_info); |
| + |
| + EXPECT_TRUE(response_info.was_cached); |
| + EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::VALIDATED, response_info.cache_entry_status); |
| +} |
| + |
| +TEST(HttpCache, CacheEntryStatusUpdated) { |
| + MockHttpCache cache; |
| + RunTransactionTest(cache.http_cache(), kETagGET_Transaction); |
| + |
| + ScopedMockTransaction update(kETagGET_Transaction); |
| + update.load_flags = LOAD_VALIDATE_CACHE; // Force a validation. |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), update, |
| + &response_info); |
| + |
| + EXPECT_FALSE(response_info.was_cached); |
| + EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::UPDATED, response_info.cache_entry_status); |
| +} |
| + |
| +TEST(HttpCache, CacheEntryStatusCantConditionalize) { |
| + MockHttpCache cache; |
| + cache.FailConditionalizations(); |
| + RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), |
| + kTypicalGET_Transaction, &response_info); |
| + |
| + EXPECT_FALSE(response_info.was_cached); |
| + EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::CANT_CONDITIONALIZE, |
| + response_info.cache_entry_status); |
| +} |
| + |
|
jkarlin
2016/07/06 17:09:41
Also add a test for an authentication request that
jamartin
2016/07/07 21:36:38
I need your help with this. Currently (see the new
jkarlin
2016/07/18 17:24:46
That's the correct behavior for each case.
jamartin
2016/07/19 16:02:46
Done.
jkarlin
2016/07/21 17:25:54
I was wrong, my apologies, the auth request can co
jamartin
2016/07/25 13:39:16
No worries. I was getting concerned by the failure
|
| } // namespace net |