Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Unified Diff: net/proxy/mojo_proxy_resolver_impl_unittest.cc

Issue 939503004: Add LoadState reporting to the mojo proxy resolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-resolver-mojo
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f495c24f97eec1db6ece484f9732eadee6bd6547..e808b6f64e0163a83b5511e12ce3250270368c81 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();
int 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;
int error_ = ERR_FAILED;
eroman 2015/02/25 00:08:05 we should actually be using net::Error throughout.
Sam McNally 2015/02/26 04:00:01 Done in https://codereview.chromium.org/896203003/
+ 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() {
+ 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; "
@@ -236,6 +260,8 @@ TEST_F(MojoProxyResolverImplTest, GetProxyForUrl) {
"QUIC quic.example.com:65000; "
"DIRECT");
request->CompleteNow(OK);
+ resolver_impl_->LoadStateChanged(request.get(),
+ LOAD_STATE_RESOLVING_PROXY_FOR_URL);
client.WaitForResult();
EXPECT_EQ(net::OK, client.error());
@@ -409,7 +435,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();
}

Powered by Google App Engine
This is Rietveld 408576698