| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | |
| 5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | |
| 11 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | |
| 12 #include "components/sessions/core/session_id.h" | |
| 13 | |
| 14 namespace predictors { | |
| 15 | |
| 16 void InitializeResourceData(ResourceData* resource, | |
| 17 const std::string& resource_url, | |
| 18 content::ResourceType resource_type, | |
| 19 int number_of_hits, | |
| 20 int number_of_misses, | |
| 21 int consecutive_misses, | |
| 22 double average_position, | |
| 23 net::RequestPriority priority, | |
| 24 bool has_validators, | |
| 25 bool always_revalidate); | |
| 26 | |
| 27 void InitializeRedirectStat(RedirectStat* redirect, | |
| 28 const std::string& url, | |
| 29 int number_of_hits, | |
| 30 int number_of_misses, | |
| 31 int consecutive_misses); | |
| 32 | |
| 33 void InitializePrecacheResource(precache::PrecacheResource* resource, | |
| 34 const std::string& url, | |
| 35 double weight_ratio, | |
| 36 precache::PrecacheResource::Type type); | |
| 37 | |
| 38 void InitializeOriginStat(OriginStat* origin_stat, | |
| 39 const std::string& origin, | |
| 40 int number_of_hits, | |
| 41 int number_of_misses, | |
| 42 int consecutive_misses, | |
| 43 double average_position, | |
| 44 bool always_access_network, | |
| 45 bool accessed_network); | |
| 46 | |
| 47 void InitializeExperiment(precache::PrecacheManifest* manifest, | |
| 48 uint32_t experiment_id, | |
| 49 const std::vector<bool>& bitset); | |
| 50 | |
| 51 PrefetchData CreatePrefetchData(const std::string& primary_key, | |
| 52 uint64_t last_visit_time = 0); | |
| 53 RedirectData CreateRedirectData(const std::string& primary_key, | |
| 54 uint64_t last_visit_time = 0); | |
| 55 precache::PrecacheManifest CreateManifestData(int64_t id = 0); | |
| 56 OriginData CreateOriginData(const std::string& host, | |
| 57 uint64_t last_visit_time = 0); | |
| 58 | |
| 59 NavigationID CreateNavigationID(SessionID::id_type tab_id, | |
| 60 const std::string& main_frame_url); | |
| 61 | |
| 62 ResourcePrefetchPredictor::PageRequestSummary CreatePageRequestSummary( | |
| 63 const std::string& main_frame_url, | |
| 64 const std::string& initial_url, | |
| 65 const std::vector<ResourcePrefetchPredictor::URLRequestSummary>& | |
| 66 subresource_requests); | |
| 67 | |
| 68 ResourcePrefetchPredictor::URLRequestSummary CreateURLRequestSummary( | |
| 69 SessionID::id_type tab_id, | |
| 70 const std::string& main_frame_url, | |
| 71 const std::string& resource_url = std::string(), | |
| 72 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, | |
| 73 net::RequestPriority priority = net::MEDIUM, | |
| 74 const std::string& mime_type = std::string(), | |
| 75 bool was_cached = false, | |
| 76 const std::string& redirect_url = std::string(), | |
| 77 bool has_validators = false, | |
| 78 bool always_revalidate = false); | |
| 79 | |
| 80 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); | |
| 81 | |
| 82 // For printing failures nicely. | |
| 83 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); | |
| 84 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); | |
| 85 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); | |
| 86 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); | |
| 87 std::ostream& operator<<( | |
| 88 std::ostream& stream, | |
| 89 const ResourcePrefetchPredictor::PageRequestSummary& summary); | |
| 90 std::ostream& operator<<( | |
| 91 std::ostream& stream, | |
| 92 const ResourcePrefetchPredictor::URLRequestSummary& summary); | |
| 93 std::ostream& operator<<(std::ostream& stream, const NavigationID& id); | |
| 94 | |
| 95 std::ostream& operator<<(std::ostream& os, const OriginData& data); | |
| 96 std::ostream& operator<<(std::ostream& os, const OriginStat& redirect); | |
| 97 | |
| 98 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs); | |
| 99 bool operator==(const ResourceData& lhs, const ResourceData& rhs); | |
| 100 bool operator==(const RedirectData& lhs, const RedirectData& rhs); | |
| 101 bool operator==(const RedirectStat& lhs, const RedirectStat& rhs); | |
| 102 bool operator==(const ResourcePrefetchPredictor::PageRequestSummary& lhs, | |
| 103 const ResourcePrefetchPredictor::PageRequestSummary& rhs); | |
| 104 bool operator==(const ResourcePrefetchPredictor::URLRequestSummary& lhs, | |
| 105 const ResourcePrefetchPredictor::URLRequestSummary& rhs); | |
| 106 bool operator==(const OriginData& lhs, const OriginData& rhs); | |
| 107 bool operator==(const OriginStat& lhs, const OriginStat& rhs); | |
| 108 | |
| 109 } // namespace predictors | |
| 110 | |
| 111 namespace precache { | |
| 112 | |
| 113 std::ostream& operator<<(std::ostream& stream, | |
| 114 const PrecacheManifest& manifest); | |
| 115 std::ostream& operator<<(std::ostream& stream, | |
| 116 const PrecacheResource& resource); | |
| 117 | |
| 118 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); | |
| 119 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); | |
| 120 | |
| 121 } // namespace precache | |
| 122 | |
| 123 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | |
| OLD | NEW |