OLD | NEW |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // DCHECK(fetcher); | 47 // DCHECK(fetcher); |
48 // // Notify delegate with whatever data you want. | 48 // // Notify delegate with whatever data you want. |
49 // fetcher->delegate()->OnURLFetchComplete(...); | 49 // fetcher->delegate()->OnURLFetchComplete(...); |
50 // // Make sure consumer of URLFetcher does the right thing. | 50 // // Make sure consumer of URLFetcher does the right thing. |
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 net::URLFetcher { |
58 public: | 58 public: |
59 TestURLFetcher(int id, | 59 TestURLFetcher(int id, |
60 const GURL& url, | 60 const GURL& url, |
61 net::URLFetcherDelegate* d); | 61 net::URLFetcherDelegate* d); |
62 virtual ~TestURLFetcher(); | 62 virtual ~TestURLFetcher(); |
63 | 63 |
64 // content::URLFetcher implementation | 64 // net::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, |
72 bool is_last_chunk) OVERRIDE; | 72 bool is_last_chunk) OVERRIDE; |
73 virtual void SetLoadFlags(int load_flags) OVERRIDE; | 73 virtual void SetLoadFlags(int load_flags) OVERRIDE; |
74 virtual int GetLoadFlags() const OVERRIDE; | 74 virtual int GetLoadFlags() const OVERRIDE; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 }; | 179 }; |
180 | 180 |
181 // Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers | 181 // Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers |
182 // are registered in a map by the id passed to the create method. | 182 // are registered in a map by the id passed to the create method. |
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 net::URLFetcher* CreateURLFetcher( |
190 int id, | 190 int id, |
191 const GURL& url, | 191 const GURL& url, |
192 content::URLFetcher::RequestType request_type, | 192 net::URLFetcher::RequestType request_type, |
193 net::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); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // FakeURLFetcherFactory that will delegate creating URLFetcher for unknown | 241 // FakeURLFetcherFactory that will delegate creating URLFetcher for unknown |
242 // url to the given factory. | 242 // url to the given factory. |
243 explicit FakeURLFetcherFactory(content::URLFetcherFactory* default_factory); | 243 explicit FakeURLFetcherFactory(content::URLFetcherFactory* default_factory); |
244 virtual ~FakeURLFetcherFactory(); | 244 virtual ~FakeURLFetcherFactory(); |
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 net::URLFetcher* CreateURLFetcher( |
252 int id, | 252 int id, |
253 const GURL& url, | 253 const GURL& url, |
254 content::URLFetcher::RequestType request_type, | 254 net::URLFetcher::RequestType request_type, |
255 net::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(). |
(...skipping 10 matching lines...) Expand all Loading... |
275 // This is an implementation of URLFetcherFactory that will create a | 275 // This is an implementation of URLFetcherFactory that will create a |
276 // URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in | 276 // URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in |
277 // integration tests to control the behavior of some requests but execute | 277 // integration tests to control the behavior of some requests but execute |
278 // all the other ones. | 278 // all the other ones. |
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 net::URLFetcher* CreateURLFetcher( |
286 int id, | 286 int id, |
287 const GURL& url, | 287 const GURL& url, |
288 content::URLFetcher::RequestType request_type, | 288 net::URLFetcher::RequestType request_type, |
289 net::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_ |
OLD | NEW |