OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 const char kJavascriptMime[] = "application/javascript"; | 47 const char kJavascriptMime[] = "application/javascript"; |
48 | 48 |
49 // Paths to resources handled by a custom request handler. They return empty | 49 // Paths to resources handled by a custom request handler. They return empty |
50 // responses with controllable response headers. | 50 // responses with controllable response headers. |
51 const char kImagePath[] = "/handled-by-test/image.png"; | 51 const char kImagePath[] = "/handled-by-test/image.png"; |
52 const char kImagePath2[] = "/handled-by-test/image2.png"; | 52 const char kImagePath2[] = "/handled-by-test/image2.png"; |
53 const char kStylePath[] = "/handled-by-test/style.css"; | 53 const char kStylePath[] = "/handled-by-test/style.css"; |
54 const char kStylePath2[] = "/handled-by-test/style2.css"; | 54 const char kStylePath2[] = "/handled-by-test/style2.css"; |
55 const char kScriptPath[] = "/handled-by-test/script.js"; | 55 const char kScriptPath[] = "/handled-by-test/script.js"; |
56 const char kScriptPath2[] = "/handled-by-test/script2.js"; | 56 const char kScriptPath2[] = "/handled-by-test/script2.js"; |
57 const char kScriptLongPath[] = "/handled-by-test/long-script.js"; | |
57 const char kFontPath[] = "/handled-by-test/font.ttf"; | 58 const char kFontPath[] = "/handled-by-test/font.ttf"; |
58 const char kRedirectPath[] = "/handled-by-test/redirect.html"; | 59 const char kRedirectPath[] = "/handled-by-test/redirect.html"; |
59 const char kRedirectPath2[] = "/handled-by-test/redirect2.html"; | 60 const char kRedirectPath2[] = "/handled-by-test/redirect2.html"; |
60 const char kRedirectPath3[] = "/handled-by-test/redirect3.html"; | 61 const char kRedirectPath3[] = "/handled-by-test/redirect3.html"; |
61 | 62 |
62 // These are loaded from a file by the test server. | 63 // These are loaded from a file by the test server. |
63 const char kHtmlSubresourcesPath[] = "/predictors/html_subresources.html"; | 64 const char kHtmlSubresourcesPath[] = "/predictors/html_subresources.html"; |
64 const char kHtmlDocumentWritePath[] = "/predictors/document_write.html"; | 65 const char kHtmlDocumentWritePath[] = "/predictors/document_write.html"; |
65 const char kScriptDocumentWritePath[] = "/predictors/document_write.js"; | 66 const char kScriptDocumentWritePath[] = "/predictors/document_write.js"; |
66 const char kHtmlAppendChildPath[] = "/predictors/append_child.html"; | 67 const char kHtmlAppendChildPath[] = "/predictors/append_child.html"; |
67 const char kScriptAppendChildPath[] = "/predictors/append_child.js"; | 68 const char kScriptAppendChildPath[] = "/predictors/append_child.js"; |
68 const char kHtmlInnerHtmlPath[] = "/predictors/inner_html.html"; | 69 const char kHtmlInnerHtmlPath[] = "/predictors/inner_html.html"; |
69 const char kScriptInnerHtmlPath[] = "/predictors/inner_html.js"; | 70 const char kScriptInnerHtmlPath[] = "/predictors/inner_html.js"; |
70 const char kHtmlXHRPath[] = "/predictors/xhr.html"; | 71 const char kHtmlXHRPath[] = "/predictors/xhr.html"; |
71 const char kScriptXHRPath[] = "/predictors/xhr.js"; | 72 const char kScriptXHRPath[] = "/predictors/xhr.js"; |
72 const char kHtmlIframePath[] = "/predictors/html_iframe.html"; | 73 const char kHtmlIframePath[] = "/predictors/html_iframe.html"; |
73 const char kHtmlJavascriptRedirectPath[] = | 74 const char kHtmlJavascriptRedirectPath[] = |
74 "/predictors/javascript_redirect.html"; | 75 "/predictors/javascript_redirect.html"; |
76 const char kHtmlFcpOrderPath[] = "/predictors/subresource_fcp_order.html"; | |
77 const char kImageRealPath[] = "/predictors/google.png"; | |
75 | 78 |
76 // Host, path. | 79 // Host, path. |
77 const char* kScript[2] = {kFooHost, kScriptPath}; | 80 const char* kScript[2] = {kFooHost, kScriptPath}; |
78 const char* kImage[2] = {kBarHost, kImagePath}; | 81 const char* kImage[2] = {kBarHost, kImagePath}; |
79 const char* kFont[2] = {kFooHost, kFontPath}; | 82 const char* kFont[2] = {kFooHost, kFontPath}; |
80 const char* kStyle[2] = {kBazHost, kStylePath}; | 83 const char* kStyle[2] = {kBazHost, kStylePath}; |
81 | 84 |
82 struct ResourceSummary { | 85 struct ResourceSummary { |
83 ResourceSummary() | 86 ResourceSummary() |
84 : version(0), | 87 : version(0), |
85 is_no_store(false), | 88 is_no_store(false), |
86 is_external(false), | 89 is_external(false), |
87 is_observable(true), | 90 is_observable(true), |
88 is_prohibited(false) {} | 91 is_prohibited(false), |
92 delay(base::TimeDelta()) { | |
alexilin
2017/04/21 13:49:05
This is not needed. base::TimeDelta isn't build-in
trevordixon
2017/04/25 12:46:09
Deleted.
| |
93 request.before_first_contentful_paint = true; | |
94 } | |
89 | 95 |
90 ResourcePrefetchPredictor::URLRequestSummary request; | 96 ResourcePrefetchPredictor::URLRequestSummary request; |
91 // Allows to update HTTP ETag. | 97 // Allows to update HTTP ETag. |
92 size_t version; | 98 size_t version; |
93 // True iff "Cache-control: no-store" header is present. | 99 // True iff "Cache-control: no-store" header is present. |
94 bool is_no_store; | 100 bool is_no_store; |
95 // True iff a request for this resource must be ignored by the custom handler. | 101 // True iff a request for this resource must be ignored by the custom handler. |
96 bool is_external; | 102 bool is_external; |
97 // True iff the LearningObserver must observe this resource. | 103 // True iff the LearningObserver must observe this resource. |
98 bool is_observable; | 104 bool is_observable; |
99 // A request with |is_prohibited| set to true makes the test that originates | 105 // A request with |is_prohibited| set to true makes the test that originates |
100 // the request fail. | 106 // the request fail. |
101 bool is_prohibited; | 107 bool is_prohibited; |
108 base::TimeDelta delay; | |
102 }; | 109 }; |
103 | 110 |
104 struct RedirectEdge { | 111 struct RedirectEdge { |
105 // This response code should be returned by previous url in the chain. | 112 // This response code should be returned by previous url in the chain. |
106 net::HttpStatusCode code; | 113 net::HttpStatusCode code; |
107 GURL url; | 114 GURL url; |
108 bool is_client_side; | 115 bool is_client_side; |
109 }; | 116 }; |
110 | 117 |
111 // Helper class to track and allow waiting for ResourcePrefetchPredictor | 118 // Helper class to track and allow waiting for ResourcePrefetchPredictor |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 } | 169 } |
163 | 170 |
164 // Fill a NavigationID with "empty" data that does not trigger | 171 // Fill a NavigationID with "empty" data that does not trigger |
165 // the is_valid DCHECK(). Allows comparing. | 172 // the is_valid DCHECK(). Allows comparing. |
166 void SetValidNavigationID(NavigationID* navigation_id) { | 173 void SetValidNavigationID(NavigationID* navigation_id) { |
167 navigation_id->tab_id = 0; | 174 navigation_id->tab_id = 0; |
168 navigation_id->main_frame_url = GURL("http://127.0.0.1"); | 175 navigation_id->main_frame_url = GURL("http://127.0.0.1"); |
169 } | 176 } |
170 | 177 |
171 void ModifySubresourceForComparison(URLRequestSummary* subresource, | 178 void ModifySubresourceForComparison(URLRequestSummary* subresource, |
172 bool match_navigation_id) { | 179 bool match_navigation_id, |
180 bool match_before_first_contentful_paint) { | |
173 if (!match_navigation_id) | 181 if (!match_navigation_id) |
174 SetValidNavigationID(&subresource->navigation_id); | 182 SetValidNavigationID(&subresource->navigation_id); |
183 if (!match_before_first_contentful_paint) | |
184 subresource->before_first_contentful_paint = true; | |
175 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE && | 185 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE && |
176 subresource->priority == net::LOWEST) { | 186 subresource->priority == net::LOWEST) { |
177 // Fuzzy comparison for images because an image priority can be | 187 // Fuzzy comparison for images because an image priority can be |
178 // boosted during layout via | 188 // boosted during layout via |
179 // ResourceFetcher::updateAllImageResourcePriorities(). | 189 // ResourceFetcher::updateAllImageResourcePriorities(). |
180 subresource->priority = net::MEDIUM; | 190 subresource->priority = net::MEDIUM; |
181 } | 191 } |
182 } | 192 } |
183 | 193 |
184 // Does a custom comparison of subresources of URLRequestSummary | 194 // Does a custom comparison of subresources of URLRequestSummary |
185 // and fail the test if the expectation is not met. | 195 // and fail the test if the expectation is not met. |
186 void CompareSubresources(std::vector<URLRequestSummary> actual_subresources, | 196 void CompareSubresources(std::vector<URLRequestSummary> actual_subresources, |
187 std::vector<URLRequestSummary> expected_subresources, | 197 std::vector<URLRequestSummary> expected_subresources, |
188 bool match_navigation_id) { | 198 bool match_navigation_id, |
199 bool match_before_first_contentful_paint) { | |
189 // Duplicate resources can be observed in a single navigation but | 200 // Duplicate resources can be observed in a single navigation but |
190 // ResourcePrefetchPredictor only cares about the first occurrence of each. | 201 // ResourcePrefetchPredictor only cares about the first occurrence of each. |
191 RemoveDuplicateSubresources(&actual_subresources); | 202 RemoveDuplicateSubresources(&actual_subresources); |
192 | 203 |
193 for (auto& subresource : actual_subresources) | 204 for (auto& subresource : actual_subresources) |
194 ModifySubresourceForComparison(&subresource, match_navigation_id); | 205 ModifySubresourceForComparison(&subresource, match_navigation_id, |
206 match_before_first_contentful_paint); | |
195 for (auto& subresource : expected_subresources) | 207 for (auto& subresource : expected_subresources) |
196 ModifySubresourceForComparison(&subresource, match_navigation_id); | 208 ModifySubresourceForComparison(&subresource, match_navigation_id, |
209 match_before_first_contentful_paint); | |
197 | 210 |
198 EXPECT_THAT(actual_subresources, | 211 EXPECT_THAT(actual_subresources, |
199 testing::UnorderedElementsAreArray(expected_subresources)); | 212 testing::UnorderedElementsAreArray(expected_subresources)); |
200 } | 213 } |
201 | 214 |
202 std::string CreateVersionedETag(size_t version, const std::string& path) { | 215 std::string CreateVersionedETag(size_t version, const std::string& path) { |
203 return base::StringPrintf("'%zu%s'", version, path.c_str()); | 216 return base::StringPrintf("'%zu%s'", version, path.c_str()); |
204 } | 217 } |
205 | 218 |
206 GURL GetRequestURL(const net::test_server::HttpRequest& request) { | 219 GURL GetRequestURL(const net::test_server::HttpRequest& request) { |
(...skipping 19 matching lines...) Expand all Loading... | |
226 // Helper class to track and allow waiting for a single OnNavigationLearned | 239 // Helper class to track and allow waiting for a single OnNavigationLearned |
227 // event. The information provided by this event is also used to verify that | 240 // event. The information provided by this event is also used to verify that |
228 // ResourcePrefetchPredictor works as expected. | 241 // ResourcePrefetchPredictor works as expected. |
229 class LearningObserver : public TestObserver { | 242 class LearningObserver : public TestObserver { |
230 public: | 243 public: |
231 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 244 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
232 | 245 |
233 LearningObserver(ResourcePrefetchPredictor* predictor, | 246 LearningObserver(ResourcePrefetchPredictor* predictor, |
234 const size_t expected_url_visit_count, | 247 const size_t expected_url_visit_count, |
235 const PageRequestSummary& expected_summary, | 248 const PageRequestSummary& expected_summary, |
236 bool match_navigation_id) | 249 bool match_navigation_id, |
250 bool match_before_first_contentful_paint) | |
237 : TestObserver(predictor), | 251 : TestObserver(predictor), |
238 url_visit_count_(expected_url_visit_count), | 252 url_visit_count_(expected_url_visit_count), |
239 summary_(expected_summary), | 253 summary_(expected_summary), |
240 match_navigation_id_(match_navigation_id) {} | 254 match_navigation_id_(match_navigation_id), |
255 match_before_first_contentful_paint_( | |
256 match_before_first_contentful_paint) {} | |
241 | 257 |
242 // TestObserver: | 258 // TestObserver: |
243 void OnNavigationLearned(size_t url_visit_count, | 259 void OnNavigationLearned(size_t url_visit_count, |
244 const PageRequestSummary& summary) override { | 260 const PageRequestSummary& summary) override { |
245 EXPECT_EQ(url_visit_count, url_visit_count_); | 261 EXPECT_EQ(url_visit_count, url_visit_count_); |
246 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); | 262 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); |
247 EXPECT_EQ(summary.initial_url, summary_.initial_url); | 263 EXPECT_EQ(summary.initial_url, summary_.initial_url); |
248 for (const auto& resource : summary.subresource_requests) | 264 for (const auto& resource : summary.subresource_requests) |
249 current_navigation_ids_.insert(resource.navigation_id); | 265 current_navigation_ids_.insert(resource.navigation_id); |
250 CompareSubresources(summary.subresource_requests, | 266 CompareSubresources(summary.subresource_requests, |
251 summary_.subresource_requests, match_navigation_id_); | 267 summary_.subresource_requests, match_navigation_id_, |
268 match_before_first_contentful_paint_); | |
252 run_loop_.Quit(); | 269 run_loop_.Quit(); |
253 } | 270 } |
254 | 271 |
255 void Wait() { run_loop_.Run(); } | 272 void Wait() { run_loop_.Run(); } |
256 | 273 |
257 std::set<NavigationID>& current_navigation_ids() { | 274 std::set<NavigationID>& current_navigation_ids() { |
258 return current_navigation_ids_; | 275 return current_navigation_ids_; |
259 } | 276 } |
260 | 277 |
261 private: | 278 private: |
262 base::RunLoop run_loop_; | 279 base::RunLoop run_loop_; |
263 size_t url_visit_count_; | 280 size_t url_visit_count_; |
264 PageRequestSummary summary_; | 281 PageRequestSummary summary_; |
265 bool match_navigation_id_; | 282 bool match_navigation_id_; |
283 bool match_before_first_contentful_paint_; | |
266 std::set<NavigationID> current_navigation_ids_; | 284 std::set<NavigationID> current_navigation_ids_; |
267 | 285 |
268 DISALLOW_COPY_AND_ASSIGN(LearningObserver); | 286 DISALLOW_COPY_AND_ASSIGN(LearningObserver); |
269 }; | 287 }; |
270 | 288 |
271 // Helper class to track and allow waiting for a single OnPrefetchingFinished | 289 // Helper class to track and allow waiting for a single OnPrefetchingFinished |
272 // event. Checks also that {Start,Stop}Prefetching are called with the right | 290 // event. Checks also that {Start,Stop}Prefetching are called with the right |
273 // argument. | 291 // argument. |
274 class PrefetchingObserver : public TestObserver { | 292 class PrefetchingObserver : public TestObserver { |
275 public: | 293 public: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 // URLs from the test server contain a port number. | 371 // URLs from the test server contain a port number. |
354 ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(true); | 372 ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(true); |
355 EnsurePredictorInitialized(); | 373 EnsurePredictorInitialized(); |
356 histogram_tester_.reset(new base::HistogramTester()); | 374 histogram_tester_.reset(new base::HistogramTester()); |
357 } | 375 } |
358 | 376 |
359 void TearDownOnMainThread() override { | 377 void TearDownOnMainThread() override { |
360 ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(false); | 378 ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(false); |
361 } | 379 } |
362 | 380 |
363 void TestLearningAndPrefetching(const GURL& main_frame_url) { | 381 void TestLearningAndPrefetching( |
382 const GURL& main_frame_url, | |
383 bool match_before_first_contentful_paint = false) { | |
alexilin
2017/04/21 13:49:05
Maybe as a global/class member to avoid this plumb
trevordixon
2017/04/25 20:23:55
Most of the plumbing goes through LearningObserver
alexilin
2017/04/26 09:25:01
Fair enough! sgtm.
| |
364 // Navigate to |main_frame_url| and check all the expectations. | 384 // Navigate to |main_frame_url| and check all the expectations. |
365 NavigateToURLAndCheckSubresources(main_frame_url); | 385 NavigateToURLAndCheckSubresources(main_frame_url, |
386 WindowOpenDisposition::CURRENT_TAB, | |
387 match_before_first_contentful_paint); | |
366 ClearCache(); | 388 ClearCache(); |
367 // It is needed to have at least two resource hits to trigger prefetch. | 389 // It is needed to have at least two resource hits to trigger prefetch. |
368 NavigateToURLAndCheckSubresources(main_frame_url); | 390 NavigateToURLAndCheckSubresources(main_frame_url, |
391 WindowOpenDisposition::CURRENT_TAB, | |
392 match_before_first_contentful_paint); | |
369 ClearCache(); | 393 ClearCache(); |
370 // Prefetch all needed resources and change expectations so that all | 394 // Prefetch all needed resources and change expectations so that all |
371 // cacheable resources should be served from cache next navigation. | 395 // cacheable resources should be served from cache next navigation. |
372 PrefetchURL(main_frame_url); | 396 PrefetchURL(main_frame_url); |
373 // To be sure that the browser send no requests to the server after | 397 // To be sure that the browser send no requests to the server after |
374 // prefetching. | 398 // prefetching. |
375 NavigateToURLAndCheckSubresourcesAllCached(main_frame_url); | 399 NavigateToURLAndCheckSubresourcesAllCached(main_frame_url); |
alexilin
2017/04/21 13:49:05
You could pass match_before_first_contentful_paint
trevordixon
2017/04/25 12:46:09
All resources are before_first_contentful_paint af
alexilin
2017/04/26 09:25:01
Yes, you're right. It'd be better to not race with
| |
376 } | 400 } |
377 | 401 |
378 void NavigateToURLAndCheckSubresourcesAllCached(const GURL& navigation_url) { | 402 void NavigateToURLAndCheckSubresourcesAllCached(const GURL& navigation_url) { |
379 for (auto& kv : resources_) { | 403 for (auto& kv : resources_) { |
380 if (kv.second.is_observable) | 404 if (kv.second.is_observable) |
381 kv.second.is_prohibited = true; | 405 kv.second.is_prohibited = true; |
382 } | 406 } |
383 NavigateToURLAndCheckSubresources(navigation_url); | 407 NavigateToURLAndCheckSubresources(navigation_url); |
384 for (auto& kv : resources_) { | 408 for (auto& kv : resources_) { |
385 if (kv.second.is_observable) | 409 if (kv.second.is_observable) |
386 kv.second.is_prohibited = false; | 410 kv.second.is_prohibited = false; |
387 } | 411 } |
388 } | 412 } |
389 | 413 |
390 void NavigateToURLAndCheckSubresources( | 414 void NavigateToURLAndCheckSubresources( |
391 const GURL& navigation_url, | 415 const GURL& navigation_url, |
392 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { | 416 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB, |
417 bool match_before_first_contentful_paint = false) { | |
393 GURL initial_url = GetLastClientSideRedirectEndpoint(navigation_url); | 418 GURL initial_url = GetLastClientSideRedirectEndpoint(navigation_url); |
394 GURL main_frame_url = GetRedirectEndpoint(navigation_url); | 419 GURL main_frame_url = GetRedirectEndpoint(navigation_url); |
395 std::vector<URLRequestSummary> url_request_summaries; | 420 std::vector<URLRequestSummary> url_request_summaries; |
396 for (const auto& kv : resources_) { | 421 for (const auto& kv : resources_) { |
397 if (kv.second.is_observable) { | 422 if (kv.second.is_observable) { |
398 url_request_summaries.push_back( | 423 url_request_summaries.push_back( |
399 GetURLRequestSummaryForResource(main_frame_url, kv.second)); | 424 GetURLRequestSummaryForResource(main_frame_url, kv.second)); |
400 } | 425 } |
401 } | 426 } |
402 | 427 |
403 bool match_navigation_id = | 428 bool match_navigation_id = |
404 disposition == WindowOpenDisposition::CURRENT_TAB; | 429 disposition == WindowOpenDisposition::CURRENT_TAB; |
405 | 430 |
406 LearningObserver observer( | 431 LearningObserver observer( |
407 predictor_, UpdateAndGetVisitCount(initial_url), | 432 predictor_, UpdateAndGetVisitCount(initial_url), |
408 CreatePageRequestSummary(main_frame_url.spec(), initial_url.spec(), | 433 CreatePageRequestSummary(main_frame_url.spec(), initial_url.spec(), |
409 url_request_summaries), | 434 url_request_summaries), |
410 match_navigation_id); | 435 match_navigation_id, match_before_first_contentful_paint); |
411 ui_test_utils::NavigateToURLWithDisposition( | 436 ui_test_utils::NavigateToURLWithDisposition( |
412 browser(), navigation_url, disposition, | 437 browser(), navigation_url, disposition, |
413 ui_test_utils::BROWSER_TEST_NONE); | 438 ui_test_utils::BROWSER_TEST_NONE); |
414 observer.Wait(); | 439 observer.Wait(); |
415 | 440 |
416 for (auto& kv : resources_) { | 441 for (auto& kv : resources_) { |
417 if (kv.second.is_observable) | 442 if (kv.second.is_observable) |
418 kv.second.request.was_cached = true; | 443 kv.second.request.was_cached = true; |
419 } | 444 } |
420 for (const auto& nav : observer.current_navigation_ids()) | 445 for (const auto& nav : observer.current_navigation_ids()) |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 } | 690 } |
666 if (summary.request.always_revalidate) | 691 if (summary.request.always_revalidate) |
667 http_response->AddCustomHeader("Cache-Control", "no-cache"); | 692 http_response->AddCustomHeader("Cache-Control", "no-cache"); |
668 else | 693 else |
669 http_response->AddCustomHeader("Cache-Control", "max-age=2147483648"); | 694 http_response->AddCustomHeader("Cache-Control", "max-age=2147483648"); |
670 | 695 |
671 // Add some content, otherwise the prefetch size histogram rounds down to | 696 // Add some content, otherwise the prefetch size histogram rounds down to |
672 // 0kB. | 697 // 0kB. |
673 http_response->set_content(std::string(1024, ' ')); | 698 http_response->set_content(std::string(1024, ' ')); |
674 | 699 |
700 if (!summary.delay.is_zero()) { | |
701 base::PlatformThread::Sleep(summary.delay); | |
702 } | |
703 | |
675 return std::move(http_response); | 704 return std::move(http_response); |
676 } | 705 } |
677 | 706 |
678 // The custom handler for redirect requests from the browser to an | 707 // The custom handler for redirect requests from the browser to an |
679 // EmbeddedTestServer. Running on the EmbeddedTestServer IO thread. | 708 // EmbeddedTestServer. Running on the EmbeddedTestServer IO thread. |
680 // Finds the data to serve requests in |redirects_| map keyed by a request | 709 // Finds the data to serve requests in |redirects_| map keyed by a request |
681 // URL. | 710 // URL. |
682 std::unique_ptr<net::test_server::HttpResponse> HandleRedirectRequest( | 711 std::unique_ptr<net::test_server::HttpResponse> HandleRedirectRequest( |
683 const net::test_server::HttpRequest& request) const { | 712 const net::test_server::HttpRequest& request) const { |
684 std::map<GURL, RedirectEdge>::const_iterator redirect_it = | 713 std::map<GURL, RedirectEdge>::const_iterator redirect_it = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 histogram_tester_->ExpectBucketCount( | 764 histogram_tester_->ExpectBucketCount( |
736 internal::kResourcePrefetchPredictorPrefetchHitsCountNotCached, 4, 1); | 765 internal::kResourcePrefetchPredictorPrefetchHitsCountNotCached, 4, 1); |
737 | 766 |
738 histogram_tester_->ExpectBucketCount( | 767 histogram_tester_->ExpectBucketCount( |
739 internal::kResourcePrefetchPredictorPrefetchMissesSize, 0, 1); | 768 internal::kResourcePrefetchPredictorPrefetchMissesSize, 0, 1); |
740 // Each request is ~1k, see HandleResourceRequest() above. | 769 // Each request is ~1k, see HandleResourceRequest() above. |
741 histogram_tester_->ExpectBucketCount( | 770 histogram_tester_->ExpectBucketCount( |
742 internal::kResourcePrefetchPredictorPrefetchHitsSize, 4, 1); | 771 internal::kResourcePrefetchPredictorPrefetchHitsSize, 4, 1); |
743 } | 772 } |
744 | 773 |
774 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | |
775 SubresourceFcpOrder) { | |
776 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | |
777 net::HIGHEST); | |
778 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
779 | |
780 ResourceSummary* long_script = AddResource( | |
781 GetURL(kScriptLongPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
782 long_script->delay = base::TimeDelta::FromMilliseconds(1500); | |
alexilin
2017/04/21 13:49:05
We'll hope that this is enough for the slowest tes
trevordixon
2017/04/25 12:46:10
Is 1500 milliseconds a good guess? Might as well g
alexilin
2017/04/25 18:42:21
It should be enough. But if this test turns out to
trevordixon
2017/04/25 20:23:55
Added a comment.
| |
783 long_script->request.before_first_contentful_paint = false; | |
784 | |
785 ResourceSummary* image = AddResource( | |
786 GetURL(kImageRealPath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
alexilin
2017/04/21 13:49:05
Is there any special reason why you need to have a
trevordixon
2017/04/25 12:46:10
I needed a real image for another reason, but that
| |
787 image->request.before_first_contentful_paint = false; | |
788 | |
789 TestLearningAndPrefetching(GetURL(kHtmlFcpOrderPath), true); | |
790 } | |
791 | |
745 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Redirect) { | 792 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Redirect) { |
746 GURL initial_url = GetURLWithHost(kFooHost, kRedirectPath); | 793 GURL initial_url = GetURLWithHost(kFooHost, kRedirectPath); |
747 GURL redirected_url = | 794 GURL redirected_url = |
748 GetPageURLWithReplacements(kBarHost, kHtmlSubresourcesPath); | 795 GetPageURLWithReplacements(kBarHost, kHtmlSubresourcesPath); |
749 AddRedirectChain(initial_url, | 796 AddRedirectChain(initial_url, |
750 {{net::HTTP_MOVED_PERMANENTLY, redirected_url}}); | 797 {{net::HTTP_MOVED_PERMANENTLY, redirected_url}}); |
751 AddResourcesFromSubresourceHtml(); | 798 AddResourcesFromSubresourceHtml(); |
752 TestLearningAndPrefetching(initial_url); | 799 TestLearningAndPrefetching(initial_url); |
753 } | 800 } |
754 | 801 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 AddResourcesFromSubresourceHtml(); | 1009 AddResourcesFromSubresourceHtml(); |
963 | 1010 |
964 NavigateToURLAndCheckSubresources(initial_url); | 1011 NavigateToURLAndCheckSubresources(initial_url); |
965 ClearCache(); | 1012 ClearCache(); |
966 NavigateToURLAndCheckSubresources(initial_url); | 1013 NavigateToURLAndCheckSubresources(initial_url); |
967 ClearCache(); | 1014 ClearCache(); |
968 NavigateToURLAndCheckPrefetching(initial_url); | 1015 NavigateToURLAndCheckPrefetching(initial_url); |
969 } | 1016 } |
970 | 1017 |
971 } // namespace predictors | 1018 } // namespace predictors |
OLD | NEW |