| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" | 27 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
| 28 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 28 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 29 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" | 29 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
| 30 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" | 30 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
| 31 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 31 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "third_party/cros_system_api/dbus/service_constants.h" | 33 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 34 | 34 |
| 35 using device::BluetoothAdapter; | 35 using device::BluetoothAdapter; |
| 36 using device::BluetoothAdapterFactory; | 36 using device::BluetoothAdapterFactory; |
| 37 using device::BluetoothAudioSink; | |
| 38 using device::BluetoothDevice; | 37 using device::BluetoothDevice; |
| 39 using device::BluetoothDiscoveryFilter; | 38 using device::BluetoothDiscoveryFilter; |
| 40 using device::BluetoothDiscoverySession; | 39 using device::BluetoothDiscoverySession; |
| 41 using device::BluetoothUUID; | 40 using device::BluetoothUUID; |
| 42 using device::TestBluetoothAdapterObserver; | 41 using device::TestBluetoothAdapterObserver; |
| 43 | 42 |
| 44 namespace bluez { | 43 namespace bluez { |
| 45 | 44 |
| 46 namespace { | 45 namespace { |
| 47 | 46 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 241 |
| 243 void AdapterCallback() { QuitMessageLoop(); } | 242 void AdapterCallback() { QuitMessageLoop(); } |
| 244 | 243 |
| 245 void DiscoverySessionCallback( | 244 void DiscoverySessionCallback( |
| 246 std::unique_ptr<BluetoothDiscoverySession> discovery_session) { | 245 std::unique_ptr<BluetoothDiscoverySession> discovery_session) { |
| 247 ++callback_count_; | 246 ++callback_count_; |
| 248 discovery_sessions_.push_back(discovery_session.release()); | 247 discovery_sessions_.push_back(discovery_session.release()); |
| 249 QuitMessageLoop(); | 248 QuitMessageLoop(); |
| 250 } | 249 } |
| 251 | 250 |
| 252 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { | |
| 253 ++callback_count_; | |
| 254 QuitMessageLoop(); | |
| 255 } | |
| 256 | |
| 257 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) { | 251 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) { |
| 258 adapter_profile_ = profile; | 252 adapter_profile_ = profile; |
| 259 ++callback_count_; | 253 ++callback_count_; |
| 260 QuitMessageLoop(); | 254 QuitMessageLoop(); |
| 261 } | 255 } |
| 262 | 256 |
| 263 void ErrorCallback() { | 257 void ErrorCallback() { |
| 264 ++error_callback_count_; | 258 ++error_callback_count_; |
| 265 QuitMessageLoop(); | 259 QuitMessageLoop(); |
| 266 } | 260 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 285 ++error_callback_count_; | 279 ++error_callback_count_; |
| 286 last_client_error_ = error_name; | 280 last_client_error_ = error_name; |
| 287 QuitMessageLoop(); | 281 QuitMessageLoop(); |
| 288 } | 282 } |
| 289 | 283 |
| 290 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { | 284 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { |
| 291 ++error_callback_count_; | 285 ++error_callback_count_; |
| 292 last_connect_error_ = error; | 286 last_connect_error_ = error; |
| 293 } | 287 } |
| 294 | 288 |
| 295 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { | |
| 296 ++error_callback_count_; | |
| 297 QuitMessageLoop(); | |
| 298 } | |
| 299 | |
| 300 void ErrorCompletionCallback(const std::string& error_message) { | 289 void ErrorCompletionCallback(const std::string& error_message) { |
| 301 ++error_callback_count_; | 290 ++error_callback_count_; |
| 302 QuitMessageLoop(); | 291 QuitMessageLoop(); |
| 303 } | 292 } |
| 304 | 293 |
| 305 // Call to fill the adapter_ member with a BluetoothAdapter instance. | 294 // Call to fill the adapter_ member with a BluetoothAdapter instance. |
| 306 void GetAdapter() { | 295 void GetAdapter() { |
| 307 adapter_ = new BluetoothAdapterBlueZ(base::Bind( | 296 adapter_ = new BluetoothAdapterBlueZ(base::Bind( |
| 308 &BluetoothBlueZTest::AdapterCallback, base::Unretained(this))); | 297 &BluetoothBlueZTest::AdapterCallback, base::Unretained(this))); |
| 309 base::RunLoop().Run(); | 298 base::RunLoop().Run(); |
| (...skipping 3944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4254 EXPECT_FALSE(adapter_->IsDiscoverable()); | 4243 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 4255 | 4244 |
| 4256 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); | 4245 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
| 4257 EXPECT_EQ(0, callback_count_); | 4246 EXPECT_EQ(0, callback_count_); |
| 4258 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; | 4247 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; |
| 4259 | 4248 |
| 4260 EXPECT_FALSE(adapter_->IsDiscovering()); | 4249 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 4261 // CreateRfcommService will DCHECK after Shutdown(). | 4250 // CreateRfcommService will DCHECK after Shutdown(). |
| 4262 // CreateL2capService will DCHECK after Shutdown(). | 4251 // CreateL2capService will DCHECK after Shutdown(). |
| 4263 | 4252 |
| 4264 BluetoothAudioSink::Options audio_sink_options; | |
| 4265 adapter_->RegisterAudioSink( | |
| 4266 audio_sink_options, | |
| 4267 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, | |
| 4268 base::Unretained(this)), | |
| 4269 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, | |
| 4270 base::Unretained(this))); | |
| 4271 EXPECT_EQ(0, callback_count_); | |
| 4272 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; | |
| 4273 | |
| 4274 BluetoothAdapterBlueZ* adapter_bluez = | 4253 BluetoothAdapterBlueZ* adapter_bluez = |
| 4275 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); | 4254 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
| 4276 EXPECT_EQ(nullptr, adapter_bluez->GetDeviceWithPath(dbus::ObjectPath(""))); | 4255 EXPECT_EQ(nullptr, adapter_bluez->GetDeviceWithPath(dbus::ObjectPath(""))); |
| 4277 | 4256 |
| 4278 // Notify methods presume objects exist that are owned by the adapter and | 4257 // Notify methods presume objects exist that are owned by the adapter and |
| 4279 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, | 4258 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, |
| 4280 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); | 4259 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 4281 // NotifyDeviceChanged | 4260 // NotifyDeviceChanged |
| 4282 // NotifyGattServiceAdded | 4261 // NotifyGattServiceAdded |
| 4283 // NotifyGattServiceRemoved | 4262 // NotifyGattServiceRemoved |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4320 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be | 4299 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be |
| 4321 // shutdown, | 4300 // shutdown, |
| 4322 // with the exception of Released. | 4301 // with the exception of Released. |
| 4323 adapter_bluez->Released(); | 4302 adapter_bluez->Released(); |
| 4324 | 4303 |
| 4325 adapter_bluez->OnRegisterAgent(); | 4304 adapter_bluez->OnRegisterAgent(); |
| 4326 adapter_bluez->OnRegisterAgentError("", ""); | 4305 adapter_bluez->OnRegisterAgentError("", ""); |
| 4327 adapter_bluez->OnRequestDefaultAgent(); | 4306 adapter_bluez->OnRequestDefaultAgent(); |
| 4328 adapter_bluez->OnRequestDefaultAgentError("", ""); | 4307 adapter_bluez->OnRequestDefaultAgentError("", ""); |
| 4329 | 4308 |
| 4330 adapter_bluez->OnRegisterAudioSink( | |
| 4331 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, | |
| 4332 base::Unretained(this)), | |
| 4333 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, | |
| 4334 base::Unretained(this)), | |
| 4335 scoped_refptr<device::BluetoothAudioSink>()); | |
| 4336 EXPECT_EQ(0, callback_count_); | |
| 4337 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; | |
| 4338 | |
| 4339 // GetPairing will DCHECK after Shutdown(). | 4309 // GetPairing will DCHECK after Shutdown(). |
| 4340 // SetAdapter will DCHECK after Shutdown(). | 4310 // SetAdapter will DCHECK after Shutdown(). |
| 4341 // SetDefaultAdapterName will DCHECK after Shutdown(). | 4311 // SetDefaultAdapterName will DCHECK after Shutdown(). |
| 4342 // RemoveAdapter will DCHECK after Shutdown(). | 4312 // RemoveAdapter will DCHECK after Shutdown(). |
| 4343 adapter_bluez->NotifyAdapterPoweredChanged(false); | 4313 adapter_bluez->NotifyAdapterPoweredChanged(false); |
| 4344 adapter_bluez->DiscoverableChanged(false); | 4314 adapter_bluez->DiscoverableChanged(false); |
| 4345 adapter_bluez->DiscoveringChanged(false); | 4315 adapter_bluez->DiscoveringChanged(false); |
| 4346 adapter_bluez->PresentChanged(false); | 4316 adapter_bluez->PresentChanged(false); |
| 4347 | 4317 |
| 4348 adapter_bluez->OnSetDiscoverable(GetCallback(), GetErrorCallback(), true); | 4318 adapter_bluez->OnSetDiscoverable(GetCallback(), GetErrorCallback(), true); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4510 adapter_->Shutdown(); | 4480 adapter_->Shutdown(); |
| 4511 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4481 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
| 4512 | 4482 |
| 4513 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4483 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
| 4514 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4484 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
| 4515 EXPECT_EQ(0, callback_count_); | 4485 EXPECT_EQ(0, callback_count_); |
| 4516 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4486 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
| 4517 } | 4487 } |
| 4518 | 4488 |
| 4519 } // namespace bluez | 4489 } // namespace bluez |
| OLD | NEW |