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

Side by Side 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: A bit of cleanup and more doc 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 unified diff | Download patch
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::NOT_IN_CACHE, response_info.cache_entry_status);
1058 } 1061 }
1059 1062
1060 // Confirm if we have a fresh entry in cache, it isn't marked as 1063 // Confirm if we have a fresh entry in cache, it isn't marked as
1061 // network verified. 1064 // network verified.
1062 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) { 1065 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) {
1063 MockHttpCache cache; 1066 MockHttpCache cache;
1064 1067
1065 // Prime cache. 1068 // Prime cache.
1066 MockTransaction transaction(kSimpleGET_Transaction); 1069 MockTransaction transaction(kSimpleGET_Transaction);
1067 1070
1068 RunTransactionTest(cache.http_cache(), transaction); 1071 RunTransactionTest(cache.http_cache(), transaction);
1069 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1072 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1070 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1073 EXPECT_EQ(1, cache.disk_cache()->create_count());
1071 1074
1072 // Re-run transaction; make sure we don't mark the network as accessed. 1075 // Re-run transaction; make sure we don't mark the network as accessed.
1073 HttpResponseInfo response_info; 1076 HttpResponseInfo response_info;
1074 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, 1077 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
1075 &response_info); 1078 &response_info);
1076 1079
1077 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1080 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1078 EXPECT_FALSE(response_info.server_data_unavailable); 1081 EXPECT_FALSE(response_info.server_data_unavailable);
1079 EXPECT_FALSE(response_info.network_accessed); 1082 EXPECT_FALSE(response_info.network_accessed);
1083 EXPECT_EQ(CacheEntryStatus::USED, response_info.cache_entry_status);
1080 } 1084 }
1081 1085
1082 TEST(HttpCache, SimpleGET_LoadBypassCache) { 1086 TEST(HttpCache, SimpleGET_LoadBypassCache) {
1083 MockHttpCache cache; 1087 MockHttpCache cache;
1084 1088
1085 // Write to the cache. 1089 // Write to the cache.
1086 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1090 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1087 1091
1088 // Force this transaction to write to the cache again. 1092 // Force this transaction to write to the cache again.
1089 MockTransaction transaction(kSimpleGET_Transaction); 1093 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()); 8002 EXPECT_EQ(2, cache.network_layer()->transaction_count());
7999 EXPECT_EQ(1, cache.disk_cache()->open_count()); 8003 EXPECT_EQ(1, cache.disk_cache()->open_count());
8000 EXPECT_EQ(1, cache.disk_cache()->create_count()); 8004 EXPECT_EQ(1, cache.disk_cache()->create_count());
8001 EXPECT_TRUE(response_info.was_cached); 8005 EXPECT_TRUE(response_info.was_cached);
8002 8006
8003 // The new SSL state is reported. 8007 // The new SSL state is reported.
8004 EXPECT_EQ(status2, response_info.ssl_info.connection_status); 8008 EXPECT_EQ(status2, response_info.ssl_info.connection_status);
8005 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); 8009 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get()));
8006 } 8010 }
8007 8011
8012 TEST(HttpCache, CacheEntryStatusOther) {
8013 MockHttpCache cache;
8014
8015 HttpResponseInfo response_info;
8016 RunTransactionTestWithResponseInfo(cache.http_cache(), kRangeGET_Transaction,
8017 &response_info);
8018
8019 EXPECT_FALSE(response_info.was_cached);
8020 EXPECT_TRUE(response_info.network_accessed);
8021 EXPECT_EQ(CacheEntryStatus::OTHER, response_info.cache_entry_status);
8022 }
8023
8024 TEST(HttpCache, CacheEntryStatusNotInCache) {
8025 MockHttpCache cache;
8026
8027 HttpResponseInfo response_info;
8028 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
8029 &response_info);
8030
8031 EXPECT_FALSE(response_info.was_cached);
8032 EXPECT_TRUE(response_info.network_accessed);
8033 EXPECT_EQ(CacheEntryStatus::NOT_IN_CACHE, response_info.cache_entry_status);
8034 }
8035
8036 TEST(HttpCache, CacheEntryStatusUsed) {
8037 MockHttpCache cache;
8038 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
8039
8040 HttpResponseInfo response_info;
8041 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
8042 &response_info);
8043
8044 EXPECT_TRUE(response_info.was_cached);
8045 EXPECT_FALSE(response_info.network_accessed);
8046 EXPECT_EQ(CacheEntryStatus::USED, response_info.cache_entry_status);
8047 }
8048
8049 TEST(HttpCache, CacheEntryStatusValidated) {
8050 MockHttpCache cache;
8051 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
8052
8053 ScopedMockTransaction still_valid(kETagGET_Transaction);
8054 still_valid.load_flags = LOAD_VALIDATE_CACHE; // Force a validation.
8055 still_valid.handler = ETagGet_ConditionalRequest_Handler;
8056
8057 HttpResponseInfo response_info;
8058 RunTransactionTestWithResponseInfo(cache.http_cache(), still_valid,
8059 &response_info);
8060
8061 EXPECT_TRUE(response_info.was_cached);
8062 EXPECT_TRUE(response_info.network_accessed);
8063 EXPECT_EQ(CacheEntryStatus::VALIDATED, response_info.cache_entry_status);
8064 }
8065
8066 TEST(HttpCache, CacheEntryStatusUpdated) {
8067 MockHttpCache cache;
8068 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
8069
8070 ScopedMockTransaction update(kETagGET_Transaction);
8071 update.load_flags = LOAD_VALIDATE_CACHE; // Force a validation.
8072
8073 HttpResponseInfo response_info;
8074 RunTransactionTestWithResponseInfo(cache.http_cache(), update,
8075 &response_info);
8076
8077 EXPECT_FALSE(response_info.was_cached);
8078 EXPECT_TRUE(response_info.network_accessed);
8079 EXPECT_EQ(CacheEntryStatus::UPDATED, response_info.cache_entry_status);
8080 }
8081
8082 TEST(HttpCache, CacheEntryStatusCantConditionalize) {
8083 MockHttpCache cache;
8084 cache.FailConditionalizations();
8085 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction);
8086
8087 HttpResponseInfo response_info;
8088 RunTransactionTestWithResponseInfo(cache.http_cache(),
8089 kTypicalGET_Transaction, &response_info);
8090
8091 EXPECT_FALSE(response_info.was_cached);
8092 EXPECT_TRUE(response_info.network_accessed);
8093 EXPECT_EQ(CacheEntryStatus::CANT_CONDITIONALIZE,
8094 response_info.cache_entry_status);
8095 }
8096
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
8008 } // namespace net 8097 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698