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