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

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 2205453002: Exposing CacheEntryStatus (former TransactionPattern) via UrlRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "net/ssl/ssl_connection_status_flags.h" 51 #include "net/ssl/ssl_connection_status_flags.h"
52 #include "net/test/cert_test_util.h" 52 #include "net/test/cert_test_util.h"
53 #include "net/test/test_data_directory.h" 53 #include "net/test/test_data_directory.h"
54 #include "net/websockets/websocket_handshake_stream_base.h" 54 #include "net/websockets/websocket_handshake_stream_base.h"
55 #include "testing/gtest/include/gtest/gtest.h" 55 #include "testing/gtest/include/gtest/gtest.h"
56 56
57 using base::Time; 57 using base::Time;
58 58
59 namespace net { 59 namespace net {
60 60
61 using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus;
62
61 namespace { 63 namespace {
62 64
63 // Tests the load timing values of a request that goes through a 65 // Tests the load timing values of a request that goes through a
64 // MockNetworkTransaction. 66 // MockNetworkTransaction.
65 void TestLoadTimingNetworkRequest(const LoadTimingInfo& load_timing_info) { 67 void TestLoadTimingNetworkRequest(const LoadTimingInfo& load_timing_info) {
66 EXPECT_FALSE(load_timing_info.socket_reused); 68 EXPECT_FALSE(load_timing_info.socket_reused);
67 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 69 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
68 70
69 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); 71 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
70 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); 72 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 1050
1049 // write to the cache 1051 // write to the cache
1050 HttpResponseInfo response_info; 1052 HttpResponseInfo response_info;
1051 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, 1053 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
1052 &response_info); 1054 &response_info);
1053 1055
1054 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1056 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1055 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1057 EXPECT_EQ(0, cache.disk_cache()->open_count());
1056 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1058 EXPECT_EQ(1, cache.disk_cache()->create_count());
1057 EXPECT_TRUE(response_info.network_accessed); 1059 EXPECT_TRUE(response_info.network_accessed);
1060 EXPECT_EQ(CacheEntryStatus::ENTRY_NOT_IN_CACHE,
1061 response_info.cache_entry_status);
1058 } 1062 }
1059 1063
1060 // Confirm if we have a fresh entry in cache, it isn't marked as 1064 // Confirm if we have a fresh entry in cache, it isn't marked as
1061 // network verified. 1065 // network verified.
1062 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) { 1066 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) {
1063 MockHttpCache cache; 1067 MockHttpCache cache;
1064 1068
1065 // Prime cache. 1069 // Prime cache.
1066 MockTransaction transaction(kSimpleGET_Transaction); 1070 MockTransaction transaction(kSimpleGET_Transaction);
1067 1071
1068 RunTransactionTest(cache.http_cache(), transaction); 1072 RunTransactionTest(cache.http_cache(), transaction);
1069 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1073 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1070 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1074 EXPECT_EQ(1, cache.disk_cache()->create_count());
1071 1075
1072 // Re-run transaction; make sure we don't mark the network as accessed. 1076 // Re-run transaction; make sure we don't mark the network as accessed.
1073 HttpResponseInfo response_info; 1077 HttpResponseInfo response_info;
1074 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, 1078 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
1075 &response_info); 1079 &response_info);
1076 1080
1077 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1081 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1078 EXPECT_FALSE(response_info.server_data_unavailable); 1082 EXPECT_FALSE(response_info.server_data_unavailable);
1079 EXPECT_FALSE(response_info.network_accessed); 1083 EXPECT_FALSE(response_info.network_accessed);
1084 EXPECT_EQ(CacheEntryStatus::ENTRY_USED, response_info.cache_entry_status);
1080 } 1085 }
1081 1086
1082 TEST(HttpCache, SimpleGET_LoadBypassCache) { 1087 TEST(HttpCache, SimpleGET_LoadBypassCache) {
1083 MockHttpCache cache; 1088 MockHttpCache cache;
1084 1089
1085 // Write to the cache. 1090 // Write to the cache.
1086 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1091 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1087 1092
1088 // Force this transaction to write to the cache again. 1093 // Force this transaction to write to the cache again.
1089 MockTransaction transaction(kSimpleGET_Transaction); 1094 MockTransaction transaction(kSimpleGET_Transaction);
(...skipping 6908 matching lines...) Expand 10 before | Expand all | Expand 10 after
7998 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 8003 EXPECT_EQ(2, cache.network_layer()->transaction_count());
7999 EXPECT_EQ(1, cache.disk_cache()->open_count()); 8004 EXPECT_EQ(1, cache.disk_cache()->open_count());
8000 EXPECT_EQ(1, cache.disk_cache()->create_count()); 8005 EXPECT_EQ(1, cache.disk_cache()->create_count());
8001 EXPECT_TRUE(response_info.was_cached); 8006 EXPECT_TRUE(response_info.was_cached);
8002 8007
8003 // The new SSL state is reported. 8008 // The new SSL state is reported.
8004 EXPECT_EQ(status2, response_info.ssl_info.connection_status); 8009 EXPECT_EQ(status2, response_info.ssl_info.connection_status);
8005 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); 8010 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get()));
8006 } 8011 }
8007 8012
8013 TEST(HttpCache, CacheEntryStatusOther) {
8014 MockHttpCache cache;
8015
8016 HttpResponseInfo response_info;
8017 RunTransactionTestWithResponseInfo(cache.http_cache(), kRangeGET_Transaction,
8018 &response_info);
8019
8020 EXPECT_FALSE(response_info.was_cached);
8021 EXPECT_TRUE(response_info.network_accessed);
8022 EXPECT_EQ(CacheEntryStatus::ENTRY_OTHER, response_info.cache_entry_status);
8023 }
8024
8025 TEST(HttpCache, CacheEntryStatusNotInCache) {
8026 MockHttpCache cache;
8027
8028 HttpResponseInfo response_info;
8029 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
8030 &response_info);
8031
8032 EXPECT_FALSE(response_info.was_cached);
8033 EXPECT_TRUE(response_info.network_accessed);
8034 EXPECT_EQ(CacheEntryStatus::ENTRY_NOT_IN_CACHE,
8035 response_info.cache_entry_status);
8036 }
8037
8038 TEST(HttpCache, CacheEntryStatusUsed) {
8039 MockHttpCache cache;
8040 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
8041
8042 HttpResponseInfo response_info;
8043 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
8044 &response_info);
8045
8046 EXPECT_TRUE(response_info.was_cached);
8047 EXPECT_FALSE(response_info.network_accessed);
8048 EXPECT_EQ(CacheEntryStatus::ENTRY_USED, response_info.cache_entry_status);
8049 }
8050
8051 TEST(HttpCache, CacheEntryStatusValidated) {
8052 MockHttpCache cache;
8053 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
8054
8055 ScopedMockTransaction still_valid(kETagGET_Transaction);
8056 still_valid.load_flags = LOAD_VALIDATE_CACHE; // Force a validation.
8057 still_valid.handler = ETagGet_ConditionalRequest_Handler;
8058
8059 HttpResponseInfo response_info;
8060 RunTransactionTestWithResponseInfo(cache.http_cache(), still_valid,
8061 &response_info);
8062
8063 EXPECT_TRUE(response_info.was_cached);
8064 EXPECT_TRUE(response_info.network_accessed);
8065 EXPECT_EQ(CacheEntryStatus::ENTRY_VALIDATED,
8066 response_info.cache_entry_status);
8067 }
8068
8069 TEST(HttpCache, CacheEntryStatusUpdated) {
8070 MockHttpCache cache;
8071 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
8072
8073 ScopedMockTransaction update(kETagGET_Transaction);
8074 update.load_flags = LOAD_VALIDATE_CACHE; // Force a validation.
8075
8076 HttpResponseInfo response_info;
8077 RunTransactionTestWithResponseInfo(cache.http_cache(), update,
8078 &response_info);
8079
8080 EXPECT_FALSE(response_info.was_cached);
8081 EXPECT_TRUE(response_info.network_accessed);
8082 EXPECT_EQ(CacheEntryStatus::ENTRY_UPDATED, response_info.cache_entry_status);
8083 }
8084
8085 TEST(HttpCache, CacheEntryStatusCantConditionalize) {
8086 MockHttpCache cache;
8087 cache.FailConditionalizations();
8088 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction);
8089
8090 HttpResponseInfo response_info;
8091 RunTransactionTestWithResponseInfo(cache.http_cache(),
8092 kTypicalGET_Transaction, &response_info);
8093
8094 EXPECT_FALSE(response_info.was_cached);
8095 EXPECT_TRUE(response_info.network_accessed);
8096 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8097 response_info.cache_entry_status);
8098 }
8099
8008 } // namespace net 8100 } // namespace net
OLDNEW
« 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