| 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 5caf2a5ffd429f33874fa5bf7cc9a80e45f29174..334bafaf142e6cd4ad5151663cb18aa30aba5c99 100644
|
| --- a/net/proxy/proxy_service_mojo_unittest.cc
|
| +++ b/net/proxy/proxy_service_mojo_unittest.cc
|
| @@ -8,7 +8,9 @@
|
|
|
| #include "base/callback_helpers.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "net/base/load_flags.h"
|
| +#include "net/base/network_delegate_impl.h"
|
| #include "net/base/test_completion_callback.h"
|
| #include "net/dns/mock_host_resolver.h"
|
| #include "net/log/net_log.h"
|
| @@ -18,6 +20,7 @@
|
| #include "net/proxy/mojo_proxy_resolver_factory.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"
|
|
|
| @@ -36,6 +39,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
|
|
|
| @@ -50,20 +78,23 @@ class ProxyServiceMojoTest : public testing::Test,
|
| this, new ProxyConfigServiceFixed(
|
| ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))),
|
| fetcher_, new DoNothingDhcpProxyScriptFetcher(), &mock_host_resolver_,
|
| - nullptr /* NetLog* */, nullptr /* NetworkDelegate* */));
|
| + nullptr /* NetLog* */, &network_delegate_));
|
| }
|
|
|
| scoped_ptr<base::ScopedClosureRunner> CreateResolver(
|
| const mojo::String& pac_script,
|
| mojo::InterfaceRequest<interfaces::ProxyResolver> req,
|
| interfaces::HostResolverPtr host_resolver,
|
| + interfaces::ProxyResolverErrorObserverPtr error_observer,
|
| interfaces::ProxyResolverFactoryRequestClientPtr client) override {
|
| InProcessMojoProxyResolverFactory::GetInstance()->CreateResolver(
|
| - pac_script, req.Pass(), host_resolver.Pass(), client.Pass());
|
| + pac_script, req.Pass(), host_resolver.Pass(), error_observer.Pass(),
|
| + client.Pass());
|
| return make_scoped_ptr(
|
| new base::ScopedClosureRunner(on_delete_closure_.closure()));
|
| }
|
|
|
| + TestNetworkDelegate network_delegate_;
|
| MockHostResolver mock_host_resolver_;
|
| MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|.
|
| scoped_ptr<ProxyService> proxy_service_;
|
| @@ -112,4 +143,22 @@ TEST_F(ProxyServiceMojoTest, DnsResolution) {
|
| on_delete_closure_.WaitForResult();
|
| }
|
|
|
| +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
|
|
|