Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc

Issue 2529263003: predictors: Ignore repeating subresources while checking. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc
index 4981a2a2fffb486d5a090044142b217c01d34091..3c013ab4b3226f9241530cc54a981515dee46aa0 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc
@@ -61,12 +61,31 @@ 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(
Benoit L 2016/11/28 14:58:04 nit: why not just a copy?
alexilin 2016/11/28 15:12:15 Done.
+ summary.subresource_requests.begin(), summary.subresource_requests.end());
+ std::sort(subresources.begin(), subresources.end(),
Benoit L 2016/11/28 14:58:04 Do you need stable_sort here?
alexilin 2016/11/28 15:12:15 Thanks! Indeed we need first occurrences of each s
+ [](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;
+}
+
// Helper class to track and allow waiting for ResourcePrefetchPredictor events.
// These events are also used to verify that ResourcePrefetchPredictor works as
// expected.
class ResourcePrefetchPredictorTestObserver : public TestObserver {
public:
- using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary;
explicit ResourcePrefetchPredictorTestObserver(
ResourcePrefetchPredictor* predictor,
@@ -83,7 +102,7 @@ class ResourcePrefetchPredictorTestObserver : public TestObserver {
EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url);
EXPECT_EQ(summary.initial_url, summary_.initial_url);
EXPECT_THAT(
Benoit L 2016/11/28 14:58:04 Can you add a comment to explain that we have dupl
alexilin 2016/11/28 15:12:15 Done.
- summary.subresource_requests,
+ GetUniqueSubresources(summary),
testing::UnorderedElementsAreArray(summary_.subresource_requests));
run_loop_.Quit();
}
@@ -100,7 +119,6 @@ class ResourcePrefetchPredictorTestObserver : public TestObserver {
class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest {
protected:
- using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698