Index: device/bluetooth/bluetooth_chromeos_unittest.cc |
diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc |
index 6ce931b4974ddf19fd3bf7cc4c023a946bafe1ee..c0e9661509abc9ed2ad5a0ff7c7b72b860837e7a 100644 |
--- a/device/bluetooth/bluetooth_chromeos_unittest.cc |
+++ b/device/bluetooth/bluetooth_chromeos_unittest.cc |
@@ -24,6 +24,7 @@ |
using device::BluetoothAdapter; |
using device::BluetoothAdapterFactory; |
+using device::BluetoothAudioSink; |
using device::BluetoothDevice; |
using device::BluetoothDiscoverySession; |
using device::BluetoothUUID; |
@@ -146,6 +147,25 @@ void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, |
*out = conn_info; |
}; |
+class FakeBluetoothProfileServiceProviderDelegate |
+ : public chromeos::BluetoothProfileServiceProvider::Delegate { |
+ public: |
+ FakeBluetoothProfileServiceProviderDelegate() {} |
+ |
+ // BluetoothProfileServiceProvider::Delegate: |
+ void Released() override {} |
+ |
+ void NewConnection(const dbus::ObjectPath&, |
+ scoped_ptr<dbus::FileDescriptor>, |
+ const BluetoothProfileServiceProvider::Delegate::Options&, |
+ const ConfirmationCallback&) override {} |
+ |
+ void RequestDisconnection(const dbus::ObjectPath&, |
+ const ConfirmationCallback&) override {} |
+ |
+ void Cancel() override {} |
+}; |
+ |
} // namespace |
class TestPairingDelegate : public BluetoothDevice::PairingDelegate { |
@@ -298,6 +318,16 @@ class BluetoothChromeOSTest : public testing::Test { |
QuitMessageLoop(); |
} |
+ void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { |
+ ++callback_count_; |
+ QuitMessageLoop(); |
+ } |
+ |
+ void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS*) { |
+ ++callback_count_; |
+ QuitMessageLoop(); |
+ } |
+ |
void ErrorCallback() { |
++error_callback_count_; |
QuitMessageLoop(); |
@@ -315,6 +345,16 @@ class BluetoothChromeOSTest : public testing::Test { |
last_connect_error_ = error; |
} |
+ void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { |
+ ++error_callback_count_; |
+ QuitMessageLoop(); |
+ } |
+ |
+ void ErrorCompletionCallback(const std::string& error_message) { |
+ ++error_callback_count_; |
+ QuitMessageLoop(); |
+ } |
+ |
// Call to fill the adapter_ member with a BluetoothAdapter instance. |
void GetAdapter() { |
adapter_ = new BluetoothAdapterChromeOS(); |
@@ -3316,7 +3356,7 @@ TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { |
// Verifies Shutdown shuts down the adapter as expected. |
TEST_F(BluetoothChromeOSTest, Shutdown) { |
- // Set up and adapter, power, discoverable, start discovery. |
+ // Set up adapter. Set powered & discoverable, start discovery. |
GetAdapter(); |
adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, |
base::Unretained(this)), |
@@ -3336,6 +3376,10 @@ TEST_F(BluetoothChromeOSTest, Shutdown) { |
ASSERT_EQ(0, error_callback_count_); |
callback_count_ = 0; |
+ TestPairingDelegate pairing_delegate; |
+ adapter_->AddPairingDelegate( |
+ &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
+ |
// Validate running adapter state. |
EXPECT_NE("", adapter_->GetAddress()); |
EXPECT_NE("", adapter_->GetName()); |
@@ -3351,37 +3395,207 @@ TEST_F(BluetoothChromeOSTest, Shutdown) { |
adapter_.get())->object_path()); |
// Shutdown |
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get())->Shutdown(); |
+ adapter_->Shutdown(); |
+ |
+ // Validate post shutdown state by calling all BluetoothAdapterChromeOS |
+ // members, in declaration order: |
- // Validate post shutdown state. |
+ adapter_->Shutdown(); |
+ // DeleteOnCorrectThread omitted as we don't want to delete in this test. |
+ { |
+ TestObserver observer(adapter_); // Calls AddObserver |
+ } // TestObserver::~TestObserver calls RemoveObserver. |
EXPECT_EQ("", adapter_->GetAddress()); |
EXPECT_EQ("", adapter_->GetName()); |
+ |
+ adapter_->SetName( |
+ "", base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_); |
+ EXPECT_EQ(1, error_callback_count_) << "SetName error"; |
+ error_callback_count_ = 0; |
+ |
EXPECT_TRUE(adapter_->IsInitialized()); |
EXPECT_FALSE(adapter_->IsPresent()); |
EXPECT_FALSE(adapter_->IsPowered()); |
- EXPECT_FALSE(adapter_->IsDiscoverable()); |
- EXPECT_FALSE(adapter_->IsDiscovering()); |
- EXPECT_EQ(0U, adapter_->GetDevices().size()); |
- EXPECT_EQ(nullptr, adapter_->GetDevice( |
- FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
- EXPECT_EQ(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
- adapter_.get())->object_path()); |
adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, |
base::Unretained(this)), |
base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_); |
+ EXPECT_EQ(1, error_callback_count_) << "SetPowered error"; |
+ error_callback_count_ = 0; |
+ |
+ EXPECT_FALSE(adapter_->IsDiscoverable()); |
+ |
adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, |
base::Unretained(this)), |
base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_); |
+ EXPECT_EQ(1, error_callback_count_) << "SetDiscoverable error"; |
+ error_callback_count_ = 0; |
+ |
+ EXPECT_FALSE(adapter_->IsDiscovering()); |
+ // CreateRfcommService will DCHECK after Shutdown(). |
+ // CreateL2capService will DCHECK after Shutdown(). |
+ |
+ BluetoothAudioSink::Options audio_sink_options; |
+ adapter_->RegisterAudioSink( |
+ audio_sink_options, |
+ base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_); |
+ EXPECT_EQ(1, error_callback_count_) << "RegisterAudioSink error"; |
+ error_callback_count_ = 0; |
+ |
+ BluetoothAdapterChromeOS* adapter_chrome_os = |
+ static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
+ EXPECT_EQ(NULL, adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); |
+ |
+ // Notify methods presume objects exist that are owned by the adapter and |
+ // destroyed in Shutdown(). Mocks are not attempted here that won't exist, |
+ // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); |
+ // NotifyDeviceChanged |
+ // NotifyGattServiceAdded |
+ // NotifyGattServiceRemoved |
+ // NotifyGattServiceChanged |
+ // NotifyGattDiscoveryComplete |
+ // NotifyGattCharacteristicAdded |
+ // NotifyGattCharacteristicRemoved |
+ // NotifyGattDescriptorAdded |
+ // NotifyGattDescriptorRemoved |
+ // NotifyGattCharacteristicValueChanged |
+ // NotifyGattDescriptorValueChanged |
+ |
+ EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); |
+ |
+ FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
+ adapter_chrome_os->UseProfile( |
+ BluetoothUUID(), dbus::ObjectPath(""), |
+ BluetoothProfileManagerClient::Options(), &profile_delegate, |
+ base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
+ EXPECT_EQ(0, error_callback_count_) << "UseProfile error"; |
+ error_callback_count_ = 0; |
+ |
+ adapter_chrome_os->ReleaseProfile(BluetoothUUID()); |
+ |
+ // Protected and private methods: |
+ |
+ adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); |
+ |
+ // BluetoothAdapterClient::Observer methods omitted, dbus will be shutdown. |
+ // BluetoothDeviceClient::Observer methods omitted, dbus will be shutdown. |
+ // BluetoothInputClient::Observer methods omitted, dbus will be shutdown. |
+ // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown, |
+ // with the exception of Released. |
+ adapter_chrome_os->Released(); |
+ |
+ adapter_chrome_os->OnRegisterAgent(); |
+ adapter_chrome_os->OnRegisterAgentError("", ""); |
+ adapter_chrome_os->OnRequestDefaultAgent(); |
+ adapter_chrome_os->OnRequestDefaultAgentError("", ""); |
+ |
+ scoped_refptr<device::BluetoothAudioSink> audio_sink; |
+ adapter_chrome_os->OnRegisterAudioSink( |
+ base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
+ base::Unretained(this)), |
+ audio_sink); |
+ EXPECT_EQ(0, callback_count_); |
+ EXPECT_EQ(0, error_callback_count_) << "RegisterAudioSink error"; |
+ |
+ // GetPairing will DCHECK after Shutdown(). |
+ // SetAdapter will DCHECK after Shutdown(). |
+ // SetDefaultAdapterName will DCHECK after Shutdown(). |
+ // RemoveAdapter will DCHECK after Shutdown(). |
+ adapter_chrome_os->PoweredChanged(false); |
+ adapter_chrome_os->DiscoverableChanged(false); |
+ adapter_chrome_os->DiscoveringChanged(false); |
+ adapter_chrome_os->PresentChanged(false); |
+ |
+ adapter_chrome_os->OnSetDiscoverable( |
+ base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
+ true); |
+ EXPECT_EQ(0, callback_count_) << "OnSetDiscoverable error"; |
+ EXPECT_EQ(1, error_callback_count_) << "OnSetDiscoverable error"; |
+ error_callback_count_ = 0; |
+ |
+ adapter_chrome_os->OnPropertyChangeCompleted( |
+ base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
+ true); |
+ EXPECT_EQ(0, callback_count_) << "OnPropertyChangeCompleted error"; |
+ EXPECT_EQ(1, error_callback_count_) << "OnPropertyChangeCompleted error"; |
+ error_callback_count_ = 0; |
+ |
+ adapter_chrome_os->AddDiscoverySession( |
+ base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_) << "AddDiscoverySession error"; |
+ EXPECT_EQ(1, error_callback_count_) << "AddDiscoverySession error"; |
+ error_callback_count_ = 0; |
+ |
+ adapter_chrome_os->RemoveDiscoverySession( |
+ base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error"; |
+ EXPECT_EQ(1, error_callback_count_) << "RemoveDiscoverySession error"; |
+ error_callback_count_ = 0; |
+ |
+ // OnStartDiscovery will DCHECK after Shutdown(). |
+ |
+ adapter_chrome_os->OnStartDiscoveryError( |
+ base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
+ "", ""); |
+ EXPECT_EQ(0, callback_count_) << "OnStartDiscoveryError error"; |
+ EXPECT_EQ(1, error_callback_count_) << "OnStartDiscoveryError error"; |
+ error_callback_count_ = 0; |
+ |
+ // OnStopDiscovery will fail after Shutdown(). |
+ |
+ adapter_chrome_os->OnStopDiscoveryError( |
+ base::Bind(&BluetoothChromeOSTest::ErrorCallback, base::Unretained(this)), |
+ "", ""); |
+ EXPECT_EQ(0, callback_count_) << "OnStopDiscoveryError error"; |
+ EXPECT_EQ(1, error_callback_count_) << "OnStopDiscoveryError error"; |
+ error_callback_count_ = 0; |
+ |
+ // OnRegisterProfile omitted, dbus will be shutdown. |
+ // SetProfileDelegate omitted, dbus will be shutdown. |
+ // OnRegisterProfileError omitted, dbus will be shutdown. |
+ |
+ adapter_chrome_os->ProcessQueuedDiscoveryRequests(); |
+ |
+ // From BluetoothAdapater: |
+ |
adapter_->StartDiscoverySession( |
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
base::Unretained(this)), |
base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
base::Unretained(this))); |
- ASSERT_EQ(0, callback_count_); |
- ASSERT_EQ(3, error_callback_count_); |
+ EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
+ EXPECT_EQ(1, error_callback_count_) << "StartDiscoverySession error"; |
+ error_callback_count_ = 0; |
+ |
+ EXPECT_EQ(0U, adapter_->GetDevices().size()); |
+ EXPECT_EQ(nullptr, adapter_->GetDevice( |
+ FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
+ TestPairingDelegate pairing_delegate2; |
+ adapter_->AddPairingDelegate( |
+ &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
+ adapter_->RemovePairingDelegate(&pairing_delegate2); |
} |
} // namespace chromeos |