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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/services/proxy_resolution_service_provider.h" 5 #include "chromeos/dbus/services/proxy_resolution_service_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) 54 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
55 : network_task_runner_(network_task_runner) { 55 : network_task_runner_(network_task_runner) {
56 proxy_info_.UseDirect(); 56 proxy_info_.UseDirect();
57 } 57 }
58 ~TestProxyResolver() override = default; 58 ~TestProxyResolver() override = default;
59 59
60 const net::ProxyInfo& proxy_info() const { return proxy_info_; } 60 const net::ProxyInfo& proxy_info() const { return proxy_info_; }
61 net::ProxyInfo* mutable_proxy_info() { return &proxy_info_; } 61 net::ProxyInfo* mutable_proxy_info() { return &proxy_info_; }
62 62
63 void set_async(bool async) { async_ = async; } 63 void set_async(bool async) { async_ = async; }
64 void set_result(net::Error result) { result_ = result; }
64 65
65 // net::ProxyResolver: 66 // net::ProxyResolver:
66 int GetProxyForURL(const GURL& url, 67 int GetProxyForURL(const GURL& url,
67 net::ProxyInfo* results, 68 net::ProxyInfo* results,
68 const net::CompletionCallback& callback, 69 const net::CompletionCallback& callback,
69 std::unique_ptr<Request>* request, 70 std::unique_ptr<Request>* request,
70 const net::NetLogWithSource& net_log) override { 71 const net::NetLogWithSource& net_log) override {
71 CHECK(network_task_runner_->BelongsToCurrentThread()); 72 CHECK(network_task_runner_->BelongsToCurrentThread());
72 results->Use(proxy_info_); 73 results->Use(proxy_info_);
73 if (!async_) 74 if (!async_)
74 return net::OK; 75 return result_;
75 76
76 base::ThreadTaskRunnerHandle::Get()->PostTask( 77 base::ThreadTaskRunnerHandle::Get()->PostTask(
77 FROM_HERE, base::Bind(callback, net::OK)); 78 FROM_HERE, base::Bind(callback, result_));
78 return net::ERR_IO_PENDING; 79 return net::ERR_IO_PENDING;
79 } 80 }
80 81
81 private: 82 private:
82 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 83 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
83 84
84 // Proxy info for GetProxyForURL() to return. 85 // Proxy info for GetProxyForURL() to return.
85 net::ProxyInfo proxy_info_; 86 net::ProxyInfo proxy_info_;
86 87
87 // If true, GetProxyForURL() replies asynchronously rather than synchronously. 88 // If true, GetProxyForURL() replies asynchronously rather than synchronously.
88 bool async_ = false; 89 bool async_ = false;
89 90
91 // Final result for GetProxyForURL() to return.
92 net::Error result_ = net::OK;
93
90 DISALLOW_COPY_AND_ASSIGN(TestProxyResolver); 94 DISALLOW_COPY_AND_ASSIGN(TestProxyResolver);
91 }; 95 };
92 96
93 // Trivial net::ProxyResolverFactory implementation that synchronously creates 97 // Trivial net::ProxyResolverFactory implementation that synchronously creates
94 // net::ForwardingProxyResolvers that forward to a single passed-in resolver. 98 // net::ForwardingProxyResolvers that forward to a single passed-in resolver.
95 class TestProxyResolverFactory : public net::ProxyResolverFactory { 99 class TestProxyResolverFactory : public net::ProxyResolverFactory {
96 public: 100 public:
97 // Ownership of |resolver| remains with the caller. |resolver| must outlive 101 // Ownership of |resolver| remains with the caller. |resolver| must outlive
98 // the forwarding resolvers returned by CreateProxyResolver(). 102 // the forwarding resolvers returned by CreateProxyResolver().
99 explicit TestProxyResolverFactory(net::ProxyResolver* resolver) 103 explicit TestProxyResolverFactory(net::ProxyResolver* resolver)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 scoped_refptr<net::URLRequestContextGetter> GetRequestContext() override { 147 scoped_refptr<net::URLRequestContextGetter> GetRequestContext() override {
144 return context_getter_; 148 return context_getter_;
145 } 149 }
146 150
147 private: 151 private:
148 // Helper method for the constructor that initializes |proxy_service_| and 152 // Helper method for the constructor that initializes |proxy_service_| and
149 // injects it into |context_getter_|'s context. 153 // injects it into |context_getter_|'s context.
150 void CreateProxyServiceOnNetworkThread() { 154 void CreateProxyServiceOnNetworkThread() {
151 CHECK(context_getter_->GetNetworkTaskRunner()->BelongsToCurrentThread()); 155 CHECK(context_getter_->GetNetworkTaskRunner()->BelongsToCurrentThread());
152 156
153 // The config's autodetect property needs to be set in order for 157 // Setting a mandatory PAC URL makes |proxy_service_| query
154 // net::ProxyService to send requests to our resolver. 158 // |proxy_resolver_| and also lets us generate
155 net::ProxyConfig config = net::ProxyConfig::CreateAutoDetect(); 159 // net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED errors.
160 net::ProxyConfig config;
161 config.set_pac_url(GURL("http://www.example.com"));
162 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!
156 proxy_service_ = base::MakeUnique<net::ProxyService>( 163 proxy_service_ = base::MakeUnique<net::ProxyService>(
157 base::MakeUnique<net::ProxyConfigServiceFixed>(config), 164 base::MakeUnique<net::ProxyConfigServiceFixed>(config),
158 base::MakeUnique<TestProxyResolverFactory>(proxy_resolver_), 165 base::MakeUnique<TestProxyResolverFactory>(proxy_resolver_),
159 nullptr /* net_log */); 166 nullptr /* net_log */);
160 context_getter_->GetURLRequestContext()->set_proxy_service( 167 context_getter_->GetURLRequestContext()->set_proxy_service(
161 proxy_service_.get()); 168 proxy_service_.get());
162 } 169 }
163 170
164 // Helper method for the destructor that resets |proxy_service_|. 171 // Helper method for the destructor that resets |proxy_service_|.
165 void DeleteProxyServiceOnNetworkThread() { 172 void DeleteProxyServiceOnNetworkThread() {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 std::string proxy_info, error; 382 std::string proxy_info, error;
376 EXPECT_TRUE(reader.PopString(&proxy_info)); 383 EXPECT_TRUE(reader.PopString(&proxy_info));
377 EXPECT_TRUE(reader.PopString(&error)); 384 EXPECT_TRUE(reader.PopString(&error));
378 EXPECT_EQ(proxy_resolver_->proxy_info().ToPacString(), proxy_info); 385 EXPECT_EQ(proxy_resolver_->proxy_info().ToPacString(), proxy_info);
379 EXPECT_EQ("", error); 386 EXPECT_EQ("", error);
380 387
381 // No signal should've been emitted. 388 // No signal should've been emitted.
382 EXPECT_FALSE(signal); 389 EXPECT_FALSE(signal);
383 } 390 }
384 391
392 TEST_F(ProxyResolutionServiceProviderTest, ResponseError) {
393 const char kSourceURL[] = "http://www.gmail.com/";
394 proxy_resolver_->set_result(net::ERR_FAILED);
395 std::unique_ptr<dbus::Response> response;
396 std::unique_ptr<SignalInfo> signal;
397 CallMethod(kSourceURL, false /* request_signal */, &response, &signal);
398
399 // The response should contain empty proxy info and a "mandatory proxy config
400 // failed" error (which the error from the resolver will be mapped to).
401 ASSERT_TRUE(response);
402 dbus::MessageReader reader(response.get());
403 std::string proxy_info, error;
404 EXPECT_TRUE(reader.PopString(&proxy_info));
405 EXPECT_TRUE(reader.PopString(&error));
406 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
407 EXPECT_EQ(net::ErrorToString(net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED),
408 error);
409
410 // No signal should've been emitted.
411 EXPECT_FALSE(signal);
412 }
413
385 } // namespace chromeos 414 } // namespace chromeos
OLDNEW
« 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