| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 11 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 11 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 12 #include "components/sessions/core/session_id.h" | 12 #include "components/sessions/core/session_id.h" |
| 13 #include "net/url_request/url_request_context.h" |
| 14 #include "net/url_request/url_request_job.h" |
| 15 #include "net/url_request/url_request_job_factory.h" |
| 13 | 16 |
| 14 namespace predictors { | 17 namespace predictors { |
| 15 | 18 |
| 16 void InitializeResourceData(ResourceData* resource, | 19 void InitializeResourceData(ResourceData* resource, |
| 17 const std::string& resource_url, | 20 const std::string& resource_url, |
| 18 content::ResourceType resource_type, | 21 content::ResourceType resource_type, |
| 19 int number_of_hits, | 22 int number_of_hits, |
| 20 int number_of_misses, | 23 int number_of_misses, |
| 21 int consecutive_misses, | 24 int consecutive_misses, |
| 22 double average_position, | 25 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, | 75 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, |
| 73 net::RequestPriority priority = net::MEDIUM, | 76 net::RequestPriority priority = net::MEDIUM, |
| 74 const std::string& mime_type = std::string(), | 77 const std::string& mime_type = std::string(), |
| 75 bool was_cached = false, | 78 bool was_cached = false, |
| 76 const std::string& redirect_url = std::string(), | 79 const std::string& redirect_url = std::string(), |
| 77 bool has_validators = false, | 80 bool has_validators = false, |
| 78 bool always_revalidate = false); | 81 bool always_revalidate = false); |
| 79 | 82 |
| 80 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); | 83 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); |
| 81 | 84 |
| 85 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { |
| 86 void OnResponseStarted(net::URLRequest* request, int net_error) override {} |
| 87 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} |
| 88 }; |
| 89 |
| 90 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( |
| 91 const char* headers); |
| 92 |
| 93 class MockURLRequestJob : public net::URLRequestJob { |
| 94 public: |
| 95 MockURLRequestJob(net::URLRequest* request, |
| 96 const net::HttpResponseInfo& response_info, |
| 97 const std::string& mime_type); |
| 98 |
| 99 bool GetMimeType(std::string* mime_type) const override; |
| 100 |
| 101 protected: |
| 102 void Start() override; |
| 103 void GetResponseInfo(net::HttpResponseInfo* info) override; |
| 104 |
| 105 private: |
| 106 net::HttpResponseInfo response_info_; |
| 107 std::string mime_type_; |
| 108 }; |
| 109 |
| 110 class MockURLRequestJobFactory : public net::URLRequestJobFactory { |
| 111 public: |
| 112 MockURLRequestJobFactory(); |
| 113 ~MockURLRequestJobFactory() override; |
| 114 |
| 115 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
| 116 const std::string& scheme, |
| 117 net::URLRequest* request, |
| 118 net::NetworkDelegate* network_delegate) const override; |
| 119 |
| 120 net::URLRequestJob* MaybeInterceptRedirect( |
| 121 net::URLRequest* request, |
| 122 net::NetworkDelegate* network_delegate, |
| 123 const GURL& location) const override; |
| 124 |
| 125 net::URLRequestJob* MaybeInterceptResponse( |
| 126 net::URLRequest* request, |
| 127 net::NetworkDelegate* network_delegate) const override; |
| 128 |
| 129 bool IsHandledProtocol(const std::string& scheme) const override; |
| 130 |
| 131 bool IsSafeRedirectTarget(const GURL& location) const override; |
| 132 |
| 133 void set_response_info(const net::HttpResponseInfo& response_info) { |
| 134 response_info_ = response_info; |
| 135 } |
| 136 |
| 137 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } |
| 138 |
| 139 private: |
| 140 net::HttpResponseInfo response_info_; |
| 141 std::string mime_type_; |
| 142 }; |
| 143 |
| 82 // For printing failures nicely. | 144 // For printing failures nicely. |
| 83 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); | 145 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); |
| 84 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); | 146 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); |
| 85 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); | 147 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); |
| 86 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); | 148 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); |
| 87 std::ostream& operator<<( | 149 std::ostream& operator<<( |
| 88 std::ostream& stream, | 150 std::ostream& stream, |
| 89 const ResourcePrefetchPredictor::PageRequestSummary& summary); | 151 const ResourcePrefetchPredictor::PageRequestSummary& summary); |
| 90 std::ostream& operator<<( | 152 std::ostream& operator<<( |
| 91 std::ostream& stream, | 153 std::ostream& stream, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 113 std::ostream& operator<<(std::ostream& stream, | 175 std::ostream& operator<<(std::ostream& stream, |
| 114 const PrecacheManifest& manifest); | 176 const PrecacheManifest& manifest); |
| 115 std::ostream& operator<<(std::ostream& stream, | 177 std::ostream& operator<<(std::ostream& stream, |
| 116 const PrecacheResource& resource); | 178 const PrecacheResource& resource); |
| 117 | 179 |
| 118 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); | 180 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); |
| 119 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); | 181 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); |
| 120 | 182 |
| 121 } // namespace precache | 183 } // namespace precache |
| 122 | 184 |
| 123 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 185 #endif // CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_ |
| OLD | NEW |