Enables compositing support for webview.
[chromium-blink-merge.git] / net / proxy / mock_proxy_resolver.h
blobe68e42be4abb8c434d146c1548e9d4614f728af9
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
3 // found in the LICENSE file.
5 #ifndef NET_PROXY_MOCK_PROXY_RESOLVER_H_
6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "googleurl/src/gurl.h"
12 #include "net/base/net_errors.h"
13 #include "net/proxy/proxy_resolver.h"
15 class MessageLoop;
17 namespace net {
19 // Asynchronous mock proxy resolver. All requests complete asynchronously,
20 // user must call Request::CompleteNow() on a pending request to signal it.
21 class MockAsyncProxyResolverBase : public ProxyResolver {
22 public:
23 class Request : public base::RefCounted<Request> {
24 public:
25 Request(MockAsyncProxyResolverBase* resolver,
26 const GURL& url,
27 ProxyInfo* results,
28 const net::CompletionCallback& callback);
30 const GURL& url() const { return url_; }
31 ProxyInfo* results() const { return results_; }
32 const net::CompletionCallback& callback() const { return callback_; }
34 void CompleteNow(int rv);
36 private:
37 friend class base::RefCounted<Request>;
39 virtual ~Request();
41 MockAsyncProxyResolverBase* resolver_;
42 const GURL url_;
43 ProxyInfo* results_;
44 net::CompletionCallback callback_;
45 MessageLoop* origin_loop_;
48 class SetPacScriptRequest {
49 public:
50 SetPacScriptRequest(
51 MockAsyncProxyResolverBase* resolver,
52 const scoped_refptr<ProxyResolverScriptData>& script_data,
53 const net::CompletionCallback& callback);
54 ~SetPacScriptRequest();
56 const ProxyResolverScriptData* script_data() const { return script_data_; }
58 void CompleteNow(int rv);
60 private:
61 MockAsyncProxyResolverBase* resolver_;
62 const scoped_refptr<ProxyResolverScriptData> script_data_;
63 net::CompletionCallback callback_;
64 MessageLoop* origin_loop_;
67 typedef std::vector<scoped_refptr<Request> > RequestsList;
69 virtual ~MockAsyncProxyResolverBase();
71 // ProxyResolver implementation.
72 virtual int GetProxyForURL(const GURL& url,
73 ProxyInfo* results,
74 const net::CompletionCallback& callback,
75 RequestHandle* request_handle,
76 const BoundNetLog& /*net_log*/) OVERRIDE;
77 virtual void CancelRequest(RequestHandle request_handle) OVERRIDE;
78 virtual LoadState GetLoadState(RequestHandle request_handle) const OVERRIDE;
79 virtual LoadState GetLoadStateThreadSafe(
80 RequestHandle request_handle) const OVERRIDE;
81 virtual int SetPacScript(
82 const scoped_refptr<ProxyResolverScriptData>& script_data,
83 const net::CompletionCallback& callback) OVERRIDE;
84 virtual void CancelSetPacScript() OVERRIDE;
86 const RequestsList& pending_requests() const {
87 return pending_requests_;
90 const RequestsList& cancelled_requests() const {
91 return cancelled_requests_;
94 SetPacScriptRequest* pending_set_pac_script_request() const;
96 bool has_pending_set_pac_script_request() const {
97 return pending_set_pac_script_request_.get() != NULL;
100 void RemovePendingRequest(Request* request);
102 void RemovePendingSetPacScriptRequest(SetPacScriptRequest* request);
104 protected:
105 explicit MockAsyncProxyResolverBase(bool expects_pac_bytes);
107 private:
108 RequestsList pending_requests_;
109 RequestsList cancelled_requests_;
110 scoped_ptr<SetPacScriptRequest> pending_set_pac_script_request_;
113 class MockAsyncProxyResolver : public MockAsyncProxyResolverBase {
114 public:
115 MockAsyncProxyResolver()
116 : MockAsyncProxyResolverBase(false /*expects_pac_bytes*/) {}
119 class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase {
120 public:
121 MockAsyncProxyResolverExpectsBytes()
122 : MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {}
125 } // namespace net
127 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_