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_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
17 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 17 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
20 #include "components/history/core/browser/history_types.h" | 20 #include "components/history/core/browser/history_types.h" |
21 #include "components/sessions/core/session_id.h" | 21 #include "components/sessions/core/session_id.h" |
22 #include "content/public/browser/resource_request_info.h" | 22 #include "content/public/browser/resource_request_info.h" |
| 23 #include "content/public/common/previews_state.h" |
23 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
25 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
26 #include "net/url_request/url_request_job.h" | 27 #include "net/url_request/url_request_job.h" |
27 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 | 31 |
31 using testing::ContainerEq; | 32 using testing::ContainerEq; |
32 using testing::Pointee; | 33 using testing::Pointee; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 const GURL& url, | 204 const GURL& url, |
204 net::RequestPriority priority, | 205 net::RequestPriority priority, |
205 content::ResourceType resource_type, | 206 content::ResourceType resource_type, |
206 bool is_main_frame) { | 207 bool is_main_frame) { |
207 std::unique_ptr<net::URLRequest> request = | 208 std::unique_ptr<net::URLRequest> request = |
208 url_request_context_.CreateRequest(url, priority, | 209 url_request_context_.CreateRequest(url, priority, |
209 &url_request_delegate_); | 210 &url_request_delegate_); |
210 request->set_first_party_for_cookies(url); | 211 request->set_first_party_for_cookies(url); |
211 content::ResourceRequestInfo::AllocateForTesting( | 212 content::ResourceRequestInfo::AllocateForTesting( |
212 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false, | 213 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false, |
213 false, true, false); | 214 false, true, content::PREVIEWS_OFF); |
214 request->Start(); | 215 request->Start(); |
215 return request; | 216 return request; |
216 } | 217 } |
217 | 218 |
218 void InitializePredictor() { | 219 void InitializePredictor() { |
219 predictor_->StartInitialization(); | 220 predictor_->StartInitialization(); |
220 base::RunLoop loop; | 221 base::RunLoop loop; |
221 loop.RunUntilIdle(); // Runs the DB lookup. | 222 loop.RunUntilIdle(); // Runs the DB lookup. |
222 profile_->BlockUntilHistoryProcessesPendingRequests(); | 223 profile_->BlockUntilHistoryProcessesPendingRequests(); |
223 } | 224 } |
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 net::MEDIUM, false, false); | 1547 net::MEDIUM, false, false); |
1547 predictor_->url_table_cache_->insert( | 1548 predictor_->url_table_cache_->insert( |
1548 std::make_pair(www_google_url.primary_key(), www_google_url)); | 1549 std::make_pair(www_google_url.primary_key(), www_google_url)); |
1549 | 1550 |
1550 urls.clear(); | 1551 urls.clear(); |
1551 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); | 1552 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); |
1552 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); | 1553 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); |
1553 } | 1554 } |
1554 | 1555 |
1555 } // namespace predictors | 1556 } // namespace predictors |
OLD | NEW |