| 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..0843a98cf4fcf7c2cd7f692d5578ffaa11d6e9a7 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,143 @@ 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);
|
| +}
|
| +
|
| +TEST(HttpCache, CacheEntryStatus401BeforeRead) {
|
| + // A 401 should be flagged as ENTRY_UNDEFINED before the call to Read.
|
| + MockHttpCache cache;
|
| + ScopedMockTransaction not_authorized(kSimpleGET_Transaction);
|
| + not_authorized.status = "HTTP/1.1 401 Unauthorized";
|
| +
|
| + HttpResponseInfo response_info;
|
| + // RunTransactionTestWithResponseInfo takes the response_info before Read is
|
| + // called.
|
| + RunTransactionTestWithResponseInfo(cache.http_cache(), not_authorized,
|
| + &response_info);
|
| +
|
| + EXPECT_FALSE(response_info.was_cached);
|
| + EXPECT_TRUE(response_info.network_accessed);
|
| + EXPECT_EQ(CacheEntryStatus::ENTRY_UNDEFINED,
|
| + response_info.cache_entry_status);
|
| +}
|
| +
|
| +TEST(HttpCache, CacheEntryStatus401AfterRead) {
|
| + // A 401 should be flagged as ENTRY_OTHER after the call to Read.
|
| + MockHttpCache cache;
|
| + ScopedMockTransaction not_authorized(kSimpleGET_Transaction);
|
| + not_authorized.status = "HTTP/1.1 401 Unauthorized";
|
| + MockHttpRequest request(not_authorized);
|
| +
|
| + std::unique_ptr<HttpTransaction> trans;
|
| + ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
|
| +
|
| + const int kBufferSize = 10;
|
| + scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
|
| + ReleaseBufferCompletionCallback cb(buffer.get());
|
| +
|
| + int rv = trans->Start(&request, cb.callback(), BoundNetLog());
|
| + EXPECT_THAT(cb.GetResult(rv), IsOk());
|
| +
|
| + // Let's check that we are going down the right path, i.e., the same as tested
|
| + // in CacheEntryStatus401BeforeRead.
|
| + ASSERT_TRUE(trans->GetResponseInfo());
|
| + ASSERT_EQ(CacheEntryStatus::ENTRY_UNDEFINED,
|
| + trans->GetResponseInfo()->cache_entry_status);
|
| +
|
| + rv = trans->Read(buffer.get(), kBufferSize, cb.callback());
|
| + EXPECT_EQ(kBufferSize, cb.GetResult(rv));
|
| +
|
| + const HttpResponseInfo* response_info = trans->GetResponseInfo();
|
| + ASSERT_TRUE(response_info);
|
| +
|
| + EXPECT_FALSE(response_info->was_cached);
|
| + EXPECT_TRUE(response_info->network_accessed);
|
| + EXPECT_EQ(CacheEntryStatus::ENTRY_OTHER, response_info->cache_entry_status);
|
| +}
|
| +
|
| } // namespace net
|
|
|