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

Side by Side Diff: chromeos/dbus/flimflam_client_unittest_base.cc

Issue 10170020: Rework chromeos::FlimflamDevice/ServiceClient with CallMethodWithErrorCallback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/flimflam_client_unittest_base.h ('k') | chromeos/dbus/flimflam_device_client.h » ('j') | 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/flimflam_client_unittest_base.h" 5 #include "chromeos/dbus/flimflam_client_unittest_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
(...skipping 12 matching lines...) Expand all
23 namespace { 23 namespace {
24 24
25 // Runs the given task. This function is used to implement the mock bus. 25 // Runs the given task. This function is used to implement the mock bus.
26 void RunTask(const tracked_objects::Location& from_here, 26 void RunTask(const tracked_objects::Location& from_here,
27 const base::Closure& task) { 27 const base::Closure& task) {
28 task.Run(); 28 task.Run();
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 FlimflamClientUnittestBase::MockClosure::MockClosure() {}
34
35 FlimflamClientUnittestBase::MockClosure::~MockClosure() {}
36
37 base::Closure FlimflamClientUnittestBase::MockClosure::GetCallback() {
38 return base::Bind(&MockClosure::Run, base::Unretained(this));
39 }
40
41
42 FlimflamClientUnittestBase::MockErrorCallback::MockErrorCallback() {}
43
44 FlimflamClientUnittestBase::MockErrorCallback::~MockErrorCallback() {}
45
46 FlimflamClientHelper::ErrorCallback
47 FlimflamClientUnittestBase::MockErrorCallback::GetCallback() {
48 return base::Bind(&MockErrorCallback::Run, base::Unretained(this));
49 }
50
51
33 FlimflamClientUnittestBase::FlimflamClientUnittestBase( 52 FlimflamClientUnittestBase::FlimflamClientUnittestBase(
34 const std::string& interface_name, 53 const std::string& interface_name,
35 const dbus::ObjectPath& object_path) 54 const dbus::ObjectPath& object_path)
36 : interface_name_(interface_name), 55 : interface_name_(interface_name),
37 object_path_(object_path) { 56 object_path_(object_path),
57 response_(NULL) {
38 } 58 }
39 59
40 FlimflamClientUnittestBase::~FlimflamClientUnittestBase() { 60 FlimflamClientUnittestBase::~FlimflamClientUnittestBase() {
41 } 61 }
42 62
43 void FlimflamClientUnittestBase::SetUp() { 63 void FlimflamClientUnittestBase::SetUp() {
44 // Create a mock bus. 64 // Create a mock bus.
45 dbus::Bus::Options options; 65 dbus::Bus::Options options;
46 options.bus_type = dbus::Bus::SYSTEM; 66 options.bus_type = dbus::Bus::SYSTEM;
47 mock_bus_ = new dbus::MockBus(options); 67 mock_bus_ = new dbus::MockBus(options);
48 68
49 // Create a mock proxy. 69 // Create a mock proxy.
50 mock_proxy_ = new dbus::MockObjectProxy( 70 mock_proxy_ = new dbus::MockObjectProxy(
51 mock_bus_.get(), 71 mock_bus_.get(),
52 flimflam::kFlimflamServiceName, 72 flimflam::kFlimflamServiceName,
53 object_path_); 73 object_path_);
54 74
55 // Set an expectation so mock_proxy's CallMethodAndBlock() will use 75 // Set an expectation so mock_proxy's CallMethodAndBlock() will use
56 // OnCallMethodAndBlock() to return responses. 76 // OnCallMethodAndBlock() to return responses.
57 EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _)) 77 EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _))
58 .WillRepeatedly(Invoke( 78 .WillRepeatedly(Invoke(
59 this, &FlimflamClientUnittestBase::OnCallMethodAndBlock)); 79 this, &FlimflamClientUnittestBase::OnCallMethodAndBlock));
60 80
61 // Set an expectation so mock_proxy's CallMethod() will use OnCallMethod() 81 // Set an expectation so mock_proxy's CallMethod() will use OnCallMethod()
62 // to return responses. 82 // to return responses.
63 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) 83 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _))
64 .WillRepeatedly(Invoke(this, &FlimflamClientUnittestBase::OnCallMethod)); 84 .WillRepeatedly(Invoke(this, &FlimflamClientUnittestBase::OnCallMethod));
65 85
86 // Set an expectation so mock_proxy's CallMethodWithErrorCallback() will use
87 // OnCallMethodWithErrorCallback() to return responses.
88 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
89 .WillRepeatedly(Invoke(
90 this, &FlimflamClientUnittestBase::OnCallMethodWithErrorCallback));
91
66 // Set an expectation so mock_proxy's ConnectToSignal() will use 92 // Set an expectation so mock_proxy's ConnectToSignal() will use
67 // OnConnectToSignal() to run the callback. 93 // OnConnectToSignal() to run the callback.
68 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 94 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
69 interface_name_, 95 interface_name_,
70 flimflam::kMonitorPropertyChanged, _, _)) 96 flimflam::kMonitorPropertyChanged, _, _))
71 .WillRepeatedly(Invoke(this, 97 .WillRepeatedly(Invoke(this,
72 &FlimflamClientUnittestBase::OnConnectToSignal)); 98 &FlimflamClientUnittestBase::OnConnectToSignal));
73 99
74 // Set an expectation so mock_bus's GetObjectProxy() for the given 100 // Set an expectation so mock_bus's GetObjectProxy() for the given
75 // service name and the object path will return mock_proxy_. 101 // service name and the object path will return mock_proxy_.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 int timeout_ms, 227 int timeout_ms,
202 const dbus::ObjectProxy::ResponseCallback& response_callback) { 228 const dbus::ObjectProxy::ResponseCallback& response_callback) {
203 EXPECT_EQ(interface_name_, method_call->GetInterface()); 229 EXPECT_EQ(interface_name_, method_call->GetInterface());
204 EXPECT_EQ(expected_method_name_, method_call->GetMember()); 230 EXPECT_EQ(expected_method_name_, method_call->GetMember());
205 dbus::MessageReader reader(method_call); 231 dbus::MessageReader reader(method_call);
206 argument_checker_.Run(&reader); 232 argument_checker_.Run(&reader);
207 message_loop_.PostTask(FROM_HERE, 233 message_loop_.PostTask(FROM_HERE,
208 base::Bind(response_callback, response_)); 234 base::Bind(response_callback, response_));
209 } 235 }
210 236
237 void FlimflamClientUnittestBase::OnCallMethodWithErrorCallback(
238 dbus::MethodCall* method_call,
239 int timeout_ms,
240 const dbus::ObjectProxy::ResponseCallback& response_callback,
241 const dbus::ObjectProxy::ErrorCallback& error_callback) {
242 OnCallMethod(method_call, timeout_ms, response_callback);
243 }
244
211 dbus::Response* FlimflamClientUnittestBase::OnCallMethodAndBlock( 245 dbus::Response* FlimflamClientUnittestBase::OnCallMethodAndBlock(
212 dbus::MethodCall* method_call, 246 dbus::MethodCall* method_call,
213 int timeout_ms) { 247 int timeout_ms) {
214 EXPECT_EQ(interface_name_, method_call->GetInterface()); 248 EXPECT_EQ(interface_name_, method_call->GetInterface());
215 EXPECT_EQ(expected_method_name_, method_call->GetMember()); 249 EXPECT_EQ(expected_method_name_, method_call->GetMember());
216 dbus::MessageReader reader(method_call); 250 dbus::MessageReader reader(method_call);
217 argument_checker_.Run(&reader); 251 argument_checker_.Run(&reader);
218 return dbus::Response::FromRawMessage( 252 return dbus::Response::FromRawMessage(
219 dbus_message_copy(response_->raw_message())); 253 dbus_message_copy(response_->raw_message()));
220 } 254 }
221 255
222 } // namespace chromeos 256 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/flimflam_client_unittest_base.h ('k') | chromeos/dbus/flimflam_device_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698