Commit 54585e4c authored by alexilin's avatar alexilin Committed by Commit bot

predictors: Fuzzy comparison of request priority for images.

The browser tests for ResourcePrefetchPredictor check that the actual
request priority is equal to the expected value. But for the images the
priority cannot be precisely defined because there is a race between the
preload scanner issuing fetch requests and frame view performing layout
and promoting priorities of all visible images.

BUG=650253,673028

Review-Url: https://codereview.chromium.org/2569723002
Cr-Commit-Position: refs/heads/master@{#437958}
parent 348e013f
......@@ -112,6 +112,19 @@ void SetValidNavigationID(NavigationID* navigation_id) {
navigation_id->main_frame_url = GURL("http://127.0.0.1");
}
void ModifySubresourceForComparison(URLRequestSummary* subresource,
bool match_navigation_id) {
if (!match_navigation_id)
SetValidNavigationID(&subresource->navigation_id);
if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE &&
subresource->priority == net::LOWEST) {
// Fuzzy comparison for images because an image priority can be
// boosted during layout via
// ResourceFetcher::updateAllImageResourcePriorities().
subresource->priority = net::MEDIUM;
}
}
// Does a custom comparison of subresources of URLRequestSummary
// and fail the test if the expectation is not met.
void CompareSubresources(std::vector<URLRequestSummary> actual_subresources,
......@@ -121,12 +134,11 @@ void CompareSubresources(std::vector<URLRequestSummary> actual_subresources,
// ResourcePrefetchPredictor only cares about the first occurrence of each.
RemoveDuplicateSubresources(&actual_subresources);
if (!match_navigation_id) {
for (auto& subresource : actual_subresources)
SetValidNavigationID(&subresource.navigation_id);
for (auto& subresource : expected_subresources)
SetValidNavigationID(&subresource.navigation_id);
}
for (auto& subresource : actual_subresources)
ModifySubresourceForComparison(&subresource, match_navigation_id);
for (auto& subresource : expected_subresources)
ModifySubresourceForComparison(&subresource, match_navigation_id);
EXPECT_THAT(actual_subresources,
testing::UnorderedElementsAreArray(expected_subresources));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment