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

Side by Side Diff: chrome/browser/predictors/resource_prefetcher_unittest.cc

Issue 2373443002: predictors: Key the resource prefetcher by URL, not navigation. (Closed)
Patch Set: Created 4 years, 2 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 | « chrome/browser/predictors/resource_prefetcher_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetcher.h" 5 #include "chrome/browser/predictors/resource_prefetcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 15 matching lines...) Expand all
26 using testing::Property; 26 using testing::Property;
27 27
28 namespace predictors { 28 namespace predictors {
29 29
30 // Wrapper over the ResourcePrefetcher that stubs out the StartURLRequest call 30 // Wrapper over the ResourcePrefetcher that stubs out the StartURLRequest call
31 // since we do not want to do network fetches in this unittest. 31 // since we do not want to do network fetches in this unittest.
32 class TestResourcePrefetcher : public ResourcePrefetcher { 32 class TestResourcePrefetcher : public ResourcePrefetcher {
33 public: 33 public:
34 TestResourcePrefetcher(ResourcePrefetcher::Delegate* delegate, 34 TestResourcePrefetcher(ResourcePrefetcher::Delegate* delegate,
35 const ResourcePrefetchPredictorConfig& config, 35 const ResourcePrefetchPredictorConfig& config,
36 const NavigationID& navigation_id, 36 const GURL& main_frame_url,
37 PrefetchKeyType key_type,
38 const std::vector<GURL>& urls) 37 const std::vector<GURL>& urls)
39 : ResourcePrefetcher(delegate, config, navigation_id, key_type, urls) {} 38 : ResourcePrefetcher(delegate, config, main_frame_url, urls) {}
40 39
41 ~TestResourcePrefetcher() override {} 40 ~TestResourcePrefetcher() override {}
42 41
43 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); 42 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request));
44 43
45 void ReadFullResponse(net::URLRequest* request) override { 44 void ReadFullResponse(net::URLRequest* request) override {
46 EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH); 45 EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH);
47 FinishRequest(request); 46 FinishRequest(request);
48 } 47 }
49 48
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 io_thread_(content::BrowserThread::IO, &loop_), 143 io_thread_(content::BrowserThread::IO, &loop_),
145 prefetcher_delegate_(&loop_) { 144 prefetcher_delegate_(&loop_) {
146 config_.max_prefetches_inflight_per_navigation = 5; 145 config_.max_prefetches_inflight_per_navigation = 5;
147 config_.max_prefetches_inflight_per_host_per_navigation = 2; 146 config_.max_prefetches_inflight_per_host_per_navigation = 2;
148 } 147 }
149 148
150 ResourcePrefetcherTest::~ResourcePrefetcherTest() { 149 ResourcePrefetcherTest::~ResourcePrefetcherTest() {
151 } 150 }
152 151
153 TEST_F(ResourcePrefetcherTest, TestPrefetcherFinishes) { 152 TEST_F(ResourcePrefetcherTest, TestPrefetcherFinishes) {
153 GURL main_frame_url("http://www.google.com");
154 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), 154 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"),
155 GURL("http://www.google.com/resource2.png"), 155 GURL("http://www.google.com/resource2.png"),
156 GURL("http://yahoo.com/resource1.png"), 156 GURL("http://yahoo.com/resource1.png"),
157 GURL("http://yahoo.com/resource2.png"), 157 GURL("http://yahoo.com/resource2.png"),
158 GURL("http://yahoo.com/resource3.png"), 158 GURL("http://yahoo.com/resource3.png"),
159 GURL("http://m.google.com/resource1.jpg"), 159 GURL("http://m.google.com/resource1.jpg"),
160 GURL("http://www.google.com/resource3.html"), 160 GURL("http://www.google.com/resource3.html"),
161 GURL("http://m.google.com/resource2.html"), 161 GURL("http://m.google.com/resource2.html"),
162 GURL("http://m.google.com/resource3.css"), 162 GURL("http://m.google.com/resource3.css"),
163 GURL("http://m.google.com/resource4.png"), 163 GURL("http://m.google.com/resource4.png"),
164 GURL("http://yahoo.com/resource4.png"), 164 GURL("http://yahoo.com/resource4.png"),
165 GURL("http://yahoo.com/resource5.png")}; 165 GURL("http://yahoo.com/resource5.png")};
166 166
167 NavigationID navigation_id(1, 2, GURL("http://www.google.com")); 167 NavigationID navigation_id(1, 2, main_frame_url);
168 168
169 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, 169 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_,
170 navigation_id, 170 main_frame_url, urls));
171 PREFETCH_KEY_TYPE_URL, urls));
172 171
173 // Starting the prefetcher maxes out the number of possible requests. 172 // Starting the prefetcher maxes out the number of possible requests.
174 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); 173 AddStartUrlRequestExpectation("http://www.google.com/resource1.html");
175 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); 174 AddStartUrlRequestExpectation("http://www.google.com/resource2.png");
176 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); 175 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png");
177 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); 176 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png");
178 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); 177 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg");
179 178
180 prefetcher_->Start(); 179 prefetcher_->Start();
181 CheckPrefetcherState(5, 7, 3); 180 CheckPrefetcherState(5, 7, 3);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 221
223 // Expect the final call. 222 // Expect the final call.
224 EXPECT_CALL(prefetcher_delegate_, 223 EXPECT_CALL(prefetcher_delegate_,
225 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); 224 ResourcePrefetcherFinished(Eq(prefetcher_.get())));
226 225
227 OnResponse("http://yahoo.com/resource3.png"); 226 OnResponse("http://yahoo.com/resource3.png");
228 CheckPrefetcherState(0, 0, 0); 227 CheckPrefetcherState(0, 0, 0);
229 } 228 }
230 229
231 TEST_F(ResourcePrefetcherTest, TestPrefetcherStopped) { 230 TEST_F(ResourcePrefetcherTest, TestPrefetcherStopped) {
231 GURL main_frame_url("http://www.google.com");
232 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), 232 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"),
233 GURL("http://www.google.com/resource2.png"), 233 GURL("http://www.google.com/resource2.png"),
234 GURL("http://yahoo.com/resource1.png"), 234 GURL("http://yahoo.com/resource1.png"),
235 GURL("http://yahoo.com/resource2.png"), 235 GURL("http://yahoo.com/resource2.png"),
236 GURL("http://yahoo.com/resource3.png"), 236 GURL("http://yahoo.com/resource3.png"),
237 GURL("http://m.google.com/resource1.jpg")}; 237 GURL("http://m.google.com/resource1.jpg")};
238 238
239 NavigationID navigation_id(1, 2, GURL("http://www.google.com")); 239 NavigationID navigation_id(1, 2, main_frame_url);
240 240
241 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, 241 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_,
242 navigation_id, 242 main_frame_url, urls));
243 PREFETCH_KEY_TYPE_HOST, urls));
244 243
245 // Starting the prefetcher maxes out the number of possible requests. 244 // Starting the prefetcher maxes out the number of possible requests.
246 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); 245 AddStartUrlRequestExpectation("http://www.google.com/resource1.html");
247 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); 246 AddStartUrlRequestExpectation("http://www.google.com/resource2.png");
248 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); 247 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png");
249 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); 248 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png");
250 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); 249 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg");
251 250
252 prefetcher_->Start(); 251 prefetcher_->Start();
253 CheckPrefetcherState(5, 1, 3); 252 CheckPrefetcherState(5, 1, 3);
(...skipping 14 matching lines...) Expand all
268 267
269 // Expect the final call. 268 // Expect the final call.
270 EXPECT_CALL(prefetcher_delegate_, 269 EXPECT_CALL(prefetcher_delegate_,
271 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); 270 ResourcePrefetcherFinished(Eq(prefetcher_.get())));
272 271
273 OnResponse("http://m.google.com/resource1.jpg"); 272 OnResponse("http://m.google.com/resource1.jpg");
274 CheckPrefetcherState(0, 1, 0); 273 CheckPrefetcherState(0, 1, 0);
275 } 274 }
276 275
277 } // namespace predictors 276 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698