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

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

Issue 2314853004: Remove calls to deprecated MessageLoop methods in chromeos. (Closed)
Patch Set: Created 4 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/run_loop.h"
6 #include "base/values.h" 7 #include "base/values.h"
7 #include "chromeos/dbus/shill_client_unittest_base.h" 8 #include "chromeos/dbus/shill_client_unittest_base.h"
8 #include "chromeos/dbus/shill_manager_client.h" 9 #include "chromeos/dbus/shill_manager_client.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/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::_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 : ShillClientUnittestBase(shill::kFlimflamManagerInterface, 56 : ShillClientUnittestBase(shill::kFlimflamManagerInterface,
56 dbus::ObjectPath(shill::kFlimflamServicePath)) { 57 dbus::ObjectPath(shill::kFlimflamServicePath)) {
57 } 58 }
58 59
59 void SetUp() override { 60 void SetUp() override {
60 ShillClientUnittestBase::SetUp(); 61 ShillClientUnittestBase::SetUp();
61 // Create a client with the mock bus. 62 // Create a client with the mock bus.
62 client_.reset(ShillManagerClient::Create()); 63 client_.reset(ShillManagerClient::Create());
63 client_->Init(mock_bus_.get()); 64 client_->Init(mock_bus_.get());
64 // Run the message loop to run the signal connection result callback. 65 // Run the message loop to run the signal connection result callback.
65 message_loop_.RunUntilIdle(); 66 base::RunLoop().RunUntilIdle();
66 } 67 }
67 68
68 void TearDown() override { ShillClientUnittestBase::TearDown(); } 69 void TearDown() override { ShillClientUnittestBase::TearDown(); }
69 70
70 protected: 71 protected:
71 std::unique_ptr<ShillManagerClient> client_; 72 std::unique_ptr<ShillManagerClient> client_;
72 }; 73 };
73 74
74 TEST_F(ShillManagerClientTest, PropertyChanged) { 75 TEST_F(ShillManagerClientTest, PropertyChanged) {
75 // Create a signal. 76 // Create a signal.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 base::DictionaryValue value; 120 base::DictionaryValue value;
120 value.SetWithoutPathExpansion(shill::kOfflineModeProperty, 121 value.SetWithoutPathExpansion(shill::kOfflineModeProperty,
121 new base::FundamentalValue(true)); 122 new base::FundamentalValue(true));
122 // Set expectations. 123 // Set expectations.
123 PrepareForMethodCall(shill::kGetPropertiesFunction, 124 PrepareForMethodCall(shill::kGetPropertiesFunction,
124 base::Bind(&ExpectNoArgument), 125 base::Bind(&ExpectNoArgument),
125 response.get()); 126 response.get());
126 // Call method. 127 // Call method.
127 client_->GetProperties(base::Bind(&ExpectDictionaryValueResult, &value)); 128 client_->GetProperties(base::Bind(&ExpectDictionaryValueResult, &value));
128 // Run the message loop. 129 // Run the message loop.
129 message_loop_.RunUntilIdle(); 130 base::RunLoop().RunUntilIdle();
130 } 131 }
131 132
132 TEST_F(ShillManagerClientTest, GetNetworksForGeolocation) { 133 TEST_F(ShillManagerClientTest, GetNetworksForGeolocation) {
133 // Create response. 134 // Create response.
134 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 135 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
135 136
136 dbus::MessageWriter writer(response.get()); 137 dbus::MessageWriter writer(response.get());
137 dbus::MessageWriter type_dict_writer(NULL); 138 dbus::MessageWriter type_dict_writer(NULL);
138 writer.OpenArray("{sv}", &type_dict_writer); 139 writer.OpenArray("{sv}", &type_dict_writer);
139 dbus::MessageWriter type_entry_writer(NULL); 140 dbus::MessageWriter type_entry_writer(NULL);
(...skipping 29 matching lines...) Expand all
169 170
170 // Set expectations. 171 // Set expectations.
171 PrepareForMethodCall(shill::kGetNetworksForGeolocation, 172 PrepareForMethodCall(shill::kGetNetworksForGeolocation,
172 base::Bind(&ExpectNoArgument), 173 base::Bind(&ExpectNoArgument),
173 response.get()); 174 response.get());
174 // Call method. 175 // Call method.
175 client_->GetNetworksForGeolocation(base::Bind(&ExpectDictionaryValueResult, 176 client_->GetNetworksForGeolocation(base::Bind(&ExpectDictionaryValueResult,
176 &type_dict_value)); 177 &type_dict_value));
177 178
178 // Run the message loop. 179 // Run the message loop.
179 message_loop_.RunUntilIdle(); 180 base::RunLoop().RunUntilIdle();
180 } 181 }
181 182
182 TEST_F(ShillManagerClientTest, SetProperty) { 183 TEST_F(ShillManagerClientTest, SetProperty) {
183 // Create response. 184 // Create response.
184 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 185 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
185 // Set expectations. 186 // Set expectations.
186 base::StringValue value("portal list"); 187 base::StringValue value("portal list");
187 PrepareForMethodCall(shill::kSetPropertyFunction, 188 PrepareForMethodCall(shill::kSetPropertyFunction,
188 base::Bind(ExpectStringAndValueArguments, 189 base::Bind(ExpectStringAndValueArguments,
189 shill::kCheckPortalListProperty, 190 shill::kCheckPortalListProperty,
190 &value), 191 &value),
191 response.get()); 192 response.get());
192 // Call method. 193 // Call method.
193 MockClosure mock_closure; 194 MockClosure mock_closure;
194 MockErrorCallback mock_error_callback; 195 MockErrorCallback mock_error_callback;
195 client_->SetProperty(shill::kCheckPortalListProperty, 196 client_->SetProperty(shill::kCheckPortalListProperty,
196 value, 197 value,
197 mock_closure.GetCallback(), 198 mock_closure.GetCallback(),
198 mock_error_callback.GetCallback()); 199 mock_error_callback.GetCallback());
199 EXPECT_CALL(mock_closure, Run()).Times(1); 200 EXPECT_CALL(mock_closure, Run()).Times(1);
200 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 201 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
201 202
202 // Run the message loop. 203 // Run the message loop.
203 message_loop_.RunUntilIdle(); 204 base::RunLoop().RunUntilIdle();
204 } 205 }
205 206
206 TEST_F(ShillManagerClientTest, RequestScan) { 207 TEST_F(ShillManagerClientTest, RequestScan) {
207 // Create response. 208 // Create response.
208 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 209 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
209 // Set expectations. 210 // Set expectations.
210 PrepareForMethodCall(shill::kRequestScanFunction, 211 PrepareForMethodCall(shill::kRequestScanFunction,
211 base::Bind(&ExpectStringArgument, shill::kTypeWifi), 212 base::Bind(&ExpectStringArgument, shill::kTypeWifi),
212 response.get()); 213 response.get());
213 // Call method. 214 // Call method.
214 MockClosure mock_closure; 215 MockClosure mock_closure;
215 MockErrorCallback mock_error_callback; 216 MockErrorCallback mock_error_callback;
216 client_->RequestScan(shill::kTypeWifi, 217 client_->RequestScan(shill::kTypeWifi,
217 mock_closure.GetCallback(), 218 mock_closure.GetCallback(),
218 mock_error_callback.GetCallback()); 219 mock_error_callback.GetCallback());
219 EXPECT_CALL(mock_closure, Run()).Times(1); 220 EXPECT_CALL(mock_closure, Run()).Times(1);
220 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 221 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
221 222
222 // Run the message loop. 223 // Run the message loop.
223 message_loop_.RunUntilIdle(); 224 base::RunLoop().RunUntilIdle();
224 } 225 }
225 226
226 TEST_F(ShillManagerClientTest, EnableTechnology) { 227 TEST_F(ShillManagerClientTest, EnableTechnology) {
227 // Create response. 228 // Create response.
228 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 229 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
229 // Set expectations. 230 // Set expectations.
230 PrepareForMethodCall(shill::kEnableTechnologyFunction, 231 PrepareForMethodCall(shill::kEnableTechnologyFunction,
231 base::Bind(&ExpectStringArgument, shill::kTypeWifi), 232 base::Bind(&ExpectStringArgument, shill::kTypeWifi),
232 response.get()); 233 response.get());
233 // Call method. 234 // Call method.
234 MockClosure mock_closure; 235 MockClosure mock_closure;
235 MockErrorCallback mock_error_callback; 236 MockErrorCallback mock_error_callback;
236 client_->EnableTechnology(shill::kTypeWifi, 237 client_->EnableTechnology(shill::kTypeWifi,
237 mock_closure.GetCallback(), 238 mock_closure.GetCallback(),
238 mock_error_callback.GetCallback()); 239 mock_error_callback.GetCallback());
239 EXPECT_CALL(mock_closure, Run()).Times(1); 240 EXPECT_CALL(mock_closure, Run()).Times(1);
240 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 241 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
241 242
242 // Run the message loop. 243 // Run the message loop.
243 message_loop_.RunUntilIdle(); 244 base::RunLoop().RunUntilIdle();
244 } 245 }
245 246
246 TEST_F(ShillManagerClientTest, DisableTechnology) { 247 TEST_F(ShillManagerClientTest, DisableTechnology) {
247 // Create response. 248 // Create response.
248 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 249 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
249 // Set expectations. 250 // Set expectations.
250 PrepareForMethodCall(shill::kDisableTechnologyFunction, 251 PrepareForMethodCall(shill::kDisableTechnologyFunction,
251 base::Bind(&ExpectStringArgument, shill::kTypeWifi), 252 base::Bind(&ExpectStringArgument, shill::kTypeWifi),
252 response.get()); 253 response.get());
253 // Call method. 254 // Call method.
254 MockClosure mock_closure; 255 MockClosure mock_closure;
255 MockErrorCallback mock_error_callback; 256 MockErrorCallback mock_error_callback;
256 client_->DisableTechnology(shill::kTypeWifi, 257 client_->DisableTechnology(shill::kTypeWifi,
257 mock_closure.GetCallback(), 258 mock_closure.GetCallback(),
258 mock_error_callback.GetCallback()); 259 mock_error_callback.GetCallback());
259 EXPECT_CALL(mock_closure, Run()).Times(1); 260 EXPECT_CALL(mock_closure, Run()).Times(1);
260 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 261 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
261 262
262 // Run the message loop. 263 // Run the message loop.
263 message_loop_.RunUntilIdle(); 264 base::RunLoop().RunUntilIdle();
264 } 265 }
265 266
266 TEST_F(ShillManagerClientTest, ConfigureService) { 267 TEST_F(ShillManagerClientTest, ConfigureService) {
267 // Create response. 268 // Create response.
268 const dbus::ObjectPath object_path("/"); 269 const dbus::ObjectPath object_path("/");
269 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 270 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
270 dbus::MessageWriter writer(response.get()); 271 dbus::MessageWriter writer(response.get());
271 writer.AppendObjectPath(object_path); 272 writer.AppendObjectPath(object_path);
272 // Create the argument dictionary. 273 // Create the argument dictionary.
273 std::unique_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties()); 274 std::unique_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties());
274 // Use a variant valued dictionary rather than a string valued one. 275 // Use a variant valued dictionary rather than a string valued one.
275 const bool string_valued = false; 276 const bool string_valued = false;
276 // Set expectations. 277 // Set expectations.
277 PrepareForMethodCall( 278 PrepareForMethodCall(
278 shill::kConfigureServiceFunction, 279 shill::kConfigureServiceFunction,
279 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued), 280 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued),
280 response.get()); 281 response.get());
281 // Call method. 282 // Call method.
282 MockErrorCallback mock_error_callback; 283 MockErrorCallback mock_error_callback;
283 client_->ConfigureService(*arg, 284 client_->ConfigureService(*arg,
284 base::Bind(&ExpectObjectPathResultWithoutStatus, 285 base::Bind(&ExpectObjectPathResultWithoutStatus,
285 object_path), 286 object_path),
286 mock_error_callback.GetCallback()); 287 mock_error_callback.GetCallback());
287 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 288 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
288 289
289 // Run the message loop. 290 // Run the message loop.
290 message_loop_.RunUntilIdle(); 291 base::RunLoop().RunUntilIdle();
291 } 292 }
292 293
293 TEST_F(ShillManagerClientTest, GetService) { 294 TEST_F(ShillManagerClientTest, GetService) {
294 // Create response. 295 // Create response.
295 const dbus::ObjectPath object_path("/"); 296 const dbus::ObjectPath object_path("/");
296 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 297 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
297 dbus::MessageWriter writer(response.get()); 298 dbus::MessageWriter writer(response.get());
298 writer.AppendObjectPath(object_path); 299 writer.AppendObjectPath(object_path);
299 // Create the argument dictionary. 300 // Create the argument dictionary.
300 std::unique_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties()); 301 std::unique_ptr<base::DictionaryValue> arg(CreateExampleServiceProperties());
301 // Use a variant valued dictionary rather than a string valued one. 302 // Use a variant valued dictionary rather than a string valued one.
302 const bool string_valued = false; 303 const bool string_valued = false;
303 // Set expectations. 304 // Set expectations.
304 PrepareForMethodCall( 305 PrepareForMethodCall(
305 shill::kGetServiceFunction, 306 shill::kGetServiceFunction,
306 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued), 307 base::Bind(&ExpectDictionaryValueArgument, arg.get(), string_valued),
307 response.get()); 308 response.get());
308 // Call method. 309 // Call method.
309 MockErrorCallback mock_error_callback; 310 MockErrorCallback mock_error_callback;
310 client_->GetService(*arg, 311 client_->GetService(*arg,
311 base::Bind(&ExpectObjectPathResultWithoutStatus, 312 base::Bind(&ExpectObjectPathResultWithoutStatus,
312 object_path), 313 object_path),
313 mock_error_callback.GetCallback()); 314 mock_error_callback.GetCallback());
314 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 315 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
315 316
316 // Run the message loop. 317 // Run the message loop.
317 message_loop_.RunUntilIdle(); 318 base::RunLoop().RunUntilIdle();
318 } 319 }
319 320
320 TEST_F(ShillManagerClientTest, VerifyDestination) { 321 TEST_F(ShillManagerClientTest, VerifyDestination) {
321 // Create response. 322 // Create response.
322 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 323 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
323 dbus::MessageWriter writer(response.get()); 324 dbus::MessageWriter writer(response.get());
324 bool expected = true; 325 bool expected = true;
325 writer.AppendBool(expected); 326 writer.AppendBool(expected);
326 // Set expectations. 327 // Set expectations.
327 std::vector<std::string> arguments; 328 std::vector<std::string> arguments;
(...skipping 18 matching lines...) Expand all
346 properties.device_serial = arguments[4]; 347 properties.device_serial = arguments[4];
347 properties.device_ssid = arguments[5]; 348 properties.device_ssid = arguments[5];
348 properties.device_bssid = arguments[6]; 349 properties.device_bssid = arguments[6];
349 client_->VerifyDestination( 350 client_->VerifyDestination(
350 properties, 351 properties,
351 base::Bind(&ExpectBoolResultWithoutStatus, expected), 352 base::Bind(&ExpectBoolResultWithoutStatus, expected),
352 mock_error_callback.GetCallback()); 353 mock_error_callback.GetCallback());
353 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 354 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
354 355
355 // Run the message loop. 356 // Run the message loop.
356 message_loop_.RunUntilIdle(); 357 base::RunLoop().RunUntilIdle();
357 } 358 }
358 359
359 TEST_F(ShillManagerClientTest, VerifyAndEncryptCredentials) { 360 TEST_F(ShillManagerClientTest, VerifyAndEncryptCredentials) {
360 // Create response. 361 // Create response.
361 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 362 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
362 dbus::MessageWriter writer(response.get()); 363 dbus::MessageWriter writer(response.get());
363 std::string expected = "encrypted_credentials"; 364 std::string expected = "encrypted_credentials";
364 writer.AppendString(expected); 365 writer.AppendString(expected);
365 // Set expectations. 366 // Set expectations.
366 std::vector<std::string> arguments; 367 std::vector<std::string> arguments;
(...skipping 23 matching lines...) Expand all
390 properties.device_ssid = arguments[5]; 391 properties.device_ssid = arguments[5];
391 properties.device_bssid = arguments[6]; 392 properties.device_bssid = arguments[6];
392 client_->VerifyAndEncryptCredentials( 393 client_->VerifyAndEncryptCredentials(
393 properties, 394 properties,
394 service_path, 395 service_path,
395 base::Bind(&ExpectStringResultWithoutStatus, expected), 396 base::Bind(&ExpectStringResultWithoutStatus, expected),
396 mock_error_callback.GetCallback()); 397 mock_error_callback.GetCallback());
397 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 398 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
398 399
399 // Run the message loop. 400 // Run the message loop.
400 message_loop_.RunUntilIdle(); 401 base::RunLoop().RunUntilIdle();
401 } 402 }
402 403
403 TEST_F(ShillManagerClientTest, VerifyAndEncryptData) { 404 TEST_F(ShillManagerClientTest, VerifyAndEncryptData) {
404 // Create response. 405 // Create response.
405 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 406 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
406 dbus::MessageWriter writer(response.get()); 407 dbus::MessageWriter writer(response.get());
407 std::string expected = "encrypted_data"; 408 std::string expected = "encrypted_data";
408 writer.AppendString(expected); 409 writer.AppendString(expected);
409 // Set expectations. 410 // Set expectations.
410 std::vector<std::string> arguments; 411 std::vector<std::string> arguments;
(...skipping 20 matching lines...) Expand all
431 properties.device_ssid = arguments[5]; 432 properties.device_ssid = arguments[5];
432 properties.device_bssid = arguments[6]; 433 properties.device_bssid = arguments[6];
433 client_->VerifyAndEncryptData( 434 client_->VerifyAndEncryptData(
434 properties, 435 properties,
435 arguments[7], 436 arguments[7],
436 base::Bind(&ExpectStringResultWithoutStatus, expected), 437 base::Bind(&ExpectStringResultWithoutStatus, expected),
437 mock_error_callback.GetCallback()); 438 mock_error_callback.GetCallback());
438 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 439 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
439 440
440 // Run the message loop. 441 // Run the message loop.
441 message_loop_.RunUntilIdle(); 442 base::RunLoop().RunUntilIdle();
442 } 443 }
443 444
444 } // namespace chromeos 445 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698