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

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

Issue 10949030: This converts the Shill clients to allow propagation of shill errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review changes Created 8 years, 3 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
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 "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
15 namespace chromeos { 17 namespace chromeos {
16 18
17 namespace { 19 namespace {
18 20
19 // Pops a string-to-string dictionary from the reader. 21 // Pops a string-to-string dictionary from the reader.
20 base::DictionaryValue* PopStringToStringDictionary( 22 base::DictionaryValue* PopStringToStringDictionary(
21 dbus::MessageReader* reader) { 23 dbus::MessageReader* reader) {
22 dbus::MessageReader array_reader(NULL); 24 dbus::MessageReader array_reader(NULL);
23 if (!reader->PopArray(&array_reader)) 25 if (!reader->PopArray(&array_reader))
24 return NULL; 26 return NULL;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Create response. 202 // Create response.
201 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 203 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
202 // Set expectations. 204 // Set expectations.
203 base::StringValue value("portal list"); 205 base::StringValue value("portal list");
204 PrepareForMethodCall(flimflam::kSetPropertyFunction, 206 PrepareForMethodCall(flimflam::kSetPropertyFunction,
205 base::Bind(ExpectStringAndValueArguments, 207 base::Bind(ExpectStringAndValueArguments,
206 flimflam::kCheckPortalListProperty, 208 flimflam::kCheckPortalListProperty,
207 &value), 209 &value),
208 response.get()); 210 response.get());
209 // Call method. 211 // Call method.
212 MockClosure mock_closure;
213 MockErrorCallback mock_error_callback;
210 client_->SetProperty(flimflam::kCheckPortalListProperty, 214 client_->SetProperty(flimflam::kCheckPortalListProperty,
211 value, 215 value,
212 base::Bind(&ExpectNoResultValue)); 216 mock_closure.GetCallback(),
217 mock_error_callback.GetCallback());
218 EXPECT_CALL(mock_closure, Run()).Times(1);
219 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
220
213 // Run the message loop. 221 // Run the message loop.
214 message_loop_.RunAllPending(); 222 message_loop_.RunAllPending();
215 } 223 }
216 224
217 TEST_F(ShillManagerClientTest, RequestScan) { 225 TEST_F(ShillManagerClientTest, RequestScan) {
218 // Create response. 226 // Create response.
219 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 227 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
220 // Set expectations. 228 // Set expectations.
221 PrepareForMethodCall(flimflam::kRequestScanFunction, 229 PrepareForMethodCall(flimflam::kRequestScanFunction,
222 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), 230 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi),
223 response.get()); 231 response.get());
224 // Call method. 232 // Call method.
225 client_->RequestScan(flimflam::kTypeWifi, base::Bind(&ExpectNoResultValue)); 233 MockClosure mock_closure;
234 MockErrorCallback mock_error_callback;
235 client_->RequestScan(flimflam::kTypeWifi,
236 mock_closure.GetCallback(),
237 mock_error_callback.GetCallback());
238 EXPECT_CALL(mock_closure, Run()).Times(1);
239 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
240
226 // Run the message loop. 241 // Run the message loop.
227 message_loop_.RunAllPending(); 242 message_loop_.RunAllPending();
228 } 243 }
229 244
230 TEST_F(ShillManagerClientTest, EnableTechnology) { 245 TEST_F(ShillManagerClientTest, EnableTechnology) {
231 // Create response. 246 // Create response.
232 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 247 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
233 // Set expectations. 248 // Set expectations.
234 PrepareForMethodCall(flimflam::kEnableTechnologyFunction, 249 PrepareForMethodCall(flimflam::kEnableTechnologyFunction,
235 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), 250 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi),
236 response.get()); 251 response.get());
237 // Call method. 252 // Call method.
253 MockClosure mock_closure;
254 MockErrorCallback mock_error_callback;
238 client_->EnableTechnology(flimflam::kTypeWifi, 255 client_->EnableTechnology(flimflam::kTypeWifi,
239 base::Bind(&ExpectNoResultValue)); 256 mock_closure.GetCallback(),
257 mock_error_callback.GetCallback());
258 EXPECT_CALL(mock_closure, Run()).Times(1);
259 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
260
240 // Run the message loop. 261 // Run the message loop.
241 message_loop_.RunAllPending(); 262 message_loop_.RunAllPending();
242 } 263 }
243 264
244 TEST_F(ShillManagerClientTest, DisableTechnology) { 265 TEST_F(ShillManagerClientTest, DisableTechnology) {
245 // Create response. 266 // Create response.
246 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 267 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
247 // Set expectations. 268 // Set expectations.
248 PrepareForMethodCall(flimflam::kDisableTechnologyFunction, 269 PrepareForMethodCall(flimflam::kDisableTechnologyFunction,
249 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi), 270 base::Bind(&ExpectStringArgument, flimflam::kTypeWifi),
250 response.get()); 271 response.get());
251 // Call method. 272 // Call method.
273 MockClosure mock_closure;
274 MockErrorCallback mock_error_callback;
252 client_->DisableTechnology(flimflam::kTypeWifi, 275 client_->DisableTechnology(flimflam::kTypeWifi,
253 base::Bind(&ExpectNoResultValue)); 276 mock_closure.GetCallback(),
277 mock_error_callback.GetCallback());
278 EXPECT_CALL(mock_closure, Run()).Times(1);
279 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
280
254 // Run the message loop. 281 // Run the message loop.
255 message_loop_.RunAllPending(); 282 message_loop_.RunAllPending();
256 } 283 }
257 284
258 TEST_F(ShillManagerClientTest, ConfigureService) { 285 TEST_F(ShillManagerClientTest, ConfigureService) {
259 // Create response. 286 // Create response.
260 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 287 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
261 // Create the argument dictionary. 288 // Create the argument dictionary.
262 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties()); 289 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties());
263 // Set expectations. 290 // Set expectations.
264 PrepareForMethodCall(flimflam::kConfigureServiceFunction, 291 PrepareForMethodCall(flimflam::kConfigureServiceFunction,
265 base::Bind(&ExpectDictionaryValueArgument, arg.get()), 292 base::Bind(&ExpectDictionaryValueArgument, arg.get()),
266 response.get()); 293 response.get());
267 // Call method. 294 // Call method.
268 client_->ConfigureService(*arg, base::Bind(&ExpectNoResultValue)); 295 MockClosure mock_closure;
296 MockErrorCallback mock_error_callback;
297 client_->ConfigureService(*arg,
298 mock_closure.GetCallback(),
299 mock_error_callback.GetCallback());
300 EXPECT_CALL(mock_closure, Run()).Times(1);
301 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
302
269 // Run the message loop. 303 // Run the message loop.
270 message_loop_.RunAllPending(); 304 message_loop_.RunAllPending();
271 } 305 }
272 306
273 TEST_F(ShillManagerClientTest, GetService) { 307 TEST_F(ShillManagerClientTest, GetService) {
308 MockErrorCallback error_callback;
hashimoto 2012/09/24 02:28:56 Move this to the line before the actual method cal
Greg Spencer (Chromium) 2012/09/24 21:50:54 Done.
274 // Create response. 309 // Create response.
275 const dbus::ObjectPath object_path("/"); 310 const dbus::ObjectPath object_path("/");
276 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 311 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
277 dbus::MessageWriter writer(response.get()); 312 dbus::MessageWriter writer(response.get());
278 writer.AppendObjectPath(object_path); 313 writer.AppendObjectPath(object_path);
279 // Create the argument dictionary. 314 // Create the argument dictionary.
280 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties()); 315 scoped_ptr<base::DictionaryValue> arg(CreateExampleProperties());
281 // Set expectations. 316 // Set expectations.
282 PrepareForMethodCall(flimflam::kGetServiceFunction, 317 PrepareForMethodCall(flimflam::kGetServiceFunction,
283 base::Bind(&ExpectDictionaryValueArgument, arg.get()), 318 base::Bind(&ExpectDictionaryValueArgument, arg.get()),
284 response.get()); 319 response.get());
285 // Call method. 320 // Call method.
286 client_->GetService(*arg, base::Bind(&ExpectObjectPathResult, object_path)); 321 client_->GetService(*arg,
322 base::Bind(&ExpectObjectPathResultWithoutStatus,
323 object_path),
324 error_callback.GetCallback());
287 // Run the message loop. 325 // Run the message loop.
288 message_loop_.RunAllPending(); 326 message_loop_.RunAllPending();
289 } 327 }
290 328
291 } // namespace chromeos 329 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698