| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 GURL("http://yahoo.com/resource2.png"), | 159 GURL("http://yahoo.com/resource2.png"), |
| 158 GURL("http://yahoo.com/resource3.png"), | 160 GURL("http://yahoo.com/resource3.png"), |
| 159 GURL("http://m.google.com/resource1.jpg"), | 161 GURL("http://m.google.com/resource1.jpg"), |
| 160 GURL("http://www.google.com/resource3.html"), | 162 GURL("http://www.google.com/resource3.html"), |
| 161 GURL("http://m.google.com/resource2.html"), | 163 GURL("http://m.google.com/resource2.html"), |
| 162 GURL("http://m.google.com/resource3.css"), | 164 GURL("http://m.google.com/resource3.css"), |
| 163 GURL("http://m.google.com/resource4.png"), | 165 GURL("http://m.google.com/resource4.png"), |
| 164 GURL("http://yahoo.com/resource4.png"), | 166 GURL("http://yahoo.com/resource4.png"), |
| 165 GURL("http://yahoo.com/resource5.png")}; | 167 GURL("http://yahoo.com/resource5.png")}; |
| 166 | 168 |
| 167 NavigationID navigation_id(1, 2, main_frame_url); | 169 NavigationID navigation_id = CreateNavigationID(1, 2, main_frame_url.spec()); |
| 168 | 170 |
| 169 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, | 171 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, |
| 170 main_frame_url, urls)); | 172 main_frame_url, urls)); |
| 171 | 173 |
| 172 // Starting the prefetcher maxes out the number of possible requests. | 174 // Starting the prefetcher maxes out the number of possible requests. |
| 173 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); | 175 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); |
| 174 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); | 176 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); |
| 175 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); | 177 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); |
| 176 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); | 178 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); |
| 177 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); | 179 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 231 |
| 230 TEST_F(ResourcePrefetcherTest, TestPrefetcherStopped) { | 232 TEST_F(ResourcePrefetcherTest, TestPrefetcherStopped) { |
| 231 GURL main_frame_url("http://www.google.com"); | 233 GURL main_frame_url("http://www.google.com"); |
| 232 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), | 234 std::vector<GURL> urls = {GURL("http://www.google.com/resource1.html"), |
| 233 GURL("http://www.google.com/resource2.png"), | 235 GURL("http://www.google.com/resource2.png"), |
| 234 GURL("http://yahoo.com/resource1.png"), | 236 GURL("http://yahoo.com/resource1.png"), |
| 235 GURL("http://yahoo.com/resource2.png"), | 237 GURL("http://yahoo.com/resource2.png"), |
| 236 GURL("http://yahoo.com/resource3.png"), | 238 GURL("http://yahoo.com/resource3.png"), |
| 237 GURL("http://m.google.com/resource1.jpg")}; | 239 GURL("http://m.google.com/resource1.jpg")}; |
| 238 | 240 |
| 239 NavigationID navigation_id(1, 2, main_frame_url); | 241 NavigationID navigation_id = CreateNavigationID(1, 2, main_frame_url.spec()); |
| 240 | 242 |
| 241 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, | 243 prefetcher_.reset(new TestResourcePrefetcher(&prefetcher_delegate_, config_, |
| 242 main_frame_url, urls)); | 244 main_frame_url, urls)); |
| 243 | 245 |
| 244 // Starting the prefetcher maxes out the number of possible requests. | 246 // Starting the prefetcher maxes out the number of possible requests. |
| 245 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); | 247 AddStartUrlRequestExpectation("http://www.google.com/resource1.html"); |
| 246 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); | 248 AddStartUrlRequestExpectation("http://www.google.com/resource2.png"); |
| 247 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); | 249 AddStartUrlRequestExpectation("http://yahoo.com/resource1.png"); |
| 248 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); | 250 AddStartUrlRequestExpectation("http://yahoo.com/resource2.png"); |
| 249 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); | 251 AddStartUrlRequestExpectation("http://m.google.com/resource1.jpg"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 267 | 269 |
| 268 // Expect the final call. | 270 // Expect the final call. |
| 269 EXPECT_CALL(prefetcher_delegate_, | 271 EXPECT_CALL(prefetcher_delegate_, |
| 270 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); | 272 ResourcePrefetcherFinished(Eq(prefetcher_.get()))); |
| 271 | 273 |
| 272 OnResponse("http://m.google.com/resource1.jpg"); | 274 OnResponse("http://m.google.com/resource1.jpg"); |
| 273 CheckPrefetcherState(0, 1, 0); | 275 CheckPrefetcherState(0, 1, 0); |
| 274 } | 276 } |
| 275 | 277 |
| 276 } // namespace predictors | 278 } // namespace predictors |
| OLD | NEW |