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