| 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 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 | |
| 15 namespace predictors { | |
| 16 | |
| 17 // Does nothing, controls which URLs are prefetchable. | |
| 18 class MockResourcePrefetchPredictor : public ResourcePrefetchPredictor { | |
| 19 public: | |
| 20 MockResourcePrefetchPredictor(const LoadingPredictorConfig& config, | |
| 21 Profile* profile); | |
| 22 ~MockResourcePrefetchPredictor(); | |
| 23 | |
| 24 MOCK_CONST_METHOD2(GetPrefetchData, | |
| 25 bool(const GURL&, ResourcePrefetchPredictor::Prediction*)); | |
| 26 MOCK_METHOD0(StartInitialization, void()); | |
| 27 MOCK_METHOD0(Shutdown, void()); | |
| 28 MOCK_METHOD2(StartPrefetching, | |
| 29 void(const GURL&, const ResourcePrefetchPredictor::Prediction&)); | |
| 30 MOCK_METHOD1(StopPrefeching, void(const GURL&)); | |
| 31 }; | |
| 32 | |
| 33 void InitializeResourceData(ResourceData* resource, | |
| 34 const std::string& resource_url, | |
| 35 content::ResourceType resource_type, | |
| 36 int number_of_hits, | |
| 37 int number_of_misses, | |
| 38 int consecutive_misses, | |
| 39 double average_position, | |
| 40 net::RequestPriority priority, | |
| 41 bool has_validators, | |
| 42 bool always_revalidate); | |
| 43 | |
| 44 void InitializeRedirectStat(RedirectStat* redirect, | |
| 45 const std::string& url, | |
| 46 int number_of_hits, | |
| 47 int number_of_misses, | |
| 48 int consecutive_misses); | |
| 49 | |
| 50 void InitializePrecacheResource(precache::PrecacheResource* resource, | |
| 51 const std::string& url, | |
| 52 double weight_ratio, | |
| 53 precache::PrecacheResource::Type type); | |
| 54 | |
| 55 void InitializeOriginStat(OriginStat* origin_stat, | |
| 56 const std::string& origin, | |
| 57 int number_of_hits, | |
| 58 int number_of_misses, | |
| 59 int consecutive_misses, | |
| 60 double average_position, | |
| 61 bool always_access_network, | |
| 62 bool accessed_network); | |
| 63 | |
| 64 void InitializeExperiment(precache::PrecacheManifest* manifest, | |
| 65 uint32_t experiment_id, | |
| 66 const std::vector<bool>& bitset); | |
| 67 | |
| 68 PrefetchData CreatePrefetchData(const std::string& primary_key, | |
| 69 uint64_t last_visit_time = 0); | |
| 70 RedirectData CreateRedirectData(const std::string& primary_key, | |
| 71 uint64_t last_visit_time = 0); | |
| 72 precache::PrecacheManifest CreateManifestData(int64_t id = 0); | |
| 73 OriginData CreateOriginData(const std::string& host, | |
| 74 uint64_t last_visit_time = 0); | |
| 75 | |
| 76 NavigationID CreateNavigationID(SessionID::id_type tab_id, | |
| 77 const std::string& main_frame_url); | |
| 78 | |
| 79 ResourcePrefetchPredictor::PageRequestSummary CreatePageRequestSummary( | |
| 80 const std::string& main_frame_url, | |
| 81 const std::string& initial_url, | |
| 82 const std::vector<ResourcePrefetchPredictor::URLRequestSummary>& | |
| 83 subresource_requests); | |
| 84 | |
| 85 ResourcePrefetchPredictor::URLRequestSummary CreateURLRequestSummary( | |
| 86 SessionID::id_type tab_id, | |
| 87 const std::string& main_frame_url, | |
| 88 const std::string& resource_url = std::string(), | |
| 89 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, | |
| 90 net::RequestPriority priority = net::MEDIUM, | |
| 91 const std::string& mime_type = std::string(), | |
| 92 bool was_cached = false, | |
| 93 const std::string& redirect_url = std::string(), | |
| 94 bool has_validators = false, | |
| 95 bool always_revalidate = false); | |
| 96 | |
| 97 ResourcePrefetchPredictor::Prediction CreatePrediction( | |
| 98 const std::string& main_frame_key, | |
| 99 std::vector<GURL> subresource_urls); | |
| 100 | |
| 101 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); | |
| 102 | |
| 103 // For printing failures nicely. | |
| 104 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); | |
| 105 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); | |
| 106 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); | |
| 107 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); | |
| 108 std::ostream& operator<<( | |
| 109 std::ostream& stream, | |
| 110 const ResourcePrefetchPredictor::PageRequestSummary& summary); | |
| 111 std::ostream& operator<<( | |
| 112 std::ostream& stream, | |
| 113 const ResourcePrefetchPredictor::URLRequestSummary& summary); | |
| 114 std::ostream& operator<<(std::ostream& stream, const NavigationID& id); | |
| 115 | |
| 116 std::ostream& operator<<(std::ostream& os, const OriginData& data); | |
| 117 std::ostream& operator<<(std::ostream& os, const OriginStat& redirect); | |
| 118 | |
| 119 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs); | |
| 120 bool operator==(const ResourceData& lhs, const ResourceData& rhs); | |
| 121 bool operator==(const RedirectData& lhs, const RedirectData& rhs); | |
| 122 bool operator==(const RedirectStat& lhs, const RedirectStat& rhs); | |
| 123 bool operator==(const ResourcePrefetchPredictor::PageRequestSummary& lhs, | |
| 124 const ResourcePrefetchPredictor::PageRequestSummary& rhs); | |
| 125 bool operator==(const ResourcePrefetchPredictor::URLRequestSummary& lhs, | |
| 126 const ResourcePrefetchPredictor::URLRequestSummary& rhs); | |
| 127 bool operator==(const OriginData& lhs, const OriginData& rhs); | |
| 128 bool operator==(const OriginStat& lhs, const OriginStat& rhs); | |
| 129 | |
| 130 } // namespace predictors | |
| 131 | |
| 132 namespace precache { | |
| 133 | |
| 134 std::ostream& operator<<(std::ostream& stream, | |
| 135 const PrecacheManifest& manifest); | |
| 136 std::ostream& operator<<(std::ostream& stream, | |
| 137 const PrecacheResource& resource); | |
| 138 | |
| 139 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); | |
| 140 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); | |
| 141 | |
| 142 } // namespace precache | |
| 143 | |
| 144 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | |
| OLD | NEW |