TestURLFetcher(int id,
const GURL& url,
URLFetcherDelegate* d);
- virtual ~TestURLFetcher();
+ ~TestURLFetcher() override;
// URLFetcher implementation
- virtual void SetUploadData(const std::string& upload_content_type,
- const std::string& upload_content) OVERRIDE;
- virtual void SetUploadFilePath(
+ void SetUploadData(const std::string& upload_content_type,
+ const std::string& upload_content) override;
+ void SetUploadFilePath(
const std::string& upload_content_type,
const base::FilePath& file_path,
uint64 range_offset,
uint64 range_length,
- scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE;
- virtual void SetChunkedUpload(
- const std::string& upload_content_type) OVERRIDE;
+ scoped_refptr<base::TaskRunner> file_task_runner) override;
+ void SetChunkedUpload(const std::string& upload_content_type) override;
// Overriden to cache the chunks uploaded. Caller can read back the uploaded
// chunks with the upload_chunks() accessor.
- virtual void AppendChunkToUpload(const std::string& data,
- bool is_last_chunk) OVERRIDE;
- virtual void SetLoadFlags(int load_flags) OVERRIDE;
- virtual int GetLoadFlags() const OVERRIDE;
- virtual void SetReferrer(const std::string& referrer) OVERRIDE;
- virtual void SetExtraRequestHeaders(
- const std::string& extra_request_headers) OVERRIDE;
- virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE;
- virtual void GetExtraRequestHeaders(
- HttpRequestHeaders* headers) const OVERRIDE;
- virtual void SetRequestContext(
- URLRequestContextGetter* request_context_getter) OVERRIDE;
- virtual void SetFirstPartyForCookies(
- const GURL& first_party_for_cookies) OVERRIDE;
- virtual void SetURLRequestUserData(
+ void AppendChunkToUpload(const std::string& data,
+ bool is_last_chunk) override;
+ void SetLoadFlags(int load_flags) override;
+ int GetLoadFlags() const override;
+ void SetReferrer(const std::string& referrer) override;
+ void SetReferrerPolicy(URLRequest::ReferrerPolicy referrer_policy) override;
+ void SetExtraRequestHeaders(
+ const std::string& extra_request_headers) override;
+ void AddExtraRequestHeader(const std::string& header_line) override;
+ void SetRequestContext(
+ URLRequestContextGetter* request_context_getter) override;
+ void SetFirstPartyForCookies(const GURL& first_party_for_cookies) override;
+ void SetURLRequestUserData(
const void* key,
- const CreateDataCallback& create_data_callback) OVERRIDE;
- virtual void SetStopOnRedirect(bool stop_on_redirect) OVERRIDE;
- virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE;
- virtual void SetMaxRetriesOn5xx(int max_retries) OVERRIDE;
- virtual int GetMaxRetriesOn5xx() const OVERRIDE;
- virtual base::TimeDelta GetBackoffDelay() const OVERRIDE;
- virtual void SetAutomaticallyRetryOnNetworkChanges(int max_retries) OVERRIDE;
- virtual void SaveResponseToFileAtPath(
+ const CreateDataCallback& create_data_callback) override;
+ void SetStopOnRedirect(bool stop_on_redirect) override;
+ void SetAutomaticallyRetryOn5xx(bool retry) override;
+ void SetMaxRetriesOn5xx(int max_retries) override;
+ int GetMaxRetriesOn5xx() const override;
+ base::TimeDelta GetBackoffDelay() const override;
+ void SetAutomaticallyRetryOnNetworkChanges(int max_retries) override;
+ void SaveResponseToFileAtPath(
const base::FilePath& file_path,
- scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE;
- virtual void SaveResponseToTemporaryFile(
- scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE;
- virtual void SaveResponseWithWriter(
- scoped_ptr<URLFetcherResponseWriter> response_writer) OVERRIDE;
- virtual HttpResponseHeaders* GetResponseHeaders() const OVERRIDE;
- virtual HostPortPair GetSocketAddress() const OVERRIDE;
- virtual bool WasFetchedViaProxy() const OVERRIDE;
- virtual void Start() OVERRIDE;
+ scoped_refptr<base::SequencedTaskRunner> file_task_runner) override;
+ void SaveResponseToTemporaryFile(
+ scoped_refptr<base::SequencedTaskRunner> file_task_runner) override;
+ void SaveResponseWithWriter(
+ scoped_ptr<URLFetcherResponseWriter> response_writer) override;
+ HttpResponseHeaders* GetResponseHeaders() const override;
+ HostPortPair GetSocketAddress() const override;
+ bool WasFetchedViaProxy() const override;
+ void Start() override;
// URL we were created with. Because of how we're using URLFetcher GetURL()
// always returns an empty URL. Chances are you'll want to use
// GetOriginalURL() in your tests.
- virtual const GURL& GetOriginalURL() const OVERRIDE;
- virtual const GURL& GetURL() const OVERRIDE;
- virtual const URLRequestStatus& GetStatus() const OVERRIDE;
- virtual int GetResponseCode() const OVERRIDE;
- virtual const ResponseCookies& GetCookies() const OVERRIDE;
- virtual void ReceivedContentWasMalformed() OVERRIDE;
+ const GURL& GetOriginalURL() const override;
+ const GURL& GetURL() const override;
+ const URLRequestStatus& GetStatus() const override;
+ int GetResponseCode() const override;
+ const ResponseCookies& GetCookies() const override;
+ void ReceivedContentWasMalformed() override;
// Override response access functions to return fake data.
- virtual bool GetResponseAsString(
- std::string* out_response_string) const OVERRIDE;
- virtual bool GetResponseAsFilePath(
- bool take_ownership, base::FilePath* out_response_path) const OVERRIDE;
+ bool GetResponseAsString(std::string* out_response_string) const override;
+ bool GetResponseAsFilePath(bool take_ownership,
+ base::FilePath* out_response_path) const override;
+
+ void GetExtraRequestHeaders(HttpRequestHeaders* headers) const;
// Sets owner of this class. Set it to a non-NULL value if you want
// to automatically unregister this fetcher from the owning factory
int id() const { return id_; }
// Returns the data uploaded on this URLFetcher.
+ const std::string& upload_content_type() const {
+ return upload_content_type_;
+ }
const std::string& upload_data() const { return upload_data_; }
const base::FilePath& upload_file_path() const { return upload_file_path_; }
const GURL original_url_;
URLFetcherDelegate* delegate_;
DelegateForTests* delegate_for_tests_;
+ std::string upload_content_type_;
std::string upload_data_;
base::FilePath upload_file_path_;
std::list<std::string> chunks_;
HttpRequestHeaders fake_extra_request_headers_;
int fake_max_retries_;
base::TimeDelta fake_backoff_delay_;
+ scoped_ptr<URLFetcherResponseWriter> response_writer_;
DISALLOW_COPY_AND_ASSIGN(TestURLFetcher);
};
public ScopedURLFetcherFactory {
public:
TestURLFetcherFactory();
- virtual ~TestURLFetcherFactory();
+ ~TestURLFetcherFactory() override;
- virtual URLFetcher* CreateURLFetcher(
- int id,
- const GURL& url,
- URLFetcher::RequestType request_type,
- URLFetcherDelegate* d) OVERRIDE;
+ URLFetcher* CreateURLFetcher(int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) override;
TestURLFetcher* GetFetcherByID(int id) const;
void RemoveFetcherFromMap(int id);
void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests);
FakeURLFetcher(const GURL& url,
URLFetcherDelegate* d,
const std::string& response_data,
- HttpStatusCode response_code);
+ HttpStatusCode response_code,
+ URLRequestStatus::Status status);
// Start the request. This will call the given delegate asynchronously
// with the pre-baked response as parameter.
- virtual void Start() OVERRIDE;
+ void Start() override;
- virtual const GURL& GetURL() const OVERRIDE;
+ const GURL& GetURL() const override;
- virtual ~FakeURLFetcher();
+ ~FakeURLFetcher() override;
private:
// This is the method which actually calls the delegate that is passed in the
// // want to respond with a simple html page and an HTTP/200 code.
// factory.SetFakeResponse("http://a.com/success",
// "<html><body>hello world</body></html>",
-// HTTP_OK);
-// // You know that class SomeService will request url http://a.com/failure and
-// // you want to test the service class by returning a server error.
-// factory.SetFakeResponse("http://a.com/failure",
+// HTTP_OK,
+// URLRequestStatus::SUCCESS);
+// // You know that class SomeService will request url http://a.com/servererror
+// // and you want to test the service class by returning a server error.
+// factory.SetFakeResponse("http://a.com/servererror",
// "",
-// HTTP_INTERNAL_SERVER_ERROR);
-// // You know that class SomeService will request url http://a.com/error and
-// // you want to test the service class by returning a specific error code,
-// // say, a HTTP/401 error.
-// factory.SetFakeResponse("http://a.com/error",
+// HTTP_INTERNAL_SERVER_ERROR,
+// URLRequestStatus::SUCCESS);
+// // You know that class SomeService will request url http://a.com/autherror
+// // and you want to test the service class by returning a specific error
+// // code, say, a HTTP/401 error.
+// factory.SetFakeResponse("http://a.com/autherror",
// "some_response",
-// HTTP_UNAUTHORIZED);
+// HTTP_UNAUTHORIZED,
+// URLRequestStatus::SUCCESS);
+//
+// // You know that class SomeService will request url http://a.com/failure
+// // and you want to test the service class by returning a failure in the
+// // network layer.
+// factory.SetFakeResponse("http://a.com/failure",
+// "",
+// HTTP_INTERNAL_SERVER_ERROR,
+// URLRequestStatus::FAILURE);
//
// SomeService service;
// service.Run(); // Will eventually request these three URLs.
// |delegate| Delegate for FakeURLFetcher
// |response_data| response data for FakeURLFetcher
// |response_code| response code for FakeURLFetcher
+ // |status| URL fetch status for FakeURLFetcher
// These arguments should by default be used in instantiating FakeURLFetcher
- // as follows: new FakeURLFetcher(url, delegate, response_data, response_code)
+ // like so:
+ // new FakeURLFetcher(url, delegate, response_data, response_code, status)
typedef base::Callback<scoped_ptr<FakeURLFetcher>(
const GURL&,
URLFetcherDelegate*,
const std::string&,
- HttpStatusCode)> FakeURLFetcherCreator;
+ HttpStatusCode,
+ URLRequestStatus::Status)> FakeURLFetcherCreator;
// |default_factory|, which can be NULL, is a URLFetcherFactory that
// will be used to construct a URLFetcher in case the URL being created
FakeURLFetcherFactory(URLFetcherFactory* default_factory,
const FakeURLFetcherCreator& creator);
- virtual ~FakeURLFetcherFactory();
+ ~FakeURLFetcherFactory() override;
// If no fake response is set for the given URL this method will delegate the
// call to |default_factory_| if it is not NULL, or return NULL if it is
// NULL.
// Otherwise, it will return a URLFetcher object which will respond with the
// pre-baked response that the client has set by calling SetFakeResponse().
- virtual URLFetcher* CreateURLFetcher(
- int id,
- const GURL& url,
- URLFetcher::RequestType request_type,
- URLFetcherDelegate* d) OVERRIDE;
+ URLFetcher* CreateURLFetcher(int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) override;
// Sets the fake response for a given URL. The |response_data| may be empty.
// The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will
// return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500.
- // Note: The URLRequestStatus of FakeURLFetchers created by the factory will
- // be FAILED for HttpStatusCodes HTTP/5xx, and SUCCESS for all other codes.
+ // The |status| argument may be any URLRequestStatus::Status value. Typically,
+ // requests that return a valid HttpStatusCode have the SUCCESS status, while
+ // requests that indicate a failure to connect to the server have the FAILED
+ // status.
void SetFakeResponse(const GURL& url,
const std::string& response_data,
- HttpStatusCode response_code);
+ HttpStatusCode response_code,
+ URLRequestStatus::Status status);
// Clear all the fake responses that were previously set via
// SetFakeResponse().
void ClearFakeResponses();
private:
+ struct FakeURLResponse {
+ std::string response_data;
+ HttpStatusCode response_code;
+ URLRequestStatus::Status status;
+ };
+ typedef std::map<GURL, FakeURLResponse> FakeResponseMap;
+
const FakeURLFetcherCreator creator_;
- typedef std::map<GURL,
- std::pair<std::string, HttpStatusCode> > FakeResponseMap;
FakeResponseMap fake_responses_;
URLFetcherFactory* const default_factory_;
const GURL& url,
URLFetcherDelegate* delegate,
const std::string& response_data,
- HttpStatusCode response_code);
+ HttpStatusCode response_code,
+ URLRequestStatus::Status status);
DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
};
class URLFetcherImplFactory : public URLFetcherFactory {
public:
URLFetcherImplFactory();
- virtual ~URLFetcherImplFactory();
+ ~URLFetcherImplFactory() override;
// This method will create a real URLFetcher.
- virtual URLFetcher* CreateURLFetcher(
- int id,
- const GURL& url,
- URLFetcher::RequestType request_type,
- URLFetcherDelegate* d) OVERRIDE;
-
+ URLFetcher* CreateURLFetcher(int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) override;
};
} // namespace net