Commit 3fbb2642 authored by alexilin's avatar alexilin Committed by Commit bot

predictors: Ignore repeating subresources while checking.

This eliminates one of the sources of flakiness in
ResourcePrefetchPredictorBrowserTest.
It seems impossible to avoid an emergence of several requests belonging to the
same subresource but we could just ignore them as real code does.
The real code also ignores repeating entries of the same subresource but doesn't
modify collection passing to test observer.

BUG=650253

Review-Url: https://codereview.chromium.org/2529263003
Cr-Commit-Position: refs/heads/master@{#434951}
parent 0d088cf0
......@@ -21,6 +21,8 @@
namespace predictors {
namespace {
static const char kImagePath[] = "/predictors/image.png";
static const char kStylePath[] = "/predictors/style.css";
static const char kScriptPath[] = "/predictors/script.js";
......@@ -61,6 +63,27 @@ class InitializationObserver : public TestObserver {
DISALLOW_COPY_AND_ASSIGN(InitializationObserver);
};
using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary;
using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
std::vector<URLRequestSummary> GetUniqueSubresources(
const PageRequestSummary& summary) {
std::vector<URLRequestSummary> subresources(summary.subresource_requests);
std::stable_sort(subresources.begin(), subresources.end(),
[](const URLRequestSummary& x, const URLRequestSummary& y) {
return x.resource_url < y.resource_url;
});
subresources.erase(
std::unique(subresources.begin(), subresources.end(),
[](const URLRequestSummary& x, const URLRequestSummary& y) {
return x.resource_url == y.resource_url;
}),
subresources.end());
return subresources;
}
} // namespace
// Helper class to track and allow waiting for ResourcePrefetchPredictor events.
// These events are also used to verify that ResourcePrefetchPredictor works as
// expected.
......@@ -82,9 +105,12 @@ class ResourcePrefetchPredictorTestObserver : public TestObserver {
EXPECT_EQ(url_visit_count, url_visit_count_);
EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url);
EXPECT_EQ(summary.initial_url, summary_.initial_url);
EXPECT_THAT(
summary.subresource_requests,
testing::UnorderedElementsAreArray(summary_.subresource_requests));
// Duplicate resources can be observed in a single navigation but
// ResourcePrefetchPredictor only cares about the first occurrence of each.
std::vector<ResourcePrefetchPredictor::URLRequestSummary> subresources =
GetUniqueSubresources(summary);
EXPECT_THAT(subresources, testing::UnorderedElementsAreArray(
summary_.subresource_requests));
run_loop_.Quit();
}
......
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