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

Unified Diff: chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc

Issue 2798223002: chromeos: Reintroduce proxy resolution service error test. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc
diff --git a/chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc b/chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc
index a3aa6e9142b1ca131fb1b5d650b0c506c9d5c4f7..ef2a0bcd7231f09ef37854c85367c0759ffb2c9e 100644
--- a/chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc
+++ b/chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc
@@ -61,6 +61,7 @@ class TestProxyResolver : public net::ProxyResolver {
net::ProxyInfo* mutable_proxy_info() { return &proxy_info_; }
void set_async(bool async) { async_ = async; }
+ void set_result(net::Error result) { result_ = result; }
// net::ProxyResolver:
int GetProxyForURL(const GURL& url,
@@ -71,10 +72,10 @@ class TestProxyResolver : public net::ProxyResolver {
CHECK(network_task_runner_->BelongsToCurrentThread());
results->Use(proxy_info_);
if (!async_)
- return net::OK;
+ return result_;
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, net::OK));
+ FROM_HERE, base::Bind(callback, result_));
return net::ERR_IO_PENDING;
}
@@ -87,6 +88,9 @@ class TestProxyResolver : public net::ProxyResolver {
// If true, GetProxyForURL() replies asynchronously rather than synchronously.
bool async_ = false;
+ // Final result for GetProxyForURL() to return.
+ net::Error result_ = net::OK;
+
DISALLOW_COPY_AND_ASSIGN(TestProxyResolver);
};
@@ -150,9 +154,12 @@ class TestDelegate : public ProxyResolutionServiceProvider::Delegate {
void CreateProxyServiceOnNetworkThread() {
CHECK(context_getter_->GetNetworkTaskRunner()->BelongsToCurrentThread());
- // The config's autodetect property needs to be set in order for
- // net::ProxyService to send requests to our resolver.
- net::ProxyConfig config = net::ProxyConfig::CreateAutoDetect();
+ // Setting a mandatory PAC URL makes |proxy_service_| query
+ // |proxy_resolver_| and also lets us generate
+ // net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED errors.
+ net::ProxyConfig config;
+ config.set_pac_url(GURL("http://www.example.com"));
+ config.set_pac_mandatory(true);
Daniel Erat 2017/04/06 01:21:39 is it legitimate to always set this, or should i o
eroman 2017/04/07 23:54:12 As written is good!
proxy_service_ = base::MakeUnique<net::ProxyService>(
base::MakeUnique<net::ProxyConfigServiceFixed>(config),
base::MakeUnique<TestProxyResolverFactory>(proxy_resolver_),
@@ -382,4 +389,26 @@ TEST_F(ProxyResolutionServiceProviderTest, ResponseAsync) {
EXPECT_FALSE(signal);
}
+TEST_F(ProxyResolutionServiceProviderTest, ResponseError) {
+ const char kSourceURL[] = "http://www.gmail.com/";
+ proxy_resolver_->set_result(net::ERR_FAILED);
+ std::unique_ptr<dbus::Response> response;
+ std::unique_ptr<SignalInfo> signal;
+ CallMethod(kSourceURL, false /* request_signal */, &response, &signal);
+
+ // The response should contain empty proxy info and a "mandatory proxy config
+ // failed" error (which the error from the resolver will be mapped to).
+ ASSERT_TRUE(response);
+ dbus::MessageReader reader(response.get());
+ std::string proxy_info, error;
+ EXPECT_TRUE(reader.PopString(&proxy_info));
+ EXPECT_TRUE(reader.PopString(&error));
+ EXPECT_EQ("DIRECT", proxy_info);
Daniel Erat 2017/04/06 01:21:39 it's a bit surprising to me that the chrome os cod
eroman 2017/04/07 23:54:12 .. that I can't comment on, not familiar with the
+ EXPECT_EQ(net::ErrorToString(net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED),
+ error);
+
+ // No signal should've been emitted.
+ EXPECT_FALSE(signal);
+}
+
} // namespace chromeos
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698