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/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "dbus/object_path.h" | 9 #include "dbus/object_path.h" |
10 #include "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" |
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 11 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
12 #include "device/bluetooth/bluetooth_adapter_factory.h" | 12 #include "device/bluetooth/bluetooth_adapter_factory.h" |
13 #include "device/bluetooth/bluetooth_device.h" | 13 #include "device/bluetooth/bluetooth_device.h" |
14 #include "device/bluetooth/bluetooth_device_chromeos.h" | 14 #include "device/bluetooth/bluetooth_device_bluez.h" |
15 #include "device/bluetooth/bluetooth_discovery_session.h" | 15 #include "device/bluetooth/bluetooth_discovery_session.h" |
16 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 16 #include "device/bluetooth/bluetooth_pairing_bluez.h" |
17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" | 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" | 19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" | 21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" | 22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/cros_system_api/dbus/service_constants.h" | 25 #include "third_party/cros_system_api/dbus/service_constants.h" |
26 | 26 |
27 using device::BluetoothAdapter; | 27 using device::BluetoothAdapter; |
28 using device::BluetoothAdapterFactory; | 28 using device::BluetoothAdapterFactory; |
29 using device::BluetoothAudioSink; | 29 using device::BluetoothAudioSink; |
30 using device::BluetoothDevice; | 30 using device::BluetoothDevice; |
31 using device::BluetoothDiscoveryFilter; | 31 using device::BluetoothDiscoveryFilter; |
32 using device::BluetoothDiscoverySession; | 32 using device::BluetoothDiscoverySession; |
33 using device::BluetoothUUID; | 33 using device::BluetoothUUID; |
34 using device::TestBluetoothAdapterObserver; | 34 using device::TestBluetoothAdapterObserver; |
35 | 35 |
36 namespace chromeos { | 36 namespace bluez { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the | 40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the |
41 // connection info to the bound argument. | 41 // connection info to the bound argument. |
42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, | 42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, |
43 const BluetoothDevice::ConnectionInfo& conn_info) { | 43 const BluetoothDevice::ConnectionInfo& conn_info) { |
44 *out = conn_info; | 44 *out = conn_info; |
45 }; | 45 }; |
46 | 46 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Some tests use a message loop since background processing is simulated; | 144 // Some tests use a message loop since background processing is simulated; |
145 // break out of those loops. | 145 // break out of those loops. |
146 void QuitMessageLoop() { | 146 void QuitMessageLoop() { |
147 if (base::MessageLoop::current() && | 147 if (base::MessageLoop::current() && |
148 base::MessageLoop::current()->is_running()) { | 148 base::MessageLoop::current()->is_running()) { |
149 base::MessageLoop::current()->Quit(); | 149 base::MessageLoop::current()->Quit(); |
150 } | 150 } |
151 } | 151 } |
152 }; | 152 }; |
153 | 153 |
154 class BluetoothChromeOSTest : public testing::Test { | 154 class BluetoothBlueZTest : public testing::Test { |
155 public: | 155 public: |
156 void SetUp() override { | 156 void SetUp() override { |
157 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = | 157 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
158 bluez::BluezDBusManager::GetSetterForTesting(); | 158 bluez::BluezDBusManager::GetSetterForTesting(); |
159 // We need to initialize BluezDBusManager early to prevent | 159 // We need to initialize BluezDBusManager early to prevent |
160 // Bluetooth*::Create() methods from picking the real instead of fake | 160 // Bluetooth*::Create() methods from picking the real instead of fake |
161 // implementations. | 161 // implementations. |
162 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; | 162 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; |
163 dbus_setter->SetBluetoothAdapterClient( | 163 dbus_setter->SetBluetoothAdapterClient( |
164 scoped_ptr<bluez::BluetoothAdapterClient>( | 164 scoped_ptr<bluez::BluetoothAdapterClient>( |
(...skipping 15 matching lines...) Expand all Loading... |
180 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); | 180 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); |
181 | 181 |
182 callback_count_ = 0; | 182 callback_count_ = 0; |
183 error_callback_count_ = 0; | 183 error_callback_count_ = 0; |
184 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; | 184 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; |
185 last_client_error_ = ""; | 185 last_client_error_ = ""; |
186 } | 186 } |
187 | 187 |
188 void TearDown() override { | 188 void TearDown() override { |
189 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = | 189 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = |
190 discovery_sessions_.begin(); | 190 discovery_sessions_.begin(); |
191 iter != discovery_sessions_.end(); | 191 iter != discovery_sessions_.end(); ++iter) { |
192 ++iter) { | |
193 BluetoothDiscoverySession* session = *iter; | 192 BluetoothDiscoverySession* session = *iter; |
194 if (!session->IsActive()) | 193 if (!session->IsActive()) |
195 continue; | 194 continue; |
196 callback_count_ = 0; | 195 callback_count_ = 0; |
197 session->Stop(GetCallback(), GetErrorCallback()); | 196 session->Stop(GetCallback(), GetErrorCallback()); |
198 message_loop_.Run(); | 197 message_loop_.Run(); |
199 ASSERT_EQ(1, callback_count_); | 198 ASSERT_EQ(1, callback_count_); |
200 } | 199 } |
201 discovery_sessions_.clear(); | 200 discovery_sessions_.clear(); |
202 adapter_ = nullptr; | 201 adapter_ = nullptr; |
203 bluez::BluezDBusManager::Shutdown(); | 202 bluez::BluezDBusManager::Shutdown(); |
204 } | 203 } |
205 | 204 |
206 // Generic callbacks | 205 // Generic callbacks |
207 void Callback() { | 206 void Callback() { |
208 ++callback_count_; | 207 ++callback_count_; |
209 QuitMessageLoop(); | 208 QuitMessageLoop(); |
210 } | 209 } |
211 | 210 |
212 base::Closure GetCallback() { | 211 base::Closure GetCallback() { |
213 return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)); | 212 return base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)); |
214 } | 213 } |
215 | 214 |
216 void DiscoverySessionCallback( | 215 void DiscoverySessionCallback( |
217 scoped_ptr<BluetoothDiscoverySession> discovery_session) { | 216 scoped_ptr<BluetoothDiscoverySession> discovery_session) { |
218 ++callback_count_; | 217 ++callback_count_; |
219 discovery_sessions_.push_back(discovery_session.release()); | 218 discovery_sessions_.push_back(discovery_session.release()); |
220 QuitMessageLoop(); | 219 QuitMessageLoop(); |
221 } | 220 } |
222 | 221 |
223 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { | 222 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { |
224 ++callback_count_; | 223 ++callback_count_; |
225 QuitMessageLoop(); | 224 QuitMessageLoop(); |
226 } | 225 } |
227 | 226 |
228 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS* profile) { | 227 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) { |
229 adapter_profile_ = profile; | 228 adapter_profile_ = profile; |
230 ++callback_count_; | 229 ++callback_count_; |
231 QuitMessageLoop(); | 230 QuitMessageLoop(); |
232 } | 231 } |
233 | 232 |
234 void ErrorCallback() { | 233 void ErrorCallback() { |
235 ++error_callback_count_; | 234 ++error_callback_count_; |
236 QuitMessageLoop(); | 235 QuitMessageLoop(); |
237 } | 236 } |
238 | 237 |
239 void DiscoveryErrorCallback(device::UMABluetoothDiscoverySessionOutcome) { | 238 void DiscoveryErrorCallback(device::UMABluetoothDiscoverySessionOutcome) { |
240 ErrorCallback(); | 239 ErrorCallback(); |
241 } | 240 } |
242 | 241 |
243 base::Closure GetErrorCallback() { | 242 base::Closure GetErrorCallback() { |
244 return base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 243 return base::Bind(&BluetoothBlueZTest::ErrorCallback, |
245 base::Unretained(this)); | 244 base::Unretained(this)); |
246 } | 245 } |
247 | 246 |
248 base::Callback<void(device::UMABluetoothDiscoverySessionOutcome)> | 247 base::Callback<void(device::UMABluetoothDiscoverySessionOutcome)> |
249 GetDiscoveryErrorCallback() { | 248 GetDiscoveryErrorCallback() { |
250 return base::Bind(&BluetoothChromeOSTest::DiscoveryErrorCallback, | 249 return base::Bind(&BluetoothBlueZTest::DiscoveryErrorCallback, |
251 base::Unretained(this)); | 250 base::Unretained(this)); |
252 } | 251 } |
253 | 252 |
254 void DBusErrorCallback(const std::string& error_name, | 253 void DBusErrorCallback(const std::string& error_name, |
255 const std::string& error_message) { | 254 const std::string& error_message) { |
256 ++error_callback_count_; | 255 ++error_callback_count_; |
257 last_client_error_ = error_name; | 256 last_client_error_ = error_name; |
258 QuitMessageLoop(); | 257 QuitMessageLoop(); |
259 } | 258 } |
260 | 259 |
261 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { | 260 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { |
262 ++error_callback_count_; | 261 ++error_callback_count_; |
263 last_connect_error_ = error; | 262 last_connect_error_ = error; |
264 } | 263 } |
265 | 264 |
266 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { | 265 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { |
267 ++error_callback_count_; | 266 ++error_callback_count_; |
268 QuitMessageLoop(); | 267 QuitMessageLoop(); |
269 } | 268 } |
270 | 269 |
271 void ErrorCompletionCallback(const std::string& error_message) { | 270 void ErrorCompletionCallback(const std::string& error_message) { |
272 ++error_callback_count_; | 271 ++error_callback_count_; |
273 QuitMessageLoop(); | 272 QuitMessageLoop(); |
274 } | 273 } |
275 | 274 |
276 // Call to fill the adapter_ member with a BluetoothAdapter instance. | 275 // Call to fill the adapter_ member with a BluetoothAdapter instance. |
277 void GetAdapter() { | 276 void GetAdapter() { |
278 adapter_ = new BluetoothAdapterChromeOS(); | 277 adapter_ = new BluetoothAdapterBlueZ(); |
279 ASSERT_TRUE(adapter_.get() != nullptr); | 278 ASSERT_TRUE(adapter_.get() != nullptr); |
280 ASSERT_TRUE(adapter_->IsInitialized()); | 279 ASSERT_TRUE(adapter_->IsInitialized()); |
281 } | 280 } |
282 | 281 |
283 // Run a discovery phase until the named device is detected, or if the named | 282 // Run a discovery phase until the named device is detected, or if the named |
284 // device is not created, the discovery process ends without finding it. | 283 // device is not created, the discovery process ends without finding it. |
285 // | 284 // |
286 // The correct behavior of discovery is tested by the "Discovery" test case | 285 // The correct behavior of discovery is tested by the "Discovery" test case |
287 // without using this function. | 286 // without using this function. |
288 void DiscoverDevice(const std::string& address) { | 287 void DiscoverDevice(const std::string& address) { |
289 ASSERT_TRUE(adapter_.get() != nullptr); | 288 ASSERT_TRUE(adapter_.get() != nullptr); |
290 ASSERT_TRUE(base::MessageLoop::current() != nullptr); | 289 ASSERT_TRUE(base::MessageLoop::current() != nullptr); |
291 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 290 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
292 | 291 |
293 TestBluetoothAdapterObserver observer(adapter_); | 292 TestBluetoothAdapterObserver observer(adapter_); |
294 | 293 |
295 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 294 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
296 adapter_->StartDiscoverySession( | 295 adapter_->StartDiscoverySession( |
297 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 296 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
298 base::Unretained(this)), | 297 base::Unretained(this)), |
299 GetErrorCallback()); | 298 GetErrorCallback()); |
300 base::MessageLoop::current()->Run(); | 299 base::MessageLoop::current()->Run(); |
301 ASSERT_EQ(2, callback_count_); | 300 ASSERT_EQ(2, callback_count_); |
302 ASSERT_EQ(0, error_callback_count_); | 301 ASSERT_EQ(0, error_callback_count_); |
303 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 302 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
304 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 303 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
305 callback_count_ = 0; | 304 callback_count_ = 0; |
306 | 305 |
307 ASSERT_TRUE(adapter_->IsPowered()); | 306 ASSERT_TRUE(adapter_->IsPowered()); |
(...skipping 23 matching lines...) Expand all Loading... |
331 base::MessageLoop message_loop_; | 330 base::MessageLoop message_loop_; |
332 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; | 331 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; |
333 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 332 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
334 scoped_refptr<BluetoothAdapter> adapter_; | 333 scoped_refptr<BluetoothAdapter> adapter_; |
335 | 334 |
336 int callback_count_; | 335 int callback_count_; |
337 int error_callback_count_; | 336 int error_callback_count_; |
338 enum BluetoothDevice::ConnectErrorCode last_connect_error_; | 337 enum BluetoothDevice::ConnectErrorCode last_connect_error_; |
339 std::string last_client_error_; | 338 std::string last_client_error_; |
340 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 339 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
341 BluetoothAdapterProfileChromeOS* adapter_profile_; | 340 BluetoothAdapterProfileBlueZ* adapter_profile_; |
342 | 341 |
343 private: | 342 private: |
344 // Some tests use a message loop since background processing is simulated; | 343 // Some tests use a message loop since background processing is simulated; |
345 // break out of those loops. | 344 // break out of those loops. |
346 void QuitMessageLoop() { | 345 void QuitMessageLoop() { |
347 if (base::MessageLoop::current() && | 346 if (base::MessageLoop::current() && |
348 base::MessageLoop::current()->is_running()) { | 347 base::MessageLoop::current()->is_running()) { |
349 base::MessageLoop::current()->Quit(); | 348 base::MessageLoop::current()->Quit(); |
350 } | 349 } |
351 } | 350 } |
352 }; | 351 }; |
353 | 352 |
354 TEST_F(BluetoothChromeOSTest, AlreadyPresent) { | 353 TEST_F(BluetoothBlueZTest, AlreadyPresent) { |
355 GetAdapter(); | 354 GetAdapter(); |
356 | 355 |
357 // This verifies that the class gets the list of adapters when created; | 356 // This verifies that the class gets the list of adapters when created; |
358 // and initializes with an existing adapter if there is one. | 357 // and initializes with an existing adapter if there is one. |
359 EXPECT_TRUE(adapter_->IsPresent()); | 358 EXPECT_TRUE(adapter_->IsPresent()); |
360 EXPECT_FALSE(adapter_->IsPowered()); | 359 EXPECT_FALSE(adapter_->IsPowered()); |
361 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress, | 360 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress, |
362 adapter_->GetAddress()); | 361 adapter_->GetAddress()); |
363 EXPECT_FALSE(adapter_->IsDiscovering()); | 362 EXPECT_FALSE(adapter_->IsDiscovering()); |
364 | 363 |
365 // There should be a device | 364 // There should be a device |
366 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 365 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
367 EXPECT_EQ(2U, devices.size()); | 366 EXPECT_EQ(2U, devices.size()); |
368 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 367 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
369 devices[0]->GetAddress()); | 368 devices[0]->GetAddress()); |
370 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 369 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
371 devices[1]->GetAddress()); | 370 devices[1]->GetAddress()); |
372 } | 371 } |
373 | 372 |
374 TEST_F(BluetoothChromeOSTest, BecomePresent) { | 373 TEST_F(BluetoothBlueZTest, BecomePresent) { |
375 fake_bluetooth_adapter_client_->SetVisible(false); | 374 fake_bluetooth_adapter_client_->SetVisible(false); |
376 GetAdapter(); | 375 GetAdapter(); |
377 ASSERT_FALSE(adapter_->IsPresent()); | 376 ASSERT_FALSE(adapter_->IsPresent()); |
378 | 377 |
379 // Install an observer; expect the AdapterPresentChanged to be called | 378 // Install an observer; expect the AdapterPresentChanged to be called |
380 // with true, and IsPresent() to return true. | 379 // with true, and IsPresent() to return true. |
381 TestBluetoothAdapterObserver observer(adapter_); | 380 TestBluetoothAdapterObserver observer(adapter_); |
382 | 381 |
383 fake_bluetooth_adapter_client_->SetVisible(true); | 382 fake_bluetooth_adapter_client_->SetVisible(true); |
384 | 383 |
385 EXPECT_EQ(1, observer.present_changed_count()); | 384 EXPECT_EQ(1, observer.present_changed_count()); |
386 EXPECT_TRUE(observer.last_present()); | 385 EXPECT_TRUE(observer.last_present()); |
387 | 386 |
388 EXPECT_TRUE(adapter_->IsPresent()); | 387 EXPECT_TRUE(adapter_->IsPresent()); |
389 | 388 |
390 // We should have had a device announced. | 389 // We should have had a device announced. |
391 EXPECT_EQ(2, observer.device_added_count()); | 390 EXPECT_EQ(2, observer.device_added_count()); |
392 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 391 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
393 observer.last_device_address()); | 392 observer.last_device_address()); |
394 | 393 |
395 // Other callbacks shouldn't be called if the values are false. | 394 // Other callbacks shouldn't be called if the values are false. |
396 EXPECT_EQ(0, observer.powered_changed_count()); | 395 EXPECT_EQ(0, observer.powered_changed_count()); |
397 EXPECT_EQ(0, observer.discovering_changed_count()); | 396 EXPECT_EQ(0, observer.discovering_changed_count()); |
398 EXPECT_FALSE(adapter_->IsPowered()); | 397 EXPECT_FALSE(adapter_->IsPowered()); |
399 EXPECT_FALSE(adapter_->IsDiscovering()); | 398 EXPECT_FALSE(adapter_->IsDiscovering()); |
400 } | 399 } |
401 | 400 |
402 TEST_F(BluetoothChromeOSTest, BecomeNotPresent) { | 401 TEST_F(BluetoothBlueZTest, BecomeNotPresent) { |
403 GetAdapter(); | 402 GetAdapter(); |
404 ASSERT_TRUE(adapter_->IsPresent()); | 403 ASSERT_TRUE(adapter_->IsPresent()); |
405 | 404 |
406 // Install an observer; expect the AdapterPresentChanged to be called | 405 // Install an observer; expect the AdapterPresentChanged to be called |
407 // with false, and IsPresent() to return false. | 406 // with false, and IsPresent() to return false. |
408 TestBluetoothAdapterObserver observer(adapter_); | 407 TestBluetoothAdapterObserver observer(adapter_); |
409 | 408 |
410 fake_bluetooth_adapter_client_->SetVisible(false); | 409 fake_bluetooth_adapter_client_->SetVisible(false); |
411 | 410 |
412 EXPECT_EQ(1, observer.present_changed_count()); | 411 EXPECT_EQ(1, observer.present_changed_count()); |
413 EXPECT_FALSE(observer.last_present()); | 412 EXPECT_FALSE(observer.last_present()); |
414 | 413 |
415 EXPECT_FALSE(adapter_->IsPresent()); | 414 EXPECT_FALSE(adapter_->IsPresent()); |
416 | 415 |
417 // We should have had a device removed. | 416 // We should have had a device removed. |
418 EXPECT_EQ(2, observer.device_removed_count()); | 417 EXPECT_EQ(2, observer.device_removed_count()); |
419 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 418 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
420 observer.last_device_address()); | 419 observer.last_device_address()); |
421 | 420 |
422 // Other callbacks shouldn't be called since the values are false. | 421 // Other callbacks shouldn't be called since the values are false. |
423 EXPECT_EQ(0, observer.powered_changed_count()); | 422 EXPECT_EQ(0, observer.powered_changed_count()); |
424 EXPECT_EQ(0, observer.discovering_changed_count()); | 423 EXPECT_EQ(0, observer.discovering_changed_count()); |
425 EXPECT_FALSE(adapter_->IsPowered()); | 424 EXPECT_FALSE(adapter_->IsPowered()); |
426 EXPECT_FALSE(adapter_->IsDiscovering()); | 425 EXPECT_FALSE(adapter_->IsDiscovering()); |
427 } | 426 } |
428 | 427 |
429 TEST_F(BluetoothChromeOSTest, SecondAdapter) { | 428 TEST_F(BluetoothBlueZTest, SecondAdapter) { |
430 GetAdapter(); | 429 GetAdapter(); |
431 ASSERT_TRUE(adapter_->IsPresent()); | 430 ASSERT_TRUE(adapter_->IsPresent()); |
432 | 431 |
433 // Install an observer, then add a second adapter. Nothing should change, | 432 // Install an observer, then add a second adapter. Nothing should change, |
434 // we ignore the second adapter. | 433 // we ignore the second adapter. |
435 TestBluetoothAdapterObserver observer(adapter_); | 434 TestBluetoothAdapterObserver observer(adapter_); |
436 | 435 |
437 fake_bluetooth_adapter_client_->SetSecondVisible(true); | 436 fake_bluetooth_adapter_client_->SetSecondVisible(true); |
438 | 437 |
439 EXPECT_EQ(0, observer.present_changed_count()); | 438 EXPECT_EQ(0, observer.present_changed_count()); |
(...skipping 25 matching lines...) Expand all Loading... |
465 observer.Reset(); | 464 observer.Reset(); |
466 | 465 |
467 // Removing the second adapter shouldn't set anything either. | 466 // Removing the second adapter shouldn't set anything either. |
468 fake_bluetooth_adapter_client_->SetSecondVisible(false); | 467 fake_bluetooth_adapter_client_->SetSecondVisible(false); |
469 | 468 |
470 EXPECT_EQ(0, observer.device_removed_count()); | 469 EXPECT_EQ(0, observer.device_removed_count()); |
471 EXPECT_EQ(0, observer.powered_changed_count()); | 470 EXPECT_EQ(0, observer.powered_changed_count()); |
472 EXPECT_EQ(0, observer.discovering_changed_count()); | 471 EXPECT_EQ(0, observer.discovering_changed_count()); |
473 } | 472 } |
474 | 473 |
475 TEST_F(BluetoothChromeOSTest, BecomePowered) { | 474 TEST_F(BluetoothBlueZTest, BecomePowered) { |
476 GetAdapter(); | 475 GetAdapter(); |
477 ASSERT_FALSE(adapter_->IsPowered()); | 476 ASSERT_FALSE(adapter_->IsPowered()); |
478 | 477 |
479 // Install an observer; expect the AdapterPoweredChanged to be called | 478 // Install an observer; expect the AdapterPoweredChanged to be called |
480 // with true, and IsPowered() to return true. | 479 // with true, and IsPowered() to return true. |
481 TestBluetoothAdapterObserver observer(adapter_); | 480 TestBluetoothAdapterObserver observer(adapter_); |
482 | 481 |
483 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 482 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
484 EXPECT_EQ(1, callback_count_); | 483 EXPECT_EQ(1, callback_count_); |
485 EXPECT_EQ(0, error_callback_count_); | 484 EXPECT_EQ(0, error_callback_count_); |
486 | 485 |
487 EXPECT_EQ(1, observer.powered_changed_count()); | 486 EXPECT_EQ(1, observer.powered_changed_count()); |
488 EXPECT_TRUE(observer.last_powered()); | 487 EXPECT_TRUE(observer.last_powered()); |
489 | 488 |
490 EXPECT_TRUE(adapter_->IsPowered()); | 489 EXPECT_TRUE(adapter_->IsPowered()); |
491 } | 490 } |
492 | 491 |
493 TEST_F(BluetoothChromeOSTest, BecomeNotPowered) { | 492 TEST_F(BluetoothBlueZTest, BecomeNotPowered) { |
494 GetAdapter(); | 493 GetAdapter(); |
495 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 494 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
496 EXPECT_EQ(1, callback_count_); | 495 EXPECT_EQ(1, callback_count_); |
497 EXPECT_EQ(0, error_callback_count_); | 496 EXPECT_EQ(0, error_callback_count_); |
498 callback_count_ = 0; | 497 callback_count_ = 0; |
499 | 498 |
500 ASSERT_TRUE(adapter_->IsPowered()); | 499 ASSERT_TRUE(adapter_->IsPowered()); |
501 | 500 |
502 // Install an observer; expect the AdapterPoweredChanged to be called | 501 // Install an observer; expect the AdapterPoweredChanged to be called |
503 // with false, and IsPowered() to return false. | 502 // with false, and IsPowered() to return false. |
504 TestBluetoothAdapterObserver observer(adapter_); | 503 TestBluetoothAdapterObserver observer(adapter_); |
505 | 504 |
506 adapter_->SetPowered(false, GetCallback(), GetErrorCallback()); | 505 adapter_->SetPowered(false, GetCallback(), GetErrorCallback()); |
507 EXPECT_EQ(1, callback_count_); | 506 EXPECT_EQ(1, callback_count_); |
508 EXPECT_EQ(0, error_callback_count_); | 507 EXPECT_EQ(0, error_callback_count_); |
509 | 508 |
510 EXPECT_EQ(1, observer.powered_changed_count()); | 509 EXPECT_EQ(1, observer.powered_changed_count()); |
511 EXPECT_FALSE(observer.last_powered()); | 510 EXPECT_FALSE(observer.last_powered()); |
512 | 511 |
513 EXPECT_FALSE(adapter_->IsPowered()); | 512 EXPECT_FALSE(adapter_->IsPowered()); |
514 } | 513 } |
515 | 514 |
516 TEST_F(BluetoothChromeOSTest, SetPoweredWhenNotPresent) { | 515 TEST_F(BluetoothBlueZTest, SetPoweredWhenNotPresent) { |
517 GetAdapter(); | 516 GetAdapter(); |
518 ASSERT_TRUE(adapter_->IsPresent()); | 517 ASSERT_TRUE(adapter_->IsPresent()); |
519 | 518 |
520 // Install an observer; expect the AdapterPresentChanged to be called | 519 // Install an observer; expect the AdapterPresentChanged to be called |
521 // with false, and IsPresent() to return false. | 520 // with false, and IsPresent() to return false. |
522 TestBluetoothAdapterObserver observer(adapter_); | 521 TestBluetoothAdapterObserver observer(adapter_); |
523 | 522 |
524 fake_bluetooth_adapter_client_->SetVisible(false); | 523 fake_bluetooth_adapter_client_->SetVisible(false); |
525 | 524 |
526 EXPECT_EQ(1, observer.present_changed_count()); | 525 EXPECT_EQ(1, observer.present_changed_count()); |
527 EXPECT_FALSE(observer.last_present()); | 526 EXPECT_FALSE(observer.last_present()); |
528 | 527 |
529 EXPECT_FALSE(adapter_->IsPresent()); | 528 EXPECT_FALSE(adapter_->IsPresent()); |
530 EXPECT_FALSE(adapter_->IsPowered()); | 529 EXPECT_FALSE(adapter_->IsPowered()); |
531 | 530 |
532 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 531 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
533 EXPECT_EQ(0, callback_count_); | 532 EXPECT_EQ(0, callback_count_); |
534 EXPECT_EQ(1, error_callback_count_); | 533 EXPECT_EQ(1, error_callback_count_); |
535 | 534 |
536 EXPECT_EQ(0, observer.powered_changed_count()); | 535 EXPECT_EQ(0, observer.powered_changed_count()); |
537 EXPECT_FALSE(observer.last_powered()); | 536 EXPECT_FALSE(observer.last_powered()); |
538 | 537 |
539 EXPECT_FALSE(adapter_->IsPowered()); | 538 EXPECT_FALSE(adapter_->IsPowered()); |
540 } | 539 } |
541 | 540 |
542 TEST_F(BluetoothChromeOSTest, ChangeAdapterName) { | 541 TEST_F(BluetoothBlueZTest, ChangeAdapterName) { |
543 GetAdapter(); | 542 GetAdapter(); |
544 | 543 |
545 static const std::string new_name(".__."); | 544 static const std::string new_name(".__."); |
546 | 545 |
547 adapter_->SetName(new_name, GetCallback(), GetErrorCallback()); | 546 adapter_->SetName(new_name, GetCallback(), GetErrorCallback()); |
548 EXPECT_EQ(1, callback_count_); | 547 EXPECT_EQ(1, callback_count_); |
549 EXPECT_EQ(0, error_callback_count_); | 548 EXPECT_EQ(0, error_callback_count_); |
550 | 549 |
551 EXPECT_EQ(new_name, adapter_->GetName()); | 550 EXPECT_EQ(new_name, adapter_->GetName()); |
552 } | 551 } |
553 | 552 |
554 TEST_F(BluetoothChromeOSTest, ChangeAdapterNameWhenNotPresent) { | 553 TEST_F(BluetoothBlueZTest, ChangeAdapterNameWhenNotPresent) { |
555 GetAdapter(); | 554 GetAdapter(); |
556 ASSERT_TRUE(adapter_->IsPresent()); | 555 ASSERT_TRUE(adapter_->IsPresent()); |
557 | 556 |
558 // Install an observer; expect the AdapterPresentChanged to be called | 557 // Install an observer; expect the AdapterPresentChanged to be called |
559 // with false, and IsPresent() to return false. | 558 // with false, and IsPresent() to return false. |
560 TestBluetoothAdapterObserver observer(adapter_); | 559 TestBluetoothAdapterObserver observer(adapter_); |
561 | 560 |
562 fake_bluetooth_adapter_client_->SetVisible(false); | 561 fake_bluetooth_adapter_client_->SetVisible(false); |
563 | 562 |
564 EXPECT_EQ(1, observer.present_changed_count()); | 563 EXPECT_EQ(1, observer.present_changed_count()); |
565 EXPECT_FALSE(observer.last_present()); | 564 EXPECT_FALSE(observer.last_present()); |
566 | 565 |
567 EXPECT_FALSE(adapter_->IsPresent()); | 566 EXPECT_FALSE(adapter_->IsPresent()); |
568 EXPECT_FALSE(adapter_->IsPowered()); | 567 EXPECT_FALSE(adapter_->IsPowered()); |
569 | 568 |
570 adapter_->SetName("^o^", GetCallback(), GetErrorCallback()); | 569 adapter_->SetName("^o^", GetCallback(), GetErrorCallback()); |
571 EXPECT_EQ(0, callback_count_); | 570 EXPECT_EQ(0, callback_count_); |
572 EXPECT_EQ(1, error_callback_count_); | 571 EXPECT_EQ(1, error_callback_count_); |
573 | 572 |
574 EXPECT_EQ("", adapter_->GetName()); | 573 EXPECT_EQ("", adapter_->GetName()); |
575 } | 574 } |
576 | 575 |
577 TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) { | 576 TEST_F(BluetoothBlueZTest, BecomeDiscoverable) { |
578 GetAdapter(); | 577 GetAdapter(); |
579 ASSERT_FALSE(adapter_->IsDiscoverable()); | 578 ASSERT_FALSE(adapter_->IsDiscoverable()); |
580 | 579 |
581 // Install an observer; expect the AdapterDiscoverableChanged to be called | 580 // Install an observer; expect the AdapterDiscoverableChanged to be called |
582 // with true, and IsDiscoverable() to return true. | 581 // with true, and IsDiscoverable() to return true. |
583 TestBluetoothAdapterObserver observer(adapter_); | 582 TestBluetoothAdapterObserver observer(adapter_); |
584 | 583 |
585 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); | 584 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
586 EXPECT_EQ(1, callback_count_); | 585 EXPECT_EQ(1, callback_count_); |
587 EXPECT_EQ(0, error_callback_count_); | 586 EXPECT_EQ(0, error_callback_count_); |
588 | 587 |
589 EXPECT_EQ(1, observer.discoverable_changed_count()); | 588 EXPECT_EQ(1, observer.discoverable_changed_count()); |
590 | 589 |
591 EXPECT_TRUE(adapter_->IsDiscoverable()); | 590 EXPECT_TRUE(adapter_->IsDiscoverable()); |
592 } | 591 } |
593 | 592 |
594 TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) { | 593 TEST_F(BluetoothBlueZTest, BecomeNotDiscoverable) { |
595 GetAdapter(); | 594 GetAdapter(); |
596 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); | 595 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
597 EXPECT_EQ(1, callback_count_); | 596 EXPECT_EQ(1, callback_count_); |
598 EXPECT_EQ(0, error_callback_count_); | 597 EXPECT_EQ(0, error_callback_count_); |
599 callback_count_ = 0; | 598 callback_count_ = 0; |
600 | 599 |
601 ASSERT_TRUE(adapter_->IsDiscoverable()); | 600 ASSERT_TRUE(adapter_->IsDiscoverable()); |
602 | 601 |
603 // Install an observer; expect the AdapterDiscoverableChanged to be called | 602 // Install an observer; expect the AdapterDiscoverableChanged to be called |
604 // with false, and IsDiscoverable() to return false. | 603 // with false, and IsDiscoverable() to return false. |
605 TestBluetoothAdapterObserver observer(adapter_); | 604 TestBluetoothAdapterObserver observer(adapter_); |
606 | 605 |
607 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback()); | 606 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback()); |
608 EXPECT_EQ(1, callback_count_); | 607 EXPECT_EQ(1, callback_count_); |
609 EXPECT_EQ(0, error_callback_count_); | 608 EXPECT_EQ(0, error_callback_count_); |
610 | 609 |
611 EXPECT_EQ(1, observer.discoverable_changed_count()); | 610 EXPECT_EQ(1, observer.discoverable_changed_count()); |
612 | 611 |
613 EXPECT_FALSE(adapter_->IsDiscoverable()); | 612 EXPECT_FALSE(adapter_->IsDiscoverable()); |
614 } | 613 } |
615 | 614 |
616 TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) { | 615 TEST_F(BluetoothBlueZTest, SetDiscoverableWhenNotPresent) { |
617 GetAdapter(); | 616 GetAdapter(); |
618 ASSERT_TRUE(adapter_->IsPresent()); | 617 ASSERT_TRUE(adapter_->IsPresent()); |
619 ASSERT_FALSE(adapter_->IsDiscoverable()); | 618 ASSERT_FALSE(adapter_->IsDiscoverable()); |
620 | 619 |
621 // Install an observer; expect the AdapterDiscoverableChanged to be called | 620 // Install an observer; expect the AdapterDiscoverableChanged to be called |
622 // with true, and IsDiscoverable() to return true. | 621 // with true, and IsDiscoverable() to return true. |
623 TestBluetoothAdapterObserver observer(adapter_); | 622 TestBluetoothAdapterObserver observer(adapter_); |
624 | 623 |
625 fake_bluetooth_adapter_client_->SetVisible(false); | 624 fake_bluetooth_adapter_client_->SetVisible(false); |
626 | 625 |
627 EXPECT_EQ(1, observer.present_changed_count()); | 626 EXPECT_EQ(1, observer.present_changed_count()); |
628 EXPECT_FALSE(observer.last_present()); | 627 EXPECT_FALSE(observer.last_present()); |
629 | 628 |
630 EXPECT_FALSE(adapter_->IsPresent()); | 629 EXPECT_FALSE(adapter_->IsPresent()); |
631 EXPECT_FALSE(adapter_->IsDiscoverable()); | 630 EXPECT_FALSE(adapter_->IsDiscoverable()); |
632 | 631 |
633 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); | 632 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
634 EXPECT_EQ(0, callback_count_); | 633 EXPECT_EQ(0, callback_count_); |
635 EXPECT_EQ(1, error_callback_count_); | 634 EXPECT_EQ(1, error_callback_count_); |
636 | 635 |
637 EXPECT_EQ(0, observer.discoverable_changed_count()); | 636 EXPECT_EQ(0, observer.discoverable_changed_count()); |
638 | 637 |
639 EXPECT_FALSE(adapter_->IsDiscoverable()); | 638 EXPECT_FALSE(adapter_->IsDiscoverable()); |
640 } | 639 } |
641 | 640 |
642 TEST_F(BluetoothChromeOSTest, StopDiscovery) { | 641 TEST_F(BluetoothBlueZTest, StopDiscovery) { |
643 GetAdapter(); | 642 GetAdapter(); |
644 | 643 |
645 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 644 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
646 adapter_->StartDiscoverySession( | 645 adapter_->StartDiscoverySession( |
647 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 646 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
648 base::Unretained(this)), | 647 base::Unretained(this)), |
649 GetErrorCallback()); | 648 GetErrorCallback()); |
650 message_loop_.Run(); | 649 message_loop_.Run(); |
651 EXPECT_EQ(2, callback_count_); | 650 EXPECT_EQ(2, callback_count_); |
652 EXPECT_EQ(0, error_callback_count_); | 651 EXPECT_EQ(0, error_callback_count_); |
653 callback_count_ = 0; | 652 callback_count_ = 0; |
654 | 653 |
655 ASSERT_TRUE(adapter_->IsPowered()); | 654 ASSERT_TRUE(adapter_->IsPowered()); |
656 ASSERT_TRUE(adapter_->IsDiscovering()); | 655 ASSERT_TRUE(adapter_->IsDiscovering()); |
657 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 656 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
(...skipping 13 matching lines...) Expand all Loading... |
671 EXPECT_FALSE(observer.last_discovering()); | 670 EXPECT_FALSE(observer.last_discovering()); |
672 | 671 |
673 EXPECT_FALSE(adapter_->IsDiscovering()); | 672 EXPECT_FALSE(adapter_->IsDiscovering()); |
674 discovery_sessions_.clear(); | 673 discovery_sessions_.clear(); |
675 callback_count_ = 0; | 674 callback_count_ = 0; |
676 | 675 |
677 // Test that the Stop callbacks get called even if the | 676 // Test that the Stop callbacks get called even if the |
678 // BluetoothDiscoverySession objects gets deleted | 677 // BluetoothDiscoverySession objects gets deleted |
679 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 678 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
680 adapter_->StartDiscoverySession( | 679 adapter_->StartDiscoverySession( |
681 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 680 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
682 base::Unretained(this)), | 681 base::Unretained(this)), |
683 GetErrorCallback()); | 682 GetErrorCallback()); |
684 message_loop_.Run(); | 683 message_loop_.Run(); |
685 EXPECT_EQ(2, callback_count_); | 684 EXPECT_EQ(2, callback_count_); |
686 EXPECT_EQ(0, error_callback_count_); | 685 EXPECT_EQ(0, error_callback_count_); |
687 callback_count_ = 0; | 686 callback_count_ = 0; |
688 ASSERT_TRUE(adapter_->IsPowered()); | 687 ASSERT_TRUE(adapter_->IsPowered()); |
689 ASSERT_TRUE(adapter_->IsDiscovering()); | 688 ASSERT_TRUE(adapter_->IsDiscovering()); |
690 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 689 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
691 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 690 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
692 | 691 |
693 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); | 692 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
694 discovery_sessions_.clear(); | 693 discovery_sessions_.clear(); |
695 | 694 |
696 message_loop_.Run(); | 695 message_loop_.Run(); |
697 EXPECT_EQ(1, callback_count_); | 696 EXPECT_EQ(1, callback_count_); |
698 EXPECT_EQ(0, error_callback_count_); | 697 EXPECT_EQ(0, error_callback_count_); |
699 } | 698 } |
700 | 699 |
701 TEST_F(BluetoothChromeOSTest, Discovery) { | 700 TEST_F(BluetoothBlueZTest, Discovery) { |
702 // Test a simulated discovery session. | 701 // Test a simulated discovery session. |
703 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 702 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
704 GetAdapter(); | 703 GetAdapter(); |
705 | 704 |
706 TestBluetoothAdapterObserver observer(adapter_); | 705 TestBluetoothAdapterObserver observer(adapter_); |
707 | 706 |
708 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 707 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
709 adapter_->StartDiscoverySession( | 708 adapter_->StartDiscoverySession( |
710 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 709 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
711 base::Unretained(this)), | 710 base::Unretained(this)), |
712 GetErrorCallback()); | 711 GetErrorCallback()); |
713 message_loop_.Run(); | 712 message_loop_.Run(); |
714 EXPECT_EQ(2, callback_count_); | 713 EXPECT_EQ(2, callback_count_); |
715 EXPECT_EQ(0, error_callback_count_); | 714 EXPECT_EQ(0, error_callback_count_); |
716 callback_count_ = 0; | 715 callback_count_ = 0; |
717 | 716 |
718 ASSERT_TRUE(adapter_->IsPowered()); | 717 ASSERT_TRUE(adapter_->IsPowered()); |
719 ASSERT_TRUE(adapter_->IsDiscovering()); | 718 ASSERT_TRUE(adapter_->IsDiscovering()); |
720 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 719 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
(...skipping 12 matching lines...) Expand all Loading... |
733 | 732 |
734 // Okay, let's run forward until a device is actually removed... | 733 // Okay, let's run forward until a device is actually removed... |
735 while (!observer.device_removed_count()) | 734 while (!observer.device_removed_count()) |
736 message_loop_.Run(); | 735 message_loop_.Run(); |
737 | 736 |
738 EXPECT_EQ(1, observer.device_removed_count()); | 737 EXPECT_EQ(1, observer.device_removed_count()); |
739 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress, | 738 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress, |
740 observer.last_device_address()); | 739 observer.last_device_address()); |
741 } | 740 } |
742 | 741 |
743 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { | 742 TEST_F(BluetoothBlueZTest, PoweredAndDiscovering) { |
744 GetAdapter(); | 743 GetAdapter(); |
745 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 744 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
746 adapter_->StartDiscoverySession( | 745 adapter_->StartDiscoverySession( |
747 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 746 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
748 base::Unretained(this)), | 747 base::Unretained(this)), |
749 GetErrorCallback()); | 748 GetErrorCallback()); |
750 message_loop_.Run(); | 749 message_loop_.Run(); |
751 EXPECT_EQ(2, callback_count_); | 750 EXPECT_EQ(2, callback_count_); |
752 EXPECT_EQ(0, error_callback_count_); | 751 EXPECT_EQ(0, error_callback_count_); |
753 callback_count_ = 0; | 752 callback_count_ = 0; |
754 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 753 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
755 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 754 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
756 | 755 |
757 // Stop the timers that the simulation uses | 756 // Stop the timers that the simulation uses |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 EXPECT_FALSE(observer.last_powered()); | 798 EXPECT_FALSE(observer.last_powered()); |
800 EXPECT_FALSE(adapter_->IsPowered()); | 799 EXPECT_FALSE(adapter_->IsPowered()); |
801 | 800 |
802 EXPECT_EQ(1, observer.discovering_changed_count()); | 801 EXPECT_EQ(1, observer.discovering_changed_count()); |
803 EXPECT_FALSE(observer.last_discovering()); | 802 EXPECT_FALSE(observer.last_discovering()); |
804 EXPECT_FALSE(adapter_->IsDiscovering()); | 803 EXPECT_FALSE(adapter_->IsDiscovering()); |
805 } | 804 } |
806 | 805 |
807 // This unit test asserts that the basic reference counting logic works | 806 // This unit test asserts that the basic reference counting logic works |
808 // correctly for discovery requests done via the BluetoothAdapter. | 807 // correctly for discovery requests done via the BluetoothAdapter. |
809 TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) { | 808 TEST_F(BluetoothBlueZTest, MultipleDiscoverySessions) { |
810 GetAdapter(); | 809 GetAdapter(); |
811 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 810 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
812 EXPECT_EQ(1, callback_count_); | 811 EXPECT_EQ(1, callback_count_); |
813 EXPECT_EQ(0, error_callback_count_); | 812 EXPECT_EQ(0, error_callback_count_); |
814 EXPECT_TRUE(adapter_->IsPowered()); | 813 EXPECT_TRUE(adapter_->IsPowered()); |
815 callback_count_ = 0; | 814 callback_count_ = 0; |
816 | 815 |
817 TestBluetoothAdapterObserver observer(adapter_); | 816 TestBluetoothAdapterObserver observer(adapter_); |
818 | 817 |
819 EXPECT_EQ(0, observer.discovering_changed_count()); | 818 EXPECT_EQ(0, observer.discovering_changed_count()); |
820 EXPECT_FALSE(observer.last_discovering()); | 819 EXPECT_FALSE(observer.last_discovering()); |
821 EXPECT_FALSE(adapter_->IsDiscovering()); | 820 EXPECT_FALSE(adapter_->IsDiscovering()); |
822 | 821 |
823 // Request device discovery 3 times. | 822 // Request device discovery 3 times. |
824 for (int i = 0; i < 3; i++) { | 823 for (int i = 0; i < 3; i++) { |
825 adapter_->StartDiscoverySession( | 824 adapter_->StartDiscoverySession( |
826 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 825 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
827 base::Unretained(this)), | 826 base::Unretained(this)), |
828 GetErrorCallback()); | 827 GetErrorCallback()); |
829 } | 828 } |
830 // Run only once, as there should have been one D-Bus call. | 829 // Run only once, as there should have been one D-Bus call. |
831 message_loop_.Run(); | 830 message_loop_.Run(); |
832 | 831 |
833 // The observer should have received the discovering changed event exactly | 832 // The observer should have received the discovering changed event exactly |
834 // once, the success callback should have been called 3 times and the adapter | 833 // once, the success callback should have been called 3 times and the adapter |
835 // should be discovering. | 834 // should be discovering. |
836 EXPECT_EQ(1, observer.discovering_changed_count()); | 835 EXPECT_EQ(1, observer.discovering_changed_count()); |
(...skipping 17 matching lines...) Expand all Loading... |
854 EXPECT_TRUE(observer.last_discovering()); | 853 EXPECT_TRUE(observer.last_discovering()); |
855 EXPECT_TRUE(adapter_->IsDiscovering()); | 854 EXPECT_TRUE(adapter_->IsDiscovering()); |
856 EXPECT_TRUE(adapter_->IsDiscovering()); | 855 EXPECT_TRUE(adapter_->IsDiscovering()); |
857 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 856 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
858 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); | 857 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); |
859 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); | 858 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); |
860 | 859 |
861 // Request device discovery 3 times. | 860 // Request device discovery 3 times. |
862 for (int i = 0; i < 3; i++) { | 861 for (int i = 0; i < 3; i++) { |
863 adapter_->StartDiscoverySession( | 862 adapter_->StartDiscoverySession( |
864 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 863 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
865 base::Unretained(this)), | 864 base::Unretained(this)), |
866 GetErrorCallback()); | 865 GetErrorCallback()); |
867 } | 866 } |
868 | 867 |
869 // The observer should have received no additional discovering changed events, | 868 // The observer should have received no additional discovering changed events, |
870 // the success callback should have been called 3 times and the adapter should | 869 // the success callback should have been called 3 times and the adapter should |
871 // still be discovering. | 870 // still be discovering. |
872 EXPECT_EQ(1, observer.discovering_changed_count()); | 871 EXPECT_EQ(1, observer.discovering_changed_count()); |
873 EXPECT_EQ(8, callback_count_); | 872 EXPECT_EQ(8, callback_count_); |
874 EXPECT_EQ(0, error_callback_count_); | 873 EXPECT_EQ(0, error_callback_count_); |
(...skipping 28 matching lines...) Expand all Loading... |
903 EXPECT_EQ(2, observer.discovering_changed_count()); | 902 EXPECT_EQ(2, observer.discovering_changed_count()); |
904 EXPECT_EQ(12, callback_count_); | 903 EXPECT_EQ(12, callback_count_); |
905 EXPECT_EQ(1, error_callback_count_); | 904 EXPECT_EQ(1, error_callback_count_); |
906 EXPECT_FALSE(observer.last_discovering()); | 905 EXPECT_FALSE(observer.last_discovering()); |
907 EXPECT_FALSE(adapter_->IsDiscovering()); | 906 EXPECT_FALSE(adapter_->IsDiscovering()); |
908 } | 907 } |
909 | 908 |
910 // This unit test asserts that the reference counting logic works correctly in | 909 // This unit test asserts that the reference counting logic works correctly in |
911 // the cases when the adapter gets reset and D-Bus calls are made outside of | 910 // the cases when the adapter gets reset and D-Bus calls are made outside of |
912 // the BluetoothAdapter. | 911 // the BluetoothAdapter. |
913 TEST_F(BluetoothChromeOSTest, | 912 TEST_F(BluetoothBlueZTest, UnexpectedChangesDuringMultipleDiscoverySessions) { |
914 UnexpectedChangesDuringMultipleDiscoverySessions) { | |
915 GetAdapter(); | 913 GetAdapter(); |
916 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 914 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
917 EXPECT_EQ(1, callback_count_); | 915 EXPECT_EQ(1, callback_count_); |
918 EXPECT_EQ(0, error_callback_count_); | 916 EXPECT_EQ(0, error_callback_count_); |
919 EXPECT_TRUE(adapter_->IsPowered()); | 917 EXPECT_TRUE(adapter_->IsPowered()); |
920 callback_count_ = 0; | 918 callback_count_ = 0; |
921 | 919 |
922 TestBluetoothAdapterObserver observer(adapter_); | 920 TestBluetoothAdapterObserver observer(adapter_); |
923 | 921 |
924 EXPECT_EQ(0, observer.discovering_changed_count()); | 922 EXPECT_EQ(0, observer.discovering_changed_count()); |
925 EXPECT_FALSE(observer.last_discovering()); | 923 EXPECT_FALSE(observer.last_discovering()); |
926 EXPECT_FALSE(adapter_->IsDiscovering()); | 924 EXPECT_FALSE(adapter_->IsDiscovering()); |
927 | 925 |
928 // Request device discovery 3 times. | 926 // Request device discovery 3 times. |
929 for (int i = 0; i < 3; i++) { | 927 for (int i = 0; i < 3; i++) { |
930 adapter_->StartDiscoverySession( | 928 adapter_->StartDiscoverySession( |
931 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 929 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
932 base::Unretained(this)), | 930 base::Unretained(this)), |
933 GetErrorCallback()); | 931 GetErrorCallback()); |
934 } | 932 } |
935 // Run only once, as there should have been one D-Bus call. | 933 // Run only once, as there should have been one D-Bus call. |
936 message_loop_.Run(); | 934 message_loop_.Run(); |
937 | 935 |
938 // The observer should have received the discovering changed event exactly | 936 // The observer should have received the discovering changed event exactly |
939 // once, the success callback should have been called 3 times and the adapter | 937 // once, the success callback should have been called 3 times and the adapter |
940 // should be discovering. | 938 // should be discovering. |
941 EXPECT_EQ(1, observer.discovering_changed_count()); | 939 EXPECT_EQ(1, observer.discovering_changed_count()); |
(...skipping 16 matching lines...) Expand all Loading... |
958 // Stop device discovery behind the adapter. The adapter and the observer | 956 // Stop device discovery behind the adapter. The adapter and the observer |
959 // should be notified of the change and the reference count should be reset. | 957 // should be notified of the change and the reference count should be reset. |
960 // Even though bluez::FakeBluetoothAdapterClient does its own reference | 958 // Even though bluez::FakeBluetoothAdapterClient does its own reference |
961 // counting and | 959 // counting and |
962 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the | 960 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the |
963 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single | 961 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single |
964 // call to | 962 // call to |
965 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work. | 963 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work. |
966 fake_bluetooth_adapter_client_->StopDiscovery( | 964 fake_bluetooth_adapter_client_->StopDiscovery( |
967 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 965 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
968 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 966 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
969 base::Unretained(this))); | 967 base::Unretained(this))); |
970 message_loop_.Run(); | 968 message_loop_.Run(); |
971 EXPECT_EQ(2, observer.discovering_changed_count()); | 969 EXPECT_EQ(2, observer.discovering_changed_count()); |
972 EXPECT_EQ(4, callback_count_); | 970 EXPECT_EQ(4, callback_count_); |
973 EXPECT_EQ(0, error_callback_count_); | 971 EXPECT_EQ(0, error_callback_count_); |
974 EXPECT_FALSE(observer.last_discovering()); | 972 EXPECT_FALSE(observer.last_discovering()); |
975 EXPECT_FALSE(adapter_->IsDiscovering()); | 973 EXPECT_FALSE(adapter_->IsDiscovering()); |
976 | 974 |
977 // All discovery session instances should have been updated. | 975 // All discovery session instances should have been updated. |
978 for (int i = 0; i < 3; i++) | 976 for (int i = 0; i < 3; i++) |
979 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); | 977 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); |
980 discovery_sessions_.clear(); | 978 discovery_sessions_.clear(); |
981 | 979 |
982 // It should be possible to successfully start discovery. | 980 // It should be possible to successfully start discovery. |
983 for (int i = 0; i < 2; i++) { | 981 for (int i = 0; i < 2; i++) { |
984 adapter_->StartDiscoverySession( | 982 adapter_->StartDiscoverySession( |
985 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 983 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
986 base::Unretained(this)), | 984 base::Unretained(this)), |
987 GetErrorCallback()); | 985 GetErrorCallback()); |
988 } | 986 } |
989 // Run only once, as there should have been one D-Bus call. | 987 // Run only once, as there should have been one D-Bus call. |
990 message_loop_.Run(); | 988 message_loop_.Run(); |
991 EXPECT_EQ(3, observer.discovering_changed_count()); | 989 EXPECT_EQ(3, observer.discovering_changed_count()); |
992 EXPECT_EQ(6, callback_count_); | 990 EXPECT_EQ(6, callback_count_); |
993 EXPECT_EQ(0, error_callback_count_); | 991 EXPECT_EQ(0, error_callback_count_); |
994 EXPECT_TRUE(observer.last_discovering()); | 992 EXPECT_TRUE(observer.last_discovering()); |
995 EXPECT_TRUE(adapter_->IsDiscovering()); | 993 EXPECT_TRUE(adapter_->IsDiscovering()); |
(...skipping 27 matching lines...) Expand all Loading... |
1023 EXPECT_EQ(0, error_callback_count_); | 1021 EXPECT_EQ(0, error_callback_count_); |
1024 EXPECT_TRUE(observer.last_discovering()); | 1022 EXPECT_TRUE(observer.last_discovering()); |
1025 EXPECT_TRUE(adapter_->IsDiscovering()); | 1023 EXPECT_TRUE(adapter_->IsDiscovering()); |
1026 | 1024 |
1027 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient | 1025 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient |
1028 // has | 1026 // has |
1029 // a reference count that is equal to 1. Pretend that this was done by an | 1027 // a reference count that is equal to 1. Pretend that this was done by an |
1030 // application other than us. Starting and stopping discovery will succeed | 1028 // application other than us. Starting and stopping discovery will succeed |
1031 // but it won't cause the discovery state to change. | 1029 // but it won't cause the discovery state to change. |
1032 adapter_->StartDiscoverySession( | 1030 adapter_->StartDiscoverySession( |
1033 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1031 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1034 base::Unretained(this)), | 1032 base::Unretained(this)), |
1035 GetErrorCallback()); | 1033 GetErrorCallback()); |
1036 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1034 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
1037 EXPECT_EQ(5, observer.discovering_changed_count()); | 1035 EXPECT_EQ(5, observer.discovering_changed_count()); |
1038 EXPECT_EQ(7, callback_count_); | 1036 EXPECT_EQ(7, callback_count_); |
1039 EXPECT_EQ(0, error_callback_count_); | 1037 EXPECT_EQ(0, error_callback_count_); |
1040 EXPECT_TRUE(observer.last_discovering()); | 1038 EXPECT_TRUE(observer.last_discovering()); |
1041 EXPECT_TRUE(adapter_->IsDiscovering()); | 1039 EXPECT_TRUE(adapter_->IsDiscovering()); |
1042 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1040 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1043 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1041 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
1044 | 1042 |
1045 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); | 1043 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
1046 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1044 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
1047 EXPECT_EQ(5, observer.discovering_changed_count()); | 1045 EXPECT_EQ(5, observer.discovering_changed_count()); |
1048 EXPECT_EQ(8, callback_count_); | 1046 EXPECT_EQ(8, callback_count_); |
1049 EXPECT_EQ(0, error_callback_count_); | 1047 EXPECT_EQ(0, error_callback_count_); |
1050 EXPECT_TRUE(observer.last_discovering()); | 1048 EXPECT_TRUE(observer.last_discovering()); |
1051 EXPECT_TRUE(adapter_->IsDiscovering()); | 1049 EXPECT_TRUE(adapter_->IsDiscovering()); |
1052 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1050 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
1053 discovery_sessions_.clear(); | 1051 discovery_sessions_.clear(); |
1054 | 1052 |
1055 // Start discovery again. | 1053 // Start discovery again. |
1056 adapter_->StartDiscoverySession( | 1054 adapter_->StartDiscoverySession( |
1057 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1055 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1058 base::Unretained(this)), | 1056 base::Unretained(this)), |
1059 GetErrorCallback()); | 1057 GetErrorCallback()); |
1060 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1058 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
1061 EXPECT_EQ(5, observer.discovering_changed_count()); | 1059 EXPECT_EQ(5, observer.discovering_changed_count()); |
1062 EXPECT_EQ(9, callback_count_); | 1060 EXPECT_EQ(9, callback_count_); |
1063 EXPECT_EQ(0, error_callback_count_); | 1061 EXPECT_EQ(0, error_callback_count_); |
1064 EXPECT_TRUE(observer.last_discovering()); | 1062 EXPECT_TRUE(observer.last_discovering()); |
1065 EXPECT_TRUE(adapter_->IsDiscovering()); | 1063 EXPECT_TRUE(adapter_->IsDiscovering()); |
1066 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1064 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1067 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1065 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
1068 | 1066 |
1069 // Stop discovery via D-Bus. The fake client's reference count will drop but | 1067 // Stop discovery via D-Bus. The fake client's reference count will drop but |
1070 // the discovery state won't change since our BluetoothAdapter also just | 1068 // the discovery state won't change since our BluetoothAdapter also just |
1071 // requested it via D-Bus. | 1069 // requested it via D-Bus. |
1072 fake_bluetooth_adapter_client_->StopDiscovery( | 1070 fake_bluetooth_adapter_client_->StopDiscovery( |
1073 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 1071 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
1074 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1072 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
1075 base::Unretained(this))); | 1073 base::Unretained(this))); |
1076 message_loop_.Run(); | 1074 message_loop_.Run(); |
1077 EXPECT_EQ(5, observer.discovering_changed_count()); | 1075 EXPECT_EQ(5, observer.discovering_changed_count()); |
1078 EXPECT_EQ(10, callback_count_); | 1076 EXPECT_EQ(10, callback_count_); |
1079 EXPECT_EQ(0, error_callback_count_); | 1077 EXPECT_EQ(0, error_callback_count_); |
1080 EXPECT_TRUE(observer.last_discovering()); | 1078 EXPECT_TRUE(observer.last_discovering()); |
1081 EXPECT_TRUE(adapter_->IsDiscovering()); | 1079 EXPECT_TRUE(adapter_->IsDiscovering()); |
1082 | 1080 |
1083 // Now end the discovery session. This should change the adapter's discovery | 1081 // Now end the discovery session. This should change the adapter's discovery |
1084 // state. | 1082 // state. |
1085 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); | 1083 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
1086 message_loop_.Run(); | 1084 message_loop_.Run(); |
1087 EXPECT_EQ(6, observer.discovering_changed_count()); | 1085 EXPECT_EQ(6, observer.discovering_changed_count()); |
1088 EXPECT_EQ(11, callback_count_); | 1086 EXPECT_EQ(11, callback_count_); |
1089 EXPECT_EQ(0, error_callback_count_); | 1087 EXPECT_EQ(0, error_callback_count_); |
1090 EXPECT_FALSE(observer.last_discovering()); | 1088 EXPECT_FALSE(observer.last_discovering()); |
1091 EXPECT_FALSE(adapter_->IsDiscovering()); | 1089 EXPECT_FALSE(adapter_->IsDiscovering()); |
1092 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1090 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
1093 } | 1091 } |
1094 | 1092 |
1095 TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) { | 1093 TEST_F(BluetoothBlueZTest, InvalidatedDiscoverySessions) { |
1096 GetAdapter(); | 1094 GetAdapter(); |
1097 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 1095 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
1098 EXPECT_EQ(1, callback_count_); | 1096 EXPECT_EQ(1, callback_count_); |
1099 EXPECT_EQ(0, error_callback_count_); | 1097 EXPECT_EQ(0, error_callback_count_); |
1100 EXPECT_TRUE(adapter_->IsPowered()); | 1098 EXPECT_TRUE(adapter_->IsPowered()); |
1101 callback_count_ = 0; | 1099 callback_count_ = 0; |
1102 | 1100 |
1103 TestBluetoothAdapterObserver observer(adapter_); | 1101 TestBluetoothAdapterObserver observer(adapter_); |
1104 | 1102 |
1105 EXPECT_EQ(0, observer.discovering_changed_count()); | 1103 EXPECT_EQ(0, observer.discovering_changed_count()); |
1106 EXPECT_FALSE(observer.last_discovering()); | 1104 EXPECT_FALSE(observer.last_discovering()); |
1107 EXPECT_FALSE(adapter_->IsDiscovering()); | 1105 EXPECT_FALSE(adapter_->IsDiscovering()); |
1108 | 1106 |
1109 // Request device discovery 3 times. | 1107 // Request device discovery 3 times. |
1110 for (int i = 0; i < 3; i++) { | 1108 for (int i = 0; i < 3; i++) { |
1111 adapter_->StartDiscoverySession( | 1109 adapter_->StartDiscoverySession( |
1112 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1110 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1113 base::Unretained(this)), | 1111 base::Unretained(this)), |
1114 GetErrorCallback()); | 1112 GetErrorCallback()); |
1115 } | 1113 } |
1116 // Run only once, as there should have been one D-Bus call. | 1114 // Run only once, as there should have been one D-Bus call. |
1117 message_loop_.Run(); | 1115 message_loop_.Run(); |
1118 | 1116 |
1119 // The observer should have received the discovering changed event exactly | 1117 // The observer should have received the discovering changed event exactly |
1120 // once, the success callback should have been called 3 times and the adapter | 1118 // once, the success callback should have been called 3 times and the adapter |
1121 // should be discovering. | 1119 // should be discovering. |
1122 EXPECT_EQ(1, observer.discovering_changed_count()); | 1120 EXPECT_EQ(1, observer.discovering_changed_count()); |
(...skipping 19 matching lines...) Expand all Loading... |
1142 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1140 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1143 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1141 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
1144 EXPECT_TRUE(adapter_->IsDiscovering()); | 1142 EXPECT_TRUE(adapter_->IsDiscovering()); |
1145 | 1143 |
1146 // Stop device discovery behind the adapter. The one active discovery session | 1144 // Stop device discovery behind the adapter. The one active discovery session |
1147 // should become inactive, but more importantly, we shouldn't run into any | 1145 // should become inactive, but more importantly, we shouldn't run into any |
1148 // memory errors as the sessions that we explicitly deleted should get | 1146 // memory errors as the sessions that we explicitly deleted should get |
1149 // cleaned up. | 1147 // cleaned up. |
1150 fake_bluetooth_adapter_client_->StopDiscovery( | 1148 fake_bluetooth_adapter_client_->StopDiscovery( |
1151 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 1149 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
1152 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1150 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
1153 base::Unretained(this))); | 1151 base::Unretained(this))); |
1154 message_loop_.Run(); | 1152 message_loop_.Run(); |
1155 EXPECT_EQ(2, observer.discovering_changed_count()); | 1153 EXPECT_EQ(2, observer.discovering_changed_count()); |
1156 EXPECT_EQ(4, callback_count_); | 1154 EXPECT_EQ(4, callback_count_); |
1157 EXPECT_EQ(0, error_callback_count_); | 1155 EXPECT_EQ(0, error_callback_count_); |
1158 EXPECT_FALSE(observer.last_discovering()); | 1156 EXPECT_FALSE(observer.last_discovering()); |
1159 EXPECT_FALSE(adapter_->IsDiscovering()); | 1157 EXPECT_FALSE(adapter_->IsDiscovering()); |
1160 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1158 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
1161 } | 1159 } |
1162 | 1160 |
1163 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { | 1161 TEST_F(BluetoothBlueZTest, QueuedDiscoveryRequests) { |
1164 GetAdapter(); | 1162 GetAdapter(); |
1165 | 1163 |
1166 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 1164 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
1167 EXPECT_EQ(1, callback_count_); | 1165 EXPECT_EQ(1, callback_count_); |
1168 EXPECT_EQ(0, error_callback_count_); | 1166 EXPECT_EQ(0, error_callback_count_); |
1169 EXPECT_TRUE(adapter_->IsPowered()); | 1167 EXPECT_TRUE(adapter_->IsPowered()); |
1170 callback_count_ = 0; | 1168 callback_count_ = 0; |
1171 | 1169 |
1172 TestBluetoothAdapterObserver observer(adapter_); | 1170 TestBluetoothAdapterObserver observer(adapter_); |
1173 | 1171 |
1174 EXPECT_EQ(0, observer.discovering_changed_count()); | 1172 EXPECT_EQ(0, observer.discovering_changed_count()); |
1175 EXPECT_FALSE(observer.last_discovering()); | 1173 EXPECT_FALSE(observer.last_discovering()); |
1176 EXPECT_FALSE(adapter_->IsDiscovering()); | 1174 EXPECT_FALSE(adapter_->IsDiscovering()); |
1177 | 1175 |
1178 // Request to start discovery. The call should be pending. | 1176 // Request to start discovery. The call should be pending. |
1179 adapter_->StartDiscoverySession( | 1177 adapter_->StartDiscoverySession( |
1180 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1178 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1181 base::Unretained(this)), | 1179 base::Unretained(this)), |
1182 GetErrorCallback()); | 1180 GetErrorCallback()); |
1183 EXPECT_EQ(0, callback_count_); | 1181 EXPECT_EQ(0, callback_count_); |
1184 | 1182 |
1185 fake_bluetooth_device_client_->EndDiscoverySimulation( | 1183 fake_bluetooth_device_client_->EndDiscoverySimulation( |
1186 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); | 1184 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); |
1187 | 1185 |
1188 // The underlying adapter has started discovery, but our call hasn't returned | 1186 // The underlying adapter has started discovery, but our call hasn't returned |
1189 // yet. | 1187 // yet. |
1190 EXPECT_EQ(1, observer.discovering_changed_count()); | 1188 EXPECT_EQ(1, observer.discovering_changed_count()); |
1191 EXPECT_TRUE(observer.last_discovering()); | 1189 EXPECT_TRUE(observer.last_discovering()); |
1192 EXPECT_TRUE(adapter_->IsDiscovering()); | 1190 EXPECT_TRUE(adapter_->IsDiscovering()); |
1193 EXPECT_TRUE(discovery_sessions_.empty()); | 1191 EXPECT_TRUE(discovery_sessions_.empty()); |
1194 | 1192 |
1195 // Request to start discovery twice. These should get queued and there should | 1193 // Request to start discovery twice. These should get queued and there should |
1196 // be no change in state. | 1194 // be no change in state. |
1197 for (int i = 0; i < 2; i++) { | 1195 for (int i = 0; i < 2; i++) { |
1198 adapter_->StartDiscoverySession( | 1196 adapter_->StartDiscoverySession( |
1199 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1197 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1200 base::Unretained(this)), | 1198 base::Unretained(this)), |
1201 GetErrorCallback()); | 1199 GetErrorCallback()); |
1202 } | 1200 } |
1203 EXPECT_EQ(0, callback_count_); | 1201 EXPECT_EQ(0, callback_count_); |
1204 EXPECT_EQ(0, error_callback_count_); | 1202 EXPECT_EQ(0, error_callback_count_); |
1205 EXPECT_EQ(1, observer.discovering_changed_count()); | 1203 EXPECT_EQ(1, observer.discovering_changed_count()); |
1206 EXPECT_TRUE(observer.last_discovering()); | 1204 EXPECT_TRUE(observer.last_discovering()); |
1207 EXPECT_TRUE(adapter_->IsDiscovering()); | 1205 EXPECT_TRUE(adapter_->IsDiscovering()); |
1208 EXPECT_TRUE(discovery_sessions_.empty()); | 1206 EXPECT_TRUE(discovery_sessions_.empty()); |
1209 | 1207 |
(...skipping 25 matching lines...) Expand all Loading... |
1235 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback()); | 1233 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback()); |
1236 EXPECT_EQ(5, callback_count_); | 1234 EXPECT_EQ(5, callback_count_); |
1237 EXPECT_EQ(1, error_callback_count_); | 1235 EXPECT_EQ(1, error_callback_count_); |
1238 EXPECT_EQ(2, observer.discovering_changed_count()); | 1236 EXPECT_EQ(2, observer.discovering_changed_count()); |
1239 EXPECT_FALSE(observer.last_discovering()); | 1237 EXPECT_FALSE(observer.last_discovering()); |
1240 EXPECT_FALSE(adapter_->IsDiscovering()); | 1238 EXPECT_FALSE(adapter_->IsDiscovering()); |
1241 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); | 1239 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); |
1242 | 1240 |
1243 // Request to start should get queued. | 1241 // Request to start should get queued. |
1244 adapter_->StartDiscoverySession( | 1242 adapter_->StartDiscoverySession( |
1245 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1243 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1246 base::Unretained(this)), | 1244 base::Unretained(this)), |
1247 GetErrorCallback()); | 1245 GetErrorCallback()); |
1248 EXPECT_EQ(5, callback_count_); | 1246 EXPECT_EQ(5, callback_count_); |
1249 EXPECT_EQ(1, error_callback_count_); | 1247 EXPECT_EQ(1, error_callback_count_); |
1250 EXPECT_EQ(2, observer.discovering_changed_count()); | 1248 EXPECT_EQ(2, observer.discovering_changed_count()); |
1251 EXPECT_FALSE(observer.last_discovering()); | 1249 EXPECT_FALSE(observer.last_discovering()); |
1252 EXPECT_FALSE(adapter_->IsDiscovering()); | 1250 EXPECT_FALSE(adapter_->IsDiscovering()); |
1253 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1251 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
1254 | 1252 |
1255 // Run the pending request. | 1253 // Run the pending request. |
(...skipping 11 matching lines...) Expand all Loading... |
1267 message_loop_.Run(); | 1265 message_loop_.Run(); |
1268 EXPECT_EQ(7, callback_count_); | 1266 EXPECT_EQ(7, callback_count_); |
1269 EXPECT_EQ(1, error_callback_count_); | 1267 EXPECT_EQ(1, error_callback_count_); |
1270 EXPECT_EQ(3, observer.discovering_changed_count()); | 1268 EXPECT_EQ(3, observer.discovering_changed_count()); |
1271 EXPECT_TRUE(observer.last_discovering()); | 1269 EXPECT_TRUE(observer.last_discovering()); |
1272 EXPECT_TRUE(adapter_->IsDiscovering()); | 1270 EXPECT_TRUE(adapter_->IsDiscovering()); |
1273 ASSERT_EQ((size_t)4, discovery_sessions_.size()); | 1271 ASSERT_EQ((size_t)4, discovery_sessions_.size()); |
1274 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); | 1272 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); |
1275 } | 1273 } |
1276 | 1274 |
1277 TEST_F(BluetoothChromeOSTest, StartDiscoverySession) { | 1275 TEST_F(BluetoothBlueZTest, StartDiscoverySession) { |
1278 GetAdapter(); | 1276 GetAdapter(); |
1279 | 1277 |
1280 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 1278 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
1281 EXPECT_EQ(1, callback_count_); | 1279 EXPECT_EQ(1, callback_count_); |
1282 EXPECT_EQ(0, error_callback_count_); | 1280 EXPECT_EQ(0, error_callback_count_); |
1283 EXPECT_TRUE(adapter_->IsPowered()); | 1281 EXPECT_TRUE(adapter_->IsPowered()); |
1284 callback_count_ = 0; | 1282 callback_count_ = 0; |
1285 | 1283 |
1286 TestBluetoothAdapterObserver observer(adapter_); | 1284 TestBluetoothAdapterObserver observer(adapter_); |
1287 | 1285 |
1288 EXPECT_EQ(0, observer.discovering_changed_count()); | 1286 EXPECT_EQ(0, observer.discovering_changed_count()); |
1289 EXPECT_FALSE(observer.last_discovering()); | 1287 EXPECT_FALSE(observer.last_discovering()); |
1290 EXPECT_FALSE(adapter_->IsDiscovering()); | 1288 EXPECT_FALSE(adapter_->IsDiscovering()); |
1291 EXPECT_TRUE(discovery_sessions_.empty()); | 1289 EXPECT_TRUE(discovery_sessions_.empty()); |
1292 | 1290 |
1293 // Request a new discovery session. | 1291 // Request a new discovery session. |
1294 adapter_->StartDiscoverySession( | 1292 adapter_->StartDiscoverySession( |
1295 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1293 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1296 base::Unretained(this)), | 1294 base::Unretained(this)), |
1297 GetErrorCallback()); | 1295 GetErrorCallback()); |
1298 message_loop_.Run(); | 1296 message_loop_.Run(); |
1299 EXPECT_EQ(1, observer.discovering_changed_count()); | 1297 EXPECT_EQ(1, observer.discovering_changed_count()); |
1300 EXPECT_EQ(1, callback_count_); | 1298 EXPECT_EQ(1, callback_count_); |
1301 EXPECT_EQ(0, error_callback_count_); | 1299 EXPECT_EQ(0, error_callback_count_); |
1302 EXPECT_TRUE(observer.last_discovering()); | 1300 EXPECT_TRUE(observer.last_discovering()); |
1303 EXPECT_TRUE(adapter_->IsDiscovering()); | 1301 EXPECT_TRUE(adapter_->IsDiscovering()); |
1304 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1302 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1305 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1303 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
1306 | 1304 |
1307 // Start another session. A new one should be returned in the callback, which | 1305 // Start another session. A new one should be returned in the callback, which |
1308 // in turn will destroy the previous session. Adapter should still be | 1306 // in turn will destroy the previous session. Adapter should still be |
1309 // discovering and the reference count should be 1. | 1307 // discovering and the reference count should be 1. |
1310 adapter_->StartDiscoverySession( | 1308 adapter_->StartDiscoverySession( |
1311 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1309 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1312 base::Unretained(this)), | 1310 base::Unretained(this)), |
1313 GetErrorCallback()); | 1311 GetErrorCallback()); |
1314 message_loop_.Run(); | 1312 message_loop_.Run(); |
1315 EXPECT_EQ(1, observer.discovering_changed_count()); | 1313 EXPECT_EQ(1, observer.discovering_changed_count()); |
1316 EXPECT_EQ(2, callback_count_); | 1314 EXPECT_EQ(2, callback_count_); |
1317 EXPECT_EQ(0, error_callback_count_); | 1315 EXPECT_EQ(0, error_callback_count_); |
1318 EXPECT_TRUE(observer.last_discovering()); | 1316 EXPECT_TRUE(observer.last_discovering()); |
1319 EXPECT_TRUE(adapter_->IsDiscovering()); | 1317 EXPECT_TRUE(adapter_->IsDiscovering()); |
1320 ASSERT_EQ((size_t)2, discovery_sessions_.size()); | 1318 ASSERT_EQ((size_t)2, discovery_sessions_.size()); |
1321 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1319 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
1322 | 1320 |
1323 // Request a new session. | 1321 // Request a new session. |
1324 adapter_->StartDiscoverySession( | 1322 adapter_->StartDiscoverySession( |
1325 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1323 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1326 base::Unretained(this)), | 1324 base::Unretained(this)), |
1327 GetErrorCallback()); | 1325 GetErrorCallback()); |
1328 message_loop_.Run(); | 1326 message_loop_.Run(); |
1329 EXPECT_EQ(1, observer.discovering_changed_count()); | 1327 EXPECT_EQ(1, observer.discovering_changed_count()); |
1330 EXPECT_EQ(3, callback_count_); | 1328 EXPECT_EQ(3, callback_count_); |
1331 EXPECT_EQ(0, error_callback_count_); | 1329 EXPECT_EQ(0, error_callback_count_); |
1332 EXPECT_TRUE(observer.last_discovering()); | 1330 EXPECT_TRUE(observer.last_discovering()); |
1333 EXPECT_TRUE(adapter_->IsDiscovering()); | 1331 EXPECT_TRUE(adapter_->IsDiscovering()); |
1334 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1332 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
1335 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); | 1333 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); |
(...skipping 17 matching lines...) Expand all Loading... |
1353 while (observer.last_discovering()) | 1351 while (observer.last_discovering()) |
1354 message_loop_.RunUntilIdle(); | 1352 message_loop_.RunUntilIdle(); |
1355 | 1353 |
1356 EXPECT_EQ(2, observer.discovering_changed_count()); | 1354 EXPECT_EQ(2, observer.discovering_changed_count()); |
1357 EXPECT_EQ(4, callback_count_); | 1355 EXPECT_EQ(4, callback_count_); |
1358 EXPECT_EQ(0, error_callback_count_); | 1356 EXPECT_EQ(0, error_callback_count_); |
1359 EXPECT_FALSE(observer.last_discovering()); | 1357 EXPECT_FALSE(observer.last_discovering()); |
1360 EXPECT_FALSE(adapter_->IsDiscovering()); | 1358 EXPECT_FALSE(adapter_->IsDiscovering()); |
1361 } | 1359 } |
1362 | 1360 |
1363 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscovery) { | 1361 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) { |
1364 // Test a simulated discovery session. | 1362 // Test a simulated discovery session. |
1365 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1363 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1366 GetAdapter(); | 1364 GetAdapter(); |
1367 | 1365 |
1368 TestBluetoothAdapterObserver observer(adapter_); | 1366 TestBluetoothAdapterObserver observer(adapter_); |
1369 | 1367 |
1370 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1368 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1371 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1369 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1372 df->SetRSSI(-60); | 1370 df->SetRSSI(-60); |
1373 df->AddUUID(BluetoothUUID("1000")); | 1371 df->AddUUID(BluetoothUUID("1000")); |
1374 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1372 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1375 | 1373 |
1376 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1374 adapter_->SetPowered( |
1377 base::Unretained(this)), | 1375 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1378 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1376 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1379 base::Unretained(this))); | |
1380 adapter_->StartDiscoverySessionWithFilter( | 1377 adapter_->StartDiscoverySessionWithFilter( |
1381 discovery_filter.Pass(), | 1378 discovery_filter.Pass(), |
1382 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1379 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1383 base::Unretained(this)), | 1380 base::Unretained(this)), |
1384 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1381 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1385 base::Unretained(this))); | |
1386 message_loop_.Run(); | 1382 message_loop_.Run(); |
1387 EXPECT_EQ(2, callback_count_); | 1383 EXPECT_EQ(2, callback_count_); |
1388 EXPECT_EQ(0, error_callback_count_); | 1384 EXPECT_EQ(0, error_callback_count_); |
1389 callback_count_ = 0; | 1385 callback_count_ = 0; |
1390 | 1386 |
1391 ASSERT_TRUE(adapter_->IsPowered()); | 1387 ASSERT_TRUE(adapter_->IsPowered()); |
1392 ASSERT_TRUE(adapter_->IsDiscovering()); | 1388 ASSERT_TRUE(adapter_->IsDiscovering()); |
1393 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1389 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1394 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 1390 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
1395 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); | 1391 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); |
1396 | 1392 |
1397 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1393 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1398 EXPECT_NE(nullptr, filter); | 1394 EXPECT_NE(nullptr, filter); |
1399 EXPECT_EQ("le", *filter->transport); | 1395 EXPECT_EQ("le", *filter->transport); |
1400 EXPECT_EQ(-60, *filter->rssi); | 1396 EXPECT_EQ(-60, *filter->rssi); |
1401 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1397 EXPECT_EQ(nullptr, filter->pathloss.get()); |
1402 std::vector<std::string> uuids = *filter->uuids; | 1398 std::vector<std::string> uuids = *filter->uuids; |
1403 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 1399 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
1404 | 1400 |
1405 discovery_sessions_[0]->Stop( | 1401 discovery_sessions_[0]->Stop( |
1406 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1402 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1407 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1403 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1408 base::Unretained(this))); | |
1409 | 1404 |
1410 message_loop_.Run(); | 1405 message_loop_.Run(); |
1411 | 1406 |
1412 EXPECT_EQ(1, callback_count_); | 1407 EXPECT_EQ(1, callback_count_); |
1413 EXPECT_EQ(0, error_callback_count_); | 1408 EXPECT_EQ(0, error_callback_count_); |
1414 | 1409 |
1415 ASSERT_TRUE(adapter_->IsPowered()); | 1410 ASSERT_TRUE(adapter_->IsPowered()); |
1416 ASSERT_FALSE(adapter_->IsDiscovering()); | 1411 ASSERT_FALSE(adapter_->IsDiscovering()); |
1417 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1412 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1418 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 1413 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
1419 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), | 1414 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), |
1420 (BluetoothDiscoveryFilter*)nullptr); | 1415 (BluetoothDiscoveryFilter*)nullptr); |
1421 | 1416 |
1422 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1417 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1423 EXPECT_EQ(nullptr, filter); | 1418 EXPECT_EQ(nullptr, filter); |
1424 } | 1419 } |
1425 | 1420 |
1426 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { | 1421 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { |
1427 // Test a simulated discovery session. | 1422 // Test a simulated discovery session. |
1428 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1423 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1429 GetAdapter(); | 1424 GetAdapter(); |
1430 | 1425 |
1431 TestBluetoothAdapterObserver observer(adapter_); | 1426 TestBluetoothAdapterObserver observer(adapter_); |
1432 | 1427 |
1433 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1428 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1434 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1429 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1435 df->SetRSSI(-60); | 1430 df->SetRSSI(-60); |
1436 df->AddUUID(BluetoothUUID("1000")); | 1431 df->AddUUID(BluetoothUUID("1000")); |
1437 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1432 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1438 | 1433 |
1439 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1434 adapter_->SetPowered( |
1440 base::Unretained(this)), | 1435 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1441 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1436 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1442 base::Unretained(this))); | |
1443 EXPECT_EQ(1, callback_count_); | 1437 EXPECT_EQ(1, callback_count_); |
1444 callback_count_ = 0; | 1438 callback_count_ = 0; |
1445 | 1439 |
1446 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); | 1440 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); |
1447 | 1441 |
1448 adapter_->StartDiscoverySessionWithFilter( | 1442 adapter_->StartDiscoverySessionWithFilter( |
1449 discovery_filter.Pass(), | 1443 discovery_filter.Pass(), |
1450 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1444 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1451 base::Unretained(this)), | 1445 base::Unretained(this)), |
1452 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1446 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1453 base::Unretained(this))); | |
1454 | 1447 |
1455 message_loop_.Run(); | 1448 message_loop_.Run(); |
1456 | 1449 |
1457 EXPECT_EQ(1, error_callback_count_); | 1450 EXPECT_EQ(1, error_callback_count_); |
1458 error_callback_count_ = 0; | 1451 error_callback_count_ = 0; |
1459 | 1452 |
1460 ASSERT_TRUE(adapter_->IsPowered()); | 1453 ASSERT_TRUE(adapter_->IsPowered()); |
1461 ASSERT_FALSE(adapter_->IsDiscovering()); | 1454 ASSERT_FALSE(adapter_->IsDiscovering()); |
1462 ASSERT_EQ((size_t)0, discovery_sessions_.size()); | 1455 ASSERT_EQ((size_t)0, discovery_sessions_.size()); |
1463 | 1456 |
1464 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1457 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1465 EXPECT_EQ(nullptr, filter); | 1458 EXPECT_EQ(nullptr, filter); |
1466 } | 1459 } |
1467 | 1460 |
1468 // This test queues two requests to StartDiscovery with pre set filter. This | 1461 // This test queues two requests to StartDiscovery with pre set filter. This |
1469 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery | 1462 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery |
1470 // DBus calls | 1463 // DBus calls |
1471 TEST_F(BluetoothChromeOSTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { | 1464 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { |
1472 // Test a simulated discovery session. | 1465 // Test a simulated discovery session. |
1473 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1466 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1474 GetAdapter(); | 1467 GetAdapter(); |
1475 | 1468 |
1476 TestBluetoothAdapterObserver observer(adapter_); | 1469 TestBluetoothAdapterObserver observer(adapter_); |
1477 | 1470 |
1478 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1471 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1479 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1472 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1480 df->SetRSSI(-60); | 1473 df->SetRSSI(-60); |
1481 df->AddUUID(BluetoothUUID("1000")); | 1474 df->AddUUID(BluetoothUUID("1000")); |
1482 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1475 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1483 | 1476 |
1484 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( | 1477 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( |
1485 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); | 1478 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); |
1486 df2->SetRSSI(-65); | 1479 df2->SetRSSI(-65); |
1487 df2->AddUUID(BluetoothUUID("1002")); | 1480 df2->AddUUID(BluetoothUUID("1002")); |
1488 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); | 1481 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); |
1489 | 1482 |
1490 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1483 adapter_->SetPowered( |
1491 base::Unretained(this)), | 1484 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1492 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1485 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1493 base::Unretained(this))); | |
1494 | 1486 |
1495 EXPECT_EQ(1, callback_count_); | 1487 EXPECT_EQ(1, callback_count_); |
1496 EXPECT_EQ(0, error_callback_count_); | 1488 EXPECT_EQ(0, error_callback_count_); |
1497 callback_count_ = 0; | 1489 callback_count_ = 0; |
1498 | 1490 |
1499 // Queue two requests to start discovery session with filter. | 1491 // Queue two requests to start discovery session with filter. |
1500 adapter_->StartDiscoverySessionWithFilter( | 1492 adapter_->StartDiscoverySessionWithFilter( |
1501 discovery_filter.Pass(), | 1493 discovery_filter.Pass(), |
1502 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1494 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1503 base::Unretained(this)), | 1495 base::Unretained(this)), |
1504 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1496 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1505 base::Unretained(this))); | |
1506 | 1497 |
1507 adapter_->StartDiscoverySessionWithFilter( | 1498 adapter_->StartDiscoverySessionWithFilter( |
1508 discovery_filter2.Pass(), | 1499 discovery_filter2.Pass(), |
1509 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1500 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1510 base::Unretained(this)), | 1501 base::Unretained(this)), |
1511 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1502 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1512 base::Unretained(this))); | |
1513 | 1503 |
1514 // Run requests, on DBus level there should be call SetDiscoveryFilter, then | 1504 // Run requests, on DBus level there should be call SetDiscoveryFilter, then |
1515 // StartDiscovery, then SetDiscoveryFilter again. | 1505 // StartDiscovery, then SetDiscoveryFilter again. |
1516 message_loop_.Run(); | 1506 message_loop_.Run(); |
1517 message_loop_.Run(); | 1507 message_loop_.Run(); |
1518 | 1508 |
1519 EXPECT_EQ(2, callback_count_); | 1509 EXPECT_EQ(2, callback_count_); |
1520 EXPECT_EQ(0, error_callback_count_); | 1510 EXPECT_EQ(0, error_callback_count_); |
1521 callback_count_ = 0; | 1511 callback_count_ = 0; |
1522 | 1512 |
1523 ASSERT_TRUE(adapter_->IsPowered()); | 1513 ASSERT_TRUE(adapter_->IsPowered()); |
1524 ASSERT_TRUE(adapter_->IsDiscovering()); | 1514 ASSERT_TRUE(adapter_->IsDiscovering()); |
1525 ASSERT_EQ((size_t)2, discovery_sessions_.size()); | 1515 ASSERT_EQ((size_t)2, discovery_sessions_.size()); |
1526 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 1516 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
1527 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); | 1517 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); |
1528 ASSERT_TRUE(discovery_sessions_[1]->IsActive()); | 1518 ASSERT_TRUE(discovery_sessions_[1]->IsActive()); |
1529 ASSERT_TRUE(df2->Equals(*discovery_sessions_[1]->GetDiscoveryFilter())); | 1519 ASSERT_TRUE(df2->Equals(*discovery_sessions_[1]->GetDiscoveryFilter())); |
1530 | 1520 |
1531 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1521 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1532 EXPECT_NE(nullptr, filter); | 1522 EXPECT_NE(nullptr, filter); |
1533 EXPECT_EQ("auto", *filter->transport); | 1523 EXPECT_EQ("auto", *filter->transport); |
1534 EXPECT_EQ(-65, *filter->rssi); | 1524 EXPECT_EQ(-65, *filter->rssi); |
1535 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1525 EXPECT_EQ(nullptr, filter->pathloss.get()); |
1536 auto uuids = *filter->uuids; | 1526 auto uuids = *filter->uuids; |
1537 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 1527 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
1538 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); | 1528 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); |
1539 | 1529 |
1540 discovery_sessions_[0]->Stop( | 1530 discovery_sessions_[0]->Stop( |
1541 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1531 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1542 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1532 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1543 base::Unretained(this))); | |
1544 | 1533 |
1545 discovery_sessions_[1]->Stop( | 1534 discovery_sessions_[1]->Stop( |
1546 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1535 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1547 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1536 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1548 base::Unretained(this))); | |
1549 | 1537 |
1550 message_loop_.Run(); | 1538 message_loop_.Run(); |
1551 | 1539 |
1552 EXPECT_EQ(2, callback_count_); | 1540 EXPECT_EQ(2, callback_count_); |
1553 EXPECT_EQ(0, error_callback_count_); | 1541 EXPECT_EQ(0, error_callback_count_); |
1554 | 1542 |
1555 ASSERT_TRUE(adapter_->IsPowered()); | 1543 ASSERT_TRUE(adapter_->IsPowered()); |
1556 ASSERT_FALSE(adapter_->IsDiscovering()); | 1544 ASSERT_FALSE(adapter_->IsDiscovering()); |
1557 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 1545 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
1558 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), | 1546 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), |
1559 (BluetoothDiscoveryFilter*)nullptr); | 1547 (BluetoothDiscoveryFilter*)nullptr); |
1560 ASSERT_FALSE(discovery_sessions_[1]->IsActive()); | 1548 ASSERT_FALSE(discovery_sessions_[1]->IsActive()); |
1561 ASSERT_EQ(discovery_sessions_[1]->GetDiscoveryFilter(), | 1549 ASSERT_EQ(discovery_sessions_[1]->GetDiscoveryFilter(), |
1562 (BluetoothDiscoveryFilter*)nullptr); | 1550 (BluetoothDiscoveryFilter*)nullptr); |
1563 | 1551 |
1564 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1552 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1565 EXPECT_EQ(nullptr, filter); | 1553 EXPECT_EQ(nullptr, filter); |
1566 } | 1554 } |
1567 | 1555 |
1568 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). | 1556 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). |
1569 // Make the first SetDiscoveryFilter fail and the second one succeed. It should | 1557 // Make the first SetDiscoveryFilter fail and the second one succeed. It should |
1570 // end up with one active discovery session. | 1558 // end up with one active discovery session. |
1571 TEST_F(BluetoothChromeOSTest, | 1559 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) { |
1572 QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) { | |
1573 // Test a simulated discovery session. | 1560 // Test a simulated discovery session. |
1574 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1561 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1575 GetAdapter(); | 1562 GetAdapter(); |
1576 | 1563 |
1577 TestBluetoothAdapterObserver observer(adapter_); | 1564 TestBluetoothAdapterObserver observer(adapter_); |
1578 | 1565 |
1579 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1566 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1580 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1567 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1581 df->SetRSSI(-60); | 1568 df->SetRSSI(-60); |
1582 df->AddUUID(BluetoothUUID("1000")); | 1569 df->AddUUID(BluetoothUUID("1000")); |
1583 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1570 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1584 | 1571 |
1585 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( | 1572 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( |
1586 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); | 1573 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); |
1587 df2->SetRSSI(-65); | 1574 df2->SetRSSI(-65); |
1588 df2->AddUUID(BluetoothUUID("1002")); | 1575 df2->AddUUID(BluetoothUUID("1002")); |
1589 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); | 1576 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); |
1590 | 1577 |
1591 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1578 adapter_->SetPowered( |
1592 base::Unretained(this)), | 1579 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1593 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1580 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1594 base::Unretained(this))); | |
1595 | 1581 |
1596 EXPECT_EQ(1, callback_count_); | 1582 EXPECT_EQ(1, callback_count_); |
1597 EXPECT_EQ(0, error_callback_count_); | 1583 EXPECT_EQ(0, error_callback_count_); |
1598 callback_count_ = 0; | 1584 callback_count_ = 0; |
1599 | 1585 |
1600 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); | 1586 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); |
1601 | 1587 |
1602 // Queue two requests to start discovery session with filter. | 1588 // Queue two requests to start discovery session with filter. |
1603 adapter_->StartDiscoverySessionWithFilter( | 1589 adapter_->StartDiscoverySessionWithFilter( |
1604 discovery_filter.Pass(), | 1590 discovery_filter.Pass(), |
1605 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1591 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1606 base::Unretained(this)), | 1592 base::Unretained(this)), |
1607 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1593 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1608 base::Unretained(this))); | |
1609 | 1594 |
1610 adapter_->StartDiscoverySessionWithFilter( | 1595 adapter_->StartDiscoverySessionWithFilter( |
1611 discovery_filter2.Pass(), | 1596 discovery_filter2.Pass(), |
1612 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1597 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1613 base::Unretained(this)), | 1598 base::Unretained(this)), |
1614 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1599 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1615 base::Unretained(this))); | |
1616 | 1600 |
1617 message_loop_.Run(); | 1601 message_loop_.Run(); |
1618 | 1602 |
1619 // First request to SetDiscoveryFilter should fail, resulting in no session | 1603 // First request to SetDiscoveryFilter should fail, resulting in no session |
1620 // being created. | 1604 // being created. |
1621 EXPECT_EQ(0, callback_count_); | 1605 EXPECT_EQ(0, callback_count_); |
1622 EXPECT_EQ(1, error_callback_count_); | 1606 EXPECT_EQ(1, error_callback_count_); |
1623 error_callback_count_ = 0; | 1607 error_callback_count_ = 0; |
1624 | 1608 |
1625 ASSERT_TRUE(adapter_->IsPowered()); | 1609 ASSERT_TRUE(adapter_->IsPowered()); |
(...skipping 14 matching lines...) Expand all Loading... |
1640 | 1624 |
1641 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1625 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1642 EXPECT_NE(nullptr, filter); | 1626 EXPECT_NE(nullptr, filter); |
1643 EXPECT_EQ("bredr", *filter->transport); | 1627 EXPECT_EQ("bredr", *filter->transport); |
1644 EXPECT_EQ(-65, *filter->rssi); | 1628 EXPECT_EQ(-65, *filter->rssi); |
1645 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1629 EXPECT_EQ(nullptr, filter->pathloss.get()); |
1646 auto uuids = *filter->uuids; | 1630 auto uuids = *filter->uuids; |
1647 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); | 1631 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); |
1648 | 1632 |
1649 discovery_sessions_[0]->Stop( | 1633 discovery_sessions_[0]->Stop( |
1650 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1634 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1651 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1635 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1652 base::Unretained(this))); | |
1653 | 1636 |
1654 message_loop_.Run(); | 1637 message_loop_.Run(); |
1655 | 1638 |
1656 EXPECT_EQ(1, callback_count_); | 1639 EXPECT_EQ(1, callback_count_); |
1657 EXPECT_EQ(0, error_callback_count_); | 1640 EXPECT_EQ(0, error_callback_count_); |
1658 | 1641 |
1659 ASSERT_TRUE(adapter_->IsPowered()); | 1642 ASSERT_TRUE(adapter_->IsPowered()); |
1660 ASSERT_FALSE(adapter_->IsDiscovering()); | 1643 ASSERT_FALSE(adapter_->IsDiscovering()); |
1661 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 1644 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
1662 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), | 1645 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), |
1663 (BluetoothDiscoveryFilter*)nullptr); | 1646 (BluetoothDiscoveryFilter*)nullptr); |
1664 | 1647 |
1665 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1648 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1666 EXPECT_EQ(nullptr, filter); | 1649 EXPECT_EQ(nullptr, filter); |
1667 } | 1650 } |
1668 | 1651 |
1669 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterAfterStartDiscovery) { | 1652 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterAfterStartDiscovery) { |
1670 // Test a simulated discovery session. | 1653 // Test a simulated discovery session. |
1671 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1654 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1672 GetAdapter(); | 1655 GetAdapter(); |
1673 | 1656 |
1674 TestBluetoothAdapterObserver observer(adapter_); | 1657 TestBluetoothAdapterObserver observer(adapter_); |
1675 | 1658 |
1676 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1659 adapter_->SetPowered( |
1677 base::Unretained(this)), | 1660 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1678 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1661 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1679 base::Unretained(this))); | |
1680 adapter_->StartDiscoverySession( | 1662 adapter_->StartDiscoverySession( |
1681 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1663 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1682 base::Unretained(this)), | 1664 base::Unretained(this)), |
1683 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1665 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1684 base::Unretained(this))); | |
1685 message_loop_.Run(); | 1666 message_loop_.Run(); |
1686 EXPECT_EQ(2, callback_count_); | 1667 EXPECT_EQ(2, callback_count_); |
1687 EXPECT_EQ(0, error_callback_count_); | 1668 EXPECT_EQ(0, error_callback_count_); |
1688 callback_count_ = 0; | 1669 callback_count_ = 0; |
1689 | 1670 |
1690 ASSERT_TRUE(adapter_->IsPowered()); | 1671 ASSERT_TRUE(adapter_->IsPowered()); |
1691 ASSERT_TRUE(adapter_->IsDiscovering()); | 1672 ASSERT_TRUE(adapter_->IsDiscovering()); |
1692 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1673 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1693 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 1674 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
1694 EXPECT_EQ(1, observer.discovering_changed_count()); | 1675 EXPECT_EQ(1, observer.discovering_changed_count()); |
1695 observer.Reset(); | 1676 observer.Reset(); |
1696 | 1677 |
1697 auto null_instance = scoped_ptr<BluetoothDiscoveryFilter>(); | 1678 auto null_instance = scoped_ptr<BluetoothDiscoveryFilter>(); |
1698 null_instance.reset(); | 1679 null_instance.reset(); |
1699 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); | 1680 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); |
1700 | 1681 |
1701 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1682 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1702 EXPECT_EQ(nullptr, filter); | 1683 EXPECT_EQ(nullptr, filter); |
1703 | 1684 |
1704 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1685 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1705 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1686 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1706 df->SetRSSI(-60); | 1687 df->SetRSSI(-60); |
1707 df->AddUUID(BluetoothUUID("1000")); | 1688 df->AddUUID(BluetoothUUID("1000")); |
1708 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1689 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1709 | 1690 |
1710 discovery_sessions_[0]->SetDiscoveryFilter( | 1691 discovery_sessions_[0]->SetDiscoveryFilter( |
1711 discovery_filter.Pass(), | 1692 discovery_filter.Pass(), |
1712 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1693 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1713 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1694 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1714 base::Unretained(this))); | |
1715 | 1695 |
1716 message_loop_.Run(); | 1696 message_loop_.Run(); |
1717 EXPECT_EQ(1, callback_count_); | 1697 EXPECT_EQ(1, callback_count_); |
1718 EXPECT_EQ(0, error_callback_count_); | 1698 EXPECT_EQ(0, error_callback_count_); |
1719 callback_count_ = 0; | 1699 callback_count_ = 0; |
1720 | 1700 |
1721 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); | 1701 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); |
1722 | 1702 |
1723 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1703 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1724 EXPECT_NE(nullptr, filter); | 1704 EXPECT_NE(nullptr, filter); |
1725 EXPECT_EQ("le", *filter->transport); | 1705 EXPECT_EQ("le", *filter->transport); |
1726 EXPECT_EQ(-60, *filter->rssi); | 1706 EXPECT_EQ(-60, *filter->rssi); |
1727 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1707 EXPECT_EQ(nullptr, filter->pathloss.get()); |
1728 std::vector<std::string> uuids = *filter->uuids; | 1708 std::vector<std::string> uuids = *filter->uuids; |
1729 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 1709 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
1730 | 1710 |
1731 discovery_sessions_[0]->Stop( | 1711 discovery_sessions_[0]->Stop( |
1732 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1712 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1733 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1713 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1734 base::Unretained(this))); | |
1735 | 1714 |
1736 message_loop_.Run(); | 1715 message_loop_.Run(); |
1737 | 1716 |
1738 EXPECT_EQ(1, callback_count_); | 1717 EXPECT_EQ(1, callback_count_); |
1739 EXPECT_EQ(0, error_callback_count_); | 1718 EXPECT_EQ(0, error_callback_count_); |
1740 | 1719 |
1741 ASSERT_TRUE(adapter_->IsPowered()); | 1720 ASSERT_TRUE(adapter_->IsPowered()); |
1742 ASSERT_FALSE(adapter_->IsDiscovering()); | 1721 ASSERT_FALSE(adapter_->IsDiscovering()); |
1743 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1722 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
1744 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 1723 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
1745 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), | 1724 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), |
1746 (BluetoothDiscoveryFilter*)nullptr); | 1725 (BluetoothDiscoveryFilter*)nullptr); |
1747 | 1726 |
1748 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1727 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1749 EXPECT_EQ(nullptr, filter); | 1728 EXPECT_EQ(nullptr, filter); |
1750 } | 1729 } |
1751 | 1730 |
1752 // This unit test asserts that the basic reference counting, and filter merging | 1731 // This unit test asserts that the basic reference counting, and filter merging |
1753 // works correctly for discovery requests done via the BluetoothAdapter. | 1732 // works correctly for discovery requests done via the BluetoothAdapter. |
1754 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscoveryMultiple) { | 1733 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryMultiple) { |
1755 GetAdapter(); | 1734 GetAdapter(); |
1756 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1735 adapter_->SetPowered( |
1757 base::Unretained(this)), | 1736 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1758 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1737 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1759 base::Unretained(this))); | |
1760 EXPECT_EQ(1, callback_count_); | 1738 EXPECT_EQ(1, callback_count_); |
1761 EXPECT_EQ(0, error_callback_count_); | 1739 EXPECT_EQ(0, error_callback_count_); |
1762 EXPECT_TRUE(adapter_->IsPowered()); | 1740 EXPECT_TRUE(adapter_->IsPowered()); |
1763 callback_count_ = 0; | 1741 callback_count_ = 0; |
1764 | 1742 |
1765 TestBluetoothAdapterObserver observer(adapter_); | 1743 TestBluetoothAdapterObserver observer(adapter_); |
1766 | 1744 |
1767 // Request device discovery with pre-set filter 3 times. | 1745 // Request device discovery with pre-set filter 3 times. |
1768 for (int i = 0; i < 3; i++) { | 1746 for (int i = 0; i < 3; i++) { |
1769 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter; | 1747 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter; |
(...skipping 14 matching lines...) Expand all Loading... |
1784 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1762 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1785 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1763 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1786 df->SetRSSI(-65); | 1764 df->SetRSSI(-65); |
1787 df->AddUUID(BluetoothUUID("1020")); | 1765 df->AddUUID(BluetoothUUID("1020")); |
1788 df->AddUUID(BluetoothUUID("1003")); | 1766 df->AddUUID(BluetoothUUID("1003")); |
1789 discovery_filter.reset(df); | 1767 discovery_filter.reset(df); |
1790 } | 1768 } |
1791 | 1769 |
1792 adapter_->StartDiscoverySessionWithFilter( | 1770 adapter_->StartDiscoverySessionWithFilter( |
1793 discovery_filter.Pass(), | 1771 discovery_filter.Pass(), |
1794 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1772 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1795 base::Unretained(this)), | 1773 base::Unretained(this)), |
1796 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1774 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1797 base::Unretained(this))); | |
1798 | 1775 |
1799 message_loop_.Run(); | 1776 message_loop_.Run(); |
1800 | 1777 |
1801 if (i == 0) { | 1778 if (i == 0) { |
1802 EXPECT_EQ(1, observer.discovering_changed_count()); | 1779 EXPECT_EQ(1, observer.discovering_changed_count()); |
1803 observer.Reset(); | 1780 observer.Reset(); |
1804 | 1781 |
1805 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1782 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1806 EXPECT_EQ("le", *filter->transport); | 1783 EXPECT_EQ("le", *filter->transport); |
1807 EXPECT_EQ(-85, *filter->rssi); | 1784 EXPECT_EQ(-85, *filter->rssi); |
(...skipping 26 matching lines...) Expand all Loading... |
1834 // be discovering. | 1811 // be discovering. |
1835 EXPECT_EQ(3, callback_count_); | 1812 EXPECT_EQ(3, callback_count_); |
1836 EXPECT_EQ(0, error_callback_count_); | 1813 EXPECT_EQ(0, error_callback_count_); |
1837 EXPECT_TRUE(adapter_->IsDiscovering()); | 1814 EXPECT_TRUE(adapter_->IsDiscovering()); |
1838 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1815 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
1839 | 1816 |
1840 callback_count_ = 0; | 1817 callback_count_ = 0; |
1841 // Request to stop discovery twice. | 1818 // Request to stop discovery twice. |
1842 for (int i = 0; i < 2; i++) { | 1819 for (int i = 0; i < 2; i++) { |
1843 discovery_sessions_[i]->Stop( | 1820 discovery_sessions_[i]->Stop( |
1844 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1821 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1845 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1822 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1846 base::Unretained(this))); | |
1847 message_loop_.Run(); | 1823 message_loop_.Run(); |
1848 | 1824 |
1849 if (i == 0) { | 1825 if (i == 0) { |
1850 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1826 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1851 EXPECT_EQ("le", *filter->transport); | 1827 EXPECT_EQ("le", *filter->transport); |
1852 EXPECT_EQ(-65, *filter->rssi); | 1828 EXPECT_EQ(-65, *filter->rssi); |
1853 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1829 EXPECT_EQ(nullptr, filter->pathloss.get()); |
1854 std::vector<std::string> uuids = *filter->uuids; | 1830 std::vector<std::string> uuids = *filter->uuids; |
1855 EXPECT_EQ(3UL, uuids.size()); | 1831 EXPECT_EQ(3UL, uuids.size()); |
1856 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 1832 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1886 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1911 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1887 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1912 df->SetRSSI(-65); | 1888 df->SetRSSI(-65); |
1913 df->AddUUID(BluetoothUUID("1020")); | 1889 df->AddUUID(BluetoothUUID("1020")); |
1914 df->AddUUID(BluetoothUUID("1003")); | 1890 df->AddUUID(BluetoothUUID("1003")); |
1915 discovery_filter.reset(df); | 1891 discovery_filter.reset(df); |
1916 } | 1892 } |
1917 | 1893 |
1918 adapter_->StartDiscoverySessionWithFilter( | 1894 adapter_->StartDiscoverySessionWithFilter( |
1919 discovery_filter.Pass(), | 1895 discovery_filter.Pass(), |
1920 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1896 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1921 base::Unretained(this)), | 1897 base::Unretained(this)), |
1922 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1898 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1923 base::Unretained(this))); | |
1924 | 1899 |
1925 // each result in 1 requests. | 1900 // each result in 1 requests. |
1926 message_loop_.Run(); | 1901 message_loop_.Run(); |
1927 | 1902 |
1928 if (i == 0) { | 1903 if (i == 0) { |
1929 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1904 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1930 EXPECT_EQ("le", *filter->transport); | 1905 EXPECT_EQ("le", *filter->transport); |
1931 EXPECT_EQ(-85, *filter->rssi); | 1906 EXPECT_EQ(-85, *filter->rssi); |
1932 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1907 EXPECT_EQ(nullptr, filter->pathloss.get()); |
1933 std::vector<std::string> uuids = *filter->uuids; | 1908 std::vector<std::string> uuids = *filter->uuids; |
(...skipping 17 matching lines...) Expand all Loading... |
1951 // still be discovering. | 1926 // still be discovering. |
1952 EXPECT_EQ(3, callback_count_); | 1927 EXPECT_EQ(3, callback_count_); |
1953 EXPECT_EQ(0, error_callback_count_); | 1928 EXPECT_EQ(0, error_callback_count_); |
1954 EXPECT_TRUE(adapter_->IsDiscovering()); | 1929 EXPECT_TRUE(adapter_->IsDiscovering()); |
1955 ASSERT_EQ((size_t)6, discovery_sessions_.size()); | 1930 ASSERT_EQ((size_t)6, discovery_sessions_.size()); |
1956 | 1931 |
1957 callback_count_ = 0; | 1932 callback_count_ = 0; |
1958 // Request to stop discovery 4 times. | 1933 // Request to stop discovery 4 times. |
1959 for (int i = 2; i < 6; i++) { | 1934 for (int i = 2; i < 6; i++) { |
1960 discovery_sessions_[i]->Stop( | 1935 discovery_sessions_[i]->Stop( |
1961 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 1936 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1962 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1937 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1963 base::Unretained(this))); | |
1964 | 1938 |
1965 // filter no 2 is same as filter no 5, so removing it shouldn't cause any | 1939 // filter no 2 is same as filter no 5, so removing it shouldn't cause any |
1966 // filter update | 1940 // filter update |
1967 if (i != 2 && i != 5) | 1941 if (i != 2 && i != 5) |
1968 message_loop_.Run(); | 1942 message_loop_.Run(); |
1969 } | 1943 } |
1970 // Run only once, as there should have been one D-Bus call. | 1944 // Run only once, as there should have been one D-Bus call. |
1971 message_loop_.Run(); | 1945 message_loop_.Run(); |
1972 | 1946 |
1973 // The success callback should have been called 4 times and the adapter should | 1947 // The success callback should have been called 4 times and the adapter should |
1974 // no longer be discovering. | 1948 // no longer be discovering. |
1975 EXPECT_EQ(4, callback_count_); | 1949 EXPECT_EQ(4, callback_count_); |
1976 EXPECT_EQ(0, error_callback_count_); | 1950 EXPECT_EQ(0, error_callback_count_); |
1977 EXPECT_FALSE(adapter_->IsDiscovering()); | 1951 EXPECT_FALSE(adapter_->IsDiscovering()); |
1978 EXPECT_EQ(1, observer.discovering_changed_count()); | 1952 EXPECT_EQ(1, observer.discovering_changed_count()); |
1979 | 1953 |
1980 // All discovery sessions should be inactive. | 1954 // All discovery sessions should be inactive. |
1981 for (int i = 0; i < 6; i++) | 1955 for (int i = 0; i < 6; i++) |
1982 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); | 1956 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); |
1983 | 1957 |
1984 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1958 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1985 EXPECT_EQ(nullptr, filter); | 1959 EXPECT_EQ(nullptr, filter); |
1986 } | 1960 } |
1987 | 1961 |
1988 // This unit test asserts that filter merging logic works correctly for filtered | 1962 // This unit test asserts that filter merging logic works correctly for filtered |
1989 // discovery requests done via the BluetoothAdapter. | 1963 // discovery requests done via the BluetoothAdapter. |
1990 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterMergingTest) { | 1964 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) { |
1991 GetAdapter(); | 1965 GetAdapter(); |
1992 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 1966 adapter_->SetPowered( |
1993 base::Unretained(this)), | 1967 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1994 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1968 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1995 base::Unretained(this))); | |
1996 | 1969 |
1997 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1970 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( |
1998 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1971 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
1999 df->SetRSSI(-15); | 1972 df->SetRSSI(-15); |
2000 df->AddUUID(BluetoothUUID("1000")); | 1973 df->AddUUID(BluetoothUUID("1000")); |
2001 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1974 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
2002 | 1975 |
2003 adapter_->StartDiscoverySessionWithFilter( | 1976 adapter_->StartDiscoverySessionWithFilter( |
2004 discovery_filter.Pass(), | 1977 discovery_filter.Pass(), |
2005 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1978 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2006 base::Unretained(this)), | 1979 base::Unretained(this)), |
2007 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1980 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2008 base::Unretained(this))); | |
2009 | 1981 |
2010 message_loop_.Run(); | 1982 message_loop_.Run(); |
2011 | 1983 |
2012 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1984 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
2013 EXPECT_EQ("le", *filter->transport); | 1985 EXPECT_EQ("le", *filter->transport); |
2014 EXPECT_EQ(-15, *filter->rssi); | 1986 EXPECT_EQ(-15, *filter->rssi); |
2015 EXPECT_EQ(nullptr, filter->pathloss.get()); | 1987 EXPECT_EQ(nullptr, filter->pathloss.get()); |
2016 std::vector<std::string> uuids = *filter->uuids; | 1988 std::vector<std::string> uuids = *filter->uuids; |
2017 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 1989 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
2018 | 1990 |
2019 df = new BluetoothDiscoveryFilter( | 1991 df = new BluetoothDiscoveryFilter( |
2020 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1992 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
2021 df->SetRSSI(-60); | 1993 df->SetRSSI(-60); |
2022 df->AddUUID(BluetoothUUID("1020")); | 1994 df->AddUUID(BluetoothUUID("1020")); |
2023 df->AddUUID(BluetoothUUID("1001")); | 1995 df->AddUUID(BluetoothUUID("1001")); |
2024 discovery_filter = scoped_ptr<BluetoothDiscoveryFilter>(df); | 1996 discovery_filter = scoped_ptr<BluetoothDiscoveryFilter>(df); |
2025 | 1997 |
2026 adapter_->StartDiscoverySessionWithFilter( | 1998 adapter_->StartDiscoverySessionWithFilter( |
2027 discovery_filter.Pass(), | 1999 discovery_filter.Pass(), |
2028 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 2000 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2029 base::Unretained(this)), | 2001 base::Unretained(this)), |
2030 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 2002 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2031 base::Unretained(this))); | |
2032 | 2003 |
2033 message_loop_.Run(); | 2004 message_loop_.Run(); |
2034 | 2005 |
2035 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 2006 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
2036 EXPECT_EQ("le", *filter->transport); | 2007 EXPECT_EQ("le", *filter->transport); |
2037 EXPECT_EQ(-60, *filter->rssi); | 2008 EXPECT_EQ(-60, *filter->rssi); |
2038 EXPECT_EQ(nullptr, filter->pathloss.get()); | 2009 EXPECT_EQ(nullptr, filter->pathloss.get()); |
2039 uuids = *filter->uuids; | 2010 uuids = *filter->uuids; |
2040 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 2011 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
2041 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); | 2012 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); |
2042 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); | 2013 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); |
2043 | 2014 |
2044 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( | 2015 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( |
2045 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); | 2016 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); |
2046 df3->SetRSSI(-65); | 2017 df3->SetRSSI(-65); |
2047 df3->AddUUID(BluetoothUUID("1020")); | 2018 df3->AddUUID(BluetoothUUID("1020")); |
2048 df3->AddUUID(BluetoothUUID("1003")); | 2019 df3->AddUUID(BluetoothUUID("1003")); |
2049 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); | 2020 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); |
2050 | 2021 |
2051 adapter_->StartDiscoverySessionWithFilter( | 2022 adapter_->StartDiscoverySessionWithFilter( |
2052 discovery_filter3.Pass(), | 2023 discovery_filter3.Pass(), |
2053 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 2024 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2054 base::Unretained(this)), | 2025 base::Unretained(this)), |
2055 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 2026 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2056 base::Unretained(this))); | |
2057 | 2027 |
2058 message_loop_.Run(); | 2028 message_loop_.Run(); |
2059 | 2029 |
2060 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 2030 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
2061 EXPECT_EQ("auto", *filter->transport); | 2031 EXPECT_EQ("auto", *filter->transport); |
2062 EXPECT_EQ(-65, *filter->rssi); | 2032 EXPECT_EQ(-65, *filter->rssi); |
2063 EXPECT_EQ(nullptr, filter->pathloss.get()); | 2033 EXPECT_EQ(nullptr, filter->pathloss.get()); |
2064 uuids = *filter->uuids; | 2034 uuids = *filter->uuids; |
2065 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 2035 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
2066 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); | 2036 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); |
2067 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003")); | 2037 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003")); |
2068 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); | 2038 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); |
2069 | 2039 |
2070 // start additionally classic scan | 2040 // start additionally classic scan |
2071 adapter_->StartDiscoverySession( | 2041 adapter_->StartDiscoverySession( |
2072 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 2042 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2073 base::Unretained(this)), | 2043 base::Unretained(this)), |
2074 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 2044 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2075 base::Unretained(this))); | |
2076 | 2045 |
2077 message_loop_.Run(); | 2046 message_loop_.Run(); |
2078 | 2047 |
2079 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 2048 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
2080 EXPECT_EQ("auto", *filter->transport); | 2049 EXPECT_EQ("auto", *filter->transport); |
2081 EXPECT_EQ(nullptr, filter->rssi.get()); | 2050 EXPECT_EQ(nullptr, filter->rssi.get()); |
2082 EXPECT_EQ(nullptr, filter->pathloss.get()); | 2051 EXPECT_EQ(nullptr, filter->pathloss.get()); |
2083 EXPECT_EQ(nullptr, filter->uuids.get()); | 2052 EXPECT_EQ(nullptr, filter->uuids.get()); |
2084 | 2053 |
2085 // Request to stop discovery 4 times. | 2054 // Request to stop discovery 4 times. |
2086 for (int i = 3; i >= 0; i--) { | 2055 for (int i = 3; i >= 0; i--) { |
2087 discovery_sessions_[i]->Stop( | 2056 discovery_sessions_[i]->Stop( |
2088 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), | 2057 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
2089 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 2058 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2090 base::Unretained(this))); | |
2091 | 2059 |
2092 // Every session stopping would trigger filter update | 2060 // Every session stopping would trigger filter update |
2093 message_loop_.Run(); | 2061 message_loop_.Run(); |
2094 } | 2062 } |
2095 } | 2063 } |
2096 | 2064 |
2097 TEST_F(BluetoothChromeOSTest, DeviceProperties) { | 2065 TEST_F(BluetoothBlueZTest, DeviceProperties) { |
2098 GetAdapter(); | 2066 GetAdapter(); |
2099 | 2067 |
2100 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2068 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2101 ASSERT_EQ(2U, devices.size()); | 2069 ASSERT_EQ(2U, devices.size()); |
2102 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2070 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2103 devices[0]->GetAddress()); | 2071 devices[0]->GetAddress()); |
2104 | 2072 |
2105 // Verify the other device properties. | 2073 // Verify the other device properties. |
2106 EXPECT_EQ( | 2074 EXPECT_EQ( |
2107 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), | 2075 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), |
(...skipping 10 matching lines...) Expand all Loading... |
2118 ASSERT_EQ(2U, uuids.size()); | 2086 ASSERT_EQ(2U, uuids.size()); |
2119 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); | 2087 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); |
2120 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); | 2088 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); |
2121 | 2089 |
2122 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); | 2090 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); |
2123 EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); | 2091 EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); |
2124 EXPECT_EQ(0x030d, devices[0]->GetProductID()); | 2092 EXPECT_EQ(0x030d, devices[0]->GetProductID()); |
2125 EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); | 2093 EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); |
2126 } | 2094 } |
2127 | 2095 |
2128 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { | 2096 TEST_F(BluetoothBlueZTest, DeviceClassChanged) { |
2129 // Simulate a change of class of a device, as sometimes occurs | 2097 // Simulate a change of class of a device, as sometimes occurs |
2130 // during discovery. | 2098 // during discovery. |
2131 GetAdapter(); | 2099 GetAdapter(); |
2132 | 2100 |
2133 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2101 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2134 ASSERT_EQ(2U, devices.size()); | 2102 ASSERT_EQ(2U, devices.size()); |
2135 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2103 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2136 devices[0]->GetAddress()); | 2104 devices[0]->GetAddress()); |
2137 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); | 2105 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); |
2138 | 2106 |
2139 // Install an observer; expect the DeviceChanged method to be called when | 2107 // Install an observer; expect the DeviceChanged method to be called when |
2140 // we change the class of the device. | 2108 // we change the class of the device. |
2141 TestBluetoothAdapterObserver observer(adapter_); | 2109 TestBluetoothAdapterObserver observer(adapter_); |
2142 | 2110 |
2143 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2111 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2144 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2112 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2145 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2113 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
2146 | 2114 |
2147 properties->bluetooth_class.ReplaceValue(0x002580); | 2115 properties->bluetooth_class.ReplaceValue(0x002580); |
2148 | 2116 |
2149 EXPECT_EQ(1, observer.device_changed_count()); | 2117 EXPECT_EQ(1, observer.device_changed_count()); |
2150 EXPECT_EQ(devices[0], observer.last_device()); | 2118 EXPECT_EQ(devices[0], observer.last_device()); |
2151 | 2119 |
2152 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[0]->GetDeviceType()); | 2120 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[0]->GetDeviceType()); |
2153 } | 2121 } |
2154 | 2122 |
2155 TEST_F(BluetoothChromeOSTest, DeviceNameChanged) { | 2123 TEST_F(BluetoothBlueZTest, DeviceNameChanged) { |
2156 // Simulate a change of name of a device. | 2124 // Simulate a change of name of a device. |
2157 GetAdapter(); | 2125 GetAdapter(); |
2158 | 2126 |
2159 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2127 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2160 ASSERT_EQ(2U, devices.size()); | 2128 ASSERT_EQ(2U, devices.size()); |
2161 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2129 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2162 devices[0]->GetAddress()); | 2130 devices[0]->GetAddress()); |
2163 ASSERT_EQ( | 2131 ASSERT_EQ( |
2164 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), | 2132 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), |
2165 devices[0]->GetName()); | 2133 devices[0]->GetName()); |
2166 | 2134 |
2167 // Install an observer; expect the DeviceChanged method to be called when | 2135 // Install an observer; expect the DeviceChanged method to be called when |
2168 // we change the alias of the device. | 2136 // we change the alias of the device. |
2169 TestBluetoothAdapterObserver observer(adapter_); | 2137 TestBluetoothAdapterObserver observer(adapter_); |
2170 | 2138 |
2171 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2139 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2172 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2140 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2173 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2141 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
2174 | 2142 |
2175 static const std::string new_name("New Device Name"); | 2143 static const std::string new_name("New Device Name"); |
2176 properties->alias.ReplaceValue(new_name); | 2144 properties->alias.ReplaceValue(new_name); |
2177 | 2145 |
2178 EXPECT_EQ(1, observer.device_changed_count()); | 2146 EXPECT_EQ(1, observer.device_changed_count()); |
2179 EXPECT_EQ(devices[0], observer.last_device()); | 2147 EXPECT_EQ(devices[0], observer.last_device()); |
2180 | 2148 |
2181 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[0]->GetName()); | 2149 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[0]->GetName()); |
2182 } | 2150 } |
2183 | 2151 |
2184 TEST_F(BluetoothChromeOSTest, DeviceAddressChanged) { | 2152 TEST_F(BluetoothBlueZTest, DeviceAddressChanged) { |
2185 // Simulate a change of address of a device. | 2153 // Simulate a change of address of a device. |
2186 GetAdapter(); | 2154 GetAdapter(); |
2187 | 2155 |
2188 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2156 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2189 ASSERT_EQ(2U, devices.size()); | 2157 ASSERT_EQ(2U, devices.size()); |
2190 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2158 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2191 devices[0]->GetAddress()); | 2159 devices[0]->GetAddress()); |
2192 ASSERT_EQ( | 2160 ASSERT_EQ( |
2193 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), | 2161 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), |
2194 devices[0]->GetName()); | 2162 devices[0]->GetName()); |
2195 | 2163 |
2196 // Install an observer; expect the DeviceAddressChanged method to be called | 2164 // Install an observer; expect the DeviceAddressChanged method to be called |
2197 // when we change the alias of the device. | 2165 // when we change the alias of the device. |
2198 TestBluetoothAdapterObserver observer(adapter_); | 2166 TestBluetoothAdapterObserver observer(adapter_); |
2199 | 2167 |
2200 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2168 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2201 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2169 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2202 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2170 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
2203 | 2171 |
2204 static const char* kNewAddress = "D9:1F:FC:11:22:33"; | 2172 static const char* kNewAddress = "D9:1F:FC:11:22:33"; |
2205 properties->address.ReplaceValue(kNewAddress); | 2173 properties->address.ReplaceValue(kNewAddress); |
2206 | 2174 |
2207 EXPECT_EQ(1, observer.device_address_changed_count()); | 2175 EXPECT_EQ(1, observer.device_address_changed_count()); |
2208 EXPECT_EQ(1, observer.device_changed_count()); | 2176 EXPECT_EQ(1, observer.device_changed_count()); |
2209 EXPECT_EQ(devices[0], observer.last_device()); | 2177 EXPECT_EQ(devices[0], observer.last_device()); |
2210 | 2178 |
2211 EXPECT_EQ(std::string(kNewAddress), devices[0]->GetAddress()); | 2179 EXPECT_EQ(std::string(kNewAddress), devices[0]->GetAddress()); |
2212 } | 2180 } |
2213 | 2181 |
2214 TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { | 2182 TEST_F(BluetoothBlueZTest, DeviceUuidsChanged) { |
2215 // Simulate a change of advertised services of a device. | 2183 // Simulate a change of advertised services of a device. |
2216 GetAdapter(); | 2184 GetAdapter(); |
2217 | 2185 |
2218 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2186 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2219 ASSERT_EQ(2U, devices.size()); | 2187 ASSERT_EQ(2U, devices.size()); |
2220 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2188 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2221 devices[0]->GetAddress()); | 2189 devices[0]->GetAddress()); |
2222 | 2190 |
2223 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); | 2191 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); |
2224 ASSERT_EQ(2U, uuids.size()); | 2192 ASSERT_EQ(2U, uuids.size()); |
(...skipping 23 matching lines...) Expand all Loading... |
2248 // Fetching the value should give the new one. | 2216 // Fetching the value should give the new one. |
2249 uuids = devices[0]->GetUUIDs(); | 2217 uuids = devices[0]->GetUUIDs(); |
2250 ASSERT_EQ(5U, uuids.size()); | 2218 ASSERT_EQ(5U, uuids.size()); |
2251 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); | 2219 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); |
2252 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); | 2220 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); |
2253 EXPECT_EQ(uuids[2], BluetoothUUID("110c")); | 2221 EXPECT_EQ(uuids[2], BluetoothUUID("110c")); |
2254 EXPECT_EQ(uuids[3], BluetoothUUID("110e")); | 2222 EXPECT_EQ(uuids[3], BluetoothUUID("110e")); |
2255 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); | 2223 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); |
2256 } | 2224 } |
2257 | 2225 |
2258 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { | 2226 TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIInvalidated) { |
2259 // Simulate invalidation of inquiry RSSI of a device, as it occurs | 2227 // Simulate invalidation of inquiry RSSI of a device, as it occurs |
2260 // when discovery is finished. | 2228 // when discovery is finished. |
2261 GetAdapter(); | 2229 GetAdapter(); |
2262 | 2230 |
2263 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2231 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2264 ASSERT_EQ(2U, devices.size()); | 2232 ASSERT_EQ(2U, devices.size()); |
2265 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2233 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2266 devices[0]->GetAddress()); | 2234 devices[0]->GetAddress()); |
2267 | 2235 |
2268 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2236 bluez::FakeBluetoothDeviceClient::Properties* properties = |
(...skipping 14 matching lines...) Expand all Loading... |
2283 properties->rssi.set_valid(false); | 2251 properties->rssi.set_valid(false); |
2284 properties->NotifyPropertyChanged(properties->rssi.name()); | 2252 properties->NotifyPropertyChanged(properties->rssi.name()); |
2285 | 2253 |
2286 EXPECT_EQ(1, observer.device_changed_count()); | 2254 EXPECT_EQ(1, observer.device_changed_count()); |
2287 EXPECT_EQ(devices[0], observer.last_device()); | 2255 EXPECT_EQ(devices[0], observer.last_device()); |
2288 | 2256 |
2289 int unknown_power = BluetoothDevice::kUnknownPower; | 2257 int unknown_power = BluetoothDevice::kUnknownPower; |
2290 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); | 2258 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); |
2291 } | 2259 } |
2292 | 2260 |
2293 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { | 2261 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) { |
2294 // Simulate invalidation of inquiry TxPower of a device, as it occurs | 2262 // Simulate invalidation of inquiry TxPower of a device, as it occurs |
2295 // when discovery is finished. | 2263 // when discovery is finished. |
2296 GetAdapter(); | 2264 GetAdapter(); |
2297 | 2265 |
2298 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2266 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2299 ASSERT_EQ(2U, devices.size()); | 2267 ASSERT_EQ(2U, devices.size()); |
2300 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2268 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2301 devices[0]->GetAddress()); | 2269 devices[0]->GetAddress()); |
2302 | 2270 |
2303 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2271 bluez::FakeBluetoothDeviceClient::Properties* properties = |
(...skipping 14 matching lines...) Expand all Loading... |
2318 properties->tx_power.set_valid(false); | 2286 properties->tx_power.set_valid(false); |
2319 properties->NotifyPropertyChanged(properties->tx_power.name()); | 2287 properties->NotifyPropertyChanged(properties->tx_power.name()); |
2320 | 2288 |
2321 EXPECT_EQ(1, observer.device_changed_count()); | 2289 EXPECT_EQ(1, observer.device_changed_count()); |
2322 EXPECT_EQ(devices[0], observer.last_device()); | 2290 EXPECT_EQ(devices[0], observer.last_device()); |
2323 | 2291 |
2324 int unknown_power = BluetoothDevice::kUnknownPower; | 2292 int unknown_power = BluetoothDevice::kUnknownPower; |
2325 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); | 2293 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); |
2326 } | 2294 } |
2327 | 2295 |
2328 TEST_F(BluetoothChromeOSTest, ForgetDevice) { | 2296 TEST_F(BluetoothBlueZTest, ForgetDevice) { |
2329 GetAdapter(); | 2297 GetAdapter(); |
2330 | 2298 |
2331 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2299 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2332 ASSERT_EQ(2U, devices.size()); | 2300 ASSERT_EQ(2U, devices.size()); |
2333 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2301 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
2334 devices[0]->GetAddress()); | 2302 devices[0]->GetAddress()); |
2335 | 2303 |
2336 std::string address = devices[0]->GetAddress(); | 2304 std::string address = devices[0]->GetAddress(); |
2337 | 2305 |
2338 // Install an observer; expect the DeviceRemoved method to be called | 2306 // Install an observer; expect the DeviceRemoved method to be called |
2339 // with the device we remove. | 2307 // with the device we remove. |
2340 TestBluetoothAdapterObserver observer(adapter_); | 2308 TestBluetoothAdapterObserver observer(adapter_); |
2341 | 2309 |
2342 devices[0]->Forget(GetErrorCallback()); | 2310 devices[0]->Forget(GetErrorCallback()); |
2343 EXPECT_EQ(0, error_callback_count_); | 2311 EXPECT_EQ(0, error_callback_count_); |
2344 | 2312 |
2345 EXPECT_EQ(1, observer.device_removed_count()); | 2313 EXPECT_EQ(1, observer.device_removed_count()); |
2346 EXPECT_EQ(address, observer.last_device_address()); | 2314 EXPECT_EQ(address, observer.last_device_address()); |
2347 | 2315 |
2348 // GetDevices shouldn't return the device either. | 2316 // GetDevices shouldn't return the device either. |
2349 devices = adapter_->GetDevices(); | 2317 devices = adapter_->GetDevices(); |
2350 ASSERT_EQ(1U, devices.size()); | 2318 ASSERT_EQ(1U, devices.size()); |
2351 } | 2319 } |
2352 | 2320 |
2353 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { | 2321 TEST_F(BluetoothBlueZTest, ForgetUnpairedDevice) { |
2354 GetAdapter(); | 2322 GetAdapter(); |
2355 DiscoverDevices(); | 2323 DiscoverDevices(); |
2356 | 2324 |
2357 BluetoothDevice* device = adapter_->GetDevice( | 2325 BluetoothDevice* device = adapter_->GetDevice( |
2358 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2326 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
2359 ASSERT_TRUE(device != nullptr); | 2327 ASSERT_TRUE(device != nullptr); |
2360 ASSERT_FALSE(device->IsPaired()); | 2328 ASSERT_FALSE(device->IsPaired()); |
2361 | 2329 |
2362 // Connect the device so it becomes trusted and remembered. | 2330 // Connect the device so it becomes trusted and remembered. |
2363 device->Connect(nullptr, GetCallback(), | 2331 device->Connect(nullptr, GetCallback(), |
2364 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2332 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2365 base::Unretained(this))); | 2333 base::Unretained(this))); |
2366 | 2334 |
2367 ASSERT_EQ(1, callback_count_); | 2335 ASSERT_EQ(1, callback_count_); |
2368 ASSERT_EQ(0, error_callback_count_); | 2336 ASSERT_EQ(0, error_callback_count_); |
2369 callback_count_ = 0; | 2337 callback_count_ = 0; |
2370 | 2338 |
2371 ASSERT_TRUE(device->IsConnected()); | 2339 ASSERT_TRUE(device->IsConnected()); |
2372 ASSERT_FALSE(device->IsConnecting()); | 2340 ASSERT_FALSE(device->IsConnecting()); |
2373 | 2341 |
2374 // Make sure the trusted property has been set to true. | 2342 // Make sure the trusted property has been set to true. |
(...skipping 12 matching lines...) Expand all Loading... |
2387 EXPECT_EQ(1, observer.device_removed_count()); | 2355 EXPECT_EQ(1, observer.device_removed_count()); |
2388 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress, | 2356 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress, |
2389 observer.last_device_address()); | 2357 observer.last_device_address()); |
2390 | 2358 |
2391 // GetDevices shouldn't return the device either. | 2359 // GetDevices shouldn't return the device either. |
2392 device = adapter_->GetDevice( | 2360 device = adapter_->GetDevice( |
2393 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2361 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
2394 EXPECT_FALSE(device != nullptr); | 2362 EXPECT_FALSE(device != nullptr); |
2395 } | 2363 } |
2396 | 2364 |
2397 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { | 2365 TEST_F(BluetoothBlueZTest, ConnectPairedDevice) { |
2398 GetAdapter(); | 2366 GetAdapter(); |
2399 | 2367 |
2400 BluetoothDevice* device = adapter_->GetDevice( | 2368 BluetoothDevice* device = adapter_->GetDevice( |
2401 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2369 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
2402 ASSERT_TRUE(device != nullptr); | 2370 ASSERT_TRUE(device != nullptr); |
2403 ASSERT_TRUE(device->IsPaired()); | 2371 ASSERT_TRUE(device->IsPaired()); |
2404 | 2372 |
2405 TestBluetoothAdapterObserver observer(adapter_); | 2373 TestBluetoothAdapterObserver observer(adapter_); |
2406 | 2374 |
2407 // Connect without a pairing delegate; since the device is already Paired | 2375 // Connect without a pairing delegate; since the device is already Paired |
2408 // this should succeed and the device should become connected. | 2376 // this should succeed and the device should become connected. |
2409 device->Connect(nullptr, GetCallback(), | 2377 device->Connect(nullptr, GetCallback(), |
2410 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2378 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2411 base::Unretained(this))); | 2379 base::Unretained(this))); |
2412 | 2380 |
2413 EXPECT_EQ(1, callback_count_); | 2381 EXPECT_EQ(1, callback_count_); |
2414 EXPECT_EQ(0, error_callback_count_); | 2382 EXPECT_EQ(0, error_callback_count_); |
2415 | 2383 |
2416 // Two changes for connecting, one for connected and one for for trusted | 2384 // Two changes for connecting, one for connected and one for for trusted |
2417 // after connecting. | 2385 // after connecting. |
2418 EXPECT_EQ(4, observer.device_changed_count()); | 2386 EXPECT_EQ(4, observer.device_changed_count()); |
2419 EXPECT_EQ(device, observer.last_device()); | 2387 EXPECT_EQ(device, observer.last_device()); |
2420 | 2388 |
2421 EXPECT_TRUE(device->IsConnected()); | 2389 EXPECT_TRUE(device->IsConnected()); |
2422 EXPECT_FALSE(device->IsConnecting()); | 2390 EXPECT_FALSE(device->IsConnecting()); |
2423 } | 2391 } |
2424 | 2392 |
2425 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { | 2393 TEST_F(BluetoothBlueZTest, ConnectUnpairableDevice) { |
2426 GetAdapter(); | 2394 GetAdapter(); |
2427 DiscoverDevices(); | 2395 DiscoverDevices(); |
2428 | 2396 |
2429 BluetoothDevice* device = adapter_->GetDevice( | 2397 BluetoothDevice* device = adapter_->GetDevice( |
2430 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2398 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
2431 ASSERT_TRUE(device != nullptr); | 2399 ASSERT_TRUE(device != nullptr); |
2432 ASSERT_FALSE(device->IsPaired()); | 2400 ASSERT_FALSE(device->IsPaired()); |
2433 | 2401 |
2434 TestBluetoothAdapterObserver observer(adapter_); | 2402 TestBluetoothAdapterObserver observer(adapter_); |
2435 | 2403 |
2436 // Connect without a pairing delegate; since the device does not require | 2404 // Connect without a pairing delegate; since the device does not require |
2437 // pairing, this should succeed and the device should become connected. | 2405 // pairing, this should succeed and the device should become connected. |
2438 device->Connect(nullptr, GetCallback(), | 2406 device->Connect(nullptr, GetCallback(), |
2439 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2407 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2440 base::Unretained(this))); | 2408 base::Unretained(this))); |
2441 | 2409 |
2442 EXPECT_EQ(1, callback_count_); | 2410 EXPECT_EQ(1, callback_count_); |
2443 EXPECT_EQ(0, error_callback_count_); | 2411 EXPECT_EQ(0, error_callback_count_); |
2444 | 2412 |
2445 // Two changes for connecting, one for connected, one for for trusted after | 2413 // Two changes for connecting, one for connected, one for for trusted after |
2446 // connection, and one for the reconnect mode (IsConnectable). | 2414 // connection, and one for the reconnect mode (IsConnectable). |
2447 EXPECT_EQ(5, observer.device_changed_count()); | 2415 EXPECT_EQ(5, observer.device_changed_count()); |
2448 EXPECT_EQ(device, observer.last_device()); | 2416 EXPECT_EQ(device, observer.last_device()); |
2449 | 2417 |
2450 EXPECT_TRUE(device->IsConnected()); | 2418 EXPECT_TRUE(device->IsConnected()); |
2451 EXPECT_FALSE(device->IsConnecting()); | 2419 EXPECT_FALSE(device->IsConnecting()); |
2452 | 2420 |
2453 // Make sure the trusted property has been set to true. | 2421 // Make sure the trusted property has been set to true. |
2454 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2422 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2455 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2423 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2456 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); | 2424 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); |
2457 EXPECT_TRUE(properties->trusted.value()); | 2425 EXPECT_TRUE(properties->trusted.value()); |
2458 | 2426 |
2459 // Verify is a HID device and is not connectable. | 2427 // Verify is a HID device and is not connectable. |
2460 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2428 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
2461 ASSERT_EQ(1U, uuids.size()); | 2429 ASSERT_EQ(1U, uuids.size()); |
2462 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2430 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
2463 EXPECT_FALSE(device->IsConnectable()); | 2431 EXPECT_FALSE(device->IsConnectable()); |
2464 } | 2432 } |
2465 | 2433 |
2466 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { | 2434 TEST_F(BluetoothBlueZTest, ConnectConnectedDevice) { |
2467 GetAdapter(); | 2435 GetAdapter(); |
2468 | 2436 |
2469 BluetoothDevice* device = adapter_->GetDevice( | 2437 BluetoothDevice* device = adapter_->GetDevice( |
2470 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2438 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
2471 ASSERT_TRUE(device != nullptr); | 2439 ASSERT_TRUE(device != nullptr); |
2472 ASSERT_TRUE(device->IsPaired()); | 2440 ASSERT_TRUE(device->IsPaired()); |
2473 | 2441 |
2474 device->Connect(nullptr, GetCallback(), | 2442 device->Connect(nullptr, GetCallback(), |
2475 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2443 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2476 base::Unretained(this))); | 2444 base::Unretained(this))); |
2477 | 2445 |
2478 ASSERT_EQ(1, callback_count_); | 2446 ASSERT_EQ(1, callback_count_); |
2479 ASSERT_EQ(0, error_callback_count_); | 2447 ASSERT_EQ(0, error_callback_count_); |
2480 callback_count_ = 0; | 2448 callback_count_ = 0; |
2481 | 2449 |
2482 ASSERT_TRUE(device->IsConnected()); | 2450 ASSERT_TRUE(device->IsConnected()); |
2483 | 2451 |
2484 // Connect again; since the device is already Connected, this shouldn't do | 2452 // Connect again; since the device is already Connected, this shouldn't do |
2485 // anything to initiate the connection. | 2453 // anything to initiate the connection. |
2486 TestBluetoothAdapterObserver observer(adapter_); | 2454 TestBluetoothAdapterObserver observer(adapter_); |
2487 | 2455 |
2488 device->Connect(nullptr, GetCallback(), | 2456 device->Connect(nullptr, GetCallback(), |
2489 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2457 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2490 base::Unretained(this))); | 2458 base::Unretained(this))); |
2491 | 2459 |
2492 EXPECT_EQ(1, callback_count_); | 2460 EXPECT_EQ(1, callback_count_); |
2493 EXPECT_EQ(0, error_callback_count_); | 2461 EXPECT_EQ(0, error_callback_count_); |
2494 | 2462 |
2495 // The observer will be called because Connecting will toggle true and false, | 2463 // The observer will be called because Connecting will toggle true and false, |
2496 // and the trusted property will be updated to true. | 2464 // and the trusted property will be updated to true. |
2497 EXPECT_EQ(3, observer.device_changed_count()); | 2465 EXPECT_EQ(3, observer.device_changed_count()); |
2498 | 2466 |
2499 EXPECT_TRUE(device->IsConnected()); | 2467 EXPECT_TRUE(device->IsConnected()); |
2500 EXPECT_FALSE(device->IsConnecting()); | 2468 EXPECT_FALSE(device->IsConnecting()); |
2501 } | 2469 } |
2502 | 2470 |
2503 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { | 2471 TEST_F(BluetoothBlueZTest, ConnectDeviceFails) { |
2504 GetAdapter(); | 2472 GetAdapter(); |
2505 DiscoverDevices(); | 2473 DiscoverDevices(); |
2506 | 2474 |
2507 BluetoothDevice* device = adapter_->GetDevice( | 2475 BluetoothDevice* device = adapter_->GetDevice( |
2508 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2476 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
2509 ASSERT_TRUE(device != nullptr); | 2477 ASSERT_TRUE(device != nullptr); |
2510 ASSERT_FALSE(device->IsPaired()); | 2478 ASSERT_FALSE(device->IsPaired()); |
2511 | 2479 |
2512 TestBluetoothAdapterObserver observer(adapter_); | 2480 TestBluetoothAdapterObserver observer(adapter_); |
2513 | 2481 |
2514 // Connect without a pairing delegate; since the device requires pairing, | 2482 // Connect without a pairing delegate; since the device requires pairing, |
2515 // this should fail with an error. | 2483 // this should fail with an error. |
2516 device->Connect(nullptr, GetCallback(), | 2484 device->Connect(nullptr, GetCallback(), |
2517 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2485 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2518 base::Unretained(this))); | 2486 base::Unretained(this))); |
2519 | 2487 |
2520 EXPECT_EQ(0, callback_count_); | 2488 EXPECT_EQ(0, callback_count_); |
2521 EXPECT_EQ(1, error_callback_count_); | 2489 EXPECT_EQ(1, error_callback_count_); |
2522 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 2490 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
2523 | 2491 |
2524 EXPECT_EQ(2, observer.device_changed_count()); | 2492 EXPECT_EQ(2, observer.device_changed_count()); |
2525 | 2493 |
2526 EXPECT_FALSE(device->IsConnected()); | 2494 EXPECT_FALSE(device->IsConnected()); |
2527 EXPECT_FALSE(device->IsConnecting()); | 2495 EXPECT_FALSE(device->IsConnecting()); |
2528 } | 2496 } |
2529 | 2497 |
2530 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { | 2498 TEST_F(BluetoothBlueZTest, DisconnectDevice) { |
2531 GetAdapter(); | 2499 GetAdapter(); |
2532 | 2500 |
2533 BluetoothDevice* device = adapter_->GetDevice( | 2501 BluetoothDevice* device = adapter_->GetDevice( |
2534 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2502 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
2535 ASSERT_TRUE(device != nullptr); | 2503 ASSERT_TRUE(device != nullptr); |
2536 ASSERT_TRUE(device->IsPaired()); | 2504 ASSERT_TRUE(device->IsPaired()); |
2537 | 2505 |
2538 device->Connect(nullptr, GetCallback(), | 2506 device->Connect(nullptr, GetCallback(), |
2539 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2507 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2540 base::Unretained(this))); | 2508 base::Unretained(this))); |
2541 | 2509 |
2542 ASSERT_EQ(1, callback_count_); | 2510 ASSERT_EQ(1, callback_count_); |
2543 ASSERT_EQ(0, error_callback_count_); | 2511 ASSERT_EQ(0, error_callback_count_); |
2544 callback_count_ = 0; | 2512 callback_count_ = 0; |
2545 | 2513 |
2546 ASSERT_TRUE(device->IsConnected()); | 2514 ASSERT_TRUE(device->IsConnected()); |
2547 ASSERT_FALSE(device->IsConnecting()); | 2515 ASSERT_FALSE(device->IsConnecting()); |
2548 | 2516 |
2549 // Disconnect the device, we should see the observer method fire and the | 2517 // Disconnect the device, we should see the observer method fire and the |
2550 // device get dropped. | 2518 // device get dropped. |
2551 TestBluetoothAdapterObserver observer(adapter_); | 2519 TestBluetoothAdapterObserver observer(adapter_); |
2552 | 2520 |
2553 device->Disconnect(GetCallback(), GetErrorCallback()); | 2521 device->Disconnect(GetCallback(), GetErrorCallback()); |
2554 | 2522 |
2555 EXPECT_EQ(1, callback_count_); | 2523 EXPECT_EQ(1, callback_count_); |
2556 EXPECT_EQ(0, error_callback_count_); | 2524 EXPECT_EQ(0, error_callback_count_); |
2557 | 2525 |
2558 EXPECT_EQ(1, observer.device_changed_count()); | 2526 EXPECT_EQ(1, observer.device_changed_count()); |
2559 EXPECT_EQ(device, observer.last_device()); | 2527 EXPECT_EQ(device, observer.last_device()); |
2560 | 2528 |
2561 EXPECT_FALSE(device->IsConnected()); | 2529 EXPECT_FALSE(device->IsConnected()); |
2562 } | 2530 } |
2563 | 2531 |
2564 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { | 2532 TEST_F(BluetoothBlueZTest, DisconnectUnconnectedDevice) { |
2565 GetAdapter(); | 2533 GetAdapter(); |
2566 | 2534 |
2567 BluetoothDevice* device = adapter_->GetDevice( | 2535 BluetoothDevice* device = adapter_->GetDevice( |
2568 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2536 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
2569 ASSERT_TRUE(device != nullptr); | 2537 ASSERT_TRUE(device != nullptr); |
2570 ASSERT_TRUE(device->IsPaired()); | 2538 ASSERT_TRUE(device->IsPaired()); |
2571 ASSERT_FALSE(device->IsConnected()); | 2539 ASSERT_FALSE(device->IsConnected()); |
2572 | 2540 |
2573 // Disconnect the device, we should see the observer method fire and the | 2541 // Disconnect the device, we should see the observer method fire and the |
2574 // device get dropped. | 2542 // device get dropped. |
2575 TestBluetoothAdapterObserver observer(adapter_); | 2543 TestBluetoothAdapterObserver observer(adapter_); |
2576 | 2544 |
2577 device->Disconnect(GetCallback(), GetErrorCallback()); | 2545 device->Disconnect(GetCallback(), GetErrorCallback()); |
2578 | 2546 |
2579 EXPECT_EQ(0, callback_count_); | 2547 EXPECT_EQ(0, callback_count_); |
2580 EXPECT_EQ(1, error_callback_count_); | 2548 EXPECT_EQ(1, error_callback_count_); |
2581 | 2549 |
2582 EXPECT_EQ(0, observer.device_changed_count()); | 2550 EXPECT_EQ(0, observer.device_changed_count()); |
2583 | 2551 |
2584 EXPECT_FALSE(device->IsConnected()); | 2552 EXPECT_FALSE(device->IsConnected()); |
2585 } | 2553 } |
2586 | 2554 |
2587 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { | 2555 TEST_F(BluetoothBlueZTest, PairLegacyAutopair) { |
2588 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2556 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2589 | 2557 |
2590 GetAdapter(); | 2558 GetAdapter(); |
2591 DiscoverDevices(); | 2559 DiscoverDevices(); |
2592 | 2560 |
2593 // The Legacy Autopair device requires no PIN or Passkey to pair because | 2561 // The Legacy Autopair device requires no PIN or Passkey to pair because |
2594 // the daemon provides 0000 to the device for us. | 2562 // the daemon provides 0000 to the device for us. |
2595 BluetoothDevice* device = adapter_->GetDevice( | 2563 BluetoothDevice* device = adapter_->GetDevice( |
2596 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2564 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
2597 ASSERT_TRUE(device != nullptr); | 2565 ASSERT_TRUE(device != nullptr); |
2598 ASSERT_FALSE(device->IsPaired()); | 2566 ASSERT_FALSE(device->IsPaired()); |
2599 | 2567 |
2600 TestBluetoothAdapterObserver observer(adapter_); | 2568 TestBluetoothAdapterObserver observer(adapter_); |
2601 | 2569 |
2602 TestPairingDelegate pairing_delegate; | 2570 TestPairingDelegate pairing_delegate; |
2603 device->Connect(&pairing_delegate, GetCallback(), | 2571 device->Connect(&pairing_delegate, GetCallback(), |
2604 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2572 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2605 base::Unretained(this))); | 2573 base::Unretained(this))); |
2606 | 2574 |
2607 EXPECT_EQ(0, pairing_delegate.call_count_); | 2575 EXPECT_EQ(0, pairing_delegate.call_count_); |
2608 EXPECT_TRUE(device->IsConnecting()); | 2576 EXPECT_TRUE(device->IsConnecting()); |
2609 | 2577 |
2610 message_loop_.Run(); | 2578 message_loop_.Run(); |
2611 | 2579 |
2612 EXPECT_EQ(1, callback_count_); | 2580 EXPECT_EQ(1, callback_count_); |
2613 EXPECT_EQ(0, error_callback_count_); | 2581 EXPECT_EQ(0, error_callback_count_); |
2614 | 2582 |
(...skipping 14 matching lines...) Expand all Loading... |
2629 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2597 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
2630 EXPECT_TRUE(device->IsConnectable()); | 2598 EXPECT_TRUE(device->IsConnectable()); |
2631 | 2599 |
2632 // Make sure the trusted property has been set to true. | 2600 // Make sure the trusted property has been set to true. |
2633 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2601 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2634 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2602 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2635 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); | 2603 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); |
2636 EXPECT_TRUE(properties->trusted.value()); | 2604 EXPECT_TRUE(properties->trusted.value()); |
2637 } | 2605 } |
2638 | 2606 |
2639 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { | 2607 TEST_F(BluetoothBlueZTest, PairDisplayPinCode) { |
2640 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2608 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2641 | 2609 |
2642 GetAdapter(); | 2610 GetAdapter(); |
2643 DiscoverDevices(); | 2611 DiscoverDevices(); |
2644 | 2612 |
2645 // Requires that we display a randomly generated PIN on the screen. | 2613 // Requires that we display a randomly generated PIN on the screen. |
2646 BluetoothDevice* device = adapter_->GetDevice( | 2614 BluetoothDevice* device = adapter_->GetDevice( |
2647 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress); | 2615 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress); |
2648 ASSERT_TRUE(device != nullptr); | 2616 ASSERT_TRUE(device != nullptr); |
2649 ASSERT_FALSE(device->IsPaired()); | 2617 ASSERT_FALSE(device->IsPaired()); |
2650 | 2618 |
2651 TestBluetoothAdapterObserver observer(adapter_); | 2619 TestBluetoothAdapterObserver observer(adapter_); |
2652 | 2620 |
2653 TestPairingDelegate pairing_delegate; | 2621 TestPairingDelegate pairing_delegate; |
2654 device->Connect(&pairing_delegate, GetCallback(), | 2622 device->Connect(&pairing_delegate, GetCallback(), |
2655 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2623 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2656 base::Unretained(this))); | 2624 base::Unretained(this))); |
2657 | 2625 |
2658 EXPECT_EQ(1, pairing_delegate.call_count_); | 2626 EXPECT_EQ(1, pairing_delegate.call_count_); |
2659 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); | 2627 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); |
2660 EXPECT_EQ("123456", pairing_delegate.last_pincode_); | 2628 EXPECT_EQ("123456", pairing_delegate.last_pincode_); |
2661 EXPECT_TRUE(device->IsConnecting()); | 2629 EXPECT_TRUE(device->IsConnecting()); |
2662 | 2630 |
2663 message_loop_.Run(); | 2631 message_loop_.Run(); |
2664 | 2632 |
2665 EXPECT_EQ(1, callback_count_); | 2633 EXPECT_EQ(1, callback_count_); |
(...skipping 16 matching lines...) Expand all Loading... |
2682 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2650 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
2683 EXPECT_TRUE(device->IsConnectable()); | 2651 EXPECT_TRUE(device->IsConnectable()); |
2684 | 2652 |
2685 // Make sure the trusted property has been set to true. | 2653 // Make sure the trusted property has been set to true. |
2686 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2654 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2687 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2655 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2688 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); | 2656 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); |
2689 EXPECT_TRUE(properties->trusted.value()); | 2657 EXPECT_TRUE(properties->trusted.value()); |
2690 } | 2658 } |
2691 | 2659 |
2692 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { | 2660 TEST_F(BluetoothBlueZTest, PairDisplayPasskey) { |
2693 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2661 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2694 | 2662 |
2695 GetAdapter(); | 2663 GetAdapter(); |
2696 DiscoverDevices(); | 2664 DiscoverDevices(); |
2697 | 2665 |
2698 // Requires that we display a randomly generated Passkey on the screen, | 2666 // Requires that we display a randomly generated Passkey on the screen, |
2699 // and notifies us as it's typed in. | 2667 // and notifies us as it's typed in. |
2700 BluetoothDevice* device = adapter_->GetDevice( | 2668 BluetoothDevice* device = adapter_->GetDevice( |
2701 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress); | 2669 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress); |
2702 ASSERT_TRUE(device != nullptr); | 2670 ASSERT_TRUE(device != nullptr); |
2703 ASSERT_FALSE(device->IsPaired()); | 2671 ASSERT_FALSE(device->IsPaired()); |
2704 | 2672 |
2705 TestBluetoothAdapterObserver observer(adapter_); | 2673 TestBluetoothAdapterObserver observer(adapter_); |
2706 | 2674 |
2707 TestPairingDelegate pairing_delegate; | 2675 TestPairingDelegate pairing_delegate; |
2708 device->Connect(&pairing_delegate, GetCallback(), | 2676 device->Connect(&pairing_delegate, GetCallback(), |
2709 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2677 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2710 base::Unretained(this))); | 2678 base::Unretained(this))); |
2711 | 2679 |
2712 // One call for DisplayPasskey() and one for KeysEntered(). | 2680 // One call for DisplayPasskey() and one for KeysEntered(). |
2713 EXPECT_EQ(2, pairing_delegate.call_count_); | 2681 EXPECT_EQ(2, pairing_delegate.call_count_); |
2714 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); | 2682 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); |
2715 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 2683 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
2716 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); | 2684 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); |
2717 EXPECT_EQ(0U, pairing_delegate.last_entered_); | 2685 EXPECT_EQ(0U, pairing_delegate.last_entered_); |
2718 | 2686 |
2719 EXPECT_TRUE(device->IsConnecting()); | 2687 EXPECT_TRUE(device->IsConnecting()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2757 // And usually not connectable. | 2725 // And usually not connectable. |
2758 EXPECT_FALSE(device->IsConnectable()); | 2726 EXPECT_FALSE(device->IsConnectable()); |
2759 | 2727 |
2760 // Make sure the trusted property has been set to true. | 2728 // Make sure the trusted property has been set to true. |
2761 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2729 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2762 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2730 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2763 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); | 2731 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); |
2764 EXPECT_TRUE(properties->trusted.value()); | 2732 EXPECT_TRUE(properties->trusted.value()); |
2765 } | 2733 } |
2766 | 2734 |
2767 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { | 2735 TEST_F(BluetoothBlueZTest, PairRequestPinCode) { |
2768 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2736 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2769 | 2737 |
2770 GetAdapter(); | 2738 GetAdapter(); |
2771 DiscoverDevices(); | 2739 DiscoverDevices(); |
2772 | 2740 |
2773 // Requires that the user enters a PIN for them. | 2741 // Requires that the user enters a PIN for them. |
2774 BluetoothDevice* device = adapter_->GetDevice( | 2742 BluetoothDevice* device = adapter_->GetDevice( |
2775 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2743 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
2776 ASSERT_TRUE(device != nullptr); | 2744 ASSERT_TRUE(device != nullptr); |
2777 ASSERT_FALSE(device->IsPaired()); | 2745 ASSERT_FALSE(device->IsPaired()); |
2778 | 2746 |
2779 TestBluetoothAdapterObserver observer(adapter_); | 2747 TestBluetoothAdapterObserver observer(adapter_); |
2780 | 2748 |
2781 TestPairingDelegate pairing_delegate; | 2749 TestPairingDelegate pairing_delegate; |
2782 device->Connect(&pairing_delegate, GetCallback(), | 2750 device->Connect(&pairing_delegate, GetCallback(), |
2783 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2751 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2784 base::Unretained(this))); | 2752 base::Unretained(this))); |
2785 | 2753 |
2786 EXPECT_EQ(1, pairing_delegate.call_count_); | 2754 EXPECT_EQ(1, pairing_delegate.call_count_); |
2787 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 2755 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
2788 EXPECT_TRUE(device->IsConnecting()); | 2756 EXPECT_TRUE(device->IsConnecting()); |
2789 | 2757 |
2790 // Set the PIN. | 2758 // Set the PIN. |
2791 device->SetPinCode("1234"); | 2759 device->SetPinCode("1234"); |
2792 message_loop_.Run(); | 2760 message_loop_.Run(); |
2793 | 2761 |
(...skipping 17 matching lines...) Expand all Loading... |
2811 // Non HID devices are always connectable. | 2779 // Non HID devices are always connectable. |
2812 EXPECT_TRUE(device->IsConnectable()); | 2780 EXPECT_TRUE(device->IsConnectable()); |
2813 | 2781 |
2814 // Make sure the trusted property has been set to true. | 2782 // Make sure the trusted property has been set to true. |
2815 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2783 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2816 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2784 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2817 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); | 2785 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
2818 EXPECT_TRUE(properties->trusted.value()); | 2786 EXPECT_TRUE(properties->trusted.value()); |
2819 } | 2787 } |
2820 | 2788 |
2821 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { | 2789 TEST_F(BluetoothBlueZTest, PairConfirmPasskey) { |
2822 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2790 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2823 | 2791 |
2824 GetAdapter(); | 2792 GetAdapter(); |
2825 DiscoverDevices(); | 2793 DiscoverDevices(); |
2826 | 2794 |
2827 // Requests that we confirm a displayed passkey. | 2795 // Requests that we confirm a displayed passkey. |
2828 BluetoothDevice* device = adapter_->GetDevice( | 2796 BluetoothDevice* device = adapter_->GetDevice( |
2829 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2797 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
2830 ASSERT_TRUE(device != nullptr); | 2798 ASSERT_TRUE(device != nullptr); |
2831 ASSERT_FALSE(device->IsPaired()); | 2799 ASSERT_FALSE(device->IsPaired()); |
2832 | 2800 |
2833 TestBluetoothAdapterObserver observer(adapter_); | 2801 TestBluetoothAdapterObserver observer(adapter_); |
2834 | 2802 |
2835 TestPairingDelegate pairing_delegate; | 2803 TestPairingDelegate pairing_delegate; |
2836 device->Connect(&pairing_delegate, GetCallback(), | 2804 device->Connect(&pairing_delegate, GetCallback(), |
2837 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2805 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2838 base::Unretained(this))); | 2806 base::Unretained(this))); |
2839 | 2807 |
2840 EXPECT_EQ(1, pairing_delegate.call_count_); | 2808 EXPECT_EQ(1, pairing_delegate.call_count_); |
2841 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 2809 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
2842 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 2810 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
2843 EXPECT_TRUE(device->IsConnecting()); | 2811 EXPECT_TRUE(device->IsConnecting()); |
2844 | 2812 |
2845 // Confirm the passkey. | 2813 // Confirm the passkey. |
2846 device->ConfirmPairing(); | 2814 device->ConfirmPairing(); |
2847 message_loop_.Run(); | 2815 message_loop_.Run(); |
(...skipping 14 matching lines...) Expand all Loading... |
2862 // Non HID devices are always connectable. | 2830 // Non HID devices are always connectable. |
2863 EXPECT_TRUE(device->IsConnectable()); | 2831 EXPECT_TRUE(device->IsConnectable()); |
2864 | 2832 |
2865 // Make sure the trusted property has been set to true. | 2833 // Make sure the trusted property has been set to true. |
2866 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2834 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2867 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2835 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2868 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 2836 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
2869 EXPECT_TRUE(properties->trusted.value()); | 2837 EXPECT_TRUE(properties->trusted.value()); |
2870 } | 2838 } |
2871 | 2839 |
2872 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { | 2840 TEST_F(BluetoothBlueZTest, PairRequestPasskey) { |
2873 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2841 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2874 | 2842 |
2875 GetAdapter(); | 2843 GetAdapter(); |
2876 DiscoverDevices(); | 2844 DiscoverDevices(); |
2877 | 2845 |
2878 // Requires that the user enters a Passkey, this would be some kind of | 2846 // Requires that the user enters a Passkey, this would be some kind of |
2879 // device that has a display, but doesn't use "just works" - maybe a car? | 2847 // device that has a display, but doesn't use "just works" - maybe a car? |
2880 BluetoothDevice* device = adapter_->GetDevice( | 2848 BluetoothDevice* device = adapter_->GetDevice( |
2881 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2849 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
2882 ASSERT_TRUE(device != nullptr); | 2850 ASSERT_TRUE(device != nullptr); |
2883 ASSERT_FALSE(device->IsPaired()); | 2851 ASSERT_FALSE(device->IsPaired()); |
2884 | 2852 |
2885 TestBluetoothAdapterObserver observer(adapter_); | 2853 TestBluetoothAdapterObserver observer(adapter_); |
2886 | 2854 |
2887 TestPairingDelegate pairing_delegate; | 2855 TestPairingDelegate pairing_delegate; |
2888 device->Connect(&pairing_delegate, GetCallback(), | 2856 device->Connect(&pairing_delegate, GetCallback(), |
2889 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2857 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2890 base::Unretained(this))); | 2858 base::Unretained(this))); |
2891 | 2859 |
2892 EXPECT_EQ(1, pairing_delegate.call_count_); | 2860 EXPECT_EQ(1, pairing_delegate.call_count_); |
2893 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 2861 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
2894 EXPECT_TRUE(device->IsConnecting()); | 2862 EXPECT_TRUE(device->IsConnecting()); |
2895 | 2863 |
2896 // Set the Passkey. | 2864 // Set the Passkey. |
2897 device->SetPasskey(1234); | 2865 device->SetPasskey(1234); |
2898 message_loop_.Run(); | 2866 message_loop_.Run(); |
2899 | 2867 |
(...skipping 13 matching lines...) Expand all Loading... |
2913 // Non HID devices are always connectable. | 2881 // Non HID devices are always connectable. |
2914 EXPECT_TRUE(device->IsConnectable()); | 2882 EXPECT_TRUE(device->IsConnectable()); |
2915 | 2883 |
2916 // Make sure the trusted property has been set to true. | 2884 // Make sure the trusted property has been set to true. |
2917 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2885 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2918 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2886 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2919 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 2887 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
2920 EXPECT_TRUE(properties->trusted.value()); | 2888 EXPECT_TRUE(properties->trusted.value()); |
2921 } | 2889 } |
2922 | 2890 |
2923 TEST_F(BluetoothChromeOSTest, PairJustWorks) { | 2891 TEST_F(BluetoothBlueZTest, PairJustWorks) { |
2924 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2892 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2925 | 2893 |
2926 GetAdapter(); | 2894 GetAdapter(); |
2927 DiscoverDevices(); | 2895 DiscoverDevices(); |
2928 | 2896 |
2929 // Uses just-works pairing, since this is an outgoing pairing, no delegate | 2897 // Uses just-works pairing, since this is an outgoing pairing, no delegate |
2930 // interaction is required. | 2898 // interaction is required. |
2931 BluetoothDevice* device = | 2899 BluetoothDevice* device = |
2932 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); | 2900 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
2933 ASSERT_TRUE(device != nullptr); | 2901 ASSERT_TRUE(device != nullptr); |
2934 ASSERT_FALSE(device->IsPaired()); | 2902 ASSERT_FALSE(device->IsPaired()); |
2935 | 2903 |
2936 TestBluetoothAdapterObserver observer(adapter_); | 2904 TestBluetoothAdapterObserver observer(adapter_); |
2937 | 2905 |
2938 TestPairingDelegate pairing_delegate; | 2906 TestPairingDelegate pairing_delegate; |
2939 device->Connect(&pairing_delegate, GetCallback(), | 2907 device->Connect(&pairing_delegate, GetCallback(), |
2940 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2908 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2941 base::Unretained(this))); | 2909 base::Unretained(this))); |
2942 | 2910 |
2943 EXPECT_EQ(0, pairing_delegate.call_count_); | 2911 EXPECT_EQ(0, pairing_delegate.call_count_); |
2944 | 2912 |
2945 message_loop_.Run(); | 2913 message_loop_.Run(); |
2946 | 2914 |
2947 EXPECT_EQ(1, callback_count_); | 2915 EXPECT_EQ(1, callback_count_); |
2948 EXPECT_EQ(0, error_callback_count_); | 2916 EXPECT_EQ(0, error_callback_count_); |
2949 | 2917 |
2950 // Two changes for connecting, one change for connected, one for paired and | 2918 // Two changes for connecting, one change for connected, one for paired and |
2951 // two for trusted (after pairing and connection). | 2919 // two for trusted (after pairing and connection). |
2952 EXPECT_EQ(6, observer.device_changed_count()); | 2920 EXPECT_EQ(6, observer.device_changed_count()); |
2953 EXPECT_EQ(device, observer.last_device()); | 2921 EXPECT_EQ(device, observer.last_device()); |
2954 | 2922 |
2955 EXPECT_TRUE(device->IsConnected()); | 2923 EXPECT_TRUE(device->IsConnected()); |
2956 EXPECT_FALSE(device->IsConnecting()); | 2924 EXPECT_FALSE(device->IsConnecting()); |
2957 | 2925 |
2958 EXPECT_TRUE(device->IsPaired()); | 2926 EXPECT_TRUE(device->IsPaired()); |
2959 | 2927 |
2960 // Non HID devices are always connectable. | 2928 // Non HID devices are always connectable. |
2961 EXPECT_TRUE(device->IsConnectable()); | 2929 EXPECT_TRUE(device->IsConnectable()); |
2962 | 2930 |
2963 // Make sure the trusted property has been set to true. | 2931 // Make sure the trusted property has been set to true. |
2964 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2932 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2965 fake_bluetooth_device_client_->GetProperties( | 2933 fake_bluetooth_device_client_->GetProperties( |
2966 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); | 2934 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
2967 EXPECT_TRUE(properties->trusted.value()); | 2935 EXPECT_TRUE(properties->trusted.value()); |
2968 } | 2936 } |
2969 | 2937 |
2970 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { | 2938 TEST_F(BluetoothBlueZTest, PairUnpairableDeviceFails) { |
2971 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2939 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
2972 | 2940 |
2973 GetAdapter(); | 2941 GetAdapter(); |
2974 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 2942 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
2975 | 2943 |
2976 BluetoothDevice* device = adapter_->GetDevice( | 2944 BluetoothDevice* device = adapter_->GetDevice( |
2977 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress); | 2945 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress); |
2978 ASSERT_TRUE(device != nullptr); | 2946 ASSERT_TRUE(device != nullptr); |
2979 ASSERT_FALSE(device->IsPaired()); | 2947 ASSERT_FALSE(device->IsPaired()); |
2980 | 2948 |
2981 TestBluetoothAdapterObserver observer(adapter_); | 2949 TestBluetoothAdapterObserver observer(adapter_); |
2982 | 2950 |
2983 TestPairingDelegate pairing_delegate; | 2951 TestPairingDelegate pairing_delegate; |
2984 device->Connect(&pairing_delegate, GetCallback(), | 2952 device->Connect(&pairing_delegate, GetCallback(), |
2985 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2953 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
2986 base::Unretained(this))); | 2954 base::Unretained(this))); |
2987 | 2955 |
2988 EXPECT_EQ(0, pairing_delegate.call_count_); | 2956 EXPECT_EQ(0, pairing_delegate.call_count_); |
2989 EXPECT_TRUE(device->IsConnecting()); | 2957 EXPECT_TRUE(device->IsConnecting()); |
2990 | 2958 |
2991 // Run the loop to get the error.. | 2959 // Run the loop to get the error.. |
2992 message_loop_.Run(); | 2960 message_loop_.Run(); |
2993 | 2961 |
2994 EXPECT_EQ(0, callback_count_); | 2962 EXPECT_EQ(0, callback_count_); |
2995 EXPECT_EQ(1, error_callback_count_); | 2963 EXPECT_EQ(1, error_callback_count_); |
2996 | 2964 |
2997 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 2965 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
2998 | 2966 |
2999 EXPECT_FALSE(device->IsConnected()); | 2967 EXPECT_FALSE(device->IsConnected()); |
3000 EXPECT_FALSE(device->IsConnecting()); | 2968 EXPECT_FALSE(device->IsConnecting()); |
3001 EXPECT_FALSE(device->IsPaired()); | 2969 EXPECT_FALSE(device->IsPaired()); |
3002 } | 2970 } |
3003 | 2971 |
3004 TEST_F(BluetoothChromeOSTest, PairingFails) { | 2972 TEST_F(BluetoothBlueZTest, PairingFails) { |
3005 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2973 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3006 | 2974 |
3007 GetAdapter(); | 2975 GetAdapter(); |
3008 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 2976 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
3009 | 2977 |
3010 // The vanishing device times out during pairing | 2978 // The vanishing device times out during pairing |
3011 BluetoothDevice* device = adapter_->GetDevice( | 2979 BluetoothDevice* device = adapter_->GetDevice( |
3012 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 2980 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
3013 ASSERT_TRUE(device != nullptr); | 2981 ASSERT_TRUE(device != nullptr); |
3014 ASSERT_FALSE(device->IsPaired()); | 2982 ASSERT_FALSE(device->IsPaired()); |
3015 | 2983 |
3016 TestBluetoothAdapterObserver observer(adapter_); | 2984 TestBluetoothAdapterObserver observer(adapter_); |
3017 | 2985 |
3018 TestPairingDelegate pairing_delegate; | 2986 TestPairingDelegate pairing_delegate; |
3019 device->Connect(&pairing_delegate, GetCallback(), | 2987 device->Connect(&pairing_delegate, GetCallback(), |
3020 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2988 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3021 base::Unretained(this))); | 2989 base::Unretained(this))); |
3022 | 2990 |
3023 EXPECT_EQ(0, pairing_delegate.call_count_); | 2991 EXPECT_EQ(0, pairing_delegate.call_count_); |
3024 EXPECT_TRUE(device->IsConnecting()); | 2992 EXPECT_TRUE(device->IsConnecting()); |
3025 | 2993 |
3026 // Run the loop to get the error.. | 2994 // Run the loop to get the error.. |
3027 message_loop_.Run(); | 2995 message_loop_.Run(); |
3028 | 2996 |
3029 EXPECT_EQ(0, callback_count_); | 2997 EXPECT_EQ(0, callback_count_); |
3030 EXPECT_EQ(1, error_callback_count_); | 2998 EXPECT_EQ(1, error_callback_count_); |
3031 | 2999 |
3032 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_); | 3000 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_); |
3033 | 3001 |
3034 EXPECT_FALSE(device->IsConnected()); | 3002 EXPECT_FALSE(device->IsConnected()); |
3035 EXPECT_FALSE(device->IsConnecting()); | 3003 EXPECT_FALSE(device->IsConnecting()); |
3036 EXPECT_FALSE(device->IsPaired()); | 3004 EXPECT_FALSE(device->IsPaired()); |
3037 } | 3005 } |
3038 | 3006 |
3039 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { | 3007 TEST_F(BluetoothBlueZTest, PairingFailsAtConnection) { |
3040 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3008 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3041 | 3009 |
3042 GetAdapter(); | 3010 GetAdapter(); |
3043 DiscoverDevices(); | 3011 DiscoverDevices(); |
3044 | 3012 |
3045 // Everything seems to go according to plan with the unconnectable device; | 3013 // Everything seems to go according to plan with the unconnectable device; |
3046 // it pairs, but then you can't make connections to it after. | 3014 // it pairs, but then you can't make connections to it after. |
3047 BluetoothDevice* device = adapter_->GetDevice( | 3015 BluetoothDevice* device = adapter_->GetDevice( |
3048 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 3016 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
3049 ASSERT_TRUE(device != nullptr); | 3017 ASSERT_TRUE(device != nullptr); |
3050 ASSERT_FALSE(device->IsPaired()); | 3018 ASSERT_FALSE(device->IsPaired()); |
3051 | 3019 |
3052 TestBluetoothAdapterObserver observer(adapter_); | 3020 TestBluetoothAdapterObserver observer(adapter_); |
3053 | 3021 |
3054 TestPairingDelegate pairing_delegate; | 3022 TestPairingDelegate pairing_delegate; |
3055 device->Connect(&pairing_delegate, GetCallback(), | 3023 device->Connect(&pairing_delegate, GetCallback(), |
3056 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3024 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3057 base::Unretained(this))); | 3025 base::Unretained(this))); |
3058 | 3026 |
3059 EXPECT_EQ(0, pairing_delegate.call_count_); | 3027 EXPECT_EQ(0, pairing_delegate.call_count_); |
3060 EXPECT_TRUE(device->IsConnecting()); | 3028 EXPECT_TRUE(device->IsConnecting()); |
3061 | 3029 |
3062 message_loop_.Run(); | 3030 message_loop_.Run(); |
3063 | 3031 |
3064 EXPECT_EQ(0, callback_count_); | 3032 EXPECT_EQ(0, callback_count_); |
3065 EXPECT_EQ(1, error_callback_count_); | 3033 EXPECT_EQ(1, error_callback_count_); |
3066 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 3034 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
3067 | 3035 |
3068 // Two changes for connecting, one for paired and one for trusted after | 3036 // Two changes for connecting, one for paired and one for trusted after |
3069 // pairing. The device should not be connected. | 3037 // pairing. The device should not be connected. |
3070 EXPECT_EQ(4, observer.device_changed_count()); | 3038 EXPECT_EQ(4, observer.device_changed_count()); |
3071 EXPECT_EQ(device, observer.last_device()); | 3039 EXPECT_EQ(device, observer.last_device()); |
3072 | 3040 |
3073 EXPECT_FALSE(device->IsConnected()); | 3041 EXPECT_FALSE(device->IsConnected()); |
3074 EXPECT_FALSE(device->IsConnecting()); | 3042 EXPECT_FALSE(device->IsConnecting()); |
3075 | 3043 |
3076 EXPECT_TRUE(device->IsPaired()); | 3044 EXPECT_TRUE(device->IsPaired()); |
3077 | 3045 |
3078 // Make sure the trusted property has been set to true still (since pairing | 3046 // Make sure the trusted property has been set to true still (since pairing |
3079 // worked). | 3047 // worked). |
3080 bluez::FakeBluetoothDeviceClient::Properties* properties = | 3048 bluez::FakeBluetoothDeviceClient::Properties* properties = |
3081 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 3049 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
3082 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath)); | 3050 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath)); |
3083 EXPECT_TRUE(properties->trusted.value()); | 3051 EXPECT_TRUE(properties->trusted.value()); |
3084 } | 3052 } |
3085 | 3053 |
3086 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { | 3054 TEST_F(BluetoothBlueZTest, PairingRejectedAtPinCode) { |
3087 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3055 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3088 | 3056 |
3089 GetAdapter(); | 3057 GetAdapter(); |
3090 DiscoverDevices(); | 3058 DiscoverDevices(); |
3091 | 3059 |
3092 // Reject the pairing after we receive a request for the PIN code. | 3060 // Reject the pairing after we receive a request for the PIN code. |
3093 BluetoothDevice* device = adapter_->GetDevice( | 3061 BluetoothDevice* device = adapter_->GetDevice( |
3094 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3062 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
3095 ASSERT_TRUE(device != nullptr); | 3063 ASSERT_TRUE(device != nullptr); |
3096 ASSERT_FALSE(device->IsPaired()); | 3064 ASSERT_FALSE(device->IsPaired()); |
3097 | 3065 |
3098 TestBluetoothAdapterObserver observer(adapter_); | 3066 TestBluetoothAdapterObserver observer(adapter_); |
3099 | 3067 |
3100 TestPairingDelegate pairing_delegate; | 3068 TestPairingDelegate pairing_delegate; |
3101 device->Connect(&pairing_delegate, GetCallback(), | 3069 device->Connect(&pairing_delegate, GetCallback(), |
3102 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3070 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3103 base::Unretained(this))); | 3071 base::Unretained(this))); |
3104 | 3072 |
3105 EXPECT_EQ(1, pairing_delegate.call_count_); | 3073 EXPECT_EQ(1, pairing_delegate.call_count_); |
3106 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 3074 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
3107 EXPECT_TRUE(device->IsConnecting()); | 3075 EXPECT_TRUE(device->IsConnecting()); |
3108 | 3076 |
3109 // Reject the pairing. | 3077 // Reject the pairing. |
3110 device->RejectPairing(); | 3078 device->RejectPairing(); |
3111 message_loop_.Run(); | 3079 message_loop_.Run(); |
3112 | 3080 |
3113 EXPECT_EQ(0, callback_count_); | 3081 EXPECT_EQ(0, callback_count_); |
3114 EXPECT_EQ(1, error_callback_count_); | 3082 EXPECT_EQ(1, error_callback_count_); |
3115 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); | 3083 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); |
3116 | 3084 |
3117 // Should be no changes except connecting going true and false. | 3085 // Should be no changes except connecting going true and false. |
3118 EXPECT_EQ(2, observer.device_changed_count()); | 3086 EXPECT_EQ(2, observer.device_changed_count()); |
3119 EXPECT_FALSE(device->IsConnected()); | 3087 EXPECT_FALSE(device->IsConnected()); |
3120 EXPECT_FALSE(device->IsConnecting()); | 3088 EXPECT_FALSE(device->IsConnecting()); |
3121 EXPECT_FALSE(device->IsPaired()); | 3089 EXPECT_FALSE(device->IsPaired()); |
3122 } | 3090 } |
3123 | 3091 |
3124 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { | 3092 TEST_F(BluetoothBlueZTest, PairingCancelledAtPinCode) { |
3125 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3093 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3126 | 3094 |
3127 GetAdapter(); | 3095 GetAdapter(); |
3128 DiscoverDevices(); | 3096 DiscoverDevices(); |
3129 | 3097 |
3130 // Cancel the pairing after we receive a request for the PIN code. | 3098 // Cancel the pairing after we receive a request for the PIN code. |
3131 BluetoothDevice* device = adapter_->GetDevice( | 3099 BluetoothDevice* device = adapter_->GetDevice( |
3132 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3100 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
3133 ASSERT_TRUE(device != nullptr); | 3101 ASSERT_TRUE(device != nullptr); |
3134 ASSERT_FALSE(device->IsPaired()); | 3102 ASSERT_FALSE(device->IsPaired()); |
3135 | 3103 |
3136 TestBluetoothAdapterObserver observer(adapter_); | 3104 TestBluetoothAdapterObserver observer(adapter_); |
3137 | 3105 |
3138 TestPairingDelegate pairing_delegate; | 3106 TestPairingDelegate pairing_delegate; |
3139 device->Connect(&pairing_delegate, GetCallback(), | 3107 device->Connect(&pairing_delegate, GetCallback(), |
3140 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3108 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3141 base::Unretained(this))); | 3109 base::Unretained(this))); |
3142 | 3110 |
3143 EXPECT_EQ(1, pairing_delegate.call_count_); | 3111 EXPECT_EQ(1, pairing_delegate.call_count_); |
3144 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 3112 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
3145 EXPECT_TRUE(device->IsConnecting()); | 3113 EXPECT_TRUE(device->IsConnecting()); |
3146 | 3114 |
3147 // Cancel the pairing. | 3115 // Cancel the pairing. |
3148 device->CancelPairing(); | 3116 device->CancelPairing(); |
3149 message_loop_.Run(); | 3117 message_loop_.Run(); |
3150 | 3118 |
3151 EXPECT_EQ(0, callback_count_); | 3119 EXPECT_EQ(0, callback_count_); |
3152 EXPECT_EQ(1, error_callback_count_); | 3120 EXPECT_EQ(1, error_callback_count_); |
3153 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); | 3121 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); |
3154 | 3122 |
3155 // Should be no changes except connecting going true and false. | 3123 // Should be no changes except connecting going true and false. |
3156 EXPECT_EQ(2, observer.device_changed_count()); | 3124 EXPECT_EQ(2, observer.device_changed_count()); |
3157 EXPECT_FALSE(device->IsConnected()); | 3125 EXPECT_FALSE(device->IsConnected()); |
3158 EXPECT_FALSE(device->IsConnecting()); | 3126 EXPECT_FALSE(device->IsConnecting()); |
3159 EXPECT_FALSE(device->IsPaired()); | 3127 EXPECT_FALSE(device->IsPaired()); |
3160 } | 3128 } |
3161 | 3129 |
3162 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { | 3130 TEST_F(BluetoothBlueZTest, PairingRejectedAtPasskey) { |
3163 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3131 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3164 | 3132 |
3165 GetAdapter(); | 3133 GetAdapter(); |
3166 DiscoverDevices(); | 3134 DiscoverDevices(); |
3167 | 3135 |
3168 // Reject the pairing after we receive a request for the passkey. | 3136 // Reject the pairing after we receive a request for the passkey. |
3169 BluetoothDevice* device = adapter_->GetDevice( | 3137 BluetoothDevice* device = adapter_->GetDevice( |
3170 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3138 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
3171 ASSERT_TRUE(device != nullptr); | 3139 ASSERT_TRUE(device != nullptr); |
3172 ASSERT_FALSE(device->IsPaired()); | 3140 ASSERT_FALSE(device->IsPaired()); |
3173 | 3141 |
3174 TestBluetoothAdapterObserver observer(adapter_); | 3142 TestBluetoothAdapterObserver observer(adapter_); |
3175 | 3143 |
3176 TestPairingDelegate pairing_delegate; | 3144 TestPairingDelegate pairing_delegate; |
3177 device->Connect(&pairing_delegate, GetCallback(), | 3145 device->Connect(&pairing_delegate, GetCallback(), |
3178 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3146 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3179 base::Unretained(this))); | 3147 base::Unretained(this))); |
3180 | 3148 |
3181 EXPECT_EQ(1, pairing_delegate.call_count_); | 3149 EXPECT_EQ(1, pairing_delegate.call_count_); |
3182 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3150 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
3183 EXPECT_TRUE(device->IsConnecting()); | 3151 EXPECT_TRUE(device->IsConnecting()); |
3184 | 3152 |
3185 // Reject the pairing. | 3153 // Reject the pairing. |
3186 device->RejectPairing(); | 3154 device->RejectPairing(); |
3187 message_loop_.Run(); | 3155 message_loop_.Run(); |
3188 | 3156 |
3189 EXPECT_EQ(0, callback_count_); | 3157 EXPECT_EQ(0, callback_count_); |
3190 EXPECT_EQ(1, error_callback_count_); | 3158 EXPECT_EQ(1, error_callback_count_); |
3191 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); | 3159 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); |
3192 | 3160 |
3193 // Should be no changes except connecting going true and false. | 3161 // Should be no changes except connecting going true and false. |
3194 EXPECT_EQ(2, observer.device_changed_count()); | 3162 EXPECT_EQ(2, observer.device_changed_count()); |
3195 EXPECT_FALSE(device->IsConnected()); | 3163 EXPECT_FALSE(device->IsConnected()); |
3196 EXPECT_FALSE(device->IsConnecting()); | 3164 EXPECT_FALSE(device->IsConnecting()); |
3197 EXPECT_FALSE(device->IsPaired()); | 3165 EXPECT_FALSE(device->IsPaired()); |
3198 } | 3166 } |
3199 | 3167 |
3200 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { | 3168 TEST_F(BluetoothBlueZTest, PairingCancelledAtPasskey) { |
3201 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3169 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3202 | 3170 |
3203 GetAdapter(); | 3171 GetAdapter(); |
3204 DiscoverDevices(); | 3172 DiscoverDevices(); |
3205 | 3173 |
3206 // Cancel the pairing after we receive a request for the passkey. | 3174 // Cancel the pairing after we receive a request for the passkey. |
3207 BluetoothDevice* device = adapter_->GetDevice( | 3175 BluetoothDevice* device = adapter_->GetDevice( |
3208 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3176 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
3209 ASSERT_TRUE(device != nullptr); | 3177 ASSERT_TRUE(device != nullptr); |
3210 ASSERT_FALSE(device->IsPaired()); | 3178 ASSERT_FALSE(device->IsPaired()); |
3211 | 3179 |
3212 TestBluetoothAdapterObserver observer(adapter_); | 3180 TestBluetoothAdapterObserver observer(adapter_); |
3213 | 3181 |
3214 TestPairingDelegate pairing_delegate; | 3182 TestPairingDelegate pairing_delegate; |
3215 device->Connect(&pairing_delegate, GetCallback(), | 3183 device->Connect(&pairing_delegate, GetCallback(), |
3216 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3184 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3217 base::Unretained(this))); | 3185 base::Unretained(this))); |
3218 | 3186 |
3219 EXPECT_EQ(1, pairing_delegate.call_count_); | 3187 EXPECT_EQ(1, pairing_delegate.call_count_); |
3220 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3188 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
3221 EXPECT_TRUE(device->IsConnecting()); | 3189 EXPECT_TRUE(device->IsConnecting()); |
3222 | 3190 |
3223 // Cancel the pairing. | 3191 // Cancel the pairing. |
3224 device->CancelPairing(); | 3192 device->CancelPairing(); |
3225 message_loop_.Run(); | 3193 message_loop_.Run(); |
3226 | 3194 |
3227 EXPECT_EQ(0, callback_count_); | 3195 EXPECT_EQ(0, callback_count_); |
3228 EXPECT_EQ(1, error_callback_count_); | 3196 EXPECT_EQ(1, error_callback_count_); |
3229 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); | 3197 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); |
3230 | 3198 |
3231 // Should be no changes except connecting going true and false. | 3199 // Should be no changes except connecting going true and false. |
3232 EXPECT_EQ(2, observer.device_changed_count()); | 3200 EXPECT_EQ(2, observer.device_changed_count()); |
3233 EXPECT_FALSE(device->IsConnected()); | 3201 EXPECT_FALSE(device->IsConnected()); |
3234 EXPECT_FALSE(device->IsConnecting()); | 3202 EXPECT_FALSE(device->IsConnecting()); |
3235 EXPECT_FALSE(device->IsPaired()); | 3203 EXPECT_FALSE(device->IsPaired()); |
3236 } | 3204 } |
3237 | 3205 |
3238 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { | 3206 TEST_F(BluetoothBlueZTest, PairingRejectedAtConfirmation) { |
3239 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3207 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3240 | 3208 |
3241 GetAdapter(); | 3209 GetAdapter(); |
3242 DiscoverDevices(); | 3210 DiscoverDevices(); |
3243 | 3211 |
3244 // Reject the pairing after we receive a request for passkey confirmation. | 3212 // Reject the pairing after we receive a request for passkey confirmation. |
3245 BluetoothDevice* device = adapter_->GetDevice( | 3213 BluetoothDevice* device = adapter_->GetDevice( |
3246 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3214 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
3247 ASSERT_TRUE(device != nullptr); | 3215 ASSERT_TRUE(device != nullptr); |
3248 ASSERT_FALSE(device->IsPaired()); | 3216 ASSERT_FALSE(device->IsPaired()); |
3249 | 3217 |
3250 TestBluetoothAdapterObserver observer(adapter_); | 3218 TestBluetoothAdapterObserver observer(adapter_); |
3251 | 3219 |
3252 TestPairingDelegate pairing_delegate; | 3220 TestPairingDelegate pairing_delegate; |
3253 device->Connect(&pairing_delegate, GetCallback(), | 3221 device->Connect(&pairing_delegate, GetCallback(), |
3254 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3222 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3255 base::Unretained(this))); | 3223 base::Unretained(this))); |
3256 | 3224 |
3257 EXPECT_EQ(1, pairing_delegate.call_count_); | 3225 EXPECT_EQ(1, pairing_delegate.call_count_); |
3258 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 3226 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
3259 EXPECT_TRUE(device->IsConnecting()); | 3227 EXPECT_TRUE(device->IsConnecting()); |
3260 | 3228 |
3261 // Reject the pairing. | 3229 // Reject the pairing. |
3262 device->RejectPairing(); | 3230 device->RejectPairing(); |
3263 message_loop_.Run(); | 3231 message_loop_.Run(); |
3264 | 3232 |
3265 EXPECT_EQ(0, callback_count_); | 3233 EXPECT_EQ(0, callback_count_); |
3266 EXPECT_EQ(1, error_callback_count_); | 3234 EXPECT_EQ(1, error_callback_count_); |
3267 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); | 3235 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); |
3268 | 3236 |
3269 // Should be no changes except connecting going true and false. | 3237 // Should be no changes except connecting going true and false. |
3270 EXPECT_EQ(2, observer.device_changed_count()); | 3238 EXPECT_EQ(2, observer.device_changed_count()); |
3271 EXPECT_FALSE(device->IsConnected()); | 3239 EXPECT_FALSE(device->IsConnected()); |
3272 EXPECT_FALSE(device->IsConnecting()); | 3240 EXPECT_FALSE(device->IsConnecting()); |
3273 EXPECT_FALSE(device->IsPaired()); | 3241 EXPECT_FALSE(device->IsPaired()); |
3274 } | 3242 } |
3275 | 3243 |
3276 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { | 3244 TEST_F(BluetoothBlueZTest, PairingCancelledAtConfirmation) { |
3277 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3245 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3278 | 3246 |
3279 GetAdapter(); | 3247 GetAdapter(); |
3280 DiscoverDevices(); | 3248 DiscoverDevices(); |
3281 | 3249 |
3282 // Cancel the pairing after we receive a request for the passkey. | 3250 // Cancel the pairing after we receive a request for the passkey. |
3283 BluetoothDevice* device = adapter_->GetDevice( | 3251 BluetoothDevice* device = adapter_->GetDevice( |
3284 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3252 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
3285 ASSERT_TRUE(device != nullptr); | 3253 ASSERT_TRUE(device != nullptr); |
3286 ASSERT_FALSE(device->IsPaired()); | 3254 ASSERT_FALSE(device->IsPaired()); |
3287 | 3255 |
3288 TestBluetoothAdapterObserver observer(adapter_); | 3256 TestBluetoothAdapterObserver observer(adapter_); |
3289 | 3257 |
3290 TestPairingDelegate pairing_delegate; | 3258 TestPairingDelegate pairing_delegate; |
3291 device->Connect(&pairing_delegate, GetCallback(), | 3259 device->Connect(&pairing_delegate, GetCallback(), |
3292 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3260 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3293 base::Unretained(this))); | 3261 base::Unretained(this))); |
3294 | 3262 |
3295 EXPECT_EQ(1, pairing_delegate.call_count_); | 3263 EXPECT_EQ(1, pairing_delegate.call_count_); |
3296 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 3264 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
3297 EXPECT_TRUE(device->IsConnecting()); | 3265 EXPECT_TRUE(device->IsConnecting()); |
3298 | 3266 |
3299 // Cancel the pairing. | 3267 // Cancel the pairing. |
3300 device->CancelPairing(); | 3268 device->CancelPairing(); |
3301 message_loop_.Run(); | 3269 message_loop_.Run(); |
3302 | 3270 |
3303 EXPECT_EQ(0, callback_count_); | 3271 EXPECT_EQ(0, callback_count_); |
3304 EXPECT_EQ(1, error_callback_count_); | 3272 EXPECT_EQ(1, error_callback_count_); |
3305 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); | 3273 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); |
3306 | 3274 |
3307 // Should be no changes except connecting going true and false. | 3275 // Should be no changes except connecting going true and false. |
3308 EXPECT_EQ(2, observer.device_changed_count()); | 3276 EXPECT_EQ(2, observer.device_changed_count()); |
3309 EXPECT_FALSE(device->IsConnected()); | 3277 EXPECT_FALSE(device->IsConnected()); |
3310 EXPECT_FALSE(device->IsConnecting()); | 3278 EXPECT_FALSE(device->IsConnecting()); |
3311 EXPECT_FALSE(device->IsPaired()); | 3279 EXPECT_FALSE(device->IsPaired()); |
3312 } | 3280 } |
3313 | 3281 |
3314 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { | 3282 TEST_F(BluetoothBlueZTest, PairingCancelledInFlight) { |
3315 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3283 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3316 | 3284 |
3317 GetAdapter(); | 3285 GetAdapter(); |
3318 DiscoverDevices(); | 3286 DiscoverDevices(); |
3319 | 3287 |
3320 // Cancel the pairing while we're waiting for the remote host. | 3288 // Cancel the pairing while we're waiting for the remote host. |
3321 BluetoothDevice* device = adapter_->GetDevice( | 3289 BluetoothDevice* device = adapter_->GetDevice( |
3322 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 3290 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
3323 ASSERT_TRUE(device != nullptr); | 3291 ASSERT_TRUE(device != nullptr); |
3324 ASSERT_FALSE(device->IsPaired()); | 3292 ASSERT_FALSE(device->IsPaired()); |
3325 | 3293 |
3326 TestBluetoothAdapterObserver observer(adapter_); | 3294 TestBluetoothAdapterObserver observer(adapter_); |
3327 | 3295 |
3328 TestPairingDelegate pairing_delegate; | 3296 TestPairingDelegate pairing_delegate; |
3329 device->Connect(&pairing_delegate, GetCallback(), | 3297 device->Connect(&pairing_delegate, GetCallback(), |
3330 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3298 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3331 base::Unretained(this))); | 3299 base::Unretained(this))); |
3332 | 3300 |
3333 EXPECT_EQ(0, pairing_delegate.call_count_); | 3301 EXPECT_EQ(0, pairing_delegate.call_count_); |
3334 EXPECT_TRUE(device->IsConnecting()); | 3302 EXPECT_TRUE(device->IsConnecting()); |
3335 | 3303 |
3336 // Cancel the pairing. | 3304 // Cancel the pairing. |
3337 device->CancelPairing(); | 3305 device->CancelPairing(); |
3338 message_loop_.Run(); | 3306 message_loop_.Run(); |
3339 | 3307 |
3340 EXPECT_EQ(0, callback_count_); | 3308 EXPECT_EQ(0, callback_count_); |
3341 EXPECT_EQ(1, error_callback_count_); | 3309 EXPECT_EQ(1, error_callback_count_); |
3342 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); | 3310 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); |
3343 | 3311 |
3344 // Should be no changes except connecting going true and false. | 3312 // Should be no changes except connecting going true and false. |
3345 EXPECT_EQ(2, observer.device_changed_count()); | 3313 EXPECT_EQ(2, observer.device_changed_count()); |
3346 EXPECT_FALSE(device->IsConnected()); | 3314 EXPECT_FALSE(device->IsConnected()); |
3347 EXPECT_FALSE(device->IsConnecting()); | 3315 EXPECT_FALSE(device->IsConnecting()); |
3348 EXPECT_FALSE(device->IsPaired()); | 3316 EXPECT_FALSE(device->IsPaired()); |
3349 } | 3317 } |
3350 | 3318 |
3351 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCode) { | 3319 TEST_F(BluetoothBlueZTest, IncomingPairRequestPinCode) { |
3352 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3320 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3353 | 3321 |
3354 GetAdapter(); | 3322 GetAdapter(); |
3355 | 3323 |
3356 TestPairingDelegate pairing_delegate; | 3324 TestPairingDelegate pairing_delegate; |
3357 adapter_->AddPairingDelegate( | 3325 adapter_->AddPairingDelegate( |
3358 &pairing_delegate, | 3326 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
3359 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | |
3360 | 3327 |
3361 // Requires that we provide a PIN code. | 3328 // Requires that we provide a PIN code. |
3362 fake_bluetooth_device_client_->CreateDevice( | 3329 fake_bluetooth_device_client_->CreateDevice( |
3363 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3330 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3364 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3331 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
3365 BluetoothDevice* device = adapter_->GetDevice( | 3332 BluetoothDevice* device = adapter_->GetDevice( |
3366 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3333 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
3367 ASSERT_TRUE(device != nullptr); | 3334 ASSERT_TRUE(device != nullptr); |
3368 ASSERT_FALSE(device->IsPaired()); | 3335 ASSERT_FALSE(device->IsPaired()); |
3369 | 3336 |
3370 TestBluetoothAdapterObserver observer(adapter_); | 3337 TestBluetoothAdapterObserver observer(adapter_); |
3371 | 3338 |
3372 fake_bluetooth_device_client_->SimulatePairing( | 3339 fake_bluetooth_device_client_->SimulatePairing( |
3373 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), | 3340 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), |
3374 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3341 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3375 base::Unretained(this))); | 3342 base::Unretained(this))); |
3376 | 3343 |
3377 EXPECT_EQ(1, pairing_delegate.call_count_); | 3344 EXPECT_EQ(1, pairing_delegate.call_count_); |
3378 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 3345 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
3379 | 3346 |
3380 // Set the PIN. | 3347 // Set the PIN. |
3381 device->SetPinCode("1234"); | 3348 device->SetPinCode("1234"); |
3382 message_loop_.Run(); | 3349 message_loop_.Run(); |
3383 | 3350 |
3384 EXPECT_EQ(1, callback_count_); | 3351 EXPECT_EQ(1, callback_count_); |
3385 EXPECT_EQ(0, error_callback_count_); | 3352 EXPECT_EQ(0, error_callback_count_); |
3386 | 3353 |
3387 // One change for paired, and one for trusted. | 3354 // One change for paired, and one for trusted. |
3388 EXPECT_EQ(2, observer.device_changed_count()); | 3355 EXPECT_EQ(2, observer.device_changed_count()); |
3389 EXPECT_EQ(device, observer.last_device()); | 3356 EXPECT_EQ(device, observer.last_device()); |
3390 | 3357 |
3391 EXPECT_TRUE(device->IsPaired()); | 3358 EXPECT_TRUE(device->IsPaired()); |
3392 | 3359 |
3393 // Make sure the trusted property has been set to true. | 3360 // Make sure the trusted property has been set to true. |
3394 bluez::FakeBluetoothDeviceClient::Properties* properties = | 3361 bluez::FakeBluetoothDeviceClient::Properties* properties = |
3395 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 3362 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
3396 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3363 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
3397 ASSERT_TRUE(properties->trusted.value()); | 3364 ASSERT_TRUE(properties->trusted.value()); |
3398 | 3365 |
3399 // No pairing context should remain on the device. | 3366 // No pairing context should remain on the device. |
3400 BluetoothDeviceChromeOS* device_chromeos = | 3367 BluetoothDeviceBlueZ* device_bluez = |
3401 static_cast<BluetoothDeviceChromeOS*>(device); | 3368 static_cast<BluetoothDeviceBlueZ*>(device); |
3402 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3369 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3403 } | 3370 } |
3404 | 3371 |
3405 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { | 3372 TEST_F(BluetoothBlueZTest, IncomingPairConfirmPasskey) { |
3406 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3373 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3407 | 3374 |
3408 GetAdapter(); | 3375 GetAdapter(); |
3409 | 3376 |
3410 TestPairingDelegate pairing_delegate; | 3377 TestPairingDelegate pairing_delegate; |
3411 adapter_->AddPairingDelegate( | 3378 adapter_->AddPairingDelegate( |
3412 &pairing_delegate, | 3379 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
3413 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | |
3414 | 3380 |
3415 // Requests that we confirm a displayed passkey. | 3381 // Requests that we confirm a displayed passkey. |
3416 fake_bluetooth_device_client_->CreateDevice( | 3382 fake_bluetooth_device_client_->CreateDevice( |
3417 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3383 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3418 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3384 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
3419 BluetoothDevice* device = adapter_->GetDevice( | 3385 BluetoothDevice* device = adapter_->GetDevice( |
3420 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3386 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
3421 ASSERT_TRUE(device != nullptr); | 3387 ASSERT_TRUE(device != nullptr); |
3422 ASSERT_FALSE(device->IsPaired()); | 3388 ASSERT_FALSE(device->IsPaired()); |
3423 | 3389 |
3424 TestBluetoothAdapterObserver observer(adapter_); | 3390 TestBluetoothAdapterObserver observer(adapter_); |
3425 | 3391 |
3426 fake_bluetooth_device_client_->SimulatePairing( | 3392 fake_bluetooth_device_client_->SimulatePairing( |
3427 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), | 3393 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), |
3428 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3394 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3429 base::Unretained(this))); | 3395 base::Unretained(this))); |
3430 | 3396 |
3431 EXPECT_EQ(1, pairing_delegate.call_count_); | 3397 EXPECT_EQ(1, pairing_delegate.call_count_); |
3432 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 3398 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
3433 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 3399 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
3434 | 3400 |
3435 // Confirm the passkey. | 3401 // Confirm the passkey. |
3436 device->ConfirmPairing(); | 3402 device->ConfirmPairing(); |
3437 message_loop_.Run(); | 3403 message_loop_.Run(); |
3438 | 3404 |
3439 EXPECT_EQ(1, callback_count_); | 3405 EXPECT_EQ(1, callback_count_); |
3440 EXPECT_EQ(0, error_callback_count_); | 3406 EXPECT_EQ(0, error_callback_count_); |
3441 | 3407 |
3442 // One change for paired, and one for trusted. | 3408 // One change for paired, and one for trusted. |
3443 EXPECT_EQ(2, observer.device_changed_count()); | 3409 EXPECT_EQ(2, observer.device_changed_count()); |
3444 EXPECT_EQ(device, observer.last_device()); | 3410 EXPECT_EQ(device, observer.last_device()); |
3445 | 3411 |
3446 EXPECT_TRUE(device->IsPaired()); | 3412 EXPECT_TRUE(device->IsPaired()); |
3447 | 3413 |
3448 // Make sure the trusted property has been set to true. | 3414 // Make sure the trusted property has been set to true. |
3449 bluez::FakeBluetoothDeviceClient::Properties* properties = | 3415 bluez::FakeBluetoothDeviceClient::Properties* properties = |
3450 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 3416 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
3451 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3417 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
3452 ASSERT_TRUE(properties->trusted.value()); | 3418 ASSERT_TRUE(properties->trusted.value()); |
3453 | 3419 |
3454 // No pairing context should remain on the device. | 3420 // No pairing context should remain on the device. |
3455 BluetoothDeviceChromeOS* device_chromeos = | 3421 BluetoothDeviceBlueZ* device_bluez = |
3456 static_cast<BluetoothDeviceChromeOS*>(device); | 3422 static_cast<BluetoothDeviceBlueZ*>(device); |
3457 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3423 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3458 } | 3424 } |
3459 | 3425 |
3460 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { | 3426 TEST_F(BluetoothBlueZTest, IncomingPairRequestPasskey) { |
3461 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3427 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3462 | 3428 |
3463 GetAdapter(); | 3429 GetAdapter(); |
3464 | 3430 |
3465 TestPairingDelegate pairing_delegate; | 3431 TestPairingDelegate pairing_delegate; |
3466 adapter_->AddPairingDelegate( | 3432 adapter_->AddPairingDelegate( |
3467 &pairing_delegate, | 3433 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
3468 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | |
3469 | 3434 |
3470 // Requests that we provide a Passkey. | 3435 // Requests that we provide a Passkey. |
3471 fake_bluetooth_device_client_->CreateDevice( | 3436 fake_bluetooth_device_client_->CreateDevice( |
3472 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3437 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3473 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3438 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
3474 BluetoothDevice* device = adapter_->GetDevice( | 3439 BluetoothDevice* device = adapter_->GetDevice( |
3475 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3440 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
3476 ASSERT_TRUE(device != nullptr); | 3441 ASSERT_TRUE(device != nullptr); |
3477 ASSERT_FALSE(device->IsPaired()); | 3442 ASSERT_FALSE(device->IsPaired()); |
3478 | 3443 |
3479 TestBluetoothAdapterObserver observer(adapter_); | 3444 TestBluetoothAdapterObserver observer(adapter_); |
3480 | 3445 |
3481 fake_bluetooth_device_client_->SimulatePairing( | 3446 fake_bluetooth_device_client_->SimulatePairing( |
3482 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), | 3447 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
3483 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3448 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3484 base::Unretained(this))); | 3449 base::Unretained(this))); |
3485 | 3450 |
3486 EXPECT_EQ(1, pairing_delegate.call_count_); | 3451 EXPECT_EQ(1, pairing_delegate.call_count_); |
3487 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3452 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
3488 | 3453 |
3489 // Set the Passkey. | 3454 // Set the Passkey. |
3490 device->SetPasskey(1234); | 3455 device->SetPasskey(1234); |
3491 message_loop_.Run(); | 3456 message_loop_.Run(); |
3492 | 3457 |
3493 EXPECT_EQ(1, callback_count_); | 3458 EXPECT_EQ(1, callback_count_); |
3494 EXPECT_EQ(0, error_callback_count_); | 3459 EXPECT_EQ(0, error_callback_count_); |
3495 | 3460 |
3496 // One change for paired, and one for trusted. | 3461 // One change for paired, and one for trusted. |
3497 EXPECT_EQ(2, observer.device_changed_count()); | 3462 EXPECT_EQ(2, observer.device_changed_count()); |
3498 EXPECT_EQ(device, observer.last_device()); | 3463 EXPECT_EQ(device, observer.last_device()); |
3499 | 3464 |
3500 EXPECT_TRUE(device->IsPaired()); | 3465 EXPECT_TRUE(device->IsPaired()); |
3501 | 3466 |
3502 // Make sure the trusted property has been set to true. | 3467 // Make sure the trusted property has been set to true. |
3503 bluez::FakeBluetoothDeviceClient::Properties* properties = | 3468 bluez::FakeBluetoothDeviceClient::Properties* properties = |
3504 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 3469 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
3505 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3470 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
3506 ASSERT_TRUE(properties->trusted.value()); | 3471 ASSERT_TRUE(properties->trusted.value()); |
3507 | 3472 |
3508 // No pairing context should remain on the device. | 3473 // No pairing context should remain on the device. |
3509 BluetoothDeviceChromeOS* device_chromeos = | 3474 BluetoothDeviceBlueZ* device_bluez = |
3510 static_cast<BluetoothDeviceChromeOS*>(device); | 3475 static_cast<BluetoothDeviceBlueZ*>(device); |
3511 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3476 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3512 } | 3477 } |
3513 | 3478 |
3514 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { | 3479 TEST_F(BluetoothBlueZTest, IncomingPairJustWorks) { |
3515 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3480 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3516 | 3481 |
3517 GetAdapter(); | 3482 GetAdapter(); |
3518 | 3483 |
3519 TestPairingDelegate pairing_delegate; | 3484 TestPairingDelegate pairing_delegate; |
3520 adapter_->AddPairingDelegate( | 3485 adapter_->AddPairingDelegate( |
3521 &pairing_delegate, | 3486 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
3522 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | |
3523 | 3487 |
3524 // Uses just-works pairing so, sinec this an incoming pairing, require | 3488 // Uses just-works pairing so, sinec this an incoming pairing, require |
3525 // authorization from the user. | 3489 // authorization from the user. |
3526 fake_bluetooth_device_client_->CreateDevice( | 3490 fake_bluetooth_device_client_->CreateDevice( |
3527 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3491 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3528 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); | 3492 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
3529 BluetoothDevice* device = | 3493 BluetoothDevice* device = |
3530 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); | 3494 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
3531 ASSERT_TRUE(device != nullptr); | 3495 ASSERT_TRUE(device != nullptr); |
3532 ASSERT_FALSE(device->IsPaired()); | 3496 ASSERT_FALSE(device->IsPaired()); |
3533 | 3497 |
3534 TestBluetoothAdapterObserver observer(adapter_); | 3498 TestBluetoothAdapterObserver observer(adapter_); |
3535 | 3499 |
3536 fake_bluetooth_device_client_->SimulatePairing( | 3500 fake_bluetooth_device_client_->SimulatePairing( |
3537 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, | 3501 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, |
3538 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3502 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3539 base::Unretained(this))); | 3503 base::Unretained(this))); |
3540 | 3504 |
3541 EXPECT_EQ(1, pairing_delegate.call_count_); | 3505 EXPECT_EQ(1, pairing_delegate.call_count_); |
3542 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); | 3506 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); |
3543 | 3507 |
3544 // Confirm the pairing. | 3508 // Confirm the pairing. |
3545 device->ConfirmPairing(); | 3509 device->ConfirmPairing(); |
3546 message_loop_.Run(); | 3510 message_loop_.Run(); |
3547 | 3511 |
3548 EXPECT_EQ(1, callback_count_); | 3512 EXPECT_EQ(1, callback_count_); |
3549 EXPECT_EQ(0, error_callback_count_); | 3513 EXPECT_EQ(0, error_callback_count_); |
3550 | 3514 |
3551 // One change for paired, and one for trusted. | 3515 // One change for paired, and one for trusted. |
3552 EXPECT_EQ(2, observer.device_changed_count()); | 3516 EXPECT_EQ(2, observer.device_changed_count()); |
3553 EXPECT_EQ(device, observer.last_device()); | 3517 EXPECT_EQ(device, observer.last_device()); |
3554 | 3518 |
3555 EXPECT_TRUE(device->IsPaired()); | 3519 EXPECT_TRUE(device->IsPaired()); |
3556 | 3520 |
3557 // Make sure the trusted property has been set to true. | 3521 // Make sure the trusted property has been set to true. |
3558 bluez::FakeBluetoothDeviceClient::Properties* properties = | 3522 bluez::FakeBluetoothDeviceClient::Properties* properties = |
3559 fake_bluetooth_device_client_->GetProperties( | 3523 fake_bluetooth_device_client_->GetProperties( |
3560 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); | 3524 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
3561 ASSERT_TRUE(properties->trusted.value()); | 3525 ASSERT_TRUE(properties->trusted.value()); |
3562 | 3526 |
3563 // No pairing context should remain on the device. | 3527 // No pairing context should remain on the device. |
3564 BluetoothDeviceChromeOS* device_chromeos = | 3528 BluetoothDeviceBlueZ* device_bluez = |
3565 static_cast<BluetoothDeviceChromeOS*>(device); | 3529 static_cast<BluetoothDeviceBlueZ*>(device); |
3566 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3530 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3567 } | 3531 } |
3568 | 3532 |
3569 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { | 3533 TEST_F(BluetoothBlueZTest, IncomingPairRequestPinCodeWithoutDelegate) { |
3570 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3534 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3571 | 3535 |
3572 GetAdapter(); | 3536 GetAdapter(); |
3573 | 3537 |
3574 // Requires that we provide a PIN Code, without a pairing delegate, | 3538 // Requires that we provide a PIN Code, without a pairing delegate, |
3575 // that will be rejected. | 3539 // that will be rejected. |
3576 fake_bluetooth_device_client_->CreateDevice( | 3540 fake_bluetooth_device_client_->CreateDevice( |
3577 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3541 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3578 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3542 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
3579 BluetoothDevice* device = adapter_->GetDevice( | 3543 BluetoothDevice* device = adapter_->GetDevice( |
3580 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3544 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
3581 ASSERT_TRUE(device != nullptr); | 3545 ASSERT_TRUE(device != nullptr); |
3582 ASSERT_FALSE(device->IsPaired()); | 3546 ASSERT_FALSE(device->IsPaired()); |
3583 | 3547 |
3584 TestBluetoothAdapterObserver observer(adapter_); | 3548 TestBluetoothAdapterObserver observer(adapter_); |
3585 | 3549 |
3586 fake_bluetooth_device_client_->SimulatePairing( | 3550 fake_bluetooth_device_client_->SimulatePairing( |
3587 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), | 3551 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), |
3588 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3552 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3589 base::Unretained(this))); | 3553 base::Unretained(this))); |
3590 | 3554 |
3591 message_loop_.Run(); | 3555 message_loop_.Run(); |
3592 | 3556 |
3593 EXPECT_EQ(0, callback_count_); | 3557 EXPECT_EQ(0, callback_count_); |
3594 EXPECT_EQ(1, error_callback_count_); | 3558 EXPECT_EQ(1, error_callback_count_); |
3595 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3559 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
3596 | 3560 |
3597 // No changes should be observer. | 3561 // No changes should be observer. |
3598 EXPECT_EQ(0, observer.device_changed_count()); | 3562 EXPECT_EQ(0, observer.device_changed_count()); |
3599 | 3563 |
3600 EXPECT_FALSE(device->IsPaired()); | 3564 EXPECT_FALSE(device->IsPaired()); |
3601 | 3565 |
3602 // No pairing context should remain on the device. | 3566 // No pairing context should remain on the device. |
3603 BluetoothDeviceChromeOS* device_chromeos = | 3567 BluetoothDeviceBlueZ* device_bluez = |
3604 static_cast<BluetoothDeviceChromeOS*>(device); | 3568 static_cast<BluetoothDeviceBlueZ*>(device); |
3605 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3569 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3606 } | 3570 } |
3607 | 3571 |
3608 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { | 3572 TEST_F(BluetoothBlueZTest, IncomingPairConfirmPasskeyWithoutDelegate) { |
3609 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3573 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3610 | 3574 |
3611 GetAdapter(); | 3575 GetAdapter(); |
3612 | 3576 |
3613 // Requests that we confirm a displayed passkey, without a pairing delegate, | 3577 // Requests that we confirm a displayed passkey, without a pairing delegate, |
3614 // that will be rejected. | 3578 // that will be rejected. |
3615 fake_bluetooth_device_client_->CreateDevice( | 3579 fake_bluetooth_device_client_->CreateDevice( |
3616 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3580 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3617 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3581 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
3618 BluetoothDevice* device = adapter_->GetDevice( | 3582 BluetoothDevice* device = adapter_->GetDevice( |
3619 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3583 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
3620 ASSERT_TRUE(device != nullptr); | 3584 ASSERT_TRUE(device != nullptr); |
3621 ASSERT_FALSE(device->IsPaired()); | 3585 ASSERT_FALSE(device->IsPaired()); |
3622 | 3586 |
3623 TestBluetoothAdapterObserver observer(adapter_); | 3587 TestBluetoothAdapterObserver observer(adapter_); |
3624 | 3588 |
3625 fake_bluetooth_device_client_->SimulatePairing( | 3589 fake_bluetooth_device_client_->SimulatePairing( |
3626 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), | 3590 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), |
3627 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3591 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3628 base::Unretained(this))); | 3592 base::Unretained(this))); |
3629 | 3593 |
3630 message_loop_.Run(); | 3594 message_loop_.Run(); |
3631 | 3595 |
3632 EXPECT_EQ(0, callback_count_); | 3596 EXPECT_EQ(0, callback_count_); |
3633 EXPECT_EQ(1, error_callback_count_); | 3597 EXPECT_EQ(1, error_callback_count_); |
3634 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3598 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
3635 | 3599 |
3636 // No changes should be observer. | 3600 // No changes should be observer. |
3637 EXPECT_EQ(0, observer.device_changed_count()); | 3601 EXPECT_EQ(0, observer.device_changed_count()); |
3638 | 3602 |
3639 EXPECT_FALSE(device->IsPaired()); | 3603 EXPECT_FALSE(device->IsPaired()); |
3640 | 3604 |
3641 // No pairing context should remain on the device. | 3605 // No pairing context should remain on the device. |
3642 BluetoothDeviceChromeOS* device_chromeos = | 3606 BluetoothDeviceBlueZ* device_bluez = |
3643 static_cast<BluetoothDeviceChromeOS*>(device); | 3607 static_cast<BluetoothDeviceBlueZ*>(device); |
3644 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3608 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3645 } | 3609 } |
3646 | 3610 |
3647 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { | 3611 TEST_F(BluetoothBlueZTest, IncomingPairRequestPasskeyWithoutDelegate) { |
3648 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3612 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3649 | 3613 |
3650 GetAdapter(); | 3614 GetAdapter(); |
3651 | 3615 |
3652 // Requests that we provide a displayed passkey, without a pairing delegate, | 3616 // Requests that we provide a displayed passkey, without a pairing delegate, |
3653 // that will be rejected. | 3617 // that will be rejected. |
3654 fake_bluetooth_device_client_->CreateDevice( | 3618 fake_bluetooth_device_client_->CreateDevice( |
3655 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3619 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3656 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3620 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
3657 BluetoothDevice* device = adapter_->GetDevice( | 3621 BluetoothDevice* device = adapter_->GetDevice( |
3658 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3622 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
3659 ASSERT_TRUE(device != nullptr); | 3623 ASSERT_TRUE(device != nullptr); |
3660 ASSERT_FALSE(device->IsPaired()); | 3624 ASSERT_FALSE(device->IsPaired()); |
3661 | 3625 |
3662 TestBluetoothAdapterObserver observer(adapter_); | 3626 TestBluetoothAdapterObserver observer(adapter_); |
3663 | 3627 |
3664 fake_bluetooth_device_client_->SimulatePairing( | 3628 fake_bluetooth_device_client_->SimulatePairing( |
3665 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), | 3629 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
3666 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3630 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3667 base::Unretained(this))); | 3631 base::Unretained(this))); |
3668 | 3632 |
3669 message_loop_.Run(); | 3633 message_loop_.Run(); |
3670 | 3634 |
3671 EXPECT_EQ(0, callback_count_); | 3635 EXPECT_EQ(0, callback_count_); |
3672 EXPECT_EQ(1, error_callback_count_); | 3636 EXPECT_EQ(1, error_callback_count_); |
3673 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3637 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
3674 | 3638 |
3675 // No changes should be observer. | 3639 // No changes should be observer. |
3676 EXPECT_EQ(0, observer.device_changed_count()); | 3640 EXPECT_EQ(0, observer.device_changed_count()); |
3677 | 3641 |
3678 EXPECT_FALSE(device->IsPaired()); | 3642 EXPECT_FALSE(device->IsPaired()); |
3679 | 3643 |
3680 // No pairing context should remain on the device. | 3644 // No pairing context should remain on the device. |
3681 BluetoothDeviceChromeOS* device_chromeos = | 3645 BluetoothDeviceBlueZ* device_bluez = |
3682 static_cast<BluetoothDeviceChromeOS*>(device); | 3646 static_cast<BluetoothDeviceBlueZ*>(device); |
3683 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3647 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3684 } | 3648 } |
3685 | 3649 |
3686 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { | 3650 TEST_F(BluetoothBlueZTest, IncomingPairJustWorksWithoutDelegate) { |
3687 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3651 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3688 | 3652 |
3689 GetAdapter(); | 3653 GetAdapter(); |
3690 | 3654 |
3691 // Uses just-works pairing and thus requires authorization for incoming | 3655 // Uses just-works pairing and thus requires authorization for incoming |
3692 // pairings, without a pairing delegate, that will be rejected. | 3656 // pairings, without a pairing delegate, that will be rejected. |
3693 fake_bluetooth_device_client_->CreateDevice( | 3657 fake_bluetooth_device_client_->CreateDevice( |
3694 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3658 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3695 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); | 3659 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
3696 BluetoothDevice* device = | 3660 BluetoothDevice* device = |
3697 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); | 3661 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
3698 ASSERT_TRUE(device != nullptr); | 3662 ASSERT_TRUE(device != nullptr); |
3699 ASSERT_FALSE(device->IsPaired()); | 3663 ASSERT_FALSE(device->IsPaired()); |
3700 | 3664 |
3701 TestBluetoothAdapterObserver observer(adapter_); | 3665 TestBluetoothAdapterObserver observer(adapter_); |
3702 | 3666 |
3703 fake_bluetooth_device_client_->SimulatePairing( | 3667 fake_bluetooth_device_client_->SimulatePairing( |
3704 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, | 3668 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, |
3705 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3669 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3706 base::Unretained(this))); | 3670 base::Unretained(this))); |
3707 | 3671 |
3708 message_loop_.Run(); | 3672 message_loop_.Run(); |
3709 | 3673 |
3710 EXPECT_EQ(0, callback_count_); | 3674 EXPECT_EQ(0, callback_count_); |
3711 EXPECT_EQ(1, error_callback_count_); | 3675 EXPECT_EQ(1, error_callback_count_); |
3712 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3676 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
3713 | 3677 |
3714 // No changes should be observer. | 3678 // No changes should be observer. |
3715 EXPECT_EQ(0, observer.device_changed_count()); | 3679 EXPECT_EQ(0, observer.device_changed_count()); |
3716 | 3680 |
3717 EXPECT_FALSE(device->IsPaired()); | 3681 EXPECT_FALSE(device->IsPaired()); |
3718 | 3682 |
3719 // No pairing context should remain on the device. | 3683 // No pairing context should remain on the device. |
3720 BluetoothDeviceChromeOS* device_chromeos = | 3684 BluetoothDeviceBlueZ* device_bluez = |
3721 static_cast<BluetoothDeviceChromeOS*>(device); | 3685 static_cast<BluetoothDeviceBlueZ*>(device); |
3722 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3686 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3723 } | 3687 } |
3724 | 3688 |
3725 TEST_F(BluetoothChromeOSTest, RemovePairingDelegateDuringPairing) { | 3689 TEST_F(BluetoothBlueZTest, RemovePairingDelegateDuringPairing) { |
3726 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3690 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
3727 | 3691 |
3728 GetAdapter(); | 3692 GetAdapter(); |
3729 | 3693 |
3730 TestPairingDelegate pairing_delegate; | 3694 TestPairingDelegate pairing_delegate; |
3731 adapter_->AddPairingDelegate( | 3695 adapter_->AddPairingDelegate( |
3732 &pairing_delegate, | 3696 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
3733 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | |
3734 | 3697 |
3735 // Requests that we provide a Passkey. | 3698 // Requests that we provide a Passkey. |
3736 fake_bluetooth_device_client_->CreateDevice( | 3699 fake_bluetooth_device_client_->CreateDevice( |
3737 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 3700 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
3738 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3701 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
3739 BluetoothDevice* device = adapter_->GetDevice( | 3702 BluetoothDevice* device = adapter_->GetDevice( |
3740 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3703 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
3741 ASSERT_TRUE(device != nullptr); | 3704 ASSERT_TRUE(device != nullptr); |
3742 ASSERT_FALSE(device->IsPaired()); | 3705 ASSERT_FALSE(device->IsPaired()); |
3743 | 3706 |
3744 TestBluetoothAdapterObserver observer(adapter_); | 3707 TestBluetoothAdapterObserver observer(adapter_); |
3745 | 3708 |
3746 fake_bluetooth_device_client_->SimulatePairing( | 3709 fake_bluetooth_device_client_->SimulatePairing( |
3747 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), | 3710 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
3748 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3711 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, |
3749 base::Unretained(this))); | 3712 base::Unretained(this))); |
3750 | 3713 |
3751 EXPECT_EQ(1, pairing_delegate.call_count_); | 3714 EXPECT_EQ(1, pairing_delegate.call_count_); |
3752 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3715 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
3753 | 3716 |
3754 // A pairing context should now be set on the device. | 3717 // A pairing context should now be set on the device. |
3755 BluetoothDeviceChromeOS* device_chromeos = | 3718 BluetoothDeviceBlueZ* device_bluez = |
3756 static_cast<BluetoothDeviceChromeOS*>(device); | 3719 static_cast<BluetoothDeviceBlueZ*>(device); |
3757 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); | 3720 ASSERT_TRUE(device_bluez->GetPairing() != nullptr); |
3758 | 3721 |
3759 // Removing the pairing delegate should remove that pairing context. | 3722 // Removing the pairing delegate should remove that pairing context. |
3760 adapter_->RemovePairingDelegate(&pairing_delegate); | 3723 adapter_->RemovePairingDelegate(&pairing_delegate); |
3761 | 3724 |
3762 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3725 EXPECT_TRUE(device_bluez->GetPairing() == nullptr); |
3763 | 3726 |
3764 // Set the Passkey, this should now have no effect since the pairing has | 3727 // Set the Passkey, this should now have no effect since the pairing has |
3765 // been, in-effect, cancelled | 3728 // been, in-effect, cancelled |
3766 device->SetPasskey(1234); | 3729 device->SetPasskey(1234); |
3767 | 3730 |
3768 EXPECT_EQ(0, callback_count_); | 3731 EXPECT_EQ(0, callback_count_); |
3769 EXPECT_EQ(0, error_callback_count_); | 3732 EXPECT_EQ(0, error_callback_count_); |
3770 EXPECT_EQ(0, observer.device_changed_count()); | 3733 EXPECT_EQ(0, observer.device_changed_count()); |
3771 | 3734 |
3772 EXPECT_FALSE(device->IsPaired()); | 3735 EXPECT_FALSE(device->IsPaired()); |
3773 } | 3736 } |
3774 | 3737 |
3775 TEST_F(BluetoothChromeOSTest, DeviceId) { | 3738 TEST_F(BluetoothBlueZTest, DeviceId) { |
3776 GetAdapter(); | 3739 GetAdapter(); |
3777 | 3740 |
3778 // Use the built-in paired device for this test, grab its Properties | 3741 // Use the built-in paired device for this test, grab its Properties |
3779 // structure so we can adjust the underlying modalias property. | 3742 // structure so we can adjust the underlying modalias property. |
3780 BluetoothDevice* device = adapter_->GetDevice( | 3743 BluetoothDevice* device = adapter_->GetDevice( |
3781 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3744 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
3782 bluez::FakeBluetoothDeviceClient::Properties* properties = | 3745 bluez::FakeBluetoothDeviceClient::Properties* properties = |
3783 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 3746 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
3784 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 3747 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
3785 | 3748 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3820 | 3783 |
3821 // Unknown vendor specification identifier. | 3784 // Unknown vendor specification identifier. |
3822 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); | 3785 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); |
3823 | 3786 |
3824 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); | 3787 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); |
3825 EXPECT_EQ(0, device->GetVendorID()); | 3788 EXPECT_EQ(0, device->GetVendorID()); |
3826 EXPECT_EQ(0, device->GetProductID()); | 3789 EXPECT_EQ(0, device->GetProductID()); |
3827 EXPECT_EQ(0, device->GetDeviceID()); | 3790 EXPECT_EQ(0, device->GetDeviceID()); |
3828 } | 3791 } |
3829 | 3792 |
3830 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { | 3793 TEST_F(BluetoothBlueZTest, GetConnectionInfoForDisconnectedDevice) { |
3831 GetAdapter(); | 3794 GetAdapter(); |
3832 BluetoothDevice* device = adapter_->GetDevice( | 3795 BluetoothDevice* device = adapter_->GetDevice( |
3833 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3796 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
3834 | 3797 |
3835 // Calling GetConnectionInfo for an unconnected device should return a result | 3798 // Calling GetConnectionInfo for an unconnected device should return a result |
3836 // in which all fields are filled with BluetoothDevice::kUnknownPower. | 3799 // in which all fields are filled with BluetoothDevice::kUnknownPower. |
3837 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); | 3800 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); |
3838 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3801 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
3839 int unknown_power = BluetoothDevice::kUnknownPower; | 3802 int unknown_power = BluetoothDevice::kUnknownPower; |
3840 EXPECT_NE(0, unknown_power); | 3803 EXPECT_NE(0, unknown_power); |
3841 EXPECT_EQ(unknown_power, conn_info.rssi); | 3804 EXPECT_EQ(unknown_power, conn_info.rssi); |
3842 EXPECT_EQ(unknown_power, conn_info.transmit_power); | 3805 EXPECT_EQ(unknown_power, conn_info.transmit_power); |
3843 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); | 3806 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); |
3844 } | 3807 } |
3845 | 3808 |
3846 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { | 3809 TEST_F(BluetoothBlueZTest, GetConnectionInfoForConnectedDevice) { |
3847 GetAdapter(); | 3810 GetAdapter(); |
3848 BluetoothDevice* device = adapter_->GetDevice( | 3811 BluetoothDevice* device = adapter_->GetDevice( |
3849 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3812 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
3850 | 3813 |
3851 device->Connect(nullptr, GetCallback(), | 3814 device->Connect(nullptr, GetCallback(), |
3852 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3815 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
3853 base::Unretained(this))); | 3816 base::Unretained(this))); |
3854 EXPECT_TRUE(device->IsConnected()); | 3817 EXPECT_TRUE(device->IsConnected()); |
3855 | 3818 |
3856 // Calling GetConnectionInfo for a connected device should return valid | 3819 // Calling GetConnectionInfo for a connected device should return valid |
3857 // results. | 3820 // results. |
3858 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); | 3821 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); |
3859 BluetoothDevice::ConnectionInfo conn_info; | 3822 BluetoothDevice::ConnectionInfo conn_info; |
3860 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3823 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
3861 EXPECT_EQ(-10, conn_info.rssi); | 3824 EXPECT_EQ(-10, conn_info.rssi); |
3862 EXPECT_EQ(3, conn_info.transmit_power); | 3825 EXPECT_EQ(3, conn_info.transmit_power); |
3863 EXPECT_EQ(4, conn_info.max_transmit_power); | 3826 EXPECT_EQ(4, conn_info.max_transmit_power); |
3864 } | 3827 } |
3865 | 3828 |
3866 // Verifies Shutdown shuts down the adapter as expected. | 3829 // Verifies Shutdown shuts down the adapter as expected. |
3867 TEST_F(BluetoothChromeOSTest, Shutdown) { | 3830 TEST_F(BluetoothBlueZTest, Shutdown) { |
3868 // Set up adapter. Set powered & discoverable, start discovery. | 3831 // Set up adapter. Set powered & discoverable, start discovery. |
3869 GetAdapter(); | 3832 GetAdapter(); |
3870 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 3833 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
3871 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); | 3834 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
3872 adapter_->StartDiscoverySession( | 3835 adapter_->StartDiscoverySession( |
3873 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 3836 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
3874 base::Unretained(this)), | 3837 base::Unretained(this)), |
3875 GetErrorCallback()); | 3838 GetErrorCallback()); |
3876 base::MessageLoop::current()->Run(); | 3839 base::MessageLoop::current()->Run(); |
3877 ASSERT_EQ(3, callback_count_); | 3840 ASSERT_EQ(3, callback_count_); |
3878 ASSERT_EQ(0, error_callback_count_); | 3841 ASSERT_EQ(0, error_callback_count_); |
3879 callback_count_ = 0; | 3842 callback_count_ = 0; |
3880 | 3843 |
3881 TestPairingDelegate pairing_delegate; | 3844 TestPairingDelegate pairing_delegate; |
3882 adapter_->AddPairingDelegate( | 3845 adapter_->AddPairingDelegate( |
3883 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3846 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
3884 | 3847 |
3885 // Validate running adapter state. | 3848 // Validate running adapter state. |
3886 EXPECT_NE("", adapter_->GetAddress()); | 3849 EXPECT_NE("", adapter_->GetAddress()); |
3887 EXPECT_NE("", adapter_->GetName()); | 3850 EXPECT_NE("", adapter_->GetName()); |
3888 EXPECT_TRUE(adapter_->IsInitialized()); | 3851 EXPECT_TRUE(adapter_->IsInitialized()); |
3889 EXPECT_TRUE(adapter_->IsPresent()); | 3852 EXPECT_TRUE(adapter_->IsPresent()); |
3890 EXPECT_TRUE(adapter_->IsPowered()); | 3853 EXPECT_TRUE(adapter_->IsPowered()); |
3891 EXPECT_TRUE(adapter_->IsDiscoverable()); | 3854 EXPECT_TRUE(adapter_->IsDiscoverable()); |
3892 EXPECT_TRUE(adapter_->IsDiscovering()); | 3855 EXPECT_TRUE(adapter_->IsDiscovering()); |
3893 EXPECT_EQ(2U, adapter_->GetDevices().size()); | 3856 EXPECT_EQ(2U, adapter_->GetDevices().size()); |
3894 EXPECT_NE(nullptr, | 3857 EXPECT_NE(nullptr, |
3895 adapter_->GetDevice( | 3858 adapter_->GetDevice( |
3896 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 3859 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
3897 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | 3860 EXPECT_NE(dbus::ObjectPath(""), |
3898 adapter_.get())->object_path()); | 3861 static_cast<BluetoothAdapterBlueZ*>(adapter_.get())->object_path()); |
3899 | 3862 |
3900 // Shutdown | 3863 // Shutdown |
3901 adapter_->Shutdown(); | 3864 adapter_->Shutdown(); |
3902 | 3865 |
3903 // Validate post shutdown state by calling all BluetoothAdapterChromeOS | 3866 // Validate post shutdown state by calling all BluetoothAdapterBlueZ |
3904 // members, in declaration order: | 3867 // members, in declaration order: |
3905 | 3868 |
3906 adapter_->Shutdown(); | 3869 adapter_->Shutdown(); |
3907 // DeleteOnCorrectThread omitted as we don't want to delete in this test. | 3870 // DeleteOnCorrectThread omitted as we don't want to delete in this test. |
3908 { | 3871 { |
3909 TestBluetoothAdapterObserver observer(adapter_); // Calls AddObserver | 3872 TestBluetoothAdapterObserver observer(adapter_); // Calls AddObserver |
3910 } // ~TestBluetoothAdapterObserver calls RemoveObserver. | 3873 } // ~TestBluetoothAdapterObserver calls RemoveObserver. |
3911 EXPECT_EQ("", adapter_->GetAddress()); | 3874 EXPECT_EQ("", adapter_->GetAddress()); |
3912 EXPECT_EQ("", adapter_->GetName()); | 3875 EXPECT_EQ("", adapter_->GetName()); |
3913 | 3876 |
(...skipping 15 matching lines...) Expand all Loading... |
3929 EXPECT_EQ(0, callback_count_); | 3892 EXPECT_EQ(0, callback_count_); |
3930 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; | 3893 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; |
3931 | 3894 |
3932 EXPECT_FALSE(adapter_->IsDiscovering()); | 3895 EXPECT_FALSE(adapter_->IsDiscovering()); |
3933 // CreateRfcommService will DCHECK after Shutdown(). | 3896 // CreateRfcommService will DCHECK after Shutdown(). |
3934 // CreateL2capService will DCHECK after Shutdown(). | 3897 // CreateL2capService will DCHECK after Shutdown(). |
3935 | 3898 |
3936 BluetoothAudioSink::Options audio_sink_options; | 3899 BluetoothAudioSink::Options audio_sink_options; |
3937 adapter_->RegisterAudioSink( | 3900 adapter_->RegisterAudioSink( |
3938 audio_sink_options, | 3901 audio_sink_options, |
3939 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, | 3902 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, |
3940 base::Unretained(this)), | 3903 base::Unretained(this)), |
3941 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, | 3904 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, |
3942 base::Unretained(this))); | 3905 base::Unretained(this))); |
3943 EXPECT_EQ(0, callback_count_); | 3906 EXPECT_EQ(0, callback_count_); |
3944 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; | 3907 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
3945 | 3908 |
3946 BluetoothAdapterChromeOS* adapter_chrome_os = | 3909 BluetoothAdapterBlueZ* adapter_chrome_os = |
3947 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | 3910 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
3948 EXPECT_EQ(nullptr, | 3911 EXPECT_EQ(nullptr, |
3949 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); | 3912 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); |
3950 | 3913 |
3951 // Notify methods presume objects exist that are owned by the adapter and | 3914 // Notify methods presume objects exist that are owned by the adapter and |
3952 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, | 3915 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, |
3953 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); | 3916 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); |
3954 // NotifyDeviceChanged | 3917 // NotifyDeviceChanged |
3955 // NotifyGattServiceAdded | 3918 // NotifyGattServiceAdded |
3956 // NotifyGattServiceRemoved | 3919 // NotifyGattServiceRemoved |
3957 // NotifyGattServiceChanged | 3920 // NotifyGattServiceChanged |
3958 // NotifyGattDiscoveryComplete | 3921 // NotifyGattDiscoveryComplete |
3959 // NotifyGattCharacteristicAdded | 3922 // NotifyGattCharacteristicAdded |
3960 // NotifyGattCharacteristicRemoved | 3923 // NotifyGattCharacteristicRemoved |
3961 // NotifyGattDescriptorAdded | 3924 // NotifyGattDescriptorAdded |
3962 // NotifyGattDescriptorRemoved | 3925 // NotifyGattDescriptorRemoved |
3963 // NotifyGattCharacteristicValueChanged | 3926 // NotifyGattCharacteristicValueChanged |
3964 // NotifyGattDescriptorValueChanged | 3927 // NotifyGattDescriptorValueChanged |
3965 | 3928 |
3966 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); | 3929 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); |
3967 | 3930 |
3968 adapter_profile_ = nullptr; | 3931 adapter_profile_ = nullptr; |
3969 | 3932 |
3970 FakeBluetoothProfileServiceProviderDelegate profile_delegate; | 3933 FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
3971 adapter_chrome_os->UseProfile( | 3934 adapter_chrome_os->UseProfile( |
3972 BluetoothUUID(), dbus::ObjectPath(""), | 3935 BluetoothUUID(), dbus::ObjectPath(""), |
3973 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, | 3936 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
3974 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 3937 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, |
3975 base::Unretained(this)), | 3938 base::Unretained(this)), |
3976 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 3939 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, |
3977 base::Unretained(this))); | 3940 base::Unretained(this))); |
3978 | 3941 |
3979 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 3942 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
3980 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 3943 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
3981 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 3944 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
3982 | 3945 |
3983 // Protected and private methods: | 3946 // Protected and private methods: |
3984 | 3947 |
3985 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); | 3948 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); |
3986 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. | 3949 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. |
3987 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); | 3950 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); |
3988 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); | 3951 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); |
3989 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); | 3952 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); |
3990 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); | 3953 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); |
3991 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); | 3954 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); |
3992 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); | 3955 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); |
3993 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be | 3956 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be |
3994 // shutdown, | 3957 // shutdown, |
3995 // with the exception of Released. | 3958 // with the exception of Released. |
3996 adapter_chrome_os->Released(); | 3959 adapter_chrome_os->Released(); |
3997 | 3960 |
3998 adapter_chrome_os->OnRegisterAgent(); | 3961 adapter_chrome_os->OnRegisterAgent(); |
3999 adapter_chrome_os->OnRegisterAgentError("", ""); | 3962 adapter_chrome_os->OnRegisterAgentError("", ""); |
4000 adapter_chrome_os->OnRequestDefaultAgent(); | 3963 adapter_chrome_os->OnRequestDefaultAgent(); |
4001 adapter_chrome_os->OnRequestDefaultAgentError("", ""); | 3964 adapter_chrome_os->OnRequestDefaultAgentError("", ""); |
4002 | 3965 |
4003 adapter_chrome_os->OnRegisterAudioSink( | 3966 adapter_chrome_os->OnRegisterAudioSink( |
4004 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, | 3967 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback, |
4005 base::Unretained(this)), | 3968 base::Unretained(this)), |
4006 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, | 3969 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback, |
4007 base::Unretained(this)), | 3970 base::Unretained(this)), |
4008 scoped_refptr<device::BluetoothAudioSink>()); | 3971 scoped_refptr<device::BluetoothAudioSink>()); |
4009 EXPECT_EQ(0, callback_count_); | 3972 EXPECT_EQ(0, callback_count_); |
4010 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; | 3973 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
4011 | 3974 |
4012 // GetPairing will DCHECK after Shutdown(). | 3975 // GetPairing will DCHECK after Shutdown(). |
4013 // SetAdapter will DCHECK after Shutdown(). | 3976 // SetAdapter will DCHECK after Shutdown(). |
4014 // SetDefaultAdapterName will DCHECK after Shutdown(). | 3977 // SetDefaultAdapterName will DCHECK after Shutdown(). |
4015 // RemoveAdapter will DCHECK after Shutdown(). | 3978 // RemoveAdapter will DCHECK after Shutdown(). |
4016 adapter_chrome_os->PoweredChanged(false); | 3979 adapter_chrome_os->PoweredChanged(false); |
(...skipping 25 matching lines...) Expand all Loading... |
4042 // OnStopDiscovery tested in Shutdown_OnStopDiscovery | 4005 // OnStopDiscovery tested in Shutdown_OnStopDiscovery |
4043 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError | 4006 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError |
4044 | 4007 |
4045 adapter_profile_ = nullptr; | 4008 adapter_profile_ = nullptr; |
4046 | 4009 |
4047 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require | 4010 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require |
4048 // UseProfile to be set first, do so again here just before calling them. | 4011 // UseProfile to be set first, do so again here just before calling them. |
4049 adapter_chrome_os->UseProfile( | 4012 adapter_chrome_os->UseProfile( |
4050 BluetoothUUID(), dbus::ObjectPath(""), | 4013 BluetoothUUID(), dbus::ObjectPath(""), |
4051 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, | 4014 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
4052 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 4015 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, |
4053 base::Unretained(this)), | 4016 base::Unretained(this)), |
4054 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 4017 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, |
4055 base::Unretained(this))); | 4018 base::Unretained(this))); |
4056 | 4019 |
4057 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 4020 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
4058 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 4021 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
4059 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 4022 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
4060 | 4023 |
4061 adapter_chrome_os->SetProfileDelegate( | 4024 adapter_chrome_os->SetProfileDelegate( |
4062 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, | 4025 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, |
4063 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 4026 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback, |
4064 base::Unretained(this)), | 4027 base::Unretained(this)), |
4065 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 4028 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback, |
4066 base::Unretained(this))); | 4029 base::Unretained(this))); |
4067 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; | 4030 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; |
4068 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; | 4031 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; |
4069 | 4032 |
4070 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", ""); | 4033 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", ""); |
4071 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; | 4034 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; |
4072 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error"; | 4035 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error"; |
4073 | 4036 |
4074 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); | 4037 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); |
4075 | 4038 |
4076 // From BluetoothAdapater: | 4039 // From BluetoothAdapater: |
4077 | 4040 |
4078 adapter_->StartDiscoverySession( | 4041 adapter_->StartDiscoverySession( |
4079 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 4042 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
4080 base::Unretained(this)), | 4043 base::Unretained(this)), |
4081 GetErrorCallback()); | 4044 GetErrorCallback()); |
4082 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; | 4045 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
4083 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; | 4046 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; |
4084 | 4047 |
4085 EXPECT_EQ(0U, adapter_->GetDevices().size()); | 4048 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
4086 EXPECT_EQ(nullptr, | 4049 EXPECT_EQ(nullptr, |
4087 adapter_->GetDevice( | 4050 adapter_->GetDevice( |
4088 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 4051 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
4089 TestPairingDelegate pairing_delegate2; | 4052 TestPairingDelegate pairing_delegate2; |
4090 adapter_->AddPairingDelegate( | 4053 adapter_->AddPairingDelegate( |
4091 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 4054 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
4092 adapter_->RemovePairingDelegate(&pairing_delegate2); | 4055 adapter_->RemovePairingDelegate(&pairing_delegate2); |
4093 } | 4056 } |
4094 | 4057 |
4095 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. | 4058 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
4096 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { | 4059 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscovery) { |
4097 const int kNumberOfDiscoverySessions = 10; | 4060 const int kNumberOfDiscoverySessions = 10; |
4098 GetAdapter(); | 4061 GetAdapter(); |
4099 BluetoothAdapterChromeOS* adapter_chrome_os = | 4062 BluetoothAdapterBlueZ* adapter_chrome_os = |
4100 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | 4063 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4101 | 4064 |
4102 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4065 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4103 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4066 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), |
4104 GetDiscoveryErrorCallback()); | 4067 GetDiscoveryErrorCallback()); |
4105 } | 4068 } |
4106 adapter_->Shutdown(); | 4069 adapter_->Shutdown(); |
4107 adapter_chrome_os->OnStartDiscovery(GetCallback(), | 4070 adapter_chrome_os->OnStartDiscovery(GetCallback(), |
4108 GetDiscoveryErrorCallback()); | 4071 GetDiscoveryErrorCallback()); |
4109 | 4072 |
4110 EXPECT_EQ(0, callback_count_); | 4073 EXPECT_EQ(0, callback_count_); |
4111 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); | 4074 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
4112 } | 4075 } |
4113 | 4076 |
4114 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. | 4077 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. |
4115 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscoveryError) { | 4078 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscoveryError) { |
4116 const int kNumberOfDiscoverySessions = 10; | 4079 const int kNumberOfDiscoverySessions = 10; |
4117 GetAdapter(); | 4080 GetAdapter(); |
4118 BluetoothAdapterChromeOS* adapter_chrome_os = | 4081 BluetoothAdapterBlueZ* adapter_chrome_os = |
4119 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | 4082 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4120 | 4083 |
4121 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4084 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4122 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4085 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), |
4123 GetDiscoveryErrorCallback()); | 4086 GetDiscoveryErrorCallback()); |
4124 } | 4087 } |
4125 adapter_->Shutdown(); | 4088 adapter_->Shutdown(); |
4126 adapter_chrome_os->OnStartDiscoveryError(GetCallback(), | 4089 adapter_chrome_os->OnStartDiscoveryError(GetCallback(), |
4127 GetDiscoveryErrorCallback(), "", ""); | 4090 GetDiscoveryErrorCallback(), "", ""); |
4128 | 4091 |
4129 EXPECT_EQ(0, callback_count_); | 4092 EXPECT_EQ(0, callback_count_); |
4130 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); | 4093 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
4131 } | 4094 } |
4132 | 4095 |
4133 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. | 4096 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
4134 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscovery) { | 4097 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscovery) { |
4135 const int kNumberOfDiscoverySessions = 10; | 4098 const int kNumberOfDiscoverySessions = 10; |
4136 GetAdapter(); | 4099 GetAdapter(); |
4137 BluetoothAdapterChromeOS* adapter_chrome_os = | 4100 BluetoothAdapterBlueZ* adapter_chrome_os = |
4138 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | 4101 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4139 | 4102 |
4140 // In order to queue up discovery sessions before an OnStopDiscovery call | 4103 // In order to queue up discovery sessions before an OnStopDiscovery call |
4141 // RemoveDiscoverySession must be called, so Add, Start, and Remove: | 4104 // RemoveDiscoverySession must be called, so Add, Start, and Remove: |
4142 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4105 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), |
4143 GetDiscoveryErrorCallback()); | 4106 GetDiscoveryErrorCallback()); |
4144 adapter_chrome_os->OnStartDiscovery(GetCallback(), | 4107 adapter_chrome_os->OnStartDiscovery(GetCallback(), |
4145 GetDiscoveryErrorCallback()); | 4108 GetDiscoveryErrorCallback()); |
4146 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), | 4109 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), |
4147 GetDiscoveryErrorCallback()); | 4110 GetDiscoveryErrorCallback()); |
4148 callback_count_ = 0; | 4111 callback_count_ = 0; |
4149 error_callback_count_ = 0; | 4112 error_callback_count_ = 0; |
4150 // Can now queue discovery sessions while waiting for OnStopDiscovery. | 4113 // Can now queue discovery sessions while waiting for OnStopDiscovery. |
4151 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4114 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4152 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4115 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), |
4153 GetDiscoveryErrorCallback()); | 4116 GetDiscoveryErrorCallback()); |
4154 } | 4117 } |
4155 adapter_->Shutdown(); | 4118 adapter_->Shutdown(); |
4156 adapter_chrome_os->OnStopDiscovery(GetCallback()); | 4119 adapter_chrome_os->OnStopDiscovery(GetCallback()); |
4157 | 4120 |
4158 // 1 successful stopped discovery from RemoveDiscoverySession, and | 4121 // 1 successful stopped discovery from RemoveDiscoverySession, and |
4159 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. | 4122 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. |
4160 EXPECT_EQ(1, callback_count_); | 4123 EXPECT_EQ(1, callback_count_); |
4161 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); | 4124 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
4162 } | 4125 } |
4163 | 4126 |
4164 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. | 4127 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. |
4165 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscoveryError) { | 4128 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscoveryError) { |
4166 const int kNumberOfDiscoverySessions = 10; | 4129 const int kNumberOfDiscoverySessions = 10; |
4167 GetAdapter(); | 4130 GetAdapter(); |
4168 BluetoothAdapterChromeOS* adapter_chrome_os = | 4131 BluetoothAdapterBlueZ* adapter_chrome_os = |
4169 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); | 4132 static_cast<BluetoothAdapterBlueZ*>(adapter_.get()); |
4170 | 4133 |
4171 // In order to queue up discovery sessions before an OnStopDiscoveryError call | 4134 // In order to queue up discovery sessions before an OnStopDiscoveryError call |
4172 // RemoveDiscoverySession must be called, so Add, Start, and Remove: | 4135 // RemoveDiscoverySession must be called, so Add, Start, and Remove: |
4173 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4136 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), |
4174 GetDiscoveryErrorCallback()); | 4137 GetDiscoveryErrorCallback()); |
4175 adapter_chrome_os->OnStartDiscovery(GetCallback(), | 4138 adapter_chrome_os->OnStartDiscovery(GetCallback(), |
4176 GetDiscoveryErrorCallback()); | 4139 GetDiscoveryErrorCallback()); |
4177 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), | 4140 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), |
4178 GetDiscoveryErrorCallback()); | 4141 GetDiscoveryErrorCallback()); |
4179 callback_count_ = 0; | 4142 callback_count_ = 0; |
4180 error_callback_count_ = 0; | 4143 error_callback_count_ = 0; |
4181 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. | 4144 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. |
4182 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { | 4145 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
4183 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), | 4146 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), |
4184 GetDiscoveryErrorCallback()); | 4147 GetDiscoveryErrorCallback()); |
4185 } | 4148 } |
4186 adapter_->Shutdown(); | 4149 adapter_->Shutdown(); |
4187 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4150 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
4188 | 4151 |
4189 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4152 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
4190 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4153 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
4191 EXPECT_EQ(0, callback_count_); | 4154 EXPECT_EQ(0, callback_count_); |
4192 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4155 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
4193 } | 4156 } |
4194 | 4157 |
4195 } // namespace chromeos | 4158 } // namespace bluez |
OLD | NEW |