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 | 9 |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
15 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "components/history/core/browser/history_service.h" | 18 #include "components/history/core/browser/history_service.h" |
18 #include "components/history/core/browser/history_types.h" | 19 #include "components/history/core/browser/history_types.h" |
| 20 #include "content/public/browser/resource_request_info.h" |
19 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 22 #include "net/http/http_response_headers.h" |
| 23 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_job.h" |
| 25 #include "net/url_request/url_request_test_util.h" |
| 26 #include "net/url_request/url_request_test_util.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
22 | 29 |
23 using testing::ContainerEq; | 30 using testing::ContainerEq; |
24 using testing::Pointee; | 31 using testing::Pointee; |
25 using testing::SetArgPointee; | 32 using testing::SetArgPointee; |
26 using testing::StrictMock; | 33 using testing::StrictMock; |
27 | 34 |
28 namespace predictors { | 35 namespace predictors { |
29 | 36 |
(...skipping 15 matching lines...) Expand all Loading... |
45 *os << "[" << data.key_type << "," << data.primary_key | 52 *os << "[" << data.key_type << "," << data.primary_key |
46 << "," << data.last_visit.ToInternalValue() << "]\n"; | 53 << "," << data.last_visit.ToInternalValue() << "]\n"; |
47 for (ResourceRows::const_iterator it = data.resources.begin(); | 54 for (ResourceRows::const_iterator it = data.resources.begin(); |
48 it != data.resources.end(); ++it) { | 55 it != data.resources.end(); ++it) { |
49 *os << "\t\t"; | 56 *os << "\t\t"; |
50 PrintTo(*it, os); | 57 PrintTo(*it, os); |
51 *os << "\n"; | 58 *os << "\n"; |
52 } | 59 } |
53 } | 60 } |
54 | 61 |
| 62 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { |
| 63 void OnResponseStarted(net::URLRequest* request) override {} |
| 64 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} |
| 65 }; |
| 66 |
| 67 class MockURLRequestJob : public net::URLRequestJob { |
| 68 public: |
| 69 MockURLRequestJob(net::URLRequest* request, |
| 70 const net::HttpResponseInfo& response_info, |
| 71 const std::string& mime_type) |
| 72 : net::URLRequestJob(request, nullptr), |
| 73 response_info_(response_info), |
| 74 mime_type_(mime_type) {} |
| 75 |
| 76 bool GetMimeType(std::string* mime_type) const override { |
| 77 *mime_type = mime_type_; |
| 78 return true; |
| 79 } |
| 80 |
| 81 protected: |
| 82 void Start() override { NotifyHeadersComplete(); } |
| 83 int GetResponseCode() const override { return 200; } |
| 84 void GetResponseInfo(net::HttpResponseInfo* info) override { |
| 85 *info = response_info_; |
| 86 } |
| 87 |
| 88 private: |
| 89 net::HttpResponseInfo response_info_; |
| 90 std::string mime_type_; |
| 91 }; |
| 92 |
| 93 class MockURLRequestJobFactory : public net::URLRequestJobFactory { |
| 94 public: |
| 95 MockURLRequestJobFactory() {} |
| 96 ~MockURLRequestJobFactory() override {} |
| 97 |
| 98 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
| 99 const std::string& scheme, |
| 100 net::URLRequest* request, |
| 101 net::NetworkDelegate* network_delegate) const override { |
| 102 return new MockURLRequestJob(request, response_info_, mime_type_); |
| 103 } |
| 104 |
| 105 net::URLRequestJob* MaybeInterceptRedirect( |
| 106 net::URLRequest* request, |
| 107 net::NetworkDelegate* network_delegate, |
| 108 const GURL& location) const override { |
| 109 return nullptr; |
| 110 } |
| 111 |
| 112 net::URLRequestJob* MaybeInterceptResponse( |
| 113 net::URLRequest* request, |
| 114 net::NetworkDelegate* network_delegate) const override { |
| 115 return nullptr; |
| 116 } |
| 117 |
| 118 bool IsHandledProtocol(const std::string& scheme) const override { |
| 119 return true; |
| 120 } |
| 121 |
| 122 bool IsHandledURL(const GURL& url) const override { return true; } |
| 123 |
| 124 bool IsSafeRedirectTarget(const GURL& location) const override { |
| 125 return true; |
| 126 } |
| 127 |
| 128 void set_response_info(const net::HttpResponseInfo& response_info) { |
| 129 response_info_ = response_info; |
| 130 } |
| 131 |
| 132 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } |
| 133 |
| 134 private: |
| 135 net::HttpResponseInfo response_info_; |
| 136 std::string mime_type_; |
| 137 }; |
| 138 |
55 class MockResourcePrefetchPredictorTables | 139 class MockResourcePrefetchPredictorTables |
56 : public ResourcePrefetchPredictorTables { | 140 : public ResourcePrefetchPredictorTables { |
57 public: | 141 public: |
58 MockResourcePrefetchPredictorTables() { } | 142 MockResourcePrefetchPredictorTables() { } |
59 | 143 |
60 MOCK_METHOD2(GetAllData, void(PrefetchDataMap* url_data_map, | 144 MOCK_METHOD2(GetAllData, void(PrefetchDataMap* url_data_map, |
61 PrefetchDataMap* host_data_map)); | 145 PrefetchDataMap* host_data_map)); |
62 MOCK_METHOD2(UpdateData, void(const PrefetchData& url_data, | 146 MOCK_METHOD2(UpdateData, void(const PrefetchData& url_data, |
63 const PrefetchData& host_data)); | 147 const PrefetchData& host_data)); |
64 MOCK_METHOD2(DeleteData, void(const std::vector<std::string>& urls, | 148 MOCK_METHOD2(DeleteData, void(const std::vector<std::string>& urls, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 summary.navigation_id = CreateNavigationID(process_id, render_frame_id, | 201 summary.navigation_id = CreateNavigationID(process_id, render_frame_id, |
118 main_frame_url); | 202 main_frame_url); |
119 summary.resource_url = GURL(resource_url); | 203 summary.resource_url = GURL(resource_url); |
120 summary.resource_type = resource_type; | 204 summary.resource_type = resource_type; |
121 summary.priority = priority; | 205 summary.priority = priority; |
122 summary.mime_type = mime_type; | 206 summary.mime_type = mime_type; |
123 summary.was_cached = was_cached; | 207 summary.was_cached = was_cached; |
124 return summary; | 208 return summary; |
125 } | 209 } |
126 | 210 |
| 211 std::unique_ptr<net::URLRequest> CreateURLRequest( |
| 212 const GURL& url, |
| 213 net::RequestPriority priority, |
| 214 content::ResourceType resource_type, |
| 215 int render_process_id, |
| 216 int render_frame_id, |
| 217 bool is_main_frame) { |
| 218 std::unique_ptr<net::URLRequest> request = |
| 219 url_request_context_.CreateRequest(url, priority, |
| 220 &url_request_delegate_); |
| 221 request->set_first_party_for_cookies(url); |
| 222 content::ResourceRequestInfo::AllocateForTesting( |
| 223 request.get(), resource_type, nullptr, render_process_id, -1, |
| 224 render_frame_id, is_main_frame, false, false, true, false); |
| 225 request->Start(); |
| 226 return request; |
| 227 } |
| 228 |
127 void InitializePredictor() { | 229 void InitializePredictor() { |
128 predictor_->StartInitialization(); | 230 predictor_->StartInitialization(); |
129 base::RunLoop loop; | 231 base::RunLoop loop; |
130 loop.RunUntilIdle(); // Runs the DB lookup. | 232 loop.RunUntilIdle(); // Runs the DB lookup. |
131 profile_->BlockUntilHistoryProcessesPendingRequests(); | 233 profile_->BlockUntilHistoryProcessesPendingRequests(); |
132 } | 234 } |
133 | 235 |
134 bool URLRequestSummaryAreEqual(const URLRequestSummary& lhs, | 236 bool URLRequestSummaryAreEqual(const URLRequestSummary& lhs, |
135 const URLRequestSummary& rhs) { | 237 const URLRequestSummary& rhs) { |
136 return lhs.navigation_id == rhs.navigation_id && | 238 return lhs.navigation_id == rhs.navigation_id && |
(...skipping 17 matching lines...) Expand all Loading... |
154 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); | 256 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); |
155 predictor_->set_mock_tables(mock_tables_); | 257 predictor_->set_mock_tables(mock_tables_); |
156 } | 258 } |
157 | 259 |
158 void InitializeSampleData(); | 260 void InitializeSampleData(); |
159 | 261 |
160 base::MessageLoop loop_; | 262 base::MessageLoop loop_; |
161 content::TestBrowserThread ui_thread_; | 263 content::TestBrowserThread ui_thread_; |
162 content::TestBrowserThread db_thread_; | 264 content::TestBrowserThread db_thread_; |
163 std::unique_ptr<TestingProfile> profile_; | 265 std::unique_ptr<TestingProfile> profile_; |
| 266 net::TestURLRequestContext url_request_context_; |
164 | 267 |
165 std::unique_ptr<ResourcePrefetchPredictor> predictor_; | 268 std::unique_ptr<ResourcePrefetchPredictor> predictor_; |
166 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables> > mock_tables_; | 269 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables> > mock_tables_; |
167 | 270 |
168 PrefetchDataMap test_url_data_; | 271 PrefetchDataMap test_url_data_; |
169 PrefetchDataMap test_host_data_; | 272 PrefetchDataMap test_host_data_; |
170 PrefetchData empty_url_data_; | 273 PrefetchData empty_url_data_; |
171 PrefetchData empty_host_data_; | 274 PrefetchData empty_host_data_; |
| 275 |
| 276 MockURLRequestJobFactory url_request_job_factory_; |
| 277 EmptyURLRequestDelegate url_request_delegate_; |
172 }; | 278 }; |
173 | 279 |
174 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() | 280 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() |
175 : loop_(base::MessageLoop::TYPE_DEFAULT), | 281 : loop_(base::MessageLoop::TYPE_DEFAULT), |
176 ui_thread_(content::BrowserThread::UI, &loop_), | 282 ui_thread_(content::BrowserThread::UI, &loop_), |
177 db_thread_(content::BrowserThread::DB, &loop_), | 283 db_thread_(content::BrowserThread::DB, &loop_), |
178 profile_(new TestingProfile()), | 284 profile_(new TestingProfile()), |
179 mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()), | 285 mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()), |
180 empty_url_data_(PREFETCH_KEY_TYPE_URL, std::string()), | 286 empty_url_data_(PREFETCH_KEY_TYPE_URL, std::string()), |
181 empty_host_data_(PREFETCH_KEY_TYPE_HOST, std::string()) {} | 287 empty_host_data_(PREFETCH_KEY_TYPE_HOST, std::string()) {} |
(...skipping 14 matching lines...) Expand all Loading... |
196 ResetPredictor(); | 302 ResetPredictor(); |
197 EXPECT_EQ(predictor_->initialization_state_, | 303 EXPECT_EQ(predictor_->initialization_state_, |
198 ResourcePrefetchPredictor::NOT_INITIALIZED); | 304 ResourcePrefetchPredictor::NOT_INITIALIZED); |
199 EXPECT_CALL(*mock_tables_.get(), | 305 EXPECT_CALL(*mock_tables_.get(), |
200 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 306 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
201 Pointee(ContainerEq(PrefetchDataMap())))); | 307 Pointee(ContainerEq(PrefetchDataMap())))); |
202 InitializePredictor(); | 308 InitializePredictor(); |
203 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 309 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
204 EXPECT_EQ(predictor_->initialization_state_, | 310 EXPECT_EQ(predictor_->initialization_state_, |
205 ResourcePrefetchPredictor::INITIALIZED); | 311 ResourcePrefetchPredictor::INITIALIZED); |
| 312 |
| 313 url_request_context_.set_job_factory(&url_request_job_factory_); |
206 } | 314 } |
207 | 315 |
208 void ResourcePrefetchPredictorTest::TearDown() { | 316 void ResourcePrefetchPredictorTest::TearDown() { |
209 predictor_.reset(NULL); | 317 predictor_.reset(NULL); |
210 profile_->DestroyHistoryService(); | 318 profile_->DestroyHistoryService(); |
211 } | 319 } |
212 | 320 |
213 void ResourcePrefetchPredictorTest::InitializeSampleData() { | 321 void ResourcePrefetchPredictorTest::InitializeSampleData() { |
214 { // Url data. | 322 { // Url data. |
215 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 323 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 884 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
777 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); | 885 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); |
778 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 886 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
779 content::RESOURCE_TYPE_PREFETCH, "")); | 887 content::RESOURCE_TYPE_PREFETCH, "")); |
780 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 888 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
781 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); | 889 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); |
782 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 890 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
783 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); | 891 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); |
784 } | 892 } |
785 | 893 |
| 894 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestMainFrame) { |
| 895 std::unique_ptr<net::URLRequest> http_request = |
| 896 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, |
| 897 content::RESOURCE_TYPE_IMAGE, 1, 1, true); |
| 898 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( |
| 899 http_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); |
| 900 |
| 901 std::unique_ptr<net::URLRequest> https_request = |
| 902 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, |
| 903 content::RESOURCE_TYPE_IMAGE, 1, 1, true); |
| 904 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( |
| 905 https_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); |
| 906 |
| 907 std::unique_ptr<net::URLRequest> file_request = |
| 908 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, |
| 909 content::RESOURCE_TYPE_IMAGE, 1, 1, true); |
| 910 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
| 911 file_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); |
| 912 } |
| 913 |
| 914 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestSubResource) { |
| 915 std::unique_ptr<net::URLRequest> http_request = |
| 916 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 917 content::RESOURCE_TYPE_IMAGE, 1, 1, false); |
| 918 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
| 919 http_request.get(), content::RESOURCE_TYPE_IMAGE)); |
| 920 |
| 921 std::unique_ptr<net::URLRequest> https_request = |
| 922 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, |
| 923 content::RESOURCE_TYPE_IMAGE, 1, 1, false); |
| 924 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
| 925 https_request.get(), content::RESOURCE_TYPE_IMAGE)); |
| 926 |
| 927 std::unique_ptr<net::URLRequest> file_request = |
| 928 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, |
| 929 content::RESOURCE_TYPE_IMAGE, 1, 1, false); |
| 930 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
| 931 file_request.get(), content::RESOURCE_TYPE_IMAGE)); |
| 932 } |
| 933 |
| 934 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseMainFrame) { |
| 935 net::HttpResponseInfo response_info; |
| 936 response_info.headers = |
| 937 scoped_refptr<net::HttpResponseHeaders>(new net::HttpResponseHeaders("")); |
| 938 url_request_job_factory_.set_response_info(response_info); |
| 939 |
| 940 std::unique_ptr<net::URLRequest> http_request = |
| 941 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, |
| 942 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); |
| 943 EXPECT_TRUE( |
| 944 ResourcePrefetchPredictor::ShouldRecordResponse(http_request.get())); |
| 945 |
| 946 std::unique_ptr<net::URLRequest> https_request = |
| 947 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, |
| 948 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); |
| 949 EXPECT_TRUE( |
| 950 ResourcePrefetchPredictor::ShouldRecordResponse(https_request.get())); |
| 951 |
| 952 std::unique_ptr<net::URLRequest> file_request = |
| 953 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, |
| 954 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); |
| 955 EXPECT_FALSE( |
| 956 ResourcePrefetchPredictor::ShouldRecordResponse(file_request.get())); |
| 957 } |
| 958 |
| 959 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseSubresource) { |
| 960 net::HttpResponseInfo response_info; |
| 961 response_info.headers = scoped_refptr<net::HttpResponseHeaders>( |
| 962 new net::HttpResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n")); |
| 963 response_info.was_cached = true; |
| 964 url_request_job_factory_.set_response_info(response_info); |
| 965 |
| 966 // Protocol |
| 967 std::unique_ptr<net::URLRequest> http_image_request = |
| 968 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 969 content::RESOURCE_TYPE_IMAGE, 1, 1, true); |
| 970 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 971 http_image_request.get())); |
| 972 |
| 973 std::unique_ptr<net::URLRequest> https_image_request = |
| 974 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, |
| 975 content::RESOURCE_TYPE_IMAGE, 1, 1, true); |
| 976 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 977 https_image_request.get())); |
| 978 |
| 979 std::unique_ptr<net::URLRequest> file_image_request = |
| 980 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, |
| 981 content::RESOURCE_TYPE_IMAGE, 1, 1, true); |
| 982 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 983 file_image_request.get())); |
| 984 |
| 985 // ResourceType |
| 986 std::unique_ptr<net::URLRequest> sub_frame_request = |
| 987 CreateURLRequest(GURL("http://www.google.com/frame.html"), net::MEDIUM, |
| 988 content::RESOURCE_TYPE_SUB_FRAME, 1, 1, true); |
| 989 EXPECT_FALSE( |
| 990 ResourcePrefetchPredictor::ShouldRecordResponse(sub_frame_request.get())); |
| 991 |
| 992 std::unique_ptr<net::URLRequest> font_request = CreateURLRequest( |
| 993 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, |
| 994 content::RESOURCE_TYPE_FONT_RESOURCE, 1, 1, true); |
| 995 EXPECT_TRUE( |
| 996 ResourcePrefetchPredictor::ShouldRecordResponse(font_request.get())); |
| 997 |
| 998 // From MIME Type. |
| 999 url_request_job_factory_.set_mime_type("image/png"); |
| 1000 std::unique_ptr<net::URLRequest> prefetch_image_request = |
| 1001 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1002 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); |
| 1003 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 1004 prefetch_image_request.get())); |
| 1005 |
| 1006 url_request_job_factory_.set_mime_type("image/my-wonderful-format"); |
| 1007 std::unique_ptr<net::URLRequest> prefetch_unknown_image_request = |
| 1008 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1009 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); |
| 1010 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 1011 prefetch_unknown_image_request.get())); |
| 1012 |
| 1013 url_request_job_factory_.set_mime_type("font/woff"); |
| 1014 std::unique_ptr<net::URLRequest> prefetch_font_request = CreateURLRequest( |
| 1015 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, |
| 1016 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); |
| 1017 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 1018 prefetch_font_request.get())); |
| 1019 |
| 1020 url_request_job_factory_.set_mime_type("font/woff-woff"); |
| 1021 std::unique_ptr<net::URLRequest> prefetch_unknown_font_request = |
| 1022 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), |
| 1023 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, 1, 1, |
| 1024 true); |
| 1025 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 1026 prefetch_unknown_font_request.get())); |
| 1027 |
| 1028 // Not main frame |
| 1029 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest( |
| 1030 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, |
| 1031 content::RESOURCE_TYPE_FONT_RESOURCE, 1, 1, false); |
| 1032 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
| 1033 font_request_sub_frame.get())); |
| 1034 } |
| 1035 |
786 } // namespace predictors | 1036 } // namespace predictors |
OLD | NEW |