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

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