| Index: chrome/browser/predictors/resource_prefetch_predictor_test_util.cc
|
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor_test_util.cc b/chrome/browser/predictors/resource_prefetch_predictor_test_util.cc
|
| index 4d61ccbbbf91f1d1ae37c2fed58c0139c98fe65b..47656392cd3f3e2f54da0de26137077c24c27ef0 100644
|
| --- a/chrome/browser/predictors/resource_prefetch_predictor_test_util.cc
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_test_util.cc
|
| @@ -4,7 +4,15 @@
|
|
|
| #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
|
|
|
| -#include <limits>
|
| +#include <cmath>
|
| +
|
| +namespace {
|
| +
|
| +bool AlmostEqual(const double x, const double y) {
|
| + return std::fabs(x - y) <= 1e-6; // Arbitrary but close enough.
|
| +}
|
| +
|
| +} // namespace
|
|
|
| namespace predictors {
|
|
|
| @@ -51,6 +59,23 @@ void InitializePrecacheResource(precache::PrecacheResource* resource,
|
| resource->set_weight_ratio(weight_ratio);
|
| }
|
|
|
| +void InitializeOriginStat(OriginStat* origin_stat,
|
| + const std::string& origin,
|
| + int number_of_hits,
|
| + int number_of_misses,
|
| + int consecutive_misses,
|
| + double average_position,
|
| + bool always_access_network,
|
| + bool accessed_network) {
|
| + origin_stat->set_origin(origin);
|
| + origin_stat->set_number_of_hits(number_of_hits);
|
| + origin_stat->set_number_of_misses(number_of_misses);
|
| + origin_stat->set_consecutive_misses(consecutive_misses);
|
| + origin_stat->set_average_position(average_position);
|
| + origin_stat->set_always_access_network(always_access_network);
|
| + origin_stat->set_accessed_network(accessed_network);
|
| +}
|
| +
|
| PrefetchData CreatePrefetchData(const std::string& primary_key,
|
| uint64_t last_visit_time) {
|
| PrefetchData data;
|
| @@ -76,6 +101,13 @@ precache::PrecacheManifest CreateManifestData(uint64_t id) {
|
| return manifest;
|
| }
|
|
|
| +OriginData CreateOriginData(const std::string& host, uint64_t last_visit_time) {
|
| + OriginData data;
|
| + data.set_host(host);
|
| + data.set_last_visit_time(last_visit_time);
|
| + return data;
|
| +}
|
| +
|
| NavigationID CreateNavigationID(SessionID::id_type tab_id,
|
| const std::string& main_frame_url) {
|
| NavigationID navigation_id;
|
| @@ -110,6 +142,7 @@ URLRequestSummary CreateURLRequestSummary(SessionID::id_type tab_id,
|
| summary.navigation_id = CreateNavigationID(tab_id, main_frame_url);
|
| summary.resource_url =
|
| resource_url.empty() ? GURL(main_frame_url) : GURL(resource_url);
|
| + summary.request_url = summary.resource_url;
|
| summary.resource_type = resource_type;
|
| summary.priority = priority;
|
| summary.mime_type = mime_type;
|
| @@ -118,6 +151,8 @@ URLRequestSummary CreateURLRequestSummary(SessionID::id_type tab_id,
|
| summary.redirect_url = GURL(redirect_url);
|
| summary.has_validators = has_validators;
|
| summary.always_revalidate = always_revalidate;
|
| + summary.is_no_store = false;
|
| + summary.network_accessed = true;
|
| return summary;
|
| }
|
|
|
| @@ -153,6 +188,21 @@ std::ostream& operator<<(std::ostream& os, const RedirectStat& redirect) {
|
| << redirect.consecutive_misses() << "]";
|
| }
|
|
|
| +std::ostream& operator<<(std::ostream& os, const OriginData& data) {
|
| + os << "[" << data.host() << "," << data.last_visit_time() << "]" << std::endl;
|
| + for (const OriginStat& origin : data.origins())
|
| + os << "\t\t" << origin << std::endl;
|
| + return os;
|
| +}
|
| +
|
| +std::ostream& operator<<(std::ostream& os, const OriginStat& origin) {
|
| + return os << "[" << origin.origin() << "," << origin.number_of_hits() << ","
|
| + << origin.number_of_misses() << "," << origin.consecutive_misses()
|
| + << "," << origin.average_position() << ","
|
| + << origin.always_access_network() << ","
|
| + << origin.accessed_network() << "]";
|
| +}
|
| +
|
| std::ostream& operator<<(std::ostream& os, const PageRequestSummary& summary) {
|
| os << "[" << summary.main_frame_url << "," << summary.initial_url << "]"
|
| << std::endl;
|
| @@ -192,7 +242,7 @@ bool operator==(const ResourceData& lhs, const ResourceData& rhs) {
|
| lhs.number_of_hits() == rhs.number_of_hits() &&
|
| lhs.number_of_misses() == rhs.number_of_misses() &&
|
| lhs.consecutive_misses() == rhs.consecutive_misses() &&
|
| - lhs.average_position() == rhs.average_position() &&
|
| + AlmostEqual(lhs.average_position(), rhs.average_position()) &&
|
| lhs.priority() == rhs.priority() &&
|
| lhs.has_validators() == rhs.has_validators() &&
|
| lhs.always_revalidate() == rhs.always_revalidate();
|
| @@ -235,6 +285,28 @@ bool operator==(const URLRequestSummary& lhs, const URLRequestSummary& rhs) {
|
| lhs.always_revalidate == rhs.always_revalidate;
|
| }
|
|
|
| +bool operator==(const OriginData& lhs, const OriginData& rhs) {
|
| + bool equal =
|
| + lhs.host() == rhs.host() && lhs.origins_size() == rhs.origins_size();
|
| + if (!equal)
|
| + return false;
|
| +
|
| + for (int i = 0; i < lhs.origins_size(); ++i)
|
| + equal = equal && lhs.origins(i) == rhs.origins(i);
|
| +
|
| + return equal;
|
| +}
|
| +
|
| +bool operator==(const OriginStat& lhs, const OriginStat& rhs) {
|
| + return lhs.origin() == rhs.origin() &&
|
| + lhs.number_of_hits() == rhs.number_of_hits() &&
|
| + lhs.number_of_misses() == rhs.number_of_misses() &&
|
| + lhs.consecutive_misses() == rhs.consecutive_misses() &&
|
| + AlmostEqual(lhs.average_position(), rhs.average_position()) &&
|
| + lhs.always_access_network() == rhs.always_access_network() &&
|
| + lhs.accessed_network() == rhs.accessed_network();
|
| +}
|
| +
|
| } // namespace predictors
|
|
|
| namespace precache {
|
| @@ -266,8 +338,7 @@ bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs) {
|
|
|
| bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs) {
|
| return lhs.url() == rhs.url() &&
|
| - std::fabs(lhs.weight_ratio() - rhs.weight_ratio()) <
|
| - std::numeric_limits<double>::epsilon();
|
| + AlmostEqual(lhs.weight_ratio(), rhs.weight_ratio());
|
| }
|
|
|
| } // namespace precache
|
|
|