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 MockURLRequestDelegate : public net::URLRequest::Delegate { | |
pasko
2016/08/10 16:40:07
it is not a powerful mock, would be more readable
Benoit L
2016/08/17 12:32:19
Done.
| |
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 net::HttpResponseInfo response_info; | |
pasko
2016/08/10 16:40:06
public members in classes are discouraged, sorry.
Benoit L
2016/08/17 12:32:19
Done.
| |
129 std::string mime_type; | |
130 }; | |
131 | |
55 class MockResourcePrefetchPredictorTables | 132 class MockResourcePrefetchPredictorTables |
56 : public ResourcePrefetchPredictorTables { | 133 : public ResourcePrefetchPredictorTables { |
57 public: | 134 public: |
58 MockResourcePrefetchPredictorTables() { } | 135 MockResourcePrefetchPredictorTables() { } |
59 | 136 |
60 MOCK_METHOD2(GetAllData, void(PrefetchDataMap* url_data_map, | 137 MOCK_METHOD2(GetAllData, void(PrefetchDataMap* url_data_map, |
61 PrefetchDataMap* host_data_map)); | 138 PrefetchDataMap* host_data_map)); |
62 MOCK_METHOD2(UpdateData, void(const PrefetchData& url_data, | 139 MOCK_METHOD2(UpdateData, void(const PrefetchData& url_data, |
63 const PrefetchData& host_data)); | 140 const PrefetchData& host_data)); |
64 MOCK_METHOD2(DeleteData, void(const std::vector<std::string>& urls, | 141 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, | 194 summary.navigation_id = CreateNavigationID(process_id, render_frame_id, |
118 main_frame_url); | 195 main_frame_url); |
119 summary.resource_url = GURL(resource_url); | 196 summary.resource_url = GURL(resource_url); |
120 summary.resource_type = resource_type; | 197 summary.resource_type = resource_type; |
121 summary.priority = priority; | 198 summary.priority = priority; |
122 summary.mime_type = mime_type; | 199 summary.mime_type = mime_type; |
123 summary.was_cached = was_cached; | 200 summary.was_cached = was_cached; |
124 return summary; | 201 return summary; |
125 } | 202 } |
126 | 203 |
204 std::unique_ptr<net::URLRequest> CreateURLRequest( | |
205 const GURL& url, | |
206 net::RequestPriority priority, | |
207 content::ResourceType resource_type, | |
208 int render_process_id, | |
209 int render_frame_id, | |
210 bool is_main_frame) { | |
211 auto request = url_request_context_.CreateRequest(url, priority, | |
pasko
2016/08/10 16:40:07
TIL: we discourage auto-ing smart pointers, see di
Benoit L
2016/08/17 12:32:19
Done.
| |
212 &url_request_delegate_); | |
213 request->set_first_party_for_cookies(url); | |
214 content::ResourceRequestInfo::AllocateForTesting( | |
215 request.get(), resource_type, nullptr, render_process_id, -1, | |
216 render_frame_id, is_main_frame, false, false, true, false); | |
217 request->Start(); | |
218 return request; | |
219 } | |
220 | |
127 void InitializePredictor() { | 221 void InitializePredictor() { |
128 predictor_->StartInitialization(); | 222 predictor_->StartInitialization(); |
129 base::RunLoop loop; | 223 base::RunLoop loop; |
130 loop.RunUntilIdle(); // Runs the DB lookup. | 224 loop.RunUntilIdle(); // Runs the DB lookup. |
131 profile_->BlockUntilHistoryProcessesPendingRequests(); | 225 profile_->BlockUntilHistoryProcessesPendingRequests(); |
132 } | 226 } |
133 | 227 |
134 bool URLRequestSummaryAreEqual(const URLRequestSummary& lhs, | 228 bool URLRequestSummaryAreEqual(const URLRequestSummary& lhs, |
135 const URLRequestSummary& rhs) { | 229 const URLRequestSummary& rhs) { |
136 return lhs.navigation_id == rhs.navigation_id && | 230 return lhs.navigation_id == rhs.navigation_id && |
(...skipping 17 matching lines...) Expand all Loading... | |
154 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); | 248 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); |
155 predictor_->set_mock_tables(mock_tables_); | 249 predictor_->set_mock_tables(mock_tables_); |
156 } | 250 } |
157 | 251 |
158 void InitializeSampleData(); | 252 void InitializeSampleData(); |
159 | 253 |
160 base::MessageLoop loop_; | 254 base::MessageLoop loop_; |
161 content::TestBrowserThread ui_thread_; | 255 content::TestBrowserThread ui_thread_; |
162 content::TestBrowserThread db_thread_; | 256 content::TestBrowserThread db_thread_; |
163 std::unique_ptr<TestingProfile> profile_; | 257 std::unique_ptr<TestingProfile> profile_; |
258 net::TestURLRequestContext url_request_context_; | |
164 | 259 |
165 std::unique_ptr<ResourcePrefetchPredictor> predictor_; | 260 std::unique_ptr<ResourcePrefetchPredictor> predictor_; |
166 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables> > mock_tables_; | 261 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables> > mock_tables_; |
167 | 262 |
168 PrefetchDataMap test_url_data_; | 263 PrefetchDataMap test_url_data_; |
169 PrefetchDataMap test_host_data_; | 264 PrefetchDataMap test_host_data_; |
170 PrefetchData empty_url_data_; | 265 PrefetchData empty_url_data_; |
171 PrefetchData empty_host_data_; | 266 PrefetchData empty_host_data_; |
267 | |
268 MockURLRequestJobFactory url_request_job_factory_; | |
269 MockURLRequestDelegate url_request_delegate_; | |
172 }; | 270 }; |
173 | 271 |
174 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() | 272 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() |
175 : loop_(base::MessageLoop::TYPE_DEFAULT), | 273 : loop_(base::MessageLoop::TYPE_DEFAULT), |
176 ui_thread_(content::BrowserThread::UI, &loop_), | 274 ui_thread_(content::BrowserThread::UI, &loop_), |
177 db_thread_(content::BrowserThread::DB, &loop_), | 275 db_thread_(content::BrowserThread::DB, &loop_), |
178 profile_(new TestingProfile()), | 276 profile_(new TestingProfile()), |
179 mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()), | 277 mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()), |
180 empty_url_data_(PREFETCH_KEY_TYPE_URL, std::string()), | 278 empty_url_data_(PREFETCH_KEY_TYPE_URL, std::string()), |
181 empty_host_data_(PREFETCH_KEY_TYPE_HOST, std::string()) {} | 279 empty_host_data_(PREFETCH_KEY_TYPE_HOST, std::string()) {} |
(...skipping 14 matching lines...) Expand all Loading... | |
196 ResetPredictor(); | 294 ResetPredictor(); |
197 EXPECT_EQ(predictor_->initialization_state_, | 295 EXPECT_EQ(predictor_->initialization_state_, |
198 ResourcePrefetchPredictor::NOT_INITIALIZED); | 296 ResourcePrefetchPredictor::NOT_INITIALIZED); |
199 EXPECT_CALL(*mock_tables_.get(), | 297 EXPECT_CALL(*mock_tables_.get(), |
200 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 298 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
201 Pointee(ContainerEq(PrefetchDataMap())))); | 299 Pointee(ContainerEq(PrefetchDataMap())))); |
202 InitializePredictor(); | 300 InitializePredictor(); |
203 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 301 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
204 EXPECT_EQ(predictor_->initialization_state_, | 302 EXPECT_EQ(predictor_->initialization_state_, |
205 ResourcePrefetchPredictor::INITIALIZED); | 303 ResourcePrefetchPredictor::INITIALIZED); |
304 | |
305 url_request_context_.set_job_factory(&url_request_job_factory_); | |
206 } | 306 } |
207 | 307 |
208 void ResourcePrefetchPredictorTest::TearDown() { | 308 void ResourcePrefetchPredictorTest::TearDown() { |
209 predictor_.reset(NULL); | 309 predictor_.reset(NULL); |
210 profile_->DestroyHistoryService(); | 310 profile_->DestroyHistoryService(); |
211 } | 311 } |
212 | 312 |
213 void ResourcePrefetchPredictorTest::InitializeSampleData() { | 313 void ResourcePrefetchPredictorTest::InitializeSampleData() { |
214 { // Url data. | 314 { // Url data. |
215 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 315 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( | 876 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
777 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); | 877 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); |
778 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 878 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
779 content::RESOURCE_TYPE_PREFETCH, "")); | 879 content::RESOURCE_TYPE_PREFETCH, "")); |
780 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 880 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
781 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); | 881 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); |
782 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 882 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
783 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); | 883 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); |
784 } | 884 } |
785 | 885 |
886 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestMainFrame) { | |
887 std::unique_ptr<net::URLRequest> http_request = | |
888 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, | |
889 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | |
890 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
891 http_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
892 | |
893 std::unique_ptr<net::URLRequest> https_request = | |
894 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, | |
895 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | |
896 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
897 https_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
898 | |
899 std::unique_ptr<net::URLRequest> file_request = | |
900 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, | |
901 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | |
902 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
903 file_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | |
904 } | |
905 | |
906 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestSubResource) { | |
907 std::unique_ptr<net::URLRequest> http_request = | |
908 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
909 content::RESOURCE_TYPE_IMAGE, 1, 1, false); | |
910 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
911 http_request.get(), content::RESOURCE_TYPE_IMAGE)); | |
912 | |
913 std::unique_ptr<net::URLRequest> https_request = | |
914 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, | |
915 content::RESOURCE_TYPE_IMAGE, 1, 1, false); | |
916 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
917 https_request.get(), content::RESOURCE_TYPE_IMAGE)); | |
918 | |
919 std::unique_ptr<net::URLRequest> file_request = | |
920 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, | |
921 content::RESOURCE_TYPE_IMAGE, 1, 1, false); | |
922 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | |
923 file_request.get(), content::RESOURCE_TYPE_IMAGE)); | |
924 } | |
925 | |
926 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseMainFrame) { | |
927 url_request_job_factory_.response_info.headers = | |
928 scoped_refptr<net::HttpResponseHeaders>(new net::HttpResponseHeaders("")); | |
929 | |
930 std::unique_ptr<net::URLRequest> http_request = | |
931 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, | |
932 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); | |
933 EXPECT_TRUE( | |
934 ResourcePrefetchPredictor::ShouldRecordResponse(http_request.get())); | |
935 | |
936 std::unique_ptr<net::URLRequest> https_request = | |
937 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, | |
938 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); | |
939 EXPECT_TRUE( | |
940 ResourcePrefetchPredictor::ShouldRecordResponse(https_request.get())); | |
941 | |
942 std::unique_ptr<net::URLRequest> file_request = | |
943 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, | |
944 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); | |
945 EXPECT_FALSE( | |
946 ResourcePrefetchPredictor::ShouldRecordResponse(file_request.get())); | |
947 } | |
948 | |
949 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseSubresource) { | |
950 url_request_job_factory_.response_info.headers = | |
951 scoped_refptr<net::HttpResponseHeaders>( | |
952 new net::HttpResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n")); | |
953 url_request_job_factory_.response_info.was_cached = true; | |
954 | |
955 // Protocol | |
956 std::unique_ptr<net::URLRequest> http_image_request = | |
957 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
958 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | |
959 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
960 http_image_request.get())); | |
961 | |
962 std::unique_ptr<net::URLRequest> https_image_request = | |
963 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, | |
964 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | |
965 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
966 https_image_request.get())); | |
967 | |
968 std::unique_ptr<net::URLRequest> file_image_request = | |
969 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, | |
970 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | |
971 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
972 file_image_request.get())); | |
973 | |
974 // ResourceType | |
975 std::unique_ptr<net::URLRequest> sub_frame_request = | |
976 CreateURLRequest(GURL("http://www.google.com/frame.html"), net::MEDIUM, | |
977 content::RESOURCE_TYPE_SUB_FRAME, 1, 1, true); | |
978 EXPECT_FALSE( | |
979 ResourcePrefetchPredictor::ShouldRecordResponse(sub_frame_request.get())); | |
980 | |
981 std::unique_ptr<net::URLRequest> font_request = CreateURLRequest( | |
982 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | |
983 content::RESOURCE_TYPE_FONT_RESOURCE, 1, 1, true); | |
984 EXPECT_TRUE( | |
985 ResourcePrefetchPredictor::ShouldRecordResponse(font_request.get())); | |
986 | |
987 // From MIME Type. | |
988 url_request_job_factory_.mime_type = "image/png"; | |
989 std::unique_ptr<net::URLRequest> prefetch_image_request = | |
990 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
991 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | |
992 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
993 prefetch_image_request.get())); | |
994 | |
995 url_request_job_factory_.mime_type = "image/my-wonderful-format"; | |
996 std::unique_ptr<net::URLRequest> prefetch_unknown_image_request = | |
997 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | |
998 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | |
999 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
1000 prefetch_unknown_image_request.get())); | |
1001 | |
1002 url_request_job_factory_.mime_type = "font/woff"; | |
1003 std::unique_ptr<net::URLRequest> prefetch_font_request = CreateURLRequest( | |
1004 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | |
1005 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | |
1006 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
1007 prefetch_font_request.get())); | |
1008 | |
1009 url_request_job_factory_.mime_type = "font/woff-woff"; | |
1010 std::unique_ptr<net::URLRequest> prefetch_unknown_font_request = | |
1011 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), | |
1012 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, 1, 1, | |
1013 true); | |
1014 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
1015 prefetch_unknown_font_request.get())); | |
1016 | |
1017 // Not main frame | |
1018 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest( | |
1019 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | |
1020 content::RESOURCE_TYPE_FONT_RESOURCE, 1, 1, false); | |
1021 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | |
1022 font_request_sub_frame.get())); | |
1023 } | |
1024 | |
786 } // namespace predictors | 1025 } // namespace predictors |
OLD | NEW |