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

Unified Diff: net/http/http_cache_unittest.cc

Issue 2113603003: Exposing CacheEntryStatus (former TransactionPattern) via UrlRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed DCHECK message Created 4 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_response_info.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
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 9f459cca946ce10fa250c63687026142dac56473..d580c6b3a60ce0397a092a61a0c05edebd947ed9 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -63,6 +63,8 @@ using base::Time;
namespace net {
+using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus;
+
namespace {
// Tests the load timing values of a request that goes through a
@@ -1060,6 +1062,8 @@ 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::ENTRY_NOT_IN_CACHE,
+ response_info.cache_entry_status);
}
// Confirm if we have a fresh entry in cache, it isn't marked as
@@ -1082,6 +1086,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::ENTRY_USED, response_info.cache_entry_status);
}
TEST(HttpCache, SimpleGET_LoadBypassCache) {
@@ -8010,4 +8015,91 @@ 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::ENTRY_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::ENTRY_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::ENTRY_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::ENTRY_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::ENTRY_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::ENTRY_CANT_CONDITIONALIZE,
+ response_info.cache_entry_status);
+}
+
} // namespace net
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_response_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698