Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 4 #ifndef CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_ |
| 5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 5 #define CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_ |
| 6 | 6 |
| 7 #include <memory> | |
| 7 #include <string> | 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 11 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 11 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 12 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 12 #include "components/sessions/core/session_id.h" | 13 #include "components/sessions/core/session_id.h" |
| 14 #include "net/url_request/url_request_context.h" | |
| 15 #include "net/url_request/url_request_job.h" | |
| 16 #include "net/url_request/url_request_job_factory.h" | |
| 17 #include "net/url_request/url_request_test_util.h" | |
| 13 | 18 |
| 14 namespace predictors { | 19 namespace predictors { |
| 15 | 20 |
| 16 void InitializeResourceData(ResourceData* resource, | 21 void InitializeResourceData(ResourceData* resource, |
| 17 const std::string& resource_url, | 22 const std::string& resource_url, |
| 18 content::ResourceType resource_type, | 23 content::ResourceType resource_type, |
| 19 int number_of_hits, | 24 int number_of_hits, |
| 20 int number_of_misses, | 25 int number_of_misses, |
| 21 int consecutive_misses, | 26 int consecutive_misses, |
| 22 double average_position, | 27 double average_position, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, | 77 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, |
| 73 net::RequestPriority priority = net::MEDIUM, | 78 net::RequestPriority priority = net::MEDIUM, |
| 74 const std::string& mime_type = std::string(), | 79 const std::string& mime_type = std::string(), |
| 75 bool was_cached = false, | 80 bool was_cached = false, |
| 76 const std::string& redirect_url = std::string(), | 81 const std::string& redirect_url = std::string(), |
| 77 bool has_validators = false, | 82 bool has_validators = false, |
| 78 bool always_revalidate = false); | 83 bool always_revalidate = false); |
| 79 | 84 |
| 80 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); | 85 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); |
| 81 | 86 |
| 87 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { | |
|
Benoit L
2017/06/07 12:01:05
nit: Since this is only referred to in the .cc fil
trevordixon
2017/06/07 12:37:15
Done.
| |
| 88 void OnResponseStarted(net::URLRequest* request, int net_error) override {} | |
| 89 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} | |
| 90 }; | |
| 91 | |
| 92 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( | |
| 93 const char* headers); | |
| 94 | |
| 95 class MockURLRequestJob : public net::URLRequestJob { | |
| 96 public: | |
| 97 MockURLRequestJob(net::URLRequest* request, | |
| 98 const net::HttpResponseInfo& response_info, | |
| 99 const std::string& mime_type); | |
| 100 | |
| 101 bool GetMimeType(std::string* mime_type) const override; | |
| 102 | |
| 103 protected: | |
| 104 void Start() override; | |
| 105 void GetResponseInfo(net::HttpResponseInfo* info) override; | |
| 106 | |
| 107 private: | |
| 108 net::HttpResponseInfo response_info_; | |
| 109 std::string mime_type_; | |
| 110 }; | |
| 111 | |
| 112 class MockURLRequestJobFactory : public net::URLRequestJobFactory { | |
| 113 public: | |
| 114 MockURLRequestJobFactory(); | |
| 115 ~MockURLRequestJobFactory() override; | |
| 116 | |
| 117 void Reset(); | |
| 118 | |
| 119 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | |
| 120 const std::string& scheme, | |
| 121 net::URLRequest* request, | |
| 122 net::NetworkDelegate* network_delegate) const override; | |
| 123 | |
| 124 net::URLRequestJob* MaybeInterceptRedirect( | |
| 125 net::URLRequest* request, | |
| 126 net::NetworkDelegate* network_delegate, | |
| 127 const GURL& location) const override; | |
| 128 | |
| 129 net::URLRequestJob* MaybeInterceptResponse( | |
| 130 net::URLRequest* request, | |
| 131 net::NetworkDelegate* network_delegate) const override; | |
| 132 | |
| 133 bool IsHandledProtocol(const std::string& scheme) const override; | |
| 134 | |
| 135 bool IsSafeRedirectTarget(const GURL& location) const override; | |
| 136 | |
| 137 void set_response_info(const net::HttpResponseInfo& response_info) { | |
| 138 response_info_ = response_info; | |
| 139 } | |
| 140 | |
| 141 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } | |
| 142 | |
| 143 private: | |
| 144 net::HttpResponseInfo response_info_; | |
| 145 std::string mime_type_; | |
| 146 }; | |
| 147 | |
| 148 std::unique_ptr<net::URLRequest> CreateURLRequest( | |
| 149 const net::TestURLRequestContext& url_request_context, | |
| 150 const GURL& url, | |
| 151 net::RequestPriority priority, | |
| 152 content::ResourceType resource_type, | |
| 153 bool is_main_frame); | |
| 154 | |
| 82 // For printing failures nicely. | 155 // For printing failures nicely. |
| 83 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); | 156 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); |
| 84 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); | 157 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); |
| 85 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); | 158 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); |
| 86 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); | 159 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); |
| 87 std::ostream& operator<<( | 160 std::ostream& operator<<( |
| 88 std::ostream& stream, | 161 std::ostream& stream, |
| 89 const ResourcePrefetchPredictor::PageRequestSummary& summary); | 162 const ResourcePrefetchPredictor::PageRequestSummary& summary); |
| 90 std::ostream& operator<<( | 163 std::ostream& operator<<( |
| 91 std::ostream& stream, | 164 std::ostream& stream, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 113 std::ostream& operator<<(std::ostream& stream, | 186 std::ostream& operator<<(std::ostream& stream, |
| 114 const PrecacheManifest& manifest); | 187 const PrecacheManifest& manifest); |
| 115 std::ostream& operator<<(std::ostream& stream, | 188 std::ostream& operator<<(std::ostream& stream, |
| 116 const PrecacheResource& resource); | 189 const PrecacheResource& resource); |
| 117 | 190 |
| 118 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); | 191 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); |
| 119 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); | 192 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); |
| 120 | 193 |
| 121 } // namespace precache | 194 } // namespace precache |
| 122 | 195 |
| 123 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 196 #endif // CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_ |
| OLD | NEW |