| 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 NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ |
| 6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ | 6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers | 235 // Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers |
| 236 // are registered in a map by the id passed to the create method. | 236 // are registered in a map by the id passed to the create method. |
| 237 // Optionally, a fetcher may be automatically unregistered from the map upon | 237 // Optionally, a fetcher may be automatically unregistered from the map upon |
| 238 // its destruction. | 238 // its destruction. |
| 239 class TestURLFetcherFactory : public URLFetcherFactory, | 239 class TestURLFetcherFactory : public URLFetcherFactory, |
| 240 public ScopedURLFetcherFactory { | 240 public ScopedURLFetcherFactory { |
| 241 public: | 241 public: |
| 242 TestURLFetcherFactory(); | 242 TestURLFetcherFactory(); |
| 243 ~TestURLFetcherFactory() override; | 243 ~TestURLFetcherFactory() override; |
| 244 | 244 |
| 245 URLFetcher* CreateURLFetcher(int id, | 245 scoped_ptr<URLFetcher> CreateURLFetcher(int id, |
| 246 const GURL& url, | 246 const GURL& url, |
| 247 URLFetcher::RequestType request_type, | 247 URLFetcher::RequestType request_type, |
| 248 URLFetcherDelegate* d) override; | 248 URLFetcherDelegate* d) override; |
| 249 TestURLFetcher* GetFetcherByID(int id) const; | 249 TestURLFetcher* GetFetcherByID(int id) const; |
| 250 void RemoveFetcherFromMap(int id); | 250 void RemoveFetcherFromMap(int id); |
| 251 void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests); | 251 void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests); |
| 252 void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) { | 252 void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) { |
| 253 remove_fetcher_on_delete_ = remove_fetcher_on_delete; | 253 remove_fetcher_on_delete_ = remove_fetcher_on_delete; |
| 254 } | 254 } |
| 255 | 255 |
| 256 private: | 256 private: |
| 257 // Maps from id passed to create to the returned URLFetcher. | 257 // Maps from id passed to create to the returned URLFetcher. |
| 258 typedef std::map<int, TestURLFetcher*> Fetchers; | 258 typedef std::map<int, TestURLFetcher*> Fetchers; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 FakeURLFetcherFactory(URLFetcherFactory* default_factory, | 394 FakeURLFetcherFactory(URLFetcherFactory* default_factory, |
| 395 const FakeURLFetcherCreator& creator); | 395 const FakeURLFetcherCreator& creator); |
| 396 | 396 |
| 397 ~FakeURLFetcherFactory() override; | 397 ~FakeURLFetcherFactory() override; |
| 398 | 398 |
| 399 // If no fake response is set for the given URL this method will delegate the | 399 // If no fake response is set for the given URL this method will delegate the |
| 400 // call to |default_factory_| if it is not NULL, or return NULL if it is | 400 // call to |default_factory_| if it is not NULL, or return NULL if it is |
| 401 // NULL. | 401 // NULL. |
| 402 // Otherwise, it will return a URLFetcher object which will respond with the | 402 // Otherwise, it will return a URLFetcher object which will respond with the |
| 403 // pre-baked response that the client has set by calling SetFakeResponse(). | 403 // pre-baked response that the client has set by calling SetFakeResponse(). |
| 404 URLFetcher* CreateURLFetcher(int id, | 404 scoped_ptr<URLFetcher> CreateURLFetcher(int id, |
| 405 const GURL& url, | 405 const GURL& url, |
| 406 URLFetcher::RequestType request_type, | 406 URLFetcher::RequestType request_type, |
| 407 URLFetcherDelegate* d) override; | 407 URLFetcherDelegate* d) override; |
| 408 | 408 |
| 409 // Sets the fake response for a given URL. The |response_data| may be empty. | 409 // Sets the fake response for a given URL. The |response_data| may be empty. |
| 410 // The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will | 410 // The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will |
| 411 // return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500. | 411 // return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500. |
| 412 // The |status| argument may be any URLRequestStatus::Status value. Typically, | 412 // The |status| argument may be any URLRequestStatus::Status value. Typically, |
| 413 // requests that return a valid HttpStatusCode have the SUCCESS status, while | 413 // requests that return a valid HttpStatusCode have the SUCCESS status, while |
| 414 // requests that indicate a failure to connect to the server have the FAILED | 414 // requests that indicate a failure to connect to the server have the FAILED |
| 415 // status. | 415 // status. |
| 416 void SetFakeResponse(const GURL& url, | 416 void SetFakeResponse(const GURL& url, |
| 417 const std::string& response_data, | 417 const std::string& response_data, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 446 // This is an implementation of URLFetcherFactory that will create a | 446 // This is an implementation of URLFetcherFactory that will create a |
| 447 // URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in | 447 // URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in |
| 448 // integration tests to control the behavior of some requests but execute | 448 // integration tests to control the behavior of some requests but execute |
| 449 // all the other ones. | 449 // all the other ones. |
| 450 class URLFetcherImplFactory : public URLFetcherFactory { | 450 class URLFetcherImplFactory : public URLFetcherFactory { |
| 451 public: | 451 public: |
| 452 URLFetcherImplFactory(); | 452 URLFetcherImplFactory(); |
| 453 ~URLFetcherImplFactory() override; | 453 ~URLFetcherImplFactory() override; |
| 454 | 454 |
| 455 // This method will create a real URLFetcher. | 455 // This method will create a real URLFetcher. |
| 456 URLFetcher* CreateURLFetcher(int id, | 456 scoped_ptr<URLFetcher> CreateURLFetcher(int id, |
| 457 const GURL& url, | 457 const GURL& url, |
| 458 URLFetcher::RequestType request_type, | 458 URLFetcher::RequestType request_type, |
| 459 URLFetcherDelegate* d) override; | 459 URLFetcherDelegate* d) override; |
| 460 }; | 460 }; |
| 461 | 461 |
| 462 } // namespace net | 462 } // namespace net |
| 463 | 463 |
| 464 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ | 464 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ |
| OLD | NEW |