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

Unified Diff: net/proxy/proxy_resolver_mojo_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/proxy_resolver_mojo_unittest.cc
diff --git a/net/proxy/proxy_resolver_mojo_unittest.cc b/net/proxy/proxy_resolver_mojo_unittest.cc
index 4de66fd70f7daa67455a56d17cd53a2506d1bfb6..7112fc751523a2a734feaedb865971035acd0495 100644
--- a/net/proxy/proxy_resolver_mojo_unittest.cc
+++ b/net/proxy/proxy_resolver_mojo_unittest.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "mojo/common/common_type_converters.h"
@@ -73,19 +74,23 @@ class MockMojoProxyResolver : public interfaces::ProxyResolver {
int error,
mojo::Array<interfaces::ProxyServerPtr> proxy_servers);
void CloseRequestClient(const GURL& url);
+ void BlockProxyRequest(const GURL& url);
void Disconnect() { binding_.Close(); }
void WaitForSetPacScript();
+ void ClearBlockedClients();
+
private:
struct ProxyResults {
- explicit ProxyResults(bool close)
- : close(close), error(OK), proxy_servers() {}
+ ProxyResults(bool close, bool block)
+ : close(close), block(block), error(OK), proxy_servers() {}
ProxyResults(int err, mojo::Array<interfaces::ProxyServerPtr>& s)
- : close(false), error(err), proxy_servers(s.Pass()) {}
+ : close(false), block(false), error(err), proxy_servers(s.Pass()) {}
bool close;
+ bool block;
int error;
mojo::Array<interfaces::ProxyServerPtr> proxy_servers;
};
@@ -104,6 +109,7 @@ class MockMojoProxyResolver : public interfaces::ProxyResolver {
std::map<GURL, ProxyResults*> proxy_results_;
+ ScopedVector<interfaces::ProxyResolverRequestClientPtr> blocked_clients_;
mojo::Binding<interfaces::ProxyResolver> binding_;
};
@@ -115,7 +121,11 @@ void MockMojoProxyResolver::AddProxyResult(
}
void MockMojoProxyResolver::CloseRequestClient(const GURL& url) {
- proxy_results_[url] = new ProxyResults(true);
+ proxy_results_[url] = new ProxyResults(true, false);
+}
+
+void MockMojoProxyResolver::BlockProxyRequest(const GURL& url) {
+ proxy_results_[url] = new ProxyResults(false, true);
}
void MockMojoProxyResolver::AddPacScriptAction(SetPacScriptAction action) {
@@ -155,6 +165,10 @@ void MockMojoProxyResolver::WaitForSetPacScript() {
run_loop.Run();
}
+void MockMojoProxyResolver::ClearBlockedClients() {
+ blocked_clients_.clear();
+}
+
void MockMojoProxyResolver::GetProxyForUrl(
const mojo::String& url,
interfaces::ProxyResolverRequestClientPtr client) {
@@ -162,6 +176,10 @@ void MockMojoProxyResolver::GetProxyForUrl(
ASSERT_NE(nullptr, result);
if (result->close) {
client.reset();
+ } else if (result->block) {
+ client->LoadStateChanged(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
+ blocked_clients_.push_back(
+ new interfaces::ProxyResolverRequestClientPtr(client.Pass()));
} else {
client->ReportResult(result->error, result->proxy_servers.Clone());
}
@@ -238,6 +256,7 @@ class Request {
int error() const { return error_; }
const ProxyInfo& results() const { return results_; }
+ LoadState load_state() { return resolver_->GetLoadState(handle_); }
private:
// Completion callback for ProxyResolverMojo::Resolve.
@@ -439,6 +458,19 @@ TEST_F(ProxyResolverMojoTest, GetProxyForURL) {
EXPECT_EQ("DIRECT", request->results().ToPacString());
}
+TEST_F(ProxyResolverMojoTest, GetProxyForURL_LoadState) {
+ scoped_ptr<Request> request(MakeRequest(GURL("http://www.example.com")));
+ mojo_proxy_resolver_factory_.GetMockResolver()->BlockProxyRequest(
+ GURL("http://www.example.com"));
+ EXPECT_EQ(ERR_IO_PENDING, request->Resolve());
+ EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, request->load_state());
+ while (request->load_state() == LOAD_STATE_RESOLVING_PROXY_FOR_URL)
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT, request->load_state());
+ mojo_proxy_resolver_factory_.GetMockResolver()->ClearBlockedClients();
+ EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, request->WaitForResult());
+}
+
TEST_F(ProxyResolverMojoTest, GetProxyForURL_MultipleResults) {
static const char kPacString[] =
"PROXY foo1:80;DIRECT;SOCKS foo2:1234;"

Powered by Google App Engine
This is Rietveld 408576698