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

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

Issue 2440723002: predictors: Make ResourcePrefetchPredictor observable. (Closed)
Patch Set: Move TestObserver outside ResourcePrefetchPredictor class. 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 unified diff | Download patch
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 "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" 5 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
6 6
7 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" 7 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
8 8
9 namespace predictors { 9 namespace predictors {
10 10
11 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
12 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary;
13
11 void InitializeResourceData(ResourceData* resource, 14 void InitializeResourceData(ResourceData* resource,
12 const std::string& resource_url, 15 const std::string& resource_url,
13 content::ResourceType resource_type, 16 content::ResourceType resource_type,
14 int number_of_hits, 17 int number_of_hits,
15 int number_of_misses, 18 int number_of_misses,
16 int consecutive_misses, 19 int consecutive_misses,
17 double average_position, 20 double average_position,
18 net::RequestPriority priority, 21 net::RequestPriority priority,
19 bool has_validators, 22 bool has_validators,
20 bool always_revalidate) { 23 bool always_revalidate) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 os << "\t\t" << redirect << std::endl; 85 os << "\t\t" << redirect << std::endl;
83 return os; 86 return os;
84 } 87 }
85 88
86 std::ostream& operator<<(std::ostream& os, const RedirectStat& redirect) { 89 std::ostream& operator<<(std::ostream& os, const RedirectStat& redirect) {
87 return os << "[" << redirect.url() << "," << redirect.number_of_hits() << "," 90 return os << "[" << redirect.url() << "," << redirect.number_of_hits() << ","
88 << redirect.number_of_misses() << "," 91 << redirect.number_of_misses() << ","
89 << redirect.consecutive_misses() << "]"; 92 << redirect.consecutive_misses() << "]";
90 } 93 }
91 94
95 std::ostream& operator<<(std::ostream& os, const PageRequestSummary& summary) {
96 os << "[" << summary.main_frame_url << "," << summary.initial_url << "]"
97 << std::endl;
98 for (const auto& request : summary.subresource_requests)
99 os << "\t\t" << request << std::endl;
100 return os;
101 }
102
103 std::ostream& operator<<(std::ostream& os, const URLRequestSummary& summary) {
104 return os << "[" << summary.navigation_id << "," << summary.resource_url
105 << "," << summary.resource_type << "," << summary.priority << ","
106 << summary.mime_type << "," << summary.was_cached << ","
107 << summary.redirect_url << "," << summary.has_validators << ","
108 << summary.always_revalidate << "]";
109 }
110
111 std::ostream& operator<<(std::ostream& os, const NavigationID& navigation_id) {
112 return os << navigation_id.render_process_id << ","
113 << navigation_id.render_frame_id << ","
114 << navigation_id.main_frame_url;
115 }
116
92 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { 117 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) {
93 bool equal = lhs.primary_key() == rhs.primary_key() && 118 bool equal = lhs.primary_key() == rhs.primary_key() &&
94 lhs.resources_size() == rhs.resources_size(); 119 lhs.resources_size() == rhs.resources_size();
95 120
96 if (!equal) 121 if (!equal)
97 return false; 122 return false;
98 123
99 for (int i = 0; i < lhs.resources_size(); ++i) 124 for (int i = 0; i < lhs.resources_size(); ++i)
100 equal = equal && lhs.resources(i) == rhs.resources(i); 125 equal = equal && lhs.resources(i) == rhs.resources(i);
101 126
(...skipping 25 matching lines...) Expand all
127 return equal; 152 return equal;
128 } 153 }
129 154
130 bool operator==(const RedirectStat& lhs, const RedirectStat& rhs) { 155 bool operator==(const RedirectStat& lhs, const RedirectStat& rhs) {
131 return lhs.url() == rhs.url() && 156 return lhs.url() == rhs.url() &&
132 lhs.number_of_hits() == rhs.number_of_hits() && 157 lhs.number_of_hits() == rhs.number_of_hits() &&
133 lhs.number_of_misses() == rhs.number_of_misses() && 158 lhs.number_of_misses() == rhs.number_of_misses() &&
134 lhs.consecutive_misses() == rhs.consecutive_misses(); 159 lhs.consecutive_misses() == rhs.consecutive_misses();
135 } 160 }
136 161
162 bool operator==(const PageRequestSummary& lhs, const PageRequestSummary& rhs) {
163 return lhs.main_frame_url == rhs.main_frame_url &&
164 lhs.initial_url == rhs.initial_url &&
165 lhs.subresource_requests == rhs.subresource_requests;
166 }
167
168 bool operator==(const URLRequestSummary& lhs, const URLRequestSummary& rhs) {
169 return lhs.navigation_id == rhs.navigation_id &&
170 lhs.resource_url == rhs.resource_url &&
171 lhs.resource_type == rhs.resource_type &&
172 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type &&
173 lhs.was_cached == rhs.was_cached &&
174 lhs.redirect_url == rhs.redirect_url &&
175 lhs.has_validators == rhs.has_validators &&
176 lhs.always_revalidate == rhs.always_revalidate;
177 }
178
137 } // namespace predictors 179 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698