| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 9 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 11 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 11 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 12 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
| 12 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | 13 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
| 13 #include "chromeos/dbus/fake_bluetooth_input_client.h" | 14 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
| 14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 15 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
| 16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 17 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_factory.h" | 18 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 18 #include "device/bluetooth/bluetooth_device.h" | 19 #include "device/bluetooth/bluetooth_device.h" |
| 19 #include "device/bluetooth/bluetooth_device_chromeos.h" | 20 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 20 #include "device/bluetooth/bluetooth_discovery_session.h" | 21 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 21 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 22 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 | 25 |
| 25 using device::BluetoothAdapter; | 26 using device::BluetoothAdapter; |
| 26 using device::BluetoothAdapterFactory; | 27 using device::BluetoothAdapterFactory; |
| 28 using device::BluetoothAudioSink; |
| 27 using device::BluetoothDevice; | 29 using device::BluetoothDevice; |
| 28 using device::BluetoothDiscoverySession; | 30 using device::BluetoothDiscoverySession; |
| 29 using device::BluetoothUUID; | 31 using device::BluetoothUUID; |
| 30 | 32 |
| 31 namespace chromeos { | 33 namespace chromeos { |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 class TestObserver : public BluetoothAdapter::Observer { | 37 class TestObserver : public BluetoothAdapter::Observer { |
| 36 public: | 38 public: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 scoped_refptr<BluetoothAdapter> adapter_; | 141 scoped_refptr<BluetoothAdapter> adapter_; |
| 140 }; | 142 }; |
| 141 | 143 |
| 142 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the | 144 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the |
| 143 // connection info to the bound argument. | 145 // connection info to the bound argument. |
| 144 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, | 146 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, |
| 145 const BluetoothDevice::ConnectionInfo& conn_info) { | 147 const BluetoothDevice::ConnectionInfo& conn_info) { |
| 146 *out = conn_info; | 148 *out = conn_info; |
| 147 }; | 149 }; |
| 148 | 150 |
| 151 class FakeBluetoothProfileServiceProviderDelegate |
| 152 : public chromeos::BluetoothProfileServiceProvider::Delegate { |
| 153 public: |
| 154 FakeBluetoothProfileServiceProviderDelegate() {} |
| 155 |
| 156 // BluetoothProfileServiceProvider::Delegate: |
| 157 void Released() override {} |
| 158 |
| 159 void NewConnection(const dbus::ObjectPath&, |
| 160 scoped_ptr<dbus::FileDescriptor>, |
| 161 const BluetoothProfileServiceProvider::Delegate::Options&, |
| 162 const ConfirmationCallback&) override {} |
| 163 |
| 164 void RequestDisconnection(const dbus::ObjectPath&, |
| 165 const ConfirmationCallback&) override {} |
| 166 |
| 167 void Cancel() override {} |
| 168 }; |
| 169 |
| 149 } // namespace | 170 } // namespace |
| 150 | 171 |
| 151 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { | 172 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { |
| 152 public: | 173 public: |
| 153 TestPairingDelegate() | 174 TestPairingDelegate() |
| 154 : call_count_(0), | 175 : call_count_(0), |
| 155 request_pincode_count_(0), | 176 request_pincode_count_(0), |
| 156 request_passkey_count_(0), | 177 request_passkey_count_(0), |
| 157 display_pincode_count_(0), | 178 display_pincode_count_(0), |
| 158 display_passkey_count_(0), | 179 display_passkey_count_(0), |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 286 |
| 266 void TearDown() override { | 287 void TearDown() override { |
| 267 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = | 288 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = |
| 268 discovery_sessions_.begin(); | 289 discovery_sessions_.begin(); |
| 269 iter != discovery_sessions_.end(); | 290 iter != discovery_sessions_.end(); |
| 270 ++iter) { | 291 ++iter) { |
| 271 BluetoothDiscoverySession* session = *iter; | 292 BluetoothDiscoverySession* session = *iter; |
| 272 if (!session->IsActive()) | 293 if (!session->IsActive()) |
| 273 continue; | 294 continue; |
| 274 callback_count_ = 0; | 295 callback_count_ = 0; |
| 275 session->Stop( | 296 session->Stop(GetCallback(), GetErrorCallback()); |
| 276 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 277 base::Unretained(this)), | |
| 278 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 279 base::Unretained(this))); | |
| 280 message_loop_.Run(); | 297 message_loop_.Run(); |
| 281 ASSERT_EQ(1, callback_count_); | 298 ASSERT_EQ(1, callback_count_); |
| 282 } | 299 } |
| 283 discovery_sessions_.clear(); | 300 discovery_sessions_.clear(); |
| 284 adapter_ = NULL; | 301 adapter_ = NULL; |
| 285 DBusThreadManager::Shutdown(); | 302 DBusThreadManager::Shutdown(); |
| 286 } | 303 } |
| 287 | 304 |
| 288 // Generic callbacks | 305 // Generic callbacks |
| 289 void Callback() { | 306 void Callback() { |
| 290 ++callback_count_; | 307 ++callback_count_; |
| 291 QuitMessageLoop(); | 308 QuitMessageLoop(); |
| 292 } | 309 } |
| 293 | 310 |
| 311 base::Closure GetCallback() { |
| 312 return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)); |
| 313 } |
| 314 |
| 294 void DiscoverySessionCallback( | 315 void DiscoverySessionCallback( |
| 295 scoped_ptr<BluetoothDiscoverySession> discovery_session) { | 316 scoped_ptr<BluetoothDiscoverySession> discovery_session) { |
| 296 ++callback_count_; | 317 ++callback_count_; |
| 297 discovery_sessions_.push_back(discovery_session.release()); | 318 discovery_sessions_.push_back(discovery_session.release()); |
| 298 QuitMessageLoop(); | 319 QuitMessageLoop(); |
| 299 } | 320 } |
| 300 | 321 |
| 322 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { |
| 323 ++callback_count_; |
| 324 QuitMessageLoop(); |
| 325 } |
| 326 |
| 327 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS*) { |
| 328 ++callback_count_; |
| 329 QuitMessageLoop(); |
| 330 } |
| 331 |
| 301 void ErrorCallback() { | 332 void ErrorCallback() { |
| 302 ++error_callback_count_; | 333 ++error_callback_count_; |
| 303 QuitMessageLoop(); | 334 QuitMessageLoop(); |
| 304 } | 335 } |
| 305 | 336 |
| 337 base::Closure GetErrorCallback() { |
| 338 return base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 339 base::Unretained(this)); |
| 340 } |
| 341 |
| 306 void DBusErrorCallback(const std::string& error_name, | 342 void DBusErrorCallback(const std::string& error_name, |
| 307 const std::string& error_message) { | 343 const std::string& error_message) { |
| 308 ++error_callback_count_; | 344 ++error_callback_count_; |
| 309 last_client_error_ = error_name; | 345 last_client_error_ = error_name; |
| 310 QuitMessageLoop(); | 346 QuitMessageLoop(); |
| 311 } | 347 } |
| 312 | 348 |
| 313 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { | 349 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { |
| 314 ++error_callback_count_; | 350 ++error_callback_count_; |
| 315 last_connect_error_ = error; | 351 last_connect_error_ = error; |
| 316 } | 352 } |
| 317 | 353 |
| 354 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { |
| 355 ++error_callback_count_; |
| 356 QuitMessageLoop(); |
| 357 } |
| 358 |
| 359 void ErrorCompletionCallback(const std::string& error_message) { |
| 360 ++error_callback_count_; |
| 361 QuitMessageLoop(); |
| 362 } |
| 363 |
| 318 // Call to fill the adapter_ member with a BluetoothAdapter instance. | 364 // Call to fill the adapter_ member with a BluetoothAdapter instance. |
| 319 void GetAdapter() { | 365 void GetAdapter() { |
| 320 adapter_ = new BluetoothAdapterChromeOS(); | 366 adapter_ = new BluetoothAdapterChromeOS(); |
| 321 ASSERT_TRUE(adapter_.get() != NULL); | 367 ASSERT_TRUE(adapter_.get() != NULL); |
| 322 ASSERT_TRUE(adapter_->IsInitialized()); | 368 ASSERT_TRUE(adapter_->IsInitialized()); |
| 323 } | 369 } |
| 324 | 370 |
| 325 // Run a discovery phase until the named device is detected, or if the named | 371 // Run a discovery phase until the named device is detected, or if the named |
| 326 // device is not created, the discovery process ends without finding it. | 372 // device is not created, the discovery process ends without finding it. |
| 327 // | 373 // |
| 328 // The correct behavior of discovery is tested by the "Discovery" test case | 374 // The correct behavior of discovery is tested by the "Discovery" test case |
| 329 // without using this function. | 375 // without using this function. |
| 330 void DiscoverDevice(const std::string& address) { | 376 void DiscoverDevice(const std::string& address) { |
| 331 ASSERT_TRUE(adapter_.get() != NULL); | 377 ASSERT_TRUE(adapter_.get() != NULL); |
| 332 ASSERT_TRUE(base::MessageLoop::current() != NULL); | 378 ASSERT_TRUE(base::MessageLoop::current() != NULL); |
| 333 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 379 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 334 | 380 |
| 335 TestObserver observer(adapter_); | 381 TestObserver observer(adapter_); |
| 336 | 382 |
| 337 adapter_->SetPowered( | 383 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 338 true, | |
| 339 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 340 base::Unretained(this)), | |
| 341 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 342 base::Unretained(this))); | |
| 343 adapter_->StartDiscoverySession( | 384 adapter_->StartDiscoverySession( |
| 344 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 385 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 345 base::Unretained(this)), | 386 base::Unretained(this)), |
| 346 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 387 GetErrorCallback()); |
| 347 base::Unretained(this))); | |
| 348 base::MessageLoop::current()->Run(); | 388 base::MessageLoop::current()->Run(); |
| 349 ASSERT_EQ(2, callback_count_); | 389 ASSERT_EQ(2, callback_count_); |
| 350 ASSERT_EQ(0, error_callback_count_); | 390 ASSERT_EQ(0, error_callback_count_); |
| 351 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 391 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 352 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 392 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 353 callback_count_ = 0; | 393 callback_count_ = 0; |
| 354 | 394 |
| 355 ASSERT_TRUE(adapter_->IsPowered()); | 395 ASSERT_TRUE(adapter_->IsPowered()); |
| 356 ASSERT_TRUE(adapter_->IsDiscovering()); | 396 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 357 | 397 |
| 358 while (!observer.device_removed_count_ && | 398 while (!observer.device_removed_count_ && |
| 359 observer.last_device_address_ != address) | 399 observer.last_device_address_ != address) |
| 360 base::MessageLoop::current()->Run(); | 400 base::MessageLoop::current()->Run(); |
| 361 | 401 |
| 362 discovery_sessions_[0]->Stop( | 402 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| 363 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 364 base::Unretained(this)), | |
| 365 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 366 base::Unretained(this))); | |
| 367 base::MessageLoop::current()->Run(); | 403 base::MessageLoop::current()->Run(); |
| 368 ASSERT_EQ(1, callback_count_); | 404 ASSERT_EQ(1, callback_count_); |
| 369 ASSERT_EQ(0, error_callback_count_); | 405 ASSERT_EQ(0, error_callback_count_); |
| 370 callback_count_ = 0; | 406 callback_count_ = 0; |
| 371 | 407 |
| 372 ASSERT_FALSE(adapter_->IsDiscovering()); | 408 ASSERT_FALSE(adapter_->IsDiscovering()); |
| 373 } | 409 } |
| 374 | 410 |
| 375 // Run a discovery phase so we have devices that can be paired with. | 411 // Run a discovery phase so we have devices that can be paired with. |
| 376 void DiscoverDevices() { | 412 void DiscoverDevices() { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 559 } |
| 524 | 560 |
| 525 TEST_F(BluetoothChromeOSTest, BecomePowered) { | 561 TEST_F(BluetoothChromeOSTest, BecomePowered) { |
| 526 GetAdapter(); | 562 GetAdapter(); |
| 527 ASSERT_FALSE(adapter_->IsPowered()); | 563 ASSERT_FALSE(adapter_->IsPowered()); |
| 528 | 564 |
| 529 // Install an observer; expect the AdapterPoweredChanged to be called | 565 // Install an observer; expect the AdapterPoweredChanged to be called |
| 530 // with true, and IsPowered() to return true. | 566 // with true, and IsPowered() to return true. |
| 531 TestObserver observer(adapter_); | 567 TestObserver observer(adapter_); |
| 532 | 568 |
| 533 adapter_->SetPowered( | 569 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 534 true, | |
| 535 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 536 base::Unretained(this)), | |
| 537 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 538 base::Unretained(this))); | |
| 539 EXPECT_EQ(1, callback_count_); | 570 EXPECT_EQ(1, callback_count_); |
| 540 EXPECT_EQ(0, error_callback_count_); | 571 EXPECT_EQ(0, error_callback_count_); |
| 541 | 572 |
| 542 EXPECT_EQ(1, observer.powered_changed_count_); | 573 EXPECT_EQ(1, observer.powered_changed_count_); |
| 543 EXPECT_TRUE(observer.last_powered_); | 574 EXPECT_TRUE(observer.last_powered_); |
| 544 | 575 |
| 545 EXPECT_TRUE(adapter_->IsPowered()); | 576 EXPECT_TRUE(adapter_->IsPowered()); |
| 546 } | 577 } |
| 547 | 578 |
| 548 TEST_F(BluetoothChromeOSTest, BecomeNotPowered) { | 579 TEST_F(BluetoothChromeOSTest, BecomeNotPowered) { |
| 549 GetAdapter(); | 580 GetAdapter(); |
| 550 adapter_->SetPowered( | 581 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 551 true, | |
| 552 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 553 base::Unretained(this)), | |
| 554 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 555 base::Unretained(this))); | |
| 556 EXPECT_EQ(1, callback_count_); | 582 EXPECT_EQ(1, callback_count_); |
| 557 EXPECT_EQ(0, error_callback_count_); | 583 EXPECT_EQ(0, error_callback_count_); |
| 558 callback_count_ = 0; | 584 callback_count_ = 0; |
| 559 | 585 |
| 560 ASSERT_TRUE(adapter_->IsPowered()); | 586 ASSERT_TRUE(adapter_->IsPowered()); |
| 561 | 587 |
| 562 // Install an observer; expect the AdapterPoweredChanged to be called | 588 // Install an observer; expect the AdapterPoweredChanged to be called |
| 563 // with false, and IsPowered() to return false. | 589 // with false, and IsPowered() to return false. |
| 564 TestObserver observer(adapter_); | 590 TestObserver observer(adapter_); |
| 565 | 591 |
| 566 adapter_->SetPowered( | 592 adapter_->SetPowered(false, GetCallback(), GetErrorCallback()); |
| 567 false, | |
| 568 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 569 base::Unretained(this)), | |
| 570 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 571 base::Unretained(this))); | |
| 572 EXPECT_EQ(1, callback_count_); | 593 EXPECT_EQ(1, callback_count_); |
| 573 EXPECT_EQ(0, error_callback_count_); | 594 EXPECT_EQ(0, error_callback_count_); |
| 574 | 595 |
| 575 EXPECT_EQ(1, observer.powered_changed_count_); | 596 EXPECT_EQ(1, observer.powered_changed_count_); |
| 576 EXPECT_FALSE(observer.last_powered_); | 597 EXPECT_FALSE(observer.last_powered_); |
| 577 | 598 |
| 578 EXPECT_FALSE(adapter_->IsPowered()); | 599 EXPECT_FALSE(adapter_->IsPowered()); |
| 579 } | 600 } |
| 580 | 601 |
| 581 TEST_F(BluetoothChromeOSTest, SetPoweredWhenNotPresent) { | 602 TEST_F(BluetoothChromeOSTest, SetPoweredWhenNotPresent) { |
| 582 GetAdapter(); | 603 GetAdapter(); |
| 583 ASSERT_TRUE(adapter_->IsPresent()); | 604 ASSERT_TRUE(adapter_->IsPresent()); |
| 584 | 605 |
| 585 // Install an observer; expect the AdapterPresentChanged to be called | 606 // Install an observer; expect the AdapterPresentChanged to be called |
| 586 // with false, and IsPresent() to return false. | 607 // with false, and IsPresent() to return false. |
| 587 TestObserver observer(adapter_); | 608 TestObserver observer(adapter_); |
| 588 | 609 |
| 589 fake_bluetooth_adapter_client_->SetVisible(false); | 610 fake_bluetooth_adapter_client_->SetVisible(false); |
| 590 | 611 |
| 591 EXPECT_EQ(1, observer.present_changed_count_); | 612 EXPECT_EQ(1, observer.present_changed_count_); |
| 592 EXPECT_FALSE(observer.last_present_); | 613 EXPECT_FALSE(observer.last_present_); |
| 593 | 614 |
| 594 EXPECT_FALSE(adapter_->IsPresent()); | 615 EXPECT_FALSE(adapter_->IsPresent()); |
| 595 EXPECT_FALSE(adapter_->IsPowered()); | 616 EXPECT_FALSE(adapter_->IsPowered()); |
| 596 | 617 |
| 597 adapter_->SetPowered( | 618 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 598 true, | |
| 599 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 600 base::Unretained(this)), | |
| 601 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 602 base::Unretained(this))); | |
| 603 EXPECT_EQ(0, callback_count_); | 619 EXPECT_EQ(0, callback_count_); |
| 604 EXPECT_EQ(1, error_callback_count_); | 620 EXPECT_EQ(1, error_callback_count_); |
| 605 | 621 |
| 606 EXPECT_EQ(0, observer.powered_changed_count_); | 622 EXPECT_EQ(0, observer.powered_changed_count_); |
| 607 EXPECT_FALSE(observer.last_powered_); | 623 EXPECT_FALSE(observer.last_powered_); |
| 608 | 624 |
| 609 EXPECT_FALSE(adapter_->IsPowered()); | 625 EXPECT_FALSE(adapter_->IsPowered()); |
| 610 } | 626 } |
| 611 | 627 |
| 612 TEST_F(BluetoothChromeOSTest, ChangeAdapterName) { | 628 TEST_F(BluetoothChromeOSTest, ChangeAdapterName) { |
| 613 GetAdapter(); | 629 GetAdapter(); |
| 614 | 630 |
| 615 static const std::string new_name(".__."); | 631 static const std::string new_name(".__."); |
| 616 | 632 |
| 617 adapter_->SetName( | 633 adapter_->SetName(new_name, GetCallback(), GetErrorCallback()); |
| 618 new_name, | |
| 619 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 620 base::Unretained(this)), | |
| 621 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 622 base::Unretained(this))); | |
| 623 EXPECT_EQ(1, callback_count_); | 634 EXPECT_EQ(1, callback_count_); |
| 624 EXPECT_EQ(0, error_callback_count_); | 635 EXPECT_EQ(0, error_callback_count_); |
| 625 | 636 |
| 626 EXPECT_EQ(new_name, adapter_->GetName()); | 637 EXPECT_EQ(new_name, adapter_->GetName()); |
| 627 } | 638 } |
| 628 | 639 |
| 629 TEST_F(BluetoothChromeOSTest, ChangeAdapterNameWhenNotPresent) { | 640 TEST_F(BluetoothChromeOSTest, ChangeAdapterNameWhenNotPresent) { |
| 630 GetAdapter(); | 641 GetAdapter(); |
| 631 ASSERT_TRUE(adapter_->IsPresent()); | 642 ASSERT_TRUE(adapter_->IsPresent()); |
| 632 | 643 |
| 633 // Install an observer; expect the AdapterPresentChanged to be called | 644 // Install an observer; expect the AdapterPresentChanged to be called |
| 634 // with false, and IsPresent() to return false. | 645 // with false, and IsPresent() to return false. |
| 635 TestObserver observer(adapter_); | 646 TestObserver observer(adapter_); |
| 636 | 647 |
| 637 fake_bluetooth_adapter_client_->SetVisible(false); | 648 fake_bluetooth_adapter_client_->SetVisible(false); |
| 638 | 649 |
| 639 EXPECT_EQ(1, observer.present_changed_count_); | 650 EXPECT_EQ(1, observer.present_changed_count_); |
| 640 EXPECT_FALSE(observer.last_present_); | 651 EXPECT_FALSE(observer.last_present_); |
| 641 | 652 |
| 642 EXPECT_FALSE(adapter_->IsPresent()); | 653 EXPECT_FALSE(adapter_->IsPresent()); |
| 643 EXPECT_FALSE(adapter_->IsPowered()); | 654 EXPECT_FALSE(adapter_->IsPowered()); |
| 644 | 655 |
| 645 adapter_->SetName( | 656 adapter_->SetName("^o^", GetCallback(), GetErrorCallback()); |
| 646 "^o^", | |
| 647 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 648 base::Unretained(this)), | |
| 649 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 650 base::Unretained(this))); | |
| 651 EXPECT_EQ(0, callback_count_); | 657 EXPECT_EQ(0, callback_count_); |
| 652 EXPECT_EQ(1, error_callback_count_); | 658 EXPECT_EQ(1, error_callback_count_); |
| 653 | 659 |
| 654 EXPECT_EQ("", adapter_->GetName()); | 660 EXPECT_EQ("", adapter_->GetName()); |
| 655 } | 661 } |
| 656 | 662 |
| 657 TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) { | 663 TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) { |
| 658 GetAdapter(); | 664 GetAdapter(); |
| 659 ASSERT_FALSE(adapter_->IsDiscoverable()); | 665 ASSERT_FALSE(adapter_->IsDiscoverable()); |
| 660 | 666 |
| 661 // Install an observer; expect the AdapterDiscoverableChanged to be called | 667 // Install an observer; expect the AdapterDiscoverableChanged to be called |
| 662 // with true, and IsDiscoverable() to return true. | 668 // with true, and IsDiscoverable() to return true. |
| 663 TestObserver observer(adapter_); | 669 TestObserver observer(adapter_); |
| 664 | 670 |
| 665 adapter_->SetDiscoverable( | 671 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
| 666 true, | |
| 667 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 668 base::Unretained(this)), | |
| 669 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 670 base::Unretained(this))); | |
| 671 EXPECT_EQ(1, callback_count_); | 672 EXPECT_EQ(1, callback_count_); |
| 672 EXPECT_EQ(0, error_callback_count_); | 673 EXPECT_EQ(0, error_callback_count_); |
| 673 | 674 |
| 674 EXPECT_EQ(1, observer.discoverable_changed_count_); | 675 EXPECT_EQ(1, observer.discoverable_changed_count_); |
| 675 | 676 |
| 676 EXPECT_TRUE(adapter_->IsDiscoverable()); | 677 EXPECT_TRUE(adapter_->IsDiscoverable()); |
| 677 } | 678 } |
| 678 | 679 |
| 679 TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) { | 680 TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) { |
| 680 GetAdapter(); | 681 GetAdapter(); |
| 681 adapter_->SetDiscoverable( | 682 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
| 682 true, | |
| 683 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 684 base::Unretained(this)), | |
| 685 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 686 base::Unretained(this))); | |
| 687 EXPECT_EQ(1, callback_count_); | 683 EXPECT_EQ(1, callback_count_); |
| 688 EXPECT_EQ(0, error_callback_count_); | 684 EXPECT_EQ(0, error_callback_count_); |
| 689 callback_count_ = 0; | 685 callback_count_ = 0; |
| 690 | 686 |
| 691 ASSERT_TRUE(adapter_->IsDiscoverable()); | 687 ASSERT_TRUE(adapter_->IsDiscoverable()); |
| 692 | 688 |
| 693 // Install an observer; expect the AdapterDiscoverableChanged to be called | 689 // Install an observer; expect the AdapterDiscoverableChanged to be called |
| 694 // with false, and IsDiscoverable() to return false. | 690 // with false, and IsDiscoverable() to return false. |
| 695 TestObserver observer(adapter_); | 691 TestObserver observer(adapter_); |
| 696 | 692 |
| 697 adapter_->SetDiscoverable( | 693 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback()); |
| 698 false, | |
| 699 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 700 base::Unretained(this)), | |
| 701 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 702 base::Unretained(this))); | |
| 703 EXPECT_EQ(1, callback_count_); | 694 EXPECT_EQ(1, callback_count_); |
| 704 EXPECT_EQ(0, error_callback_count_); | 695 EXPECT_EQ(0, error_callback_count_); |
| 705 | 696 |
| 706 EXPECT_EQ(1, observer.discoverable_changed_count_); | 697 EXPECT_EQ(1, observer.discoverable_changed_count_); |
| 707 | 698 |
| 708 EXPECT_FALSE(adapter_->IsDiscoverable()); | 699 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 709 } | 700 } |
| 710 | 701 |
| 711 TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) { | 702 TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) { |
| 712 GetAdapter(); | 703 GetAdapter(); |
| 713 ASSERT_TRUE(adapter_->IsPresent()); | 704 ASSERT_TRUE(adapter_->IsPresent()); |
| 714 ASSERT_FALSE(adapter_->IsDiscoverable()); | 705 ASSERT_FALSE(adapter_->IsDiscoverable()); |
| 715 | 706 |
| 716 // Install an observer; expect the AdapterDiscoverableChanged to be called | 707 // Install an observer; expect the AdapterDiscoverableChanged to be called |
| 717 // with true, and IsDiscoverable() to return true. | 708 // with true, and IsDiscoverable() to return true. |
| 718 TestObserver observer(adapter_); | 709 TestObserver observer(adapter_); |
| 719 | 710 |
| 720 fake_bluetooth_adapter_client_->SetVisible(false); | 711 fake_bluetooth_adapter_client_->SetVisible(false); |
| 721 | 712 |
| 722 EXPECT_EQ(1, observer.present_changed_count_); | 713 EXPECT_EQ(1, observer.present_changed_count_); |
| 723 EXPECT_FALSE(observer.last_present_); | 714 EXPECT_FALSE(observer.last_present_); |
| 724 | 715 |
| 725 EXPECT_FALSE(adapter_->IsPresent()); | 716 EXPECT_FALSE(adapter_->IsPresent()); |
| 726 EXPECT_FALSE(adapter_->IsDiscoverable()); | 717 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 727 | 718 |
| 728 adapter_->SetDiscoverable( | 719 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
| 729 true, | |
| 730 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 731 base::Unretained(this)), | |
| 732 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 733 base::Unretained(this))); | |
| 734 EXPECT_EQ(0, callback_count_); | 720 EXPECT_EQ(0, callback_count_); |
| 735 EXPECT_EQ(1, error_callback_count_); | 721 EXPECT_EQ(1, error_callback_count_); |
| 736 | 722 |
| 737 EXPECT_EQ(0, observer.discoverable_changed_count_); | 723 EXPECT_EQ(0, observer.discoverable_changed_count_); |
| 738 | 724 |
| 739 EXPECT_FALSE(adapter_->IsDiscoverable()); | 725 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 740 } | 726 } |
| 741 | 727 |
| 742 TEST_F(BluetoothChromeOSTest, StopDiscovery) { | 728 TEST_F(BluetoothChromeOSTest, StopDiscovery) { |
| 743 GetAdapter(); | 729 GetAdapter(); |
| 744 | 730 |
| 745 adapter_->SetPowered( | 731 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 746 true, | |
| 747 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 748 base::Unretained(this)), | |
| 749 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 750 base::Unretained(this))); | |
| 751 adapter_->StartDiscoverySession( | 732 adapter_->StartDiscoverySession( |
| 752 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 733 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 753 base::Unretained(this)), | 734 base::Unretained(this)), |
| 754 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 735 GetErrorCallback()); |
| 755 base::Unretained(this))); | |
| 756 message_loop_.Run(); | 736 message_loop_.Run(); |
| 757 EXPECT_EQ(2, callback_count_); | 737 EXPECT_EQ(2, callback_count_); |
| 758 EXPECT_EQ(0, error_callback_count_); | 738 EXPECT_EQ(0, error_callback_count_); |
| 759 callback_count_ = 0; | 739 callback_count_ = 0; |
| 760 | 740 |
| 761 ASSERT_TRUE(adapter_->IsPowered()); | 741 ASSERT_TRUE(adapter_->IsPowered()); |
| 762 ASSERT_TRUE(adapter_->IsDiscovering()); | 742 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 763 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 743 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 764 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 744 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 765 | 745 |
| 766 // Install an observer; aside from the callback, expect the | 746 // Install an observer; aside from the callback, expect the |
| 767 // AdapterDiscoveringChanged method to be called and no longer to be | 747 // AdapterDiscoveringChanged method to be called and no longer to be |
| 768 // discovering, | 748 // discovering, |
| 769 TestObserver observer(adapter_); | 749 TestObserver observer(adapter_); |
| 770 | 750 |
| 771 discovery_sessions_[0]->Stop( | 751 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| 772 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 773 base::Unretained(this)), | |
| 774 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 775 base::Unretained(this))); | |
| 776 message_loop_.Run(); | 752 message_loop_.Run(); |
| 777 EXPECT_EQ(1, callback_count_); | 753 EXPECT_EQ(1, callback_count_); |
| 778 EXPECT_EQ(0, error_callback_count_); | 754 EXPECT_EQ(0, error_callback_count_); |
| 779 | 755 |
| 780 EXPECT_EQ(1, observer.discovering_changed_count_); | 756 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 781 EXPECT_FALSE(observer.last_discovering_); | 757 EXPECT_FALSE(observer.last_discovering_); |
| 782 | 758 |
| 783 EXPECT_FALSE(adapter_->IsDiscovering()); | 759 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 784 } | 760 } |
| 785 | 761 |
| 786 TEST_F(BluetoothChromeOSTest, Discovery) { | 762 TEST_F(BluetoothChromeOSTest, Discovery) { |
| 787 // Test a simulated discovery session. | 763 // Test a simulated discovery session. |
| 788 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 764 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 789 GetAdapter(); | 765 GetAdapter(); |
| 790 | 766 |
| 791 TestObserver observer(adapter_); | 767 TestObserver observer(adapter_); |
| 792 | 768 |
| 793 adapter_->SetPowered( | 769 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 794 true, | |
| 795 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 796 base::Unretained(this)), | |
| 797 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 798 base::Unretained(this))); | |
| 799 adapter_->StartDiscoverySession( | 770 adapter_->StartDiscoverySession( |
| 800 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 771 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 801 base::Unretained(this)), | 772 base::Unretained(this)), |
| 802 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 773 GetErrorCallback()); |
| 803 base::Unretained(this))); | |
| 804 message_loop_.Run(); | 774 message_loop_.Run(); |
| 805 EXPECT_EQ(2, callback_count_); | 775 EXPECT_EQ(2, callback_count_); |
| 806 EXPECT_EQ(0, error_callback_count_); | 776 EXPECT_EQ(0, error_callback_count_); |
| 807 callback_count_ = 0; | 777 callback_count_ = 0; |
| 808 | 778 |
| 809 ASSERT_TRUE(adapter_->IsPowered()); | 779 ASSERT_TRUE(adapter_->IsPowered()); |
| 810 ASSERT_TRUE(adapter_->IsDiscovering()); | 780 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 811 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 781 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 812 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 782 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 813 | 783 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 826 while (!observer.device_removed_count_) | 796 while (!observer.device_removed_count_) |
| 827 message_loop_.Run(); | 797 message_loop_.Run(); |
| 828 | 798 |
| 829 EXPECT_EQ(1, observer.device_removed_count_); | 799 EXPECT_EQ(1, observer.device_removed_count_); |
| 830 EXPECT_EQ(FakeBluetoothDeviceClient::kVanishingDeviceAddress, | 800 EXPECT_EQ(FakeBluetoothDeviceClient::kVanishingDeviceAddress, |
| 831 observer.last_device_address_); | 801 observer.last_device_address_); |
| 832 } | 802 } |
| 833 | 803 |
| 834 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { | 804 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { |
| 835 GetAdapter(); | 805 GetAdapter(); |
| 836 adapter_->SetPowered( | 806 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 837 true, | |
| 838 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 839 base::Unretained(this)), | |
| 840 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 841 base::Unretained(this))); | |
| 842 adapter_->StartDiscoverySession( | 807 adapter_->StartDiscoverySession( |
| 843 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 808 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 844 base::Unretained(this)), | 809 base::Unretained(this)), |
| 845 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 810 GetErrorCallback()); |
| 846 base::Unretained(this))); | |
| 847 message_loop_.Run(); | 811 message_loop_.Run(); |
| 848 EXPECT_EQ(2, callback_count_); | 812 EXPECT_EQ(2, callback_count_); |
| 849 EXPECT_EQ(0, error_callback_count_); | 813 EXPECT_EQ(0, error_callback_count_); |
| 850 callback_count_ = 0; | 814 callback_count_ = 0; |
| 851 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 815 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 852 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 816 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 853 | 817 |
| 854 // Stop the timers that the simulation uses | 818 // Stop the timers that the simulation uses |
| 855 fake_bluetooth_device_client_->EndDiscoverySimulation( | 819 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 856 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 820 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 | 864 |
| 901 EXPECT_EQ(1, observer.discovering_changed_count_); | 865 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 902 EXPECT_FALSE(observer.last_discovering_); | 866 EXPECT_FALSE(observer.last_discovering_); |
| 903 EXPECT_FALSE(adapter_->IsDiscovering()); | 867 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 904 } | 868 } |
| 905 | 869 |
| 906 // This unit test asserts that the basic reference counting logic works | 870 // This unit test asserts that the basic reference counting logic works |
| 907 // correctly for discovery requests done via the BluetoothAdapter. | 871 // correctly for discovery requests done via the BluetoothAdapter. |
| 908 TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) { | 872 TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) { |
| 909 GetAdapter(); | 873 GetAdapter(); |
| 910 adapter_->SetPowered( | 874 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 911 true, | |
| 912 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 913 base::Unretained(this)), | |
| 914 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 915 base::Unretained(this))); | |
| 916 EXPECT_EQ(1, callback_count_); | 875 EXPECT_EQ(1, callback_count_); |
| 917 EXPECT_EQ(0, error_callback_count_); | 876 EXPECT_EQ(0, error_callback_count_); |
| 918 EXPECT_TRUE(adapter_->IsPowered()); | 877 EXPECT_TRUE(adapter_->IsPowered()); |
| 919 callback_count_ = 0; | 878 callback_count_ = 0; |
| 920 | 879 |
| 921 TestObserver observer(adapter_); | 880 TestObserver observer(adapter_); |
| 922 | 881 |
| 923 EXPECT_EQ(0, observer.discovering_changed_count_); | 882 EXPECT_EQ(0, observer.discovering_changed_count_); |
| 924 EXPECT_FALSE(observer.last_discovering_); | 883 EXPECT_FALSE(observer.last_discovering_); |
| 925 EXPECT_FALSE(adapter_->IsDiscovering()); | 884 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 926 | 885 |
| 927 // Request device discovery 3 times. | 886 // Request device discovery 3 times. |
| 928 for (int i = 0; i < 3; i++) { | 887 for (int i = 0; i < 3; i++) { |
| 929 adapter_->StartDiscoverySession( | 888 adapter_->StartDiscoverySession( |
| 930 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 889 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 931 base::Unretained(this)), | 890 base::Unretained(this)), |
| 932 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 891 GetErrorCallback()); |
| 933 base::Unretained(this))); | |
| 934 } | 892 } |
| 935 // Run only once, as there should have been one D-Bus call. | 893 // Run only once, as there should have been one D-Bus call. |
| 936 message_loop_.Run(); | 894 message_loop_.Run(); |
| 937 | 895 |
| 938 // The observer should have received the discovering changed event exactly | 896 // The observer should have received the discovering changed event exactly |
| 939 // once, the success callback should have been called 3 times and the adapter | 897 // once, the success callback should have been called 3 times and the adapter |
| 940 // should be discovering. | 898 // should be discovering. |
| 941 EXPECT_EQ(1, observer.discovering_changed_count_); | 899 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 942 EXPECT_EQ(3, callback_count_); | 900 EXPECT_EQ(3, callback_count_); |
| 943 EXPECT_EQ(0, error_callback_count_); | 901 EXPECT_EQ(0, error_callback_count_); |
| 944 EXPECT_TRUE(observer.last_discovering_); | 902 EXPECT_TRUE(observer.last_discovering_); |
| 945 EXPECT_TRUE(adapter_->IsDiscovering()); | 903 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 946 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 904 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 947 | 905 |
| 948 // Request to stop discovery twice. | 906 // Request to stop discovery twice. |
| 949 for (int i = 0; i < 2; i++) { | 907 for (int i = 0; i < 2; i++) { |
| 950 discovery_sessions_[i]->Stop( | 908 discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback()); |
| 951 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 952 base::Unretained(this)), | |
| 953 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 954 base::Unretained(this))); | |
| 955 } | 909 } |
| 956 | 910 |
| 957 // The observer should have received no additional discovering changed events, | 911 // The observer should have received no additional discovering changed events, |
| 958 // the success callback should have been called 2 times and the adapter should | 912 // the success callback should have been called 2 times and the adapter should |
| 959 // still be discovering. | 913 // still be discovering. |
| 960 EXPECT_EQ(1, observer.discovering_changed_count_); | 914 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 961 EXPECT_EQ(5, callback_count_); | 915 EXPECT_EQ(5, callback_count_); |
| 962 EXPECT_EQ(0, error_callback_count_); | 916 EXPECT_EQ(0, error_callback_count_); |
| 963 EXPECT_TRUE(observer.last_discovering_); | 917 EXPECT_TRUE(observer.last_discovering_); |
| 964 EXPECT_TRUE(adapter_->IsDiscovering()); | 918 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 965 EXPECT_TRUE(adapter_->IsDiscovering()); | 919 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 966 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 920 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 967 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); | 921 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); |
| 968 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); | 922 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); |
| 969 | 923 |
| 970 // Request device discovery 3 times. | 924 // Request device discovery 3 times. |
| 971 for (int i = 0; i < 3; i++) { | 925 for (int i = 0; i < 3; i++) { |
| 972 adapter_->StartDiscoverySession( | 926 adapter_->StartDiscoverySession( |
| 973 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 927 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 974 base::Unretained(this)), | 928 base::Unretained(this)), |
| 975 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 929 GetErrorCallback()); |
| 976 base::Unretained(this))); | |
| 977 } | 930 } |
| 978 | 931 |
| 979 // The observer should have received no additional discovering changed events, | 932 // The observer should have received no additional discovering changed events, |
| 980 // the success callback should have been called 3 times and the adapter should | 933 // the success callback should have been called 3 times and the adapter should |
| 981 // still be discovering. | 934 // still be discovering. |
| 982 EXPECT_EQ(1, observer.discovering_changed_count_); | 935 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 983 EXPECT_EQ(8, callback_count_); | 936 EXPECT_EQ(8, callback_count_); |
| 984 EXPECT_EQ(0, error_callback_count_); | 937 EXPECT_EQ(0, error_callback_count_); |
| 985 EXPECT_TRUE(observer.last_discovering_); | 938 EXPECT_TRUE(observer.last_discovering_); |
| 986 EXPECT_TRUE(adapter_->IsDiscovering()); | 939 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 987 ASSERT_EQ((size_t)6, discovery_sessions_.size()); | 940 ASSERT_EQ((size_t)6, discovery_sessions_.size()); |
| 988 | 941 |
| 989 // Request to stop discovery 4 times. | 942 // Request to stop discovery 4 times. |
| 990 for (int i = 2; i < 6; i++) { | 943 for (int i = 2; i < 6; i++) { |
| 991 discovery_sessions_[i]->Stop( | 944 discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback()); |
| 992 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 993 base::Unretained(this)), | |
| 994 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 995 base::Unretained(this))); | |
| 996 } | 945 } |
| 997 // Run only once, as there should have been one D-Bus call. | 946 // Run only once, as there should have been one D-Bus call. |
| 998 message_loop_.Run(); | 947 message_loop_.Run(); |
| 999 | 948 |
| 1000 // The observer should have received the discovering changed event exactly | 949 // The observer should have received the discovering changed event exactly |
| 1001 // once, the success callback should have been called 4 times and the adapter | 950 // once, the success callback should have been called 4 times and the adapter |
| 1002 // should no longer be discovering. | 951 // should no longer be discovering. |
| 1003 EXPECT_EQ(2, observer.discovering_changed_count_); | 952 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1004 EXPECT_EQ(12, callback_count_); | 953 EXPECT_EQ(12, callback_count_); |
| 1005 EXPECT_EQ(0, error_callback_count_); | 954 EXPECT_EQ(0, error_callback_count_); |
| 1006 EXPECT_FALSE(observer.last_discovering_); | 955 EXPECT_FALSE(observer.last_discovering_); |
| 1007 EXPECT_FALSE(adapter_->IsDiscovering()); | 956 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1008 | 957 |
| 1009 // All discovery sessions should be inactive. | 958 // All discovery sessions should be inactive. |
| 1010 for (int i = 0; i < 6; i++) | 959 for (int i = 0; i < 6; i++) |
| 1011 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); | 960 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); |
| 1012 | 961 |
| 1013 // Request to stop discovery on of the inactive sessions. | 962 // Request to stop discovery on of the inactive sessions. |
| 1014 discovery_sessions_[0]->Stop( | 963 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| 1015 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1016 base::Unretained(this)), | |
| 1017 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1018 base::Unretained(this))); | |
| 1019 | 964 |
| 1020 // The call should have failed. | 965 // The call should have failed. |
| 1021 EXPECT_EQ(2, observer.discovering_changed_count_); | 966 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1022 EXPECT_EQ(12, callback_count_); | 967 EXPECT_EQ(12, callback_count_); |
| 1023 EXPECT_EQ(1, error_callback_count_); | 968 EXPECT_EQ(1, error_callback_count_); |
| 1024 EXPECT_FALSE(observer.last_discovering_); | 969 EXPECT_FALSE(observer.last_discovering_); |
| 1025 EXPECT_FALSE(adapter_->IsDiscovering()); | 970 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1026 } | 971 } |
| 1027 | 972 |
| 1028 // This unit test asserts that the reference counting logic works correctly in | 973 // This unit test asserts that the reference counting logic works correctly in |
| 1029 // the cases when the adapter gets reset and D-Bus calls are made outside of | 974 // the cases when the adapter gets reset and D-Bus calls are made outside of |
| 1030 // the BluetoothAdapter. | 975 // the BluetoothAdapter. |
| 1031 TEST_F(BluetoothChromeOSTest, | 976 TEST_F(BluetoothChromeOSTest, |
| 1032 UnexpectedChangesDuringMultipleDiscoverySessions) { | 977 UnexpectedChangesDuringMultipleDiscoverySessions) { |
| 1033 GetAdapter(); | 978 GetAdapter(); |
| 1034 adapter_->SetPowered( | 979 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 1035 true, | |
| 1036 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1037 base::Unretained(this)), | |
| 1038 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1039 base::Unretained(this))); | |
| 1040 EXPECT_EQ(1, callback_count_); | 980 EXPECT_EQ(1, callback_count_); |
| 1041 EXPECT_EQ(0, error_callback_count_); | 981 EXPECT_EQ(0, error_callback_count_); |
| 1042 EXPECT_TRUE(adapter_->IsPowered()); | 982 EXPECT_TRUE(adapter_->IsPowered()); |
| 1043 callback_count_ = 0; | 983 callback_count_ = 0; |
| 1044 | 984 |
| 1045 TestObserver observer(adapter_); | 985 TestObserver observer(adapter_); |
| 1046 | 986 |
| 1047 EXPECT_EQ(0, observer.discovering_changed_count_); | 987 EXPECT_EQ(0, observer.discovering_changed_count_); |
| 1048 EXPECT_FALSE(observer.last_discovering_); | 988 EXPECT_FALSE(observer.last_discovering_); |
| 1049 EXPECT_FALSE(adapter_->IsDiscovering()); | 989 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1050 | 990 |
| 1051 // Request device discovery 3 times. | 991 // Request device discovery 3 times. |
| 1052 for (int i = 0; i < 3; i++) { | 992 for (int i = 0; i < 3; i++) { |
| 1053 adapter_->StartDiscoverySession( | 993 adapter_->StartDiscoverySession( |
| 1054 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 994 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1055 base::Unretained(this)), | 995 base::Unretained(this)), |
| 1056 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 996 GetErrorCallback()); |
| 1057 base::Unretained(this))); | |
| 1058 } | 997 } |
| 1059 // Run only once, as there should have been one D-Bus call. | 998 // Run only once, as there should have been one D-Bus call. |
| 1060 message_loop_.Run(); | 999 message_loop_.Run(); |
| 1061 | 1000 |
| 1062 // The observer should have received the discovering changed event exactly | 1001 // The observer should have received the discovering changed event exactly |
| 1063 // once, the success callback should have been called 3 times and the adapter | 1002 // once, the success callback should have been called 3 times and the adapter |
| 1064 // should be discovering. | 1003 // should be discovering. |
| 1065 EXPECT_EQ(1, observer.discovering_changed_count_); | 1004 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1066 EXPECT_EQ(3, callback_count_); | 1005 EXPECT_EQ(3, callback_count_); |
| 1067 EXPECT_EQ(0, error_callback_count_); | 1006 EXPECT_EQ(0, error_callback_count_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1079 ASSERT_TRUE(adapter_->IsPowered()); | 1018 ASSERT_TRUE(adapter_->IsPowered()); |
| 1080 ASSERT_TRUE(adapter_->IsDiscovering()); | 1019 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 1081 | 1020 |
| 1082 // Stop device discovery behind the adapter. The adapter and the observer | 1021 // Stop device discovery behind the adapter. The adapter and the observer |
| 1083 // should be notified of the change and the reference count should be reset. | 1022 // should be notified of the change and the reference count should be reset. |
| 1084 // Even though FakeBluetoothAdapterClient does its own reference counting and | 1023 // Even though FakeBluetoothAdapterClient does its own reference counting and |
| 1085 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the | 1024 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the |
| 1086 // FakeBluetoothAdapterClient's count should be only 1 and a single call to | 1025 // FakeBluetoothAdapterClient's count should be only 1 and a single call to |
| 1087 // FakeBluetoothAdapterClient::StopDiscovery should work. | 1026 // FakeBluetoothAdapterClient::StopDiscovery should work. |
| 1088 fake_bluetooth_adapter_client_->StopDiscovery( | 1027 fake_bluetooth_adapter_client_->StopDiscovery( |
| 1089 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1028 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(), |
| 1090 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1091 base::Unretained(this)), | |
| 1092 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1029 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 1093 base::Unretained(this))); | 1030 base::Unretained(this))); |
| 1094 message_loop_.Run(); | 1031 message_loop_.Run(); |
| 1095 EXPECT_EQ(2, observer.discovering_changed_count_); | 1032 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1096 EXPECT_EQ(4, callback_count_); | 1033 EXPECT_EQ(4, callback_count_); |
| 1097 EXPECT_EQ(0, error_callback_count_); | 1034 EXPECT_EQ(0, error_callback_count_); |
| 1098 EXPECT_FALSE(observer.last_discovering_); | 1035 EXPECT_FALSE(observer.last_discovering_); |
| 1099 EXPECT_FALSE(adapter_->IsDiscovering()); | 1036 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1100 | 1037 |
| 1101 // All discovery session instances should have been updated. | 1038 // All discovery session instances should have been updated. |
| 1102 for (int i = 0; i < 3; i++) | 1039 for (int i = 0; i < 3; i++) |
| 1103 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); | 1040 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); |
| 1104 discovery_sessions_.clear(); | 1041 discovery_sessions_.clear(); |
| 1105 | 1042 |
| 1106 // It should be possible to successfully start discovery. | 1043 // It should be possible to successfully start discovery. |
| 1107 for (int i = 0; i < 2; i++) { | 1044 for (int i = 0; i < 2; i++) { |
| 1108 adapter_->StartDiscoverySession( | 1045 adapter_->StartDiscoverySession( |
| 1109 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1046 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1110 base::Unretained(this)), | 1047 base::Unretained(this)), |
| 1111 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1048 GetErrorCallback()); |
| 1112 base::Unretained(this))); | |
| 1113 } | 1049 } |
| 1114 // Run only once, as there should have been one D-Bus call. | 1050 // Run only once, as there should have been one D-Bus call. |
| 1115 message_loop_.Run(); | 1051 message_loop_.Run(); |
| 1116 EXPECT_EQ(3, observer.discovering_changed_count_); | 1052 EXPECT_EQ(3, observer.discovering_changed_count_); |
| 1117 EXPECT_EQ(6, callback_count_); | 1053 EXPECT_EQ(6, callback_count_); |
| 1118 EXPECT_EQ(0, error_callback_count_); | 1054 EXPECT_EQ(0, error_callback_count_); |
| 1119 EXPECT_TRUE(observer.last_discovering_); | 1055 EXPECT_TRUE(observer.last_discovering_); |
| 1120 EXPECT_TRUE(adapter_->IsDiscovering()); | 1056 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1121 ASSERT_EQ((size_t)2, discovery_sessions_.size()); | 1057 ASSERT_EQ((size_t)2, discovery_sessions_.size()); |
| 1122 | 1058 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1147 EXPECT_EQ(6, callback_count_); | 1083 EXPECT_EQ(6, callback_count_); |
| 1148 EXPECT_EQ(0, error_callback_count_); | 1084 EXPECT_EQ(0, error_callback_count_); |
| 1149 EXPECT_TRUE(observer.last_discovering_); | 1085 EXPECT_TRUE(observer.last_discovering_); |
| 1150 EXPECT_TRUE(adapter_->IsDiscovering()); | 1086 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1151 | 1087 |
| 1152 // Start and stop discovery. At this point, FakeBluetoothAdapterClient has | 1088 // Start and stop discovery. At this point, FakeBluetoothAdapterClient has |
| 1153 // a reference count that is equal to 1. Pretend that this was done by an | 1089 // a reference count that is equal to 1. Pretend that this was done by an |
| 1154 // application other than us. Starting and stopping discovery will succeed | 1090 // application other than us. Starting and stopping discovery will succeed |
| 1155 // but it won't cause the discovery state to change. | 1091 // but it won't cause the discovery state to change. |
| 1156 adapter_->StartDiscoverySession( | 1092 adapter_->StartDiscoverySession( |
| 1157 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1093 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1158 base::Unretained(this)), | 1094 base::Unretained(this)), |
| 1159 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1095 GetErrorCallback()); |
| 1160 base::Unretained(this))); | |
| 1161 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1096 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
| 1162 EXPECT_EQ(5, observer.discovering_changed_count_); | 1097 EXPECT_EQ(5, observer.discovering_changed_count_); |
| 1163 EXPECT_EQ(7, callback_count_); | 1098 EXPECT_EQ(7, callback_count_); |
| 1164 EXPECT_EQ(0, error_callback_count_); | 1099 EXPECT_EQ(0, error_callback_count_); |
| 1165 EXPECT_TRUE(observer.last_discovering_); | 1100 EXPECT_TRUE(observer.last_discovering_); |
| 1166 EXPECT_TRUE(adapter_->IsDiscovering()); | 1101 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1167 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1102 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 1168 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1103 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1169 | 1104 |
| 1170 discovery_sessions_[0]->Stop( | 1105 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| 1171 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1172 base::Unretained(this)), | |
| 1173 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1174 base::Unretained(this))); | |
| 1175 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1106 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
| 1176 EXPECT_EQ(5, observer.discovering_changed_count_); | 1107 EXPECT_EQ(5, observer.discovering_changed_count_); |
| 1177 EXPECT_EQ(8, callback_count_); | 1108 EXPECT_EQ(8, callback_count_); |
| 1178 EXPECT_EQ(0, error_callback_count_); | 1109 EXPECT_EQ(0, error_callback_count_); |
| 1179 EXPECT_TRUE(observer.last_discovering_); | 1110 EXPECT_TRUE(observer.last_discovering_); |
| 1180 EXPECT_TRUE(adapter_->IsDiscovering()); | 1111 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1181 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1112 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 1182 discovery_sessions_.clear(); | 1113 discovery_sessions_.clear(); |
| 1183 | 1114 |
| 1184 // Start discovery again. | 1115 // Start discovery again. |
| 1185 adapter_->StartDiscoverySession( | 1116 adapter_->StartDiscoverySession( |
| 1186 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1117 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1187 base::Unretained(this)), | 1118 base::Unretained(this)), |
| 1188 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1119 GetErrorCallback()); |
| 1189 base::Unretained(this))); | |
| 1190 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1120 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
| 1191 EXPECT_EQ(5, observer.discovering_changed_count_); | 1121 EXPECT_EQ(5, observer.discovering_changed_count_); |
| 1192 EXPECT_EQ(9, callback_count_); | 1122 EXPECT_EQ(9, callback_count_); |
| 1193 EXPECT_EQ(0, error_callback_count_); | 1123 EXPECT_EQ(0, error_callback_count_); |
| 1194 EXPECT_TRUE(observer.last_discovering_); | 1124 EXPECT_TRUE(observer.last_discovering_); |
| 1195 EXPECT_TRUE(adapter_->IsDiscovering()); | 1125 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1196 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1126 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 1197 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1127 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1198 | 1128 |
| 1199 // Stop discovery via D-Bus. The fake client's reference count will drop but | 1129 // Stop discovery via D-Bus. The fake client's reference count will drop but |
| 1200 // the discovery state won't change since our BluetoothAdapter also just | 1130 // the discovery state won't change since our BluetoothAdapter also just |
| 1201 // requested it via D-Bus. | 1131 // requested it via D-Bus. |
| 1202 fake_bluetooth_adapter_client_->StopDiscovery( | 1132 fake_bluetooth_adapter_client_->StopDiscovery( |
| 1203 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1133 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(), |
| 1204 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1205 base::Unretained(this)), | |
| 1206 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1134 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 1207 base::Unretained(this))); | 1135 base::Unretained(this))); |
| 1208 message_loop_.Run(); | 1136 message_loop_.Run(); |
| 1209 EXPECT_EQ(5, observer.discovering_changed_count_); | 1137 EXPECT_EQ(5, observer.discovering_changed_count_); |
| 1210 EXPECT_EQ(10, callback_count_); | 1138 EXPECT_EQ(10, callback_count_); |
| 1211 EXPECT_EQ(0, error_callback_count_); | 1139 EXPECT_EQ(0, error_callback_count_); |
| 1212 EXPECT_TRUE(observer.last_discovering_); | 1140 EXPECT_TRUE(observer.last_discovering_); |
| 1213 EXPECT_TRUE(adapter_->IsDiscovering()); | 1141 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1214 | 1142 |
| 1215 // Now end the discovery session. This should change the adapter's discovery | 1143 // Now end the discovery session. This should change the adapter's discovery |
| 1216 // state. | 1144 // state. |
| 1217 discovery_sessions_[0]->Stop( | 1145 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| 1218 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1219 base::Unretained(this)), | |
| 1220 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1221 base::Unretained(this))); | |
| 1222 message_loop_.Run(); | 1146 message_loop_.Run(); |
| 1223 EXPECT_EQ(6, observer.discovering_changed_count_); | 1147 EXPECT_EQ(6, observer.discovering_changed_count_); |
| 1224 EXPECT_EQ(11, callback_count_); | 1148 EXPECT_EQ(11, callback_count_); |
| 1225 EXPECT_EQ(0, error_callback_count_); | 1149 EXPECT_EQ(0, error_callback_count_); |
| 1226 EXPECT_FALSE(observer.last_discovering_); | 1150 EXPECT_FALSE(observer.last_discovering_); |
| 1227 EXPECT_FALSE(adapter_->IsDiscovering()); | 1151 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1228 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1152 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 1229 } | 1153 } |
| 1230 | 1154 |
| 1231 TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) { | 1155 TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) { |
| 1232 GetAdapter(); | 1156 GetAdapter(); |
| 1233 adapter_->SetPowered( | 1157 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 1234 true, | |
| 1235 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1236 base::Unretained(this)), | |
| 1237 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1238 base::Unretained(this))); | |
| 1239 EXPECT_EQ(1, callback_count_); | 1158 EXPECT_EQ(1, callback_count_); |
| 1240 EXPECT_EQ(0, error_callback_count_); | 1159 EXPECT_EQ(0, error_callback_count_); |
| 1241 EXPECT_TRUE(adapter_->IsPowered()); | 1160 EXPECT_TRUE(adapter_->IsPowered()); |
| 1242 callback_count_ = 0; | 1161 callback_count_ = 0; |
| 1243 | 1162 |
| 1244 TestObserver observer(adapter_); | 1163 TestObserver observer(adapter_); |
| 1245 | 1164 |
| 1246 EXPECT_EQ(0, observer.discovering_changed_count_); | 1165 EXPECT_EQ(0, observer.discovering_changed_count_); |
| 1247 EXPECT_FALSE(observer.last_discovering_); | 1166 EXPECT_FALSE(observer.last_discovering_); |
| 1248 EXPECT_FALSE(adapter_->IsDiscovering()); | 1167 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1249 | 1168 |
| 1250 // Request device discovery 3 times. | 1169 // Request device discovery 3 times. |
| 1251 for (int i = 0; i < 3; i++) { | 1170 for (int i = 0; i < 3; i++) { |
| 1252 adapter_->StartDiscoverySession( | 1171 adapter_->StartDiscoverySession( |
| 1253 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1172 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1254 base::Unretained(this)), | 1173 base::Unretained(this)), |
| 1255 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1174 GetErrorCallback()); |
| 1256 base::Unretained(this))); | |
| 1257 } | 1175 } |
| 1258 // Run only once, as there should have been one D-Bus call. | 1176 // Run only once, as there should have been one D-Bus call. |
| 1259 message_loop_.Run(); | 1177 message_loop_.Run(); |
| 1260 | 1178 |
| 1261 // The observer should have received the discovering changed event exactly | 1179 // The observer should have received the discovering changed event exactly |
| 1262 // once, the success callback should have been called 3 times and the adapter | 1180 // once, the success callback should have been called 3 times and the adapter |
| 1263 // should be discovering. | 1181 // should be discovering. |
| 1264 EXPECT_EQ(1, observer.discovering_changed_count_); | 1182 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1265 EXPECT_EQ(3, callback_count_); | 1183 EXPECT_EQ(3, callback_count_); |
| 1266 EXPECT_EQ(0, error_callback_count_); | 1184 EXPECT_EQ(0, error_callback_count_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1283 discovery_sessions_.pop_back(); | 1201 discovery_sessions_.pop_back(); |
| 1284 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1202 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 1285 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1203 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1286 EXPECT_TRUE(adapter_->IsDiscovering()); | 1204 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1287 | 1205 |
| 1288 // Stop device discovery behind the adapter. The one active discovery session | 1206 // Stop device discovery behind the adapter. The one active discovery session |
| 1289 // should become inactive, but more importantly, we shouldn't run into any | 1207 // should become inactive, but more importantly, we shouldn't run into any |
| 1290 // memory errors as the sessions that we explicitly deleted should get | 1208 // memory errors as the sessions that we explicitly deleted should get |
| 1291 // cleaned up. | 1209 // cleaned up. |
| 1292 fake_bluetooth_adapter_client_->StopDiscovery( | 1210 fake_bluetooth_adapter_client_->StopDiscovery( |
| 1293 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1211 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(), |
| 1294 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1295 base::Unretained(this)), | |
| 1296 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1212 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 1297 base::Unretained(this))); | 1213 base::Unretained(this))); |
| 1298 message_loop_.Run(); | 1214 message_loop_.Run(); |
| 1299 EXPECT_EQ(2, observer.discovering_changed_count_); | 1215 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1300 EXPECT_EQ(4, callback_count_); | 1216 EXPECT_EQ(4, callback_count_); |
| 1301 EXPECT_EQ(0, error_callback_count_); | 1217 EXPECT_EQ(0, error_callback_count_); |
| 1302 EXPECT_FALSE(observer.last_discovering_); | 1218 EXPECT_FALSE(observer.last_discovering_); |
| 1303 EXPECT_FALSE(adapter_->IsDiscovering()); | 1219 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1304 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1220 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 1305 } | 1221 } |
| 1306 | 1222 |
| 1307 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { | 1223 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { |
| 1308 GetAdapter(); | 1224 GetAdapter(); |
| 1309 | 1225 |
| 1310 adapter_->SetPowered( | 1226 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 1311 true, | |
| 1312 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1313 base::Unretained(this)), | |
| 1314 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1315 base::Unretained(this))); | |
| 1316 EXPECT_EQ(1, callback_count_); | 1227 EXPECT_EQ(1, callback_count_); |
| 1317 EXPECT_EQ(0, error_callback_count_); | 1228 EXPECT_EQ(0, error_callback_count_); |
| 1318 EXPECT_TRUE(adapter_->IsPowered()); | 1229 EXPECT_TRUE(adapter_->IsPowered()); |
| 1319 callback_count_ = 0; | 1230 callback_count_ = 0; |
| 1320 | 1231 |
| 1321 TestObserver observer(adapter_); | 1232 TestObserver observer(adapter_); |
| 1322 | 1233 |
| 1323 EXPECT_EQ(0, observer.discovering_changed_count_); | 1234 EXPECT_EQ(0, observer.discovering_changed_count_); |
| 1324 EXPECT_FALSE(observer.last_discovering_); | 1235 EXPECT_FALSE(observer.last_discovering_); |
| 1325 EXPECT_FALSE(adapter_->IsDiscovering()); | 1236 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1326 | 1237 |
| 1327 // Request to start discovery. The call should be pending. | 1238 // Request to start discovery. The call should be pending. |
| 1328 adapter_->StartDiscoverySession( | 1239 adapter_->StartDiscoverySession( |
| 1329 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1240 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1330 base::Unretained(this)), | 1241 base::Unretained(this)), |
| 1331 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1242 GetErrorCallback()); |
| 1332 base::Unretained(this))); | |
| 1333 EXPECT_EQ(0, callback_count_); | 1243 EXPECT_EQ(0, callback_count_); |
| 1334 | 1244 |
| 1335 fake_bluetooth_device_client_->EndDiscoverySimulation( | 1245 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 1336 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 1246 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
| 1337 | 1247 |
| 1338 // The underlying adapter has started discovery, but our call hasn't returned | 1248 // The underlying adapter has started discovery, but our call hasn't returned |
| 1339 // yet. | 1249 // yet. |
| 1340 EXPECT_EQ(1, observer.discovering_changed_count_); | 1250 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1341 EXPECT_TRUE(observer.last_discovering_); | 1251 EXPECT_TRUE(observer.last_discovering_); |
| 1342 EXPECT_TRUE(adapter_->IsDiscovering()); | 1252 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1343 EXPECT_TRUE(discovery_sessions_.empty()); | 1253 EXPECT_TRUE(discovery_sessions_.empty()); |
| 1344 | 1254 |
| 1345 // Request to start discovery twice. These should get queued and there should | 1255 // Request to start discovery twice. These should get queued and there should |
| 1346 // be no change in state. | 1256 // be no change in state. |
| 1347 for (int i = 0; i < 2; i++) { | 1257 for (int i = 0; i < 2; i++) { |
| 1348 adapter_->StartDiscoverySession( | 1258 adapter_->StartDiscoverySession( |
| 1349 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1259 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1350 base::Unretained(this)), | 1260 base::Unretained(this)), |
| 1351 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1261 GetErrorCallback()); |
| 1352 base::Unretained(this))); | |
| 1353 } | 1262 } |
| 1354 EXPECT_EQ(0, callback_count_); | 1263 EXPECT_EQ(0, callback_count_); |
| 1355 EXPECT_EQ(0, error_callback_count_); | 1264 EXPECT_EQ(0, error_callback_count_); |
| 1356 EXPECT_EQ(1, observer.discovering_changed_count_); | 1265 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1357 EXPECT_TRUE(observer.last_discovering_); | 1266 EXPECT_TRUE(observer.last_discovering_); |
| 1358 EXPECT_TRUE(adapter_->IsDiscovering()); | 1267 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1359 EXPECT_TRUE(discovery_sessions_.empty()); | 1268 EXPECT_TRUE(discovery_sessions_.empty()); |
| 1360 | 1269 |
| 1361 // Process the pending call. The queued calls should execute and the discovery | 1270 // Process the pending call. The queued calls should execute and the discovery |
| 1362 // session reference count should increase. | 1271 // session reference count should increase. |
| 1363 message_loop_.Run(); | 1272 message_loop_.Run(); |
| 1364 EXPECT_EQ(3, callback_count_); | 1273 EXPECT_EQ(3, callback_count_); |
| 1365 EXPECT_EQ(0, error_callback_count_); | 1274 EXPECT_EQ(0, error_callback_count_); |
| 1366 EXPECT_EQ(1, observer.discovering_changed_count_); | 1275 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1367 EXPECT_TRUE(observer.last_discovering_); | 1276 EXPECT_TRUE(observer.last_discovering_); |
| 1368 EXPECT_TRUE(adapter_->IsDiscovering()); | 1277 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1369 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1278 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 1370 | 1279 |
| 1371 // Verify the reference count by removing sessions 3 times. The last request | 1280 // Verify the reference count by removing sessions 3 times. The last request |
| 1372 // should remain pending. | 1281 // should remain pending. |
| 1373 for (int i = 0; i < 3; i++) { | 1282 for (int i = 0; i < 3; i++) { |
| 1374 discovery_sessions_[i]->Stop( | 1283 discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback()); |
| 1375 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1376 base::Unretained(this)), | |
| 1377 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1378 base::Unretained(this))); | |
| 1379 } | 1284 } |
| 1380 EXPECT_EQ(5, callback_count_); | 1285 EXPECT_EQ(5, callback_count_); |
| 1381 EXPECT_EQ(0, error_callback_count_); | 1286 EXPECT_EQ(0, error_callback_count_); |
| 1382 EXPECT_EQ(2, observer.discovering_changed_count_); | 1287 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1383 EXPECT_FALSE(observer.last_discovering_); | 1288 EXPECT_FALSE(observer.last_discovering_); |
| 1384 EXPECT_FALSE(adapter_->IsDiscovering()); | 1289 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1385 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1290 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 1386 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); | 1291 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); |
| 1387 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); | 1292 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); |
| 1388 | 1293 |
| 1389 // Request to stop the session whose call is pending should fail. | 1294 // Request to stop the session whose call is pending should fail. |
| 1390 discovery_sessions_[2]->Stop( | 1295 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback()); |
| 1391 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1392 base::Unretained(this)), | |
| 1393 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1394 base::Unretained(this))); | |
| 1395 EXPECT_EQ(5, callback_count_); | 1296 EXPECT_EQ(5, callback_count_); |
| 1396 EXPECT_EQ(1, error_callback_count_); | 1297 EXPECT_EQ(1, error_callback_count_); |
| 1397 EXPECT_EQ(2, observer.discovering_changed_count_); | 1298 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1398 EXPECT_FALSE(observer.last_discovering_); | 1299 EXPECT_FALSE(observer.last_discovering_); |
| 1399 EXPECT_FALSE(adapter_->IsDiscovering()); | 1300 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1400 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); | 1301 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); |
| 1401 | 1302 |
| 1402 // Request to start should get queued. | 1303 // Request to start should get queued. |
| 1403 adapter_->StartDiscoverySession( | 1304 adapter_->StartDiscoverySession( |
| 1404 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1305 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1405 base::Unretained(this)), | 1306 base::Unretained(this)), |
| 1406 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1307 GetErrorCallback()); |
| 1407 base::Unretained(this))); | |
| 1408 EXPECT_EQ(5, callback_count_); | 1308 EXPECT_EQ(5, callback_count_); |
| 1409 EXPECT_EQ(1, error_callback_count_); | 1309 EXPECT_EQ(1, error_callback_count_); |
| 1410 EXPECT_EQ(2, observer.discovering_changed_count_); | 1310 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1411 EXPECT_FALSE(observer.last_discovering_); | 1311 EXPECT_FALSE(observer.last_discovering_); |
| 1412 EXPECT_FALSE(adapter_->IsDiscovering()); | 1312 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1413 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1313 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 1414 | 1314 |
| 1415 // Run the pending request. | 1315 // Run the pending request. |
| 1416 message_loop_.Run(); | 1316 message_loop_.Run(); |
| 1417 EXPECT_EQ(6, callback_count_); | 1317 EXPECT_EQ(6, callback_count_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1430 EXPECT_EQ(3, observer.discovering_changed_count_); | 1330 EXPECT_EQ(3, observer.discovering_changed_count_); |
| 1431 EXPECT_TRUE(observer.last_discovering_); | 1331 EXPECT_TRUE(observer.last_discovering_); |
| 1432 EXPECT_TRUE(adapter_->IsDiscovering()); | 1332 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1433 ASSERT_EQ((size_t)4, discovery_sessions_.size()); | 1333 ASSERT_EQ((size_t)4, discovery_sessions_.size()); |
| 1434 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); | 1334 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); |
| 1435 } | 1335 } |
| 1436 | 1336 |
| 1437 TEST_F(BluetoothChromeOSTest, StartDiscoverySession) { | 1337 TEST_F(BluetoothChromeOSTest, StartDiscoverySession) { |
| 1438 GetAdapter(); | 1338 GetAdapter(); |
| 1439 | 1339 |
| 1440 adapter_->SetPowered( | 1340 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 1441 true, | |
| 1442 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1443 base::Unretained(this)), | |
| 1444 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1445 base::Unretained(this))); | |
| 1446 EXPECT_EQ(1, callback_count_); | 1341 EXPECT_EQ(1, callback_count_); |
| 1447 EXPECT_EQ(0, error_callback_count_); | 1342 EXPECT_EQ(0, error_callback_count_); |
| 1448 EXPECT_TRUE(adapter_->IsPowered()); | 1343 EXPECT_TRUE(adapter_->IsPowered()); |
| 1449 callback_count_ = 0; | 1344 callback_count_ = 0; |
| 1450 | 1345 |
| 1451 TestObserver observer(adapter_); | 1346 TestObserver observer(adapter_); |
| 1452 | 1347 |
| 1453 EXPECT_EQ(0, observer.discovering_changed_count_); | 1348 EXPECT_EQ(0, observer.discovering_changed_count_); |
| 1454 EXPECT_FALSE(observer.last_discovering_); | 1349 EXPECT_FALSE(observer.last_discovering_); |
| 1455 EXPECT_FALSE(adapter_->IsDiscovering()); | 1350 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1456 EXPECT_TRUE(discovery_sessions_.empty()); | 1351 EXPECT_TRUE(discovery_sessions_.empty()); |
| 1457 | 1352 |
| 1458 // Request a new discovery session. | 1353 // Request a new discovery session. |
| 1459 adapter_->StartDiscoverySession( | 1354 adapter_->StartDiscoverySession( |
| 1460 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1355 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1461 base::Unretained(this)), | 1356 base::Unretained(this)), |
| 1462 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1357 GetErrorCallback()); |
| 1463 base::Unretained(this))); | |
| 1464 message_loop_.Run(); | 1358 message_loop_.Run(); |
| 1465 EXPECT_EQ(1, observer.discovering_changed_count_); | 1359 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1466 EXPECT_EQ(1, callback_count_); | 1360 EXPECT_EQ(1, callback_count_); |
| 1467 EXPECT_EQ(0, error_callback_count_); | 1361 EXPECT_EQ(0, error_callback_count_); |
| 1468 EXPECT_TRUE(observer.last_discovering_); | 1362 EXPECT_TRUE(observer.last_discovering_); |
| 1469 EXPECT_TRUE(adapter_->IsDiscovering()); | 1363 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1470 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1364 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 1471 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1365 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1472 | 1366 |
| 1473 // Start another session. A new one should be returned in the callback, which | 1367 // Start another session. A new one should be returned in the callback, which |
| 1474 // in turn will destroy the previous session. Adapter should still be | 1368 // in turn will destroy the previous session. Adapter should still be |
| 1475 // discovering and the reference count should be 1. | 1369 // discovering and the reference count should be 1. |
| 1476 adapter_->StartDiscoverySession( | 1370 adapter_->StartDiscoverySession( |
| 1477 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1371 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1478 base::Unretained(this)), | 1372 base::Unretained(this)), |
| 1479 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1373 GetErrorCallback()); |
| 1480 base::Unretained(this))); | |
| 1481 message_loop_.Run(); | 1374 message_loop_.Run(); |
| 1482 EXPECT_EQ(1, observer.discovering_changed_count_); | 1375 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1483 EXPECT_EQ(2, callback_count_); | 1376 EXPECT_EQ(2, callback_count_); |
| 1484 EXPECT_EQ(0, error_callback_count_); | 1377 EXPECT_EQ(0, error_callback_count_); |
| 1485 EXPECT_TRUE(observer.last_discovering_); | 1378 EXPECT_TRUE(observer.last_discovering_); |
| 1486 EXPECT_TRUE(adapter_->IsDiscovering()); | 1379 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1487 ASSERT_EQ((size_t)2, discovery_sessions_.size()); | 1380 ASSERT_EQ((size_t)2, discovery_sessions_.size()); |
| 1488 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1381 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1489 | 1382 |
| 1490 // Request a new session. | 1383 // Request a new session. |
| 1491 adapter_->StartDiscoverySession( | 1384 adapter_->StartDiscoverySession( |
| 1492 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1385 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1493 base::Unretained(this)), | 1386 base::Unretained(this)), |
| 1494 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1387 GetErrorCallback()); |
| 1495 base::Unretained(this))); | |
| 1496 message_loop_.Run(); | 1388 message_loop_.Run(); |
| 1497 EXPECT_EQ(1, observer.discovering_changed_count_); | 1389 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1498 EXPECT_EQ(3, callback_count_); | 1390 EXPECT_EQ(3, callback_count_); |
| 1499 EXPECT_EQ(0, error_callback_count_); | 1391 EXPECT_EQ(0, error_callback_count_); |
| 1500 EXPECT_TRUE(observer.last_discovering_); | 1392 EXPECT_TRUE(observer.last_discovering_); |
| 1501 EXPECT_TRUE(adapter_->IsDiscovering()); | 1393 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1502 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1394 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 1503 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); | 1395 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); |
| 1504 EXPECT_NE(discovery_sessions_[0], discovery_sessions_[1]); | 1396 EXPECT_NE(discovery_sessions_[0], discovery_sessions_[1]); |
| 1505 | 1397 |
| 1506 // Stop the previous discovery session. The session should end but discovery | 1398 // Stop the previous discovery session. The session should end but discovery |
| 1507 // should continue. | 1399 // should continue. |
| 1508 discovery_sessions_[0]->Stop( | 1400 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| 1509 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1510 base::Unretained(this)), | |
| 1511 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1512 base::Unretained(this))); | |
| 1513 message_loop_.Run(); | 1401 message_loop_.Run(); |
| 1514 EXPECT_EQ(1, observer.discovering_changed_count_); | 1402 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1515 EXPECT_EQ(4, callback_count_); | 1403 EXPECT_EQ(4, callback_count_); |
| 1516 EXPECT_EQ(0, error_callback_count_); | 1404 EXPECT_EQ(0, error_callback_count_); |
| 1517 EXPECT_TRUE(observer.last_discovering_); | 1405 EXPECT_TRUE(observer.last_discovering_); |
| 1518 EXPECT_TRUE(adapter_->IsDiscovering()); | 1406 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1519 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1407 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 1520 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1408 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 1521 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); | 1409 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); |
| 1522 | 1410 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 ASSERT_EQ(2U, devices.size()); | 1556 ASSERT_EQ(2U, devices.size()); |
| 1669 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 1557 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 1670 devices[0]->GetAddress()); | 1558 devices[0]->GetAddress()); |
| 1671 | 1559 |
| 1672 std::string address = devices[0]->GetAddress(); | 1560 std::string address = devices[0]->GetAddress(); |
| 1673 | 1561 |
| 1674 // Install an observer; expect the DeviceRemoved method to be called | 1562 // Install an observer; expect the DeviceRemoved method to be called |
| 1675 // with the device we remove. | 1563 // with the device we remove. |
| 1676 TestObserver observer(adapter_); | 1564 TestObserver observer(adapter_); |
| 1677 | 1565 |
| 1678 devices[0]->Forget( | 1566 devices[0]->Forget(GetErrorCallback()); |
| 1679 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1680 base::Unretained(this))); | |
| 1681 EXPECT_EQ(0, error_callback_count_); | 1567 EXPECT_EQ(0, error_callback_count_); |
| 1682 | 1568 |
| 1683 EXPECT_EQ(1, observer.device_removed_count_); | 1569 EXPECT_EQ(1, observer.device_removed_count_); |
| 1684 EXPECT_EQ(address, observer.last_device_address_); | 1570 EXPECT_EQ(address, observer.last_device_address_); |
| 1685 | 1571 |
| 1686 // GetDevices shouldn't return the device either. | 1572 // GetDevices shouldn't return the device either. |
| 1687 devices = adapter_->GetDevices(); | 1573 devices = adapter_->GetDevices(); |
| 1688 ASSERT_EQ(1U, devices.size()); | 1574 ASSERT_EQ(1U, devices.size()); |
| 1689 } | 1575 } |
| 1690 | 1576 |
| 1691 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { | 1577 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { |
| 1692 GetAdapter(); | 1578 GetAdapter(); |
| 1693 DiscoverDevices(); | 1579 DiscoverDevices(); |
| 1694 | 1580 |
| 1695 BluetoothDevice* device = adapter_->GetDevice( | 1581 BluetoothDevice* device = adapter_->GetDevice( |
| 1696 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 1582 FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 1697 ASSERT_TRUE(device != NULL); | 1583 ASSERT_TRUE(device != NULL); |
| 1698 ASSERT_FALSE(device->IsPaired()); | 1584 ASSERT_FALSE(device->IsPaired()); |
| 1699 | 1585 |
| 1700 // Connect the device so it becomes trusted and remembered. | 1586 // Connect the device so it becomes trusted and remembered. |
| 1701 device->Connect( | 1587 device->Connect(NULL, GetCallback(), |
| 1702 NULL, | 1588 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1703 base::Bind(&BluetoothChromeOSTest::Callback, | 1589 base::Unretained(this))); |
| 1704 base::Unretained(this)), | |
| 1705 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1706 base::Unretained(this))); | |
| 1707 | 1590 |
| 1708 ASSERT_EQ(1, callback_count_); | 1591 ASSERT_EQ(1, callback_count_); |
| 1709 ASSERT_EQ(0, error_callback_count_); | 1592 ASSERT_EQ(0, error_callback_count_); |
| 1710 callback_count_ = 0; | 1593 callback_count_ = 0; |
| 1711 | 1594 |
| 1712 ASSERT_TRUE(device->IsConnected()); | 1595 ASSERT_TRUE(device->IsConnected()); |
| 1713 ASSERT_FALSE(device->IsConnecting()); | 1596 ASSERT_FALSE(device->IsConnecting()); |
| 1714 | 1597 |
| 1715 // Make sure the trusted property has been set to true. | 1598 // Make sure the trusted property has been set to true. |
| 1716 FakeBluetoothDeviceClient::Properties* properties = | 1599 FakeBluetoothDeviceClient::Properties* properties = |
| 1717 fake_bluetooth_device_client_->GetProperties( | 1600 fake_bluetooth_device_client_->GetProperties( |
| 1718 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); | 1601 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); |
| 1719 ASSERT_TRUE(properties->trusted.value()); | 1602 ASSERT_TRUE(properties->trusted.value()); |
| 1720 | 1603 |
| 1721 // Install an observer; expect the DeviceRemoved method to be called | 1604 // Install an observer; expect the DeviceRemoved method to be called |
| 1722 // with the device we remove. | 1605 // with the device we remove. |
| 1723 TestObserver observer(adapter_); | 1606 TestObserver observer(adapter_); |
| 1724 | 1607 |
| 1725 device->Forget( | 1608 device->Forget(GetErrorCallback()); |
| 1726 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1727 base::Unretained(this))); | |
| 1728 EXPECT_EQ(0, error_callback_count_); | 1609 EXPECT_EQ(0, error_callback_count_); |
| 1729 | 1610 |
| 1730 EXPECT_EQ(1, observer.device_removed_count_); | 1611 EXPECT_EQ(1, observer.device_removed_count_); |
| 1731 EXPECT_EQ(FakeBluetoothDeviceClient::kConnectUnpairableAddress, | 1612 EXPECT_EQ(FakeBluetoothDeviceClient::kConnectUnpairableAddress, |
| 1732 observer.last_device_address_); | 1613 observer.last_device_address_); |
| 1733 | 1614 |
| 1734 // GetDevices shouldn't return the device either. | 1615 // GetDevices shouldn't return the device either. |
| 1735 device = adapter_->GetDevice( | 1616 device = adapter_->GetDevice( |
| 1736 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 1617 FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 1737 EXPECT_FALSE(device != NULL); | 1618 EXPECT_FALSE(device != NULL); |
| 1738 } | 1619 } |
| 1739 | 1620 |
| 1740 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { | 1621 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { |
| 1741 GetAdapter(); | 1622 GetAdapter(); |
| 1742 | 1623 |
| 1743 BluetoothDevice* device = adapter_->GetDevice( | 1624 BluetoothDevice* device = adapter_->GetDevice( |
| 1744 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 1625 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 1745 ASSERT_TRUE(device != NULL); | 1626 ASSERT_TRUE(device != NULL); |
| 1746 ASSERT_TRUE(device->IsPaired()); | 1627 ASSERT_TRUE(device->IsPaired()); |
| 1747 | 1628 |
| 1748 TestObserver observer(adapter_); | 1629 TestObserver observer(adapter_); |
| 1749 | 1630 |
| 1750 // Connect without a pairing delegate; since the device is already Paired | 1631 // Connect without a pairing delegate; since the device is already Paired |
| 1751 // this should succeed and the device should become connected. | 1632 // this should succeed and the device should become connected. |
| 1752 device->Connect( | 1633 device->Connect(NULL, GetCallback(), |
| 1753 NULL, | 1634 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1754 base::Bind(&BluetoothChromeOSTest::Callback, | 1635 base::Unretained(this))); |
| 1755 base::Unretained(this)), | |
| 1756 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1757 base::Unretained(this))); | |
| 1758 | 1636 |
| 1759 EXPECT_EQ(1, callback_count_); | 1637 EXPECT_EQ(1, callback_count_); |
| 1760 EXPECT_EQ(0, error_callback_count_); | 1638 EXPECT_EQ(0, error_callback_count_); |
| 1761 | 1639 |
| 1762 // Two changes for connecting, one for connected and one for for trusted | 1640 // Two changes for connecting, one for connected and one for for trusted |
| 1763 // after connecting. | 1641 // after connecting. |
| 1764 EXPECT_EQ(4, observer.device_changed_count_); | 1642 EXPECT_EQ(4, observer.device_changed_count_); |
| 1765 EXPECT_EQ(device, observer.last_device_); | 1643 EXPECT_EQ(device, observer.last_device_); |
| 1766 | 1644 |
| 1767 EXPECT_TRUE(device->IsConnected()); | 1645 EXPECT_TRUE(device->IsConnected()); |
| 1768 EXPECT_FALSE(device->IsConnecting()); | 1646 EXPECT_FALSE(device->IsConnecting()); |
| 1769 } | 1647 } |
| 1770 | 1648 |
| 1771 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { | 1649 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { |
| 1772 GetAdapter(); | 1650 GetAdapter(); |
| 1773 DiscoverDevices(); | 1651 DiscoverDevices(); |
| 1774 | 1652 |
| 1775 BluetoothDevice* device = adapter_->GetDevice( | 1653 BluetoothDevice* device = adapter_->GetDevice( |
| 1776 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 1654 FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 1777 ASSERT_TRUE(device != NULL); | 1655 ASSERT_TRUE(device != NULL); |
| 1778 ASSERT_FALSE(device->IsPaired()); | 1656 ASSERT_FALSE(device->IsPaired()); |
| 1779 | 1657 |
| 1780 TestObserver observer(adapter_); | 1658 TestObserver observer(adapter_); |
| 1781 | 1659 |
| 1782 // Connect without a pairing delegate; since the device does not require | 1660 // Connect without a pairing delegate; since the device does not require |
| 1783 // pairing, this should succeed and the device should become connected. | 1661 // pairing, this should succeed and the device should become connected. |
| 1784 device->Connect( | 1662 device->Connect(NULL, GetCallback(), |
| 1785 NULL, | 1663 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1786 base::Bind(&BluetoothChromeOSTest::Callback, | 1664 base::Unretained(this))); |
| 1787 base::Unretained(this)), | |
| 1788 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1789 base::Unretained(this))); | |
| 1790 | 1665 |
| 1791 EXPECT_EQ(1, callback_count_); | 1666 EXPECT_EQ(1, callback_count_); |
| 1792 EXPECT_EQ(0, error_callback_count_); | 1667 EXPECT_EQ(0, error_callback_count_); |
| 1793 | 1668 |
| 1794 // Two changes for connecting, one for connected, one for for trusted after | 1669 // Two changes for connecting, one for connected, one for for trusted after |
| 1795 // connection, and one for the reconnect mode (IsConnectable). | 1670 // connection, and one for the reconnect mode (IsConnectable). |
| 1796 EXPECT_EQ(5, observer.device_changed_count_); | 1671 EXPECT_EQ(5, observer.device_changed_count_); |
| 1797 EXPECT_EQ(device, observer.last_device_); | 1672 EXPECT_EQ(device, observer.last_device_); |
| 1798 | 1673 |
| 1799 EXPECT_TRUE(device->IsConnected()); | 1674 EXPECT_TRUE(device->IsConnected()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1813 } | 1688 } |
| 1814 | 1689 |
| 1815 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { | 1690 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { |
| 1816 GetAdapter(); | 1691 GetAdapter(); |
| 1817 | 1692 |
| 1818 BluetoothDevice* device = adapter_->GetDevice( | 1693 BluetoothDevice* device = adapter_->GetDevice( |
| 1819 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 1694 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 1820 ASSERT_TRUE(device != NULL); | 1695 ASSERT_TRUE(device != NULL); |
| 1821 ASSERT_TRUE(device->IsPaired()); | 1696 ASSERT_TRUE(device->IsPaired()); |
| 1822 | 1697 |
| 1823 device->Connect( | 1698 device->Connect(NULL, GetCallback(), |
| 1824 NULL, | 1699 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1825 base::Bind(&BluetoothChromeOSTest::Callback, | 1700 base::Unretained(this))); |
| 1826 base::Unretained(this)), | |
| 1827 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1828 base::Unretained(this))); | |
| 1829 | 1701 |
| 1830 ASSERT_EQ(1, callback_count_); | 1702 ASSERT_EQ(1, callback_count_); |
| 1831 ASSERT_EQ(0, error_callback_count_); | 1703 ASSERT_EQ(0, error_callback_count_); |
| 1832 callback_count_ = 0; | 1704 callback_count_ = 0; |
| 1833 | 1705 |
| 1834 ASSERT_TRUE(device->IsConnected()); | 1706 ASSERT_TRUE(device->IsConnected()); |
| 1835 | 1707 |
| 1836 // Connect again; since the device is already Connected, this shouldn't do | 1708 // Connect again; since the device is already Connected, this shouldn't do |
| 1837 // anything to initiate the connection. | 1709 // anything to initiate the connection. |
| 1838 TestObserver observer(adapter_); | 1710 TestObserver observer(adapter_); |
| 1839 | 1711 |
| 1840 device->Connect( | 1712 device->Connect(NULL, GetCallback(), |
| 1841 NULL, | 1713 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1842 base::Bind(&BluetoothChromeOSTest::Callback, | 1714 base::Unretained(this))); |
| 1843 base::Unretained(this)), | |
| 1844 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1845 base::Unretained(this))); | |
| 1846 | 1715 |
| 1847 EXPECT_EQ(1, callback_count_); | 1716 EXPECT_EQ(1, callback_count_); |
| 1848 EXPECT_EQ(0, error_callback_count_); | 1717 EXPECT_EQ(0, error_callback_count_); |
| 1849 | 1718 |
| 1850 // The observer will be called because Connecting will toggle true and false, | 1719 // The observer will be called because Connecting will toggle true and false, |
| 1851 // and the trusted property will be updated to true. | 1720 // and the trusted property will be updated to true. |
| 1852 EXPECT_EQ(3, observer.device_changed_count_); | 1721 EXPECT_EQ(3, observer.device_changed_count_); |
| 1853 | 1722 |
| 1854 EXPECT_TRUE(device->IsConnected()); | 1723 EXPECT_TRUE(device->IsConnected()); |
| 1855 EXPECT_FALSE(device->IsConnecting()); | 1724 EXPECT_FALSE(device->IsConnecting()); |
| 1856 } | 1725 } |
| 1857 | 1726 |
| 1858 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { | 1727 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { |
| 1859 GetAdapter(); | 1728 GetAdapter(); |
| 1860 DiscoverDevices(); | 1729 DiscoverDevices(); |
| 1861 | 1730 |
| 1862 BluetoothDevice* device = adapter_->GetDevice( | 1731 BluetoothDevice* device = adapter_->GetDevice( |
| 1863 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 1732 FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 1864 ASSERT_TRUE(device != NULL); | 1733 ASSERT_TRUE(device != NULL); |
| 1865 ASSERT_FALSE(device->IsPaired()); | 1734 ASSERT_FALSE(device->IsPaired()); |
| 1866 | 1735 |
| 1867 TestObserver observer(adapter_); | 1736 TestObserver observer(adapter_); |
| 1868 | 1737 |
| 1869 // Connect without a pairing delegate; since the device requires pairing, | 1738 // Connect without a pairing delegate; since the device requires pairing, |
| 1870 // this should fail with an error. | 1739 // this should fail with an error. |
| 1871 device->Connect( | 1740 device->Connect(NULL, GetCallback(), |
| 1872 NULL, | 1741 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1873 base::Bind(&BluetoothChromeOSTest::Callback, | 1742 base::Unretained(this))); |
| 1874 base::Unretained(this)), | |
| 1875 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1876 base::Unretained(this))); | |
| 1877 | 1743 |
| 1878 EXPECT_EQ(0, callback_count_); | 1744 EXPECT_EQ(0, callback_count_); |
| 1879 EXPECT_EQ(1, error_callback_count_); | 1745 EXPECT_EQ(1, error_callback_count_); |
| 1880 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 1746 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
| 1881 | 1747 |
| 1882 EXPECT_EQ(2, observer.device_changed_count_); | 1748 EXPECT_EQ(2, observer.device_changed_count_); |
| 1883 | 1749 |
| 1884 EXPECT_FALSE(device->IsConnected()); | 1750 EXPECT_FALSE(device->IsConnected()); |
| 1885 EXPECT_FALSE(device->IsConnecting()); | 1751 EXPECT_FALSE(device->IsConnecting()); |
| 1886 } | 1752 } |
| 1887 | 1753 |
| 1888 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { | 1754 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { |
| 1889 GetAdapter(); | 1755 GetAdapter(); |
| 1890 | 1756 |
| 1891 BluetoothDevice* device = adapter_->GetDevice( | 1757 BluetoothDevice* device = adapter_->GetDevice( |
| 1892 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 1758 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 1893 ASSERT_TRUE(device != NULL); | 1759 ASSERT_TRUE(device != NULL); |
| 1894 ASSERT_TRUE(device->IsPaired()); | 1760 ASSERT_TRUE(device->IsPaired()); |
| 1895 | 1761 |
| 1896 device->Connect( | 1762 device->Connect(NULL, GetCallback(), |
| 1897 NULL, | 1763 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1898 base::Bind(&BluetoothChromeOSTest::Callback, | 1764 base::Unretained(this))); |
| 1899 base::Unretained(this)), | |
| 1900 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1901 base::Unretained(this))); | |
| 1902 | 1765 |
| 1903 ASSERT_EQ(1, callback_count_); | 1766 ASSERT_EQ(1, callback_count_); |
| 1904 ASSERT_EQ(0, error_callback_count_); | 1767 ASSERT_EQ(0, error_callback_count_); |
| 1905 callback_count_ = 0; | 1768 callback_count_ = 0; |
| 1906 | 1769 |
| 1907 ASSERT_TRUE(device->IsConnected()); | 1770 ASSERT_TRUE(device->IsConnected()); |
| 1908 ASSERT_FALSE(device->IsConnecting()); | 1771 ASSERT_FALSE(device->IsConnecting()); |
| 1909 | 1772 |
| 1910 // Disconnect the device, we should see the observer method fire and the | 1773 // Disconnect the device, we should see the observer method fire and the |
| 1911 // device get dropped. | 1774 // device get dropped. |
| 1912 TestObserver observer(adapter_); | 1775 TestObserver observer(adapter_); |
| 1913 | 1776 |
| 1914 device->Disconnect( | 1777 device->Disconnect(GetCallback(), GetErrorCallback()); |
| 1915 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1916 base::Unretained(this)), | |
| 1917 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1918 base::Unretained(this))); | |
| 1919 | 1778 |
| 1920 EXPECT_EQ(1, callback_count_); | 1779 EXPECT_EQ(1, callback_count_); |
| 1921 EXPECT_EQ(0, error_callback_count_); | 1780 EXPECT_EQ(0, error_callback_count_); |
| 1922 | 1781 |
| 1923 EXPECT_EQ(1, observer.device_changed_count_); | 1782 EXPECT_EQ(1, observer.device_changed_count_); |
| 1924 EXPECT_EQ(device, observer.last_device_); | 1783 EXPECT_EQ(device, observer.last_device_); |
| 1925 | 1784 |
| 1926 EXPECT_FALSE(device->IsConnected()); | 1785 EXPECT_FALSE(device->IsConnected()); |
| 1927 } | 1786 } |
| 1928 | 1787 |
| 1929 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { | 1788 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { |
| 1930 GetAdapter(); | 1789 GetAdapter(); |
| 1931 | 1790 |
| 1932 BluetoothDevice* device = adapter_->GetDevice( | 1791 BluetoothDevice* device = adapter_->GetDevice( |
| 1933 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 1792 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 1934 ASSERT_TRUE(device != NULL); | 1793 ASSERT_TRUE(device != NULL); |
| 1935 ASSERT_TRUE(device->IsPaired()); | 1794 ASSERT_TRUE(device->IsPaired()); |
| 1936 ASSERT_FALSE(device->IsConnected()); | 1795 ASSERT_FALSE(device->IsConnected()); |
| 1937 | 1796 |
| 1938 // Disconnect the device, we should see the observer method fire and the | 1797 // Disconnect the device, we should see the observer method fire and the |
| 1939 // device get dropped. | 1798 // device get dropped. |
| 1940 TestObserver observer(adapter_); | 1799 TestObserver observer(adapter_); |
| 1941 | 1800 |
| 1942 device->Disconnect( | 1801 device->Disconnect(GetCallback(), GetErrorCallback()); |
| 1943 base::Bind(&BluetoothChromeOSTest::Callback, | |
| 1944 base::Unretained(this)), | |
| 1945 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 1946 base::Unretained(this))); | |
| 1947 | 1802 |
| 1948 EXPECT_EQ(0, callback_count_); | 1803 EXPECT_EQ(0, callback_count_); |
| 1949 EXPECT_EQ(1, error_callback_count_); | 1804 EXPECT_EQ(1, error_callback_count_); |
| 1950 | 1805 |
| 1951 EXPECT_EQ(0, observer.device_changed_count_); | 1806 EXPECT_EQ(0, observer.device_changed_count_); |
| 1952 | 1807 |
| 1953 EXPECT_FALSE(device->IsConnected()); | 1808 EXPECT_FALSE(device->IsConnected()); |
| 1954 } | 1809 } |
| 1955 | 1810 |
| 1956 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { | 1811 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { |
| 1957 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1812 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 1958 | 1813 |
| 1959 GetAdapter(); | 1814 GetAdapter(); |
| 1960 DiscoverDevices(); | 1815 DiscoverDevices(); |
| 1961 | 1816 |
| 1962 // The Legacy Autopair device requires no PIN or Passkey to pair because | 1817 // The Legacy Autopair device requires no PIN or Passkey to pair because |
| 1963 // the daemon provides 0000 to the device for us. | 1818 // the daemon provides 0000 to the device for us. |
| 1964 BluetoothDevice* device = adapter_->GetDevice( | 1819 BluetoothDevice* device = adapter_->GetDevice( |
| 1965 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 1820 FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 1966 ASSERT_TRUE(device != NULL); | 1821 ASSERT_TRUE(device != NULL); |
| 1967 ASSERT_FALSE(device->IsPaired()); | 1822 ASSERT_FALSE(device->IsPaired()); |
| 1968 | 1823 |
| 1969 TestObserver observer(adapter_); | 1824 TestObserver observer(adapter_); |
| 1970 | 1825 |
| 1971 TestPairingDelegate pairing_delegate; | 1826 TestPairingDelegate pairing_delegate; |
| 1972 device->Connect( | 1827 device->Connect(&pairing_delegate, GetCallback(), |
| 1973 &pairing_delegate, | 1828 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 1974 base::Bind(&BluetoothChromeOSTest::Callback, | 1829 base::Unretained(this))); |
| 1975 base::Unretained(this)), | |
| 1976 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 1977 base::Unretained(this))); | |
| 1978 | 1830 |
| 1979 EXPECT_EQ(0, pairing_delegate.call_count_); | 1831 EXPECT_EQ(0, pairing_delegate.call_count_); |
| 1980 EXPECT_TRUE(device->IsConnecting()); | 1832 EXPECT_TRUE(device->IsConnecting()); |
| 1981 | 1833 |
| 1982 message_loop_.Run(); | 1834 message_loop_.Run(); |
| 1983 | 1835 |
| 1984 EXPECT_EQ(1, callback_count_); | 1836 EXPECT_EQ(1, callback_count_); |
| 1985 EXPECT_EQ(0, error_callback_count_); | 1837 EXPECT_EQ(0, error_callback_count_); |
| 1986 | 1838 |
| 1987 // Two changes for connecting, one change for connected, one for paired, | 1839 // Two changes for connecting, one change for connected, one for paired, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2016 | 1868 |
| 2017 // Requires that we display a randomly generated PIN on the screen. | 1869 // Requires that we display a randomly generated PIN on the screen. |
| 2018 BluetoothDevice* device = adapter_->GetDevice( | 1870 BluetoothDevice* device = adapter_->GetDevice( |
| 2019 FakeBluetoothDeviceClient::kDisplayPinCodeAddress); | 1871 FakeBluetoothDeviceClient::kDisplayPinCodeAddress); |
| 2020 ASSERT_TRUE(device != NULL); | 1872 ASSERT_TRUE(device != NULL); |
| 2021 ASSERT_FALSE(device->IsPaired()); | 1873 ASSERT_FALSE(device->IsPaired()); |
| 2022 | 1874 |
| 2023 TestObserver observer(adapter_); | 1875 TestObserver observer(adapter_); |
| 2024 | 1876 |
| 2025 TestPairingDelegate pairing_delegate; | 1877 TestPairingDelegate pairing_delegate; |
| 2026 device->Connect( | 1878 device->Connect(&pairing_delegate, GetCallback(), |
| 2027 &pairing_delegate, | 1879 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2028 base::Bind(&BluetoothChromeOSTest::Callback, | 1880 base::Unretained(this))); |
| 2029 base::Unretained(this)), | |
| 2030 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2031 base::Unretained(this))); | |
| 2032 | 1881 |
| 2033 EXPECT_EQ(1, pairing_delegate.call_count_); | 1882 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2034 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); | 1883 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); |
| 2035 EXPECT_EQ("123456", pairing_delegate.last_pincode_); | 1884 EXPECT_EQ("123456", pairing_delegate.last_pincode_); |
| 2036 EXPECT_TRUE(device->IsConnecting()); | 1885 EXPECT_TRUE(device->IsConnecting()); |
| 2037 | 1886 |
| 2038 message_loop_.Run(); | 1887 message_loop_.Run(); |
| 2039 | 1888 |
| 2040 EXPECT_EQ(1, callback_count_); | 1889 EXPECT_EQ(1, callback_count_); |
| 2041 EXPECT_EQ(0, error_callback_count_); | 1890 EXPECT_EQ(0, error_callback_count_); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 // Requires that we display a randomly generated Passkey on the screen, | 1922 // Requires that we display a randomly generated Passkey on the screen, |
| 2074 // and notifies us as it's typed in. | 1923 // and notifies us as it's typed in. |
| 2075 BluetoothDevice* device = adapter_->GetDevice( | 1924 BluetoothDevice* device = adapter_->GetDevice( |
| 2076 FakeBluetoothDeviceClient::kDisplayPasskeyAddress); | 1925 FakeBluetoothDeviceClient::kDisplayPasskeyAddress); |
| 2077 ASSERT_TRUE(device != NULL); | 1926 ASSERT_TRUE(device != NULL); |
| 2078 ASSERT_FALSE(device->IsPaired()); | 1927 ASSERT_FALSE(device->IsPaired()); |
| 2079 | 1928 |
| 2080 TestObserver observer(adapter_); | 1929 TestObserver observer(adapter_); |
| 2081 | 1930 |
| 2082 TestPairingDelegate pairing_delegate; | 1931 TestPairingDelegate pairing_delegate; |
| 2083 device->Connect( | 1932 device->Connect(&pairing_delegate, GetCallback(), |
| 2084 &pairing_delegate, | 1933 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2085 base::Bind(&BluetoothChromeOSTest::Callback, | 1934 base::Unretained(this))); |
| 2086 base::Unretained(this)), | |
| 2087 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2088 base::Unretained(this))); | |
| 2089 | 1935 |
| 2090 // One call for DisplayPasskey() and one for KeysEntered(). | 1936 // One call for DisplayPasskey() and one for KeysEntered(). |
| 2091 EXPECT_EQ(2, pairing_delegate.call_count_); | 1937 EXPECT_EQ(2, pairing_delegate.call_count_); |
| 2092 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); | 1938 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); |
| 2093 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 1939 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
| 2094 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); | 1940 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); |
| 2095 EXPECT_EQ(0U, pairing_delegate.last_entered_); | 1941 EXPECT_EQ(0U, pairing_delegate.last_entered_); |
| 2096 | 1942 |
| 2097 EXPECT_TRUE(device->IsConnecting()); | 1943 EXPECT_TRUE(device->IsConnecting()); |
| 2098 | 1944 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 | 1996 |
| 2151 // Requires that the user enters a PIN for them. | 1997 // Requires that the user enters a PIN for them. |
| 2152 BluetoothDevice* device = adapter_->GetDevice( | 1998 BluetoothDevice* device = adapter_->GetDevice( |
| 2153 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 1999 FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 2154 ASSERT_TRUE(device != NULL); | 2000 ASSERT_TRUE(device != NULL); |
| 2155 ASSERT_FALSE(device->IsPaired()); | 2001 ASSERT_FALSE(device->IsPaired()); |
| 2156 | 2002 |
| 2157 TestObserver observer(adapter_); | 2003 TestObserver observer(adapter_); |
| 2158 | 2004 |
| 2159 TestPairingDelegate pairing_delegate; | 2005 TestPairingDelegate pairing_delegate; |
| 2160 device->Connect( | 2006 device->Connect(&pairing_delegate, GetCallback(), |
| 2161 &pairing_delegate, | 2007 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2162 base::Bind(&BluetoothChromeOSTest::Callback, | 2008 base::Unretained(this))); |
| 2163 base::Unretained(this)), | |
| 2164 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2165 base::Unretained(this))); | |
| 2166 | 2009 |
| 2167 EXPECT_EQ(1, pairing_delegate.call_count_); | 2010 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2168 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 2011 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
| 2169 EXPECT_TRUE(device->IsConnecting()); | 2012 EXPECT_TRUE(device->IsConnecting()); |
| 2170 | 2013 |
| 2171 // Set the PIN. | 2014 // Set the PIN. |
| 2172 device->SetPinCode("1234"); | 2015 device->SetPinCode("1234"); |
| 2173 message_loop_.Run(); | 2016 message_loop_.Run(); |
| 2174 | 2017 |
| 2175 EXPECT_EQ(1, callback_count_); | 2018 EXPECT_EQ(1, callback_count_); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 | 2050 |
| 2208 // Requests that we confirm a displayed passkey. | 2051 // Requests that we confirm a displayed passkey. |
| 2209 BluetoothDevice* device = adapter_->GetDevice( | 2052 BluetoothDevice* device = adapter_->GetDevice( |
| 2210 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2053 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 2211 ASSERT_TRUE(device != NULL); | 2054 ASSERT_TRUE(device != NULL); |
| 2212 ASSERT_FALSE(device->IsPaired()); | 2055 ASSERT_FALSE(device->IsPaired()); |
| 2213 | 2056 |
| 2214 TestObserver observer(adapter_); | 2057 TestObserver observer(adapter_); |
| 2215 | 2058 |
| 2216 TestPairingDelegate pairing_delegate; | 2059 TestPairingDelegate pairing_delegate; |
| 2217 device->Connect( | 2060 device->Connect(&pairing_delegate, GetCallback(), |
| 2218 &pairing_delegate, | 2061 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2219 base::Bind(&BluetoothChromeOSTest::Callback, | 2062 base::Unretained(this))); |
| 2220 base::Unretained(this)), | |
| 2221 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2222 base::Unretained(this))); | |
| 2223 | 2063 |
| 2224 EXPECT_EQ(1, pairing_delegate.call_count_); | 2064 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2225 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 2065 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
| 2226 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 2066 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
| 2227 EXPECT_TRUE(device->IsConnecting()); | 2067 EXPECT_TRUE(device->IsConnecting()); |
| 2228 | 2068 |
| 2229 // Confirm the passkey. | 2069 // Confirm the passkey. |
| 2230 device->ConfirmPairing(); | 2070 device->ConfirmPairing(); |
| 2231 message_loop_.Run(); | 2071 message_loop_.Run(); |
| 2232 | 2072 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2262 // Requires that the user enters a Passkey, this would be some kind of | 2102 // Requires that the user enters a Passkey, this would be some kind of |
| 2263 // device that has a display, but doesn't use "just works" - maybe a car? | 2103 // device that has a display, but doesn't use "just works" - maybe a car? |
| 2264 BluetoothDevice* device = adapter_->GetDevice( | 2104 BluetoothDevice* device = adapter_->GetDevice( |
| 2265 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2105 FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 2266 ASSERT_TRUE(device != NULL); | 2106 ASSERT_TRUE(device != NULL); |
| 2267 ASSERT_FALSE(device->IsPaired()); | 2107 ASSERT_FALSE(device->IsPaired()); |
| 2268 | 2108 |
| 2269 TestObserver observer(adapter_); | 2109 TestObserver observer(adapter_); |
| 2270 | 2110 |
| 2271 TestPairingDelegate pairing_delegate; | 2111 TestPairingDelegate pairing_delegate; |
| 2272 device->Connect( | 2112 device->Connect(&pairing_delegate, GetCallback(), |
| 2273 &pairing_delegate, | 2113 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2274 base::Bind(&BluetoothChromeOSTest::Callback, | 2114 base::Unretained(this))); |
| 2275 base::Unretained(this)), | |
| 2276 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2277 base::Unretained(this))); | |
| 2278 | 2115 |
| 2279 EXPECT_EQ(1, pairing_delegate.call_count_); | 2116 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2280 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 2117 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 2281 EXPECT_TRUE(device->IsConnecting()); | 2118 EXPECT_TRUE(device->IsConnecting()); |
| 2282 | 2119 |
| 2283 // Set the Passkey. | 2120 // Set the Passkey. |
| 2284 device->SetPasskey(1234); | 2121 device->SetPasskey(1234); |
| 2285 message_loop_.Run(); | 2122 message_loop_.Run(); |
| 2286 | 2123 |
| 2287 EXPECT_EQ(1, callback_count_); | 2124 EXPECT_EQ(1, callback_count_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2316 // Uses just-works pairing, since this is an outgoing pairing, no delegate | 2153 // Uses just-works pairing, since this is an outgoing pairing, no delegate |
| 2317 // interaction is required. | 2154 // interaction is required. |
| 2318 BluetoothDevice* device = adapter_->GetDevice( | 2155 BluetoothDevice* device = adapter_->GetDevice( |
| 2319 FakeBluetoothDeviceClient::kJustWorksAddress); | 2156 FakeBluetoothDeviceClient::kJustWorksAddress); |
| 2320 ASSERT_TRUE(device != NULL); | 2157 ASSERT_TRUE(device != NULL); |
| 2321 ASSERT_FALSE(device->IsPaired()); | 2158 ASSERT_FALSE(device->IsPaired()); |
| 2322 | 2159 |
| 2323 TestObserver observer(adapter_); | 2160 TestObserver observer(adapter_); |
| 2324 | 2161 |
| 2325 TestPairingDelegate pairing_delegate; | 2162 TestPairingDelegate pairing_delegate; |
| 2326 device->Connect( | 2163 device->Connect(&pairing_delegate, GetCallback(), |
| 2327 &pairing_delegate, | 2164 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2328 base::Bind(&BluetoothChromeOSTest::Callback, | 2165 base::Unretained(this))); |
| 2329 base::Unretained(this)), | |
| 2330 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2331 base::Unretained(this))); | |
| 2332 | 2166 |
| 2333 EXPECT_EQ(0, pairing_delegate.call_count_); | 2167 EXPECT_EQ(0, pairing_delegate.call_count_); |
| 2334 | 2168 |
| 2335 message_loop_.Run(); | 2169 message_loop_.Run(); |
| 2336 | 2170 |
| 2337 EXPECT_EQ(1, callback_count_); | 2171 EXPECT_EQ(1, callback_count_); |
| 2338 EXPECT_EQ(0, error_callback_count_); | 2172 EXPECT_EQ(0, error_callback_count_); |
| 2339 | 2173 |
| 2340 // Two changes for connecting, one change for connected, one for paired and | 2174 // Two changes for connecting, one change for connected, one for paired and |
| 2341 // two for trusted (after pairing and connection). | 2175 // two for trusted (after pairing and connection). |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2364 DiscoverDevice(FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 2198 DiscoverDevice(FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
| 2365 | 2199 |
| 2366 BluetoothDevice* device = adapter_->GetDevice( | 2200 BluetoothDevice* device = adapter_->GetDevice( |
| 2367 FakeBluetoothDeviceClient::kUnpairableDeviceAddress); | 2201 FakeBluetoothDeviceClient::kUnpairableDeviceAddress); |
| 2368 ASSERT_TRUE(device != NULL); | 2202 ASSERT_TRUE(device != NULL); |
| 2369 ASSERT_FALSE(device->IsPaired()); | 2203 ASSERT_FALSE(device->IsPaired()); |
| 2370 | 2204 |
| 2371 TestObserver observer(adapter_); | 2205 TestObserver observer(adapter_); |
| 2372 | 2206 |
| 2373 TestPairingDelegate pairing_delegate; | 2207 TestPairingDelegate pairing_delegate; |
| 2374 device->Connect( | 2208 device->Connect(&pairing_delegate, GetCallback(), |
| 2375 &pairing_delegate, | 2209 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2376 base::Bind(&BluetoothChromeOSTest::Callback, | 2210 base::Unretained(this))); |
| 2377 base::Unretained(this)), | |
| 2378 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2379 base::Unretained(this))); | |
| 2380 | 2211 |
| 2381 EXPECT_EQ(0, pairing_delegate.call_count_); | 2212 EXPECT_EQ(0, pairing_delegate.call_count_); |
| 2382 EXPECT_TRUE(device->IsConnecting()); | 2213 EXPECT_TRUE(device->IsConnecting()); |
| 2383 | 2214 |
| 2384 // Run the loop to get the error.. | 2215 // Run the loop to get the error.. |
| 2385 message_loop_.Run(); | 2216 message_loop_.Run(); |
| 2386 | 2217 |
| 2387 EXPECT_EQ(0, callback_count_); | 2218 EXPECT_EQ(0, callback_count_); |
| 2388 EXPECT_EQ(1, error_callback_count_); | 2219 EXPECT_EQ(1, error_callback_count_); |
| 2389 | 2220 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2402 | 2233 |
| 2403 // The vanishing device times out during pairing | 2234 // The vanishing device times out during pairing |
| 2404 BluetoothDevice* device = adapter_->GetDevice( | 2235 BluetoothDevice* device = adapter_->GetDevice( |
| 2405 FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 2236 FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
| 2406 ASSERT_TRUE(device != NULL); | 2237 ASSERT_TRUE(device != NULL); |
| 2407 ASSERT_FALSE(device->IsPaired()); | 2238 ASSERT_FALSE(device->IsPaired()); |
| 2408 | 2239 |
| 2409 TestObserver observer(adapter_); | 2240 TestObserver observer(adapter_); |
| 2410 | 2241 |
| 2411 TestPairingDelegate pairing_delegate; | 2242 TestPairingDelegate pairing_delegate; |
| 2412 device->Connect( | 2243 device->Connect(&pairing_delegate, GetCallback(), |
| 2413 &pairing_delegate, | 2244 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2414 base::Bind(&BluetoothChromeOSTest::Callback, | 2245 base::Unretained(this))); |
| 2415 base::Unretained(this)), | |
| 2416 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2417 base::Unretained(this))); | |
| 2418 | 2246 |
| 2419 EXPECT_EQ(0, pairing_delegate.call_count_); | 2247 EXPECT_EQ(0, pairing_delegate.call_count_); |
| 2420 EXPECT_TRUE(device->IsConnecting()); | 2248 EXPECT_TRUE(device->IsConnecting()); |
| 2421 | 2249 |
| 2422 // Run the loop to get the error.. | 2250 // Run the loop to get the error.. |
| 2423 message_loop_.Run(); | 2251 message_loop_.Run(); |
| 2424 | 2252 |
| 2425 EXPECT_EQ(0, callback_count_); | 2253 EXPECT_EQ(0, callback_count_); |
| 2426 EXPECT_EQ(1, error_callback_count_); | 2254 EXPECT_EQ(1, error_callback_count_); |
| 2427 | 2255 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2441 // Everything seems to go according to plan with the unconnectable device; | 2269 // Everything seems to go according to plan with the unconnectable device; |
| 2442 // it pairs, but then you can't make connections to it after. | 2270 // it pairs, but then you can't make connections to it after. |
| 2443 BluetoothDevice* device = adapter_->GetDevice( | 2271 BluetoothDevice* device = adapter_->GetDevice( |
| 2444 FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 2272 FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
| 2445 ASSERT_TRUE(device != NULL); | 2273 ASSERT_TRUE(device != NULL); |
| 2446 ASSERT_FALSE(device->IsPaired()); | 2274 ASSERT_FALSE(device->IsPaired()); |
| 2447 | 2275 |
| 2448 TestObserver observer(adapter_); | 2276 TestObserver observer(adapter_); |
| 2449 | 2277 |
| 2450 TestPairingDelegate pairing_delegate; | 2278 TestPairingDelegate pairing_delegate; |
| 2451 device->Connect( | 2279 device->Connect(&pairing_delegate, GetCallback(), |
| 2452 &pairing_delegate, | 2280 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2453 base::Bind(&BluetoothChromeOSTest::Callback, | 2281 base::Unretained(this))); |
| 2454 base::Unretained(this)), | |
| 2455 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2456 base::Unretained(this))); | |
| 2457 | 2282 |
| 2458 EXPECT_EQ(0, pairing_delegate.call_count_); | 2283 EXPECT_EQ(0, pairing_delegate.call_count_); |
| 2459 EXPECT_TRUE(device->IsConnecting()); | 2284 EXPECT_TRUE(device->IsConnecting()); |
| 2460 | 2285 |
| 2461 message_loop_.Run(); | 2286 message_loop_.Run(); |
| 2462 | 2287 |
| 2463 EXPECT_EQ(0, callback_count_); | 2288 EXPECT_EQ(0, callback_count_); |
| 2464 EXPECT_EQ(1, error_callback_count_); | 2289 EXPECT_EQ(1, error_callback_count_); |
| 2465 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 2290 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
| 2466 | 2291 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2491 | 2316 |
| 2492 // Reject the pairing after we receive a request for the PIN code. | 2317 // Reject the pairing after we receive a request for the PIN code. |
| 2493 BluetoothDevice* device = adapter_->GetDevice( | 2318 BluetoothDevice* device = adapter_->GetDevice( |
| 2494 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2319 FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 2495 ASSERT_TRUE(device != NULL); | 2320 ASSERT_TRUE(device != NULL); |
| 2496 ASSERT_FALSE(device->IsPaired()); | 2321 ASSERT_FALSE(device->IsPaired()); |
| 2497 | 2322 |
| 2498 TestObserver observer(adapter_); | 2323 TestObserver observer(adapter_); |
| 2499 | 2324 |
| 2500 TestPairingDelegate pairing_delegate; | 2325 TestPairingDelegate pairing_delegate; |
| 2501 device->Connect( | 2326 device->Connect(&pairing_delegate, GetCallback(), |
| 2502 &pairing_delegate, | 2327 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2503 base::Bind(&BluetoothChromeOSTest::Callback, | 2328 base::Unretained(this))); |
| 2504 base::Unretained(this)), | |
| 2505 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2506 base::Unretained(this))); | |
| 2507 | 2329 |
| 2508 EXPECT_EQ(1, pairing_delegate.call_count_); | 2330 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2509 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 2331 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
| 2510 EXPECT_TRUE(device->IsConnecting()); | 2332 EXPECT_TRUE(device->IsConnecting()); |
| 2511 | 2333 |
| 2512 // Reject the pairing. | 2334 // Reject the pairing. |
| 2513 device->RejectPairing(); | 2335 device->RejectPairing(); |
| 2514 message_loop_.Run(); | 2336 message_loop_.Run(); |
| 2515 | 2337 |
| 2516 EXPECT_EQ(0, callback_count_); | 2338 EXPECT_EQ(0, callback_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2532 | 2354 |
| 2533 // Cancel the pairing after we receive a request for the PIN code. | 2355 // Cancel the pairing after we receive a request for the PIN code. |
| 2534 BluetoothDevice* device = adapter_->GetDevice( | 2356 BluetoothDevice* device = adapter_->GetDevice( |
| 2535 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2357 FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 2536 ASSERT_TRUE(device != NULL); | 2358 ASSERT_TRUE(device != NULL); |
| 2537 ASSERT_FALSE(device->IsPaired()); | 2359 ASSERT_FALSE(device->IsPaired()); |
| 2538 | 2360 |
| 2539 TestObserver observer(adapter_); | 2361 TestObserver observer(adapter_); |
| 2540 | 2362 |
| 2541 TestPairingDelegate pairing_delegate; | 2363 TestPairingDelegate pairing_delegate; |
| 2542 device->Connect( | 2364 device->Connect(&pairing_delegate, GetCallback(), |
| 2543 &pairing_delegate, | 2365 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2544 base::Bind(&BluetoothChromeOSTest::Callback, | 2366 base::Unretained(this))); |
| 2545 base::Unretained(this)), | |
| 2546 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2547 base::Unretained(this))); | |
| 2548 | 2367 |
| 2549 EXPECT_EQ(1, pairing_delegate.call_count_); | 2368 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2550 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 2369 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
| 2551 EXPECT_TRUE(device->IsConnecting()); | 2370 EXPECT_TRUE(device->IsConnecting()); |
| 2552 | 2371 |
| 2553 // Cancel the pairing. | 2372 // Cancel the pairing. |
| 2554 device->CancelPairing(); | 2373 device->CancelPairing(); |
| 2555 message_loop_.Run(); | 2374 message_loop_.Run(); |
| 2556 | 2375 |
| 2557 EXPECT_EQ(0, callback_count_); | 2376 EXPECT_EQ(0, callback_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2573 | 2392 |
| 2574 // Reject the pairing after we receive a request for the passkey. | 2393 // Reject the pairing after we receive a request for the passkey. |
| 2575 BluetoothDevice* device = adapter_->GetDevice( | 2394 BluetoothDevice* device = adapter_->GetDevice( |
| 2576 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2395 FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 2577 ASSERT_TRUE(device != NULL); | 2396 ASSERT_TRUE(device != NULL); |
| 2578 ASSERT_FALSE(device->IsPaired()); | 2397 ASSERT_FALSE(device->IsPaired()); |
| 2579 | 2398 |
| 2580 TestObserver observer(adapter_); | 2399 TestObserver observer(adapter_); |
| 2581 | 2400 |
| 2582 TestPairingDelegate pairing_delegate; | 2401 TestPairingDelegate pairing_delegate; |
| 2583 device->Connect( | 2402 device->Connect(&pairing_delegate, GetCallback(), |
| 2584 &pairing_delegate, | 2403 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2585 base::Bind(&BluetoothChromeOSTest::Callback, | 2404 base::Unretained(this))); |
| 2586 base::Unretained(this)), | |
| 2587 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2588 base::Unretained(this))); | |
| 2589 | 2405 |
| 2590 EXPECT_EQ(1, pairing_delegate.call_count_); | 2406 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2591 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 2407 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 2592 EXPECT_TRUE(device->IsConnecting()); | 2408 EXPECT_TRUE(device->IsConnecting()); |
| 2593 | 2409 |
| 2594 // Reject the pairing. | 2410 // Reject the pairing. |
| 2595 device->RejectPairing(); | 2411 device->RejectPairing(); |
| 2596 message_loop_.Run(); | 2412 message_loop_.Run(); |
| 2597 | 2413 |
| 2598 EXPECT_EQ(0, callback_count_); | 2414 EXPECT_EQ(0, callback_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2614 | 2430 |
| 2615 // Cancel the pairing after we receive a request for the passkey. | 2431 // Cancel the pairing after we receive a request for the passkey. |
| 2616 BluetoothDevice* device = adapter_->GetDevice( | 2432 BluetoothDevice* device = adapter_->GetDevice( |
| 2617 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2433 FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 2618 ASSERT_TRUE(device != NULL); | 2434 ASSERT_TRUE(device != NULL); |
| 2619 ASSERT_FALSE(device->IsPaired()); | 2435 ASSERT_FALSE(device->IsPaired()); |
| 2620 | 2436 |
| 2621 TestObserver observer(adapter_); | 2437 TestObserver observer(adapter_); |
| 2622 | 2438 |
| 2623 TestPairingDelegate pairing_delegate; | 2439 TestPairingDelegate pairing_delegate; |
| 2624 device->Connect( | 2440 device->Connect(&pairing_delegate, GetCallback(), |
| 2625 &pairing_delegate, | 2441 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2626 base::Bind(&BluetoothChromeOSTest::Callback, | 2442 base::Unretained(this))); |
| 2627 base::Unretained(this)), | |
| 2628 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2629 base::Unretained(this))); | |
| 2630 | 2443 |
| 2631 EXPECT_EQ(1, pairing_delegate.call_count_); | 2444 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2632 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 2445 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 2633 EXPECT_TRUE(device->IsConnecting()); | 2446 EXPECT_TRUE(device->IsConnecting()); |
| 2634 | 2447 |
| 2635 // Cancel the pairing. | 2448 // Cancel the pairing. |
| 2636 device->CancelPairing(); | 2449 device->CancelPairing(); |
| 2637 message_loop_.Run(); | 2450 message_loop_.Run(); |
| 2638 | 2451 |
| 2639 EXPECT_EQ(0, callback_count_); | 2452 EXPECT_EQ(0, callback_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2655 | 2468 |
| 2656 // Reject the pairing after we receive a request for passkey confirmation. | 2469 // Reject the pairing after we receive a request for passkey confirmation. |
| 2657 BluetoothDevice* device = adapter_->GetDevice( | 2470 BluetoothDevice* device = adapter_->GetDevice( |
| 2658 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2471 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 2659 ASSERT_TRUE(device != NULL); | 2472 ASSERT_TRUE(device != NULL); |
| 2660 ASSERT_FALSE(device->IsPaired()); | 2473 ASSERT_FALSE(device->IsPaired()); |
| 2661 | 2474 |
| 2662 TestObserver observer(adapter_); | 2475 TestObserver observer(adapter_); |
| 2663 | 2476 |
| 2664 TestPairingDelegate pairing_delegate; | 2477 TestPairingDelegate pairing_delegate; |
| 2665 device->Connect( | 2478 device->Connect(&pairing_delegate, GetCallback(), |
| 2666 &pairing_delegate, | 2479 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2667 base::Bind(&BluetoothChromeOSTest::Callback, | 2480 base::Unretained(this))); |
| 2668 base::Unretained(this)), | |
| 2669 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2670 base::Unretained(this))); | |
| 2671 | 2481 |
| 2672 EXPECT_EQ(1, pairing_delegate.call_count_); | 2482 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2673 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 2483 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
| 2674 EXPECT_TRUE(device->IsConnecting()); | 2484 EXPECT_TRUE(device->IsConnecting()); |
| 2675 | 2485 |
| 2676 // Reject the pairing. | 2486 // Reject the pairing. |
| 2677 device->RejectPairing(); | 2487 device->RejectPairing(); |
| 2678 message_loop_.Run(); | 2488 message_loop_.Run(); |
| 2679 | 2489 |
| 2680 EXPECT_EQ(0, callback_count_); | 2490 EXPECT_EQ(0, callback_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2696 | 2506 |
| 2697 // Cancel the pairing after we receive a request for the passkey. | 2507 // Cancel the pairing after we receive a request for the passkey. |
| 2698 BluetoothDevice* device = adapter_->GetDevice( | 2508 BluetoothDevice* device = adapter_->GetDevice( |
| 2699 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2509 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 2700 ASSERT_TRUE(device != NULL); | 2510 ASSERT_TRUE(device != NULL); |
| 2701 ASSERT_FALSE(device->IsPaired()); | 2511 ASSERT_FALSE(device->IsPaired()); |
| 2702 | 2512 |
| 2703 TestObserver observer(adapter_); | 2513 TestObserver observer(adapter_); |
| 2704 | 2514 |
| 2705 TestPairingDelegate pairing_delegate; | 2515 TestPairingDelegate pairing_delegate; |
| 2706 device->Connect( | 2516 device->Connect(&pairing_delegate, GetCallback(), |
| 2707 &pairing_delegate, | 2517 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2708 base::Bind(&BluetoothChromeOSTest::Callback, | 2518 base::Unretained(this))); |
| 2709 base::Unretained(this)), | |
| 2710 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2711 base::Unretained(this))); | |
| 2712 | 2519 |
| 2713 EXPECT_EQ(1, pairing_delegate.call_count_); | 2520 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2714 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 2521 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
| 2715 EXPECT_TRUE(device->IsConnecting()); | 2522 EXPECT_TRUE(device->IsConnecting()); |
| 2716 | 2523 |
| 2717 // Cancel the pairing. | 2524 // Cancel the pairing. |
| 2718 device->CancelPairing(); | 2525 device->CancelPairing(); |
| 2719 message_loop_.Run(); | 2526 message_loop_.Run(); |
| 2720 | 2527 |
| 2721 EXPECT_EQ(0, callback_count_); | 2528 EXPECT_EQ(0, callback_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2737 | 2544 |
| 2738 // Cancel the pairing while we're waiting for the remote host. | 2545 // Cancel the pairing while we're waiting for the remote host. |
| 2739 BluetoothDevice* device = adapter_->GetDevice( | 2546 BluetoothDevice* device = adapter_->GetDevice( |
| 2740 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2547 FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 2741 ASSERT_TRUE(device != NULL); | 2548 ASSERT_TRUE(device != NULL); |
| 2742 ASSERT_FALSE(device->IsPaired()); | 2549 ASSERT_FALSE(device->IsPaired()); |
| 2743 | 2550 |
| 2744 TestObserver observer(adapter_); | 2551 TestObserver observer(adapter_); |
| 2745 | 2552 |
| 2746 TestPairingDelegate pairing_delegate; | 2553 TestPairingDelegate pairing_delegate; |
| 2747 device->Connect( | 2554 device->Connect(&pairing_delegate, GetCallback(), |
| 2748 &pairing_delegate, | 2555 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2749 base::Bind(&BluetoothChromeOSTest::Callback, | 2556 base::Unretained(this))); |
| 2750 base::Unretained(this)), | |
| 2751 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 2752 base::Unretained(this))); | |
| 2753 | 2557 |
| 2754 EXPECT_EQ(0, pairing_delegate.call_count_); | 2558 EXPECT_EQ(0, pairing_delegate.call_count_); |
| 2755 EXPECT_TRUE(device->IsConnecting()); | 2559 EXPECT_TRUE(device->IsConnecting()); |
| 2756 | 2560 |
| 2757 // Cancel the pairing. | 2561 // Cancel the pairing. |
| 2758 device->CancelPairing(); | 2562 device->CancelPairing(); |
| 2759 message_loop_.Run(); | 2563 message_loop_.Run(); |
| 2760 | 2564 |
| 2761 EXPECT_EQ(0, callback_count_); | 2565 EXPECT_EQ(0, callback_count_); |
| 2762 EXPECT_EQ(1, error_callback_count_); | 2566 EXPECT_EQ(1, error_callback_count_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2784 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2588 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 2785 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 2589 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 2786 BluetoothDevice* device = adapter_->GetDevice( | 2590 BluetoothDevice* device = adapter_->GetDevice( |
| 2787 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2591 FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 2788 ASSERT_TRUE(device != NULL); | 2592 ASSERT_TRUE(device != NULL); |
| 2789 ASSERT_FALSE(device->IsPaired()); | 2593 ASSERT_FALSE(device->IsPaired()); |
| 2790 | 2594 |
| 2791 TestObserver observer(adapter_); | 2595 TestObserver observer(adapter_); |
| 2792 | 2596 |
| 2793 fake_bluetooth_device_client_->SimulatePairing( | 2597 fake_bluetooth_device_client_->SimulatePairing( |
| 2794 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), | 2598 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true, |
| 2795 true, | 2599 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 2796 base::Bind(&BluetoothChromeOSTest::Callback, | 2600 base::Unretained(this))); |
| 2797 base::Unretained(this)), | |
| 2798 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 2799 base::Unretained(this))); | |
| 2800 | 2601 |
| 2801 EXPECT_EQ(1, pairing_delegate.call_count_); | 2602 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2802 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 2603 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
| 2803 | 2604 |
| 2804 // Set the PIN. | 2605 // Set the PIN. |
| 2805 device->SetPinCode("1234"); | 2606 device->SetPinCode("1234"); |
| 2806 message_loop_.Run(); | 2607 message_loop_.Run(); |
| 2807 | 2608 |
| 2808 EXPECT_EQ(1, callback_count_); | 2609 EXPECT_EQ(1, callback_count_); |
| 2809 EXPECT_EQ(0, error_callback_count_); | 2610 EXPECT_EQ(0, error_callback_count_); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2841 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2642 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 2842 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 2643 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 2843 BluetoothDevice* device = adapter_->GetDevice( | 2644 BluetoothDevice* device = adapter_->GetDevice( |
| 2844 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2645 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 2845 ASSERT_TRUE(device != NULL); | 2646 ASSERT_TRUE(device != NULL); |
| 2846 ASSERT_FALSE(device->IsPaired()); | 2647 ASSERT_FALSE(device->IsPaired()); |
| 2847 | 2648 |
| 2848 TestObserver observer(adapter_); | 2649 TestObserver observer(adapter_); |
| 2849 | 2650 |
| 2850 fake_bluetooth_device_client_->SimulatePairing( | 2651 fake_bluetooth_device_client_->SimulatePairing( |
| 2851 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), | 2652 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true, |
| 2852 true, | 2653 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 2853 base::Bind(&BluetoothChromeOSTest::Callback, | 2654 base::Unretained(this))); |
| 2854 base::Unretained(this)), | |
| 2855 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 2856 base::Unretained(this))); | |
| 2857 | 2655 |
| 2858 EXPECT_EQ(1, pairing_delegate.call_count_); | 2656 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2859 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 2657 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
| 2860 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 2658 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
| 2861 | 2659 |
| 2862 // Confirm the passkey. | 2660 // Confirm the passkey. |
| 2863 device->ConfirmPairing(); | 2661 device->ConfirmPairing(); |
| 2864 message_loop_.Run(); | 2662 message_loop_.Run(); |
| 2865 | 2663 |
| 2866 EXPECT_EQ(1, callback_count_); | 2664 EXPECT_EQ(1, callback_count_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2899 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2697 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 2900 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 2698 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 2901 BluetoothDevice* device = adapter_->GetDevice( | 2699 BluetoothDevice* device = adapter_->GetDevice( |
| 2902 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2700 FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 2903 ASSERT_TRUE(device != NULL); | 2701 ASSERT_TRUE(device != NULL); |
| 2904 ASSERT_FALSE(device->IsPaired()); | 2702 ASSERT_FALSE(device->IsPaired()); |
| 2905 | 2703 |
| 2906 TestObserver observer(adapter_); | 2704 TestObserver observer(adapter_); |
| 2907 | 2705 |
| 2908 fake_bluetooth_device_client_->SimulatePairing( | 2706 fake_bluetooth_device_client_->SimulatePairing( |
| 2909 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), | 2707 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, |
| 2910 true, | 2708 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 2911 base::Bind(&BluetoothChromeOSTest::Callback, | 2709 base::Unretained(this))); |
| 2912 base::Unretained(this)), | |
| 2913 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 2914 base::Unretained(this))); | |
| 2915 | 2710 |
| 2916 EXPECT_EQ(1, pairing_delegate.call_count_); | 2711 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2917 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 2712 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 2918 | 2713 |
| 2919 // Set the Passkey. | 2714 // Set the Passkey. |
| 2920 device->SetPasskey(1234); | 2715 device->SetPasskey(1234); |
| 2921 message_loop_.Run(); | 2716 message_loop_.Run(); |
| 2922 | 2717 |
| 2923 EXPECT_EQ(1, callback_count_); | 2718 EXPECT_EQ(1, callback_count_); |
| 2924 EXPECT_EQ(0, error_callback_count_); | 2719 EXPECT_EQ(0, error_callback_count_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2957 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2752 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 2958 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 2753 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); |
| 2959 BluetoothDevice* device = adapter_->GetDevice( | 2754 BluetoothDevice* device = adapter_->GetDevice( |
| 2960 FakeBluetoothDeviceClient::kJustWorksAddress); | 2755 FakeBluetoothDeviceClient::kJustWorksAddress); |
| 2961 ASSERT_TRUE(device != NULL); | 2756 ASSERT_TRUE(device != NULL); |
| 2962 ASSERT_FALSE(device->IsPaired()); | 2757 ASSERT_FALSE(device->IsPaired()); |
| 2963 | 2758 |
| 2964 TestObserver observer(adapter_); | 2759 TestObserver observer(adapter_); |
| 2965 | 2760 |
| 2966 fake_bluetooth_device_client_->SimulatePairing( | 2761 fake_bluetooth_device_client_->SimulatePairing( |
| 2967 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), | 2762 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true, |
| 2968 true, | 2763 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 2969 base::Bind(&BluetoothChromeOSTest::Callback, | 2764 base::Unretained(this))); |
| 2970 base::Unretained(this)), | |
| 2971 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 2972 base::Unretained(this))); | |
| 2973 | 2765 |
| 2974 EXPECT_EQ(1, pairing_delegate.call_count_); | 2766 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 2975 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); | 2767 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); |
| 2976 | 2768 |
| 2977 // Confirm the pairing. | 2769 // Confirm the pairing. |
| 2978 device->ConfirmPairing(); | 2770 device->ConfirmPairing(); |
| 2979 message_loop_.Run(); | 2771 message_loop_.Run(); |
| 2980 | 2772 |
| 2981 EXPECT_EQ(1, callback_count_); | 2773 EXPECT_EQ(1, callback_count_); |
| 2982 EXPECT_EQ(0, error_callback_count_); | 2774 EXPECT_EQ(0, error_callback_count_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3010 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2802 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 3011 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 2803 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3012 BluetoothDevice* device = adapter_->GetDevice( | 2804 BluetoothDevice* device = adapter_->GetDevice( |
| 3013 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2805 FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3014 ASSERT_TRUE(device != NULL); | 2806 ASSERT_TRUE(device != NULL); |
| 3015 ASSERT_FALSE(device->IsPaired()); | 2807 ASSERT_FALSE(device->IsPaired()); |
| 3016 | 2808 |
| 3017 TestObserver observer(adapter_); | 2809 TestObserver observer(adapter_); |
| 3018 | 2810 |
| 3019 fake_bluetooth_device_client_->SimulatePairing( | 2811 fake_bluetooth_device_client_->SimulatePairing( |
| 3020 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), | 2812 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true, |
| 3021 true, | 2813 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3022 base::Bind(&BluetoothChromeOSTest::Callback, | 2814 base::Unretained(this))); |
| 3023 base::Unretained(this)), | |
| 3024 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 3025 base::Unretained(this))); | |
| 3026 | 2815 |
| 3027 message_loop_.Run(); | 2816 message_loop_.Run(); |
| 3028 | 2817 |
| 3029 EXPECT_EQ(0, callback_count_); | 2818 EXPECT_EQ(0, callback_count_); |
| 3030 EXPECT_EQ(1, error_callback_count_); | 2819 EXPECT_EQ(1, error_callback_count_); |
| 3031 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 2820 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3032 | 2821 |
| 3033 // No changes should be observer. | 2822 // No changes should be observer. |
| 3034 EXPECT_EQ(0, observer.device_changed_count_); | 2823 EXPECT_EQ(0, observer.device_changed_count_); |
| 3035 | 2824 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3052 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2841 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 3053 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 2842 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3054 BluetoothDevice* device = adapter_->GetDevice( | 2843 BluetoothDevice* device = adapter_->GetDevice( |
| 3055 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2844 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3056 ASSERT_TRUE(device != NULL); | 2845 ASSERT_TRUE(device != NULL); |
| 3057 ASSERT_FALSE(device->IsPaired()); | 2846 ASSERT_FALSE(device->IsPaired()); |
| 3058 | 2847 |
| 3059 TestObserver observer(adapter_); | 2848 TestObserver observer(adapter_); |
| 3060 | 2849 |
| 3061 fake_bluetooth_device_client_->SimulatePairing( | 2850 fake_bluetooth_device_client_->SimulatePairing( |
| 3062 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), | 2851 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true, |
| 3063 true, | 2852 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3064 base::Bind(&BluetoothChromeOSTest::Callback, | 2853 base::Unretained(this))); |
| 3065 base::Unretained(this)), | |
| 3066 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 3067 base::Unretained(this))); | |
| 3068 | 2854 |
| 3069 message_loop_.Run(); | 2855 message_loop_.Run(); |
| 3070 | 2856 |
| 3071 EXPECT_EQ(0, callback_count_); | 2857 EXPECT_EQ(0, callback_count_); |
| 3072 EXPECT_EQ(1, error_callback_count_); | 2858 EXPECT_EQ(1, error_callback_count_); |
| 3073 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 2859 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3074 | 2860 |
| 3075 // No changes should be observer. | 2861 // No changes should be observer. |
| 3076 EXPECT_EQ(0, observer.device_changed_count_); | 2862 EXPECT_EQ(0, observer.device_changed_count_); |
| 3077 | 2863 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3094 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2880 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 3095 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 2881 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3096 BluetoothDevice* device = adapter_->GetDevice( | 2882 BluetoothDevice* device = adapter_->GetDevice( |
| 3097 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2883 FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3098 ASSERT_TRUE(device != NULL); | 2884 ASSERT_TRUE(device != NULL); |
| 3099 ASSERT_FALSE(device->IsPaired()); | 2885 ASSERT_FALSE(device->IsPaired()); |
| 3100 | 2886 |
| 3101 TestObserver observer(adapter_); | 2887 TestObserver observer(adapter_); |
| 3102 | 2888 |
| 3103 fake_bluetooth_device_client_->SimulatePairing( | 2889 fake_bluetooth_device_client_->SimulatePairing( |
| 3104 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), | 2890 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, |
| 3105 true, | 2891 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3106 base::Bind(&BluetoothChromeOSTest::Callback, | 2892 base::Unretained(this))); |
| 3107 base::Unretained(this)), | |
| 3108 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 3109 base::Unretained(this))); | |
| 3110 | 2893 |
| 3111 message_loop_.Run(); | 2894 message_loop_.Run(); |
| 3112 | 2895 |
| 3113 EXPECT_EQ(0, callback_count_); | 2896 EXPECT_EQ(0, callback_count_); |
| 3114 EXPECT_EQ(1, error_callback_count_); | 2897 EXPECT_EQ(1, error_callback_count_); |
| 3115 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 2898 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3116 | 2899 |
| 3117 // No changes should be observer. | 2900 // No changes should be observer. |
| 3118 EXPECT_EQ(0, observer.device_changed_count_); | 2901 EXPECT_EQ(0, observer.device_changed_count_); |
| 3119 | 2902 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3136 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2919 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 3137 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 2920 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3138 BluetoothDevice* device = adapter_->GetDevice( | 2921 BluetoothDevice* device = adapter_->GetDevice( |
| 3139 FakeBluetoothDeviceClient::kJustWorksAddress); | 2922 FakeBluetoothDeviceClient::kJustWorksAddress); |
| 3140 ASSERT_TRUE(device != NULL); | 2923 ASSERT_TRUE(device != NULL); |
| 3141 ASSERT_FALSE(device->IsPaired()); | 2924 ASSERT_FALSE(device->IsPaired()); |
| 3142 | 2925 |
| 3143 TestObserver observer(adapter_); | 2926 TestObserver observer(adapter_); |
| 3144 | 2927 |
| 3145 fake_bluetooth_device_client_->SimulatePairing( | 2928 fake_bluetooth_device_client_->SimulatePairing( |
| 3146 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), | 2929 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true, |
| 3147 true, | 2930 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3148 base::Bind(&BluetoothChromeOSTest::Callback, | 2931 base::Unretained(this))); |
| 3149 base::Unretained(this)), | |
| 3150 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 3151 base::Unretained(this))); | |
| 3152 | 2932 |
| 3153 message_loop_.Run(); | 2933 message_loop_.Run(); |
| 3154 | 2934 |
| 3155 EXPECT_EQ(0, callback_count_); | 2935 EXPECT_EQ(0, callback_count_); |
| 3156 EXPECT_EQ(1, error_callback_count_); | 2936 EXPECT_EQ(1, error_callback_count_); |
| 3157 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 2937 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3158 | 2938 |
| 3159 // No changes should be observer. | 2939 // No changes should be observer. |
| 3160 EXPECT_EQ(0, observer.device_changed_count_); | 2940 EXPECT_EQ(0, observer.device_changed_count_); |
| 3161 | 2941 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3182 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 2962 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 3183 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 2963 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3184 BluetoothDevice* device = adapter_->GetDevice( | 2964 BluetoothDevice* device = adapter_->GetDevice( |
| 3185 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2965 FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3186 ASSERT_TRUE(device != NULL); | 2966 ASSERT_TRUE(device != NULL); |
| 3187 ASSERT_FALSE(device->IsPaired()); | 2967 ASSERT_FALSE(device->IsPaired()); |
| 3188 | 2968 |
| 3189 TestObserver observer(adapter_); | 2969 TestObserver observer(adapter_); |
| 3190 | 2970 |
| 3191 fake_bluetooth_device_client_->SimulatePairing( | 2971 fake_bluetooth_device_client_->SimulatePairing( |
| 3192 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), | 2972 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, |
| 3193 true, | 2973 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3194 base::Bind(&BluetoothChromeOSTest::Callback, | 2974 base::Unretained(this))); |
| 3195 base::Unretained(this)), | |
| 3196 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | |
| 3197 base::Unretained(this))); | |
| 3198 | 2975 |
| 3199 EXPECT_EQ(1, pairing_delegate.call_count_); | 2976 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3200 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 2977 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 3201 | 2978 |
| 3202 // A pairing context should now be set on the device. | 2979 // A pairing context should now be set on the device. |
| 3203 BluetoothDeviceChromeOS* device_chromeos = | 2980 BluetoothDeviceChromeOS* device_chromeos = |
| 3204 static_cast<BluetoothDeviceChromeOS*>(device); | 2981 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3205 ASSERT_TRUE(device_chromeos->GetPairing() != NULL); | 2982 ASSERT_TRUE(device_chromeos->GetPairing() != NULL); |
| 3206 | 2983 |
| 3207 // Removing the pairing delegate should remove that pairing context. | 2984 // Removing the pairing delegate should remove that pairing context. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3289 EXPECT_EQ(unknown_power, conn_info.rssi); | 3066 EXPECT_EQ(unknown_power, conn_info.rssi); |
| 3290 EXPECT_EQ(unknown_power, conn_info.transmit_power); | 3067 EXPECT_EQ(unknown_power, conn_info.transmit_power); |
| 3291 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); | 3068 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); |
| 3292 } | 3069 } |
| 3293 | 3070 |
| 3294 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { | 3071 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { |
| 3295 GetAdapter(); | 3072 GetAdapter(); |
| 3296 BluetoothDevice* device = | 3073 BluetoothDevice* device = |
| 3297 adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3074 adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3298 | 3075 |
| 3299 device->Connect( | 3076 device->Connect(NULL, GetCallback(), |
| 3300 NULL, | 3077 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3301 base::Bind(&BluetoothChromeOSTest::Callback, | 3078 base::Unretained(this))); |
| 3302 base::Unretained(this)), | |
| 3303 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | |
| 3304 base::Unretained(this))); | |
| 3305 EXPECT_TRUE(device->IsConnected()); | 3079 EXPECT_TRUE(device->IsConnected()); |
| 3306 | 3080 |
| 3307 // Calling GetConnectionInfo for a connected device should return valid | 3081 // Calling GetConnectionInfo for a connected device should return valid |
| 3308 // results. | 3082 // results. |
| 3309 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); | 3083 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); |
| 3310 BluetoothDevice::ConnectionInfo conn_info; | 3084 BluetoothDevice::ConnectionInfo conn_info; |
| 3311 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3085 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
| 3312 EXPECT_EQ(-10, conn_info.rssi); | 3086 EXPECT_EQ(-10, conn_info.rssi); |
| 3313 EXPECT_EQ(3, conn_info.transmit_power); | 3087 EXPECT_EQ(3, conn_info.transmit_power); |
| 3314 EXPECT_EQ(4, conn_info.max_transmit_power); | 3088 EXPECT_EQ(4, conn_info.max_transmit_power); |
| 3315 } | 3089 } |
| 3316 | 3090 |
| 3317 // Verifies Shutdown shuts down the adapter as expected. | 3091 // Verifies Shutdown shuts down the adapter as expected. |
| 3318 TEST_F(BluetoothChromeOSTest, Shutdown) { | 3092 TEST_F(BluetoothChromeOSTest, Shutdown) { |
| 3319 // Set up and adapter, power, discoverable, start discovery. | 3093 // Set up adapter. Set powered & discoverable, start discovery. |
| 3320 GetAdapter(); | 3094 GetAdapter(); |
| 3321 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3095 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 3322 base::Unretained(this)), | 3096 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
| 3323 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 3324 base::Unretained(this))); | |
| 3325 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, | |
| 3326 base::Unretained(this)), | |
| 3327 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | |
| 3328 base::Unretained(this))); | |
| 3329 adapter_->StartDiscoverySession( | 3097 adapter_->StartDiscoverySession( |
| 3330 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 3098 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 3331 base::Unretained(this)), | 3099 base::Unretained(this)), |
| 3332 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3100 GetErrorCallback()); |
| 3333 base::Unretained(this))); | |
| 3334 base::MessageLoop::current()->Run(); | 3101 base::MessageLoop::current()->Run(); |
| 3335 ASSERT_EQ(3, callback_count_); | 3102 ASSERT_EQ(3, callback_count_); |
| 3336 ASSERT_EQ(0, error_callback_count_); | 3103 ASSERT_EQ(0, error_callback_count_); |
| 3337 callback_count_ = 0; | 3104 callback_count_ = 0; |
| 3338 | 3105 |
| 3106 TestPairingDelegate pairing_delegate; |
| 3107 adapter_->AddPairingDelegate( |
| 3108 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3109 |
| 3339 // Validate running adapter state. | 3110 // Validate running adapter state. |
| 3340 EXPECT_NE("", adapter_->GetAddress()); | 3111 EXPECT_NE("", adapter_->GetAddress()); |
| 3341 EXPECT_NE("", adapter_->GetName()); | 3112 EXPECT_NE("", adapter_->GetName()); |
| 3342 EXPECT_TRUE(adapter_->IsInitialized()); | 3113 EXPECT_TRUE(adapter_->IsInitialized()); |
| 3343 EXPECT_TRUE(adapter_->IsPresent()); | 3114 EXPECT_TRUE(adapter_->IsPresent()); |
| 3344 EXPECT_TRUE(adapter_->IsPowered()); | 3115 EXPECT_TRUE(adapter_->IsPowered()); |
| 3345 EXPECT_TRUE(adapter_->IsDiscoverable()); | 3116 EXPECT_TRUE(adapter_->IsDiscoverable()); |
| 3346 EXPECT_TRUE(adapter_->IsDiscovering()); | 3117 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 3347 EXPECT_EQ(2U, adapter_->GetDevices().size()); | 3118 EXPECT_EQ(2U, adapter_->GetDevices().size()); |
| 3348 EXPECT_NE(nullptr, adapter_->GetDevice( | 3119 EXPECT_NE(nullptr, adapter_->GetDevice( |
| 3349 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 3120 FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3350 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | 3121 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
| 3351 adapter_.get())->object_path()); | 3122 adapter_.get())->object_path()); |
| 3352 | 3123 |
| 3353 // Shutdown | 3124 // Shutdown |
| 3354 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())->Shutdown(); | 3125 adapter_->Shutdown(); |
| 3355 | 3126 |
| 3356 // Validate post shutdown state. | 3127 // Validate post shutdown state by calling all BluetoothAdapterChromeOS |
| 3128 // members, in declaration order: |
| 3129 |
| 3130 adapter_->Shutdown(); |
| 3131 // DeleteOnCorrectThread omitted as we don't want to delete in this test. |
| 3132 { |
| 3133 TestObserver observer(adapter_); // Calls AddObserver |
| 3134 } // TestObserver::~TestObserver calls RemoveObserver. |
| 3357 EXPECT_EQ("", adapter_->GetAddress()); | 3135 EXPECT_EQ("", adapter_->GetAddress()); |
| 3358 EXPECT_EQ("", adapter_->GetName()); | 3136 EXPECT_EQ("", adapter_->GetName()); |
| 3137 |
| 3138 adapter_->SetName("", GetCallback(), GetErrorCallback()); |
| 3139 EXPECT_EQ(0, callback_count_); |
| 3140 EXPECT_EQ(1, error_callback_count_--) << "SetName error"; |
| 3141 |
| 3359 EXPECT_TRUE(adapter_->IsInitialized()); | 3142 EXPECT_TRUE(adapter_->IsInitialized()); |
| 3360 EXPECT_FALSE(adapter_->IsPresent()); | 3143 EXPECT_FALSE(adapter_->IsPresent()); |
| 3361 EXPECT_FALSE(adapter_->IsPowered()); | 3144 EXPECT_FALSE(adapter_->IsPowered()); |
| 3145 |
| 3146 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 3147 EXPECT_EQ(0, callback_count_); |
| 3148 EXPECT_EQ(1, error_callback_count_--) << "SetPowered error"; |
| 3149 |
| 3362 EXPECT_FALSE(adapter_->IsDiscoverable()); | 3150 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 3151 |
| 3152 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); |
| 3153 EXPECT_EQ(0, callback_count_); |
| 3154 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; |
| 3155 |
| 3363 EXPECT_FALSE(adapter_->IsDiscovering()); | 3156 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 3157 // CreateRfcommService will DCHECK after Shutdown(). |
| 3158 // CreateL2capService will DCHECK after Shutdown(). |
| 3159 |
| 3160 BluetoothAudioSink::Options audio_sink_options; |
| 3161 adapter_->RegisterAudioSink( |
| 3162 audio_sink_options, |
| 3163 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
| 3164 base::Unretained(this)), |
| 3165 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, |
| 3166 base::Unretained(this))); |
| 3167 EXPECT_EQ(0, callback_count_); |
| 3168 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
| 3169 |
| 3170 BluetoothAdapterChromeOS* adapter_chrome_os = |
| 3171 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
| 3172 EXPECT_EQ(NULL, adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); |
| 3173 |
| 3174 // Notify methods presume objects exist that are owned by the adapter and |
| 3175 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, |
| 3176 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 3177 // NotifyDeviceChanged |
| 3178 // NotifyGattServiceAdded |
| 3179 // NotifyGattServiceRemoved |
| 3180 // NotifyGattServiceChanged |
| 3181 // NotifyGattDiscoveryComplete |
| 3182 // NotifyGattCharacteristicAdded |
| 3183 // NotifyGattCharacteristicRemoved |
| 3184 // NotifyGattDescriptorAdded |
| 3185 // NotifyGattDescriptorRemoved |
| 3186 // NotifyGattCharacteristicValueChanged |
| 3187 // NotifyGattDescriptorValueChanged |
| 3188 |
| 3189 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); |
| 3190 |
| 3191 FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
| 3192 adapter_chrome_os->UseProfile( |
| 3193 BluetoothUUID(), dbus::ObjectPath(""), |
| 3194 BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 3195 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3196 base::Unretained(this)), |
| 3197 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3198 base::Unretained(this))); |
| 3199 base::MessageLoop::current()->Run(); |
| 3200 EXPECT_EQ(1, callback_count_--) << "UseProfile error"; |
| 3201 EXPECT_EQ(0, error_callback_count_) << "UseProfile error"; |
| 3202 |
| 3203 adapter_chrome_os->ReleaseProfile(BluetoothUUID()); |
| 3204 |
| 3205 // Protected and private methods: |
| 3206 |
| 3207 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); |
| 3208 |
| 3209 // BluetoothAdapterClient::Observer methods omitted, dbus will be shutdown. |
| 3210 // BluetoothDeviceClient::Observer methods omitted, dbus will be shutdown. |
| 3211 // BluetoothInputClient::Observer methods omitted, dbus will be shutdown. |
| 3212 // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown, |
| 3213 // with the exception of Released. |
| 3214 adapter_chrome_os->Released(); |
| 3215 |
| 3216 adapter_chrome_os->OnRegisterAgent(); |
| 3217 adapter_chrome_os->OnRegisterAgentError("", ""); |
| 3218 adapter_chrome_os->OnRequestDefaultAgent(); |
| 3219 adapter_chrome_os->OnRequestDefaultAgentError("", ""); |
| 3220 |
| 3221 adapter_chrome_os->OnRegisterAudioSink( |
| 3222 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
| 3223 base::Unretained(this)), |
| 3224 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, |
| 3225 base::Unretained(this)), |
| 3226 scoped_refptr<device::BluetoothAudioSink>()); |
| 3227 EXPECT_EQ(0, callback_count_); |
| 3228 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; |
| 3229 |
| 3230 // GetPairing will DCHECK after Shutdown(). |
| 3231 // SetAdapter will DCHECK after Shutdown(). |
| 3232 // SetDefaultAdapterName will DCHECK after Shutdown(). |
| 3233 // RemoveAdapter will DCHECK after Shutdown(). |
| 3234 adapter_chrome_os->PoweredChanged(false); |
| 3235 adapter_chrome_os->DiscoverableChanged(false); |
| 3236 adapter_chrome_os->DiscoveringChanged(false); |
| 3237 adapter_chrome_os->PresentChanged(false); |
| 3238 |
| 3239 adapter_chrome_os->OnSetDiscoverable(GetCallback(), GetErrorCallback(), true); |
| 3240 EXPECT_EQ(0, callback_count_) << "OnSetDiscoverable error"; |
| 3241 EXPECT_EQ(1, error_callback_count_--) << "OnSetDiscoverable error"; |
| 3242 |
| 3243 adapter_chrome_os->OnPropertyChangeCompleted(GetCallback(), |
| 3244 GetErrorCallback(), true); |
| 3245 EXPECT_EQ(0, callback_count_) << "OnPropertyChangeCompleted error"; |
| 3246 EXPECT_EQ(1, error_callback_count_--) << "OnPropertyChangeCompleted error"; |
| 3247 |
| 3248 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3249 EXPECT_EQ(0, callback_count_) << "AddDiscoverySession error"; |
| 3250 EXPECT_EQ(1, error_callback_count_--) << "AddDiscoverySession error"; |
| 3251 |
| 3252 adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3253 EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error"; |
| 3254 EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error"; |
| 3255 |
| 3256 // OnStartDiscovery tested in Shutdown_OnStartDiscovery |
| 3257 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError |
| 3258 // OnStopDiscovery tested in Shutdown_OnStopDiscovery |
| 3259 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError |
| 3260 |
| 3261 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require |
| 3262 // UseProfile to be set first, do so again here just before calling them. |
| 3263 adapter_chrome_os->UseProfile( |
| 3264 BluetoothUUID(), dbus::ObjectPath(""), |
| 3265 BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 3266 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3267 base::Unretained(this)), |
| 3268 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3269 base::Unretained(this))); |
| 3270 |
| 3271 adapter_chrome_os->OnRegisterProfile( |
| 3272 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, |
| 3273 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3274 base::Unretained(this)), |
| 3275 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3276 base::Unretained(this))); |
| 3277 EXPECT_EQ(1, callback_count_--) << "OnRegisterProfile error"; |
| 3278 EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfile error"; |
| 3279 |
| 3280 adapter_chrome_os->SetProfileDelegate( |
| 3281 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, |
| 3282 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3283 base::Unretained(this)), |
| 3284 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3285 base::Unretained(this))); |
| 3286 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; |
| 3287 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; |
| 3288 |
| 3289 adapter_chrome_os->OnRegisterProfileError( |
| 3290 BluetoothUUID(), |
| 3291 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3292 base::Unretained(this)), |
| 3293 "", ""); |
| 3294 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; |
| 3295 EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfileError error"; |
| 3296 |
| 3297 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); |
| 3298 |
| 3299 // From BluetoothAdapater: |
| 3300 |
| 3301 adapter_->StartDiscoverySession( |
| 3302 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 3303 base::Unretained(this)), |
| 3304 GetErrorCallback()); |
| 3305 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
| 3306 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; |
| 3307 |
| 3364 EXPECT_EQ(0U, adapter_->GetDevices().size()); | 3308 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 3365 EXPECT_EQ(nullptr, adapter_->GetDevice( | 3309 EXPECT_EQ(nullptr, adapter_->GetDevice( |
| 3366 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 3310 FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3367 EXPECT_EQ(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | 3311 TestPairingDelegate pairing_delegate2; |
| 3368 adapter_.get())->object_path()); | 3312 adapter_->AddPairingDelegate( |
| 3369 | 3313 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3370 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3314 adapter_->RemovePairingDelegate(&pairing_delegate2); |
| 3371 base::Unretained(this)), | 3315 } |
| 3372 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3316 |
| 3373 base::Unretained(this))); | 3317 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
| 3374 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, | 3318 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { |
| 3375 base::Unretained(this)), | 3319 const int kNumberOfDiscoverySessions = 10; |
| 3376 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3320 GetAdapter(); |
| 3377 base::Unretained(this))); | 3321 BluetoothAdapterChromeOS* adapter_chrome_os = |
| 3378 adapter_->StartDiscoverySession( | 3322 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
| 3379 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 3323 |
| 3380 base::Unretained(this)), | 3324 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
| 3381 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 3325 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3382 base::Unretained(this))); | 3326 } |
| 3383 ASSERT_EQ(0, callback_count_); | 3327 adapter_->Shutdown(); |
| 3384 ASSERT_EQ(3, error_callback_count_); | 3328 adapter_chrome_os->OnStartDiscovery(GetCallback(), GetErrorCallback()); |
| 3329 |
| 3330 EXPECT_EQ(0, callback_count_); |
| 3331 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
| 3332 } |
| 3333 |
| 3334 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. |
| 3335 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscoveryError) { |
| 3336 const int kNumberOfDiscoverySessions = 10; |
| 3337 GetAdapter(); |
| 3338 BluetoothAdapterChromeOS* adapter_chrome_os = |
| 3339 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
| 3340 |
| 3341 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
| 3342 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3343 } |
| 3344 adapter_->Shutdown(); |
| 3345 adapter_chrome_os->OnStartDiscoveryError(GetCallback(), GetErrorCallback(), |
| 3346 "", ""); |
| 3347 |
| 3348 EXPECT_EQ(0, callback_count_); |
| 3349 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
| 3350 } |
| 3351 |
| 3352 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
| 3353 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscovery) { |
| 3354 const int kNumberOfDiscoverySessions = 10; |
| 3355 GetAdapter(); |
| 3356 BluetoothAdapterChromeOS* adapter_chrome_os = |
| 3357 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
| 3358 |
| 3359 // In order to queue up discovery sessions before an OnStopDiscovery call |
| 3360 // RemoveDiscoverySession must be called, so Add, Start, and Remove: |
| 3361 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3362 adapter_chrome_os->OnStartDiscovery(GetCallback(), GetErrorCallback()); |
| 3363 adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3364 callback_count_ = 0; |
| 3365 error_callback_count_ = 0; |
| 3366 // Can now queue discovery sessions while waiting for OnStopDiscovery. |
| 3367 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
| 3368 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3369 } |
| 3370 adapter_->Shutdown(); |
| 3371 adapter_chrome_os->OnStopDiscovery(GetCallback()); |
| 3372 |
| 3373 // 1 successful stopped discovery from RemoveDiscoverySession, and |
| 3374 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. |
| 3375 EXPECT_EQ(1, callback_count_); |
| 3376 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); |
| 3377 } |
| 3378 |
| 3379 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. |
| 3380 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscoveryError) { |
| 3381 const int kNumberOfDiscoverySessions = 10; |
| 3382 GetAdapter(); |
| 3383 BluetoothAdapterChromeOS* adapter_chrome_os = |
| 3384 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); |
| 3385 |
| 3386 // In order to queue up discovery sessions before an OnStopDiscoveryError call |
| 3387 // RemoveDiscoverySession must be called, so Add, Start, and Remove: |
| 3388 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3389 adapter_chrome_os->OnStartDiscovery(GetCallback(), GetErrorCallback()); |
| 3390 adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3391 callback_count_ = 0; |
| 3392 error_callback_count_ = 0; |
| 3393 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. |
| 3394 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { |
| 3395 adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback()); |
| 3396 } |
| 3397 adapter_->Shutdown(); |
| 3398 adapter_chrome_os->OnStopDiscoveryError(GetErrorCallback(), "", ""); |
| 3399 |
| 3400 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
| 3401 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
| 3402 EXPECT_EQ(0, callback_count_); |
| 3403 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
| 3385 } | 3404 } |
| 3386 | 3405 |
| 3387 } // namespace chromeos | 3406 } // namespace chromeos |
| OLD | NEW |