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

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

Issue 2668563002: Change MockHttpCache constructor to take boolean to set quic server info factory (Closed)
Patch Set: Created 3 years, 10 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 <string> 5 #include <string>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 EXPECT_THAT(rv, IsOk()); 77 EXPECT_THAT(rv, IsOk());
78 std::string expected(mock_trans->data); 78 std::string expected(mock_trans->data);
79 EXPECT_EQ(expected, content); 79 EXPECT_EQ(expected, content);
80 RemoveMockTransaction(mock_trans.get()); 80 RemoveMockTransaction(mock_trans.get());
81 } 81 }
82 82
83 } // namespace 83 } // namespace
84 84
85 TEST(HttpCacheLookupManagerTest, ServerPushMissCache) { 85 TEST(HttpCacheLookupManagerTest, ServerPushMissCache) {
86 MockHttpCache mock_cache; 86 MockHttpCache mock_cache(false);
Ryan Hamilton 2017/01/31 01:32:26 You might also consider keeping the old no-arg con
Zhongyi Shi 2017/02/02 01:05:12 Done.
87 HttpCacheLookupManager push_delegate(mock_cache.http_cache(), 87 HttpCacheLookupManager push_delegate(mock_cache.http_cache(),
88 NetLogWithSource()); 88 NetLogWithSource());
89 GURL request_url("http://www.example.com/pushed.jpg"); 89 GURL request_url("http://www.example.com/pushed.jpg");
90 90
91 std::unique_ptr<MockServerPushHelper> push_helper = 91 std::unique_ptr<MockServerPushHelper> push_helper =
92 base::MakeUnique<MockServerPushHelper>(request_url); 92 base::MakeUnique<MockServerPushHelper>(request_url);
93 MockServerPushHelper* push_helper_ptr = push_helper.get(); 93 MockServerPushHelper* push_helper_ptr = push_helper.get();
94 94
95 // Receive a server push and should not cancel the push. 95 // Receive a server push and should not cancel the push.
96 EXPECT_CALL(*push_helper_ptr, Cancel()).Times(0); 96 EXPECT_CALL(*push_helper_ptr, Cancel()).Times(0);
97 push_delegate.OnPush(std::move(push_helper)); 97 push_delegate.OnPush(std::move(push_helper));
98 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
99 99
100 // Make sure no network transaction is created. 100 // Make sure no network transaction is created.
101 EXPECT_EQ(0, mock_cache.network_layer()->transaction_count()); 101 EXPECT_EQ(0, mock_cache.network_layer()->transaction_count());
102 EXPECT_EQ(0, mock_cache.disk_cache()->open_count()); 102 EXPECT_EQ(0, mock_cache.disk_cache()->open_count());
103 EXPECT_EQ(0, mock_cache.disk_cache()->create_count()); 103 EXPECT_EQ(0, mock_cache.disk_cache()->create_count());
104 } 104 }
105 105
106 TEST(HttpCacheLookupManagerTest, ServerPushDoNotCreateCacheEntry) { 106 TEST(HttpCacheLookupManagerTest, ServerPushDoNotCreateCacheEntry) {
107 MockHttpCache mock_cache; 107 MockHttpCache mock_cache(false);
108 HttpCacheLookupManager push_delegate(mock_cache.http_cache(), 108 HttpCacheLookupManager push_delegate(mock_cache.http_cache(),
109 NetLogWithSource()); 109 NetLogWithSource());
110 GURL request_url("http://www.example.com/pushed.jpg"); 110 GURL request_url("http://www.example.com/pushed.jpg");
111 111
112 std::unique_ptr<MockServerPushHelper> push_helper = 112 std::unique_ptr<MockServerPushHelper> push_helper =
113 base::MakeUnique<MockServerPushHelper>(request_url); 113 base::MakeUnique<MockServerPushHelper>(request_url);
114 MockServerPushHelper* push_helper_ptr = push_helper.get(); 114 MockServerPushHelper* push_helper_ptr = push_helper.get();
115 115
116 // Receive a server push and should not cancel the push. 116 // Receive a server push and should not cancel the push.
117 EXPECT_CALL(*push_helper_ptr, Cancel()).Times(0); 117 EXPECT_CALL(*push_helper_ptr, Cancel()).Times(0);
118 push_delegate.OnPush(std::move(push_helper)); 118 push_delegate.OnPush(std::move(push_helper));
119 base::RunLoop().RunUntilIdle(); 119 base::RunLoop().RunUntilIdle();
120 120
121 // Receive another server push for the same url. 121 // Receive another server push for the same url.
122 std::unique_ptr<MockServerPushHelper> push_helper2 = 122 std::unique_ptr<MockServerPushHelper> push_helper2 =
123 base::MakeUnique<MockServerPushHelper>(request_url); 123 base::MakeUnique<MockServerPushHelper>(request_url);
124 MockServerPushHelper* push_helper_ptr2 = push_helper2.get(); 124 MockServerPushHelper* push_helper_ptr2 = push_helper2.get();
125 EXPECT_CALL(*push_helper_ptr2, Cancel()).Times(0); 125 EXPECT_CALL(*push_helper_ptr2, Cancel()).Times(0);
126 push_delegate.OnPush(std::move(push_helper2)); 126 push_delegate.OnPush(std::move(push_helper2));
127 base::RunLoop().RunUntilIdle(); 127 base::RunLoop().RunUntilIdle();
128 128
129 // Verify no network transaction is created. 129 // Verify no network transaction is created.
130 EXPECT_EQ(0, mock_cache.network_layer()->transaction_count()); 130 EXPECT_EQ(0, mock_cache.network_layer()->transaction_count());
131 EXPECT_EQ(0, mock_cache.disk_cache()->open_count()); 131 EXPECT_EQ(0, mock_cache.disk_cache()->open_count());
132 // Verify no cache entry is created for server push lookup. 132 // Verify no cache entry is created for server push lookup.
133 EXPECT_EQ(0, mock_cache.disk_cache()->create_count()); 133 EXPECT_EQ(0, mock_cache.disk_cache()->create_count());
134 } 134 }
135 135
136 TEST(HttpCacheLookupManagerTest, ServerPushHitCache) { 136 TEST(HttpCacheLookupManagerTest, ServerPushHitCache) {
137 MockHttpCache mock_cache; 137 MockHttpCache mock_cache(false);
138 HttpCacheLookupManager push_delegate(mock_cache.http_cache(), 138 HttpCacheLookupManager push_delegate(mock_cache.http_cache(),
139 NetLogWithSource()); 139 NetLogWithSource());
140 GURL request_url("http://www.example.com/pushed.jpg"); 140 GURL request_url("http://www.example.com/pushed.jpg");
141 141
142 // Populate the cache entry so that the cache lookup for server push hits. 142 // Populate the cache entry so that the cache lookup for server push hits.
143 PopulateCacheEntry(mock_cache.http_cache(), request_url); 143 PopulateCacheEntry(mock_cache.http_cache(), request_url);
144 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count()); 144 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count());
145 EXPECT_EQ(0, mock_cache.disk_cache()->open_count()); 145 EXPECT_EQ(0, mock_cache.disk_cache()->open_count());
146 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 146 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
147 147
(...skipping 17 matching lines...) Expand all
165 EXPECT_EQ(1, mock_cache.disk_cache()->open_count()); 165 EXPECT_EQ(1, mock_cache.disk_cache()->open_count());
166 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 166 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
167 167
168 RemoveMockTransaction(mock_trans.get()); 168 RemoveMockTransaction(mock_trans.get());
169 } 169 }
170 170
171 // Test when a server push is received while the HttpCacheLookupManager has a 171 // Test when a server push is received while the HttpCacheLookupManager has a
172 // pending lookup transaction for the same URL, the new server push will not 172 // pending lookup transaction for the same URL, the new server push will not
173 // send a new lookup transaction and should not be canceled. 173 // send a new lookup transaction and should not be canceled.
174 TEST(HttpCacheLookupManagerTest, ServerPushPendingLookup) { 174 TEST(HttpCacheLookupManagerTest, ServerPushPendingLookup) {
175 MockHttpCache mock_cache; 175 MockHttpCache mock_cache(false);
176 HttpCacheLookupManager push_delegate(mock_cache.http_cache(), 176 HttpCacheLookupManager push_delegate(mock_cache.http_cache(),
177 NetLogWithSource()); 177 NetLogWithSource());
178 GURL request_url("http://www.example.com/pushed.jpg"); 178 GURL request_url("http://www.example.com/pushed.jpg");
179 179
180 // Populate the cache entry so that the cache lookup for server push hits. 180 // Populate the cache entry so that the cache lookup for server push hits.
181 PopulateCacheEntry(mock_cache.http_cache(), request_url); 181 PopulateCacheEntry(mock_cache.http_cache(), request_url);
182 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count()); 182 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count());
183 EXPECT_EQ(0, mock_cache.disk_cache()->open_count()); 183 EXPECT_EQ(0, mock_cache.disk_cache()->open_count());
184 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 184 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
185 185
(...skipping 24 matching lines...) Expand all
210 // Make sure no new net layer transaction is created. 210 // Make sure no new net layer transaction is created.
211 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count()); 211 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count());
212 EXPECT_EQ(1, mock_cache.disk_cache()->open_count()); 212 EXPECT_EQ(1, mock_cache.disk_cache()->open_count());
213 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 213 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
214 214
215 RemoveMockTransaction(mock_trans.get()); 215 RemoveMockTransaction(mock_trans.get());
216 } 216 }
217 217
218 // Test the server push lookup is based on the full url. 218 // Test the server push lookup is based on the full url.
219 TEST(HttpCacheLookupManagerTest, ServerPushLookupOnUrl) { 219 TEST(HttpCacheLookupManagerTest, ServerPushLookupOnUrl) {
220 MockHttpCache mock_cache; 220 MockHttpCache mock_cache(false);
221 HttpCacheLookupManager push_delegate(mock_cache.http_cache(), 221 HttpCacheLookupManager push_delegate(mock_cache.http_cache(),
222 NetLogWithSource()); 222 NetLogWithSource());
223 GURL request_url("http://www.example.com/pushed.jpg?u=0"); 223 GURL request_url("http://www.example.com/pushed.jpg?u=0");
224 GURL request_url2("http://www.example.com/pushed.jpg?u=1"); 224 GURL request_url2("http://www.example.com/pushed.jpg?u=1");
225 225
226 // Populate the cache entry so that the cache lookup for server push hits. 226 // Populate the cache entry so that the cache lookup for server push hits.
227 PopulateCacheEntry(mock_cache.http_cache(), request_url); 227 PopulateCacheEntry(mock_cache.http_cache(), request_url);
228 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count()); 228 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count());
229 EXPECT_EQ(0, mock_cache.disk_cache()->open_count()); 229 EXPECT_EQ(0, mock_cache.disk_cache()->open_count());
230 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 230 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 base::RunLoop().RunUntilIdle(); 280 base::RunLoop().RunUntilIdle();
281 // Make sure no new net layer transaction is created. 281 // Make sure no new net layer transaction is created.
282 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count()); 282 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count());
283 EXPECT_EQ(2, mock_cache.disk_cache()->open_count()); 283 EXPECT_EQ(2, mock_cache.disk_cache()->open_count());
284 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 284 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
285 RemoveMockTransaction(mock_trans3.get()); 285 RemoveMockTransaction(mock_trans3.get());
286 } 286 }
287 287
288 } // namespace net 288 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698