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

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

Issue 10038011: Add FlimflamProfileClientTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ 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
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 "dbus/message.h" 9 #include "dbus/message.h"
9 #include "dbus/object_path.h" 10 #include "dbus/object_path.h"
10 #include "dbus/values_util.h" 11 #include "dbus/values_util.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h"
14 15
15 using ::testing::_; 16 using ::testing::_;
16 using ::testing::Invoke; 17 using ::testing::Invoke;
17 using ::testing::Return; 18 using ::testing::Return;
18 19
19 namespace chromeos { 20 namespace chromeos {
20 21
21 FlimflamClientUnittestBase::FlimflamClientUnittestBase( 22 FlimflamClientUnittestBase::FlimflamClientUnittestBase(
22 const std::string& interface_name) : interface_name_(interface_name) { 23 const std::string& interface_name,
24 const dbus::ObjectPath& object_path) : interface_name_(interface_name),
stevenjb 2012/04/12 17:38:30 nit: newline and indent before ':'
hashimoto 2012/04/13 06:31:14 Done.
25 object_path_(object_path) {
23 } 26 }
24 27
25 FlimflamClientUnittestBase::~FlimflamClientUnittestBase() { 28 FlimflamClientUnittestBase::~FlimflamClientUnittestBase() {
26 } 29 }
27 30
28 void FlimflamClientUnittestBase::SetUp() { 31 void FlimflamClientUnittestBase::SetUp() {
29 // Create a mock bus. 32 // Create a mock bus.
30 dbus::Bus::Options options; 33 dbus::Bus::Options options;
31 options.bus_type = dbus::Bus::SYSTEM; 34 options.bus_type = dbus::Bus::SYSTEM;
32 mock_bus_ = new dbus::MockBus(options); 35 mock_bus_ = new dbus::MockBus(options);
33 36
34 // Create a mock proxy. 37 // Create a mock proxy.
35 mock_proxy_ = new dbus::MockObjectProxy( 38 mock_proxy_ = new dbus::MockObjectProxy(
36 mock_bus_.get(), 39 mock_bus_.get(),
37 flimflam::kFlimflamServiceName, 40 flimflam::kFlimflamServiceName,
38 dbus::ObjectPath(flimflam::kFlimflamServicePath)); 41 object_path_);
39 42
40 // Set an expectation so mock_proxy's CallMethod() will use OnCallMethod() 43 // Set an expectation so mock_proxy's CallMethod() will use OnCallMethod()
41 // to return responses. 44 // to return responses.
42 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) 45 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _))
43 .WillRepeatedly(Invoke(this, &FlimflamClientUnittestBase::OnCallMethod)); 46 .WillRepeatedly(Invoke(this, &FlimflamClientUnittestBase::OnCallMethod));
44 47
45 // Set an expectation so mock_proxy's ConnectToSignal() will use 48 // Set an expectation so mock_proxy's ConnectToSignal() will use
46 // OnConnectToSignal() to run the callback. 49 // OnConnectToSignal() to run the callback.
47 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 50 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
48 interface_name_, 51 interface_name_,
49 flimflam::kMonitorPropertyChanged, _, _)) 52 flimflam::kMonitorPropertyChanged, _, _))
50 .WillRepeatedly(Invoke(this, 53 .WillRepeatedly(Invoke(this,
51 &FlimflamClientUnittestBase::OnConnectToSignal)); 54 &FlimflamClientUnittestBase::OnConnectToSignal));
52 55
53 // Set an expectation so mock_bus's GetObjectProxy() for the given 56 // Set an expectation so mock_bus's GetObjectProxy() for the given
54 // service name and the object path will return mock_proxy_. 57 // service name and the object path will return mock_proxy_.
55 EXPECT_CALL(*mock_bus_, GetObjectProxy( 58 EXPECT_CALL(*mock_bus_, GetObjectProxy(flimflam::kFlimflamServiceName,
56 flimflam::kFlimflamServiceName, 59 object_path_))
57 dbus::ObjectPath(flimflam::kFlimflamServicePath)))
58 .WillOnce(Return(mock_proxy_.get())); 60 .WillOnce(Return(mock_proxy_.get()));
59 61
60 // ShutdownAndBlock() will be called in TearDown(). 62 // ShutdownAndBlock() will be called in TearDown().
61 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); 63 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return());
62 } 64 }
63 65
64 void FlimflamClientUnittestBase::TearDown() { 66 void FlimflamClientUnittestBase::TearDown() {
65 mock_bus_->ShutdownAndBlock(); 67 mock_bus_->ShutdownAndBlock();
66 } 68 }
67 69
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); 145 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status);
144 EXPECT_EQ(expected_result, result); 146 EXPECT_EQ(expected_result, result);
145 } 147 }
146 148
147 // static 149 // static
148 void FlimflamClientUnittestBase::ExpectDictionaryValueResult( 150 void FlimflamClientUnittestBase::ExpectDictionaryValueResult(
149 const base::DictionaryValue* expected_result, 151 const base::DictionaryValue* expected_result,
150 DBusMethodCallStatus call_status, 152 DBusMethodCallStatus call_status,
151 const base::DictionaryValue& result) { 153 const base::DictionaryValue& result) {
152 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); 154 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status);
153 EXPECT_TRUE(expected_result->Equals(&result)); 155 std::string expected_result_string;
156 base::JSONWriter::Write(expected_result, &expected_result_string);
157 std::string result_string;
158 base::JSONWriter::Write(&result, &result_string);
159 EXPECT_EQ(expected_result_string, result_string);
154 } 160 }
155 161
156 void FlimflamClientUnittestBase::OnConnectToSignal( 162 void FlimflamClientUnittestBase::OnConnectToSignal(
157 const std::string& interface_name, 163 const std::string& interface_name,
158 const std::string& signal_name, 164 const std::string& signal_name,
159 const dbus::ObjectProxy::SignalCallback& signal_callback, 165 const dbus::ObjectProxy::SignalCallback& signal_callback,
160 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { 166 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
161 property_changed_handler_ = signal_callback; 167 property_changed_handler_ = signal_callback;
162 const bool success = true; 168 const bool success = true;
163 message_loop_.PostTask(FROM_HERE, 169 message_loop_.PostTask(FROM_HERE,
164 base::Bind(on_connected_callback, 170 base::Bind(on_connected_callback,
165 interface_name, 171 interface_name,
166 signal_name, 172 signal_name,
167 success)); 173 success));
168 } 174 }
169 175
170 void FlimflamClientUnittestBase::OnCallMethod( 176 void FlimflamClientUnittestBase::OnCallMethod(
171 dbus::MethodCall* method_call, 177 dbus::MethodCall* method_call,
172 int timeout_ms, 178 int timeout_ms,
173 const dbus::ObjectProxy::ResponseCallback& response_callback) { 179 const dbus::ObjectProxy::ResponseCallback& response_callback) {
174 EXPECT_EQ(interface_name_, method_call->GetInterface()); 180 EXPECT_EQ(interface_name_, method_call->GetInterface());
175 EXPECT_EQ(expected_method_name_, method_call->GetMember()); 181 EXPECT_EQ(expected_method_name_, method_call->GetMember());
176 dbus::MessageReader reader(method_call); 182 dbus::MessageReader reader(method_call);
177 argument_checker_.Run(&reader); 183 argument_checker_.Run(&reader);
178 message_loop_.PostTask(FROM_HERE, 184 message_loop_.PostTask(FROM_HERE,
179 base::Bind(response_callback, response_)); 185 base::Bind(response_callback, response_));
180 } 186 }
181 187
182 } // namespace chromeos 188 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/flimflam_client_unittest_base.h ('k') | chromeos/dbus/flimflam_manager_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698