summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 23:44:05 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 23:44:05 +0000
commit8f2d8bddb95c01334a497ee5bff6f16ab02598d0 (patch)
treef9dab06b96c01a415a07e189c095121ca605e720 /net/url_request
parente2f963f190d976d507c2c56c34d0358121221a78 (diff)
downloadchromium_src-8f2d8bddb95c01334a497ee5bff6f16ab02598d0.zip
chromium_src-8f2d8bddb95c01334a497ee5bff6f16ab02598d0.tar.gz
chromium_src-8f2d8bddb95c01334a497ee5bff6f16ab02598d0.tar.bz2
Move test_url_fetcher_factory.* from content/ to net/url_request
Also mark URLFetcherImpl as NET_EXPORT_PRIVATE instead of NET_EXPORT, as it shouldn't be used except for some code in test_url_fetcher_factory.*. Update all references. BUG=118220 TEST= TBR=jam@chromium.org,jhawkins@chromium.org,mnissler@chromium.org Review URL: https://chromiumcodereview.appspot.com/10581012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/test_url_fetcher_factory.cc346
-rw-r--r--net/url_request/test_url_fetcher_factory.h299
-rw-r--r--net/url_request/url_fetcher_impl.h3
3 files changed, 646 insertions, 2 deletions
diff --git a/net/url_request/test_url_fetcher_factory.cc b/net/url_request/test_url_fetcher_factory.cc
new file mode 100644
index 0000000..03169f8
--- /dev/null
+++ b/net/url_request/test_url_fetcher_factory.cc
@@ -0,0 +1,346 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/url_request/test_url_fetcher_factory.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop.h"
+#include "net/base/host_port_pair.h"
+#include "net/http/http_response_headers.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "net/url_request/url_fetcher_impl.h"
+#include "net/url_request/url_request_status.h"
+
+namespace net {
+
+ScopedURLFetcherFactory::ScopedURLFetcherFactory(
+ URLFetcherFactory* factory) {
+ DCHECK(!URLFetcherImpl::factory());
+ URLFetcherImpl::set_factory(factory);
+}
+
+ScopedURLFetcherFactory::~ScopedURLFetcherFactory() {
+ DCHECK(URLFetcherImpl::factory());
+ URLFetcherImpl::set_factory(NULL);
+}
+
+TestURLFetcher::TestURLFetcher(int id,
+ const GURL& url,
+ URLFetcherDelegate* d)
+ : id_(id),
+ original_url_(url),
+ delegate_(d),
+ did_receive_last_chunk_(false),
+ fake_load_flags_(0),
+ fake_response_code_(-1),
+ fake_response_destination_(STRING),
+ fake_was_fetched_via_proxy_(false),
+ fake_max_retries_(0) {
+}
+
+TestURLFetcher::~TestURLFetcher() {
+}
+
+void TestURLFetcher::SetUploadData(const std::string& upload_content_type,
+ const std::string& upload_content) {
+ upload_data_ = upload_content;
+}
+
+void TestURLFetcher::SetChunkedUpload(const std::string& upload_content_type) {
+}
+
+void TestURLFetcher::AppendChunkToUpload(const std::string& data,
+ bool is_last_chunk) {
+ DCHECK(!did_receive_last_chunk_);
+ did_receive_last_chunk_ = is_last_chunk;
+ chunks_.push_back(data);
+}
+
+void TestURLFetcher::SetLoadFlags(int load_flags) {
+ fake_load_flags_= load_flags;
+}
+
+int TestURLFetcher::GetLoadFlags() const {
+ return fake_load_flags_;
+}
+
+void TestURLFetcher::SetReferrer(const std::string& referrer) {
+}
+
+void TestURLFetcher::SetExtraRequestHeaders(
+ const std::string& extra_request_headers) {
+ fake_extra_request_headers_.Clear();
+ fake_extra_request_headers_.AddHeadersFromString(extra_request_headers);
+}
+
+void TestURLFetcher::AddExtraRequestHeader(const std::string& header_line) {
+ fake_extra_request_headers_.AddHeaderFromString(header_line);
+}
+
+void TestURLFetcher::GetExtraRequestHeaders(
+ HttpRequestHeaders* headers) const {
+ *headers = fake_extra_request_headers_;
+}
+
+void TestURLFetcher::SetRequestContext(
+ URLRequestContextGetter* request_context_getter) {
+}
+
+void TestURLFetcher::SetFirstPartyForCookies(
+ const GURL& first_party_for_cookies) {
+}
+
+void TestURLFetcher::SetURLRequestUserData(
+ const void* key,
+ const CreateDataCallback& create_data_callback) {
+}
+
+void TestURLFetcher::SetStopOnRedirect(bool stop_on_redirect) {
+}
+
+void TestURLFetcher::SetAutomaticallyRetryOn5xx(bool retry) {
+}
+
+void TestURLFetcher::SetMaxRetries(int max_retries) {
+ fake_max_retries_ = max_retries;
+}
+
+int TestURLFetcher::GetMaxRetries() const {
+ return fake_max_retries_;
+}
+
+base::TimeDelta TestURLFetcher::GetBackoffDelay() const {
+ return fake_backoff_delay_;
+}
+
+void TestURLFetcher::SaveResponseToFileAtPath(
+ const FilePath& file_path,
+ scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) {
+}
+
+void TestURLFetcher::SaveResponseToTemporaryFile(
+ scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) {
+}
+
+HttpResponseHeaders* TestURLFetcher::GetResponseHeaders() const {
+ return fake_response_headers_;
+}
+
+HostPortPair TestURLFetcher::GetSocketAddress() const {
+ NOTIMPLEMENTED();
+ return HostPortPair();
+}
+
+bool TestURLFetcher::WasFetchedViaProxy() const {
+ return fake_was_fetched_via_proxy_;
+}
+
+void TestURLFetcher::Start() {
+ // Overriden to do nothing. It is assumed the caller will notify the delegate.
+}
+
+const GURL& TestURLFetcher::GetOriginalURL() const {
+ return original_url_;
+}
+
+const GURL& TestURLFetcher::GetURL() const {
+ return fake_url_;
+}
+
+const URLRequestStatus& TestURLFetcher::GetStatus() const {
+ return fake_status_;
+}
+
+int TestURLFetcher::GetResponseCode() const {
+ return fake_response_code_;
+}
+
+const ResponseCookies& TestURLFetcher::GetCookies() const {
+ return fake_cookies_;
+}
+
+bool TestURLFetcher::FileErrorOccurred(
+ base::PlatformFileError* out_error_code) const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+void TestURLFetcher::ReceivedContentWasMalformed() {
+}
+
+bool TestURLFetcher::GetResponseAsString(
+ std::string* out_response_string) const {
+ if (fake_response_destination_ != STRING)
+ return false;
+
+ *out_response_string = fake_response_string_;
+ return true;
+}
+
+bool TestURLFetcher::GetResponseAsFilePath(
+ bool take_ownership, FilePath* out_response_path) const {
+ if (fake_response_destination_ != TEMP_FILE)
+ return false;
+
+ *out_response_path = fake_response_file_path_;
+ return true;
+}
+
+void TestURLFetcher::set_status(const URLRequestStatus& status) {
+ fake_status_ = status;
+}
+
+void TestURLFetcher::set_was_fetched_via_proxy(bool flag) {
+ fake_was_fetched_via_proxy_ = flag;
+}
+
+void TestURLFetcher::set_response_headers(
+ scoped_refptr<HttpResponseHeaders> headers) {
+ fake_response_headers_ = headers;
+}
+
+void TestURLFetcher::set_backoff_delay(base::TimeDelta backoff_delay) {
+ fake_backoff_delay_ = backoff_delay;
+}
+
+void TestURLFetcher::SetResponseString(const std::string& response) {
+ fake_response_destination_ = STRING;
+ fake_response_string_ = response;
+}
+
+void TestURLFetcher::SetResponseFilePath(const FilePath& path) {
+ fake_response_destination_ = TEMP_FILE;
+ fake_response_file_path_ = path;
+}
+
+TestURLFetcherFactory::TestURLFetcherFactory()
+ : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+}
+
+TestURLFetcherFactory::~TestURLFetcherFactory() {}
+
+URLFetcher* TestURLFetcherFactory::CreateURLFetcher(
+ int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) {
+ TestURLFetcher* fetcher = new TestURLFetcher(id, url, d);
+ fetchers_[id] = fetcher;
+ return fetcher;
+}
+
+TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const {
+ Fetchers::const_iterator i = fetchers_.find(id);
+ return i == fetchers_.end() ? NULL : i->second;
+}
+
+void TestURLFetcherFactory::RemoveFetcherFromMap(int id) {
+ Fetchers::iterator i = fetchers_.find(id);
+ DCHECK(i != fetchers_.end());
+ fetchers_.erase(i);
+}
+
+// This class is used by the FakeURLFetcherFactory below.
+class FakeURLFetcher : public TestURLFetcher {
+ public:
+ // Normal URL fetcher constructor but also takes in a pre-baked response.
+ FakeURLFetcher(const GURL& url,
+ URLFetcherDelegate* d,
+ const std::string& response_data, bool success)
+ : TestURLFetcher(0, url, d),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
+ set_status(URLRequestStatus(
+ success ? URLRequestStatus::SUCCESS :
+ URLRequestStatus::FAILED,
+ 0));
+ set_response_code(success ? 200 : 500);
+ SetResponseString(response_data);
+ }
+
+ // Start the request. This will call the given delegate asynchronously
+ // with the pre-baked response as parameter.
+ virtual void Start() OVERRIDE {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr()));
+ }
+
+ virtual const GURL& GetURL() const OVERRIDE {
+ return TestURLFetcher::GetOriginalURL();
+ }
+
+ private:
+ virtual ~FakeURLFetcher() {
+ }
+
+ // This is the method which actually calls the delegate that is passed in the
+ // constructor.
+ void RunDelegate() {
+ delegate()->OnURLFetchComplete(this);
+ }
+
+ base::WeakPtrFactory<FakeURLFetcher> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher);
+};
+
+FakeURLFetcherFactory::FakeURLFetcherFactory()
+ : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ default_factory_(NULL) {
+}
+
+FakeURLFetcherFactory::FakeURLFetcherFactory(
+ URLFetcherFactory* default_factory)
+ : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ default_factory_(default_factory) {
+}
+
+FakeURLFetcherFactory::~FakeURLFetcherFactory() {}
+
+URLFetcher* FakeURLFetcherFactory::CreateURLFetcher(
+ int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) {
+ FakeResponseMap::const_iterator it = fake_responses_.find(url);
+ if (it == fake_responses_.end()) {
+ if (default_factory_ == NULL) {
+ // If we don't have a baked response for that URL we return NULL.
+ DLOG(ERROR) << "No baked response for URL: " << url.spec();
+ return NULL;
+ } else {
+ return default_factory_->CreateURLFetcher(id, url, request_type, d);
+ }
+ }
+ return new FakeURLFetcher(url, d, it->second.first, it->second.second);
+}
+
+void FakeURLFetcherFactory::SetFakeResponse(const std::string& url,
+ const std::string& response_data,
+ bool success) {
+ // Overwrite existing URL if it already exists.
+ fake_responses_[GURL(url)] = std::make_pair(response_data, success);
+}
+
+void FakeURLFetcherFactory::ClearFakeResponses() {
+ fake_responses_.clear();
+}
+
+URLFetcherImplFactory::URLFetcherImplFactory() {}
+
+URLFetcherImplFactory::~URLFetcherImplFactory() {}
+
+URLFetcher* URLFetcherImplFactory::CreateURLFetcher(
+ int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) {
+ return new URLFetcherImpl(url, request_type, d);
+}
+
+} // namespace net
diff --git a/net/url_request/test_url_fetcher_factory.h b/net/url_request/test_url_fetcher_factory.h
new file mode 100644
index 0000000..6d12345
--- /dev/null
+++ b/net/url_request/test_url_fetcher_factory.h
@@ -0,0 +1,299 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
+#define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
+#pragma once
+
+#include <list>
+#include <map>
+#include <string>
+#include <utility>
+
+#include "base/compiler_specific.h"
+#include "base/threading/non_thread_safe.h"
+#include "googleurl/src/gurl.h"
+#include "net/http/http_request_headers.h"
+#include "net/url_request/url_fetcher_factory.h"
+#include "net/url_request/url_request_status.h"
+
+namespace net {
+
+// Changes URLFetcher's Factory for the lifetime of the object.
+// Note that this scoper cannot be nested (to make it even harder to misuse).
+class ScopedURLFetcherFactory : public base::NonThreadSafe {
+ public:
+ explicit ScopedURLFetcherFactory(URLFetcherFactory* factory);
+ virtual ~ScopedURLFetcherFactory();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory);
+};
+
+// TestURLFetcher and TestURLFetcherFactory are used for testing consumers of
+// URLFetcher. TestURLFetcherFactory is a URLFetcherFactory that creates
+// TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is
+// expected that you'll grab the delegate from the TestURLFetcher and invoke
+// the callback method when appropriate. In this way it's easy to mock a
+// URLFetcher.
+// Typical usage:
+// // TestURLFetcher requires a MessageLoop.
+// MessageLoop message_loop;
+// // And an IO thread to release URLRequestContextGetter in URLFetcher::Core.
+// BrowserThreadImpl io_thread(BrowserThread::IO, &message_loop);
+// // Create factory (it automatically sets itself as URLFetcher's factory).
+// TestURLFetcherFactory factory;
+// // Do something that triggers creation of a URLFetcher.
+// ...
+// TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id);
+// DCHECK(fetcher);
+// // Notify delegate with whatever data you want.
+// fetcher->delegate()->OnURLFetchComplete(...);
+// // Make sure consumer of URLFetcher does the right thing.
+// ...
+//
+// Note: if you don't know when your request objects will be created you
+// might want to use the FakeURLFetcher and FakeURLFetcherFactory classes
+// below.
+
+class TestURLFetcher : public URLFetcher {
+ public:
+ TestURLFetcher(int id,
+ const GURL& url,
+ URLFetcherDelegate* d);
+ virtual ~TestURLFetcher();
+
+ // URLFetcher implementation
+ virtual void SetUploadData(const std::string& upload_content_type,
+ const std::string& upload_content) OVERRIDE;
+ virtual 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(
+ 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 SetMaxRetries(int max_retries) OVERRIDE;
+ virtual int GetMaxRetries() const OVERRIDE;
+ virtual base::TimeDelta GetBackoffDelay() const OVERRIDE;
+ virtual void SaveResponseToFileAtPath(
+ const FilePath& file_path,
+ scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE;
+ virtual void SaveResponseToTemporaryFile(
+ scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE;
+ virtual HttpResponseHeaders* GetResponseHeaders() const OVERRIDE;
+ virtual HostPortPair GetSocketAddress() const OVERRIDE;
+ virtual bool WasFetchedViaProxy() const OVERRIDE;
+ virtual 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 bool FileErrorOccurred(
+ base::PlatformFileError* out_error_code) const OVERRIDE;
+ virtual 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, FilePath* out_response_path) const OVERRIDE;
+
+ // Unique ID in our factory.
+ int id() const { return id_; }
+
+ // Returns the data uploaded on this URLFetcher.
+ const std::string& upload_data() const { return upload_data_; }
+
+ // Returns the chunks of data uploaded on this URLFetcher.
+ const std::list<std::string>& upload_chunks() const { return chunks_; }
+
+ // Returns the delegate installed on the URLFetcher.
+ URLFetcherDelegate* delegate() const { return delegate_; }
+
+ void set_url(const GURL& url) { fake_url_ = url; }
+ void set_status(const URLRequestStatus& status);
+ void set_response_code(int response_code) {
+ fake_response_code_ = response_code;
+ }
+ void set_cookies(const ResponseCookies& c) { fake_cookies_ = c; }
+ void set_was_fetched_via_proxy(bool flag);
+ void set_response_headers(scoped_refptr<HttpResponseHeaders> headers);
+ void set_backoff_delay(base::TimeDelta backoff_delay);
+
+ // Set string data.
+ void SetResponseString(const std::string& response);
+
+ // Set File data.
+ void SetResponseFilePath(const FilePath& path);
+
+ private:
+ enum ResponseDestinationType {
+ STRING, // Default: In a std::string
+ TEMP_FILE // Write to a temp file
+ };
+
+ const int id_;
+ const GURL original_url_;
+ URLFetcherDelegate* delegate_;
+ std::string upload_data_;
+ std::list<std::string> chunks_;
+ bool did_receive_last_chunk_;
+
+ // User can use set_* methods to provide values returned by getters.
+ // Setting the real values is not possible, because the real class
+ // has no setters. The data is a private member of a class defined
+ // in a .cc file, so we can't get at it with friendship.
+ int fake_load_flags_;
+ GURL fake_url_;
+ URLRequestStatus fake_status_;
+ int fake_response_code_;
+ ResponseCookies fake_cookies_;
+ ResponseDestinationType fake_response_destination_;
+ std::string fake_response_string_;
+ FilePath fake_response_file_path_;
+ bool fake_was_fetched_via_proxy_;
+ scoped_refptr<HttpResponseHeaders> fake_response_headers_;
+ HttpRequestHeaders fake_extra_request_headers_;
+ int fake_max_retries_;
+ base::TimeDelta fake_backoff_delay_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestURLFetcher);
+};
+
+// Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers
+// are registered in a map by the id passed to the create method.
+class TestURLFetcherFactory : public URLFetcherFactory,
+ public ScopedURLFetcherFactory {
+ public:
+ TestURLFetcherFactory();
+ virtual ~TestURLFetcherFactory();
+
+ virtual URLFetcher* CreateURLFetcher(
+ int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) OVERRIDE;
+ TestURLFetcher* GetFetcherByID(int id) const;
+ void RemoveFetcherFromMap(int id);
+
+ private:
+ // Maps from id passed to create to the returned URLFetcher.
+ typedef std::map<int, TestURLFetcher*> Fetchers;
+ Fetchers fetchers_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory);
+};
+
+// The FakeURLFetcher and FakeURLFetcherFactory classes are similar to the
+// ones above but don't require you to know when exactly the URLFetcher objects
+// will be created.
+//
+// These classes let you set pre-baked HTTP responses for particular URLs.
+// E.g., if the user requests http://a.com/ then respond with an HTTP/500.
+//
+// We assume that the thread that is calling Start() on the URLFetcher object
+// has a message loop running.
+//
+// This class is not thread-safe. You should not call SetFakeResponse or
+// ClearFakeResponse at the same time you call CreateURLFetcher. However, it is
+// OK to start URLFetcher objects while setting or clearning fake responses
+// since already created URLFetcher objects will not be affected by any changes
+// made to the fake responses (once a URLFetcher object is created you cannot
+// change its fake response).
+//
+// Example usage:
+// FakeURLFetcherFactory factory;
+//
+// // You know that class SomeService will request url http://a.com/ and you
+// // want to test the service class by returning an error.
+// factory.SetFakeResponse("http://a.com/", "", false);
+// // But if the service requests http://b.com/asdf you want to respond with
+// // a simple html page and an HTTP/200 code.
+// factory.SetFakeResponse("http://b.com/asdf",
+// "<html><body>hello world</body></html>",
+// true);
+//
+// SomeService service;
+// service.Run(); // Will eventually request these two URLs.
+
+class FakeURLFetcherFactory : public URLFetcherFactory,
+ public ScopedURLFetcherFactory {
+ public:
+ FakeURLFetcherFactory();
+ // FakeURLFetcherFactory that will delegate creating URLFetcher for unknown
+ // url to the given factory.
+ explicit FakeURLFetcherFactory(URLFetcherFactory* default_factory);
+ virtual ~FakeURLFetcherFactory();
+
+ // 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;
+
+ // Sets the fake response for a given URL. If success is true we will serve
+ // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty.
+ void SetFakeResponse(const std::string& url,
+ const std::string& response_data,
+ bool success);
+
+ // Clear all the fake responses that were previously set via
+ // SetFakeResponse().
+ void ClearFakeResponses();
+
+ private:
+ typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap;
+ FakeResponseMap fake_responses_;
+ URLFetcherFactory* default_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
+};
+
+// This is an implementation of URLFetcherFactory that will create a
+// URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in
+// integration tests to control the behavior of some requests but execute
+// all the other ones.
+class URLFetcherImplFactory : public URLFetcherFactory {
+ public:
+ URLFetcherImplFactory();
+ virtual ~URLFetcherImplFactory();
+
+ // This method will create a real URLFetcher.
+ virtual URLFetcher* CreateURLFetcher(
+ int id,
+ const GURL& url,
+ URLFetcher::RequestType request_type,
+ URLFetcherDelegate* d) OVERRIDE;
+
+};
+
+} // namespace net
+
+#endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
diff --git a/net/url_request/url_fetcher_impl.h b/net/url_request/url_fetcher_impl.h
index 9076691..eca1f19 100644
--- a/net/url_request/url_fetcher_impl.h
+++ b/net/url_request/url_fetcher_impl.h
@@ -25,8 +25,7 @@ class URLFetcherCore;
class URLFetcherDelegate;
class URLFetcherFactory;
-// TODO(akalin): Remove NET_EXPORT once URLFetcher::Create is in net/.
-class NET_EXPORT URLFetcherImpl : public URLFetcher {
+class NET_EXPORT_PRIVATE URLFetcherImpl : public URLFetcher {
public:
// |url| is the URL to send the request to.
// |request_type| is the type of request to make.