| 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 "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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 resource.set_number_of_hits(number_of_hits); | 26 resource.set_number_of_hits(number_of_hits); |
| 27 resource.set_number_of_misses(number_of_misses); | 27 resource.set_number_of_misses(number_of_misses); |
| 28 resource.set_consecutive_misses(consecutive_misses); | 28 resource.set_consecutive_misses(consecutive_misses); |
| 29 resource.set_average_position(average_position); | 29 resource.set_average_position(average_position); |
| 30 resource.set_priority(static_cast<ResourceData::Priority>(priority)); | 30 resource.set_priority(static_cast<ResourceData::Priority>(priority)); |
| 31 resource.set_has_validators(has_validators); | 31 resource.set_has_validators(has_validators); |
| 32 resource.set_always_revalidate(always_revalidate); | 32 resource.set_always_revalidate(always_revalidate); |
| 33 return resource; | 33 return resource; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void InitializeRedirectStat(RedirectStat* redirect, |
| 37 const std::string& url, |
| 38 int number_of_hits, |
| 39 int number_of_misses, |
| 40 int consecutive_misses) { |
| 41 redirect->set_url(url); |
| 42 redirect->set_number_of_hits(number_of_hits); |
| 43 redirect->set_number_of_misses(number_of_misses); |
| 44 redirect->set_consecutive_misses(consecutive_misses); |
| 45 } |
| 46 |
| 47 RedirectData CreateRedirectData(const std::string& primary_key) { |
| 48 RedirectData data; |
| 49 data.set_primary_key(primary_key); |
| 50 return data; |
| 51 } |
| 52 |
| 53 void PrintTo(const PrefetchData& data, ::std::ostream* os) { |
| 54 *os << "[" << data.key_type << "," << data.primary_key << "," |
| 55 << data.last_visit.ToInternalValue() << "]\n"; |
| 56 for (const ResourceData& resource : data.resources) { |
| 57 *os << "\t\t"; |
| 58 PrintTo(resource, os); |
| 59 *os << "\n"; |
| 60 } |
| 61 } |
| 62 |
| 36 void PrintTo(const ResourceData& resource, ::std::ostream* os) { | 63 void PrintTo(const ResourceData& resource, ::std::ostream* os) { |
| 37 *os << "[" << resource.resource_url() << "," << resource.resource_type() | 64 *os << "[" << resource.resource_url() << "," << resource.resource_type() |
| 38 << "," << resource.number_of_hits() << "," << resource.number_of_misses() | 65 << "," << resource.number_of_hits() << "," << resource.number_of_misses() |
| 39 << "," << resource.consecutive_misses() << "," | 66 << "," << resource.consecutive_misses() << "," |
| 40 << resource.average_position() << "," << resource.priority() << "," | 67 << resource.average_position() << "," << resource.priority() << "," |
| 41 << resource.has_validators() << "," << resource.always_revalidate() | 68 << resource.has_validators() << "," << resource.always_revalidate() |
| 42 << "]"; | 69 << "]"; |
| 43 } | 70 } |
| 44 | 71 |
| 45 void PrintTo(const PrefetchData& data, ::std::ostream* os) { | 72 void PrintTo(const RedirectStat& redirect, ::std::ostream* os) { |
| 46 *os << "[" << data.key_type << "," << data.primary_key << "," | 73 *os << "[" << redirect.url() << "," << redirect.number_of_hits() << "," |
| 47 << data.last_visit.ToInternalValue() << "]\n"; | 74 << redirect.number_of_misses() << "," << redirect.consecutive_misses() |
| 48 for (const ResourceData& resource : data.resources) { | 75 << "]"; |
| 76 } |
| 77 |
| 78 void PrintTo(const RedirectData& data, ::std::ostream* os) { |
| 79 *os << "[" << data.primary_key() << "," << data.last_visit_time() << "]\n"; |
| 80 for (const RedirectStat& redirect : data.redirect_endpoints()) { |
| 49 *os << "\t\t"; | 81 *os << "\t\t"; |
| 50 PrintTo(resource, os); | 82 PrintTo(redirect, os); |
| 51 *os << "\n"; | 83 *os << "\n"; |
| 52 } | 84 } |
| 53 } | 85 } |
| 54 | 86 |
| 87 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { |
| 88 bool equal = lhs.key_type == rhs.key_type && |
| 89 lhs.primary_key == rhs.primary_key && |
| 90 lhs.resources.size() == rhs.resources.size(); |
| 91 |
| 92 if (!equal) |
| 93 return false; |
| 94 |
| 95 for (size_t i = 0; i < lhs.resources.size(); ++i) |
| 96 equal = equal && lhs.resources[i] == rhs.resources[i]; |
| 97 |
| 98 return equal; |
| 99 } |
| 100 |
| 55 bool operator==(const ResourceData& lhs, const ResourceData& rhs) { | 101 bool operator==(const ResourceData& lhs, const ResourceData& rhs) { |
| 56 return lhs.resource_url() == rhs.resource_url() && | 102 return lhs.resource_url() == rhs.resource_url() && |
| 57 lhs.resource_type() == rhs.resource_type() && | 103 lhs.resource_type() == rhs.resource_type() && |
| 58 lhs.number_of_hits() == rhs.number_of_hits() && | 104 lhs.number_of_hits() == rhs.number_of_hits() && |
| 59 lhs.number_of_misses() == rhs.number_of_misses() && | 105 lhs.number_of_misses() == rhs.number_of_misses() && |
| 60 lhs.consecutive_misses() == rhs.consecutive_misses() && | 106 lhs.consecutive_misses() == rhs.consecutive_misses() && |
| 61 lhs.average_position() == rhs.average_position() && | 107 lhs.average_position() == rhs.average_position() && |
| 62 lhs.priority() == rhs.priority() && | 108 lhs.priority() == rhs.priority() && |
| 63 lhs.has_validators() == rhs.has_validators() && | 109 lhs.has_validators() == rhs.has_validators() && |
| 64 lhs.always_revalidate() == rhs.always_revalidate(); | 110 lhs.always_revalidate() == rhs.always_revalidate(); |
| 65 } | 111 } |
| 66 | 112 |
| 67 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { | 113 bool operator==(const RedirectStat& lhs, const RedirectStat& rhs) { |
| 68 bool equal = lhs.key_type == rhs.key_type && | 114 return lhs.url() == rhs.url() && |
| 69 lhs.primary_key == rhs.primary_key && | 115 lhs.number_of_hits() == rhs.number_of_hits() && |
| 70 lhs.resources.size() == rhs.resources.size(); | 116 lhs.number_of_misses() == rhs.number_of_misses() && |
| 117 lhs.consecutive_misses() == rhs.consecutive_misses(); |
| 118 } |
| 119 |
| 120 bool operator==(const RedirectData& lhs, const RedirectData& rhs) { |
| 121 bool equal = lhs.primary_key() == rhs.primary_key() && |
| 122 lhs.redirect_endpoints_size() == rhs.redirect_endpoints_size(); |
| 71 | 123 |
| 72 if (!equal) | 124 if (!equal) |
| 73 return false; | 125 return false; |
| 74 | 126 |
| 75 for (size_t i = 0; i < lhs.resources.size(); ++i) | 127 for (int i = 0; i < lhs.redirect_endpoints_size(); ++i) |
| 76 equal = equal && lhs.resources[i] == rhs.resources[i]; | 128 equal = equal && lhs.redirect_endpoints(i) == rhs.redirect_endpoints(i); |
| 77 | 129 |
| 78 return equal; | 130 return equal; |
| 79 } | 131 } |
| 80 | 132 |
| 81 } // namespace predictors | 133 } // namespace predictors |
| OLD | NEW |