OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
11 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 11 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
12 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | 12 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
13 #include "chromeos/dbus/fake_bluetooth_input_client.h" | 13 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_adapter.h" | 15 #include "device/bluetooth/bluetooth_adapter.h" |
16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
17 #include "device/bluetooth/bluetooth_adapter_factory.h" | 17 #include "device/bluetooth/bluetooth_adapter_factory.h" |
18 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
19 #include "device/bluetooth/bluetooth_device_chromeos.h" | 19 #include "device/bluetooth/bluetooth_device_chromeos.h" |
20 #include "device/bluetooth/bluetooth_discovery_session.h" | 20 #include "device/bluetooth/bluetooth_discovery_session.h" |
21 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 21 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
24 | 24 |
25 using device::BluetoothAdapter; | 25 using device::BluetoothAdapter; |
26 using device::BluetoothAdapterFactory; | 26 using device::BluetoothAdapterFactory; |
| 27 using device::BluetoothAudioSink; |
27 using device::BluetoothDevice; | 28 using device::BluetoothDevice; |
28 using device::BluetoothDiscoverySession; | 29 using device::BluetoothDiscoverySession; |
29 using device::BluetoothUUID; | 30 using device::BluetoothUUID; |
30 | 31 |
31 namespace chromeos { | 32 namespace chromeos { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 class TestObserver : public BluetoothAdapter::Observer { | 36 class TestObserver : public BluetoothAdapter::Observer { |
36 public: | 37 public: |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 scoped_refptr<BluetoothAdapter> adapter_; | 140 scoped_refptr<BluetoothAdapter> adapter_; |
140 }; | 141 }; |
141 | 142 |
142 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the | 143 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the |
143 // connection info to the bound argument. | 144 // connection info to the bound argument. |
144 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, | 145 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, |
145 const BluetoothDevice::ConnectionInfo& conn_info) { | 146 const BluetoothDevice::ConnectionInfo& conn_info) { |
146 *out = conn_info; | 147 *out = conn_info; |
147 }; | 148 }; |
148 | 149 |
| 150 class FakeBluetoothProfileServiceProviderDelegate |
| 151 : public chromeos::BluetoothProfileServiceProvider::Delegate { |
| 152 public: |
| 153 FakeBluetoothProfileServiceProviderDelegate() {} |
| 154 |
| 155 // BluetoothProfileServiceProvider::Delegate: |
| 156 void Released() override {} |
| 157 |
| 158 void NewConnection(const dbus::ObjectPath&, |
| 159 scoped_ptr<dbus::FileDescriptor>, |
| 160 const BluetoothProfileServiceProvider::Delegate::Options&, |
| 161 const ConfirmationCallback&) override {} |
| 162 |
| 163 void RequestDisconnection(const dbus::ObjectPath&, |
| 164 const ConfirmationCallback&) override {} |
| 165 |
| 166 void Cancel() override {} |
| 167 }; |
| 168 |
149 } // namespace | 169 } // namespace |
150 | 170 |
151 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { | 171 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { |
152 public: | 172 public: |
153 TestPairingDelegate() | 173 TestPairingDelegate() |
154 : call_count_(0), | 174 : call_count_(0), |
155 request_pincode_count_(0), | 175 request_pincode_count_(0), |
156 request_passkey_count_(0), | 176 request_passkey_count_(0), |
157 display_pincode_count_(0), | 177 display_pincode_count_(0), |
158 display_passkey_count_(0), | 178 display_passkey_count_(0), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 QuitMessageLoop(); | 311 QuitMessageLoop(); |
292 } | 312 } |
293 | 313 |
294 void DiscoverySessionCallback( | 314 void DiscoverySessionCallback( |
295 scoped_ptr<BluetoothDiscoverySession> discovery_session) { | 315 scoped_ptr<BluetoothDiscoverySession> discovery_session) { |
296 ++callback_count_; | 316 ++callback_count_; |
297 discovery_sessions_.push_back(discovery_session.release()); | 317 discovery_sessions_.push_back(discovery_session.release()); |
298 QuitMessageLoop(); | 318 QuitMessageLoop(); |
299 } | 319 } |
300 | 320 |
| 321 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { |
| 322 ++callback_count_; |
| 323 QuitMessageLoop(); |
| 324 } |
| 325 |
| 326 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS*) { |
| 327 ++callback_count_; |
| 328 QuitMessageLoop(); |
| 329 } |
| 330 |
301 void ErrorCallback() { | 331 void ErrorCallback() { |
302 ++error_callback_count_; | 332 ++error_callback_count_; |
303 QuitMessageLoop(); | 333 QuitMessageLoop(); |
304 } | 334 } |
305 | 335 |
306 void DBusErrorCallback(const std::string& error_name, | 336 void DBusErrorCallback(const std::string& error_name, |
307 const std::string& error_message) { | 337 const std::string& error_message) { |
308 ++error_callback_count_; | 338 ++error_callback_count_; |
309 last_client_error_ = error_name; | 339 last_client_error_ = error_name; |
310 QuitMessageLoop(); | 340 QuitMessageLoop(); |
311 } | 341 } |
312 | 342 |
313 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { | 343 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { |
314 ++error_callback_count_; | 344 ++error_callback_count_; |
315 last_connect_error_ = error; | 345 last_connect_error_ = error; |
316 } | 346 } |
317 | 347 |
| 348 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { |
| 349 ++error_callback_count_; |
| 350 QuitMessageLoop(); |
| 351 } |
| 352 |
| 353 void ErrorCompletionCallback(const std::string& error_message) { |
| 354 ++error_callback_count_; |
| 355 QuitMessageLoop(); |
| 356 } |
| 357 |
318 // Call to fill the adapter_ member with a BluetoothAdapter instance. | 358 // Call to fill the adapter_ member with a BluetoothAdapter instance. |
319 void GetAdapter() { | 359 void GetAdapter() { |
320 adapter_ = new BluetoothAdapterChromeOS(); | 360 adapter_ = new BluetoothAdapterChromeOS(); |
321 ASSERT_TRUE(adapter_.get() != NULL); | 361 ASSERT_TRUE(adapter_.get() != NULL); |
322 ASSERT_TRUE(adapter_->IsInitialized()); | 362 ASSERT_TRUE(adapter_->IsInitialized()); |
323 } | 363 } |
324 | 364 |
325 // Run a discovery phase until the named device is detected, or if the named | 365 // Run a discovery phase until the named device is detected, or if the named |
326 // device is not created, the discovery process ends without finding it. | 366 // device is not created, the discovery process ends without finding it. |
327 // | 367 // |
(...skipping 2981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3309 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); | 3349 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); |
3310 BluetoothDevice::ConnectionInfo conn_info; | 3350 BluetoothDevice::ConnectionInfo conn_info; |
3311 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3351 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
3312 EXPECT_EQ(-10, conn_info.rssi); | 3352 EXPECT_EQ(-10, conn_info.rssi); |
3313 EXPECT_EQ(3, conn_info.transmit_power); | 3353 EXPECT_EQ(3, conn_info.transmit_power); |
3314 EXPECT_EQ(4, conn_info.max_transmit_power); | 3354 EXPECT_EQ(4, conn_info.max_transmit_power); |
3315 } | 3355 } |
3316 | 3356 |
3317 // Verifies Shutdown shuts down the adapter as expected. | 3357 // Verifies Shutdown shuts down the adapter as expected. |
3318 TEST_F(BluetoothChromeOSTest, Shutdown) { | 3358 TEST_F(BluetoothChromeOSTest, Shutdown) { |
3319 // Set up and adapter, power, discoverable, start discovery. | 3359 // Set up adapter. Set powered & discoverable, start discovery. |
3320 GetAdapter(); | 3360 GetAdapter(); |
3321 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3361 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, |
3322 base::Unretained(this)), | 3362 base::Unretained(this)), |
3323 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3363 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
3324 base::Unretained(this))); | 3364 base::Unretained(this))); |
3325 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3365 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, |
3326 base::Unretained(this)), | 3366 base::Unretained(this)), |
3327 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3367 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
3328 base::Unretained(this))); | 3368 base::Unretained(this))); |
3329 adapter_->StartDiscoverySession( | 3369 adapter_->StartDiscoverySession( |
3330 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 3370 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
3331 base::Unretained(this)), | 3371 base::Unretained(this)), |
3332 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3372 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
3333 base::Unretained(this))); | 3373 base::Unretained(this))); |
3334 base::MessageLoop::current()->Run(); | 3374 base::MessageLoop::current()->Run(); |
3335 ASSERT_EQ(3, callback_count_); | 3375 ASSERT_EQ(3, callback_count_); |
3336 ASSERT_EQ(0, error_callback_count_); | 3376 ASSERT_EQ(0, error_callback_count_); |
3337 callback_count_ = 0; | 3377 callback_count_ = 0; |
3338 | 3378 |
| 3379 TestPairingDelegate pairing_delegate; |
| 3380 adapter_->AddPairingDelegate( |
| 3381 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3382 |
3339 // Validate running adapter state. | 3383 // Validate running adapter state. |
3340 EXPECT_NE("", adapter_->GetAddress()); | 3384 EXPECT_NE("", adapter_->GetAddress()); |
3341 EXPECT_NE("", adapter_->GetName()); | 3385 EXPECT_NE("", adapter_->GetName()); |
3342 EXPECT_TRUE(adapter_->IsInitialized()); | 3386 EXPECT_TRUE(adapter_->IsInitialized()); |
3343 EXPECT_TRUE(adapter_->IsPresent()); | 3387 EXPECT_TRUE(adapter_->IsPresent()); |
3344 EXPECT_TRUE(adapter_->IsPowered()); | 3388 EXPECT_TRUE(adapter_->IsPowered()); |
3345 EXPECT_TRUE(adapter_->IsDiscoverable()); | 3389 EXPECT_TRUE(adapter_->IsDiscoverable()); |
3346 EXPECT_TRUE(adapter_->IsDiscovering()); | 3390 EXPECT_TRUE(adapter_->IsDiscovering()); |
3347 EXPECT_EQ(2U, adapter_->GetDevices().size()); | 3391 EXPECT_EQ(2U, adapter_->GetDevices().size()); |
3348 EXPECT_NE(nullptr, adapter_->GetDevice( | 3392 EXPECT_NE(nullptr, adapter_->GetDevice( |
3349 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 3393 FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
3350 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | 3394 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
3351 adapter_.get())->object_path()); | 3395 adapter_.get())->object_path()); |
3352 | 3396 |
3353 // Shutdown | 3397 // Shutdown |
3354 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())->Shutdown(); | 3398 adapter_->Shutdown(); |
3355 | 3399 |
3356 // Validate post shutdown state. | 3400 // Validate post shutdown state by calling all BluetoothAdapterChromeOS |
| 3401 // members, in declaration order: |
| 3402 |
| 3403 adapter_->Shutdown(); |
| 3404 // DeleteOnCorrectThread omitted as we don't want to delete in this test. |
| 3405 { |
| 3406 TestObserver observer(adapter_); // Calls AddObserver |
| 3407 } // TestObserver::~TestObserver calls RemoveObserver. |
3357 EXPECT_EQ("", adapter_->GetAddress()); | 3408 EXPECT_EQ("", adapter_->GetAddress()); |
3358 EXPECT_EQ("", adapter_->GetName()); | 3409 EXPECT_EQ("", adapter_->GetName()); |
| 3410 |
| 3411 adapter_->SetName( |
| 3412 "", base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
| 3413 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3414 base::Unretained(this))); |
| 3415 EXPECT_EQ(0, callback_count_); |
| 3416 EXPECT_EQ(1, error_callback_count_--) << "SetName error"; |
| 3417 |
3359 EXPECT_TRUE(adapter_->IsInitialized()); | 3418 EXPECT_TRUE(adapter_->IsInitialized()); |
3360 EXPECT_FALSE(adapter_->IsPresent()); | 3419 EXPECT_FALSE(adapter_->IsPresent()); |
3361 EXPECT_FALSE(adapter_->IsPowered()); | 3420 EXPECT_FALSE(adapter_->IsPowered()); |
3362 EXPECT_FALSE(adapter_->IsDiscoverable()); | |
3363 EXPECT_FALSE(adapter_->IsDiscovering()); | |
3364 EXPECT_EQ(0U, adapter_->GetDevices().size()); | |
3365 EXPECT_EQ(nullptr, adapter_->GetDevice( | |
3366 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | |
3367 EXPECT_EQ(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | |
3368 adapter_.get())->object_path()); | |
3369 | 3421 |
3370 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3422 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, |
3371 base::Unretained(this)), | 3423 base::Unretained(this)), |
3372 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3424 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
3373 base::Unretained(this))); | 3425 base::Unretained(this))); |
| 3426 EXPECT_EQ(0, callback_count_); |
| 3427 EXPECT_EQ(1, error_callback_count_--) << "SetPowered error"; |
| 3428 |
| 3429 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 3430 |
3374 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3431 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, |
3375 base::Unretained(this)), | 3432 base::Unretained(this)), |
3376 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3433 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
3377 base::Unretained(this))); | 3434 base::Unretained(this))); |
| 3435 EXPECT_EQ(0, callback_count_); |
| 3436 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; |
| 3437 |
| 3438 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 3439 // CreateRfcommService will DCHECK after Shutdown(). |
| 3440 // CreateL2capService will DCHECK after Shutdown(). |
| 3441 |
| 3442 BluetoothAudioSink::Options audio_sink_options; |
| 3443 adapter_->RegisterAudioSink( |
| 3444 audio_sink_options, |
| 3445 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
| 3446 base::Unretained(this)), |
| 3447 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, |
| 3448 base::Unretained(this))); |
| 3449 EXPECT_EQ(0, callback_count_); |
| 3450 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
| 3451 |
| 3452 BluetoothAdapterChromeOS* adapter_chrome_os = |
| 3453 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
| 3454 EXPECT_EQ(NULL, adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); |
| 3455 |
| 3456 // Notify methods presume objects exist that are owned by the adapter and |
| 3457 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, |
| 3458 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 3459 // NotifyDeviceChanged |
| 3460 // NotifyGattServiceAdded |
| 3461 // NotifyGattServiceRemoved |
| 3462 // NotifyGattServiceChanged |
| 3463 // NotifyGattDiscoveryComplete |
| 3464 // NotifyGattCharacteristicAdded |
| 3465 // NotifyGattCharacteristicRemoved |
| 3466 // NotifyGattDescriptorAdded |
| 3467 // NotifyGattDescriptorRemoved |
| 3468 // NotifyGattCharacteristicValueChanged |
| 3469 // NotifyGattDescriptorValueChanged |
| 3470 |
| 3471 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); |
| 3472 |
| 3473 FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
| 3474 adapter_chrome_os->UseProfile( |
| 3475 BluetoothUUID(), dbus::ObjectPath(""), |
| 3476 BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 3477 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3478 base::Unretained(this)), |
| 3479 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3480 base::Unretained(this))); |
| 3481 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
| 3482 EXPECT_EQ(0, error_callback_count_) << "UseProfile error"; |
| 3483 |
| 3484 adapter_chrome_os->ReleaseProfile(BluetoothUUID()); |
| 3485 |
| 3486 // Protected and private methods: |
| 3487 |
| 3488 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); |
| 3489 |
| 3490 // BluetoothAdapterClient::Observer methods omitted, dbus will be shutdown. |
| 3491 // BluetoothDeviceClient::Observer methods omitted, dbus will be shutdown. |
| 3492 // BluetoothInputClient::Observer methods omitted, dbus will be shutdown. |
| 3493 // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown, |
| 3494 // with the exception of Released. |
| 3495 adapter_chrome_os->Released(); |
| 3496 |
| 3497 adapter_chrome_os->OnRegisterAgent(); |
| 3498 adapter_chrome_os->OnRegisterAgentError("", ""); |
| 3499 adapter_chrome_os->OnRequestDefaultAgent(); |
| 3500 adapter_chrome_os->OnRequestDefaultAgentError("", ""); |
| 3501 |
| 3502 adapter_chrome_os->OnRegisterAudioSink( |
| 3503 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
| 3504 base::Unretained(this)), |
| 3505 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, |
| 3506 base::Unretained(this)), |
| 3507 scoped_refptr<device::BluetoothAudioSink>()); |
| 3508 EXPECT_EQ(0, callback_count_); |
| 3509 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
| 3510 |
| 3511 // GetPairing will DCHECK after Shutdown(). |
| 3512 // SetAdapter will DCHECK after Shutdown(). |
| 3513 // SetDefaultAdapterName will DCHECK after Shutdown(). |
| 3514 // RemoveAdapter will DCHECK after Shutdown(). |
| 3515 adapter_chrome_os->PoweredChanged(false); |
| 3516 adapter_chrome_os->DiscoverableChanged(false); |
| 3517 adapter_chrome_os->DiscoveringChanged(false); |
| 3518 adapter_chrome_os->PresentChanged(false); |
| 3519 |
| 3520 adapter_chrome_os->OnSetDiscoverable( |
| 3521 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
| 3522 base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
| 3523 true); |
| 3524 EXPECT_EQ(0, callback_count_) << "OnSetDiscoverable error"; |
| 3525 EXPECT_EQ(1, error_callback_count_--) << "OnSetDiscoverable error"; |
| 3526 |
| 3527 adapter_chrome_os->OnPropertyChangeCompleted( |
| 3528 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
| 3529 base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
| 3530 true); |
| 3531 EXPECT_EQ(0, callback_count_) << "OnPropertyChangeCompleted error"; |
| 3532 EXPECT_EQ(1, error_callback_count_--) << "OnPropertyChangeCompleted error"; |
| 3533 |
| 3534 adapter_chrome_os->AddDiscoverySession( |
| 3535 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
| 3536 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3537 base::Unretained(this))); |
| 3538 EXPECT_EQ(0, callback_count_) << "AddDiscoverySession error"; |
| 3539 EXPECT_EQ(1, error_callback_count_--) << "AddDiscoverySession error"; |
| 3540 |
| 3541 adapter_chrome_os->RemoveDiscoverySession( |
| 3542 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
| 3543 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3544 base::Unretained(this))); |
| 3545 EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error"; |
| 3546 EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error"; |
| 3547 |
| 3548 // OnStartDiscovery will DCHECK after Shutdown(). |
| 3549 |
| 3550 adapter_chrome_os->OnStartDiscoveryError( |
| 3551 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
| 3552 base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
| 3553 "", ""); |
| 3554 EXPECT_EQ(0, callback_count_) << "OnStartDiscoveryError error"; |
| 3555 EXPECT_EQ(1, error_callback_count_--) << "OnStartDiscoveryError error"; |
| 3556 |
| 3557 // OnStopDiscovery will fail after Shutdown(). |
| 3558 |
| 3559 adapter_chrome_os->OnStopDiscoveryError( |
| 3560 base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
| 3561 "", ""); |
| 3562 EXPECT_EQ(0, callback_count_) << "OnStopDiscoveryError error"; |
| 3563 EXPECT_EQ(1, error_callback_count_--) << "OnStopDiscoveryError error"; |
| 3564 |
| 3565 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require |
| 3566 // UseProfile to be set first, do so again here just before calling them. |
| 3567 adapter_chrome_os->UseProfile( |
| 3568 BluetoothUUID(), dbus::ObjectPath(""), |
| 3569 BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 3570 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3571 base::Unretained(this)), |
| 3572 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3573 base::Unretained(this))); |
| 3574 |
| 3575 adapter_chrome_os->OnRegisterProfile( |
| 3576 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, |
| 3577 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3578 base::Unretained(this)), |
| 3579 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3580 base::Unretained(this))); |
| 3581 EXPECT_EQ(1, callback_count_--) << "OnRegisterProfile error"; |
| 3582 EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfile error"; |
| 3583 |
| 3584 adapter_chrome_os->SetProfileDelegate( |
| 3585 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, |
| 3586 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3587 base::Unretained(this)), |
| 3588 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3589 base::Unretained(this))); |
| 3590 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; |
| 3591 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; |
| 3592 |
| 3593 adapter_chrome_os->OnRegisterProfileError( |
| 3594 BluetoothUUID(), |
| 3595 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3596 base::Unretained(this)), |
| 3597 "", ""); |
| 3598 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; |
| 3599 EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfileError error"; |
| 3600 |
| 3601 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); |
| 3602 |
| 3603 // From BluetoothAdapater: |
| 3604 |
3378 adapter_->StartDiscoverySession( | 3605 adapter_->StartDiscoverySession( |
3379 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 3606 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
3380 base::Unretained(this)), | 3607 base::Unretained(this)), |
3381 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3608 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
3382 base::Unretained(this))); | 3609 base::Unretained(this))); |
3383 ASSERT_EQ(0, callback_count_); | 3610 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
3384 ASSERT_EQ(3, error_callback_count_); | 3611 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; |
| 3612 |
| 3613 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 3614 EXPECT_EQ(nullptr, adapter_->GetDevice( |
| 3615 FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3616 TestPairingDelegate pairing_delegate2; |
| 3617 adapter_->AddPairingDelegate( |
| 3618 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3619 adapter_->RemovePairingDelegate(&pairing_delegate2); |
3385 } | 3620 } |
3386 | 3621 |
3387 } // namespace chromeos | 3622 } // namespace chromeos |
OLD | NEW |