| Index: net/proxy/proxy_service_mojo_unittest.cc
|
| diff --git a/net/proxy/proxy_service_mojo_unittest.cc b/net/proxy/proxy_service_mojo_unittest.cc
|
| index 4f9491f1a803f315164b5cd65496ec9c8762192c..4918731a925652de3cc5d98703cdce94b808386c 100644
|
| --- a/net/proxy/proxy_service_mojo_unittest.cc
|
| +++ b/net/proxy/proxy_service_mojo_unittest.cc
|
| @@ -7,14 +7,17 @@
|
| #include <string>
|
|
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/base/net_log.h"
|
| +#include "net/base/network_delegate_impl.h"
|
| #include "net/base/test_completion_callback.h"
|
| #include "net/dns/mock_host_resolver.h"
|
| #include "net/proxy/dhcp_proxy_script_fetcher.h"
|
| #include "net/proxy/mock_proxy_script_fetcher.h"
|
| #include "net/proxy/proxy_config_service_fixed.h"
|
| #include "net/proxy/proxy_service.h"
|
| +#include "net/test/event_waiter.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| @@ -33,6 +36,31 @@ const char kDnsResolvePacScript[] =
|
| " return 'DIRECT';\n"
|
| " return 'QUIC bar:4321';\n"
|
| "}";
|
| +const char kErrorPacScript[] =
|
| + "function FindProxyForURL(url, host) {\n"
|
| + " throw new Error('test error');\n"
|
| + "}";
|
| +
|
| +class TestNetworkDelegate : public NetworkDelegateImpl {
|
| + public:
|
| + enum Event {
|
| + PAC_SCRIPT_ERROR,
|
| + };
|
| +
|
| + EventWaiter<Event>& event_waiter() { return event_waiter_; }
|
| +
|
| + void OnPACScriptError(int line_number, const base::string16& error) override;
|
| +
|
| + private:
|
| + EventWaiter<Event> event_waiter_;
|
| +};
|
| +
|
| +void TestNetworkDelegate::OnPACScriptError(int line_number,
|
| + const base::string16& error) {
|
| + event_waiter_.NotifyEvent(PAC_SCRIPT_ERROR);
|
| + EXPECT_EQ(2, line_number);
|
| + EXPECT_TRUE(base::UTF16ToUTF8(error).find("test error") != std::string::npos);
|
| +}
|
|
|
| } // namespace
|
|
|
| @@ -46,9 +74,10 @@ class ProxyServiceMojoTest : public testing::Test {
|
| new ProxyConfigServiceFixed(
|
| ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))),
|
| fetcher_, new DoNothingDhcpProxyScriptFetcher(), &mock_host_resolver_,
|
| - nullptr /* NetLog* */, nullptr /* NetworkDelegate* */));
|
| + nullptr /* NetLog* */, &network_delegate_));
|
| }
|
|
|
| + TestNetworkDelegate network_delegate_;
|
| MockHostResolver mock_host_resolver_;
|
| MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|.
|
| scoped_ptr<ProxyService> proxy_service_;
|
| @@ -92,4 +121,22 @@ TEST_F(ProxyServiceMojoTest, DnsResolution) {
|
| EXPECT_EQ(1u, mock_host_resolver_.num_resolve());
|
| }
|
|
|
| +TEST_F(ProxyServiceMojoTest, Error) {
|
| + ProxyInfo info;
|
| + TestCompletionCallback callback;
|
| + EXPECT_EQ(ERR_IO_PENDING,
|
| + proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info,
|
| + callback.callback(), nullptr, nullptr,
|
| + BoundNetLog()));
|
| +
|
| + // Proxy script fetcher should have a fetch triggered by the first
|
| + // |ResolveProxy()| request.
|
| + EXPECT_TRUE(fetcher_->has_pending_request());
|
| + EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
|
| + fetcher_->NotifyFetchCompletion(OK, kErrorPacScript);
|
| +
|
| + network_delegate_.event_waiter().WaitForEvent(
|
| + TestNetworkDelegate::PAC_SCRIPT_ERROR);
|
| +}
|
| +
|
| } // namespace net
|
|
|