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

Side by Side Diff: chromeos/dbus/shill_device_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_device_client.h" 9 #include "chromeos/dbus/shill_device_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::kFlimflamDeviceInterface, 56 : ShillClientUnittestBase(shill::kFlimflamDeviceInterface,
56 dbus::ObjectPath(kExampleDevicePath)) { 57 dbus::ObjectPath(kExampleDevicePath)) {
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(ShillDeviceClient::Create()); 63 client_.reset(ShillDeviceClient::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<ShillDeviceClient> client_; 72 std::unique_ptr<ShillDeviceClient> client_;
72 }; 73 };
73 74
74 TEST_F(ShillDeviceClientTest, PropertyChanged) { 75 TEST_F(ShillDeviceClientTest, PropertyChanged) {
75 const bool kValue = true; 76 const bool kValue = true;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 base::DictionaryValue value; 127 base::DictionaryValue value;
127 value.SetWithoutPathExpansion(shill::kCellularAllowRoamingProperty, 128 value.SetWithoutPathExpansion(shill::kCellularAllowRoamingProperty,
128 new base::FundamentalValue(kValue)); 129 new base::FundamentalValue(kValue));
129 PrepareForMethodCall(shill::kGetPropertiesFunction, 130 PrepareForMethodCall(shill::kGetPropertiesFunction,
130 base::Bind(&ExpectNoArgument), 131 base::Bind(&ExpectNoArgument),
131 response.get()); 132 response.get());
132 // Call method. 133 // Call method.
133 client_->GetProperties(dbus::ObjectPath(kExampleDevicePath), 134 client_->GetProperties(dbus::ObjectPath(kExampleDevicePath),
134 base::Bind(&ExpectDictionaryValueResult, &value)); 135 base::Bind(&ExpectDictionaryValueResult, &value));
135 // Run the message loop. 136 // Run the message loop.
136 message_loop_.RunUntilIdle(); 137 base::RunLoop().RunUntilIdle();
137 } 138 }
138 139
139 TEST_F(ShillDeviceClientTest, ProposeScan) { 140 TEST_F(ShillDeviceClientTest, ProposeScan) {
140 // Create response. 141 // Create response.
141 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 142 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
142 143
143 // Set expectations. 144 // Set expectations.
144 PrepareForMethodCall(shill::kProposeScanFunction, 145 PrepareForMethodCall(shill::kProposeScanFunction,
145 base::Bind(&ExpectNoArgument), 146 base::Bind(&ExpectNoArgument),
146 response.get()); 147 response.get());
147 // Call method. 148 // Call method.
148 client_->ProposeScan(dbus::ObjectPath(kExampleDevicePath), 149 client_->ProposeScan(dbus::ObjectPath(kExampleDevicePath),
149 base::Bind(&ExpectNoResultValue)); 150 base::Bind(&ExpectNoResultValue));
150 // Run the message loop. 151 // Run the message loop.
151 message_loop_.RunUntilIdle(); 152 base::RunLoop().RunUntilIdle();
152 } 153 }
153 154
154 TEST_F(ShillDeviceClientTest, SetProperty) { 155 TEST_F(ShillDeviceClientTest, SetProperty) {
155 const bool kValue = true; 156 const bool kValue = true;
156 // Create response. 157 // Create response.
157 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 158 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
158 159
159 // Set expectations. 160 // Set expectations.
160 const base::FundamentalValue value(kValue); 161 const base::FundamentalValue value(kValue);
161 PrepareForMethodCall(shill::kSetPropertyFunction, 162 PrepareForMethodCall(shill::kSetPropertyFunction,
162 base::Bind(&ExpectStringAndValueArguments, 163 base::Bind(&ExpectStringAndValueArguments,
163 shill::kCellularAllowRoamingProperty, 164 shill::kCellularAllowRoamingProperty,
164 &value), 165 &value),
165 response.get()); 166 response.get());
166 // Call method. 167 // Call method.
167 MockClosure mock_closure; 168 MockClosure mock_closure;
168 MockErrorCallback mock_error_callback; 169 MockErrorCallback mock_error_callback;
169 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath), 170 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath),
170 shill::kCellularAllowRoamingProperty, 171 shill::kCellularAllowRoamingProperty,
171 value, 172 value,
172 mock_closure.GetCallback(), 173 mock_closure.GetCallback(),
173 mock_error_callback.GetCallback()); 174 mock_error_callback.GetCallback());
174 EXPECT_CALL(mock_closure, Run()).Times(1); 175 EXPECT_CALL(mock_closure, Run()).Times(1);
175 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 176 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
176 177
177 // Run the message loop. 178 // Run the message loop.
178 message_loop_.RunUntilIdle(); 179 base::RunLoop().RunUntilIdle();
179 } 180 }
180 181
181 TEST_F(ShillDeviceClientTest, ClearProperty) { 182 TEST_F(ShillDeviceClientTest, ClearProperty) {
182 // Create response. 183 // Create response.
183 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 184 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
184 185
185 // Set expectations. 186 // Set expectations.
186 PrepareForMethodCall(shill::kClearPropertyFunction, 187 PrepareForMethodCall(shill::kClearPropertyFunction,
187 base::Bind(&ExpectStringArgument, 188 base::Bind(&ExpectStringArgument,
188 shill::kCellularAllowRoamingProperty), 189 shill::kCellularAllowRoamingProperty),
189 response.get()); 190 response.get());
190 // Call method. 191 // Call method.
191 client_->ClearProperty(dbus::ObjectPath(kExampleDevicePath), 192 client_->ClearProperty(dbus::ObjectPath(kExampleDevicePath),
192 shill::kCellularAllowRoamingProperty, 193 shill::kCellularAllowRoamingProperty,
193 base::Bind(&ExpectNoResultValue)); 194 base::Bind(&ExpectNoResultValue));
194 // Run the message loop. 195 // Run the message loop.
195 message_loop_.RunUntilIdle(); 196 base::RunLoop().RunUntilIdle();
196 } 197 }
197 198
198 TEST_F(ShillDeviceClientTest, AddIPConfig) { 199 TEST_F(ShillDeviceClientTest, AddIPConfig) {
199 const dbus::ObjectPath expected_result("/result/path"); 200 const dbus::ObjectPath expected_result("/result/path");
200 // Create response. 201 // Create response.
201 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 202 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
202 dbus::MessageWriter writer(response.get()); 203 dbus::MessageWriter writer(response.get());
203 writer.AppendObjectPath(expected_result); 204 writer.AppendObjectPath(expected_result);
204 205
205 // Set expectations. 206 // Set expectations.
206 PrepareForMethodCall(shill::kAddIPConfigFunction, 207 PrepareForMethodCall(shill::kAddIPConfigFunction,
207 base::Bind(&ExpectStringArgument, shill::kTypeDHCP), 208 base::Bind(&ExpectStringArgument, shill::kTypeDHCP),
208 response.get()); 209 response.get());
209 // Call method. 210 // Call method.
210 client_->AddIPConfig(dbus::ObjectPath(kExampleDevicePath), 211 client_->AddIPConfig(dbus::ObjectPath(kExampleDevicePath),
211 shill::kTypeDHCP, 212 shill::kTypeDHCP,
212 base::Bind(&ExpectObjectPathResult, expected_result)); 213 base::Bind(&ExpectObjectPathResult, expected_result));
213 // Run the message loop. 214 // Run the message loop.
214 message_loop_.RunUntilIdle(); 215 base::RunLoop().RunUntilIdle();
215 } 216 }
216 217
217 TEST_F(ShillDeviceClientTest, RequirePin) { 218 TEST_F(ShillDeviceClientTest, RequirePin) {
218 const char kPin[] = "123456"; 219 const char kPin[] = "123456";
219 const bool kRequired = true; 220 const bool kRequired = true;
220 // Create response. 221 // Create response.
221 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 222 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
222 223
223 // Set expectations. 224 // Set expectations.
224 MockClosure mock_closure; 225 MockClosure mock_closure;
225 MockErrorCallback mock_error_callback; 226 MockErrorCallback mock_error_callback;
226 PrepareForMethodCall(shill::kRequirePinFunction, 227 PrepareForMethodCall(shill::kRequirePinFunction,
227 base::Bind(&ExpectStringAndBoolArguments, 228 base::Bind(&ExpectStringAndBoolArguments,
228 kPin, 229 kPin,
229 kRequired), 230 kRequired),
230 response.get()); 231 response.get());
231 EXPECT_CALL(mock_closure, Run()).Times(1); 232 EXPECT_CALL(mock_closure, Run()).Times(1);
232 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 233 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
233 // Call method. 234 // Call method.
234 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath), 235 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath),
235 kPin, 236 kPin,
236 kRequired, 237 kRequired,
237 mock_closure.GetCallback(), 238 mock_closure.GetCallback(),
238 mock_error_callback.GetCallback()); 239 mock_error_callback.GetCallback());
239 // Run the message loop. 240 // Run the message loop.
240 message_loop_.RunUntilIdle(); 241 base::RunLoop().RunUntilIdle();
241 } 242 }
242 243
243 TEST_F(ShillDeviceClientTest, EnterPin) { 244 TEST_F(ShillDeviceClientTest, EnterPin) {
244 const char kPin[] = "123456"; 245 const char kPin[] = "123456";
245 // Create response. 246 // Create response.
246 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 247 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
247 248
248 // Set expectations. 249 // Set expectations.
249 MockClosure mock_closure; 250 MockClosure mock_closure;
250 MockErrorCallback mock_error_callback; 251 MockErrorCallback mock_error_callback;
251 PrepareForMethodCall(shill::kEnterPinFunction, 252 PrepareForMethodCall(shill::kEnterPinFunction,
252 base::Bind(&ExpectStringArgument, 253 base::Bind(&ExpectStringArgument,
253 kPin), 254 kPin),
254 response.get()); 255 response.get());
255 EXPECT_CALL(mock_closure, Run()).Times(1); 256 EXPECT_CALL(mock_closure, Run()).Times(1);
256 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 257 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
257 258
258 // Call method. 259 // Call method.
259 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath), 260 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath),
260 kPin, 261 kPin,
261 mock_closure.GetCallback(), 262 mock_closure.GetCallback(),
262 mock_error_callback.GetCallback()); 263 mock_error_callback.GetCallback());
263 // Run the message loop. 264 // Run the message loop.
264 message_loop_.RunUntilIdle(); 265 base::RunLoop().RunUntilIdle();
265 } 266 }
266 267
267 TEST_F(ShillDeviceClientTest, UnblockPin) { 268 TEST_F(ShillDeviceClientTest, UnblockPin) {
268 const char kPuk[] = "987654"; 269 const char kPuk[] = "987654";
269 const char kPin[] = "123456"; 270 const char kPin[] = "123456";
270 // Create response. 271 // Create response.
271 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 272 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
272 273
273 // Set expectations. 274 // Set expectations.
274 MockClosure mock_closure; 275 MockClosure mock_closure;
275 MockErrorCallback mock_error_callback; 276 MockErrorCallback mock_error_callback;
276 PrepareForMethodCall(shill::kUnblockPinFunction, 277 PrepareForMethodCall(shill::kUnblockPinFunction,
277 base::Bind(&ExpectTwoStringArguments, kPuk, kPin), 278 base::Bind(&ExpectTwoStringArguments, kPuk, kPin),
278 response.get()); 279 response.get());
279 EXPECT_CALL(mock_closure, Run()).Times(1); 280 EXPECT_CALL(mock_closure, Run()).Times(1);
280 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 281 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
281 282
282 // Call method. 283 // Call method.
283 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath), 284 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath),
284 kPuk, 285 kPuk,
285 kPin, 286 kPin,
286 mock_closure.GetCallback(), 287 mock_closure.GetCallback(),
287 mock_error_callback.GetCallback()); 288 mock_error_callback.GetCallback());
288 // Run the message loop. 289 // Run the message loop.
289 message_loop_.RunUntilIdle(); 290 base::RunLoop().RunUntilIdle();
290 } 291 }
291 292
292 TEST_F(ShillDeviceClientTest, ChangePin) { 293 TEST_F(ShillDeviceClientTest, ChangePin) {
293 const char kOldPin[] = "123456"; 294 const char kOldPin[] = "123456";
294 const char kNewPin[] = "234567"; 295 const char kNewPin[] = "234567";
295 // Create response. 296 // Create response.
296 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 297 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
297 298
298 // Set expectations. 299 // Set expectations.
299 MockClosure mock_closure; 300 MockClosure mock_closure;
300 MockErrorCallback mock_error_callback; 301 MockErrorCallback mock_error_callback;
301 PrepareForMethodCall(shill::kChangePinFunction, 302 PrepareForMethodCall(shill::kChangePinFunction,
302 base::Bind(&ExpectTwoStringArguments, 303 base::Bind(&ExpectTwoStringArguments,
303 kOldPin, 304 kOldPin,
304 kNewPin), 305 kNewPin),
305 response.get()); 306 response.get());
306 EXPECT_CALL(mock_closure, Run()).Times(1); 307 EXPECT_CALL(mock_closure, Run()).Times(1);
307 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 308 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
308 309
309 // Call method. 310 // Call method.
310 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath), 311 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath),
311 kOldPin, 312 kOldPin,
312 kNewPin, 313 kNewPin,
313 mock_closure.GetCallback(), 314 mock_closure.GetCallback(),
314 mock_error_callback.GetCallback()); 315 mock_error_callback.GetCallback());
315 // Run the message loop. 316 // Run the message loop.
316 message_loop_.RunUntilIdle(); 317 base::RunLoop().RunUntilIdle();
317 } 318 }
318 319
319 TEST_F(ShillDeviceClientTest, Register) { 320 TEST_F(ShillDeviceClientTest, Register) {
320 const char kNetworkId[] = "networkid"; 321 const char kNetworkId[] = "networkid";
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 324
324 // Set expectations. 325 // Set expectations.
325 MockClosure mock_closure; 326 MockClosure mock_closure;
326 MockErrorCallback mock_error_callback; 327 MockErrorCallback mock_error_callback;
327 PrepareForMethodCall(shill::kRegisterFunction, 328 PrepareForMethodCall(shill::kRegisterFunction,
328 base::Bind(&ExpectStringArgument, kNetworkId), 329 base::Bind(&ExpectStringArgument, kNetworkId),
329 response.get()); 330 response.get());
330 EXPECT_CALL(mock_closure, Run()).Times(1); 331 EXPECT_CALL(mock_closure, Run()).Times(1);
331 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); 332 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
332 333
333 // Call method. 334 // Call method.
334 client_->Register(dbus::ObjectPath(kExampleDevicePath), 335 client_->Register(dbus::ObjectPath(kExampleDevicePath),
335 kNetworkId, 336 kNetworkId,
336 mock_closure.GetCallback(), 337 mock_closure.GetCallback(),
337 mock_error_callback.GetCallback()); 338 mock_error_callback.GetCallback());
338 // Run the message loop. 339 // Run the message loop.
339 message_loop_.RunUntilIdle(); 340 base::RunLoop().RunUntilIdle();
340 } 341 }
341 342
342 TEST_F(ShillDeviceClientTest, SetCarrier) { 343 TEST_F(ShillDeviceClientTest, SetCarrier) {
343 const char kCarrier[] = "carrier"; 344 const char kCarrier[] = "carrier";
344 // Create response. 345 // Create response.
345 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 346 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
346 347
347 // Set expectations. 348 // Set expectations.
348 MockClosure mock_closure; 349 MockClosure mock_closure;
349 MockErrorCallback mock_error_callback; 350 MockErrorCallback mock_error_callback;
350 PrepareForMethodCall(shill::kSetCarrierFunction, 351 PrepareForMethodCall(shill::kSetCarrierFunction,
351 base::Bind(&ExpectStringArgument, kCarrier), 352 base::Bind(&ExpectStringArgument, kCarrier),
352 response.get()); 353 response.get());
353 EXPECT_CALL(mock_closure, Run()).Times(1); 354 EXPECT_CALL(mock_closure, Run()).Times(1);
354 // Call method. 355 // Call method.
355 client_->SetCarrier(dbus::ObjectPath(kExampleDevicePath), 356 client_->SetCarrier(dbus::ObjectPath(kExampleDevicePath),
356 kCarrier, 357 kCarrier,
357 mock_closure.GetCallback(), 358 mock_closure.GetCallback(),
358 mock_error_callback.GetCallback()); 359 mock_error_callback.GetCallback());
359 // Run the message loop. 360 // Run the message loop.
360 message_loop_.RunUntilIdle(); 361 base::RunLoop().RunUntilIdle();
361 } 362 }
362 363
363 TEST_F(ShillDeviceClientTest, Reset) { 364 TEST_F(ShillDeviceClientTest, Reset) {
364 // Create response. 365 // Create response.
365 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 366 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
366 367
367 // Set expectations. 368 // Set expectations.
368 MockClosure mock_closure; 369 MockClosure mock_closure;
369 MockErrorCallback mock_error_callback; 370 MockErrorCallback mock_error_callback;
370 PrepareForMethodCall(shill::kResetFunction, 371 PrepareForMethodCall(shill::kResetFunction,
371 base::Bind(&ExpectNoArgument), 372 base::Bind(&ExpectNoArgument),
372 response.get()); 373 response.get());
373 EXPECT_CALL(mock_closure, Run()).Times(1); 374 EXPECT_CALL(mock_closure, Run()).Times(1);
374 // Call method. 375 // Call method.
375 client_->Reset(dbus::ObjectPath(kExampleDevicePath), 376 client_->Reset(dbus::ObjectPath(kExampleDevicePath),
376 mock_closure.GetCallback(), 377 mock_closure.GetCallback(),
377 mock_error_callback.GetCallback()); 378 mock_error_callback.GetCallback());
378 // Run the message loop. 379 // Run the message loop.
379 message_loop_.RunUntilIdle(); 380 base::RunLoop().RunUntilIdle();
380 } 381 }
381 382
382 } // namespace chromeos 383 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698