 Chromium Code Reviews
 Chromium Code Reviews Issue 939503004:
  Add LoadState reporting to the mojo proxy resolver.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-resolver-mojo
    
  
    Issue 939503004:
  Add LoadState reporting to the mojo proxy resolver.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-resolver-mojo| Index: net/proxy/mojo_proxy_resolver_impl_unittest.cc | 
| diff --git a/net/proxy/mojo_proxy_resolver_impl_unittest.cc b/net/proxy/mojo_proxy_resolver_impl_unittest.cc | 
| index a6b44294791aed1d9f7dbb7caff0bb66f742c510..7411837cf0272416641098fdce2ecf558ebb9574 100644 | 
| --- a/net/proxy/mojo_proxy_resolver_impl_unittest.cc | 
| +++ b/net/proxy/mojo_proxy_resolver_impl_unittest.cc | 
| @@ -28,15 +28,18 @@ class TestRequestClient : public interfaces::ProxyResolverRequestClient, | 
| mojo::InterfaceRequest<interfaces::ProxyResolverRequestClient> request); | 
| void WaitForResult(); | 
| + void WaitForLoadStateChange(); | 
| void WaitForConnectionError(); | 
| Error error() { return error_; } | 
| const mojo::Array<interfaces::ProxyServerPtr>& results() { return results_; } | 
| + LoadState load_state() { return load_state_; } | 
| private: | 
| // interfaces::ProxyResolverRequestClient override. | 
| void ReportResult(int32_t error, | 
| mojo::Array<interfaces::ProxyServerPtr> results) override; | 
| + void LoadStateChanged(int32_t load_state) override; | 
| // mojo::ErrorHandler override. | 
| void OnConnectionError() override; | 
| @@ -44,6 +47,7 @@ class TestRequestClient : public interfaces::ProxyResolverRequestClient, | 
| bool done_ = false; | 
| bool encountered_connection_error_ = false; | 
| Error error_ = ERR_FAILED; | 
| + LoadState load_state_ = LOAD_STATE_IDLE; | 
| mojo::Array<interfaces::ProxyServerPtr> results_; | 
| base::Closure run_loop_quit_closure_; | 
| base::Closure connection_error_callback_; | 
| @@ -67,6 +71,12 @@ void TestRequestClient::WaitForResult() { | 
| ASSERT_TRUE(done_); | 
| } | 
| +void TestRequestClient::WaitForLoadStateChange() { | 
| 
Anand Mistry (off Chromium)
2015/03/10 03:36:09
Switch to net::EventWaiter. You are, after all, wa
 
Sam McNally
2015/03/10 06:47:35
Done.
 | 
| + base::RunLoop run_loop; | 
| + run_loop_quit_closure_ = run_loop.QuitClosure(); | 
| + run_loop.Run(); | 
| +} | 
| + | 
| void TestRequestClient::WaitForConnectionError() { | 
| if (encountered_connection_error_) | 
| return; | 
| @@ -89,6 +99,12 @@ void TestRequestClient::ReportResult( | 
| done_ = true; | 
| } | 
| +void TestRequestClient::LoadStateChanged(int32_t load_state) { | 
| + load_state_ = static_cast<LoadState>(load_state); | 
| + if (!run_loop_quit_closure_.is_null()) | 
| + run_loop_quit_closure_.Run(); | 
| +} | 
| + | 
| void TestRequestClient::OnConnectionError() { | 
| if (!connection_error_callback_.is_null()) | 
| connection_error_callback_.Run(); | 
| @@ -211,12 +227,14 @@ class MojoProxyResolverImplTest : public testing::Test { | 
| scoped_ptr<CallbackMockProxyResolver> mock_resolver( | 
| new CallbackMockProxyResolver); | 
| mock_proxy_resolver_ = mock_resolver.get(); | 
| - resolver_.reset(new MojoProxyResolverImpl(mock_resolver.Pass())); | 
| + resolver_impl_.reset(new MojoProxyResolverImpl(mock_resolver.Pass())); | 
| + resolver_ = resolver_impl_.get(); | 
| } | 
| CallbackMockProxyResolver* mock_proxy_resolver_; | 
| - scoped_ptr<interfaces::ProxyResolver> resolver_; | 
| + scoped_ptr<MojoProxyResolverImpl> resolver_impl_; | 
| + interfaces::ProxyResolver* resolver_; | 
| }; | 
| TEST_F(MojoProxyResolverImplTest, GetProxyForUrl) { | 
| @@ -228,6 +246,12 @@ TEST_F(MojoProxyResolverImplTest, GetProxyForUrl) { | 
| scoped_refptr<MockAsyncProxyResolverBase::Request> request = | 
| mock_proxy_resolver_->pending_requests()[0]; | 
| EXPECT_EQ(GURL("http://example.com"), request->url()); | 
| + | 
| + resolver_impl_->LoadStateChanged(request.get(), | 
| + LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT); | 
| + client.WaitForLoadStateChange(); | 
| + EXPECT_EQ(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT, client.load_state()); | 
| + | 
| request->results()->UsePacString( | 
| "PROXY proxy.example.com:1; " | 
| "SOCKS4 socks4.example.com:2; " | 
| @@ -409,7 +433,7 @@ TEST_F(MojoProxyResolverImplTest, DestroyService) { | 
| ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); | 
| scoped_refptr<MockAsyncProxyResolverBase::Request> request = | 
| mock_proxy_resolver_->pending_requests()[0]; | 
| - resolver_.reset(); | 
| + resolver_impl_.reset(); | 
| client.WaitForConnectionError(); | 
| } |