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

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

Issue 681723003: Add new shill client for VPN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated the interface to better suit the upper layer Created 6 years, 1 month 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
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/shill_client_unittest_base.h" 5 #include "chromeos/dbus/shill_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 "chromeos/dbus/shill_third_party_vpn_driver_client.h"
pneubeck (no reviews) 2014/11/11 13:09:35 already included in the header
kaliamoorthi 2014/11/11 14:58:32 Done.
10 #include "chromeos/network/shill_property_util.h" 11 #include "chromeos/network/shill_property_util.h"
11 #include "dbus/message.h" 12 #include "dbus/message.h"
12 #include "dbus/object_path.h" 13 #include "dbus/object_path.h"
13 #include "dbus/values_util.h" 14 #include "dbus/values_util.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h" 17 #include "third_party/cros_system_api/dbus/service_constants.h"
18 // TODO(kaliamoorthi): Remove inclusion of shill_third_party_vpn_driver_client
19 // after the string constants in it are moved to service_constants.h
17 20
18 using ::testing::_; 21 using ::testing::_;
19 using ::testing::Invoke; 22 using ::testing::Invoke;
20 using ::testing::Return; 23 using ::testing::Return;
21 24
22 namespace chromeos { 25 namespace chromeos {
23 26
24 namespace { 27 namespace {
25 28
26 // Pops a string-to-string dictionary from the reader. 29 // Pops a string-to-string dictionary from the reader.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ShillClientUnittestBase::MockErrorCallback::MockErrorCallback() {} 95 ShillClientUnittestBase::MockErrorCallback::MockErrorCallback() {}
93 96
94 ShillClientUnittestBase::MockErrorCallback::~MockErrorCallback() {} 97 ShillClientUnittestBase::MockErrorCallback::~MockErrorCallback() {}
95 98
96 ShillClientUnittestBase::MockPropertyChangeObserver:: 99 ShillClientUnittestBase::MockPropertyChangeObserver::
97 MockPropertyChangeObserver() {} 100 MockPropertyChangeObserver() {}
98 101
99 ShillClientUnittestBase::MockPropertyChangeObserver:: 102 ShillClientUnittestBase::MockPropertyChangeObserver::
100 ~MockPropertyChangeObserver() {} 103 ~MockPropertyChangeObserver() {}
101 104
105 ShillClientUnittestBase::MockShillThirdPartyVpnObserver::
106 MockShillThirdPartyVpnObserver() {}
107
108 ShillClientUnittestBase::MockShillThirdPartyVpnObserver::
109 ~MockShillThirdPartyVpnObserver() {}
110
102 ShillClientHelper::ErrorCallback 111 ShillClientHelper::ErrorCallback
103 ShillClientUnittestBase::MockErrorCallback::GetCallback() { 112 ShillClientUnittestBase::MockErrorCallback::GetCallback() {
104 return base::Bind(&MockErrorCallback::Run, base::Unretained(this)); 113 return base::Bind(&MockErrorCallback::Run, base::Unretained(this));
105 } 114 }
106 115
107 116
108 ShillClientUnittestBase::ShillClientUnittestBase( 117 ShillClientUnittestBase::ShillClientUnittestBase(
109 const std::string& interface_name, 118 const std::string& interface_name,
110 const dbus::ObjectPath& object_path) 119 const dbus::ObjectPath& object_path)
111 : interface_name_(interface_name), 120 : interface_name_(interface_name),
(...skipping 21 matching lines...) Expand all
133 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)) 142 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _))
134 .WillRepeatedly(Invoke(this, &ShillClientUnittestBase::OnCallMethod)); 143 .WillRepeatedly(Invoke(this, &ShillClientUnittestBase::OnCallMethod));
135 144
136 // Set an expectation so mock_proxy's CallMethodWithErrorCallback() will use 145 // Set an expectation so mock_proxy's CallMethodWithErrorCallback() will use
137 // OnCallMethodWithErrorCallback() to return responses. 146 // OnCallMethodWithErrorCallback() to return responses.
138 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _)) 147 EXPECT_CALL(*mock_proxy_.get(), CallMethodWithErrorCallback(_, _, _, _))
139 .WillRepeatedly(Invoke( 148 .WillRepeatedly(Invoke(
140 this, &ShillClientUnittestBase::OnCallMethodWithErrorCallback)); 149 this, &ShillClientUnittestBase::OnCallMethodWithErrorCallback));
141 150
142 // Set an expectation so mock_proxy's ConnectToSignal() will use 151 // Set an expectation so mock_proxy's ConnectToSignal() will use
143 // OnConnectToSignal() to run the callback. 152 // OnConnectToPropertyChanged() to run the callback.
144 EXPECT_CALL( 153 EXPECT_CALL(
145 *mock_proxy_.get(), 154 *mock_proxy_.get(),
146 ConnectToSignal(interface_name_, shill::kMonitorPropertyChanged, _, _)) 155 ConnectToSignal(interface_name_, shill::kMonitorPropertyChanged, _, _))
147 .WillRepeatedly( 156 .WillRepeatedly(
148 Invoke(this, &ShillClientUnittestBase::OnConnectToSignal)); 157 Invoke(this, &ShillClientUnittestBase::OnConnectToPropertyChanged));
158
159 EXPECT_CALL(
160 *mock_proxy_.get(),
161 ConnectToSignal(interface_name_, shill::kOnPlatformMessageFunction, _, _))
162 .WillRepeatedly(
163 Invoke(this, &ShillClientUnittestBase::OnConnectToPlatformMessage));
164
165 EXPECT_CALL(
166 *mock_proxy_.get(),
167 ConnectToSignal(interface_name_, shill::kOnPacketReceivedFunction, _, _))
168 .WillRepeatedly(
169 Invoke(this, &ShillClientUnittestBase::OnConnectToPacketReceieved));
149 170
150 // Set an expectation so mock_bus's GetObjectProxy() for the given 171 // Set an expectation so mock_bus's GetObjectProxy() for the given
151 // service name and the object path will return mock_proxy_. 172 // service name and the object path will return mock_proxy_.
152 EXPECT_CALL(*mock_bus_.get(), 173 EXPECT_CALL(*mock_bus_.get(),
153 GetObjectProxy(shill::kFlimflamServiceName, object_path_)) 174 GetObjectProxy(shill::kFlimflamServiceName, object_path_))
154 .WillOnce(Return(mock_proxy_.get())); 175 .WillOnce(Return(mock_proxy_.get()));
155 176
156 // Set an expectation so mock_bus's GetDBusTaskRunner will return the current 177 // Set an expectation so mock_bus's GetDBusTaskRunner will return the current
157 // task runner. 178 // task runner.
158 EXPECT_CALL(*mock_bus_.get(), GetDBusTaskRunner()) 179 EXPECT_CALL(*mock_bus_.get(), GetDBusTaskRunner())
159 .WillRepeatedly(Return(message_loop_.message_loop_proxy().get())); 180 .WillRepeatedly(Return(message_loop_.message_loop_proxy().get()));
160 181
161 // ShutdownAndBlock() will be called in TearDown(). 182 // ShutdownAndBlock() will be called in TearDown().
162 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); 183 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return());
163 } 184 }
164 185
165 void ShillClientUnittestBase::TearDown() { 186 void ShillClientUnittestBase::TearDown() {
166 mock_bus_->ShutdownAndBlock(); 187 mock_bus_->ShutdownAndBlock();
167 } 188 }
168 189
169 void ShillClientUnittestBase::PrepareForMethodCall( 190 void ShillClientUnittestBase::PrepareForMethodCall(
170 const std::string& method_name, 191 const std::string& method_name,
171 const ArgumentCheckCallback& argument_checker, 192 const ArgumentCheckCallback& argument_checker,
172 dbus::Response* response) { 193 dbus::Response* response) {
173 expected_method_name_ = method_name; 194 expected_method_name_ = method_name;
174 argument_checker_ = argument_checker; 195 argument_checker_ = argument_checker;
175 response_ = response; 196 response_ = response;
176 } 197 }
177 198
199 void ShillClientUnittestBase::SendPlatformMessageSignal(
200 dbus::Signal* signal) {
201 ASSERT_FALSE(platform_message_handler_.is_null());
202 platform_message_handler_.Run(signal);
203 }
204
205 void ShillClientUnittestBase::SendPacketReceievedSignal(
206 dbus::Signal* signal) {
207 ASSERT_FALSE(packet_receieved__handler_.is_null());
208 packet_receieved__handler_.Run(signal);
209 }
210
178 void ShillClientUnittestBase::SendPropertyChangedSignal( 211 void ShillClientUnittestBase::SendPropertyChangedSignal(
179 dbus::Signal* signal) { 212 dbus::Signal* signal) {
180 ASSERT_FALSE(property_changed_handler_.is_null()); 213 ASSERT_FALSE(property_changed_handler_.is_null());
181 property_changed_handler_.Run(signal); 214 property_changed_handler_.Run(signal);
182 } 215 }
183 216
184 // static 217 // static
185 void ShillClientUnittestBase::ExpectPropertyChanged( 218 void ShillClientUnittestBase::ExpectPropertyChanged(
186 const std::string& expected_name, 219 const std::string& expected_name,
187 const base::Value* expected_value, 220 const base::Value* expected_value,
188 const std::string& name, 221 const std::string& name,
189 const base::Value& value) { 222 const base::Value& value) {
190 EXPECT_EQ(expected_name, name); 223 EXPECT_EQ(expected_name, name);
191 EXPECT_TRUE(expected_value->Equals(&value)); 224 EXPECT_TRUE(expected_value->Equals(&value));
192 } 225 }
193 226
194 // static 227 // static
195 void ShillClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) { 228 void ShillClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) {
196 EXPECT_FALSE(reader->HasMoreData()); 229 EXPECT_FALSE(reader->HasMoreData());
197 } 230 }
198 231
199 // static 232 // static
233 void ShillClientUnittestBase::ExpectUint32Argument(
234 uint32 expected_value,
235 dbus::MessageReader* reader) {
236 uint32 value;
237 ASSERT_TRUE(reader->PopUint32(&value));
238 EXPECT_EQ(expected_value, value);
239 EXPECT_FALSE(reader->HasMoreData());
240 }
241
242 // static
243 void ShillClientUnittestBase::ExpectArrayOfBytesArgument(
244 const std::string& expected_bytes,
245 dbus::MessageReader* reader) {
246 const uint8* bytes;
pneubeck (no reviews) 2014/11/11 13:09:35 built-in types should be initialized (also mention
kaliamoorthi 2014/11/11 14:58:32 Done.
247 size_t size;
248 ASSERT_TRUE(reader->PopArrayOfBytes(&bytes, &size));
249 EXPECT_EQ(expected_bytes.size(), size);
250 for (size_t i = 0; i < size; ++i) {
251 EXPECT_EQ(expected_bytes[i], bytes[i]);
252 }
253 EXPECT_FALSE(reader->HasMoreData());
254 }
255
256 // static
200 void ShillClientUnittestBase::ExpectStringArgument( 257 void ShillClientUnittestBase::ExpectStringArgument(
201 const std::string& expected_string, 258 const std::string& expected_string,
202 dbus::MessageReader* reader) { 259 dbus::MessageReader* reader) {
203 std::string str; 260 std::string str;
204 ASSERT_TRUE(reader->PopString(&str)); 261 ASSERT_TRUE(reader->PopString(&str));
205 EXPECT_EQ(expected_string, str); 262 EXPECT_EQ(expected_string, str);
206 EXPECT_FALSE(reader->HasMoreData()); 263 EXPECT_FALSE(reader->HasMoreData());
207 } 264 }
208 265
209 // static 266 // static
(...skipping 26 matching lines...) Expand all
236 EXPECT_EQ(expected_string, str); 293 EXPECT_EQ(expected_string, str);
237 scoped_ptr<base::Value> value(dbus::PopDataAsValue(reader)); 294 scoped_ptr<base::Value> value(dbus::PopDataAsValue(reader));
238 ASSERT_TRUE(value.get()); 295 ASSERT_TRUE(value.get());
239 EXPECT_TRUE(value->Equals(expected_value)); 296 EXPECT_TRUE(value->Equals(expected_value));
240 EXPECT_FALSE(reader->HasMoreData()); 297 EXPECT_FALSE(reader->HasMoreData());
241 } 298 }
242 299
243 // static 300 // static
244 void ShillClientUnittestBase::ExpectDictionaryValueArgument( 301 void ShillClientUnittestBase::ExpectDictionaryValueArgument(
245 const base::DictionaryValue* expected_dictionary, 302 const base::DictionaryValue* expected_dictionary,
303 bool string_valued,
246 dbus::MessageReader* reader) { 304 dbus::MessageReader* reader) {
247 dbus::MessageReader array_reader(NULL); 305 dbus::MessageReader array_reader(NULL);
248 ASSERT_TRUE(reader->PopArray(&array_reader)); 306 ASSERT_TRUE(reader->PopArray(&array_reader));
249 while (array_reader.HasMoreData()) { 307 while (array_reader.HasMoreData()) {
250 dbus::MessageReader entry_reader(NULL); 308 dbus::MessageReader entry_reader(NULL);
251 ASSERT_TRUE(array_reader.PopDictEntry(&entry_reader)); 309 ASSERT_TRUE(array_reader.PopDictEntry(&entry_reader));
252 std::string key; 310 std::string key;
253 ASSERT_TRUE(entry_reader.PopString(&key)); 311 ASSERT_TRUE(entry_reader.PopString(&key));
312 if (string_valued) {
pneubeck (no reviews) 2014/11/11 13:09:35 wouldn't it have the same effect if you just check
kaliamoorthi 2014/11/11 14:58:32 No, the way the data is marshaled is different if
313 std::string value;
314 std::string expected_value;
315 ASSERT_TRUE(entry_reader.PopString(&value));
316 EXPECT_TRUE(expected_dictionary->GetStringWithoutPathExpansion(
317 key, &expected_value));
318 EXPECT_EQ(expected_value, value);
319 continue;
320 }
254 dbus::MessageReader variant_reader(NULL); 321 dbus::MessageReader variant_reader(NULL);
255 ASSERT_TRUE(entry_reader.PopVariant(&variant_reader)); 322 ASSERT_TRUE(entry_reader.PopVariant(&variant_reader));
256 scoped_ptr<base::Value> value; 323 scoped_ptr<base::Value> value;
257 // Variants in the dictionary can be basic types or string-to-string 324 // Variants in the dictionary can be basic types or string-to-string
258 // dictinoary. 325 // dictinoary.
259 switch (variant_reader.GetDataType()) { 326 switch (variant_reader.GetDataType()) {
260 case dbus::Message::ARRAY: 327 case dbus::Message::ARRAY:
261 value.reset(PopStringToStringDictionary(&variant_reader)); 328 value.reset(PopStringToStringDictionary(&variant_reader));
262 break; 329 break;
263 case dbus::Message::BOOL: 330 case dbus::Message::BOOL:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 410
344 // static 411 // static
345 void ShillClientUnittestBase::ExpectDictionaryValueResult( 412 void ShillClientUnittestBase::ExpectDictionaryValueResult(
346 const base::DictionaryValue* expected_result, 413 const base::DictionaryValue* expected_result,
347 DBusMethodCallStatus call_status, 414 DBusMethodCallStatus call_status,
348 const base::DictionaryValue& result) { 415 const base::DictionaryValue& result) {
349 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); 416 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status);
350 ExpectDictionaryValueResultWithoutStatus(expected_result, result); 417 ExpectDictionaryValueResultWithoutStatus(expected_result, result);
351 } 418 }
352 419
353 void ShillClientUnittestBase::OnConnectToSignal( 420 void ShillClientUnittestBase::OnConnectToPlatformMessage(
354 const std::string& interface_name, 421 const std::string& interface_name,
355 const std::string& signal_name, 422 const std::string& signal_name,
356 const dbus::ObjectProxy::SignalCallback& signal_callback, 423 const dbus::ObjectProxy::SignalCallback& signal_callback,
424 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
425 platform_message_handler_ = signal_callback;
426 const bool success = true;
427 message_loop_.PostTask(FROM_HERE,
428 base::Bind(on_connected_callback,
429 interface_name,
430 signal_name,
431 success));
432 }
433
434 void ShillClientUnittestBase::OnConnectToPacketReceieved(
435 const std::string& interface_name,
436 const std::string& signal_name,
437 const dbus::ObjectProxy::SignalCallback& signal_callback,
438 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
439 packet_receieved__handler_ = signal_callback;
440 const bool success = true;
441 message_loop_.PostTask(FROM_HERE,
442 base::Bind(on_connected_callback,
443 interface_name,
444 signal_name,
445 success));
446 }
447
448 void ShillClientUnittestBase::OnConnectToPropertyChanged(
449 const std::string& interface_name,
450 const std::string& signal_name,
451 const dbus::ObjectProxy::SignalCallback& signal_callback,
357 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { 452 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
358 property_changed_handler_ = signal_callback; 453 property_changed_handler_ = signal_callback;
359 const bool success = true; 454 const bool success = true;
360 message_loop_.PostTask(FROM_HERE, 455 message_loop_.PostTask(FROM_HERE,
361 base::Bind(on_connected_callback, 456 base::Bind(on_connected_callback,
362 interface_name, 457 interface_name,
363 signal_name, 458 signal_name,
364 success)); 459 success));
365 } 460 }
366 461
(...skipping 11 matching lines...) Expand all
378 473
379 void ShillClientUnittestBase::OnCallMethodWithErrorCallback( 474 void ShillClientUnittestBase::OnCallMethodWithErrorCallback(
380 dbus::MethodCall* method_call, 475 dbus::MethodCall* method_call,
381 int timeout_ms, 476 int timeout_ms,
382 const dbus::ObjectProxy::ResponseCallback& response_callback, 477 const dbus::ObjectProxy::ResponseCallback& response_callback,
383 const dbus::ObjectProxy::ErrorCallback& error_callback) { 478 const dbus::ObjectProxy::ErrorCallback& error_callback) {
384 OnCallMethod(method_call, timeout_ms, response_callback); 479 OnCallMethod(method_call, timeout_ms, response_callback);
385 } 480 }
386 481
387 } // namespace chromeos 482 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698