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