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

Side by Side Diff: chromeos/dbus/services/proxy_resolution_service_provider_unittest.cc

Issue 2824943005: chromeos: Add org.chromium.NetworkProxyService D-Bus service. (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 | « chromeos/dbus/services/proxy_resolution_service_provider.cc ('k') | 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } // namespace 189 } // namespace
190 190
191 class ProxyResolutionServiceProviderTest : public testing::Test { 191 class ProxyResolutionServiceProviderTest : public testing::Test {
192 public: 192 public:
193 ProxyResolutionServiceProviderTest() : network_thread_("NetworkThread") { 193 ProxyResolutionServiceProviderTest() : network_thread_("NetworkThread") {
194 CHECK(network_thread_.Start()); 194 CHECK(network_thread_.Start());
195 195
196 proxy_resolver_ = 196 proxy_resolver_ =
197 base::MakeUnique<TestProxyResolver>(network_thread_.task_runner()); 197 base::MakeUnique<TestProxyResolver>(network_thread_.task_runner());
198 service_provider_ = base::MakeUnique<ProxyResolutionServiceProvider>( 198 service_provider_ = base::MakeUnique<ProxyResolutionServiceProvider>(
199 kNetworkProxyServiceInterface, kNetworkProxyServiceResolveProxyMethod,
199 base::MakeUnique<TestDelegate>(network_thread_.task_runner(), 200 base::MakeUnique<TestDelegate>(network_thread_.task_runner(),
200 proxy_resolver_.get())); 201 proxy_resolver_.get()));
201 test_helper_.SetUp(kLibCrosServiceName, 202 test_helper_.SetUp(
202 dbus::ObjectPath(kLibCrosServicePath), 203 kNetworkProxyServiceName, dbus::ObjectPath(kNetworkProxyServicePath),
203 kLibCrosServiceInterface, kResolveNetworkProxy, 204 kNetworkProxyServiceInterface, kNetworkProxyServiceResolveProxyMethod,
204 service_provider_.get()); 205 service_provider_.get());
205 } 206 }
206 207
207 ~ProxyResolutionServiceProviderTest() override { 208 ~ProxyResolutionServiceProviderTest() override {
208 test_helper_.TearDown(); 209 test_helper_.TearDown();
209 210
210 // URLRequestContextGetter posts a task to delete itself to its task runner, 211 // URLRequestContextGetter posts a task to delete itself to its task runner,
211 // so give it a chance to do that. 212 // so give it a chance to do that.
212 service_provider_.reset(); 213 service_provider_.reset();
213 RunPendingTasks(network_thread_.task_runner()); 214 RunPendingTasks(network_thread_.task_runner());
214 215
(...skipping 30 matching lines...) Expand all
245 246
246 // Called when connected to a signal. 247 // Called when connected to a signal.
247 void OnConnectedToSignal(const std::string& signal_interface, 248 void OnConnectedToSignal(const std::string& signal_interface,
248 const std::string& signal_name, 249 const std::string& signal_name,
249 bool success){ 250 bool success){
250 EXPECT_EQ(kReturnSignalInterface, signal_interface); 251 EXPECT_EQ(kReturnSignalInterface, signal_interface);
251 EXPECT_EQ(kReturnSignalName, signal_name); 252 EXPECT_EQ(kReturnSignalName, signal_name);
252 EXPECT_TRUE(success); 253 EXPECT_TRUE(success);
253 } 254 }
254 255
255 // Makes a D-Bus call to |service_provider_|'s ResolveNetworkProxy method. If 256 // Makes a D-Bus call to |service_provider_|'s ResolveProxy method. If
256 // |request_signal| is true, requests that the proxy information be returned 257 // |request_signal| is true, requests that the proxy information be returned
257 // via a signal; otherwise it should be included in the response. 258 // via a signal; otherwise it should be included in the response.
258 // |response_out| is updated to hold the response, and |signal_out| is updated 259 // |response_out| is updated to hold the response, and |signal_out| is updated
259 // to hold information about the emitted signal, if any. 260 // to hold information about the emitted signal, if any.
260 void CallMethod(const std::string& source_url, 261 void CallMethod(const std::string& source_url,
261 bool request_signal, 262 bool request_signal,
262 std::unique_ptr<dbus::Response>* response_out, 263 std::unique_ptr<dbus::Response>* response_out,
263 std::unique_ptr<SignalInfo>* signal_out) { 264 std::unique_ptr<SignalInfo>* signal_out) {
264 dbus::MethodCall method_call(kLibCrosServiceInterface, 265 dbus::MethodCall method_call(kNetworkProxyServiceInterface,
265 kResolveNetworkProxy); 266 kNetworkProxyServiceResolveProxyMethod);
266 dbus::MessageWriter writer(&method_call); 267 dbus::MessageWriter writer(&method_call);
267 writer.AppendString(source_url); 268 writer.AppendString(source_url);
268 if (request_signal) { 269 if (request_signal) {
269 writer.AppendString(kReturnSignalInterface); 270 writer.AppendString(kReturnSignalInterface);
270 writer.AppendString(kReturnSignalName); 271 writer.AppendString(kReturnSignalName);
271 272
272 // Connect to the signal that will be sent to kReturnSignalInterface and 273 // Connect to the signal that will be sent to kReturnSignalInterface and
273 // kReturnSignalName. ResolveNetworkProxy() will send the result as a 274 // kReturnSignalName.
274 // signal. OnSignalReceived() will be called upon the delivery.
275 test_helper_.SetUpReturnSignal( 275 test_helper_.SetUpReturnSignal(
276 kReturnSignalInterface, kReturnSignalName, 276 kReturnSignalInterface, kReturnSignalName,
277 base::Bind(&ProxyResolutionServiceProviderTest::OnSignalReceived, 277 base::Bind(&ProxyResolutionServiceProviderTest::OnSignalReceived,
278 base::Unretained(this)), 278 base::Unretained(this)),
279 base::Bind(&ProxyResolutionServiceProviderTest::OnConnectedToSignal, 279 base::Bind(&ProxyResolutionServiceProviderTest::OnConnectedToSignal,
280 base::Unretained(this))); 280 base::Unretained(this)));
281 } 281 }
282 282
283 *response_out = test_helper_.CallMethod(&method_call); 283 *response_out = test_helper_.CallMethod(&method_call);
284 284
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 EXPECT_TRUE(reader.PopString(&error)); 409 EXPECT_TRUE(reader.PopString(&error));
410 EXPECT_EQ("DIRECT", proxy_info); 410 EXPECT_EQ("DIRECT", proxy_info);
411 EXPECT_EQ(net::ErrorToString(net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED), 411 EXPECT_EQ(net::ErrorToString(net::ERR_MANDATORY_PROXY_CONFIGURATION_FAILED),
412 error); 412 error);
413 413
414 // No signal should've been emitted. 414 // No signal should've been emitted.
415 EXPECT_FALSE(signal); 415 EXPECT_FALSE(signal);
416 } 416 }
417 417
418 } // namespace chromeos 418 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/services/proxy_resolution_service_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698