| 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/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
| 17 #include "chrome/browser/predictors/loading_predictor.h" | 17 #include "chrome/browser/predictors/loading_predictor.h" |
| 18 #include "chrome/browser/predictors/loading_test_util.h" |
| 18 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 19 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 19 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | |
| 20 #include "chrome/browser/predictors/resource_prefetcher_manager.h" | 20 #include "chrome/browser/predictors/resource_prefetcher_manager.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/history/core/browser/history_service.h" | 22 #include "components/history/core/browser/history_service.h" |
| 23 #include "components/history/core/browser/history_types.h" | 23 #include "components/history/core/browser/history_types.h" |
| 24 #include "components/sessions/core/session_id.h" | 24 #include "components/sessions/core/session_id.h" |
| 25 #include "content/public/browser/resource_request_info.h" | |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 28 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 27 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 29 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 30 #include "net/url_request/url_request_job.h" | 29 #include "net/url_request/url_request_job.h" |
| 31 #include "net/url_request/url_request_test_util.h" | |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 32 |
| 35 using testing::ContainerEq; | 33 using testing::ContainerEq; |
| 36 using testing::Pointee; | 34 using testing::Pointee; |
| 37 using testing::SetArgPointee; | 35 using testing::SetArgPointee; |
| 38 using testing::StrictMock; | 36 using testing::StrictMock; |
| 39 using testing::UnorderedElementsAre; | 37 using testing::UnorderedElementsAre; |
| 40 | 38 |
| 41 namespace predictors { | 39 namespace predictors { |
| 42 | 40 |
| 43 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 41 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
| 44 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 42 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
| 45 using PrefetchDataMap = std::map<std::string, PrefetchData>; | 43 using PrefetchDataMap = std::map<std::string, PrefetchData>; |
| 46 using RedirectDataMap = std::map<std::string, RedirectData>; | 44 using RedirectDataMap = std::map<std::string, RedirectData>; |
| 47 using OriginDataMap = std::map<std::string, OriginData>; | 45 using OriginDataMap = std::map<std::string, OriginData>; |
| 48 using ManifestDataMap = std::map<std::string, precache::PrecacheManifest>; | 46 using ManifestDataMap = std::map<std::string, precache::PrecacheManifest>; |
| 49 | 47 |
| 50 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( | |
| 51 const char* headers) { | |
| 52 return make_scoped_refptr(new net::HttpResponseHeaders( | |
| 53 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); | |
| 54 } | |
| 55 | |
| 56 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { | |
| 57 void OnResponseStarted(net::URLRequest* request, int net_error) override {} | |
| 58 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} | |
| 59 }; | |
| 60 | |
| 61 class MockURLRequestJob : public net::URLRequestJob { | |
| 62 public: | |
| 63 MockURLRequestJob(net::URLRequest* request, | |
| 64 const net::HttpResponseInfo& response_info, | |
| 65 const std::string& mime_type) | |
| 66 : net::URLRequestJob(request, nullptr), | |
| 67 response_info_(response_info), | |
| 68 mime_type_(mime_type) {} | |
| 69 | |
| 70 bool GetMimeType(std::string* mime_type) const override { | |
| 71 *mime_type = mime_type_; | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 protected: | |
| 76 void Start() override { NotifyHeadersComplete(); } | |
| 77 void GetResponseInfo(net::HttpResponseInfo* info) override { | |
| 78 *info = response_info_; | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 net::HttpResponseInfo response_info_; | |
| 83 std::string mime_type_; | |
| 84 }; | |
| 85 | |
| 86 class MockURLRequestJobFactory : public net::URLRequestJobFactory { | |
| 87 public: | |
| 88 MockURLRequestJobFactory() {} | |
| 89 ~MockURLRequestJobFactory() override {} | |
| 90 | |
| 91 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | |
| 92 const std::string& scheme, | |
| 93 net::URLRequest* request, | |
| 94 net::NetworkDelegate* network_delegate) const override { | |
| 95 return new MockURLRequestJob(request, response_info_, mime_type_); | |
| 96 } | |
| 97 | |
| 98 net::URLRequestJob* MaybeInterceptRedirect( | |
| 99 net::URLRequest* request, | |
| 100 net::NetworkDelegate* network_delegate, | |
| 101 const GURL& location) const override { | |
| 102 return nullptr; | |
| 103 } | |
| 104 | |
| 105 net::URLRequestJob* MaybeInterceptResponse( | |
| 106 net::URLRequest* request, | |
| 107 net::NetworkDelegate* network_delegate) const override { | |
| 108 return nullptr; | |
| 109 } | |
| 110 | |
| 111 bool IsHandledProtocol(const std::string& scheme) const override { | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 bool IsSafeRedirectTarget(const GURL& location) const override { | |
| 116 return true; | |
| 117 } | |
| 118 | |
| 119 void set_response_info(const net::HttpResponseInfo& response_info) { | |
| 120 response_info_ = response_info; | |
| 121 } | |
| 122 | |
| 123 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } | |
| 124 | |
| 125 private: | |
| 126 net::HttpResponseInfo response_info_; | |
| 127 std::string mime_type_; | |
| 128 }; | |
| 129 | |
| 130 template <typename T> | 48 template <typename T> |
| 131 class FakeGlowplugKeyValueTable : public GlowplugKeyValueTable<T> { | 49 class FakeGlowplugKeyValueTable : public GlowplugKeyValueTable<T> { |
| 132 public: | 50 public: |
| 133 FakeGlowplugKeyValueTable() : GlowplugKeyValueTable<T>("") {} | 51 FakeGlowplugKeyValueTable() : GlowplugKeyValueTable<T>("") {} |
| 134 void GetAllData(std::map<std::string, T>* data_map, | 52 void GetAllData(std::map<std::string, T>* data_map, |
| 135 sql::Connection* db) const override { | 53 sql::Connection* db) const override { |
| 136 *data_map = data_; | 54 *data_map = data_; |
| 137 } | 55 } |
| 138 void UpdateData(const std::string& key, | 56 void UpdateData(const std::string& key, |
| 139 const T& data, | 57 const T& data, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 FakeGlowplugKeyValueTable<RedirectData> url_redirect_table_; | 110 FakeGlowplugKeyValueTable<RedirectData> url_redirect_table_; |
| 193 FakeGlowplugKeyValueTable<PrefetchData> host_resource_table_; | 111 FakeGlowplugKeyValueTable<PrefetchData> host_resource_table_; |
| 194 FakeGlowplugKeyValueTable<RedirectData> host_redirect_table_; | 112 FakeGlowplugKeyValueTable<RedirectData> host_redirect_table_; |
| 195 FakeGlowplugKeyValueTable<precache::PrecacheManifest> manifest_table_; | 113 FakeGlowplugKeyValueTable<precache::PrecacheManifest> manifest_table_; |
| 196 FakeGlowplugKeyValueTable<OriginData> origin_table_; | 114 FakeGlowplugKeyValueTable<OriginData> origin_table_; |
| 197 | 115 |
| 198 protected: | 116 protected: |
| 199 ~MockResourcePrefetchPredictorTables() override = default; | 117 ~MockResourcePrefetchPredictorTables() override = default; |
| 200 }; | 118 }; |
| 201 | 119 |
| 202 class MockResourcePrefetchPredictorObserver : public TestObserver { | 120 class MockLoadingPredictorObserver : public TestObserver { |
| 203 public: | 121 public: |
| 204 explicit MockResourcePrefetchPredictorObserver( | 122 explicit MockLoadingPredictorObserver(ResourcePrefetchPredictor* predictor) |
| 205 ResourcePrefetchPredictor* predictor) | |
| 206 : TestObserver(predictor) {} | 123 : TestObserver(predictor) {} |
| 207 | 124 |
| 208 MOCK_METHOD2( | 125 MOCK_METHOD2( |
| 209 OnNavigationLearned, | 126 OnNavigationLearned, |
| 210 void(size_t url_visit_count, | 127 void(size_t url_visit_count, |
| 211 const ResourcePrefetchPredictor::PageRequestSummary& summary)); | 128 const ResourcePrefetchPredictor::PageRequestSummary& summary)); |
| 212 }; | 129 }; |
| 213 | 130 |
| 214 class ResourcePrefetchPredictorTest : public testing::Test { | 131 class ResourcePrefetchPredictorTest : public testing::Test { |
| 215 public: | 132 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 236 URLRequestSummary CreateRedirectRequestSummary( | 153 URLRequestSummary CreateRedirectRequestSummary( |
| 237 SessionID::id_type session_id, | 154 SessionID::id_type session_id, |
| 238 const std::string& main_frame_url, | 155 const std::string& main_frame_url, |
| 239 const std::string& redirect_url) { | 156 const std::string& redirect_url) { |
| 240 URLRequestSummary summary = | 157 URLRequestSummary summary = |
| 241 CreateURLRequestSummary(session_id, main_frame_url); | 158 CreateURLRequestSummary(session_id, main_frame_url); |
| 242 summary.redirect_url = GURL(redirect_url); | 159 summary.redirect_url = GURL(redirect_url); |
| 243 return summary; | 160 return summary; |
| 244 } | 161 } |
| 245 | 162 |
| 246 std::unique_ptr<net::URLRequest> CreateURLRequest( | |
| 247 const GURL& url, | |
| 248 net::RequestPriority priority, | |
| 249 content::ResourceType resource_type, | |
| 250 bool is_main_frame) { | |
| 251 std::unique_ptr<net::URLRequest> request = | |
| 252 url_request_context_.CreateRequest(url, priority, | |
| 253 &url_request_delegate_, | |
| 254 TRAFFIC_ANNOTATION_FOR_TESTS); | |
| 255 request->set_first_party_for_cookies(url); | |
| 256 content::ResourceRequestInfo::AllocateForTesting( | |
| 257 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false, | |
| 258 false, true, content::PREVIEWS_OFF); | |
| 259 request->Start(); | |
| 260 return request; | |
| 261 } | |
| 262 | |
| 263 void InitializePredictor() { | 163 void InitializePredictor() { |
| 264 loading_predictor_->StartInitialization(); | 164 loading_predictor_->StartInitialization(); |
| 265 base::RunLoop loop; | 165 base::RunLoop loop; |
| 266 loop.RunUntilIdle(); // Runs the DB lookup. | 166 loop.RunUntilIdle(); // Runs the DB lookup. |
| 267 profile_->BlockUntilHistoryProcessesPendingRequests(); | 167 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 268 } | 168 } |
| 269 | 169 |
| 270 void ResetPredictor(bool small_db = true) { | 170 void ResetPredictor(bool small_db = true) { |
| 271 LoadingPredictorConfig config; | 171 LoadingPredictorConfig config; |
| 272 PopulateTestConfig(&config, small_db); | 172 PopulateTestConfig(&config, small_db); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS)); | 223 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS)); |
| 324 // Initialize the predictor with empty data. | 224 // Initialize the predictor with empty data. |
| 325 ResetPredictor(); | 225 ResetPredictor(); |
| 326 EXPECT_EQ(predictor_->initialization_state_, | 226 EXPECT_EQ(predictor_->initialization_state_, |
| 327 ResourcePrefetchPredictor::NOT_INITIALIZED); | 227 ResourcePrefetchPredictor::NOT_INITIALIZED); |
| 328 InitializePredictor(); | 228 InitializePredictor(); |
| 329 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 229 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 330 EXPECT_EQ(predictor_->initialization_state_, | 230 EXPECT_EQ(predictor_->initialization_state_, |
| 331 ResourcePrefetchPredictor::INITIALIZED); | 231 ResourcePrefetchPredictor::INITIALIZED); |
| 332 | 232 |
| 233 url_request_job_factory_.Reset(); |
| 333 url_request_context_.set_job_factory(&url_request_job_factory_); | 234 url_request_context_.set_job_factory(&url_request_job_factory_); |
| 334 | 235 |
| 335 histogram_tester_.reset(new base::HistogramTester()); | 236 histogram_tester_.reset(new base::HistogramTester()); |
| 336 } | 237 } |
| 337 | 238 |
| 338 void ResourcePrefetchPredictorTest::TearDown() { | 239 void ResourcePrefetchPredictorTest::TearDown() { |
| 339 EXPECT_EQ(*predictor_->url_resource_data_->data_cache_, | 240 EXPECT_EQ(*predictor_->url_resource_data_->data_cache_, |
| 340 mock_tables_->url_resource_table_.data_); | 241 mock_tables_->url_resource_table_.data_); |
| 341 EXPECT_EQ(*predictor_->url_redirect_data_->data_cache_, | 242 EXPECT_EQ(*predictor_->url_redirect_data_->data_cache_, |
| 342 mock_tables_->url_redirect_table_.data_); | 243 mock_tables_->url_redirect_table_.data_); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 predictor_->RecordURLResponse(resource1); | 512 predictor_->RecordURLResponse(resource1); |
| 612 URLRequestSummary resource2 = CreateURLRequestSummary( | 513 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 613 1, "https://www.google.com", "https://google.com/script1.js", | 514 1, "https://www.google.com", "https://google.com/script1.js", |
| 614 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 515 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 615 predictor_->RecordURLResponse(resource2); | 516 predictor_->RecordURLResponse(resource2); |
| 616 URLRequestSummary resource3 = CreateURLRequestSummary( | 517 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 617 1, "https://www.google.com", "https://google.com/script2.js", | 518 1, "https://www.google.com", "https://google.com/script2.js", |
| 618 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 519 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 619 predictor_->RecordURLResponse(resource3); | 520 predictor_->RecordURLResponse(resource3); |
| 620 | 521 |
| 621 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_); | 522 StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_); |
| 622 EXPECT_CALL( | 523 EXPECT_CALL( |
| 623 mock_observer, | 524 mock_observer, |
| 624 OnNavigationLearned(kVisitCount, | 525 OnNavigationLearned(kVisitCount, |
| 625 CreatePageRequestSummary( | 526 CreatePageRequestSummary( |
| 626 "https://www.google.com", "http://www.google.com", | 527 "https://www.google.com", "http://www.google.com", |
| 627 {resource1, resource2, resource3}))); | 528 {resource1, resource2, resource3}))); |
| 628 | 529 |
| 629 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 530 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 630 profile_->BlockUntilHistoryProcessesPendingRequests(); | 531 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 631 | 532 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 611 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 711 redirected.redirect_url = GURL("http://dev.null.google.com/style.css"); | 612 redirected.redirect_url = GURL("http://dev.null.google.com/style.css"); |
| 712 | 613 |
| 713 predictor_->RecordURLRedirect(redirected); | 614 predictor_->RecordURLRedirect(redirected); |
| 714 redirected.is_no_store = true; | 615 redirected.is_no_store = true; |
| 715 redirected.request_url = redirected.redirect_url; | 616 redirected.request_url = redirected.redirect_url; |
| 716 redirected.redirect_url = GURL(); | 617 redirected.redirect_url = GURL(); |
| 717 | 618 |
| 718 predictor_->RecordURLResponse(redirected); | 619 predictor_->RecordURLResponse(redirected); |
| 719 | 620 |
| 720 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_); | 621 StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_); |
| 721 EXPECT_CALL(mock_observer, | 622 EXPECT_CALL(mock_observer, |
| 722 OnNavigationLearned( | 623 OnNavigationLearned( |
| 723 kVisitCount, CreatePageRequestSummary("http://www.google.com", | 624 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
| 724 "http://www.google.com", | 625 "http://www.google.com", |
| 725 resources))); | 626 resources))); |
| 726 | 627 |
| 727 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 628 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 728 profile_->BlockUntilHistoryProcessesPendingRequests(); | 629 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 729 | 630 |
| 730 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); | 631 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 1, "http://www.google.com", "http://google.com/style2.css", | 725 1, "http://www.google.com", "http://google.com/style2.css", |
| 825 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); | 726 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
| 826 predictor_->RecordURLResponse(resources.back()); | 727 predictor_->RecordURLResponse(resources.back()); |
| 827 auto no_store = CreateURLRequestSummary( | 728 auto no_store = CreateURLRequestSummary( |
| 828 1, "http://www.google.com", | 729 1, "http://www.google.com", |
| 829 "http://static.google.com/style2-no-store.css", | 730 "http://static.google.com/style2-no-store.css", |
| 830 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 731 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 831 no_store.is_no_store = true; | 732 no_store.is_no_store = true; |
| 832 predictor_->RecordURLResponse(no_store); | 733 predictor_->RecordURLResponse(no_store); |
| 833 | 734 |
| 834 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_); | 735 StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_); |
| 835 EXPECT_CALL(mock_observer, | 736 EXPECT_CALL(mock_observer, |
| 836 OnNavigationLearned( | 737 OnNavigationLearned( |
| 837 kVisitCount, CreatePageRequestSummary("http://www.google.com", | 738 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
| 838 "http://www.google.com", | 739 "http://www.google.com", |
| 839 resources))); | 740 resources))); |
| 840 | 741 |
| 841 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 742 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 842 profile_->BlockUntilHistoryProcessesPendingRequests(); | 743 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 843 | 744 |
| 844 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); | 745 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 | 827 |
| 927 URLRequestSummary resource1 = CreateURLRequestSummary( | 828 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 928 1, "http://www.nike.com", "http://nike.com/style1.css", | 829 1, "http://www.nike.com", "http://nike.com/style1.css", |
| 929 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 830 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 930 predictor_->RecordURLResponse(resource1); | 831 predictor_->RecordURLResponse(resource1); |
| 931 URLRequestSummary resource2 = CreateURLRequestSummary( | 832 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 932 1, "http://www.nike.com", "http://nike.com/image2.png", | 833 1, "http://www.nike.com", "http://nike.com/image2.png", |
| 933 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 834 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 934 predictor_->RecordURLResponse(resource2); | 835 predictor_->RecordURLResponse(resource2); |
| 935 | 836 |
| 936 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_); | 837 StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_); |
| 937 EXPECT_CALL(mock_observer, | 838 EXPECT_CALL(mock_observer, |
| 938 OnNavigationLearned( | 839 OnNavigationLearned( |
| 939 kVisitCount, CreatePageRequestSummary( | 840 kVisitCount, CreatePageRequestSummary( |
| 940 "http://www.nike.com", "http://www.nike.com", | 841 "http://www.nike.com", "http://www.nike.com", |
| 941 {resource1, resource2}))); | 842 {resource1, resource2}))); |
| 942 | 843 |
| 943 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 844 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 944 profile_->BlockUntilHistoryProcessesPendingRequests(); | 845 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 945 | 846 |
| 946 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); | 847 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 897 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 997 | 898 |
| 998 URLRequestSummary fb2 = CreateRedirectRequestSummary( | 899 URLRequestSummary fb2 = CreateRedirectRequestSummary( |
| 999 1, "http://fb.com/google", "http://facebook.com/google"); | 900 1, "http://fb.com/google", "http://facebook.com/google"); |
| 1000 predictor_->RecordURLRedirect(fb2); | 901 predictor_->RecordURLRedirect(fb2); |
| 1001 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 902 URLRequestSummary fb3 = CreateRedirectRequestSummary( |
| 1002 1, "http://facebook.com/google", "https://facebook.com/google"); | 903 1, "http://facebook.com/google", "https://facebook.com/google"); |
| 1003 predictor_->RecordURLRedirect(fb3); | 904 predictor_->RecordURLRedirect(fb3); |
| 1004 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); | 905 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); |
| 1005 | 906 |
| 1006 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_); | 907 StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_); |
| 1007 EXPECT_CALL( | 908 EXPECT_CALL( |
| 1008 mock_observer, | 909 mock_observer, |
| 1009 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( | 910 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( |
| 1010 "https://facebook.com/google", | 911 "https://facebook.com/google", |
| 1011 "http://fb.com/google", | 912 "http://fb.com/google", |
| 1012 std::vector<URLRequestSummary>()))); | 913 std::vector<URLRequestSummary>()))); |
| 1013 | 914 |
| 1014 predictor_->RecordMainFrameLoadComplete(fb_end); | 915 predictor_->RecordMainFrameLoadComplete(fb_end); |
| 1015 profile_->BlockUntilHistoryProcessesPendingRequests(); | 916 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 1016 | 917 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1046 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 947 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 1047 | 948 |
| 1048 URLRequestSummary fb2 = CreateRedirectRequestSummary( | 949 URLRequestSummary fb2 = CreateRedirectRequestSummary( |
| 1049 1, "http://fb.com/google", "http://facebook.com/google"); | 950 1, "http://fb.com/google", "http://facebook.com/google"); |
| 1050 predictor_->RecordURLRedirect(fb2); | 951 predictor_->RecordURLRedirect(fb2); |
| 1051 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 952 URLRequestSummary fb3 = CreateRedirectRequestSummary( |
| 1052 1, "http://facebook.com/google", "https://facebook.com/google"); | 953 1, "http://facebook.com/google", "https://facebook.com/google"); |
| 1053 predictor_->RecordURLRedirect(fb3); | 954 predictor_->RecordURLRedirect(fb3); |
| 1054 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); | 955 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); |
| 1055 | 956 |
| 1056 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_); | 957 StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_); |
| 1057 EXPECT_CALL( | 958 EXPECT_CALL( |
| 1058 mock_observer, | 959 mock_observer, |
| 1059 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( | 960 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( |
| 1060 "https://facebook.com/google", | 961 "https://facebook.com/google", |
| 1061 "http://fb.com/google", | 962 "http://fb.com/google", |
| 1062 std::vector<URLRequestSummary>()))); | 963 std::vector<URLRequestSummary>()))); |
| 1063 | 964 |
| 1064 predictor_->RecordMainFrameLoadComplete(fb_end); | 965 predictor_->RecordMainFrameLoadComplete(fb_end); |
| 1065 profile_->BlockUntilHistoryProcessesPendingRequests(); | 966 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 1066 | 967 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 predictor_->inflight_navigations_[main_frame1.navigation_id] | 1364 predictor_->inflight_navigations_[main_frame1.navigation_id] |
| 1464 ->subresource_requests[0]); | 1365 ->subresource_requests[0]); |
| 1465 EXPECT_EQ(resource2, | 1366 EXPECT_EQ(resource2, |
| 1466 predictor_->inflight_navigations_[main_frame1.navigation_id] | 1367 predictor_->inflight_navigations_[main_frame1.navigation_id] |
| 1467 ->subresource_requests[1]); | 1368 ->subresource_requests[1]); |
| 1468 EXPECT_EQ(resource3, | 1369 EXPECT_EQ(resource3, |
| 1469 predictor_->inflight_navigations_[main_frame1.navigation_id] | 1370 predictor_->inflight_navigations_[main_frame1.navigation_id] |
| 1470 ->subresource_requests[2]); | 1371 ->subresource_requests[2]); |
| 1471 } | 1372 } |
| 1472 | 1373 |
| 1473 TEST_F(ResourcePrefetchPredictorTest, HandledResourceTypes) { | |
| 1474 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1475 content::RESOURCE_TYPE_STYLESHEET, "bogus/mime-type")); | |
| 1476 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1477 content::RESOURCE_TYPE_STYLESHEET, "")); | |
| 1478 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1479 content::RESOURCE_TYPE_WORKER, "text/css")); | |
| 1480 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1481 content::RESOURCE_TYPE_WORKER, "")); | |
| 1482 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1483 content::RESOURCE_TYPE_PREFETCH, "text/css")); | |
| 1484 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1485 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); | |
| 1486 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1487 content::RESOURCE_TYPE_PREFETCH, "")); | |
| 1488 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1489 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); | |
| 1490 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1491 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); | |
| 1492 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1493 content::RESOURCE_TYPE_XHR, "")); | |
| 1494 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1495 content::RESOURCE_TYPE_XHR, "bogus/mime-type")); | |
| 1496 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | |
| 1497 content::RESOURCE_TYPE_XHR, "application/javascript")); | |
| 1498 } | |
| 1499 | |
| 1500 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestMainFrame) { | |
| 1501 std::unique_ptr<net::URLRequest> http_request = | |
| 1502 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, | |
| 1503 content::RESOURCE_TYPE_IMAGE, true); | |
| 1504 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1505 http_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
| 1506 | |
| 1507 std::unique_ptr<net::URLRequest> https_request = | |
| 1508 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, | |
| 1509 content::RESOURCE_TYPE_IMAGE, true); | |
| 1510 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1511 https_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
| 1512 | |
| 1513 std::unique_ptr<net::URLRequest> file_request = | |
| 1514 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, | |
| 1515 content::RESOURCE_TYPE_IMAGE, true); | |
| 1516 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1517 file_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
| 1518 | |
| 1519 std::unique_ptr<net::URLRequest> https_request_with_port = | |
| 1520 CreateURLRequest(GURL("https://www.google.com:666"), net::MEDIUM, | |
| 1521 content::RESOURCE_TYPE_IMAGE, true); | |
| 1522 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1523 https_request_with_port.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
| 1524 } | |
| 1525 | |
| 1526 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestSubResource) { | |
| 1527 std::unique_ptr<net::URLRequest> http_request = | |
| 1528 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
| 1529 content::RESOURCE_TYPE_IMAGE, false); | |
| 1530 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1531 http_request.get(), content::RESOURCE_TYPE_IMAGE)); | |
| 1532 | |
| 1533 std::unique_ptr<net::URLRequest> https_request = | |
| 1534 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, | |
| 1535 content::RESOURCE_TYPE_IMAGE, false); | |
| 1536 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1537 https_request.get(), content::RESOURCE_TYPE_IMAGE)); | |
| 1538 | |
| 1539 std::unique_ptr<net::URLRequest> file_request = | |
| 1540 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, | |
| 1541 content::RESOURCE_TYPE_IMAGE, false); | |
| 1542 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1543 file_request.get(), content::RESOURCE_TYPE_IMAGE)); | |
| 1544 | |
| 1545 std::unique_ptr<net::URLRequest> https_request_with_port = | |
| 1546 CreateURLRequest(GURL("https://www.google.com:666/cat.png"), net::MEDIUM, | |
| 1547 content::RESOURCE_TYPE_IMAGE, false); | |
| 1548 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
| 1549 https_request_with_port.get(), content::RESOURCE_TYPE_IMAGE)); | |
| 1550 } | |
| 1551 | |
| 1552 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseMainFrame) { | |
| 1553 net::HttpResponseInfo response_info; | |
| 1554 response_info.headers = MakeResponseHeaders(""); | |
| 1555 url_request_job_factory_.set_response_info(response_info); | |
| 1556 | |
| 1557 std::unique_ptr<net::URLRequest> http_request = | |
| 1558 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, | |
| 1559 content::RESOURCE_TYPE_MAIN_FRAME, true); | |
| 1560 EXPECT_TRUE( | |
| 1561 ResourcePrefetchPredictor::ShouldRecordResponse(http_request.get())); | |
| 1562 | |
| 1563 std::unique_ptr<net::URLRequest> https_request = | |
| 1564 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, | |
| 1565 content::RESOURCE_TYPE_MAIN_FRAME, true); | |
| 1566 EXPECT_TRUE( | |
| 1567 ResourcePrefetchPredictor::ShouldRecordResponse(https_request.get())); | |
| 1568 | |
| 1569 std::unique_ptr<net::URLRequest> file_request = | |
| 1570 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, | |
| 1571 content::RESOURCE_TYPE_MAIN_FRAME, true); | |
| 1572 EXPECT_FALSE( | |
| 1573 ResourcePrefetchPredictor::ShouldRecordResponse(file_request.get())); | |
| 1574 | |
| 1575 std::unique_ptr<net::URLRequest> https_request_with_port = | |
| 1576 CreateURLRequest(GURL("https://www.google.com:666"), net::MEDIUM, | |
| 1577 content::RESOURCE_TYPE_MAIN_FRAME, true); | |
| 1578 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1579 https_request_with_port.get())); | |
| 1580 } | |
| 1581 | |
| 1582 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseSubresource) { | |
| 1583 net::HttpResponseInfo response_info; | |
| 1584 response_info.headers = | |
| 1585 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); | |
| 1586 response_info.was_cached = true; | |
| 1587 url_request_job_factory_.set_response_info(response_info); | |
| 1588 | |
| 1589 // Protocol. | |
| 1590 std::unique_ptr<net::URLRequest> http_image_request = | |
| 1591 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
| 1592 content::RESOURCE_TYPE_IMAGE, true); | |
| 1593 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1594 http_image_request.get())); | |
| 1595 | |
| 1596 std::unique_ptr<net::URLRequest> https_image_request = | |
| 1597 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, | |
| 1598 content::RESOURCE_TYPE_IMAGE, true); | |
| 1599 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1600 https_image_request.get())); | |
| 1601 | |
| 1602 std::unique_ptr<net::URLRequest> https_image_request_with_port = | |
| 1603 CreateURLRequest(GURL("https://www.google.com:666/cat.png"), net::MEDIUM, | |
| 1604 content::RESOURCE_TYPE_IMAGE, true); | |
| 1605 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1606 https_image_request_with_port.get())); | |
| 1607 | |
| 1608 std::unique_ptr<net::URLRequest> file_image_request = | |
| 1609 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, | |
| 1610 content::RESOURCE_TYPE_IMAGE, true); | |
| 1611 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1612 file_image_request.get())); | |
| 1613 | |
| 1614 // ResourceType. | |
| 1615 std::unique_ptr<net::URLRequest> sub_frame_request = | |
| 1616 CreateURLRequest(GURL("http://www.google.com/frame.html"), net::MEDIUM, | |
| 1617 content::RESOURCE_TYPE_SUB_FRAME, true); | |
| 1618 EXPECT_FALSE( | |
| 1619 ResourcePrefetchPredictor::ShouldRecordResponse(sub_frame_request.get())); | |
| 1620 | |
| 1621 std::unique_ptr<net::URLRequest> font_request = | |
| 1622 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), | |
| 1623 net::MEDIUM, content::RESOURCE_TYPE_FONT_RESOURCE, true); | |
| 1624 EXPECT_TRUE( | |
| 1625 ResourcePrefetchPredictor::ShouldRecordResponse(font_request.get())); | |
| 1626 | |
| 1627 // From MIME Type. | |
| 1628 url_request_job_factory_.set_mime_type("image/png"); | |
| 1629 std::unique_ptr<net::URLRequest> prefetch_image_request = | |
| 1630 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
| 1631 content::RESOURCE_TYPE_PREFETCH, true); | |
| 1632 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1633 prefetch_image_request.get())); | |
| 1634 | |
| 1635 url_request_job_factory_.set_mime_type("image/my-wonderful-format"); | |
| 1636 std::unique_ptr<net::URLRequest> prefetch_unknown_image_request = | |
| 1637 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
| 1638 content::RESOURCE_TYPE_PREFETCH, true); | |
| 1639 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1640 prefetch_unknown_image_request.get())); | |
| 1641 | |
| 1642 url_request_job_factory_.set_mime_type("font/woff"); | |
| 1643 std::unique_ptr<net::URLRequest> prefetch_font_request = | |
| 1644 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), | |
| 1645 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, true); | |
| 1646 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1647 prefetch_font_request.get())); | |
| 1648 | |
| 1649 url_request_job_factory_.set_mime_type("font/woff-woff"); | |
| 1650 std::unique_ptr<net::URLRequest> prefetch_unknown_font_request = | |
| 1651 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), | |
| 1652 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, true); | |
| 1653 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1654 prefetch_unknown_font_request.get())); | |
| 1655 | |
| 1656 // Not main frame. | |
| 1657 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest( | |
| 1658 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | |
| 1659 content::RESOURCE_TYPE_FONT_RESOURCE, false); | |
| 1660 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
| 1661 font_request_sub_frame.get())); | |
| 1662 } | |
| 1663 | |
| 1664 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponse) { | 1374 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponse) { |
| 1665 net::HttpResponseInfo response_info; | 1375 net::HttpResponseInfo response_info; |
| 1666 response_info.headers = | 1376 response_info.headers = |
| 1667 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); | 1377 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); |
| 1668 response_info.was_cached = true; | 1378 response_info.was_cached = true; |
| 1669 url_request_job_factory_.set_response_info(response_info); | 1379 url_request_job_factory_.set_response_info(response_info); |
| 1670 | 1380 |
| 1671 GURL url("http://www.google.com/cat.png"); | 1381 GURL url("http://www.google.com/cat.png"); |
| 1672 std::unique_ptr<net::URLRequest> request = | 1382 std::unique_ptr<net::URLRequest> request = |
| 1673 CreateURLRequest(url, net::MEDIUM, content::RESOURCE_TYPE_IMAGE, true); | 1383 CreateURLRequest(url_request_context_, url, net::MEDIUM, |
| 1384 content::RESOURCE_TYPE_IMAGE, true); |
| 1674 URLRequestSummary summary; | 1385 URLRequestSummary summary; |
| 1675 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); | 1386 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); |
| 1676 EXPECT_EQ(url, summary.resource_url); | 1387 EXPECT_EQ(url, summary.resource_url); |
| 1677 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); | 1388 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); |
| 1678 EXPECT_TRUE(summary.was_cached); | 1389 EXPECT_TRUE(summary.was_cached); |
| 1679 EXPECT_FALSE(summary.has_validators); | 1390 EXPECT_FALSE(summary.has_validators); |
| 1680 EXPECT_FALSE(summary.always_revalidate); | 1391 EXPECT_FALSE(summary.always_revalidate); |
| 1681 | 1392 |
| 1682 // Navigation_id elements should be unset by default. | 1393 // Navigation_id elements should be unset by default. |
| 1683 EXPECT_EQ(-1, summary.navigation_id.tab_id); | 1394 EXPECT_EQ(-1, summary.navigation_id.tab_id); |
| 1684 EXPECT_EQ(GURL(), summary.navigation_id.main_frame_url); | 1395 EXPECT_EQ(GURL(), summary.navigation_id.main_frame_url); |
| 1685 } | 1396 } |
| 1686 | 1397 |
| 1687 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseContentType) { | 1398 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseContentType) { |
| 1688 net::HttpResponseInfo response_info; | 1399 net::HttpResponseInfo response_info; |
| 1689 response_info.headers = MakeResponseHeaders( | 1400 response_info.headers = MakeResponseHeaders( |
| 1690 "HTTP/1.1 200 OK\n\n" | 1401 "HTTP/1.1 200 OK\n\n" |
| 1691 "Some: Headers\n" | 1402 "Some: Headers\n" |
| 1692 "Content-Type: image/whatever\n"); | 1403 "Content-Type: image/whatever\n"); |
| 1693 url_request_job_factory_.set_response_info(response_info); | 1404 url_request_job_factory_.set_response_info(response_info); |
| 1694 url_request_job_factory_.set_mime_type("image/png"); | 1405 url_request_job_factory_.set_mime_type("image/png"); |
| 1695 | 1406 |
| 1696 std::unique_ptr<net::URLRequest> request = | 1407 std::unique_ptr<net::URLRequest> request = CreateURLRequest( |
| 1697 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1408 url_request_context_, GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1698 content::RESOURCE_TYPE_PREFETCH, true); | 1409 content::RESOURCE_TYPE_PREFETCH, true); |
| 1699 URLRequestSummary summary; | 1410 URLRequestSummary summary; |
| 1700 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); | 1411 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); |
| 1701 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); | 1412 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); |
| 1702 } | 1413 } |
| 1703 | 1414 |
| 1704 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseCachePolicy) { | 1415 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseCachePolicy) { |
| 1705 net::HttpResponseInfo response_info; | 1416 net::HttpResponseInfo response_info; |
| 1706 response_info.headers = MakeResponseHeaders( | 1417 response_info.headers = MakeResponseHeaders( |
| 1707 "HTTP/1.1 200 OK\n" | 1418 "HTTP/1.1 200 OK\n" |
| 1708 "Some: Headers\n"); | 1419 "Some: Headers\n"); |
| 1709 url_request_job_factory_.set_response_info(response_info); | 1420 url_request_job_factory_.set_response_info(response_info); |
| 1710 | 1421 |
| 1711 std::unique_ptr<net::URLRequest> request_no_validators = | 1422 std::unique_ptr<net::URLRequest> request_no_validators = CreateURLRequest( |
| 1712 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1423 url_request_context_, GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1713 content::RESOURCE_TYPE_PREFETCH, true); | 1424 content::RESOURCE_TYPE_PREFETCH, true); |
| 1714 | 1425 |
| 1715 URLRequestSummary summary; | 1426 URLRequestSummary summary; |
| 1716 EXPECT_TRUE( | 1427 EXPECT_TRUE( |
| 1717 URLRequestSummary::SummarizeResponse(*request_no_validators, &summary)); | 1428 URLRequestSummary::SummarizeResponse(*request_no_validators, &summary)); |
| 1718 EXPECT_FALSE(summary.has_validators); | 1429 EXPECT_FALSE(summary.has_validators); |
| 1719 | 1430 |
| 1720 response_info.headers = MakeResponseHeaders( | 1431 response_info.headers = MakeResponseHeaders( |
| 1721 "HTTP/1.1 200 OK\n" | 1432 "HTTP/1.1 200 OK\n" |
| 1722 "ETag: \"Cr66\"\n" | 1433 "ETag: \"Cr66\"\n" |
| 1723 "Cache-Control: no-cache\n"); | 1434 "Cache-Control: no-cache\n"); |
| 1724 url_request_job_factory_.set_response_info(response_info); | 1435 url_request_job_factory_.set_response_info(response_info); |
| 1725 std::unique_ptr<net::URLRequest> request_etag = | 1436 std::unique_ptr<net::URLRequest> request_etag = CreateURLRequest( |
| 1726 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1437 url_request_context_, GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1727 content::RESOURCE_TYPE_PREFETCH, true); | 1438 content::RESOURCE_TYPE_PREFETCH, true); |
| 1728 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); | 1439 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); |
| 1729 EXPECT_TRUE(summary.has_validators); | 1440 EXPECT_TRUE(summary.has_validators); |
| 1730 EXPECT_TRUE(summary.always_revalidate); | 1441 EXPECT_TRUE(summary.always_revalidate); |
| 1731 } | 1442 } |
| 1732 | 1443 |
| 1733 TEST_F(ResourcePrefetchPredictorTest, PopulatePrefetcherRequest) { | 1444 TEST_F(ResourcePrefetchPredictorTest, PopulatePrefetcherRequest) { |
| 1734 // The data that will be used in populating. | 1445 // The data that will be used in populating. |
| 1735 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1); | 1446 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1); |
| 1736 InitializeResourceData(google.add_resources(), "http://google.com/image1.png", | 1447 InitializeResourceData(google.add_resources(), "http://google.com/image1.png", |
| 1737 content::RESOURCE_TYPE_IMAGE, 10, 0, 0, 2.2, | 1448 content::RESOURCE_TYPE_IMAGE, 10, 0, 0, 2.2, |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 ResourceData* resource3_rd = host_data.add_resources(); | 1811 ResourceData* resource3_rd = host_data.add_resources(); |
| 2101 InitializeResourceData(resource3_rd, "http://google.com/script2.js", | 1812 InitializeResourceData(resource3_rd, "http://google.com/script2.js", |
| 2102 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, | 1813 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, |
| 2103 net::MEDIUM, false, false); | 1814 net::MEDIUM, false, false); |
| 2104 resource3_rd->set_before_first_contentful_paint(false); | 1815 resource3_rd->set_before_first_contentful_paint(false); |
| 2105 EXPECT_EQ(mock_tables_->host_resource_table_.data_, | 1816 EXPECT_EQ(mock_tables_->host_resource_table_.data_, |
| 2106 PrefetchDataMap({{host_data.primary_key(), host_data}})); | 1817 PrefetchDataMap({{host_data.primary_key(), host_data}})); |
| 2107 } | 1818 } |
| 2108 | 1819 |
| 2109 } // namespace predictors | 1820 } // namespace predictors |
| OLD | NEW |