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 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 4146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4157 BluetoothAudioSink::Options audio_sink_options; | 4157 BluetoothAudioSink::Options audio_sink_options; |
4158 adapter_->RegisterAudioSink( | 4158 adapter_->RegisterAudioSink( |
4159 audio_sink_options, | 4159 audio_sink_options, |
4160 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, | 4160 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, |
4161 base::Unretained(this)), | 4161 base::Unretained(this)), |
4162 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, | 4162 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, |
4163 base::Unretained(this))); | 4163 base::Unretained(this))); |
4164 EXPECT_EQ(0, callback_count_); | 4164 EXPECT_EQ(0, callback_count_); |
4165 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; | 4165 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
4166 | 4166 |
4167 BluetoothAdapterBlueZ* adapter_chrome_os = | 4167 BluetoothAdapterBlueZ* adapter_bluez = |
4168 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); | 4168 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4169 EXPECT_EQ(nullptr, | 4169 EXPECT_EQ(nullptr, adapter_bluez->GetDeviceWithPath(dbus::ObjectPath(""))); |
4170 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); | |
4171 | 4170 |
4172 // Notify methods presume objects exist that are owned by the adapter and | 4171 // Notify methods presume objects exist that are owned by the adapter and |
4173 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, | 4172 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, |
4174 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); | 4173 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); |
4175 // NotifyDeviceChanged | 4174 // NotifyDeviceChanged |
4176 // NotifyGattServiceAdded | 4175 // NotifyGattServiceAdded |
4177 // NotifyGattServiceRemoved | 4176 // NotifyGattServiceRemoved |
4178 // NotifyGattServiceChanged | 4177 // NotifyGattServiceChanged |
4179 // NotifyGattDiscoveryComplete | 4178 // NotifyGattDiscoveryComplete |
4180 // NotifyGattCharacteristicAdded | 4179 // NotifyGattCharacteristicAdded |
4181 // NotifyGattCharacteristicRemoved | 4180 // NotifyGattCharacteristicRemoved |
4182 // NotifyGattDescriptorAdded | 4181 // NotifyGattDescriptorAdded |
4183 // NotifyGattDescriptorRemoved | 4182 // NotifyGattDescriptorRemoved |
4184 // NotifyGattCharacteristicValueChanged | 4183 // NotifyGattCharacteristicValueChanged |
4185 // NotifyGattDescriptorValueChanged | 4184 // NotifyGattDescriptorValueChanged |
4186 | 4185 |
4187 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); | 4186 EXPECT_EQ(dbus::ObjectPath(""), adapter_bluez->object_path()); |
4188 | 4187 |
4189 adapter_profile_ = nullptr; | 4188 adapter_profile_ = nullptr; |
4190 | 4189 |
4191 FakeBluetoothProfileServiceProviderDelegate profile_delegate; | 4190 FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
4192 adapter_chrome_os->UseProfile( | 4191 adapter_bluez->UseProfile( |
4193 BluetoothUUID(), dbus::ObjectPath(""), | 4192 BluetoothUUID(), dbus::ObjectPath(""), |
4194 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, | 4193 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
4195 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, | 4194 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, |
4196 base::Unretained(this)), | 4195 base::Unretained(this)), |
4197 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, | 4196 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, |
4198 base::Unretained(this))); | 4197 base::Unretained(this))); |
4199 | 4198 |
4200 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 4199 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
4201 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 4200 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
4202 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 4201 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
4203 | 4202 |
4204 // Protected and private methods: | 4203 // Protected and private methods: |
4205 | 4204 |
4206 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); | 4205 adapter_bluez->RemovePairingDelegateInternal(&pairing_delegate); |
4207 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. | 4206 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. |
4208 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); | 4207 adapter_bluez->AdapterRemoved(dbus::ObjectPath("x")); |
4209 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); | 4208 adapter_bluez->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); |
4210 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); | 4209 adapter_bluez->DeviceAdded(dbus::ObjectPath("")); |
4211 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); | 4210 adapter_bluez->DeviceRemoved(dbus::ObjectPath("")); |
4212 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); | 4211 adapter_bluez->DevicePropertyChanged(dbus::ObjectPath(""), ""); |
4213 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); | 4212 adapter_bluez->InputPropertyChanged(dbus::ObjectPath(""), ""); |
4214 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be | 4213 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be |
4215 // shutdown, | 4214 // shutdown, |
4216 // with the exception of Released. | 4215 // with the exception of Released. |
4217 adapter_chrome_os->Released(); | 4216 adapter_bluez->Released(); |
4218 | 4217 |
4219 adapter_chrome_os->OnRegisterAgent(); | 4218 adapter_bluez->OnRegisterAgent(); |
4220 adapter_chrome_os->OnRegisterAgentError("", ""); | 4219 adapter_bluez->OnRegisterAgentError("", ""); |
4221 adapter_chrome_os->OnRequestDefaultAgent(); | 4220 adapter_bluez->OnRequestDefaultAgent(); |
4222 adapter_chrome_os->OnRequestDefaultAgentError("", ""); | 4221 adapter_bluez->OnRequestDefaultAgentError("", ""); |
4223 | 4222 |
4224 adapter_chrome_os->OnRegisterAudioSink( | 4223 adapter_bluez->OnRegisterAudioSink( |
4225 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, | 4224 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, |
4226 base::Unretained(this)), | 4225 base::Unretained(this)), |
4227 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, | 4226 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, |
4228 base::Unretained(this)), | 4227 base::Unretained(this)), |
4229 scoped_refptr<device::BluetoothAudioSink>()); | 4228 scoped_refptr<device::BluetoothAudioSink>()); |
4230 EXPECT_EQ(0, callback_count_); | 4229 EXPECT_EQ(0, callback_count_); |
4231 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; | 4230 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
4232 | 4231 |
4233 // GetPairing will DCHECK after Shutdown(). | 4232 // GetPairing will DCHECK after Shutdown(). |
4234 // SetAdapter will DCHECK after Shutdown(). | 4233 // SetAdapter will DCHECK after Shutdown(). |
4235 // SetDefaultAdapterName will DCHECK after Shutdown(). | 4234 // SetDefaultAdapterName will DCHECK after Shutdown(). |
4236 // RemoveAdapter will DCHECK after Shutdown(). | 4235 // RemoveAdapter will DCHECK after Shutdown(). |
4237 adapter_chrome_os->PoweredChanged(false); | 4236 adapter_bluez->PoweredChanged(false); |
4238 adapter_chrome_os->DiscoverableChanged(false); | 4237 adapter_bluez->DiscoverableChanged(false); |
4239 adapter_chrome_os->DiscoveringChanged(false); | 4238 adapter_bluez->DiscoveringChanged(false); |
4240 adapter_chrome_os->PresentChanged(false); | 4239 adapter_bluez->PresentChanged(false); |
4241 | 4240 |
4242 adapter_chrome_os->OnSetDiscoverable(GetCallback(), GetErrorCallback(), true); | 4241 adapter_bluez->OnSetDiscoverable(GetCallback(), GetErrorCallback(), true); |
4243 EXPECT_EQ(0, callback_count_) << "OnSetDiscoverable error"; | 4242 EXPECT_EQ(0, callback_count_) << "OnSetDiscoverable error"; |
4244 EXPECT_EQ(1, error_callback_count_--) << "OnSetDiscoverable error"; | 4243 EXPECT_EQ(1, error_callback_count_--) << "OnSetDiscoverable error"; |
4245 | 4244 |
4246 adapter_chrome_os->OnPropertyChangeCompleted(GetCallback(), | 4245 adapter_bluez->OnPropertyChangeCompleted(GetCallback(), GetErrorCallback(), |
4247 GetErrorCallback(), true); | 4246 true); |
4248 EXPECT_EQ(0, callback_count_) << "OnPropertyChangeCompleted error"; | 4247 EXPECT_EQ(0, callback_count_) << "OnPropertyChangeCompleted error"; |
4249 EXPECT_EQ(1, error_callback_count_--) << "OnPropertyChangeCompleted error"; | 4248 EXPECT_EQ(1, error_callback_count_--) << "OnPropertyChangeCompleted error"; |
4250 | 4249 |
4251 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4250 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4252 GetDiscoveryErrorCallback()); | 4251 GetDiscoveryErrorCallback()); |
4253 EXPECT_EQ(0, callback_count_) << "AddDiscoverySession error"; | 4252 EXPECT_EQ(0, callback_count_) << "AddDiscoverySession error"; |
4254 EXPECT_EQ(1, error_callback_count_--) << "AddDiscoverySession error"; | 4253 EXPECT_EQ(1, error_callback_count_--) << "AddDiscoverySession error"; |
4255 | 4254 |
4256 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), | 4255 adapter_bluez->RemoveDiscoverySession(nullptr, GetCallback(), |
4257 GetDiscoveryErrorCallback()); | 4256 GetDiscoveryErrorCallback()); |
4258 EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error"; | 4257 EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error"; |
4259 EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error"; | 4258 EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error"; |
4260 | 4259 |
4261 // OnStartDiscovery tested in Shutdown_OnStartDiscovery | 4260 // OnStartDiscovery tested in Shutdown_OnStartDiscovery |
4262 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError | 4261 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError |
4263 // OnStopDiscovery tested in Shutdown_OnStopDiscovery | 4262 // OnStopDiscovery tested in Shutdown_OnStopDiscovery |
4264 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError | 4263 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError |
4265 | 4264 |
4266 adapter_profile_ = nullptr; | 4265 adapter_profile_ = nullptr; |
4267 | 4266 |
4268 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require | 4267 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require |
4269 // UseProfile to be set first, do so again here just before calling them. | 4268 // UseProfile to be set first, do so again here just before calling them. |
4270 adapter_chrome_os->UseProfile( | 4269 adapter_bluez->UseProfile( |
4271 BluetoothUUID(), dbus::ObjectPath(""), | 4270 BluetoothUUID(), dbus::ObjectPath(""), |
4272 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, | 4271 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
4273 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, | 4272 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, |
4274 base::Unretained(this)), | 4273 base::Unretained(this)), |
4275 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, | 4274 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, |
4276 base::Unretained(this))); | 4275 base::Unretained(this))); |
4277 | 4276 |
4278 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 4277 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
4279 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 4278 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
4280 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 4279 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
4281 | 4280 |
4282 adapter_chrome_os->SetProfileDelegate( | 4281 adapter_bluez->SetProfileDelegate( |
4283 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, | 4282 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, |
4284 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, | 4283 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, |
4285 base::Unretained(this)), | 4284 base::Unretained(this)), |
4286 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, | 4285 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, |
4287 base::Unretained(this))); | 4286 base::Unretained(this))); |
4288 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; | 4287 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; |
4289 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; | 4288 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; |
4290 | 4289 |
4291 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", ""); | 4290 adapter_bluez->OnRegisterProfileError(BluetoothUUID(), "", ""); |
4292 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; | 4291 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; |
4293 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error"; | 4292 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error"; |
4294 | 4293 |
4295 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); | 4294 adapter_bluez->ProcessQueuedDiscoveryRequests(); |
4296 | 4295 |
4297 // From BluetoothAdapater: | 4296 // From BluetoothAdapater: |
4298 | 4297 |
4299 adapter_->StartDiscoverySession( | 4298 adapter_->StartDiscoverySession( |
4300 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 4299 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
4301 base::Unretained(this)), | 4300 base::Unretained(this)), |
4302 GetErrorCallback()); | 4301 GetErrorCallback()); |
4303 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; | 4302 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
4304 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; | 4303 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; |
4305 | 4304 |
4306 EXPECT_EQ(0U, adapter_->GetDevices().size()); | 4305 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
4307 EXPECT_EQ(nullptr, | 4306 EXPECT_EQ(nullptr, |
4308 adapter_->GetDevice( | 4307 adapter_->GetDevice( |
4309 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 4308 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
4310 TestPairingDelegate pairing_delegate2; | 4309 TestPairingDelegate pairing_delegate2; |
4311 adapter_->AddPairingDelegate( | 4310 adapter_->AddPairingDelegate( |
4312 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 4311 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
4313 adapter_->RemovePairingDelegate(&pairing_delegate2); | 4312 adapter_->RemovePairingDelegate(&pairing_delegate2); |
4314 } | 4313 } |
4315 | 4314 |
4316 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. | 4315 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
4317 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscovery) { | 4316 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscovery) { |
4318 const int kNumberOfDiscoverySessions = 10; | 4317 const int kNumberOfDiscoverySessions = 10; |
4319 GetAdapter(); | 4318 GetAdapter(); |
4320 BluetoothAdapterBlueZ* adapter_chrome_os = | 4319 BluetoothAdapterBlueZ* adapter_bluez = |
4321 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); | 4320 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4322 | 4321 |
4323 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4322 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4324 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4323 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4325 GetDiscoveryErrorCallback()); | 4324 GetDiscoveryErrorCallback()); |
4326 } | 4325 } |
4327 adapter_->Shutdown(); | 4326 adapter_->Shutdown(); |
4328 adapter_chrome_os->OnStartDiscovery(GetCallback(), | 4327 adapter_bluez->OnStartDiscovery(GetCallback(), GetDiscoveryErrorCallback()); |
4329 GetDiscoveryErrorCallback()); | |
4330 | 4328 |
4331 EXPECT_EQ(0, callback_count_); | 4329 EXPECT_EQ(0, callback_count_); |
4332 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); | 4330 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
4333 } | 4331 } |
4334 | 4332 |
4335 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. | 4333 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. |
4336 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscoveryError) { | 4334 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscoveryError) { |
4337 const int kNumberOfDiscoverySessions = 10; | 4335 const int kNumberOfDiscoverySessions = 10; |
4338 GetAdapter(); | 4336 GetAdapter(); |
4339 BluetoothAdapterBlueZ* adapter_chrome_os = | 4337 BluetoothAdapterBlueZ* adapter_bluez = |
4340 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); | 4338 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4341 | 4339 |
4342 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4340 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4343 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4341 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4344 GetDiscoveryErrorCallback()); | 4342 GetDiscoveryErrorCallback()); |
4345 } | 4343 } |
4346 adapter_->Shutdown(); | 4344 adapter_->Shutdown(); |
4347 adapter_chrome_os->OnStartDiscoveryError(GetCallback(), | 4345 adapter_bluez->OnStartDiscoveryError(GetCallback(), |
4348 GetDiscoveryErrorCallback(), "", ""); | 4346 GetDiscoveryErrorCallback(), "", ""); |
4349 | 4347 |
4350 EXPECT_EQ(0, callback_count_); | 4348 EXPECT_EQ(0, callback_count_); |
4351 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); | 4349 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
4352 } | 4350 } |
4353 | 4351 |
4354 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. | 4352 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
4355 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscovery) { | 4353 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscovery) { |
4356 const int kNumberOfDiscoverySessions = 10; | 4354 const int kNumberOfDiscoverySessions = 10; |
4357 GetAdapter(); | 4355 GetAdapter(); |
4358 BluetoothAdapterBlueZ* adapter_chrome_os = | 4356 BluetoothAdapterBlueZ* adapter_bluez = |
4359 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); | 4357 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4360 | 4358 |
4361 // In order to queue up discovery sessions before an OnStopDiscovery call | 4359 // In order to queue up discovery sessions before an OnStopDiscovery call |
4362 // RemoveDiscoverySession must be called, so Add, Start, and Remove: | 4360 // RemoveDiscoverySession must be called, so Add, Start, and Remove: |
4363 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4361 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4364 GetDiscoveryErrorCallback()); | 4362 GetDiscoveryErrorCallback()); |
4365 adapter_chrome_os->OnStartDiscovery(GetCallback(), | 4363 adapter_bluez->OnStartDiscovery(GetCallback(), GetDiscoveryErrorCallback()); |
4366 GetDiscoveryErrorCallback()); | 4364 adapter_bluez->RemoveDiscoverySession(nullptr, GetCallback(), |
4367 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), | 4365 GetDiscoveryErrorCallback()); |
4368 GetDiscoveryErrorCallback()); | |
4369 callback_count_ = 0; | 4366 callback_count_ = 0; |
4370 error_callback_count_ = 0; | 4367 error_callback_count_ = 0; |
4371 // Can now queue discovery sessions while waiting for OnStopDiscovery. | 4368 // Can now queue discovery sessions while waiting for OnStopDiscovery. |
4372 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4369 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4373 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4370 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4374 GetDiscoveryErrorCallback()); | 4371 GetDiscoveryErrorCallback()); |
4375 } | 4372 } |
4376 adapter_->Shutdown(); | 4373 adapter_->Shutdown(); |
4377 adapter_chrome_os->OnStopDiscovery(GetCallback()); | 4374 adapter_bluez->OnStopDiscovery(GetCallback()); |
4378 | 4375 |
4379 // 1 successful stopped discovery from RemoveDiscoverySession, and | 4376 // 1 successful stopped discovery from RemoveDiscoverySession, and |
4380 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. | 4377 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. |
4381 EXPECT_EQ(1, callback_count_); | 4378 EXPECT_EQ(1, callback_count_); |
4382 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); | 4379 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
4383 } | 4380 } |
4384 | 4381 |
4385 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. | 4382 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. |
4386 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscoveryError) { | 4383 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscoveryError) { |
4387 const int kNumberOfDiscoverySessions = 10; | 4384 const int kNumberOfDiscoverySessions = 10; |
4388 GetAdapter(); | 4385 GetAdapter(); |
4389 BluetoothAdapterBlueZ* adapter_chrome_os = | 4386 BluetoothAdapterBlueZ* adapter_bluez = |
4390 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); | 4387 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4391 | 4388 |
4392 // In order to queue up discovery sessions before an OnStopDiscoveryError call | 4389 // In order to queue up discovery sessions before an OnStopDiscoveryError call |
4393 // RemoveDiscoverySession must be called, so Add, Start, and Remove: | 4390 // RemoveDiscoverySession must be called, so Add, Start, and Remove: |
4394 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4391 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4395 GetDiscoveryErrorCallback()); | 4392 GetDiscoveryErrorCallback()); |
4396 adapter_chrome_os->OnStartDiscovery(GetCallback(), | 4393 adapter_bluez->OnStartDiscovery(GetCallback(), GetDiscoveryErrorCallback()); |
4397 GetDiscoveryErrorCallback()); | 4394 adapter_bluez->RemoveDiscoverySession(nullptr, GetCallback(), |
4398 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), | 4395 GetDiscoveryErrorCallback()); |
4399 GetDiscoveryErrorCallback()); | |
4400 callback_count_ = 0; | 4396 callback_count_ = 0; |
4401 error_callback_count_ = 0; | 4397 error_callback_count_ = 0; |
4402 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. | 4398 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. |
4403 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4399 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4404 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4400 adapter_bluez->AddDiscoverySession(nullptr, GetCallback(), |
4405 GetDiscoveryErrorCallback()); | 4401 GetDiscoveryErrorCallback()); |
4406 } | 4402 } |
4407 adapter_->Shutdown(); | 4403 adapter_->Shutdown(); |
4408 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4404 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
4409 | 4405 |
4410 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4406 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
4411 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4407 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
4412 EXPECT_EQ(0, callback_count_); | 4408 EXPECT_EQ(0, callback_count_); |
4413 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4409 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
4414 } | 4410 } |
4415 | 4411 |
4416 } // namespace bluez | 4412 } // namespace bluez |
OLD | NEW |