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

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

Issue 2561493003: Rework of ResourcePrefetchPredictor browser tests infrastructure. (Closed)
Patch Set: Using BROWSER_TEST_NONE Created 4 years 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 91e3d93786e17c3e8a87925d0a4301fed1fa73b3..2942b6c42253972fb62dd0fd2c84fa35ff6d7bf4 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc
@@ -107,6 +107,14 @@ std::vector<URLRequestSummary> GetUniqueSubresources(
return subresources;
}
+// Fill a NavigationID with "empty" data that does not trigger
+// the is_valid DCHECK(). Allows comparing.
+void EmptyNavigationId(NavigationID* navigation_id) {
+ navigation_id->render_process_id = 0;
+ navigation_id->render_frame_id = 0;
+ navigation_id->main_frame_url = GURL("http://127.0.0.1");
+}
+
} // namespace
// Helper class to track and allow waiting for ResourcePrefetchPredictor events.
@@ -119,10 +127,12 @@ class ResourcePrefetchPredictorTestObserver : public TestObserver {
explicit ResourcePrefetchPredictorTestObserver(
ResourcePrefetchPredictor* predictor,
const size_t expected_url_visit_count,
- const PageRequestSummary& expected_summary)
+ const PageRequestSummary& expected_summary,
+ bool match_navigation_id)
: TestObserver(predictor),
url_visit_count_(expected_url_visit_count),
- summary_(expected_summary) {}
+ summary_(expected_summary),
+ match_navigation_id_(match_navigation_id) {}
// TestObserver:
void OnNavigationLearned(size_t url_visit_count,
@@ -132,10 +142,20 @@ class ResourcePrefetchPredictorTestObserver : public TestObserver {
EXPECT_EQ(summary.initial_url, summary_.initial_url);
// 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));
+ std::vector<ResourcePrefetchPredictor::URLRequestSummary>
alexilin 2016/12/07 16:57:12 Probably, it could be better to extract the code r
ahemery 2016/12/08 11:08:45 Extracted in CompareSubresources(...)
+ subresources_results = GetUniqueSubresources(summary);
alexilin 2016/12/07 16:57:11 nit: I'd prefer different naming. For example, act
ahemery 2016/12/08 11:08:44 Renamed
+ std::vector<ResourcePrefetchPredictor::URLRequestSummary> subresources_ref(
+ summary_.subresource_requests);
+ if (!match_navigation_id_) {
+ for (auto& subresource : subresources_ref) {
alexilin 2016/12/07 16:57:11 nit: Remove curly brace.
ahemery 2016/12/08 11:08:44 Done
+ EmptyNavigationId(&subresource.navigation_id);
+ }
+ for (auto& subresource : subresources_results) {
alexilin 2016/12/07 16:57:12 ditto
+ EmptyNavigationId(&subresource.navigation_id);
+ }
+ }
+ EXPECT_THAT(subresources_results,
+ testing::UnorderedElementsAreArray(subresources_ref));
run_loop_.Quit();
}
@@ -145,6 +165,7 @@ class ResourcePrefetchPredictorTestObserver : public TestObserver {
base::RunLoop run_loop_;
size_t url_visit_count_;
PageRequestSummary summary_;
+ bool match_navigation_id_;
DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTestObserver);
};
@@ -173,7 +194,9 @@ class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest {
EnsurePredictorInitialized();
}
- void NavigateToURLAndCheckSubresources(const GURL& main_frame_url) {
+ void NavigateToURLAndCheckSubresources(
+ const GURL& main_frame_url,
+ WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) {
GURL endpoint_url = GetRedirectEndpoint(main_frame_url);
std::vector<URLRequestSummary> url_request_summaries;
for (const auto& kv : resources_) {
@@ -182,11 +205,16 @@ class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest {
url_request_summaries.push_back(
GetURLRequestSummaryForResource(endpoint_url, kv.second));
}
+ bool match_navigation_id =
+ (disposition == WindowOpenDisposition::CURRENT_TAB);
ResourcePrefetchPredictorTestObserver observer(
predictor_, UpdateAndGetVisitCount(main_frame_url),
CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(),
- url_request_summaries));
- ui_test_utils::NavigateToURL(browser(), main_frame_url);
+ url_request_summaries),
+ match_navigation_id);
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), main_frame_url, disposition,
+ ui_test_utils::BROWSER_TEST_NONE);
observer.Wait();
}
@@ -489,4 +517,26 @@ IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest,
NavigateToURLAndCheckSubresources(GetURL(kHtmlIframePath));
}
+IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, LearningInPopup) {
+ AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST);
+ AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET,
+ net::HIGHEST);
+ AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM);
+ AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE,
+ net::HIGHEST);
+ NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath),
+ WindowOpenDisposition::NEW_POPUP);
+}
+
+IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, LearningInNewTab) {
+ AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE,
alexilin 2016/12/07 16:57:11 Why font resource became first in the list?
ahemery 2016/12/08 11:08:44 Corrected, see main comment
alexilin 2016/12/08 12:57:25 There wasn't any logical mistake it was just a lit
+ net::HIGHEST);
+ AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST);
+ AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET,
+ net::HIGHEST);
+ AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM);
+ NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath),
+ WindowOpenDisposition::NEW_FOREGROUND_TAB);
+}
+
} // namespace predictors
« 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