OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "chromeos/dbus/shill_client_unittest_base.h" | 7 #include "chromeos/dbus/shill_client_unittest_base.h" |
8 #include "chromeos/dbus/shill_manager_client.h" | 8 #include "chromeos/dbus/shill_manager_client.h" |
9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
10 #include "dbus/object_path.h" | 10 #include "dbus/object_path.h" |
11 #include "dbus/values_util.h" | 11 #include "dbus/values_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
14 | 14 |
| 15 using testing::_; |
| 16 using testing::ByRef; |
| 17 |
15 namespace chromeos { | 18 namespace chromeos { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 // Pops a string-to-string dictionary from the reader. | 22 // Pops a string-to-string dictionary from the reader. |
20 base::DictionaryValue* PopStringToStringDictionary( | 23 base::DictionaryValue* PopStringToStringDictionary( |
21 dbus::MessageReader* reader) { | 24 dbus::MessageReader* reader) { |
22 dbus::MessageReader array_reader(NULL); | 25 dbus::MessageReader array_reader(NULL); |
23 if (!reader->PopArray(&array_reader)) | 26 if (!reader->PopArray(&array_reader)) |
24 return NULL; | 27 return NULL; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 TEST_F(ShillManagerClientTest, PropertyChanged) { | 127 TEST_F(ShillManagerClientTest, PropertyChanged) { |
125 // Create a signal. | 128 // Create a signal. |
126 base::FundamentalValue kOfflineMode(true); | 129 base::FundamentalValue kOfflineMode(true); |
127 dbus::Signal signal(flimflam::kFlimflamManagerInterface, | 130 dbus::Signal signal(flimflam::kFlimflamManagerInterface, |
128 flimflam::kMonitorPropertyChanged); | 131 flimflam::kMonitorPropertyChanged); |
129 dbus::MessageWriter writer(&signal); | 132 dbus::MessageWriter writer(&signal); |
130 writer.AppendString(flimflam::kOfflineModeProperty); | 133 writer.AppendString(flimflam::kOfflineModeProperty); |
131 dbus::AppendBasicTypeValueData(&writer, kOfflineMode); | 134 dbus::AppendBasicTypeValueData(&writer, kOfflineMode); |
132 | 135 |
133 // Set expectations. | 136 // Set expectations. |
134 client_->SetPropertyChangedHandler(base::Bind(&ExpectPropertyChanged, | 137 MockPropertyChangeObserver observer; |
135 flimflam::kOfflineModeProperty, | 138 EXPECT_CALL(observer, |
136 &kOfflineMode)); | 139 OnPropertyChanged(flimflam::kOfflineModeProperty, |
| 140 ValueEq(ByRef(kOfflineMode)))).Times(1); |
| 141 |
| 142 // Add the observer |
| 143 client_->AddPropertyChangedObserver(&observer); |
| 144 |
137 // Run the signal callback. | 145 // Run the signal callback. |
138 SendPropertyChangedSignal(&signal); | 146 SendPropertyChangedSignal(&signal); |
139 | 147 |
140 // Reset the handler. | 148 // Remove the observer. |
141 client_->ResetPropertyChangedHandler(); | 149 client_->RemovePropertyChangedObserver(&observer); |
| 150 |
| 151 // Make sure it's not called anymore. |
| 152 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0); |
| 153 |
| 154 // Run the signal callback again and make sure the observer isn't called. |
| 155 SendPropertyChangedSignal(&signal); |
142 } | 156 } |
143 | 157 |
144 TEST_F(ShillManagerClientTest, GetProperties) { | 158 TEST_F(ShillManagerClientTest, GetProperties) { |
145 // Create response. | 159 // Create response. |
146 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 160 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
147 dbus::MessageWriter writer(response.get()); | 161 dbus::MessageWriter writer(response.get()); |
148 dbus::MessageWriter array_writer(NULL); | 162 dbus::MessageWriter array_writer(NULL); |
149 writer.OpenArray("{sv}", &array_writer); | 163 writer.OpenArray("{sv}", &array_writer); |
150 dbus::MessageWriter entry_writer(NULL); | 164 dbus::MessageWriter entry_writer(NULL); |
151 array_writer.OpenDictEntry(&entry_writer); | 165 array_writer.OpenDictEntry(&entry_writer); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Create response. | 214 // Create response. |
201 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 215 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
202 // Set expectations. | 216 // Set expectations. |
203 base::StringValue value("portal list"); | 217 base::StringValue value("portal list"); |
204 PrepareForMethodCall(flimflam::kSetPropertyFunction, | 218 PrepareForMethodCall(flimflam::kSetPropertyFunction, |
205 base::Bind(ExpectStringAndValueArguments, | 219 base::Bind(ExpectStringAndValueArguments, |
206 flimflam::kCheckPortalListProperty, | 220 flimflam::kCheckPortalListProperty, |
207 &value), | 221 &value), |
208 response.get()); | 222 response.get()); |
209 // Call method. | 223 // Call method. |
| 224 MockClosure mock_closure; |
| 225 MockErrorCallback mock_error_callback; |
210 client_->SetProperty(flimflam::kCheckPortalListProperty, | 226 client_->SetProperty(flimflam::kCheckPortalListProperty, |
211 value, | 227 value, |
212 base::Bind(&ExpectNoResultValue)); | 228 mock_closure.GetCallback(), |
| 229 mock_error_callback.GetCallback()); |
| 230 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 231 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 232 |
213 // Run the message loop. | 233 // Run the message loop. |
214 message_loop_.RunAllPending(); | 234 message_loop_.RunAllPending(); |
215 } | 235 } |
216 | 236 |
217 TEST_F(ShillManagerClientTest, RequestScan) { | 237 TEST_F(ShillManagerClientTest, RequestScan) { |
218 // Create response. | 238 // Create response. |
219 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 239 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
220 // Set expectations. | 240 // Set expectations. |
221 PrepareForMethodCall(flimflam::kRequestScanFunction, | 241 PrepareForMethodCall(flimflam::kRequestScanFunction, |
222 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), | 242 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), |
223 response.get()); | 243 response.get()); |
224 // Call method. | 244 // Call method. |
225 client_->RequestScan(flimflam::kTypeWifi, base::Bind(&ExpectNoResultValue)); | 245 MockClosure mock_closure; |
| 246 MockErrorCallback mock_error_callback; |
| 247 client_->RequestScan(flimflam::kTypeWifi, |
| 248 mock_closure.GetCallback(), |
| 249 mock_error_callback.GetCallback()); |
| 250 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 251 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 252 |
226 // Run the message loop. | 253 // Run the message loop. |
227 message_loop_.RunAllPending(); | 254 message_loop_.RunAllPending(); |
228 } | 255 } |
229 | 256 |
230 TEST_F(ShillManagerClientTest, EnableTechnology) { | 257 TEST_F(ShillManagerClientTest, EnableTechnology) { |
231 // Create response. | 258 // Create response. |
232 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 259 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
233 // Set expectations. | 260 // Set expectations. |
234 PrepareForMethodCall(flimflam::kEnableTechnologyFunction, | 261 PrepareForMethodCall(flimflam::kEnableTechnologyFunction, |
235 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), | 262 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), |
236 response.get()); | 263 response.get()); |
237 // Call method. | 264 // Call method. |
| 265 MockClosure mock_closure; |
| 266 MockErrorCallback mock_error_callback; |
238 client_->EnableTechnology(flimflam::kTypeWifi, | 267 client_->EnableTechnology(flimflam::kTypeWifi, |
239 base::Bind(&ExpectNoResultValue)); | 268 mock_closure.GetCallback(), |
| 269 mock_error_callback.GetCallback()); |
| 270 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 271 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 272 |
240 // Run the message loop. | 273 // Run the message loop. |
241 message_loop_.RunAllPending(); | 274 message_loop_.RunAllPending(); |
242 } | 275 } |
243 | 276 |
244 TEST_F(ShillManagerClientTest, DisableTechnology) { | 277 TEST_F(ShillManagerClientTest, DisableTechnology) { |
245 // Create response. | 278 // Create response. |
246 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 279 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
247 // Set expectations. | 280 // Set expectations. |
248 PrepareForMethodCall(flimflam::kDisableTechnologyFunction, | 281 PrepareForMethodCall(flimflam::kDisableTechnologyFunction, |
249 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), | 282 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), |
250 response.get()); | 283 response.get()); |
251 // Call method. | 284 // Call method. |
| 285 MockClosure mock_closure; |
| 286 MockErrorCallback mock_error_callback; |
252 client_->DisableTechnology(flimflam::kTypeWifi, | 287 client_->DisableTechnology(flimflam::kTypeWifi, |
253 base::Bind(&ExpectNoResultValue)); | 288 mock_closure.GetCallback(), |
| 289 mock_error_callback.GetCallback()); |
| 290 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 291 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 292 |
254 // Run the message loop. | 293 // Run the message loop. |
255 message_loop_.RunAllPending(); | 294 message_loop_.RunAllPending(); |
256 } | 295 } |
257 | 296 |
258 TEST_F(ShillManagerClientTest, ConfigureService) { | 297 TEST_F(ShillManagerClientTest, ConfigureService) { |
259 // Create response. | 298 // Create response. |
260 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 299 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
261 // Create the argument dictionary. | 300 // Create the argument dictionary. |
262 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties()); | 301 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties()); |
263 // Set expectations. | 302 // Set expectations. |
264 PrepareForMethodCall(flimflam::kConfigureServiceFunction, | 303 PrepareForMethodCall(flimflam::kConfigureServiceFunction, |
265 base::Bind(&ExpectDictionaryValueArgument, arg.get()), | 304 base::Bind(&ExpectDictionaryValueArgument, arg.get()), |
266 response.get()); | 305 response.get()); |
267 // Call method. | 306 // Call method. |
268 client_->ConfigureService(*arg, base::Bind(&ExpectNoResultValue)); | 307 MockClosure mock_closure; |
| 308 MockErrorCallback mock_error_callback; |
| 309 client_->ConfigureService(*arg, |
| 310 mock_closure.GetCallback(), |
| 311 mock_error_callback.GetCallback()); |
| 312 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 313 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 314 |
269 // Run the message loop. | 315 // Run the message loop. |
270 message_loop_.RunAllPending(); | 316 message_loop_.RunAllPending(); |
271 } | 317 } |
272 | 318 |
273 TEST_F(ShillManagerClientTest, GetService) { | 319 TEST_F(ShillManagerClientTest, GetService) { |
| 320 MockErrorCallback error_callback; |
274 // Create response. | 321 // Create response. |
275 const dbus::ObjectPath object_path("/"); | 322 const dbus::ObjectPath object_path("/"); |
276 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 323 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
277 dbus::MessageWriter writer(response.get()); | 324 dbus::MessageWriter writer(response.get()); |
278 writer.AppendObjectPath(object_path); | 325 writer.AppendObjectPath(object_path); |
279 // Create the argument dictionary. | 326 // Create the argument dictionary. |
280 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties()); | 327 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties()); |
281 // Set expectations. | 328 // Set expectations. |
282 PrepareForMethodCall(flimflam::kGetServiceFunction, | 329 PrepareForMethodCall(flimflam::kGetServiceFunction, |
283 base::Bind(&ExpectDictionaryValueArgument, arg.get()), | 330 base::Bind(&ExpectDictionaryValueArgument, arg.get()), |
284 response.get()); | 331 response.get()); |
285 // Call method. | 332 // Call method. |
286 client_->GetService(*arg, base::Bind(&ExpectObjectPathResult, object_path)); | 333 client_->GetService(*arg, |
| 334 base::Bind(&ExpectObjectPathResult, object_path), |
| 335 error_callback.GetCallback()); |
287 // Run the message loop. | 336 // Run the message loop. |
288 message_loop_.RunAllPending(); | 337 message_loop_.RunAllPending(); |
289 } | 338 } |
290 | 339 |
291 } // namespace chromeos | 340 } // namespace chromeos |
OLD | NEW |