X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnet%2Furl_request%2Ftest_url_fetcher_factory.h;h=f2139d9bf0fe66d773e75ecba09de59995eabe3e;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=50ab815d63ea8b4c968df0d53c66fe2e0fea36d8;hpb=4b53d56b8a1db20d4089f6d4f37126d43f907125;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/net/url_request/test_url_fetcher_factory.h b/src/net/url_request/test_url_fetcher_factory.h index 50ab815..f2139d9 100644 --- a/src/net/url_request/test_url_fetcher_factory.h +++ b/src/net/url_request/test_url_fetcher_factory.h @@ -104,11 +104,11 @@ class TestURLFetcher : public URLFetcher { virtual void SetLoadFlags(int load_flags) OVERRIDE; virtual int GetLoadFlags() const OVERRIDE; virtual void SetReferrer(const std::string& referrer) OVERRIDE; + virtual void SetReferrerPolicy( + URLRequest::ReferrerPolicy referrer_policy) 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( @@ -124,9 +124,9 @@ class TestURLFetcher : public URLFetcher { virtual void SetAutomaticallyRetryOnNetworkChanges(int max_retries) OVERRIDE; virtual void SaveResponseToFileAtPath( const base::FilePath& file_path, - scoped_refptr file_task_runner) OVERRIDE; + scoped_refptr file_task_runner) OVERRIDE; virtual void SaveResponseToTemporaryFile( - scoped_refptr file_task_runner) OVERRIDE; + scoped_refptr file_task_runner) OVERRIDE; virtual void SaveResponseWithWriter( scoped_ptr response_writer) OVERRIDE; virtual HttpResponseHeaders* GetResponseHeaders() const OVERRIDE; @@ -149,6 +149,8 @@ class TestURLFetcher : public URLFetcher { virtual 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 // upon destruction. @@ -220,6 +222,7 @@ class TestURLFetcher : public URLFetcher { HttpRequestHeaders fake_extra_request_headers_; int fake_max_retries_; base::TimeDelta fake_backoff_delay_; + scoped_ptr response_writer_; DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); }; @@ -287,7 +290,8 @@ class FakeURLFetcher : public TestURLFetcher { 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. @@ -326,18 +330,29 @@ class FakeURLFetcher : public TestURLFetcher { // // want to respond with a simple html page and an HTTP/200 code. // factory.SetFakeResponse("http://a.com/success", // "hello world", -// 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. @@ -350,13 +365,16 @@ class FakeURLFetcherFactory : public URLFetcherFactory, // |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( 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 @@ -390,20 +408,28 @@ class FakeURLFetcherFactory : public URLFetcherFactory, // 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 FakeResponseMap; + const FakeURLFetcherCreator creator_; - typedef std::map > FakeResponseMap; FakeResponseMap fake_responses_; URLFetcherFactory* const default_factory_; @@ -411,7 +437,8 @@ class FakeURLFetcherFactory : public URLFetcherFactory, const GURL& url, URLFetcherDelegate* delegate, const std::string& response_data, - HttpStatusCode response_code); + HttpStatusCode response_code, + URLRequestStatus::Status status); DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); };