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

Side by Side Diff: device/bluetooth/bluez/bluetooth_adapter_profile_bluez_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
11 #include "device/bluetooth/bluetooth_adapter.h" 12 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_adapter_factory.h" 13 #include "device/bluetooth/bluetooth_adapter_factory.h"
13 #include "device/bluetooth/bluetooth_uuid.h" 14 #include "device/bluetooth/bluetooth_uuid.h"
14 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 15 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
15 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" 16 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h"
16 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
17 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
18 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" 19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
19 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
20 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" 21 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h"
(...skipping 30 matching lines...) Expand all
51 std::unique_ptr<bluez::BluetoothDeviceClient>( 52 std::unique_ptr<bluez::BluetoothDeviceClient>(
52 new bluez::FakeBluetoothDeviceClient)); 53 new bluez::FakeBluetoothDeviceClient));
53 dbus_setter->SetBluetoothProfileManagerClient( 54 dbus_setter->SetBluetoothProfileManagerClient(
54 std::unique_ptr<bluez::BluetoothProfileManagerClient>( 55 std::unique_ptr<bluez::BluetoothProfileManagerClient>(
55 new bluez::FakeBluetoothProfileManagerClient)); 56 new bluez::FakeBluetoothProfileManagerClient));
56 57
57 // Grab a pointer to the adapter. 58 // Grab a pointer to the adapter.
58 device::BluetoothAdapterFactory::GetAdapter( 59 device::BluetoothAdapterFactory::GetAdapter(
59 base::Bind(&BluetoothAdapterProfileBlueZTest::AdapterCallback, 60 base::Bind(&BluetoothAdapterProfileBlueZTest::AdapterCallback,
60 base::Unretained(this))); 61 base::Unretained(this)));
61 base::MessageLoop::current()->Run(); 62 base::RunLoop().Run();
62 ASSERT_TRUE(adapter_.get() != nullptr); 63 ASSERT_TRUE(adapter_.get() != nullptr);
63 ASSERT_TRUE(adapter_->IsInitialized()); 64 ASSERT_TRUE(adapter_->IsInitialized());
64 ASSERT_TRUE(adapter_->IsPresent()); 65 ASSERT_TRUE(adapter_->IsPresent());
65 66
66 // Turn on the adapter. 67 // Turn on the adapter.
67 adapter_->SetPowered(true, base::Bind(&base::DoNothing), 68 adapter_->SetPowered(true, base::Bind(&base::DoNothing),
68 base::Bind(&base::DoNothing)); 69 base::Bind(&base::DoNothing));
69 ASSERT_TRUE(adapter_->IsPowered()); 70 ASSERT_TRUE(adapter_->IsPowered());
70 } 71 }
71 72
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 175
175 options.require_authentication.reset(new bool(false)); 176 options.require_authentication.reset(new bool(false));
176 177
177 BluetoothAdapterProfileBlueZ::Register( 178 BluetoothAdapterProfileBlueZ::Register(
178 uuid, options, 179 uuid, options,
179 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback, 180 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback,
180 base::Unretained(this)), 181 base::Unretained(this)),
181 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 182 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
182 base::Unretained(this))); 183 base::Unretained(this)));
183 184
184 message_loop_.RunUntilIdle(); 185 base::RunLoop().RunUntilIdle();
185 186
186 EXPECT_TRUE(profile_); 187 EXPECT_TRUE(profile_);
187 EXPECT_EQ(1U, success_callback_count_); 188 EXPECT_EQ(1U, success_callback_count_);
188 EXPECT_EQ(0U, error_callback_count_); 189 EXPECT_EQ(0U, error_callback_count_);
189 190
190 EXPECT_EQ(0U, profile_->DelegateCount()); 191 EXPECT_EQ(0U, profile_->DelegateCount());
191 192
192 profile_->SetDelegate(fake_delegate_paired_.device_path_, 193 profile_->SetDelegate(fake_delegate_paired_.device_path_,
193 &fake_delegate_paired_); 194 &fake_delegate_paired_);
194 195
(...skipping 16 matching lines...) Expand all
211 212
212 options.require_authentication.reset(new bool(false)); 213 options.require_authentication.reset(new bool(false));
213 214
214 BluetoothAdapterProfileBlueZ::Register( 215 BluetoothAdapterProfileBlueZ::Register(
215 uuid, options, 216 uuid, options,
216 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback, 217 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback,
217 base::Unretained(this)), 218 base::Unretained(this)),
218 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 219 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
219 base::Unretained(this))); 220 base::Unretained(this)));
220 221
221 message_loop_.RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
222 223
223 EXPECT_TRUE(profile_); 224 EXPECT_TRUE(profile_);
224 EXPECT_EQ(1U, success_callback_count_); 225 EXPECT_EQ(1U, success_callback_count_);
225 EXPECT_EQ(0U, error_callback_count_); 226 EXPECT_EQ(0U, error_callback_count_);
226 227
227 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 228 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
228 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath), 229 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath),
229 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 230 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
230 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback, 231 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
231 base::Unretained(this)), 232 base::Unretained(this)),
232 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 233 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
233 base::Unretained(this))); 234 base::Unretained(this)));
234 235
235 message_loop_.RunUntilIdle(); 236 base::RunLoop().RunUntilIdle();
236 237
237 EXPECT_EQ(1U, success_callback_count_); 238 EXPECT_EQ(1U, success_callback_count_);
238 EXPECT_EQ(1U, error_callback_count_); 239 EXPECT_EQ(1U, error_callback_count_);
239 240
240 EXPECT_EQ(0U, fake_delegate_paired_.connections_); 241 EXPECT_EQ(0U, fake_delegate_paired_.connections_);
241 } 242 }
242 243
243 TEST_F(BluetoothAdapterProfileBlueZTest, Routing) { 244 TEST_F(BluetoothAdapterProfileBlueZTest, Routing) {
244 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); 245 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid);
245 bluez::BluetoothProfileManagerClient::Options options; 246 bluez::BluetoothProfileManagerClient::Options options;
246 247
247 options.require_authentication.reset(new bool(false)); 248 options.require_authentication.reset(new bool(false));
248 249
249 BluetoothAdapterProfileBlueZ::Register( 250 BluetoothAdapterProfileBlueZ::Register(
250 uuid, options, 251 uuid, options,
251 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback, 252 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback,
252 base::Unretained(this)), 253 base::Unretained(this)),
253 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 254 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
254 base::Unretained(this))); 255 base::Unretained(this)));
255 256
256 message_loop_.RunUntilIdle(); 257 base::RunLoop().RunUntilIdle();
257 258
258 ASSERT_TRUE(profile_); 259 ASSERT_TRUE(profile_);
259 ASSERT_EQ(1U, success_callback_count_); 260 ASSERT_EQ(1U, success_callback_count_);
260 ASSERT_EQ(0U, error_callback_count_); 261 ASSERT_EQ(0U, error_callback_count_);
261 262
262 profile_->SetDelegate(fake_delegate_paired_.device_path_, 263 profile_->SetDelegate(fake_delegate_paired_.device_path_,
263 &fake_delegate_paired_); 264 &fake_delegate_paired_);
264 profile_->SetDelegate(fake_delegate_autopair_.device_path_, 265 profile_->SetDelegate(fake_delegate_autopair_.device_path_,
265 &fake_delegate_autopair_); 266 &fake_delegate_autopair_);
266 profile_->SetDelegate(fake_delegate_listen_.device_path_, 267 profile_->SetDelegate(fake_delegate_listen_.device_path_,
267 &fake_delegate_listen_); 268 &fake_delegate_listen_);
268 269
269 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 270 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
270 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath), 271 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath),
271 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 272 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
272 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback, 273 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
273 base::Unretained(this)), 274 base::Unretained(this)),
274 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 275 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
275 base::Unretained(this))); 276 base::Unretained(this)));
276 277
277 message_loop_.RunUntilIdle(); 278 base::RunLoop().RunUntilIdle();
278 279
279 EXPECT_EQ(2U, success_callback_count_); 280 EXPECT_EQ(2U, success_callback_count_);
280 EXPECT_EQ(0U, error_callback_count_); 281 EXPECT_EQ(0U, error_callback_count_);
281 282
282 EXPECT_EQ(1U, fake_delegate_paired_.connections_); 283 EXPECT_EQ(1U, fake_delegate_paired_.connections_);
283 284
284 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 285 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
285 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath), 286 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath),
286 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 287 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
287 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback, 288 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
288 base::Unretained(this)), 289 base::Unretained(this)),
289 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 290 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
290 base::Unretained(this))); 291 base::Unretained(this)));
291 292
292 message_loop_.RunUntilIdle(); 293 base::RunLoop().RunUntilIdle();
293 294
294 EXPECT_EQ(3U, success_callback_count_); 295 EXPECT_EQ(3U, success_callback_count_);
295 EXPECT_EQ(0U, error_callback_count_); 296 EXPECT_EQ(0U, error_callback_count_);
296 297
297 EXPECT_EQ(1U, fake_delegate_autopair_.connections_); 298 EXPECT_EQ(1U, fake_delegate_autopair_.connections_);
298 299
299 // Incoming connections look the same from BlueZ. 300 // Incoming connections look the same from BlueZ.
300 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 301 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
301 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath), 302 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath),
302 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 303 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
303 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback, 304 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
304 base::Unretained(this)), 305 base::Unretained(this)),
305 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback, 306 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
306 base::Unretained(this))); 307 base::Unretained(this)));
307 308
308 message_loop_.RunUntilIdle(); 309 base::RunLoop().RunUntilIdle();
309 310
310 EXPECT_EQ(4U, success_callback_count_); 311 EXPECT_EQ(4U, success_callback_count_);
311 EXPECT_EQ(0U, error_callback_count_); 312 EXPECT_EQ(0U, error_callback_count_);
312 313
313 EXPECT_EQ(1U, fake_delegate_listen_.connections_); 314 EXPECT_EQ(1U, fake_delegate_listen_.connections_);
314 } 315 }
315 316
316 TEST_F(BluetoothAdapterProfileBlueZTest, SimultaneousRegister) { 317 TEST_F(BluetoothAdapterProfileBlueZTest, SimultaneousRegister) {
317 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); 318 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid);
318 bluez::BluetoothProfileManagerClient::Options options; 319 bluez::BluetoothProfileManagerClient::Options options;
(...skipping 13 matching lines...) Expand all
332 base::Unretained(this))); 333 base::Unretained(this)));
333 334
334 adapter->UseProfile( 335 adapter->UseProfile(
335 uuid, fake_delegate_autopair_.device_path_, options, 336 uuid, fake_delegate_autopair_.device_path_, options,
336 &fake_delegate_autopair_, 337 &fake_delegate_autopair_,
337 base::Bind(&BluetoothAdapterProfileBlueZTest::MatchedProfileCallback, 338 base::Bind(&BluetoothAdapterProfileBlueZTest::MatchedProfileCallback,
338 base::Unretained(this)), 339 base::Unretained(this)),
339 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback, 340 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
340 base::Unretained(this))); 341 base::Unretained(this)));
341 342
342 message_loop_.RunUntilIdle(); 343 base::RunLoop().RunUntilIdle();
343 344
344 EXPECT_TRUE(profile_user_ptr_); 345 EXPECT_TRUE(profile_user_ptr_);
345 EXPECT_EQ(2U, success_callback_count_); 346 EXPECT_EQ(2U, success_callback_count_);
346 EXPECT_EQ(0U, error_callback_count_); 347 EXPECT_EQ(0U, error_callback_count_);
347 348
348 adapter->ReleaseProfile(fake_delegate_paired_.device_path_, 349 adapter->ReleaseProfile(fake_delegate_paired_.device_path_,
349 profile_user_ptr_); 350 profile_user_ptr_);
350 adapter->ReleaseProfile(fake_delegate_autopair_.device_path_, 351 adapter->ReleaseProfile(fake_delegate_autopair_.device_path_,
351 profile_user_ptr_); 352 profile_user_ptr_);
352 353
353 message_loop_.RunUntilIdle(); 354 base::RunLoop().RunUntilIdle();
354 } 355 }
355 356
356 TEST_F(BluetoothAdapterProfileBlueZTest, SimultaneousRegisterFail) { 357 TEST_F(BluetoothAdapterProfileBlueZTest, SimultaneousRegisterFail) {
357 BluetoothUUID uuid( 358 BluetoothUUID uuid(
358 bluez::FakeBluetoothProfileManagerClient::kUnregisterableUuid); 359 bluez::FakeBluetoothProfileManagerClient::kUnregisterableUuid);
359 bluez::BluetoothProfileManagerClient::Options options; 360 bluez::BluetoothProfileManagerClient::Options options;
360 BluetoothAdapterBlueZ* adapter = 361 BluetoothAdapterBlueZ* adapter =
361 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); 362 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
362 363
363 options.require_authentication.reset(new bool(false)); 364 options.require_authentication.reset(new bool(false));
364 365
365 success_callback_count_ = 0; 366 success_callback_count_ = 0;
366 error_callback_count_ = 0; 367 error_callback_count_ = 0;
367 368
368 adapter->UseProfile( 369 adapter->UseProfile(
369 uuid, fake_delegate_paired_.device_path_, options, &fake_delegate_paired_, 370 uuid, fake_delegate_paired_.device_path_, options, &fake_delegate_paired_,
370 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileUserSuccessCallback, 371 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileUserSuccessCallback,
371 base::Unretained(this)), 372 base::Unretained(this)),
372 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback, 373 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
373 base::Unretained(this))); 374 base::Unretained(this)));
374 375
375 adapter->UseProfile( 376 adapter->UseProfile(
376 uuid, fake_delegate_autopair_.device_path_, options, 377 uuid, fake_delegate_autopair_.device_path_, options,
377 &fake_delegate_autopair_, 378 &fake_delegate_autopair_,
378 base::Bind(&BluetoothAdapterProfileBlueZTest::MatchedProfileCallback, 379 base::Bind(&BluetoothAdapterProfileBlueZTest::MatchedProfileCallback,
379 base::Unretained(this)), 380 base::Unretained(this)),
380 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback, 381 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
381 base::Unretained(this))); 382 base::Unretained(this)));
382 383
383 message_loop_.RunUntilIdle(); 384 base::RunLoop().RunUntilIdle();
384 385
385 EXPECT_FALSE(profile_user_ptr_); 386 EXPECT_FALSE(profile_user_ptr_);
386 EXPECT_EQ(0U, success_callback_count_); 387 EXPECT_EQ(0U, success_callback_count_);
387 EXPECT_EQ(2U, error_callback_count_); 388 EXPECT_EQ(2U, error_callback_count_);
388 } 389 }
389 390
390 } // namespace bluez 391 } // namespace bluez
OLDNEW
« no previous file with comments | « device/battery/battery_status_manager_linux.cc ('k') | device/bluetooth/bluez/bluetooth_advertisement_bluez_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698