OLD | NEW |
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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 bool has_validators, | 30 bool has_validators, |
31 bool always_revalidate) { | 31 bool always_revalidate) { |
32 resource->set_resource_url(resource_url); | 32 resource->set_resource_url(resource_url); |
33 resource->set_resource_type( | 33 resource->set_resource_type( |
34 static_cast<ResourceData::ResourceType>(resource_type)); | 34 static_cast<ResourceData::ResourceType>(resource_type)); |
35 resource->set_number_of_hits(number_of_hits); | 35 resource->set_number_of_hits(number_of_hits); |
36 resource->set_number_of_misses(number_of_misses); | 36 resource->set_number_of_misses(number_of_misses); |
37 resource->set_consecutive_misses(consecutive_misses); | 37 resource->set_consecutive_misses(consecutive_misses); |
38 resource->set_average_position(average_position); | 38 resource->set_average_position(average_position); |
39 resource->set_priority(static_cast<ResourceData::Priority>(priority)); | 39 resource->set_priority(static_cast<ResourceData::Priority>(priority)); |
| 40 resource->set_before_first_contentful_paint(true); |
40 resource->set_has_validators(has_validators); | 41 resource->set_has_validators(has_validators); |
41 resource->set_always_revalidate(always_revalidate); | 42 resource->set_always_revalidate(always_revalidate); |
42 } | 43 } |
43 | 44 |
44 void InitializeRedirectStat(RedirectStat* redirect, | 45 void InitializeRedirectStat(RedirectStat* redirect, |
45 const std::string& url, | 46 const std::string& url, |
46 int number_of_hits, | 47 int number_of_hits, |
47 int number_of_misses, | 48 int number_of_misses, |
48 int consecutive_misses) { | 49 int consecutive_misses) { |
49 redirect->set_url(url); | 50 redirect->set_url(url); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const std::string& redirect_url, | 157 const std::string& redirect_url, |
157 bool has_validators, | 158 bool has_validators, |
158 bool always_revalidate) { | 159 bool always_revalidate) { |
159 URLRequestSummary summary; | 160 URLRequestSummary summary; |
160 summary.navigation_id = CreateNavigationID(tab_id, main_frame_url); | 161 summary.navigation_id = CreateNavigationID(tab_id, main_frame_url); |
161 summary.resource_url = | 162 summary.resource_url = |
162 resource_url.empty() ? GURL(main_frame_url) : GURL(resource_url); | 163 resource_url.empty() ? GURL(main_frame_url) : GURL(resource_url); |
163 summary.request_url = summary.resource_url; | 164 summary.request_url = summary.resource_url; |
164 summary.resource_type = resource_type; | 165 summary.resource_type = resource_type; |
165 summary.priority = priority; | 166 summary.priority = priority; |
| 167 summary.before_first_contentful_paint = true; |
166 summary.mime_type = mime_type; | 168 summary.mime_type = mime_type; |
167 summary.was_cached = was_cached; | 169 summary.was_cached = was_cached; |
168 if (!redirect_url.empty()) | 170 if (!redirect_url.empty()) |
169 summary.redirect_url = GURL(redirect_url); | 171 summary.redirect_url = GURL(redirect_url); |
170 summary.has_validators = has_validators; | 172 summary.has_validators = has_validators; |
171 summary.always_revalidate = always_revalidate; | 173 summary.always_revalidate = always_revalidate; |
172 summary.is_no_store = false; | 174 summary.is_no_store = false; |
173 summary.network_accessed = true; | 175 summary.network_accessed = true; |
174 return summary; | 176 return summary; |
175 } | 177 } |
176 | 178 |
177 std::ostream& operator<<(std::ostream& os, const PrefetchData& data) { | 179 std::ostream& operator<<(std::ostream& os, const PrefetchData& data) { |
178 os << "[" << data.primary_key() << "," << data.last_visit_time() << "]" | 180 os << "[" << data.primary_key() << "," << data.last_visit_time() << "]" |
179 << std::endl; | 181 << std::endl; |
180 for (const ResourceData& resource : data.resources()) | 182 for (const ResourceData& resource : data.resources()) |
181 os << "\t\t" << resource << std::endl; | 183 os << "\t\t" << resource << std::endl; |
182 return os; | 184 return os; |
183 } | 185 } |
184 | 186 |
185 std::ostream& operator<<(std::ostream& os, const ResourceData& resource) { | 187 std::ostream& operator<<(std::ostream& os, const ResourceData& resource) { |
186 return os << "[" << resource.resource_url() << "," << resource.resource_type() | 188 return os << "[" << resource.resource_url() << "," << resource.resource_type() |
187 << "," << resource.number_of_hits() << "," | 189 << "," << resource.number_of_hits() << "," |
188 << resource.number_of_misses() << "," | 190 << resource.number_of_misses() << "," |
189 << resource.consecutive_misses() << "," | 191 << resource.consecutive_misses() << "," |
190 << resource.average_position() << "," << resource.priority() << "," | 192 << resource.average_position() << "," << resource.priority() << "," |
| 193 << resource.before_first_contentful_paint() << "," |
191 << resource.has_validators() << "," << resource.always_revalidate() | 194 << resource.has_validators() << "," << resource.always_revalidate() |
192 << "]"; | 195 << "]"; |
193 } | 196 } |
194 | 197 |
195 std::ostream& operator<<(std::ostream& os, const RedirectData& data) { | 198 std::ostream& operator<<(std::ostream& os, const RedirectData& data) { |
196 os << "[" << data.primary_key() << "," << data.last_visit_time() << "]" | 199 os << "[" << data.primary_key() << "," << data.last_visit_time() << "]" |
197 << std::endl; | 200 << std::endl; |
198 for (const RedirectStat& redirect : data.redirect_endpoints()) | 201 for (const RedirectStat& redirect : data.redirect_endpoints()) |
199 os << "\t\t" << redirect << std::endl; | 202 os << "\t\t" << redirect << std::endl; |
200 return os; | 203 return os; |
(...skipping 24 matching lines...) Expand all Loading... |
225 os << "[" << summary.main_frame_url << "," << summary.initial_url << "]" | 228 os << "[" << summary.main_frame_url << "," << summary.initial_url << "]" |
226 << std::endl; | 229 << std::endl; |
227 for (const auto& request : summary.subresource_requests) | 230 for (const auto& request : summary.subresource_requests) |
228 os << "\t\t" << request << std::endl; | 231 os << "\t\t" << request << std::endl; |
229 return os; | 232 return os; |
230 } | 233 } |
231 | 234 |
232 std::ostream& operator<<(std::ostream& os, const URLRequestSummary& summary) { | 235 std::ostream& operator<<(std::ostream& os, const URLRequestSummary& summary) { |
233 return os << "[" << summary.navigation_id << "," << summary.resource_url | 236 return os << "[" << summary.navigation_id << "," << summary.resource_url |
234 << "," << summary.resource_type << "," << summary.priority << "," | 237 << "," << summary.resource_type << "," << summary.priority << "," |
235 << summary.mime_type << "," << summary.was_cached << "," | 238 << summary.before_first_contentful_paint << "," << summary.mime_type |
236 << summary.redirect_url << "," << summary.has_validators << "," | 239 << "," << summary.was_cached << "," << summary.redirect_url << "," |
237 << summary.always_revalidate << "]"; | 240 << summary.has_validators << "," << summary.always_revalidate |
| 241 << "]"; |
238 } | 242 } |
239 | 243 |
240 std::ostream& operator<<(std::ostream& os, const NavigationID& navigation_id) { | 244 std::ostream& operator<<(std::ostream& os, const NavigationID& navigation_id) { |
241 return os << navigation_id.tab_id << "," << navigation_id.main_frame_url; | 245 return os << navigation_id.tab_id << "," << navigation_id.main_frame_url; |
242 } | 246 } |
243 | 247 |
244 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { | 248 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { |
245 bool equal = lhs.primary_key() == rhs.primary_key() && | 249 bool equal = lhs.primary_key() == rhs.primary_key() && |
246 lhs.resources_size() == rhs.resources_size(); | 250 lhs.resources_size() == rhs.resources_size(); |
247 | 251 |
248 if (!equal) | 252 if (!equal) |
249 return false; | 253 return false; |
250 | 254 |
251 for (int i = 0; i < lhs.resources_size(); ++i) | 255 for (int i = 0; i < lhs.resources_size(); ++i) |
252 equal = equal && lhs.resources(i) == rhs.resources(i); | 256 equal = equal && lhs.resources(i) == rhs.resources(i); |
253 | 257 |
254 return equal; | 258 return equal; |
255 } | 259 } |
256 | 260 |
257 bool operator==(const ResourceData& lhs, const ResourceData& rhs) { | 261 bool operator==(const ResourceData& lhs, const ResourceData& rhs) { |
258 return lhs.resource_url() == rhs.resource_url() && | 262 return lhs.resource_url() == rhs.resource_url() && |
259 lhs.resource_type() == rhs.resource_type() && | 263 lhs.resource_type() == rhs.resource_type() && |
260 lhs.number_of_hits() == rhs.number_of_hits() && | 264 lhs.number_of_hits() == rhs.number_of_hits() && |
261 lhs.number_of_misses() == rhs.number_of_misses() && | 265 lhs.number_of_misses() == rhs.number_of_misses() && |
262 lhs.consecutive_misses() == rhs.consecutive_misses() && | 266 lhs.consecutive_misses() == rhs.consecutive_misses() && |
263 AlmostEqual(lhs.average_position(), rhs.average_position()) && | 267 AlmostEqual(lhs.average_position(), rhs.average_position()) && |
264 lhs.priority() == rhs.priority() && | 268 lhs.priority() == rhs.priority() && |
| 269 lhs.before_first_contentful_paint() == |
| 270 rhs.before_first_contentful_paint() && |
265 lhs.has_validators() == rhs.has_validators() && | 271 lhs.has_validators() == rhs.has_validators() && |
266 lhs.always_revalidate() == rhs.always_revalidate(); | 272 lhs.always_revalidate() == rhs.always_revalidate(); |
267 } | 273 } |
268 | 274 |
269 bool operator==(const RedirectData& lhs, const RedirectData& rhs) { | 275 bool operator==(const RedirectData& lhs, const RedirectData& rhs) { |
270 bool equal = lhs.primary_key() == rhs.primary_key() && | 276 bool equal = lhs.primary_key() == rhs.primary_key() && |
271 lhs.redirect_endpoints_size() == rhs.redirect_endpoints_size(); | 277 lhs.redirect_endpoints_size() == rhs.redirect_endpoints_size(); |
272 | 278 |
273 if (!equal) | 279 if (!equal) |
274 return false; | 280 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
290 return lhs.main_frame_url == rhs.main_frame_url && | 296 return lhs.main_frame_url == rhs.main_frame_url && |
291 lhs.initial_url == rhs.initial_url && | 297 lhs.initial_url == rhs.initial_url && |
292 lhs.subresource_requests == rhs.subresource_requests; | 298 lhs.subresource_requests == rhs.subresource_requests; |
293 } | 299 } |
294 | 300 |
295 bool operator==(const URLRequestSummary& lhs, const URLRequestSummary& rhs) { | 301 bool operator==(const URLRequestSummary& lhs, const URLRequestSummary& rhs) { |
296 return lhs.navigation_id == rhs.navigation_id && | 302 return lhs.navigation_id == rhs.navigation_id && |
297 lhs.resource_url == rhs.resource_url && | 303 lhs.resource_url == rhs.resource_url && |
298 lhs.resource_type == rhs.resource_type && | 304 lhs.resource_type == rhs.resource_type && |
299 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type && | 305 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type && |
| 306 lhs.before_first_contentful_paint == |
| 307 rhs.before_first_contentful_paint && |
300 lhs.was_cached == rhs.was_cached && | 308 lhs.was_cached == rhs.was_cached && |
301 lhs.redirect_url == rhs.redirect_url && | 309 lhs.redirect_url == rhs.redirect_url && |
302 lhs.has_validators == rhs.has_validators && | 310 lhs.has_validators == rhs.has_validators && |
303 lhs.always_revalidate == rhs.always_revalidate; | 311 lhs.always_revalidate == rhs.always_revalidate; |
304 } | 312 } |
305 | 313 |
306 bool operator==(const OriginData& lhs, const OriginData& rhs) { | 314 bool operator==(const OriginData& lhs, const OriginData& rhs) { |
307 bool equal = | 315 bool equal = |
308 lhs.host() == rhs.host() && lhs.origins_size() == rhs.origins_size(); | 316 lhs.host() == rhs.host() && lhs.origins_size() == rhs.origins_size(); |
309 if (!equal) | 317 if (!equal) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 361 |
354 return equal; | 362 return equal; |
355 } | 363 } |
356 | 364 |
357 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs) { | 365 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs) { |
358 return lhs.url() == rhs.url() && | 366 return lhs.url() == rhs.url() && |
359 AlmostEqual(lhs.weight_ratio(), rhs.weight_ratio()); | 367 AlmostEqual(lhs.weight_ratio(), rhs.weight_ratio()); |
360 } | 368 } |
361 | 369 |
362 } // namespace precache | 370 } // namespace precache |
OLD | NEW |