Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <string> | |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | |
| 15 #include "chrome/browser/predictors/resource_prefetcher_manager.h" | 17 #include "chrome/browser/predictors/resource_prefetcher_manager.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 18 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 19 #include "net/url_request/redirect_info.h" | 21 #include "net/url_request/redirect_info.h" |
| 20 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 21 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 io_thread_(content::BrowserThread::IO, &loop_), | 145 io_thread_(content::BrowserThread::IO, &loop_), |
| 144 prefetcher_delegate_(&loop_) { | 146 prefetcher_delegate_(&loop_) { |
| 145 config_.max_prefetches_inflight_per_navigation = 5; | 147 config_.max_prefetches_inflight_per_navigation = 5; |
| 146 config_.max_prefetches_inflight_per_host_per_navigation = 2; | 148 config_.max_prefetches_inflight_per_host_per_navigation = 2; |
| 147 } | 149 } |
| 148 | 150 |
| 149 ResourcePrefetcherTest::~ResourcePrefetcherTest() { | 151 ResourcePrefetcherTest::~ResourcePrefetcherTest() { |
| 150 } | 152 } |
| 151 | 153 |
| 152 TEST_F(ResourcePrefetcherTest, TestPrefetcherFinishes) { | 154 TEST_F(ResourcePrefetcherTest, TestPrefetcherFinishes) { |
| 153 GURL main_frame_url("http://www.google.com"); | 155 std::string main_frame_url_string("http://www.google.com"); |
| 156 GURL main_frame_url(main_frame_url_string); | |
|
Benoit L
2016/12/06 14:58:18
nit: You can use main_frame_url.spec() to avoid ad
ahemery
2016/12/06 15:17:38
Simplified
| |
| 154 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), | 157 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), |
| 155 GURL("http://www.google.com/resource2.png"), | 158 GURL("http://www.google.com/resource2.png"), |
| 156 GURL("http://yahoo.com/resource1.png"), | 159 GURL("http://yahoo.com/resource1.png"), |
| 157 GURL("http://yahoo.com/resource2.png"), | 160 GURL("http://yahoo.com/resource2.png"), |
| 158 GURL("http://yahoo.com/resource3.png"), | 161 GURL("http://yahoo.com/resource3.png"), |
| 159 GURL("http://m.google.com/resource1.jpg"), | 162 GURL("http://m.google.com/resource1.jpg"), |
| 160 GURL("http://www.google.com/resource3.html"), | 163 GURL("http://www.google.com/resource3.html"), |
| 161 GURL("http://m.google.com/resource2.html"), | 164 GURL("http://m.google.com/resource2.html"), |
| 162 GURL("http://m.google.com/resource3.css"), | 165 GURL("http://m.google.com/resource3.css"), |
| 163 GURL("http://m.google.com/resource4.png"), | 166 GURL("http://m.google.com/resource4.png"), |
| 164 GURL("http://yahoo.com/resource4.png"), | 167 GURL("http://yahoo.com/resource4.png"), |
| 165 GURL("http://yahoo.com/resource5.png")}; | 168 GURL("http://yahoo.com/resource5.png")}; |
| 166 | 169 |
| 167 NavigationID navigation_id(1, 2, main_frame_url); | 170 NavigationID navigation_id = CreateNavigationID(1, 2, main_frame_url_string); |
| 168 | 171 |
| 169 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, | 172 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, |
| 170 main_frame_url, urls)); | 173 main_frame_url, urls)); |
| 171 | 174 |
| 172 // Starting the prefetcher maxes out the number of possible requests. | 175 // Starting the prefetcher maxes out the number of possible requests. |
| 173 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); | 176 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); |
| 174 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); | 177 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); |
| 175 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); | 178 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); |
| 176 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); | 179 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); |
| 177 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); | 180 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 224 |
| 222 // Expect the final call. | 225 // Expect the final call. |
| 223 EXPECT_CALL(prefetcher_delegate_, | 226 EXPECT_CALL(prefetcher_delegate_, |
| 224 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); | 227 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); |
| 225 | 228 |
| 226 OnResponse("http://yahoo.com/resource3.png"); | 229 OnResponse("http://yahoo.com/resource3.png"); |
| 227 CheckPrefetcherState(0, 0, 0); | 230 CheckPrefetcherState(0, 0, 0); |
| 228 } | 231 } |
| 229 | 232 |
| 230 TEST_F(ResourcePrefetcherTest, TestPrefetcherStopped) { | 233 TEST_F(ResourcePrefetcherTest, TestPrefetcherStopped) { |
| 231 GURL main_frame_url("http://www.google.com"); | 234 std::string main_frame_url_string("http://www.google.com"); |
|
Benoit L
2016/12/06 14:58:18
nit: ditto.
| |
| 235 GURL main_frame_url(main_frame_url_string); | |
| 232 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), | 236 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), |
| 233 GURL("http://www.google.com/resource2.png"), | 237 GURL("http://www.google.com/resource2.png"), |
| 234 GURL("http://yahoo.com/resource1.png"), | 238 GURL("http://yahoo.com/resource1.png"), |
| 235 GURL("http://yahoo.com/resource2.png"), | 239 GURL("http://yahoo.com/resource2.png"), |
| 236 GURL("http://yahoo.com/resource3.png"), | 240 GURL("http://yahoo.com/resource3.png"), |
| 237 GURL("http://m.google.com/resource1.jpg")}; | 241 GURL("http://m.google.com/resource1.jpg")}; |
| 238 | 242 |
| 239 NavigationID navigation_id(1, 2, main_frame_url); | 243 NavigationID navigation_id = CreateNavigationID(1, 2, main_frame_url_string); |
| 240 | 244 |
| 241 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, | 245 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, |
| 242 main_frame_url, urls)); | 246 main_frame_url, urls)); |
| 243 | 247 |
| 244 // Starting the prefetcher maxes out the number of possible requests. | 248 // Starting the prefetcher maxes out the number of possible requests. |
| 245 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); | 249 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); |
| 246 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); | 250 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); |
| 247 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); | 251 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); |
| 248 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); | 252 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); |
| 249 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); | 253 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 267 | 271 |
| 268 // Expect the final call. | 272 // Expect the final call. |
| 269 EXPECT_CALL(prefetcher_delegate_, | 273 EXPECT_CALL(prefetcher_delegate_, |
| 270 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); | 274 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); |
| 271 | 275 |
| 272 OnResponse("http://m.google.com/resource1.jpg"); | 276 OnResponse("http://m.google.com/resource1.jpg"); |
| 273 CheckPrefetcherState(0, 1, 0); | 277 CheckPrefetcherState(0, 1, 0); |
| 274 } | 278 } |
| 275 | 279 |
| 276 } // namespace predictors | 280 } // namespace predictors |
| OLD | NEW |