Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: content/test/test_url_fetcher_factory.h

Issue 10392192: Remove content::URLFetcherDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/common/url_fetcher_factory.h ('k') | content/test/test_url_fetcher_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 4
5 #ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ 5 #ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_
6 #define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ 6 #define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // ... 51 // ...
52 // 52 //
53 // Note: if you don't know when your request objects will be created you 53 // Note: if you don't know when your request objects will be created you
54 // might want to use the FakeURLFetcher and FakeURLFetcherFactory classes 54 // might want to use the FakeURLFetcher and FakeURLFetcherFactory classes
55 // below. 55 // below.
56 56
57 class TestURLFetcher : public content::URLFetcher { 57 class TestURLFetcher : public content::URLFetcher {
58 public: 58 public:
59 TestURLFetcher(int id, 59 TestURLFetcher(int id,
60 const GURL& url, 60 const GURL& url,
61 content::URLFetcherDelegate* d); 61 net::URLFetcherDelegate* d);
62 virtual ~TestURLFetcher(); 62 virtual ~TestURLFetcher();
63 63
64 // content::URLFetcher implementation 64 // content::URLFetcher implementation
65 virtual void SetUploadData(const std::string& upload_content_type, 65 virtual void SetUploadData(const std::string& upload_content_type,
66 const std::string& upload_content) OVERRIDE; 66 const std::string& upload_content) OVERRIDE;
67 virtual void SetChunkedUpload( 67 virtual void SetChunkedUpload(
68 const std::string& upload_content_type) OVERRIDE; 68 const std::string& upload_content_type) OVERRIDE;
69 // Overriden to cache the chunks uploaded. Caller can read back the uploaded 69 // Overriden to cache the chunks uploaded. Caller can read back the uploaded
70 // chunks with the upload_chunks() accessor. 70 // chunks with the upload_chunks() accessor.
71 virtual void AppendChunkToUpload(const std::string& data, 71 virtual void AppendChunkToUpload(const std::string& data,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Unique ID in our factory. 119 // Unique ID in our factory.
120 int id() const { return id_; } 120 int id() const { return id_; }
121 121
122 // Returns the data uploaded on this URLFetcher. 122 // Returns the data uploaded on this URLFetcher.
123 const std::string& upload_data() const { return upload_data_; } 123 const std::string& upload_data() const { return upload_data_; }
124 124
125 // Returns the chunks of data uploaded on this URLFetcher. 125 // Returns the chunks of data uploaded on this URLFetcher.
126 const std::list<std::string>& upload_chunks() const { return chunks_; } 126 const std::list<std::string>& upload_chunks() const { return chunks_; }
127 127
128 // Returns the delegate installed on the URLFetcher. 128 // Returns the delegate installed on the URLFetcher.
129 content::URLFetcherDelegate* delegate() const { return delegate_; } 129 net::URLFetcherDelegate* delegate() const { return delegate_; }
130 130
131 void set_url(const GURL& url) { fake_url_ = url; } 131 void set_url(const GURL& url) { fake_url_ = url; }
132 void set_status(const net::URLRequestStatus& status); 132 void set_status(const net::URLRequestStatus& status);
133 void set_response_code(int response_code) { 133 void set_response_code(int response_code) {
134 fake_response_code_ = response_code; 134 fake_response_code_ = response_code;
135 } 135 }
136 void set_cookies(const net::ResponseCookies& c) { fake_cookies_ = c; } 136 void set_cookies(const net::ResponseCookies& c) { fake_cookies_ = c; }
137 void set_was_fetched_via_proxy(bool flag); 137 void set_was_fetched_via_proxy(bool flag);
138 void set_response_headers(scoped_refptr<net::HttpResponseHeaders> headers); 138 void set_response_headers(scoped_refptr<net::HttpResponseHeaders> headers);
139 void set_backoff_delay(base::TimeDelta backoff_delay); 139 void set_backoff_delay(base::TimeDelta backoff_delay);
140 140
141 // Set string data. 141 // Set string data.
142 void SetResponseString(const std::string& response); 142 void SetResponseString(const std::string& response);
143 143
144 // Set File data. 144 // Set File data.
145 void SetResponseFilePath(const FilePath& path); 145 void SetResponseFilePath(const FilePath& path);
146 146
147 private: 147 private:
148 enum ResponseDestinationType { 148 enum ResponseDestinationType {
149 STRING, // Default: In a std::string 149 STRING, // Default: In a std::string
150 TEMP_FILE // Write to a temp file 150 TEMP_FILE // Write to a temp file
151 }; 151 };
152 152
153 const int id_; 153 const int id_;
154 const GURL original_url_; 154 const GURL original_url_;
155 content::URLFetcherDelegate* delegate_; 155 net::URLFetcherDelegate* delegate_;
156 std::string upload_data_; 156 std::string upload_data_;
157 std::list<std::string> chunks_; 157 std::list<std::string> chunks_;
158 bool did_receive_last_chunk_; 158 bool did_receive_last_chunk_;
159 159
160 // User can use set_* methods to provide values returned by getters. 160 // User can use set_* methods to provide values returned by getters.
161 // Setting the real values is not possible, because the real class 161 // Setting the real values is not possible, because the real class
162 // has no setters. The data is a private member of a class defined 162 // has no setters. The data is a private member of a class defined
163 // in a .cc file, so we can't get at it with friendship. 163 // in a .cc file, so we can't get at it with friendship.
164 int fake_load_flags_; 164 int fake_load_flags_;
165 GURL fake_url_; 165 GURL fake_url_;
(...skipping 17 matching lines...) Expand all
183 class TestURLFetcherFactory : public content::URLFetcherFactory, 183 class TestURLFetcherFactory : public content::URLFetcherFactory,
184 public ScopedURLFetcherFactory { 184 public ScopedURLFetcherFactory {
185 public: 185 public:
186 TestURLFetcherFactory(); 186 TestURLFetcherFactory();
187 virtual ~TestURLFetcherFactory(); 187 virtual ~TestURLFetcherFactory();
188 188
189 virtual content::URLFetcher* CreateURLFetcher( 189 virtual content::URLFetcher* CreateURLFetcher(
190 int id, 190 int id,
191 const GURL& url, 191 const GURL& url,
192 content::URLFetcher::RequestType request_type, 192 content::URLFetcher::RequestType request_type,
193 content::URLFetcherDelegate* d) OVERRIDE; 193 net::URLFetcherDelegate* d) OVERRIDE;
194 TestURLFetcher* GetFetcherByID(int id) const; 194 TestURLFetcher* GetFetcherByID(int id) const;
195 void RemoveFetcherFromMap(int id); 195 void RemoveFetcherFromMap(int id);
196 196
197 private: 197 private:
198 // Maps from id passed to create to the returned URLFetcher. 198 // Maps from id passed to create to the returned URLFetcher.
199 typedef std::map<int, TestURLFetcher*> Fetchers; 199 typedef std::map<int, TestURLFetcher*> Fetchers;
200 Fetchers fetchers_; 200 Fetchers fetchers_;
201 201
202 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); 202 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory);
203 }; 203 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 // If no fake response is set for the given URL this method will delegate the 246 // If no fake response is set for the given URL this method will delegate the
247 // call to |default_factory_| if it is not NULL, or return NULL if it is 247 // call to |default_factory_| if it is not NULL, or return NULL if it is
248 // NULL. 248 // NULL.
249 // Otherwise, it will return a URLFetcher object which will respond with the 249 // Otherwise, it will return a URLFetcher object which will respond with the
250 // pre-baked response that the client has set by calling SetFakeResponse(). 250 // pre-baked response that the client has set by calling SetFakeResponse().
251 virtual content::URLFetcher* CreateURLFetcher( 251 virtual content::URLFetcher* CreateURLFetcher(
252 int id, 252 int id,
253 const GURL& url, 253 const GURL& url,
254 content::URLFetcher::RequestType request_type, 254 content::URLFetcher::RequestType request_type,
255 content::URLFetcherDelegate* d) OVERRIDE; 255 net::URLFetcherDelegate* d) OVERRIDE;
256 256
257 // Sets the fake response for a given URL. If success is true we will serve 257 // Sets the fake response for a given URL. If success is true we will serve
258 // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty. 258 // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty.
259 void SetFakeResponse(const std::string& url, 259 void SetFakeResponse(const std::string& url,
260 const std::string& response_data, 260 const std::string& response_data,
261 bool success); 261 bool success);
262 262
263 // Clear all the fake responses that were previously set via 263 // Clear all the fake responses that were previously set via
264 // SetFakeResponse(). 264 // SetFakeResponse().
265 void ClearFakeResponses(); 265 void ClearFakeResponses();
(...skipping 13 matching lines...) Expand all
279 class URLFetcherImplFactory : public content::URLFetcherFactory { 279 class URLFetcherImplFactory : public content::URLFetcherFactory {
280 public: 280 public:
281 URLFetcherImplFactory(); 281 URLFetcherImplFactory();
282 virtual ~URLFetcherImplFactory(); 282 virtual ~URLFetcherImplFactory();
283 283
284 // This method will create a real URLFetcher. 284 // This method will create a real URLFetcher.
285 virtual content::URLFetcher* CreateURLFetcher( 285 virtual content::URLFetcher* CreateURLFetcher(
286 int id, 286 int id,
287 const GURL& url, 287 const GURL& url,
288 content::URLFetcher::RequestType request_type, 288 content::URLFetcher::RequestType request_type,
289 content::URLFetcherDelegate* d) OVERRIDE; 289 net::URLFetcherDelegate* d) OVERRIDE;
290 290
291 }; 291 };
292 292
293 #endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ 293 #endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_
OLDNEW
« no previous file with comments | « content/public/common/url_fetcher_factory.h ('k') | content/test/test_url_fetcher_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698