summaryrefslogtreecommitdiffstats
path: root/net/proxy/proxy_service_unittest.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-06 05:42:11 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-06 05:42:11 +0000
commit550dd1ae4b01d438a9d8e46e5069de600f0f648f (patch)
tree76de85cfaf2b4b64b1ebd65b6d8bda57e6943c20 /net/proxy/proxy_service_unittest.cc
parenta1353855e56d0154af127b9cb6df95287a4d5be5 (diff)
downloadchromium_src-550dd1ae4b01d438a9d8e46e5069de600f0f648f.zip
chromium_src-550dd1ae4b01d438a9d8e46e5069de600f0f648f.tar.gz
chromium_src-550dd1ae4b01d438a9d8e46e5069de600f0f648f.tar.bz2
Remove dependency on SingleThreadedProxyResolver from resolve_proxy_msg_helper_unittest.cc.
Extracts MockAsyncProxyResolver to "mock_proxy_resolver.h". This should be the last unittest that needs cleanup post r21631. BUG=http://crbug.com/11079 Review URL: http://codereview.chromium.org/160619 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_service_unittest.cc')
-rw-r--r--net/proxy/proxy_service_unittest.cc151
1 files changed, 1 insertions, 150 deletions
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index 3b3eb49..f4deb67 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -9,6 +9,7 @@
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
+#include "net/proxy/mock_proxy_resolver.h"
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_resolver.h"
#include "net/proxy/proxy_script_fetcher.h"
@@ -36,156 +37,6 @@ class MockProxyConfigService: public ProxyConfigService {
ProxyConfig config;
};
-// Asynchronous mock proxy resolver. All requests complete asynchronously,
-// user must call Request::CompleteNow() on a pending request to signal it.
-class MockAsyncProxyResolverBase : public ProxyResolver {
- public:
- class Request : public base::RefCounted<Request> {
- public:
- Request(MockAsyncProxyResolverBase* resolver,
- const GURL& url,
- ProxyInfo* results,
- CompletionCallback* callback)
- : resolver_(resolver),
- url_(url),
- results_(results),
- callback_(callback),
- origin_loop_(MessageLoop::current()) {
- }
-
- const GURL& url() const { return url_; }
- ProxyInfo* results() const { return results_; }
- CompletionCallback* callback() const { return callback_; }
-
- void CompleteNow(int rv) {
- CompletionCallback* callback = callback_;
-
- // May delete |this|.
- resolver_->RemovePendingRequest(this);
-
- callback->Run(rv);
- }
-
- private:
- MockAsyncProxyResolverBase* resolver_;
- const GURL url_;
- ProxyInfo* results_;
- CompletionCallback* callback_;
- MessageLoop* origin_loop_;
- };
-
- class SetPacScriptRequest {
- public:
- SetPacScriptRequest(MockAsyncProxyResolverBase* resolver,
- const GURL& pac_url,
- const std::string& pac_bytes,
- CompletionCallback* callback)
- : resolver_(resolver),
- pac_url_(pac_url),
- pac_bytes_(pac_bytes),
- callback_(callback),
- origin_loop_(MessageLoop::current()) {
- }
-
- const GURL& pac_url() const { return pac_url_; }
- const std::string& pac_bytes() const { return pac_bytes_; }
-
- void CompleteNow(int rv) {
- CompletionCallback* callback = callback_;
-
- // Will delete |this|.
- resolver_->RemovePendingSetPacScriptRequest(this);
-
- callback->Run(rv);
- }
-
- private:
- MockAsyncProxyResolverBase* resolver_;
- const GURL pac_url_;
- const std::string pac_bytes_;
- CompletionCallback* callback_;
- MessageLoop* origin_loop_;
- };
-
- typedef std::vector<scoped_refptr<Request> > RequestsList;
-
- // ProxyResolver implementation:
- virtual int GetProxyForURL(const GURL& url,
- ProxyInfo* results,
- CompletionCallback* callback,
- RequestHandle* request_handle) {
- scoped_refptr<Request> request = new Request(this, url, results, callback);
- pending_requests_.push_back(request);
-
- if (request_handle)
- *request_handle = reinterpret_cast<RequestHandle>(request.get());
-
- // Test code completes the request by calling request->CompleteNow().
- return ERR_IO_PENDING;
- }
-
- virtual void CancelRequest(RequestHandle request_handle) {
- scoped_refptr<Request> request = reinterpret_cast<Request*>(request_handle);
- cancelled_requests_.push_back(request);
- RemovePendingRequest(request);
- }
-
- virtual int SetPacScript(const GURL& pac_url,
- const std::string& pac_bytes,
- CompletionCallback* callback) {
- EXPECT_EQ(NULL, pending_set_pac_script_request_.get());
- pending_set_pac_script_request_.reset(
- new SetPacScriptRequest(this, pac_url, pac_bytes, callback));
- // Finished when user calls SetPacScriptRequest::CompleteNow().
- return ERR_IO_PENDING;
- }
-
- const RequestsList& pending_requests() const {
- return pending_requests_;
- }
-
- const RequestsList& cancelled_requests() const {
- return cancelled_requests_;
- }
-
- SetPacScriptRequest* pending_set_pac_script_request() const {
- return pending_set_pac_script_request_.get();
- }
-
- void RemovePendingRequest(Request* request) {
- RequestsList::iterator it = std::find(
- pending_requests_.begin(), pending_requests_.end(), request);
- DCHECK(it != pending_requests_.end());
- pending_requests_.erase(it);
- }
-
- void RemovePendingSetPacScriptRequest(SetPacScriptRequest* request) {
- EXPECT_EQ(request, pending_set_pac_script_request());
- pending_set_pac_script_request_.reset();
- }
-
- protected:
- explicit MockAsyncProxyResolverBase(bool expects_pac_bytes)
- : ProxyResolver(expects_pac_bytes) {}
-
- private:
- RequestsList pending_requests_;
- RequestsList cancelled_requests_;
- scoped_ptr<SetPacScriptRequest> pending_set_pac_script_request_;
-};
-
-class MockAsyncProxyResolver : public MockAsyncProxyResolverBase {
- public:
- MockAsyncProxyResolver()
- : MockAsyncProxyResolverBase(false /*expects_pac_bytes*/) {}
-};
-
-class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase {
- public:
- MockAsyncProxyResolverExpectsBytes()
- : MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {}
-};
-
} // namespace
// A mock ProxyScriptFetcher. No result will be returned to the fetch client