| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8e349f6174196b2ff296d7cf52b59c12c6f2f3ab
|
| --- /dev/null
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_test_util.cc
|
| @@ -0,0 +1,91 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
|
| +
|
| +#include <sstream>
|
| +
|
| +#include "chrome/browser/predictors/resource_prefetch_predictor.h"
|
| +#include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
|
| +
|
| +namespace predictors {
|
| +
|
| +using ::chrome_browser_predictors::ResourceData;
|
| +
|
| +ResourceData MakeResourceData(std::string resource_url,
|
| + content::ResourceType resource_type,
|
| + int number_of_hits,
|
| + int number_of_misses,
|
| + int consecutive_misses,
|
| + double average_position,
|
| + net::RequestPriority priority,
|
| + bool has_validators,
|
| + bool always_revalidate) {
|
| + using ResourceType = ::chrome_browser_predictors::ResourceData_ResourceType;
|
| + using Priority = ::chrome_browser_predictors::ResourceData_Priority;
|
| +
|
| + ResourceData resource;
|
| + resource.set_resource_url(resource_url);
|
| + resource.set_resource_type(static_cast<ResourceType>(resource_type));
|
| + resource.set_number_of_hits(number_of_hits);
|
| + resource.set_number_of_misses(number_of_misses);
|
| + resource.set_consecutive_misses(consecutive_misses);
|
| + resource.set_average_position(average_position);
|
| + resource.set_priority(static_cast<Priority>(priority));
|
| + resource.set_has_validators(has_validators);
|
| + resource.set_always_revalidate(always_revalidate);
|
| +
|
| + ResourcePrefetchPredictorTables::UpdateResourceScore(&resource);
|
| +
|
| + return resource;
|
| +}
|
| +
|
| +// For printing failures nicely.
|
| +void PrintTo(const ResourceData& resource, ::std::ostream* os) {
|
| + *os << "[" << resource.primary_key() << "," << resource.resource_url() << ","
|
| + << resource.resource_type() << "," << resource.number_of_hits() << ","
|
| + << resource.number_of_misses() << "," << resource.consecutive_misses()
|
| + << "," << resource.average_position() << "," << resource.score() << "]";
|
| +}
|
| +
|
| +void PrintTo(const ResourcePrefetchPredictorTables::PrefetchData& data,
|
| + ::std::ostream* os) {
|
| + *os << "[" << data.key_type << "," << data.primary_key << ","
|
| + << data.last_visit.ToInternalValue() << "]\n";
|
| + for (const ResourceData& resource : data.resources) {
|
| + *os << "\t\t";
|
| + PrintTo(resource, os);
|
| + *os << "\n";
|
| + }
|
| +}
|
| +
|
| +bool operator==(const ResourceData& lhs, const ResourceData& rhs) {
|
| + // The primary key is not set.
|
| + return !lhs.has_primary_key() && !rhs.has_primary_key() &&
|
| + lhs.resource_url() == rhs.resource_url() &&
|
| + lhs.resource_type() == rhs.resource_type() &&
|
| + lhs.number_of_misses() == rhs.number_of_misses() &&
|
| + lhs.consecutive_misses() == rhs.consecutive_misses() &&
|
| + lhs.average_position() == rhs.average_position() &&
|
| + lhs.priority() == rhs.priority() &&
|
| + lhs.has_validators() == rhs.has_validators() &&
|
| + lhs.always_revalidate() == rhs.always_revalidate() &&
|
| + lhs.score() == rhs.score();
|
| +}
|
| +
|
| +bool operator==(const ResourcePrefetchPredictorTables::PrefetchData& lhs,
|
| + const ResourcePrefetchPredictorTables::PrefetchData& rhs) {
|
| + bool equal = lhs.key_type == rhs.key_type &&
|
| + lhs.primary_key == rhs.primary_key &&
|
| + lhs.resources.size() == rhs.resources.size();
|
| + if (!equal)
|
| + return false;
|
| + for (size_t i = 0; i < lhs.resources.size(); ++i) {
|
| + if (!(lhs.resources[i] == rhs.resources[i]))
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +} // namespace predictors
|
|
|