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_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ |
5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_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 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( | |
86 const char* headers); | |
87 | |
88 class MockURLRequestJob : public net::URLRequestJob { | |
89 public: | |
90 MockURLRequestJob(net::URLRequest* request, | |
91 const net::HttpResponseInfo& response_info, | |
92 const std::string& mime_type); | |
93 | |
94 bool GetMimeType(std::string* mime_type) const override; | |
95 | |
96 protected: | |
97 void Start() override; | |
98 void GetResponseInfo(net::HttpResponseInfo* info) override; | |
99 | |
100 private: | |
101 net::HttpResponseInfo response_info_; | |
102 std::string mime_type_; | |
103 }; | |
104 | |
105 class MockURLRequestJobFactory : public net::URLRequestJobFactory { | |
106 public: | |
107 MockURLRequestJobFactory(); | |
108 ~MockURLRequestJobFactory() override; | |
109 | |
110 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | |
111 const std::string& scheme, | |
112 net::URLRequest* request, | |
113 net::NetworkDelegate* network_delegate) const override; | |
114 | |
115 net::URLRequestJob* MaybeInterceptRedirect( | |
116 net::URLRequest* request, | |
117 net::NetworkDelegate* network_delegate, | |
118 const GURL& location) const override; | |
119 | |
120 net::URLRequestJob* MaybeInterceptResponse( | |
121 net::URLRequest* request, | |
122 net::NetworkDelegate* network_delegate) const override; | |
123 | |
124 bool IsHandledProtocol(const std::string& scheme) const override; | |
125 | |
126 bool IsSafeRedirectTarget(const GURL& location) const override; | |
127 | |
128 void set_response_info(const net::HttpResponseInfo& response_info); | |
Benoit L
2017/06/02 12:44:00
nit: you can inline trivial setters.
trevordixon
2017/06/06 13:08:04
Done.
| |
129 | |
130 void set_mime_type(const std::string& mime_type); | |
131 | |
132 private: | |
133 net::HttpResponseInfo response_info_; | |
134 std::string mime_type_; | |
135 }; | |
136 | |
82 // For printing failures nicely. | 137 // For printing failures nicely. |
83 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); | 138 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); |
84 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); | 139 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); |
85 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); | 140 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); |
86 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); | 141 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); |
87 std::ostream& operator<<( | 142 std::ostream& operator<<( |
88 std::ostream& stream, | 143 std::ostream& stream, |
89 const ResourcePrefetchPredictor::PageRequestSummary& summary); | 144 const ResourcePrefetchPredictor::PageRequestSummary& summary); |
90 std::ostream& operator<<( | 145 std::ostream& operator<<( |
91 std::ostream& stream, | 146 std::ostream& stream, |
(...skipping 22 matching lines...) Expand all Loading... | |
114 const PrecacheManifest& manifest); | 169 const PrecacheManifest& manifest); |
115 std::ostream& operator<<(std::ostream& stream, | 170 std::ostream& operator<<(std::ostream& stream, |
116 const PrecacheResource& resource); | 171 const PrecacheResource& resource); |
117 | 172 |
118 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); | 173 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); |
119 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); | 174 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); |
120 | 175 |
121 } // namespace precache | 176 } // namespace precache |
122 | 177 |
123 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 178 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ |
OLD | NEW |