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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc

Issue 2569723002: predictors: Fuzzy comparison of request priority for images. (Closed)
Patch Set: Rebase. 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 6 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" 7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" 8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 // Fill a NavigationID with "empty" data that does not trigger 107 // Fill a NavigationID with "empty" data that does not trigger
108 // the is_valid DCHECK(). Allows comparing. 108 // the is_valid DCHECK(). Allows comparing.
109 void SetValidNavigationID(NavigationID* navigation_id) { 109 void SetValidNavigationID(NavigationID* navigation_id) {
110 navigation_id->render_process_id = 0; 110 navigation_id->render_process_id = 0;
111 navigation_id->render_frame_id = 0; 111 navigation_id->render_frame_id = 0;
112 navigation_id->main_frame_url = GURL("http://127.0.0.1"); 112 navigation_id->main_frame_url = GURL("http://127.0.0.1");
113 } 113 }
114 114
115 void ModifySubresourceForComparison(URLRequestSummary* subresource,
116 bool match_navigation_id) {
117 if (!match_navigation_id)
118 SetValidNavigationID(&subresource->navigation_id);
119 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE &&
120 subresource->priority == net::LOWEST) {
121 // Fuzzy comparison for images because an image priority can be
122 // boosted during layout via
123 // ResourceFetcher::updateAllImageResourcePriorities().
124 subresource->priority = net::MEDIUM;
125 }
126 }
127
115 // Does a custom comparison of subresources of URLRequestSummary 128 // Does a custom comparison of subresources of URLRequestSummary
116 // and fail the test if the expectation is not met. 129 // and fail the test if the expectation is not met.
117 void CompareSubresources(std::vector<URLRequestSummary> actual_subresources, 130 void CompareSubresources(std::vector<URLRequestSummary> actual_subresources,
118 std::vector<URLRequestSummary> expected_subresources, 131 std::vector<URLRequestSummary> expected_subresources,
119 bool match_navigation_id) { 132 bool match_navigation_id) {
120 // Duplicate resources can be observed in a single navigation but 133 // Duplicate resources can be observed in a single navigation but
121 // ResourcePrefetchPredictor only cares about the first occurrence of each. 134 // ResourcePrefetchPredictor only cares about the first occurrence of each.
122 RemoveDuplicateSubresources(&actual_subresources); 135 RemoveDuplicateSubresources(&actual_subresources);
123 136
124 if (!match_navigation_id) { 137 for (auto& subresource : actual_subresources)
125 for (auto& subresource : actual_subresources) 138 ModifySubresourceForComparison(&subresource, match_navigation_id);
126 SetValidNavigationID(&subresource.navigation_id); 139 for (auto& subresource : expected_subresources)
127 for (auto& subresource : expected_subresources) 140 ModifySubresourceForComparison(&subresource, match_navigation_id);
128 SetValidNavigationID(&subresource.navigation_id); 141
129 }
130 EXPECT_THAT(actual_subresources, 142 EXPECT_THAT(actual_subresources,
131 testing::UnorderedElementsAreArray(expected_subresources)); 143 testing::UnorderedElementsAreArray(expected_subresources));
132 } 144 }
133 145
134 } // namespace 146 } // namespace
135 147
136 // Helper class to track and allow waiting for ResourcePrefetchPredictor events. 148 // Helper class to track and allow waiting for ResourcePrefetchPredictor events.
137 // These events are also used to verify that ResourcePrefetchPredictor works as 149 // These events are also used to verify that ResourcePrefetchPredictor works as
138 // expected. 150 // expected.
139 class ResourcePrefetchPredictorTestObserver : public TestObserver { 151 class ResourcePrefetchPredictorTestObserver : public TestObserver {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, 523 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET,
512 net::HIGHEST); 524 net::HIGHEST);
513 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); 525 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM);
514 // Included from <iframe src="html_subresources.html"> and not recored. 526 // Included from <iframe src="html_subresources.html"> and not recored.
515 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), 527 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath),
516 GetURL(kScriptPath), GetURL(kFontPath)}); 528 GetURL(kScriptPath), GetURL(kFontPath)});
517 NavigateToURLAndCheckSubresources(GetURL(kHtmlIframePath)); 529 NavigateToURLAndCheckSubresources(GetURL(kHtmlIframePath));
518 } 530 }
519 531
520 } // namespace predictors 532 } // namespace predictors
OLDNEW
« 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