| Index: net/proxy/proxy_service_unittest.cc
|
| diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
|
| index f5ae3d77e7d35a22313a802bc624631ed7d62ca7..aac8bc9683d57a7212edafeae2c0179f5d4772a7 100644
|
| --- a/net/proxy/proxy_service_unittest.cc
|
| +++ b/net/proxy/proxy_service_unittest.cc
|
| @@ -15,7 +15,9 @@
|
| #include "net/base/net_log.h"
|
| #include "net/base/net_log_unittest.h"
|
| #include "net/base/test_completion_callback.h"
|
| +#include "net/proxy/dhcp_proxy_script_fetcher.h"
|
| #include "net/proxy/mock_proxy_resolver.h"
|
| +#include "net/proxy/mock_proxy_script_fetcher.h"
|
| #include "net/proxy/proxy_config_service.h"
|
| #include "net/proxy/proxy_resolver.h"
|
| #include "net/proxy/proxy_script_fetcher.h"
|
| @@ -67,53 +69,6 @@ class MockProxyConfigService: public ProxyConfigService {
|
|
|
| } // namespace
|
|
|
| -// A mock ProxyScriptFetcher. No result will be returned to the fetch client
|
| -// until we call NotifyFetchCompletion() to set the results.
|
| -class MockProxyScriptFetcher : public ProxyScriptFetcher {
|
| - public:
|
| - MockProxyScriptFetcher()
|
| - : pending_request_callback_(NULL), pending_request_text_(NULL) {
|
| - }
|
| -
|
| - // ProxyScriptFetcher implementation.
|
| - virtual int Fetch(const GURL& url,
|
| - string16* text,
|
| - CompletionCallback* callback) {
|
| - DCHECK(!has_pending_request());
|
| -
|
| - // Save the caller's information, and have them wait.
|
| - pending_request_url_ = url;
|
| - pending_request_callback_ = callback;
|
| - pending_request_text_ = text;
|
| - return ERR_IO_PENDING;
|
| - }
|
| -
|
| - void NotifyFetchCompletion(int result, const std::string& ascii_text) {
|
| - DCHECK(has_pending_request());
|
| - *pending_request_text_ = ASCIIToUTF16(ascii_text);
|
| - CompletionCallback* callback = pending_request_callback_;
|
| - pending_request_callback_ = NULL;
|
| - callback->Run(result);
|
| - }
|
| -
|
| - virtual void Cancel() {}
|
| -
|
| - virtual URLRequestContext* GetRequestContext() { return NULL; }
|
| -
|
| - const GURL& pending_request_url() const {
|
| - return pending_request_url_;
|
| - }
|
| -
|
| - bool has_pending_request() const {
|
| - return pending_request_callback_ != NULL;
|
| - }
|
| -
|
| - private:
|
| - GURL pending_request_url_;
|
| - CompletionCallback* pending_request_callback_;
|
| - string16* pending_request_text_;
|
| -};
|
| -
|
| TEST(ProxyServiceTest, Direct) {
|
| MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
|
| ProxyService service(new MockProxyConfigService(
|
| @@ -449,7 +404,8 @@ TEST(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher();
|
| + service.SetProxyScriptFetchers(fetcher, dhcp_fetcher);
|
|
|
| // Start resolve request.
|
| GURL url("http://www.google.com/");
|
| @@ -1183,7 +1139,8 @@ TEST(ProxyServiceTest, InitialPACScriptDownload) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 3 requests.
|
|
|
| @@ -1262,7 +1219,8 @@ TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 2 requests.
|
|
|
| @@ -1290,7 +1248,8 @@ TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) {
|
| // the initialization with the new fetcher.
|
|
|
| fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Nothing has been sent to the resolver yet.
|
| EXPECT_TRUE(resolver->pending_requests().empty());
|
| @@ -1319,7 +1278,8 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 3 requests.
|
| ProxyInfo info1;
|
| @@ -1410,7 +1370,8 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 2 requests.
|
|
|
| @@ -1480,7 +1441,8 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 2 requests.
|
|
|
| @@ -1555,7 +1517,8 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 2 requests.
|
|
|
| @@ -1612,7 +1575,8 @@ TEST(ProxyServiceTest, BypassDoesntApplyToPac) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 1 requests.
|
|
|
| @@ -1679,7 +1643,8 @@ TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) {
|
| ProxyService service(config_service, resolver, NULL);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Start 1 request.
|
|
|
| @@ -1810,7 +1775,8 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
|
| ProxyService service(config_service, resolver, &log);
|
|
|
| MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
|
| - service.SetProxyScriptFetcher(fetcher);
|
| + service.SetProxyScriptFetchers(fetcher,
|
| + new DoNothingDhcpProxyScriptFetcher());
|
|
|
| // Disable the "wait after IP address changes" hack, so this unit-test can
|
| // complete quickly.
|
|
|