| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | |
| 11 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | |
| 12 #include "chromeos/dbus/fake_bluetooth_device_client.h" | |
| 13 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | |
| 14 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
| 15 #include "dbus/object_path.h" | 9 #include "dbus/object_path.h" |
| 16 #include "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 18 #include "device/bluetooth/bluetooth_adapter_factory.h" | 12 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 19 #include "device/bluetooth/bluetooth_device.h" | 13 #include "device/bluetooth/bluetooth_device.h" |
| 20 #include "device/bluetooth/bluetooth_device_chromeos.h" | 14 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 21 #include "device/bluetooth/bluetooth_discovery_session.h" | 15 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 22 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 16 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
| 19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
| 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
| 22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
| 23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "third_party/cros_system_api/dbus/service_constants.h" | 25 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 26 | 26 |
| 27 using device::BluetoothAdapter; | 27 using device::BluetoothAdapter; |
| 28 using device::BluetoothAdapterFactory; | 28 using device::BluetoothAdapterFactory; |
| 29 using device::BluetoothAudioSink; | 29 using device::BluetoothAudioSink; |
| 30 using device::BluetoothDevice; | 30 using device::BluetoothDevice; |
| 31 using device::BluetoothDiscoveryFilter; | 31 using device::BluetoothDiscoveryFilter; |
| 32 using device::BluetoothDiscoverySession; | 32 using device::BluetoothDiscoverySession; |
| 33 using device::BluetoothUUID; | 33 using device::BluetoothUUID; |
| 34 using device::TestBluetoothAdapterObserver; | 34 using device::TestBluetoothAdapterObserver; |
| 35 | 35 |
| 36 namespace chromeos { | 36 namespace chromeos { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the | 40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the |
| 41 // connection info to the bound argument. | 41 // connection info to the bound argument. |
| 42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, | 42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, |
| 43 const BluetoothDevice::ConnectionInfo& conn_info) { | 43 const BluetoothDevice::ConnectionInfo& conn_info) { |
| 44 *out = conn_info; | 44 *out = conn_info; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class FakeBluetoothProfileServiceProviderDelegate | 47 class FakeBluetoothProfileServiceProviderDelegate |
| 48 : public chromeos::BluetoothProfileServiceProvider::Delegate { | 48 : public bluez::BluetoothProfileServiceProvider::Delegate { |
| 49 public: | 49 public: |
| 50 FakeBluetoothProfileServiceProviderDelegate() {} | 50 FakeBluetoothProfileServiceProviderDelegate() {} |
| 51 | 51 |
| 52 // BluetoothProfileServiceProvider::Delegate: | 52 // bluez::BluetoothProfileServiceProvider::Delegate: |
| 53 void Released() override {} | 53 void Released() override {} |
| 54 | 54 |
| 55 void NewConnection(const dbus::ObjectPath&, | 55 void NewConnection( |
| 56 scoped_ptr<dbus::FileDescriptor>, | 56 const dbus::ObjectPath&, |
| 57 const BluetoothProfileServiceProvider::Delegate::Options&, | 57 scoped_ptr<dbus::FileDescriptor>, |
| 58 const ConfirmationCallback&) override {} | 58 const bluez::BluetoothProfileServiceProvider::Delegate::Options&, |
| 59 const ConfirmationCallback&) override {} |
| 59 | 60 |
| 60 void RequestDisconnection(const dbus::ObjectPath&, | 61 void RequestDisconnection(const dbus::ObjectPath&, |
| 61 const ConfirmationCallback&) override {} | 62 const ConfirmationCallback&) override {} |
| 62 | 63 |
| 63 void Cancel() override {} | 64 void Cancel() override {} |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 } // namespace | 67 } // namespace |
| 67 | 68 |
| 68 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { | 69 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (base::MessageLoop::current() && | 147 if (base::MessageLoop::current() && |
| 147 base::MessageLoop::current()->is_running()) { | 148 base::MessageLoop::current()->is_running()) { |
| 148 base::MessageLoop::current()->Quit(); | 149 base::MessageLoop::current()->Quit(); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 }; | 152 }; |
| 152 | 153 |
| 153 class BluetoothChromeOSTest : public testing::Test { | 154 class BluetoothChromeOSTest : public testing::Test { |
| 154 public: | 155 public: |
| 155 void SetUp() override { | 156 void SetUp() override { |
| 156 scoped_ptr<DBusThreadManagerSetter> dbus_setter = | 157 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
| 157 chromeos::DBusThreadManager::GetSetterForTesting(); | 158 bluez::BluezDBusManager::GetSetterForTesting(); |
| 158 // We need to initialize DBusThreadManager early to prevent | 159 // We need to initialize BluezDBusManager early to prevent |
| 159 // Bluetooth*::Create() methods from picking the real instead of fake | 160 // Bluetooth*::Create() methods from picking the real instead of fake |
| 160 // implementations. | 161 // implementations. |
| 161 fake_bluetooth_adapter_client_ = new FakeBluetoothAdapterClient; | 162 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; |
| 162 dbus_setter->SetBluetoothAdapterClient( | 163 dbus_setter->SetBluetoothAdapterClient( |
| 163 scoped_ptr<BluetoothAdapterClient>(fake_bluetooth_adapter_client_)); | 164 scoped_ptr<bluez::BluetoothAdapterClient>( |
| 164 fake_bluetooth_device_client_ = new FakeBluetoothDeviceClient; | 165 fake_bluetooth_adapter_client_)); |
| 166 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; |
| 165 dbus_setter->SetBluetoothDeviceClient( | 167 dbus_setter->SetBluetoothDeviceClient( |
| 166 scoped_ptr<BluetoothDeviceClient>(fake_bluetooth_device_client_)); | 168 scoped_ptr<bluez::BluetoothDeviceClient>( |
| 169 fake_bluetooth_device_client_)); |
| 167 dbus_setter->SetBluetoothInputClient( | 170 dbus_setter->SetBluetoothInputClient( |
| 168 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); | 171 scoped_ptr<bluez::BluetoothInputClient>( |
| 172 new bluez::FakeBluetoothInputClient)); |
| 169 dbus_setter->SetBluetoothAgentManagerClient( | 173 dbus_setter->SetBluetoothAgentManagerClient( |
| 170 scoped_ptr<BluetoothAgentManagerClient>( | 174 scoped_ptr<bluez::BluetoothAgentManagerClient>( |
| 171 new FakeBluetoothAgentManagerClient)); | 175 new bluez::FakeBluetoothAgentManagerClient)); |
| 172 dbus_setter->SetBluetoothGattServiceClient( | 176 dbus_setter->SetBluetoothGattServiceClient( |
| 173 scoped_ptr<BluetoothGattServiceClient>( | 177 scoped_ptr<bluez::BluetoothGattServiceClient>( |
| 174 new FakeBluetoothGattServiceClient)); | 178 new bluez::FakeBluetoothGattServiceClient)); |
| 175 | 179 |
| 176 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); | 180 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); |
| 177 | 181 |
| 178 callback_count_ = 0; | 182 callback_count_ = 0; |
| 179 error_callback_count_ = 0; | 183 error_callback_count_ = 0; |
| 180 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; | 184 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; |
| 181 last_client_error_ = ""; | 185 last_client_error_ = ""; |
| 182 } | 186 } |
| 183 | 187 |
| 184 void TearDown() override { | 188 void TearDown() override { |
| 185 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = | 189 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = |
| 186 discovery_sessions_.begin(); | 190 discovery_sessions_.begin(); |
| 187 iter != discovery_sessions_.end(); | 191 iter != discovery_sessions_.end(); |
| 188 ++iter) { | 192 ++iter) { |
| 189 BluetoothDiscoverySession* session = *iter; | 193 BluetoothDiscoverySession* session = *iter; |
| 190 if (!session->IsActive()) | 194 if (!session->IsActive()) |
| 191 continue; | 195 continue; |
| 192 callback_count_ = 0; | 196 callback_count_ = 0; |
| 193 session->Stop(GetCallback(), GetErrorCallback()); | 197 session->Stop(GetCallback(), GetErrorCallback()); |
| 194 message_loop_.Run(); | 198 message_loop_.Run(); |
| 195 ASSERT_EQ(1, callback_count_); | 199 ASSERT_EQ(1, callback_count_); |
| 196 } | 200 } |
| 197 discovery_sessions_.clear(); | 201 discovery_sessions_.clear(); |
| 198 adapter_ = nullptr; | 202 adapter_ = nullptr; |
| 199 DBusThreadManager::Shutdown(); | 203 bluez::BluezDBusManager::Shutdown(); |
| 200 } | 204 } |
| 201 | 205 |
| 202 // Generic callbacks | 206 // Generic callbacks |
| 203 void Callback() { | 207 void Callback() { |
| 204 ++callback_count_; | 208 ++callback_count_; |
| 205 QuitMessageLoop(); | 209 QuitMessageLoop(); |
| 206 } | 210 } |
| 207 | 211 |
| 208 base::Closure GetCallback() { | 212 base::Closure GetCallback() { |
| 209 return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)); | 213 return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 322 |
| 319 // Run a discovery phase so we have devices that can be paired with. | 323 // Run a discovery phase so we have devices that can be paired with. |
| 320 void DiscoverDevices() { | 324 void DiscoverDevices() { |
| 321 // Pass an invalid address for the device so that the discovery process | 325 // Pass an invalid address for the device so that the discovery process |
| 322 // completes with all devices. | 326 // completes with all devices. |
| 323 DiscoverDevice("does not exist"); | 327 DiscoverDevice("does not exist"); |
| 324 } | 328 } |
| 325 | 329 |
| 326 protected: | 330 protected: |
| 327 base::MessageLoop message_loop_; | 331 base::MessageLoop message_loop_; |
| 328 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; | 332 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; |
| 329 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 333 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
| 330 scoped_refptr<BluetoothAdapter> adapter_; | 334 scoped_refptr<BluetoothAdapter> adapter_; |
| 331 | 335 |
| 332 int callback_count_; | 336 int callback_count_; |
| 333 int error_callback_count_; | 337 int error_callback_count_; |
| 334 enum BluetoothDevice::ConnectErrorCode last_connect_error_; | 338 enum BluetoothDevice::ConnectErrorCode last_connect_error_; |
| 335 std::string last_client_error_; | 339 std::string last_client_error_; |
| 336 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 340 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
| 337 BluetoothAdapterProfileChromeOS* adapter_profile_; | 341 BluetoothAdapterProfileChromeOS* adapter_profile_; |
| 338 | 342 |
| 339 private: | 343 private: |
| 340 // Some tests use a message loop since background processing is simulated; | 344 // Some tests use a message loop since background processing is simulated; |
| 341 // break out of those loops. | 345 // break out of those loops. |
| 342 void QuitMessageLoop() { | 346 void QuitMessageLoop() { |
| 343 if (base::MessageLoop::current() && | 347 if (base::MessageLoop::current() && |
| 344 base::MessageLoop::current()->is_running()) { | 348 base::MessageLoop::current()->is_running()) { |
| 345 base::MessageLoop::current()->Quit(); | 349 base::MessageLoop::current()->Quit(); |
| 346 } | 350 } |
| 347 } | 351 } |
| 348 }; | 352 }; |
| 349 | 353 |
| 350 TEST_F(BluetoothChromeOSTest, AlreadyPresent) { | 354 TEST_F(BluetoothChromeOSTest, AlreadyPresent) { |
| 351 GetAdapter(); | 355 GetAdapter(); |
| 352 | 356 |
| 353 // This verifies that the class gets the list of adapters when created; | 357 // This verifies that the class gets the list of adapters when created; |
| 354 // and initializes with an existing adapter if there is one. | 358 // and initializes with an existing adapter if there is one. |
| 355 EXPECT_TRUE(adapter_->IsPresent()); | 359 EXPECT_TRUE(adapter_->IsPresent()); |
| 356 EXPECT_FALSE(adapter_->IsPowered()); | 360 EXPECT_FALSE(adapter_->IsPowered()); |
| 357 EXPECT_EQ(FakeBluetoothAdapterClient::kAdapterAddress, | 361 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress, |
| 358 adapter_->GetAddress()); | 362 adapter_->GetAddress()); |
| 359 EXPECT_FALSE(adapter_->IsDiscovering()); | 363 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 360 | 364 |
| 361 // There should be a device | 365 // There should be a device |
| 362 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 366 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 363 EXPECT_EQ(2U, devices.size()); | 367 EXPECT_EQ(2U, devices.size()); |
| 364 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 368 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 365 devices[0]->GetAddress()); | 369 devices[0]->GetAddress()); |
| 366 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 370 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
| 367 devices[1]->GetAddress()); | 371 devices[1]->GetAddress()); |
| 368 } | 372 } |
| 369 | 373 |
| 370 TEST_F(BluetoothChromeOSTest, BecomePresent) { | 374 TEST_F(BluetoothChromeOSTest, BecomePresent) { |
| 371 fake_bluetooth_adapter_client_->SetVisible(false); | 375 fake_bluetooth_adapter_client_->SetVisible(false); |
| 372 GetAdapter(); | 376 GetAdapter(); |
| 373 ASSERT_FALSE(adapter_->IsPresent()); | 377 ASSERT_FALSE(adapter_->IsPresent()); |
| 374 | 378 |
| 375 // Install an observer; expect the AdapterPresentChanged to be called | 379 // Install an observer; expect the AdapterPresentChanged to be called |
| 376 // with true, and IsPresent() to return true. | 380 // with true, and IsPresent() to return true. |
| 377 TestBluetoothAdapterObserver observer(adapter_); | 381 TestBluetoothAdapterObserver observer(adapter_); |
| 378 | 382 |
| 379 fake_bluetooth_adapter_client_->SetVisible(true); | 383 fake_bluetooth_adapter_client_->SetVisible(true); |
| 380 | 384 |
| 381 EXPECT_EQ(1, observer.present_changed_count()); | 385 EXPECT_EQ(1, observer.present_changed_count()); |
| 382 EXPECT_TRUE(observer.last_present()); | 386 EXPECT_TRUE(observer.last_present()); |
| 383 | 387 |
| 384 EXPECT_TRUE(adapter_->IsPresent()); | 388 EXPECT_TRUE(adapter_->IsPresent()); |
| 385 | 389 |
| 386 // We should have had a device announced. | 390 // We should have had a device announced. |
| 387 EXPECT_EQ(2, observer.device_added_count()); | 391 EXPECT_EQ(2, observer.device_added_count()); |
| 388 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 392 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
| 389 observer.last_device_address()); | 393 observer.last_device_address()); |
| 390 | 394 |
| 391 // Other callbacks shouldn't be called if the values are false. | 395 // Other callbacks shouldn't be called if the values are false. |
| 392 EXPECT_EQ(0, observer.powered_changed_count()); | 396 EXPECT_EQ(0, observer.powered_changed_count()); |
| 393 EXPECT_EQ(0, observer.discovering_changed_count()); | 397 EXPECT_EQ(0, observer.discovering_changed_count()); |
| 394 EXPECT_FALSE(adapter_->IsPowered()); | 398 EXPECT_FALSE(adapter_->IsPowered()); |
| 395 EXPECT_FALSE(adapter_->IsDiscovering()); | 399 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 396 } | 400 } |
| 397 | 401 |
| 398 TEST_F(BluetoothChromeOSTest, BecomeNotPresent) { | 402 TEST_F(BluetoothChromeOSTest, BecomeNotPresent) { |
| 399 GetAdapter(); | 403 GetAdapter(); |
| 400 ASSERT_TRUE(adapter_->IsPresent()); | 404 ASSERT_TRUE(adapter_->IsPresent()); |
| 401 | 405 |
| 402 // Install an observer; expect the AdapterPresentChanged to be called | 406 // Install an observer; expect the AdapterPresentChanged to be called |
| 403 // with false, and IsPresent() to return false. | 407 // with false, and IsPresent() to return false. |
| 404 TestBluetoothAdapterObserver observer(adapter_); | 408 TestBluetoothAdapterObserver observer(adapter_); |
| 405 | 409 |
| 406 fake_bluetooth_adapter_client_->SetVisible(false); | 410 fake_bluetooth_adapter_client_->SetVisible(false); |
| 407 | 411 |
| 408 EXPECT_EQ(1, observer.present_changed_count()); | 412 EXPECT_EQ(1, observer.present_changed_count()); |
| 409 EXPECT_FALSE(observer.last_present()); | 413 EXPECT_FALSE(observer.last_present()); |
| 410 | 414 |
| 411 EXPECT_FALSE(adapter_->IsPresent()); | 415 EXPECT_FALSE(adapter_->IsPresent()); |
| 412 | 416 |
| 413 // We should have had a device removed. | 417 // We should have had a device removed. |
| 414 EXPECT_EQ(2, observer.device_removed_count()); | 418 EXPECT_EQ(2, observer.device_removed_count()); |
| 415 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 419 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
| 416 observer.last_device_address()); | 420 observer.last_device_address()); |
| 417 | 421 |
| 418 // Other callbacks shouldn't be called since the values are false. | 422 // Other callbacks shouldn't be called since the values are false. |
| 419 EXPECT_EQ(0, observer.powered_changed_count()); | 423 EXPECT_EQ(0, observer.powered_changed_count()); |
| 420 EXPECT_EQ(0, observer.discovering_changed_count()); | 424 EXPECT_EQ(0, observer.discovering_changed_count()); |
| 421 EXPECT_FALSE(adapter_->IsPowered()); | 425 EXPECT_FALSE(adapter_->IsPowered()); |
| 422 EXPECT_FALSE(adapter_->IsDiscovering()); | 426 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 423 } | 427 } |
| 424 | 428 |
| 425 TEST_F(BluetoothChromeOSTest, SecondAdapter) { | 429 TEST_F(BluetoothChromeOSTest, SecondAdapter) { |
| 426 GetAdapter(); | 430 GetAdapter(); |
| 427 ASSERT_TRUE(adapter_->IsPresent()); | 431 ASSERT_TRUE(adapter_->IsPresent()); |
| 428 | 432 |
| 429 // Install an observer, then add a second adapter. Nothing should change, | 433 // Install an observer, then add a second adapter. Nothing should change, |
| 430 // we ignore the second adapter. | 434 // we ignore the second adapter. |
| 431 TestBluetoothAdapterObserver observer(adapter_); | 435 TestBluetoothAdapterObserver observer(adapter_); |
| 432 | 436 |
| 433 fake_bluetooth_adapter_client_->SetSecondVisible(true); | 437 fake_bluetooth_adapter_client_->SetSecondVisible(true); |
| 434 | 438 |
| 435 EXPECT_EQ(0, observer.present_changed_count()); | 439 EXPECT_EQ(0, observer.present_changed_count()); |
| 436 | 440 |
| 437 EXPECT_TRUE(adapter_->IsPresent()); | 441 EXPECT_TRUE(adapter_->IsPresent()); |
| 438 EXPECT_EQ(FakeBluetoothAdapterClient::kAdapterAddress, | 442 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress, |
| 439 adapter_->GetAddress()); | 443 adapter_->GetAddress()); |
| 440 | 444 |
| 441 // Try removing the first adapter, we should now act as if the adapter | 445 // Try removing the first adapter, we should now act as if the adapter |
| 442 // is no longer present rather than fall back to the second. | 446 // is no longer present rather than fall back to the second. |
| 443 fake_bluetooth_adapter_client_->SetVisible(false); | 447 fake_bluetooth_adapter_client_->SetVisible(false); |
| 444 | 448 |
| 445 EXPECT_EQ(1, observer.present_changed_count()); | 449 EXPECT_EQ(1, observer.present_changed_count()); |
| 446 EXPECT_FALSE(observer.last_present()); | 450 EXPECT_FALSE(observer.last_present()); |
| 447 | 451 |
| 448 EXPECT_FALSE(adapter_->IsPresent()); | 452 EXPECT_FALSE(adapter_->IsPresent()); |
| 449 | 453 |
| 450 // We should have had a device removed. | 454 // We should have had a device removed. |
| 451 EXPECT_EQ(2, observer.device_removed_count()); | 455 EXPECT_EQ(2, observer.device_removed_count()); |
| 452 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, | 456 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, |
| 453 observer.last_device_address()); | 457 observer.last_device_address()); |
| 454 | 458 |
| 455 // Other callbacks shouldn't be called since the values are false. | 459 // Other callbacks shouldn't be called since the values are false. |
| 456 EXPECT_EQ(0, observer.powered_changed_count()); | 460 EXPECT_EQ(0, observer.powered_changed_count()); |
| 457 EXPECT_EQ(0, observer.discovering_changed_count()); | 461 EXPECT_EQ(0, observer.discovering_changed_count()); |
| 458 EXPECT_FALSE(adapter_->IsPowered()); | 462 EXPECT_FALSE(adapter_->IsPowered()); |
| 459 EXPECT_FALSE(adapter_->IsDiscovering()); | 463 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 460 | 464 |
| 461 observer.Reset(); | 465 observer.Reset(); |
| 462 | 466 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 | 717 |
| 714 ASSERT_TRUE(adapter_->IsPowered()); | 718 ASSERT_TRUE(adapter_->IsPowered()); |
| 715 ASSERT_TRUE(adapter_->IsDiscovering()); | 719 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 716 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 720 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 717 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 721 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 718 | 722 |
| 719 // First two devices to appear. | 723 // First two devices to appear. |
| 720 message_loop_.Run(); | 724 message_loop_.Run(); |
| 721 | 725 |
| 722 EXPECT_EQ(2, observer.device_added_count()); | 726 EXPECT_EQ(2, observer.device_added_count()); |
| 723 EXPECT_EQ(FakeBluetoothDeviceClient::kLowEnergyAddress, | 727 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
| 724 observer.last_device_address()); | 728 observer.last_device_address()); |
| 725 | 729 |
| 726 // Next we should get another two devices... | 730 // Next we should get another two devices... |
| 727 message_loop_.Run(); | 731 message_loop_.Run(); |
| 728 EXPECT_EQ(4, observer.device_added_count()); | 732 EXPECT_EQ(4, observer.device_added_count()); |
| 729 | 733 |
| 730 // Okay, let's run forward until a device is actually removed... | 734 // Okay, let's run forward until a device is actually removed... |
| 731 while (!observer.device_removed_count()) | 735 while (!observer.device_removed_count()) |
| 732 message_loop_.Run(); | 736 message_loop_.Run(); |
| 733 | 737 |
| 734 EXPECT_EQ(1, observer.device_removed_count()); | 738 EXPECT_EQ(1, observer.device_removed_count()); |
| 735 EXPECT_EQ(FakeBluetoothDeviceClient::kVanishingDeviceAddress, | 739 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress, |
| 736 observer.last_device_address()); | 740 observer.last_device_address()); |
| 737 } | 741 } |
| 738 | 742 |
| 739 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { | 743 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { |
| 740 GetAdapter(); | 744 GetAdapter(); |
| 741 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); | 745 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); |
| 742 adapter_->StartDiscoverySession( | 746 adapter_->StartDiscoverySession( |
| 743 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 747 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 744 base::Unretained(this)), | 748 base::Unretained(this)), |
| 745 GetErrorCallback()); | 749 GetErrorCallback()); |
| 746 message_loop_.Run(); | 750 message_loop_.Run(); |
| 747 EXPECT_EQ(2, callback_count_); | 751 EXPECT_EQ(2, callback_count_); |
| 748 EXPECT_EQ(0, error_callback_count_); | 752 EXPECT_EQ(0, error_callback_count_); |
| 749 callback_count_ = 0; | 753 callback_count_ = 0; |
| 750 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 754 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 751 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 755 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 752 | 756 |
| 753 // Stop the timers that the simulation uses | 757 // Stop the timers that the simulation uses |
| 754 fake_bluetooth_device_client_->EndDiscoverySimulation( | 758 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 755 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 759 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); |
| 756 | 760 |
| 757 ASSERT_TRUE(adapter_->IsPowered()); | 761 ASSERT_TRUE(adapter_->IsPowered()); |
| 758 ASSERT_TRUE(adapter_->IsDiscovering()); | 762 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 759 | 763 |
| 760 fake_bluetooth_adapter_client_->SetVisible(false); | 764 fake_bluetooth_adapter_client_->SetVisible(false); |
| 761 ASSERT_FALSE(adapter_->IsPresent()); | 765 ASSERT_FALSE(adapter_->IsPresent()); |
| 762 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 766 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
| 763 | 767 |
| 764 // Install an observer; expect the AdapterPresentChanged, | 768 // Install an observer; expect the AdapterPresentChanged, |
| 765 // AdapterPoweredChanged and AdapterDiscoveringChanged methods to be called | 769 // AdapterPoweredChanged and AdapterDiscoveringChanged methods to be called |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 EXPECT_EQ(0, error_callback_count_); | 943 EXPECT_EQ(0, error_callback_count_); |
| 940 EXPECT_TRUE(observer.last_discovering()); | 944 EXPECT_TRUE(observer.last_discovering()); |
| 941 EXPECT_TRUE(adapter_->IsDiscovering()); | 945 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 942 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 946 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 943 | 947 |
| 944 for (int i = 0; i < 3; i++) | 948 for (int i = 0; i < 3; i++) |
| 945 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); | 949 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); |
| 946 | 950 |
| 947 // Stop the timers that the simulation uses | 951 // Stop the timers that the simulation uses |
| 948 fake_bluetooth_device_client_->EndDiscoverySimulation( | 952 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 949 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 953 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); |
| 950 | 954 |
| 951 ASSERT_TRUE(adapter_->IsPowered()); | 955 ASSERT_TRUE(adapter_->IsPowered()); |
| 952 ASSERT_TRUE(adapter_->IsDiscovering()); | 956 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 953 | 957 |
| 954 // Stop device discovery behind the adapter. The adapter and the observer | 958 // Stop device discovery behind the adapter. The adapter and the observer |
| 955 // should be notified of the change and the reference count should be reset. | 959 // should be notified of the change and the reference count should be reset. |
| 956 // Even though FakeBluetoothAdapterClient does its own reference counting and | 960 // Even though bluez::FakeBluetoothAdapterClient does its own reference |
| 961 // counting and |
| 957 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the | 962 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the |
| 958 // FakeBluetoothAdapterClient's count should be only 1 and a single call to | 963 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single |
| 959 // FakeBluetoothAdapterClient::StopDiscovery should work. | 964 // call to |
| 965 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work. |
| 960 fake_bluetooth_adapter_client_->StopDiscovery( | 966 fake_bluetooth_adapter_client_->StopDiscovery( |
| 961 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(), | 967 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 962 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 968 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 963 base::Unretained(this))); | 969 base::Unretained(this))); |
| 964 message_loop_.Run(); | 970 message_loop_.Run(); |
| 965 EXPECT_EQ(2, observer.discovering_changed_count()); | 971 EXPECT_EQ(2, observer.discovering_changed_count()); |
| 966 EXPECT_EQ(4, callback_count_); | 972 EXPECT_EQ(4, callback_count_); |
| 967 EXPECT_EQ(0, error_callback_count_); | 973 EXPECT_EQ(0, error_callback_count_); |
| 968 EXPECT_FALSE(observer.last_discovering()); | 974 EXPECT_FALSE(observer.last_discovering()); |
| 969 EXPECT_FALSE(adapter_->IsDiscovering()); | 975 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 970 | 976 |
| 971 // All discovery session instances should have been updated. | 977 // All discovery session instances should have been updated. |
| 972 for (int i = 0; i < 3; i++) | 978 for (int i = 0; i < 3; i++) |
| 973 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); | 979 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 986 EXPECT_EQ(6, callback_count_); | 992 EXPECT_EQ(6, callback_count_); |
| 987 EXPECT_EQ(0, error_callback_count_); | 993 EXPECT_EQ(0, error_callback_count_); |
| 988 EXPECT_TRUE(observer.last_discovering()); | 994 EXPECT_TRUE(observer.last_discovering()); |
| 989 EXPECT_TRUE(adapter_->IsDiscovering()); | 995 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 990 ASSERT_EQ((size_t)2, discovery_sessions_.size()); | 996 ASSERT_EQ((size_t)2, discovery_sessions_.size()); |
| 991 | 997 |
| 992 for (int i = 0; i < 2; i++) | 998 for (int i = 0; i < 2; i++) |
| 993 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); | 999 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); |
| 994 | 1000 |
| 995 fake_bluetooth_device_client_->EndDiscoverySimulation( | 1001 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 996 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 1002 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); |
| 997 | 1003 |
| 998 // Make the adapter disappear and appear. This will make it come back as | 1004 // Make the adapter disappear and appear. This will make it come back as |
| 999 // discovering. When this happens, the reference count should become and | 1005 // discovering. When this happens, the reference count should become and |
| 1000 // remain 0 as no new request was made through the BluetoothAdapter. | 1006 // remain 0 as no new request was made through the BluetoothAdapter. |
| 1001 fake_bluetooth_adapter_client_->SetVisible(false); | 1007 fake_bluetooth_adapter_client_->SetVisible(false); |
| 1002 ASSERT_FALSE(adapter_->IsPresent()); | 1008 ASSERT_FALSE(adapter_->IsPresent()); |
| 1003 EXPECT_EQ(4, observer.discovering_changed_count()); | 1009 EXPECT_EQ(4, observer.discovering_changed_count()); |
| 1004 EXPECT_EQ(6, callback_count_); | 1010 EXPECT_EQ(6, callback_count_); |
| 1005 EXPECT_EQ(0, error_callback_count_); | 1011 EXPECT_EQ(0, error_callback_count_); |
| 1006 EXPECT_FALSE(observer.last_discovering()); | 1012 EXPECT_FALSE(observer.last_discovering()); |
| 1007 EXPECT_FALSE(adapter_->IsDiscovering()); | 1013 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1008 | 1014 |
| 1009 for (int i = 0; i < 2; i++) | 1015 for (int i = 0; i < 2; i++) |
| 1010 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); | 1016 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); |
| 1011 discovery_sessions_.clear(); | 1017 discovery_sessions_.clear(); |
| 1012 | 1018 |
| 1013 fake_bluetooth_adapter_client_->SetVisible(true); | 1019 fake_bluetooth_adapter_client_->SetVisible(true); |
| 1014 ASSERT_TRUE(adapter_->IsPresent()); | 1020 ASSERT_TRUE(adapter_->IsPresent()); |
| 1015 EXPECT_EQ(5, observer.discovering_changed_count()); | 1021 EXPECT_EQ(5, observer.discovering_changed_count()); |
| 1016 EXPECT_EQ(6, callback_count_); | 1022 EXPECT_EQ(6, callback_count_); |
| 1017 EXPECT_EQ(0, error_callback_count_); | 1023 EXPECT_EQ(0, error_callback_count_); |
| 1018 EXPECT_TRUE(observer.last_discovering()); | 1024 EXPECT_TRUE(observer.last_discovering()); |
| 1019 EXPECT_TRUE(adapter_->IsDiscovering()); | 1025 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1020 | 1026 |
| 1021 // Start and stop discovery. At this point, FakeBluetoothAdapterClient has | 1027 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient |
| 1028 // has |
| 1022 // a reference count that is equal to 1. Pretend that this was done by an | 1029 // a reference count that is equal to 1. Pretend that this was done by an |
| 1023 // application other than us. Starting and stopping discovery will succeed | 1030 // application other than us. Starting and stopping discovery will succeed |
| 1024 // but it won't cause the discovery state to change. | 1031 // but it won't cause the discovery state to change. |
| 1025 adapter_->StartDiscoverySession( | 1032 adapter_->StartDiscoverySession( |
| 1026 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1033 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1027 base::Unretained(this)), | 1034 base::Unretained(this)), |
| 1028 GetErrorCallback()); | 1035 GetErrorCallback()); |
| 1029 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. | 1036 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. |
| 1030 EXPECT_EQ(5, observer.discovering_changed_count()); | 1037 EXPECT_EQ(5, observer.discovering_changed_count()); |
| 1031 EXPECT_EQ(7, callback_count_); | 1038 EXPECT_EQ(7, callback_count_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1056 EXPECT_EQ(0, error_callback_count_); | 1063 EXPECT_EQ(0, error_callback_count_); |
| 1057 EXPECT_TRUE(observer.last_discovering()); | 1064 EXPECT_TRUE(observer.last_discovering()); |
| 1058 EXPECT_TRUE(adapter_->IsDiscovering()); | 1065 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1059 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1066 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 1060 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1067 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1061 | 1068 |
| 1062 // Stop discovery via D-Bus. The fake client's reference count will drop but | 1069 // Stop discovery via D-Bus. The fake client's reference count will drop but |
| 1063 // the discovery state won't change since our BluetoothAdapter also just | 1070 // the discovery state won't change since our BluetoothAdapter also just |
| 1064 // requested it via D-Bus. | 1071 // requested it via D-Bus. |
| 1065 fake_bluetooth_adapter_client_->StopDiscovery( | 1072 fake_bluetooth_adapter_client_->StopDiscovery( |
| 1066 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(), | 1073 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 1067 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1074 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 1068 base::Unretained(this))); | 1075 base::Unretained(this))); |
| 1069 message_loop_.Run(); | 1076 message_loop_.Run(); |
| 1070 EXPECT_EQ(5, observer.discovering_changed_count()); | 1077 EXPECT_EQ(5, observer.discovering_changed_count()); |
| 1071 EXPECT_EQ(10, callback_count_); | 1078 EXPECT_EQ(10, callback_count_); |
| 1072 EXPECT_EQ(0, error_callback_count_); | 1079 EXPECT_EQ(0, error_callback_count_); |
| 1073 EXPECT_TRUE(observer.last_discovering()); | 1080 EXPECT_TRUE(observer.last_discovering()); |
| 1074 EXPECT_TRUE(adapter_->IsDiscovering()); | 1081 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1075 | 1082 |
| 1076 // Now end the discovery session. This should change the adapter's discovery | 1083 // Now end the discovery session. This should change the adapter's discovery |
| 1077 // state. | 1084 // state. |
| 1078 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); | 1085 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 EXPECT_EQ(0, error_callback_count_); | 1124 EXPECT_EQ(0, error_callback_count_); |
| 1118 EXPECT_TRUE(observer.last_discovering()); | 1125 EXPECT_TRUE(observer.last_discovering()); |
| 1119 EXPECT_TRUE(adapter_->IsDiscovering()); | 1126 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1120 ASSERT_EQ((size_t)3, discovery_sessions_.size()); | 1127 ASSERT_EQ((size_t)3, discovery_sessions_.size()); |
| 1121 | 1128 |
| 1122 for (int i = 0; i < 3; i++) | 1129 for (int i = 0; i < 3; i++) |
| 1123 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); | 1130 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); |
| 1124 | 1131 |
| 1125 // Stop the timers that the simulation uses | 1132 // Stop the timers that the simulation uses |
| 1126 fake_bluetooth_device_client_->EndDiscoverySimulation( | 1133 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 1127 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 1134 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); |
| 1128 | 1135 |
| 1129 ASSERT_TRUE(adapter_->IsPowered()); | 1136 ASSERT_TRUE(adapter_->IsPowered()); |
| 1130 ASSERT_TRUE(adapter_->IsDiscovering()); | 1137 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 1131 | 1138 |
| 1132 // Delete all but one discovery session. | 1139 // Delete all but one discovery session. |
| 1133 discovery_sessions_.pop_back(); | 1140 discovery_sessions_.pop_back(); |
| 1134 discovery_sessions_.pop_back(); | 1141 discovery_sessions_.pop_back(); |
| 1135 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 1142 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
| 1136 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 1143 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
| 1137 EXPECT_TRUE(adapter_->IsDiscovering()); | 1144 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1138 | 1145 |
| 1139 // Stop device discovery behind the adapter. The one active discovery session | 1146 // Stop device discovery behind the adapter. The one active discovery session |
| 1140 // should become inactive, but more importantly, we shouldn't run into any | 1147 // should become inactive, but more importantly, we shouldn't run into any |
| 1141 // memory errors as the sessions that we explicitly deleted should get | 1148 // memory errors as the sessions that we explicitly deleted should get |
| 1142 // cleaned up. | 1149 // cleaned up. |
| 1143 fake_bluetooth_adapter_client_->StopDiscovery( | 1150 fake_bluetooth_adapter_client_->StopDiscovery( |
| 1144 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(), | 1151 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 1145 base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 1152 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 1146 base::Unretained(this))); | 1153 base::Unretained(this))); |
| 1147 message_loop_.Run(); | 1154 message_loop_.Run(); |
| 1148 EXPECT_EQ(2, observer.discovering_changed_count()); | 1155 EXPECT_EQ(2, observer.discovering_changed_count()); |
| 1149 EXPECT_EQ(4, callback_count_); | 1156 EXPECT_EQ(4, callback_count_); |
| 1150 EXPECT_EQ(0, error_callback_count_); | 1157 EXPECT_EQ(0, error_callback_count_); |
| 1151 EXPECT_FALSE(observer.last_discovering()); | 1158 EXPECT_FALSE(observer.last_discovering()); |
| 1152 EXPECT_FALSE(adapter_->IsDiscovering()); | 1159 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1153 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 1160 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
| 1154 } | 1161 } |
| 1155 | 1162 |
| 1156 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { | 1163 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1169 EXPECT_FALSE(adapter_->IsDiscovering()); | 1176 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1170 | 1177 |
| 1171 // Request to start discovery. The call should be pending. | 1178 // Request to start discovery. The call should be pending. |
| 1172 adapter_->StartDiscoverySession( | 1179 adapter_->StartDiscoverySession( |
| 1173 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1180 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1174 base::Unretained(this)), | 1181 base::Unretained(this)), |
| 1175 GetErrorCallback()); | 1182 GetErrorCallback()); |
| 1176 EXPECT_EQ(0, callback_count_); | 1183 EXPECT_EQ(0, callback_count_); |
| 1177 | 1184 |
| 1178 fake_bluetooth_device_client_->EndDiscoverySimulation( | 1185 fake_bluetooth_device_client_->EndDiscoverySimulation( |
| 1179 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 1186 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); |
| 1180 | 1187 |
| 1181 // The underlying adapter has started discovery, but our call hasn't returned | 1188 // The underlying adapter has started discovery, but our call hasn't returned |
| 1182 // yet. | 1189 // yet. |
| 1183 EXPECT_EQ(1, observer.discovering_changed_count()); | 1190 EXPECT_EQ(1, observer.discovering_changed_count()); |
| 1184 EXPECT_TRUE(observer.last_discovering()); | 1191 EXPECT_TRUE(observer.last_discovering()); |
| 1185 EXPECT_TRUE(adapter_->IsDiscovering()); | 1192 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1186 EXPECT_TRUE(discovery_sessions_.empty()); | 1193 EXPECT_TRUE(discovery_sessions_.empty()); |
| 1187 | 1194 |
| 1188 // Request to start discovery twice. These should get queued and there should | 1195 // Request to start discovery twice. These should get queued and there should |
| 1189 // be no change in state. | 1196 // be no change in state. |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2085 // Every session stopping would trigger filter update | 2092 // Every session stopping would trigger filter update |
| 2086 message_loop_.Run(); | 2093 message_loop_.Run(); |
| 2087 } | 2094 } |
| 2088 } | 2095 } |
| 2089 | 2096 |
| 2090 TEST_F(BluetoothChromeOSTest, DeviceProperties) { | 2097 TEST_F(BluetoothChromeOSTest, DeviceProperties) { |
| 2091 GetAdapter(); | 2098 GetAdapter(); |
| 2092 | 2099 |
| 2093 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2100 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2094 ASSERT_EQ(2U, devices.size()); | 2101 ASSERT_EQ(2U, devices.size()); |
| 2095 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2102 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2096 devices[0]->GetAddress()); | 2103 devices[0]->GetAddress()); |
| 2097 | 2104 |
| 2098 // Verify the other device properties. | 2105 // Verify the other device properties. |
| 2099 EXPECT_EQ(base::UTF8ToUTF16(FakeBluetoothDeviceClient::kPairedDeviceName), | 2106 EXPECT_EQ( |
| 2100 devices[0]->GetName()); | 2107 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), |
| 2108 devices[0]->GetName()); |
| 2101 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); | 2109 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); |
| 2102 EXPECT_TRUE(devices[0]->IsPaired()); | 2110 EXPECT_TRUE(devices[0]->IsPaired()); |
| 2103 EXPECT_FALSE(devices[0]->IsConnected()); | 2111 EXPECT_FALSE(devices[0]->IsConnected()); |
| 2104 EXPECT_FALSE(devices[0]->IsConnecting()); | 2112 EXPECT_FALSE(devices[0]->IsConnecting()); |
| 2105 | 2113 |
| 2106 // Non HID devices are always connectable. | 2114 // Non HID devices are always connectable. |
| 2107 EXPECT_TRUE(devices[0]->IsConnectable()); | 2115 EXPECT_TRUE(devices[0]->IsConnectable()); |
| 2108 | 2116 |
| 2109 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); | 2117 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); |
| 2110 ASSERT_EQ(2U, uuids.size()); | 2118 ASSERT_EQ(2U, uuids.size()); |
| 2111 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); | 2119 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); |
| 2112 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); | 2120 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); |
| 2113 | 2121 |
| 2114 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); | 2122 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); |
| 2115 EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); | 2123 EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); |
| 2116 EXPECT_EQ(0x030d, devices[0]->GetProductID()); | 2124 EXPECT_EQ(0x030d, devices[0]->GetProductID()); |
| 2117 EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); | 2125 EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); |
| 2118 } | 2126 } |
| 2119 | 2127 |
| 2120 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { | 2128 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { |
| 2121 // Simulate a change of class of a device, as sometimes occurs | 2129 // Simulate a change of class of a device, as sometimes occurs |
| 2122 // during discovery. | 2130 // during discovery. |
| 2123 GetAdapter(); | 2131 GetAdapter(); |
| 2124 | 2132 |
| 2125 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2133 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2126 ASSERT_EQ(2U, devices.size()); | 2134 ASSERT_EQ(2U, devices.size()); |
| 2127 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2135 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2128 devices[0]->GetAddress()); | 2136 devices[0]->GetAddress()); |
| 2129 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); | 2137 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); |
| 2130 | 2138 |
| 2131 // Install an observer; expect the DeviceChanged method to be called when | 2139 // Install an observer; expect the DeviceChanged method to be called when |
| 2132 // we change the class of the device. | 2140 // we change the class of the device. |
| 2133 TestBluetoothAdapterObserver observer(adapter_); | 2141 TestBluetoothAdapterObserver observer(adapter_); |
| 2134 | 2142 |
| 2135 FakeBluetoothDeviceClient::Properties* properties = | 2143 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2136 fake_bluetooth_device_client_->GetProperties( | 2144 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2137 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2145 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2138 | 2146 |
| 2139 properties->bluetooth_class.ReplaceValue(0x002580); | 2147 properties->bluetooth_class.ReplaceValue(0x002580); |
| 2140 | 2148 |
| 2141 EXPECT_EQ(1, observer.device_changed_count()); | 2149 EXPECT_EQ(1, observer.device_changed_count()); |
| 2142 EXPECT_EQ(devices[0], observer.last_device()); | 2150 EXPECT_EQ(devices[0], observer.last_device()); |
| 2143 | 2151 |
| 2144 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[0]->GetDeviceType()); | 2152 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[0]->GetDeviceType()); |
| 2145 } | 2153 } |
| 2146 | 2154 |
| 2147 TEST_F(BluetoothChromeOSTest, DeviceNameChanged) { | 2155 TEST_F(BluetoothChromeOSTest, DeviceNameChanged) { |
| 2148 // Simulate a change of name of a device. | 2156 // Simulate a change of name of a device. |
| 2149 GetAdapter(); | 2157 GetAdapter(); |
| 2150 | 2158 |
| 2151 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2159 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2152 ASSERT_EQ(2U, devices.size()); | 2160 ASSERT_EQ(2U, devices.size()); |
| 2153 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2161 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2154 devices[0]->GetAddress()); | 2162 devices[0]->GetAddress()); |
| 2155 ASSERT_EQ(base::UTF8ToUTF16(FakeBluetoothDeviceClient::kPairedDeviceName), | 2163 ASSERT_EQ( |
| 2156 devices[0]->GetName()); | 2164 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), |
| 2165 devices[0]->GetName()); |
| 2157 | 2166 |
| 2158 // Install an observer; expect the DeviceChanged method to be called when | 2167 // Install an observer; expect the DeviceChanged method to be called when |
| 2159 // we change the alias of the device. | 2168 // we change the alias of the device. |
| 2160 TestBluetoothAdapterObserver observer(adapter_); | 2169 TestBluetoothAdapterObserver observer(adapter_); |
| 2161 | 2170 |
| 2162 FakeBluetoothDeviceClient::Properties* properties = | 2171 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2163 fake_bluetooth_device_client_->GetProperties( | 2172 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2164 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2173 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2165 | 2174 |
| 2166 static const std::string new_name("New Device Name"); | 2175 static const std::string new_name("New Device Name"); |
| 2167 properties->alias.ReplaceValue(new_name); | 2176 properties->alias.ReplaceValue(new_name); |
| 2168 | 2177 |
| 2169 EXPECT_EQ(1, observer.device_changed_count()); | 2178 EXPECT_EQ(1, observer.device_changed_count()); |
| 2170 EXPECT_EQ(devices[0], observer.last_device()); | 2179 EXPECT_EQ(devices[0], observer.last_device()); |
| 2171 | 2180 |
| 2172 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[0]->GetName()); | 2181 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[0]->GetName()); |
| 2173 } | 2182 } |
| 2174 | 2183 |
| 2175 TEST_F(BluetoothChromeOSTest, DeviceAddressChanged) { | 2184 TEST_F(BluetoothChromeOSTest, DeviceAddressChanged) { |
| 2176 // Simulate a change of address of a device. | 2185 // Simulate a change of address of a device. |
| 2177 GetAdapter(); | 2186 GetAdapter(); |
| 2178 | 2187 |
| 2179 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2188 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2180 ASSERT_EQ(2U, devices.size()); | 2189 ASSERT_EQ(2U, devices.size()); |
| 2181 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2190 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2182 devices[0]->GetAddress()); | 2191 devices[0]->GetAddress()); |
| 2183 ASSERT_EQ(base::UTF8ToUTF16(FakeBluetoothDeviceClient::kPairedDeviceName), | 2192 ASSERT_EQ( |
| 2184 devices[0]->GetName()); | 2193 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), |
| 2194 devices[0]->GetName()); |
| 2185 | 2195 |
| 2186 // Install an observer; expect the DeviceAddressChanged method to be called | 2196 // Install an observer; expect the DeviceAddressChanged method to be called |
| 2187 // when we change the alias of the device. | 2197 // when we change the alias of the device. |
| 2188 TestBluetoothAdapterObserver observer(adapter_); | 2198 TestBluetoothAdapterObserver observer(adapter_); |
| 2189 | 2199 |
| 2190 FakeBluetoothDeviceClient::Properties* properties = | 2200 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2191 fake_bluetooth_device_client_->GetProperties( | 2201 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2192 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2202 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2193 | 2203 |
| 2194 static const char* kNewAddress = "D9:1F:FC:11:22:33"; | 2204 static const char* kNewAddress = "D9:1F:FC:11:22:33"; |
| 2195 properties->address.ReplaceValue(kNewAddress); | 2205 properties->address.ReplaceValue(kNewAddress); |
| 2196 | 2206 |
| 2197 EXPECT_EQ(1, observer.device_address_changed_count()); | 2207 EXPECT_EQ(1, observer.device_address_changed_count()); |
| 2198 EXPECT_EQ(1, observer.device_changed_count()); | 2208 EXPECT_EQ(1, observer.device_changed_count()); |
| 2199 EXPECT_EQ(devices[0], observer.last_device()); | 2209 EXPECT_EQ(devices[0], observer.last_device()); |
| 2200 | 2210 |
| 2201 EXPECT_EQ(std::string(kNewAddress), devices[0]->GetAddress()); | 2211 EXPECT_EQ(std::string(kNewAddress), devices[0]->GetAddress()); |
| 2202 } | 2212 } |
| 2203 | 2213 |
| 2204 TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { | 2214 TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { |
| 2205 // Simulate a change of advertised services of a device. | 2215 // Simulate a change of advertised services of a device. |
| 2206 GetAdapter(); | 2216 GetAdapter(); |
| 2207 | 2217 |
| 2208 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2218 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2209 ASSERT_EQ(2U, devices.size()); | 2219 ASSERT_EQ(2U, devices.size()); |
| 2210 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2220 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2211 devices[0]->GetAddress()); | 2221 devices[0]->GetAddress()); |
| 2212 | 2222 |
| 2213 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); | 2223 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); |
| 2214 ASSERT_EQ(2U, uuids.size()); | 2224 ASSERT_EQ(2U, uuids.size()); |
| 2215 ASSERT_EQ(uuids[0], BluetoothUUID("1800")); | 2225 ASSERT_EQ(uuids[0], BluetoothUUID("1800")); |
| 2216 ASSERT_EQ(uuids[1], BluetoothUUID("1801")); | 2226 ASSERT_EQ(uuids[1], BluetoothUUID("1801")); |
| 2217 | 2227 |
| 2218 // Install an observer; expect the DeviceChanged method to be called when | 2228 // Install an observer; expect the DeviceChanged method to be called when |
| 2219 // we change the class of the device. | 2229 // we change the class of the device. |
| 2220 TestBluetoothAdapterObserver observer(adapter_); | 2230 TestBluetoothAdapterObserver observer(adapter_); |
| 2221 | 2231 |
| 2222 FakeBluetoothDeviceClient::Properties* properties = | 2232 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2223 fake_bluetooth_device_client_->GetProperties( | 2233 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2224 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2234 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2225 | 2235 |
| 2226 std::vector<std::string> new_uuids; | 2236 std::vector<std::string> new_uuids; |
| 2227 new_uuids.push_back(uuids[0].canonical_value()); | 2237 new_uuids.push_back(uuids[0].canonical_value()); |
| 2228 new_uuids.push_back(uuids[1].canonical_value()); | 2238 new_uuids.push_back(uuids[1].canonical_value()); |
| 2229 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); | 2239 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); |
| 2230 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); | 2240 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); |
| 2231 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); | 2241 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); |
| 2232 | 2242 |
| 2233 properties->uuids.ReplaceValue(new_uuids); | 2243 properties->uuids.ReplaceValue(new_uuids); |
| 2234 | 2244 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2245 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); | 2255 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); |
| 2246 } | 2256 } |
| 2247 | 2257 |
| 2248 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { | 2258 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { |
| 2249 // Simulate invalidation of inquiry RSSI of a device, as it occurs | 2259 // Simulate invalidation of inquiry RSSI of a device, as it occurs |
| 2250 // when discovery is finished. | 2260 // when discovery is finished. |
| 2251 GetAdapter(); | 2261 GetAdapter(); |
| 2252 | 2262 |
| 2253 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2263 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2254 ASSERT_EQ(2U, devices.size()); | 2264 ASSERT_EQ(2U, devices.size()); |
| 2255 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2265 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2256 devices[0]->GetAddress()); | 2266 devices[0]->GetAddress()); |
| 2257 | 2267 |
| 2258 FakeBluetoothDeviceClient::Properties* properties = | 2268 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2259 fake_bluetooth_device_client_->GetProperties( | 2269 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2260 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2270 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2261 | 2271 |
| 2262 // During discovery, rssi is a valid value (-75) | 2272 // During discovery, rssi is a valid value (-75) |
| 2263 properties->rssi.ReplaceValue(-75); | 2273 properties->rssi.ReplaceValue(-75); |
| 2264 properties->rssi.set_valid(true); | 2274 properties->rssi.set_valid(true); |
| 2265 | 2275 |
| 2266 ASSERT_EQ(-75, devices[0]->GetInquiryRSSI()); | 2276 ASSERT_EQ(-75, devices[0]->GetInquiryRSSI()); |
| 2267 | 2277 |
| 2268 // Install an observer; expect the DeviceChanged method to be called when | 2278 // Install an observer; expect the DeviceChanged method to be called when |
| 2269 // we invalidate the RSSI of the device. | 2279 // we invalidate the RSSI of the device. |
| 2270 TestBluetoothAdapterObserver observer(adapter_); | 2280 TestBluetoothAdapterObserver observer(adapter_); |
| 2271 | 2281 |
| 2272 // When discovery is over, the value should be invalidated. | 2282 // When discovery is over, the value should be invalidated. |
| 2273 properties->rssi.set_valid(false); | 2283 properties->rssi.set_valid(false); |
| 2274 properties->NotifyPropertyChanged(properties->rssi.name()); | 2284 properties->NotifyPropertyChanged(properties->rssi.name()); |
| 2275 | 2285 |
| 2276 EXPECT_EQ(1, observer.device_changed_count()); | 2286 EXPECT_EQ(1, observer.device_changed_count()); |
| 2277 EXPECT_EQ(devices[0], observer.last_device()); | 2287 EXPECT_EQ(devices[0], observer.last_device()); |
| 2278 | 2288 |
| 2279 int unknown_power = BluetoothDevice::kUnknownPower; | 2289 int unknown_power = BluetoothDevice::kUnknownPower; |
| 2280 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); | 2290 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); |
| 2281 } | 2291 } |
| 2282 | 2292 |
| 2283 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { | 2293 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { |
| 2284 // Simulate invalidation of inquiry TxPower of a device, as it occurs | 2294 // Simulate invalidation of inquiry TxPower of a device, as it occurs |
| 2285 // when discovery is finished. | 2295 // when discovery is finished. |
| 2286 GetAdapter(); | 2296 GetAdapter(); |
| 2287 | 2297 |
| 2288 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2298 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2289 ASSERT_EQ(2U, devices.size()); | 2299 ASSERT_EQ(2U, devices.size()); |
| 2290 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2300 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2291 devices[0]->GetAddress()); | 2301 devices[0]->GetAddress()); |
| 2292 | 2302 |
| 2293 FakeBluetoothDeviceClient::Properties* properties = | 2303 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2294 fake_bluetooth_device_client_->GetProperties( | 2304 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2295 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2305 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2296 | 2306 |
| 2297 // During discovery, tx_power is a valid value (0) | 2307 // During discovery, tx_power is a valid value (0) |
| 2298 properties->tx_power.ReplaceValue(0); | 2308 properties->tx_power.ReplaceValue(0); |
| 2299 properties->tx_power.set_valid(true); | 2309 properties->tx_power.set_valid(true); |
| 2300 | 2310 |
| 2301 ASSERT_EQ(0, devices[0]->GetInquiryTxPower()); | 2311 ASSERT_EQ(0, devices[0]->GetInquiryTxPower()); |
| 2302 | 2312 |
| 2303 // Install an observer; expect the DeviceChanged method to be called when | 2313 // Install an observer; expect the DeviceChanged method to be called when |
| 2304 // we invalidate the tx_power of the device. | 2314 // we invalidate the tx_power of the device. |
| 2305 TestBluetoothAdapterObserver observer(adapter_); | 2315 TestBluetoothAdapterObserver observer(adapter_); |
| 2306 | 2316 |
| 2307 // When discovery is over, the value should be invalidated. | 2317 // When discovery is over, the value should be invalidated. |
| 2308 properties->tx_power.set_valid(false); | 2318 properties->tx_power.set_valid(false); |
| 2309 properties->NotifyPropertyChanged(properties->tx_power.name()); | 2319 properties->NotifyPropertyChanged(properties->tx_power.name()); |
| 2310 | 2320 |
| 2311 EXPECT_EQ(1, observer.device_changed_count()); | 2321 EXPECT_EQ(1, observer.device_changed_count()); |
| 2312 EXPECT_EQ(devices[0], observer.last_device()); | 2322 EXPECT_EQ(devices[0], observer.last_device()); |
| 2313 | 2323 |
| 2314 int unknown_power = BluetoothDevice::kUnknownPower; | 2324 int unknown_power = BluetoothDevice::kUnknownPower; |
| 2315 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); | 2325 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); |
| 2316 } | 2326 } |
| 2317 | 2327 |
| 2318 TEST_F(BluetoothChromeOSTest, ForgetDevice) { | 2328 TEST_F(BluetoothChromeOSTest, ForgetDevice) { |
| 2319 GetAdapter(); | 2329 GetAdapter(); |
| 2320 | 2330 |
| 2321 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2331 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2322 ASSERT_EQ(2U, devices.size()); | 2332 ASSERT_EQ(2U, devices.size()); |
| 2323 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2333 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2324 devices[0]->GetAddress()); | 2334 devices[0]->GetAddress()); |
| 2325 | 2335 |
| 2326 std::string address = devices[0]->GetAddress(); | 2336 std::string address = devices[0]->GetAddress(); |
| 2327 | 2337 |
| 2328 // Install an observer; expect the DeviceRemoved method to be called | 2338 // Install an observer; expect the DeviceRemoved method to be called |
| 2329 // with the device we remove. | 2339 // with the device we remove. |
| 2330 TestBluetoothAdapterObserver observer(adapter_); | 2340 TestBluetoothAdapterObserver observer(adapter_); |
| 2331 | 2341 |
| 2332 devices[0]->Forget(GetErrorCallback()); | 2342 devices[0]->Forget(GetErrorCallback()); |
| 2333 EXPECT_EQ(0, error_callback_count_); | 2343 EXPECT_EQ(0, error_callback_count_); |
| 2334 | 2344 |
| 2335 EXPECT_EQ(1, observer.device_removed_count()); | 2345 EXPECT_EQ(1, observer.device_removed_count()); |
| 2336 EXPECT_EQ(address, observer.last_device_address()); | 2346 EXPECT_EQ(address, observer.last_device_address()); |
| 2337 | 2347 |
| 2338 // GetDevices shouldn't return the device either. | 2348 // GetDevices shouldn't return the device either. |
| 2339 devices = adapter_->GetDevices(); | 2349 devices = adapter_->GetDevices(); |
| 2340 ASSERT_EQ(1U, devices.size()); | 2350 ASSERT_EQ(1U, devices.size()); |
| 2341 } | 2351 } |
| 2342 | 2352 |
| 2343 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { | 2353 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { |
| 2344 GetAdapter(); | 2354 GetAdapter(); |
| 2345 DiscoverDevices(); | 2355 DiscoverDevices(); |
| 2346 | 2356 |
| 2347 BluetoothDevice* device = adapter_->GetDevice( | 2357 BluetoothDevice* device = adapter_->GetDevice( |
| 2348 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2358 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 2349 ASSERT_TRUE(device != nullptr); | 2359 ASSERT_TRUE(device != nullptr); |
| 2350 ASSERT_FALSE(device->IsPaired()); | 2360 ASSERT_FALSE(device->IsPaired()); |
| 2351 | 2361 |
| 2352 // Connect the device so it becomes trusted and remembered. | 2362 // Connect the device so it becomes trusted and remembered. |
| 2353 device->Connect(nullptr, GetCallback(), | 2363 device->Connect(nullptr, GetCallback(), |
| 2354 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2364 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2355 base::Unretained(this))); | 2365 base::Unretained(this))); |
| 2356 | 2366 |
| 2357 ASSERT_EQ(1, callback_count_); | 2367 ASSERT_EQ(1, callback_count_); |
| 2358 ASSERT_EQ(0, error_callback_count_); | 2368 ASSERT_EQ(0, error_callback_count_); |
| 2359 callback_count_ = 0; | 2369 callback_count_ = 0; |
| 2360 | 2370 |
| 2361 ASSERT_TRUE(device->IsConnected()); | 2371 ASSERT_TRUE(device->IsConnected()); |
| 2362 ASSERT_FALSE(device->IsConnecting()); | 2372 ASSERT_FALSE(device->IsConnecting()); |
| 2363 | 2373 |
| 2364 // Make sure the trusted property has been set to true. | 2374 // Make sure the trusted property has been set to true. |
| 2365 FakeBluetoothDeviceClient::Properties* properties = | 2375 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2366 fake_bluetooth_device_client_->GetProperties( | 2376 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2367 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); | 2377 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); |
| 2368 ASSERT_TRUE(properties->trusted.value()); | 2378 ASSERT_TRUE(properties->trusted.value()); |
| 2369 | 2379 |
| 2370 // Install an observer; expect the DeviceRemoved method to be called | 2380 // Install an observer; expect the DeviceRemoved method to be called |
| 2371 // with the device we remove. | 2381 // with the device we remove. |
| 2372 TestBluetoothAdapterObserver observer(adapter_); | 2382 TestBluetoothAdapterObserver observer(adapter_); |
| 2373 | 2383 |
| 2374 device->Forget(GetErrorCallback()); | 2384 device->Forget(GetErrorCallback()); |
| 2375 EXPECT_EQ(0, error_callback_count_); | 2385 EXPECT_EQ(0, error_callback_count_); |
| 2376 | 2386 |
| 2377 EXPECT_EQ(1, observer.device_removed_count()); | 2387 EXPECT_EQ(1, observer.device_removed_count()); |
| 2378 EXPECT_EQ(FakeBluetoothDeviceClient::kConnectUnpairableAddress, | 2388 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress, |
| 2379 observer.last_device_address()); | 2389 observer.last_device_address()); |
| 2380 | 2390 |
| 2381 // GetDevices shouldn't return the device either. | 2391 // GetDevices shouldn't return the device either. |
| 2382 device = adapter_->GetDevice( | 2392 device = adapter_->GetDevice( |
| 2383 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2393 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 2384 EXPECT_FALSE(device != nullptr); | 2394 EXPECT_FALSE(device != nullptr); |
| 2385 } | 2395 } |
| 2386 | 2396 |
| 2387 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { | 2397 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { |
| 2388 GetAdapter(); | 2398 GetAdapter(); |
| 2389 | 2399 |
| 2390 BluetoothDevice* device = adapter_->GetDevice( | 2400 BluetoothDevice* device = adapter_->GetDevice( |
| 2391 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2401 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2392 ASSERT_TRUE(device != nullptr); | 2402 ASSERT_TRUE(device != nullptr); |
| 2393 ASSERT_TRUE(device->IsPaired()); | 2403 ASSERT_TRUE(device->IsPaired()); |
| 2394 | 2404 |
| 2395 TestBluetoothAdapterObserver observer(adapter_); | 2405 TestBluetoothAdapterObserver observer(adapter_); |
| 2396 | 2406 |
| 2397 // Connect without a pairing delegate; since the device is already Paired | 2407 // Connect without a pairing delegate; since the device is already Paired |
| 2398 // this should succeed and the device should become connected. | 2408 // this should succeed and the device should become connected. |
| 2399 device->Connect(nullptr, GetCallback(), | 2409 device->Connect(nullptr, GetCallback(), |
| 2400 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2410 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2401 base::Unretained(this))); | 2411 base::Unretained(this))); |
| 2402 | 2412 |
| 2403 EXPECT_EQ(1, callback_count_); | 2413 EXPECT_EQ(1, callback_count_); |
| 2404 EXPECT_EQ(0, error_callback_count_); | 2414 EXPECT_EQ(0, error_callback_count_); |
| 2405 | 2415 |
| 2406 // Two changes for connecting, one for connected and one for for trusted | 2416 // Two changes for connecting, one for connected and one for for trusted |
| 2407 // after connecting. | 2417 // after connecting. |
| 2408 EXPECT_EQ(4, observer.device_changed_count()); | 2418 EXPECT_EQ(4, observer.device_changed_count()); |
| 2409 EXPECT_EQ(device, observer.last_device()); | 2419 EXPECT_EQ(device, observer.last_device()); |
| 2410 | 2420 |
| 2411 EXPECT_TRUE(device->IsConnected()); | 2421 EXPECT_TRUE(device->IsConnected()); |
| 2412 EXPECT_FALSE(device->IsConnecting()); | 2422 EXPECT_FALSE(device->IsConnecting()); |
| 2413 } | 2423 } |
| 2414 | 2424 |
| 2415 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { | 2425 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { |
| 2416 GetAdapter(); | 2426 GetAdapter(); |
| 2417 DiscoverDevices(); | 2427 DiscoverDevices(); |
| 2418 | 2428 |
| 2419 BluetoothDevice* device = adapter_->GetDevice( | 2429 BluetoothDevice* device = adapter_->GetDevice( |
| 2420 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2430 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 2421 ASSERT_TRUE(device != nullptr); | 2431 ASSERT_TRUE(device != nullptr); |
| 2422 ASSERT_FALSE(device->IsPaired()); | 2432 ASSERT_FALSE(device->IsPaired()); |
| 2423 | 2433 |
| 2424 TestBluetoothAdapterObserver observer(adapter_); | 2434 TestBluetoothAdapterObserver observer(adapter_); |
| 2425 | 2435 |
| 2426 // Connect without a pairing delegate; since the device does not require | 2436 // Connect without a pairing delegate; since the device does not require |
| 2427 // pairing, this should succeed and the device should become connected. | 2437 // pairing, this should succeed and the device should become connected. |
| 2428 device->Connect(nullptr, GetCallback(), | 2438 device->Connect(nullptr, GetCallback(), |
| 2429 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2439 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2430 base::Unretained(this))); | 2440 base::Unretained(this))); |
| 2431 | 2441 |
| 2432 EXPECT_EQ(1, callback_count_); | 2442 EXPECT_EQ(1, callback_count_); |
| 2433 EXPECT_EQ(0, error_callback_count_); | 2443 EXPECT_EQ(0, error_callback_count_); |
| 2434 | 2444 |
| 2435 // Two changes for connecting, one for connected, one for for trusted after | 2445 // Two changes for connecting, one for connected, one for for trusted after |
| 2436 // connection, and one for the reconnect mode (IsConnectable). | 2446 // connection, and one for the reconnect mode (IsConnectable). |
| 2437 EXPECT_EQ(5, observer.device_changed_count()); | 2447 EXPECT_EQ(5, observer.device_changed_count()); |
| 2438 EXPECT_EQ(device, observer.last_device()); | 2448 EXPECT_EQ(device, observer.last_device()); |
| 2439 | 2449 |
| 2440 EXPECT_TRUE(device->IsConnected()); | 2450 EXPECT_TRUE(device->IsConnected()); |
| 2441 EXPECT_FALSE(device->IsConnecting()); | 2451 EXPECT_FALSE(device->IsConnecting()); |
| 2442 | 2452 |
| 2443 // Make sure the trusted property has been set to true. | 2453 // Make sure the trusted property has been set to true. |
| 2444 FakeBluetoothDeviceClient::Properties* properties = | 2454 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2445 fake_bluetooth_device_client_->GetProperties( | 2455 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2446 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); | 2456 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); |
| 2447 EXPECT_TRUE(properties->trusted.value()); | 2457 EXPECT_TRUE(properties->trusted.value()); |
| 2448 | 2458 |
| 2449 // Verify is a HID device and is not connectable. | 2459 // Verify is a HID device and is not connectable. |
| 2450 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2460 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2451 ASSERT_EQ(1U, uuids.size()); | 2461 ASSERT_EQ(1U, uuids.size()); |
| 2452 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2462 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2453 EXPECT_FALSE(device->IsConnectable()); | 2463 EXPECT_FALSE(device->IsConnectable()); |
| 2454 } | 2464 } |
| 2455 | 2465 |
| 2456 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { | 2466 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { |
| 2457 GetAdapter(); | 2467 GetAdapter(); |
| 2458 | 2468 |
| 2459 BluetoothDevice* device = adapter_->GetDevice( | 2469 BluetoothDevice* device = adapter_->GetDevice( |
| 2460 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2470 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2461 ASSERT_TRUE(device != nullptr); | 2471 ASSERT_TRUE(device != nullptr); |
| 2462 ASSERT_TRUE(device->IsPaired()); | 2472 ASSERT_TRUE(device->IsPaired()); |
| 2463 | 2473 |
| 2464 device->Connect(nullptr, GetCallback(), | 2474 device->Connect(nullptr, GetCallback(), |
| 2465 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2475 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2466 base::Unretained(this))); | 2476 base::Unretained(this))); |
| 2467 | 2477 |
| 2468 ASSERT_EQ(1, callback_count_); | 2478 ASSERT_EQ(1, callback_count_); |
| 2469 ASSERT_EQ(0, error_callback_count_); | 2479 ASSERT_EQ(0, error_callback_count_); |
| 2470 callback_count_ = 0; | 2480 callback_count_ = 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2488 | 2498 |
| 2489 EXPECT_TRUE(device->IsConnected()); | 2499 EXPECT_TRUE(device->IsConnected()); |
| 2490 EXPECT_FALSE(device->IsConnecting()); | 2500 EXPECT_FALSE(device->IsConnecting()); |
| 2491 } | 2501 } |
| 2492 | 2502 |
| 2493 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { | 2503 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { |
| 2494 GetAdapter(); | 2504 GetAdapter(); |
| 2495 DiscoverDevices(); | 2505 DiscoverDevices(); |
| 2496 | 2506 |
| 2497 BluetoothDevice* device = adapter_->GetDevice( | 2507 BluetoothDevice* device = adapter_->GetDevice( |
| 2498 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2508 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 2499 ASSERT_TRUE(device != nullptr); | 2509 ASSERT_TRUE(device != nullptr); |
| 2500 ASSERT_FALSE(device->IsPaired()); | 2510 ASSERT_FALSE(device->IsPaired()); |
| 2501 | 2511 |
| 2502 TestBluetoothAdapterObserver observer(adapter_); | 2512 TestBluetoothAdapterObserver observer(adapter_); |
| 2503 | 2513 |
| 2504 // Connect without a pairing delegate; since the device requires pairing, | 2514 // Connect without a pairing delegate; since the device requires pairing, |
| 2505 // this should fail with an error. | 2515 // this should fail with an error. |
| 2506 device->Connect(nullptr, GetCallback(), | 2516 device->Connect(nullptr, GetCallback(), |
| 2507 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2517 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2508 base::Unretained(this))); | 2518 base::Unretained(this))); |
| 2509 | 2519 |
| 2510 EXPECT_EQ(0, callback_count_); | 2520 EXPECT_EQ(0, callback_count_); |
| 2511 EXPECT_EQ(1, error_callback_count_); | 2521 EXPECT_EQ(1, error_callback_count_); |
| 2512 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 2522 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
| 2513 | 2523 |
| 2514 EXPECT_EQ(2, observer.device_changed_count()); | 2524 EXPECT_EQ(2, observer.device_changed_count()); |
| 2515 | 2525 |
| 2516 EXPECT_FALSE(device->IsConnected()); | 2526 EXPECT_FALSE(device->IsConnected()); |
| 2517 EXPECT_FALSE(device->IsConnecting()); | 2527 EXPECT_FALSE(device->IsConnecting()); |
| 2518 } | 2528 } |
| 2519 | 2529 |
| 2520 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { | 2530 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { |
| 2521 GetAdapter(); | 2531 GetAdapter(); |
| 2522 | 2532 |
| 2523 BluetoothDevice* device = adapter_->GetDevice( | 2533 BluetoothDevice* device = adapter_->GetDevice( |
| 2524 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2534 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2525 ASSERT_TRUE(device != nullptr); | 2535 ASSERT_TRUE(device != nullptr); |
| 2526 ASSERT_TRUE(device->IsPaired()); | 2536 ASSERT_TRUE(device->IsPaired()); |
| 2527 | 2537 |
| 2528 device->Connect(nullptr, GetCallback(), | 2538 device->Connect(nullptr, GetCallback(), |
| 2529 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2539 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2530 base::Unretained(this))); | 2540 base::Unretained(this))); |
| 2531 | 2541 |
| 2532 ASSERT_EQ(1, callback_count_); | 2542 ASSERT_EQ(1, callback_count_); |
| 2533 ASSERT_EQ(0, error_callback_count_); | 2543 ASSERT_EQ(0, error_callback_count_); |
| 2534 callback_count_ = 0; | 2544 callback_count_ = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2548 EXPECT_EQ(1, observer.device_changed_count()); | 2558 EXPECT_EQ(1, observer.device_changed_count()); |
| 2549 EXPECT_EQ(device, observer.last_device()); | 2559 EXPECT_EQ(device, observer.last_device()); |
| 2550 | 2560 |
| 2551 EXPECT_FALSE(device->IsConnected()); | 2561 EXPECT_FALSE(device->IsConnected()); |
| 2552 } | 2562 } |
| 2553 | 2563 |
| 2554 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { | 2564 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { |
| 2555 GetAdapter(); | 2565 GetAdapter(); |
| 2556 | 2566 |
| 2557 BluetoothDevice* device = adapter_->GetDevice( | 2567 BluetoothDevice* device = adapter_->GetDevice( |
| 2558 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2568 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2559 ASSERT_TRUE(device != nullptr); | 2569 ASSERT_TRUE(device != nullptr); |
| 2560 ASSERT_TRUE(device->IsPaired()); | 2570 ASSERT_TRUE(device->IsPaired()); |
| 2561 ASSERT_FALSE(device->IsConnected()); | 2571 ASSERT_FALSE(device->IsConnected()); |
| 2562 | 2572 |
| 2563 // Disconnect the device, we should see the observer method fire and the | 2573 // Disconnect the device, we should see the observer method fire and the |
| 2564 // device get dropped. | 2574 // device get dropped. |
| 2565 TestBluetoothAdapterObserver observer(adapter_); | 2575 TestBluetoothAdapterObserver observer(adapter_); |
| 2566 | 2576 |
| 2567 device->Disconnect(GetCallback(), GetErrorCallback()); | 2577 device->Disconnect(GetCallback(), GetErrorCallback()); |
| 2568 | 2578 |
| 2569 EXPECT_EQ(0, callback_count_); | 2579 EXPECT_EQ(0, callback_count_); |
| 2570 EXPECT_EQ(1, error_callback_count_); | 2580 EXPECT_EQ(1, error_callback_count_); |
| 2571 | 2581 |
| 2572 EXPECT_EQ(0, observer.device_changed_count()); | 2582 EXPECT_EQ(0, observer.device_changed_count()); |
| 2573 | 2583 |
| 2574 EXPECT_FALSE(device->IsConnected()); | 2584 EXPECT_FALSE(device->IsConnected()); |
| 2575 } | 2585 } |
| 2576 | 2586 |
| 2577 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { | 2587 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { |
| 2578 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2588 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2579 | 2589 |
| 2580 GetAdapter(); | 2590 GetAdapter(); |
| 2581 DiscoverDevices(); | 2591 DiscoverDevices(); |
| 2582 | 2592 |
| 2583 // The Legacy Autopair device requires no PIN or Passkey to pair because | 2593 // The Legacy Autopair device requires no PIN or Passkey to pair because |
| 2584 // the daemon provides 0000 to the device for us. | 2594 // the daemon provides 0000 to the device for us. |
| 2585 BluetoothDevice* device = adapter_->GetDevice( | 2595 BluetoothDevice* device = adapter_->GetDevice( |
| 2586 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2596 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 2587 ASSERT_TRUE(device != nullptr); | 2597 ASSERT_TRUE(device != nullptr); |
| 2588 ASSERT_FALSE(device->IsPaired()); | 2598 ASSERT_FALSE(device->IsPaired()); |
| 2589 | 2599 |
| 2590 TestBluetoothAdapterObserver observer(adapter_); | 2600 TestBluetoothAdapterObserver observer(adapter_); |
| 2591 | 2601 |
| 2592 TestPairingDelegate pairing_delegate; | 2602 TestPairingDelegate pairing_delegate; |
| 2593 device->Connect(&pairing_delegate, GetCallback(), | 2603 device->Connect(&pairing_delegate, GetCallback(), |
| 2594 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2604 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2595 base::Unretained(this))); | 2605 base::Unretained(this))); |
| 2596 | 2606 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2613 | 2623 |
| 2614 EXPECT_TRUE(device->IsPaired()); | 2624 EXPECT_TRUE(device->IsPaired()); |
| 2615 | 2625 |
| 2616 // Verify is a HID device and is connectable. | 2626 // Verify is a HID device and is connectable. |
| 2617 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2627 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2618 ASSERT_EQ(1U, uuids.size()); | 2628 ASSERT_EQ(1U, uuids.size()); |
| 2619 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2629 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2620 EXPECT_TRUE(device->IsConnectable()); | 2630 EXPECT_TRUE(device->IsConnectable()); |
| 2621 | 2631 |
| 2622 // Make sure the trusted property has been set to true. | 2632 // Make sure the trusted property has been set to true. |
| 2623 FakeBluetoothDeviceClient::Properties* properties = | 2633 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2624 fake_bluetooth_device_client_->GetProperties( | 2634 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2625 dbus::ObjectPath(FakeBluetoothDeviceClient::kLegacyAutopairPath)); | 2635 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); |
| 2626 EXPECT_TRUE(properties->trusted.value()); | 2636 EXPECT_TRUE(properties->trusted.value()); |
| 2627 } | 2637 } |
| 2628 | 2638 |
| 2629 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { | 2639 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { |
| 2630 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2640 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2631 | 2641 |
| 2632 GetAdapter(); | 2642 GetAdapter(); |
| 2633 DiscoverDevices(); | 2643 DiscoverDevices(); |
| 2634 | 2644 |
| 2635 // Requires that we display a randomly generated PIN on the screen. | 2645 // Requires that we display a randomly generated PIN on the screen. |
| 2636 BluetoothDevice* device = adapter_->GetDevice( | 2646 BluetoothDevice* device = adapter_->GetDevice( |
| 2637 FakeBluetoothDeviceClient::kDisplayPinCodeAddress); | 2647 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress); |
| 2638 ASSERT_TRUE(device != nullptr); | 2648 ASSERT_TRUE(device != nullptr); |
| 2639 ASSERT_FALSE(device->IsPaired()); | 2649 ASSERT_FALSE(device->IsPaired()); |
| 2640 | 2650 |
| 2641 TestBluetoothAdapterObserver observer(adapter_); | 2651 TestBluetoothAdapterObserver observer(adapter_); |
| 2642 | 2652 |
| 2643 TestPairingDelegate pairing_delegate; | 2653 TestPairingDelegate pairing_delegate; |
| 2644 device->Connect(&pairing_delegate, GetCallback(), | 2654 device->Connect(&pairing_delegate, GetCallback(), |
| 2645 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2655 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2646 base::Unretained(this))); | 2656 base::Unretained(this))); |
| 2647 | 2657 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2666 | 2676 |
| 2667 EXPECT_TRUE(device->IsPaired()); | 2677 EXPECT_TRUE(device->IsPaired()); |
| 2668 | 2678 |
| 2669 // Verify is a HID device and is connectable. | 2679 // Verify is a HID device and is connectable. |
| 2670 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2680 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2671 ASSERT_EQ(1U, uuids.size()); | 2681 ASSERT_EQ(1U, uuids.size()); |
| 2672 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2682 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2673 EXPECT_TRUE(device->IsConnectable()); | 2683 EXPECT_TRUE(device->IsConnectable()); |
| 2674 | 2684 |
| 2675 // Make sure the trusted property has been set to true. | 2685 // Make sure the trusted property has been set to true. |
| 2676 FakeBluetoothDeviceClient::Properties* properties = | 2686 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2677 fake_bluetooth_device_client_->GetProperties( | 2687 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2678 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPinCodePath)); | 2688 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); |
| 2679 EXPECT_TRUE(properties->trusted.value()); | 2689 EXPECT_TRUE(properties->trusted.value()); |
| 2680 } | 2690 } |
| 2681 | 2691 |
| 2682 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { | 2692 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { |
| 2683 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2693 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2684 | 2694 |
| 2685 GetAdapter(); | 2695 GetAdapter(); |
| 2686 DiscoverDevices(); | 2696 DiscoverDevices(); |
| 2687 | 2697 |
| 2688 // Requires that we display a randomly generated Passkey on the screen, | 2698 // Requires that we display a randomly generated Passkey on the screen, |
| 2689 // and notifies us as it's typed in. | 2699 // and notifies us as it's typed in. |
| 2690 BluetoothDevice* device = adapter_->GetDevice( | 2700 BluetoothDevice* device = adapter_->GetDevice( |
| 2691 FakeBluetoothDeviceClient::kDisplayPasskeyAddress); | 2701 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress); |
| 2692 ASSERT_TRUE(device != nullptr); | 2702 ASSERT_TRUE(device != nullptr); |
| 2693 ASSERT_FALSE(device->IsPaired()); | 2703 ASSERT_FALSE(device->IsPaired()); |
| 2694 | 2704 |
| 2695 TestBluetoothAdapterObserver observer(adapter_); | 2705 TestBluetoothAdapterObserver observer(adapter_); |
| 2696 | 2706 |
| 2697 TestPairingDelegate pairing_delegate; | 2707 TestPairingDelegate pairing_delegate; |
| 2698 device->Connect(&pairing_delegate, GetCallback(), | 2708 device->Connect(&pairing_delegate, GetCallback(), |
| 2699 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2709 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2700 base::Unretained(this))); | 2710 base::Unretained(this))); |
| 2701 | 2711 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2741 | 2751 |
| 2742 // Verify is a HID device. | 2752 // Verify is a HID device. |
| 2743 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2753 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2744 ASSERT_EQ(1U, uuids.size()); | 2754 ASSERT_EQ(1U, uuids.size()); |
| 2745 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2755 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2746 | 2756 |
| 2747 // And usually not connectable. | 2757 // And usually not connectable. |
| 2748 EXPECT_FALSE(device->IsConnectable()); | 2758 EXPECT_FALSE(device->IsConnectable()); |
| 2749 | 2759 |
| 2750 // Make sure the trusted property has been set to true. | 2760 // Make sure the trusted property has been set to true. |
| 2751 FakeBluetoothDeviceClient::Properties* properties = | 2761 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2752 fake_bluetooth_device_client_->GetProperties( | 2762 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2753 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPasskeyPath)); | 2763 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); |
| 2754 EXPECT_TRUE(properties->trusted.value()); | 2764 EXPECT_TRUE(properties->trusted.value()); |
| 2755 } | 2765 } |
| 2756 | 2766 |
| 2757 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { | 2767 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { |
| 2758 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2768 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2759 | 2769 |
| 2760 GetAdapter(); | 2770 GetAdapter(); |
| 2761 DiscoverDevices(); | 2771 DiscoverDevices(); |
| 2762 | 2772 |
| 2763 // Requires that the user enters a PIN for them. | 2773 // Requires that the user enters a PIN for them. |
| 2764 BluetoothDevice* device = adapter_->GetDevice( | 2774 BluetoothDevice* device = adapter_->GetDevice( |
| 2765 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2775 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 2766 ASSERT_TRUE(device != nullptr); | 2776 ASSERT_TRUE(device != nullptr); |
| 2767 ASSERT_FALSE(device->IsPaired()); | 2777 ASSERT_FALSE(device->IsPaired()); |
| 2768 | 2778 |
| 2769 TestBluetoothAdapterObserver observer(adapter_); | 2779 TestBluetoothAdapterObserver observer(adapter_); |
| 2770 | 2780 |
| 2771 TestPairingDelegate pairing_delegate; | 2781 TestPairingDelegate pairing_delegate; |
| 2772 device->Connect(&pairing_delegate, GetCallback(), | 2782 device->Connect(&pairing_delegate, GetCallback(), |
| 2773 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2783 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2774 base::Unretained(this))); | 2784 base::Unretained(this))); |
| 2775 | 2785 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2795 EXPECT_TRUE(device->IsPaired()); | 2805 EXPECT_TRUE(device->IsPaired()); |
| 2796 | 2806 |
| 2797 // Verify is not a HID device. | 2807 // Verify is not a HID device. |
| 2798 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2808 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2799 ASSERT_EQ(0U, uuids.size()); | 2809 ASSERT_EQ(0U, uuids.size()); |
| 2800 | 2810 |
| 2801 // Non HID devices are always connectable. | 2811 // Non HID devices are always connectable. |
| 2802 EXPECT_TRUE(device->IsConnectable()); | 2812 EXPECT_TRUE(device->IsConnectable()); |
| 2803 | 2813 |
| 2804 // Make sure the trusted property has been set to true. | 2814 // Make sure the trusted property has been set to true. |
| 2805 FakeBluetoothDeviceClient::Properties* properties = | 2815 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2806 fake_bluetooth_device_client_->GetProperties( | 2816 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2807 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 2817 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 2808 EXPECT_TRUE(properties->trusted.value()); | 2818 EXPECT_TRUE(properties->trusted.value()); |
| 2809 } | 2819 } |
| 2810 | 2820 |
| 2811 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { | 2821 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { |
| 2812 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2822 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2813 | 2823 |
| 2814 GetAdapter(); | 2824 GetAdapter(); |
| 2815 DiscoverDevices(); | 2825 DiscoverDevices(); |
| 2816 | 2826 |
| 2817 // Requests that we confirm a displayed passkey. | 2827 // Requests that we confirm a displayed passkey. |
| 2818 BluetoothDevice* device = adapter_->GetDevice( | 2828 BluetoothDevice* device = adapter_->GetDevice( |
| 2819 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2829 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 2820 ASSERT_TRUE(device != nullptr); | 2830 ASSERT_TRUE(device != nullptr); |
| 2821 ASSERT_FALSE(device->IsPaired()); | 2831 ASSERT_FALSE(device->IsPaired()); |
| 2822 | 2832 |
| 2823 TestBluetoothAdapterObserver observer(adapter_); | 2833 TestBluetoothAdapterObserver observer(adapter_); |
| 2824 | 2834 |
| 2825 TestPairingDelegate pairing_delegate; | 2835 TestPairingDelegate pairing_delegate; |
| 2826 device->Connect(&pairing_delegate, GetCallback(), | 2836 device->Connect(&pairing_delegate, GetCallback(), |
| 2827 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2837 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2828 base::Unretained(this))); | 2838 base::Unretained(this))); |
| 2829 | 2839 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2846 | 2856 |
| 2847 EXPECT_TRUE(device->IsConnected()); | 2857 EXPECT_TRUE(device->IsConnected()); |
| 2848 EXPECT_FALSE(device->IsConnecting()); | 2858 EXPECT_FALSE(device->IsConnecting()); |
| 2849 | 2859 |
| 2850 EXPECT_TRUE(device->IsPaired()); | 2860 EXPECT_TRUE(device->IsPaired()); |
| 2851 | 2861 |
| 2852 // Non HID devices are always connectable. | 2862 // Non HID devices are always connectable. |
| 2853 EXPECT_TRUE(device->IsConnectable()); | 2863 EXPECT_TRUE(device->IsConnectable()); |
| 2854 | 2864 |
| 2855 // Make sure the trusted property has been set to true. | 2865 // Make sure the trusted property has been set to true. |
| 2856 FakeBluetoothDeviceClient::Properties* properties = | 2866 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2857 fake_bluetooth_device_client_->GetProperties( | 2867 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2858 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 2868 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 2859 EXPECT_TRUE(properties->trusted.value()); | 2869 EXPECT_TRUE(properties->trusted.value()); |
| 2860 } | 2870 } |
| 2861 | 2871 |
| 2862 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { | 2872 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { |
| 2863 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2873 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2864 | 2874 |
| 2865 GetAdapter(); | 2875 GetAdapter(); |
| 2866 DiscoverDevices(); | 2876 DiscoverDevices(); |
| 2867 | 2877 |
| 2868 // Requires that the user enters a Passkey, this would be some kind of | 2878 // Requires that the user enters a Passkey, this would be some kind of |
| 2869 // device that has a display, but doesn't use "just works" - maybe a car? | 2879 // device that has a display, but doesn't use "just works" - maybe a car? |
| 2870 BluetoothDevice* device = adapter_->GetDevice( | 2880 BluetoothDevice* device = adapter_->GetDevice( |
| 2871 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2881 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 2872 ASSERT_TRUE(device != nullptr); | 2882 ASSERT_TRUE(device != nullptr); |
| 2873 ASSERT_FALSE(device->IsPaired()); | 2883 ASSERT_FALSE(device->IsPaired()); |
| 2874 | 2884 |
| 2875 TestBluetoothAdapterObserver observer(adapter_); | 2885 TestBluetoothAdapterObserver observer(adapter_); |
| 2876 | 2886 |
| 2877 TestPairingDelegate pairing_delegate; | 2887 TestPairingDelegate pairing_delegate; |
| 2878 device->Connect(&pairing_delegate, GetCallback(), | 2888 device->Connect(&pairing_delegate, GetCallback(), |
| 2879 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2889 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2880 base::Unretained(this))); | 2890 base::Unretained(this))); |
| 2881 | 2891 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2897 | 2907 |
| 2898 EXPECT_TRUE(device->IsConnected()); | 2908 EXPECT_TRUE(device->IsConnected()); |
| 2899 EXPECT_FALSE(device->IsConnecting()); | 2909 EXPECT_FALSE(device->IsConnecting()); |
| 2900 | 2910 |
| 2901 EXPECT_TRUE(device->IsPaired()); | 2911 EXPECT_TRUE(device->IsPaired()); |
| 2902 | 2912 |
| 2903 // Non HID devices are always connectable. | 2913 // Non HID devices are always connectable. |
| 2904 EXPECT_TRUE(device->IsConnectable()); | 2914 EXPECT_TRUE(device->IsConnectable()); |
| 2905 | 2915 |
| 2906 // Make sure the trusted property has been set to true. | 2916 // Make sure the trusted property has been set to true. |
| 2907 FakeBluetoothDeviceClient::Properties* properties = | 2917 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2908 fake_bluetooth_device_client_->GetProperties( | 2918 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2909 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 2919 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 2910 EXPECT_TRUE(properties->trusted.value()); | 2920 EXPECT_TRUE(properties->trusted.value()); |
| 2911 } | 2921 } |
| 2912 | 2922 |
| 2913 TEST_F(BluetoothChromeOSTest, PairJustWorks) { | 2923 TEST_F(BluetoothChromeOSTest, PairJustWorks) { |
| 2914 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2924 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2915 | 2925 |
| 2916 GetAdapter(); | 2926 GetAdapter(); |
| 2917 DiscoverDevices(); | 2927 DiscoverDevices(); |
| 2918 | 2928 |
| 2919 // Uses just-works pairing, since this is an outgoing pairing, no delegate | 2929 // Uses just-works pairing, since this is an outgoing pairing, no delegate |
| 2920 // interaction is required. | 2930 // interaction is required. |
| 2921 BluetoothDevice* device = adapter_->GetDevice( | 2931 BluetoothDevice* device = |
| 2922 FakeBluetoothDeviceClient::kJustWorksAddress); | 2932 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
| 2923 ASSERT_TRUE(device != nullptr); | 2933 ASSERT_TRUE(device != nullptr); |
| 2924 ASSERT_FALSE(device->IsPaired()); | 2934 ASSERT_FALSE(device->IsPaired()); |
| 2925 | 2935 |
| 2926 TestBluetoothAdapterObserver observer(adapter_); | 2936 TestBluetoothAdapterObserver observer(adapter_); |
| 2927 | 2937 |
| 2928 TestPairingDelegate pairing_delegate; | 2938 TestPairingDelegate pairing_delegate; |
| 2929 device->Connect(&pairing_delegate, GetCallback(), | 2939 device->Connect(&pairing_delegate, GetCallback(), |
| 2930 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2940 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2931 base::Unretained(this))); | 2941 base::Unretained(this))); |
| 2932 | 2942 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2944 | 2954 |
| 2945 EXPECT_TRUE(device->IsConnected()); | 2955 EXPECT_TRUE(device->IsConnected()); |
| 2946 EXPECT_FALSE(device->IsConnecting()); | 2956 EXPECT_FALSE(device->IsConnecting()); |
| 2947 | 2957 |
| 2948 EXPECT_TRUE(device->IsPaired()); | 2958 EXPECT_TRUE(device->IsPaired()); |
| 2949 | 2959 |
| 2950 // Non HID devices are always connectable. | 2960 // Non HID devices are always connectable. |
| 2951 EXPECT_TRUE(device->IsConnectable()); | 2961 EXPECT_TRUE(device->IsConnectable()); |
| 2952 | 2962 |
| 2953 // Make sure the trusted property has been set to true. | 2963 // Make sure the trusted property has been set to true. |
| 2954 FakeBluetoothDeviceClient::Properties* properties = | 2964 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2955 fake_bluetooth_device_client_->GetProperties( | 2965 fake_bluetooth_device_client_->GetProperties( |
| 2956 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 2966 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 2957 EXPECT_TRUE(properties->trusted.value()); | 2967 EXPECT_TRUE(properties->trusted.value()); |
| 2958 } | 2968 } |
| 2959 | 2969 |
| 2960 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { | 2970 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { |
| 2961 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2971 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2962 | 2972 |
| 2963 GetAdapter(); | 2973 GetAdapter(); |
| 2964 DiscoverDevice(FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 2974 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
| 2965 | 2975 |
| 2966 BluetoothDevice* device = adapter_->GetDevice( | 2976 BluetoothDevice* device = adapter_->GetDevice( |
| 2967 FakeBluetoothDeviceClient::kUnpairableDeviceAddress); | 2977 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress); |
| 2968 ASSERT_TRUE(device != nullptr); | 2978 ASSERT_TRUE(device != nullptr); |
| 2969 ASSERT_FALSE(device->IsPaired()); | 2979 ASSERT_FALSE(device->IsPaired()); |
| 2970 | 2980 |
| 2971 TestBluetoothAdapterObserver observer(adapter_); | 2981 TestBluetoothAdapterObserver observer(adapter_); |
| 2972 | 2982 |
| 2973 TestPairingDelegate pairing_delegate; | 2983 TestPairingDelegate pairing_delegate; |
| 2974 device->Connect(&pairing_delegate, GetCallback(), | 2984 device->Connect(&pairing_delegate, GetCallback(), |
| 2975 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2985 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2976 base::Unretained(this))); | 2986 base::Unretained(this))); |
| 2977 | 2987 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2988 | 2998 |
| 2989 EXPECT_FALSE(device->IsConnected()); | 2999 EXPECT_FALSE(device->IsConnected()); |
| 2990 EXPECT_FALSE(device->IsConnecting()); | 3000 EXPECT_FALSE(device->IsConnecting()); |
| 2991 EXPECT_FALSE(device->IsPaired()); | 3001 EXPECT_FALSE(device->IsPaired()); |
| 2992 } | 3002 } |
| 2993 | 3003 |
| 2994 TEST_F(BluetoothChromeOSTest, PairingFails) { | 3004 TEST_F(BluetoothChromeOSTest, PairingFails) { |
| 2995 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3005 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2996 | 3006 |
| 2997 GetAdapter(); | 3007 GetAdapter(); |
| 2998 DiscoverDevice(FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 3008 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
| 2999 | 3009 |
| 3000 // The vanishing device times out during pairing | 3010 // The vanishing device times out during pairing |
| 3001 BluetoothDevice* device = adapter_->GetDevice( | 3011 BluetoothDevice* device = adapter_->GetDevice( |
| 3002 FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 3012 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
| 3003 ASSERT_TRUE(device != nullptr); | 3013 ASSERT_TRUE(device != nullptr); |
| 3004 ASSERT_FALSE(device->IsPaired()); | 3014 ASSERT_FALSE(device->IsPaired()); |
| 3005 | 3015 |
| 3006 TestBluetoothAdapterObserver observer(adapter_); | 3016 TestBluetoothAdapterObserver observer(adapter_); |
| 3007 | 3017 |
| 3008 TestPairingDelegate pairing_delegate; | 3018 TestPairingDelegate pairing_delegate; |
| 3009 device->Connect(&pairing_delegate, GetCallback(), | 3019 device->Connect(&pairing_delegate, GetCallback(), |
| 3010 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3020 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3011 base::Unretained(this))); | 3021 base::Unretained(this))); |
| 3012 | 3022 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3028 | 3038 |
| 3029 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { | 3039 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { |
| 3030 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3040 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3031 | 3041 |
| 3032 GetAdapter(); | 3042 GetAdapter(); |
| 3033 DiscoverDevices(); | 3043 DiscoverDevices(); |
| 3034 | 3044 |
| 3035 // Everything seems to go according to plan with the unconnectable device; | 3045 // Everything seems to go according to plan with the unconnectable device; |
| 3036 // it pairs, but then you can't make connections to it after. | 3046 // it pairs, but then you can't make connections to it after. |
| 3037 BluetoothDevice* device = adapter_->GetDevice( | 3047 BluetoothDevice* device = adapter_->GetDevice( |
| 3038 FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 3048 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
| 3039 ASSERT_TRUE(device != nullptr); | 3049 ASSERT_TRUE(device != nullptr); |
| 3040 ASSERT_FALSE(device->IsPaired()); | 3050 ASSERT_FALSE(device->IsPaired()); |
| 3041 | 3051 |
| 3042 TestBluetoothAdapterObserver observer(adapter_); | 3052 TestBluetoothAdapterObserver observer(adapter_); |
| 3043 | 3053 |
| 3044 TestPairingDelegate pairing_delegate; | 3054 TestPairingDelegate pairing_delegate; |
| 3045 device->Connect(&pairing_delegate, GetCallback(), | 3055 device->Connect(&pairing_delegate, GetCallback(), |
| 3046 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3056 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3047 base::Unretained(this))); | 3057 base::Unretained(this))); |
| 3048 | 3058 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3060 EXPECT_EQ(4, observer.device_changed_count()); | 3070 EXPECT_EQ(4, observer.device_changed_count()); |
| 3061 EXPECT_EQ(device, observer.last_device()); | 3071 EXPECT_EQ(device, observer.last_device()); |
| 3062 | 3072 |
| 3063 EXPECT_FALSE(device->IsConnected()); | 3073 EXPECT_FALSE(device->IsConnected()); |
| 3064 EXPECT_FALSE(device->IsConnecting()); | 3074 EXPECT_FALSE(device->IsConnecting()); |
| 3065 | 3075 |
| 3066 EXPECT_TRUE(device->IsPaired()); | 3076 EXPECT_TRUE(device->IsPaired()); |
| 3067 | 3077 |
| 3068 // Make sure the trusted property has been set to true still (since pairing | 3078 // Make sure the trusted property has been set to true still (since pairing |
| 3069 // worked). | 3079 // worked). |
| 3070 FakeBluetoothDeviceClient::Properties* properties = | 3080 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3071 fake_bluetooth_device_client_->GetProperties( | 3081 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3072 dbus::ObjectPath( | 3082 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath)); |
| 3073 FakeBluetoothDeviceClient::kUnconnectableDevicePath)); | |
| 3074 EXPECT_TRUE(properties->trusted.value()); | 3083 EXPECT_TRUE(properties->trusted.value()); |
| 3075 } | 3084 } |
| 3076 | 3085 |
| 3077 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { | 3086 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { |
| 3078 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3087 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3079 | 3088 |
| 3080 GetAdapter(); | 3089 GetAdapter(); |
| 3081 DiscoverDevices(); | 3090 DiscoverDevices(); |
| 3082 | 3091 |
| 3083 // Reject the pairing after we receive a request for the PIN code. | 3092 // Reject the pairing after we receive a request for the PIN code. |
| 3084 BluetoothDevice* device = adapter_->GetDevice( | 3093 BluetoothDevice* device = adapter_->GetDevice( |
| 3085 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3094 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3086 ASSERT_TRUE(device != nullptr); | 3095 ASSERT_TRUE(device != nullptr); |
| 3087 ASSERT_FALSE(device->IsPaired()); | 3096 ASSERT_FALSE(device->IsPaired()); |
| 3088 | 3097 |
| 3089 TestBluetoothAdapterObserver observer(adapter_); | 3098 TestBluetoothAdapterObserver observer(adapter_); |
| 3090 | 3099 |
| 3091 TestPairingDelegate pairing_delegate; | 3100 TestPairingDelegate pairing_delegate; |
| 3092 device->Connect(&pairing_delegate, GetCallback(), | 3101 device->Connect(&pairing_delegate, GetCallback(), |
| 3093 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3102 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3094 base::Unretained(this))); | 3103 base::Unretained(this))); |
| 3095 | 3104 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3113 } | 3122 } |
| 3114 | 3123 |
| 3115 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { | 3124 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { |
| 3116 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3125 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3117 | 3126 |
| 3118 GetAdapter(); | 3127 GetAdapter(); |
| 3119 DiscoverDevices(); | 3128 DiscoverDevices(); |
| 3120 | 3129 |
| 3121 // Cancel the pairing after we receive a request for the PIN code. | 3130 // Cancel the pairing after we receive a request for the PIN code. |
| 3122 BluetoothDevice* device = adapter_->GetDevice( | 3131 BluetoothDevice* device = adapter_->GetDevice( |
| 3123 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3132 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3124 ASSERT_TRUE(device != nullptr); | 3133 ASSERT_TRUE(device != nullptr); |
| 3125 ASSERT_FALSE(device->IsPaired()); | 3134 ASSERT_FALSE(device->IsPaired()); |
| 3126 | 3135 |
| 3127 TestBluetoothAdapterObserver observer(adapter_); | 3136 TestBluetoothAdapterObserver observer(adapter_); |
| 3128 | 3137 |
| 3129 TestPairingDelegate pairing_delegate; | 3138 TestPairingDelegate pairing_delegate; |
| 3130 device->Connect(&pairing_delegate, GetCallback(), | 3139 device->Connect(&pairing_delegate, GetCallback(), |
| 3131 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3140 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3132 base::Unretained(this))); | 3141 base::Unretained(this))); |
| 3133 | 3142 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3151 } | 3160 } |
| 3152 | 3161 |
| 3153 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { | 3162 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { |
| 3154 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3163 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3155 | 3164 |
| 3156 GetAdapter(); | 3165 GetAdapter(); |
| 3157 DiscoverDevices(); | 3166 DiscoverDevices(); |
| 3158 | 3167 |
| 3159 // Reject the pairing after we receive a request for the passkey. | 3168 // Reject the pairing after we receive a request for the passkey. |
| 3160 BluetoothDevice* device = adapter_->GetDevice( | 3169 BluetoothDevice* device = adapter_->GetDevice( |
| 3161 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3170 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3162 ASSERT_TRUE(device != nullptr); | 3171 ASSERT_TRUE(device != nullptr); |
| 3163 ASSERT_FALSE(device->IsPaired()); | 3172 ASSERT_FALSE(device->IsPaired()); |
| 3164 | 3173 |
| 3165 TestBluetoothAdapterObserver observer(adapter_); | 3174 TestBluetoothAdapterObserver observer(adapter_); |
| 3166 | 3175 |
| 3167 TestPairingDelegate pairing_delegate; | 3176 TestPairingDelegate pairing_delegate; |
| 3168 device->Connect(&pairing_delegate, GetCallback(), | 3177 device->Connect(&pairing_delegate, GetCallback(), |
| 3169 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3178 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3170 base::Unretained(this))); | 3179 base::Unretained(this))); |
| 3171 | 3180 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3189 } | 3198 } |
| 3190 | 3199 |
| 3191 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { | 3200 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { |
| 3192 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3201 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3193 | 3202 |
| 3194 GetAdapter(); | 3203 GetAdapter(); |
| 3195 DiscoverDevices(); | 3204 DiscoverDevices(); |
| 3196 | 3205 |
| 3197 // Cancel the pairing after we receive a request for the passkey. | 3206 // Cancel the pairing after we receive a request for the passkey. |
| 3198 BluetoothDevice* device = adapter_->GetDevice( | 3207 BluetoothDevice* device = adapter_->GetDevice( |
| 3199 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3208 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3200 ASSERT_TRUE(device != nullptr); | 3209 ASSERT_TRUE(device != nullptr); |
| 3201 ASSERT_FALSE(device->IsPaired()); | 3210 ASSERT_FALSE(device->IsPaired()); |
| 3202 | 3211 |
| 3203 TestBluetoothAdapterObserver observer(adapter_); | 3212 TestBluetoothAdapterObserver observer(adapter_); |
| 3204 | 3213 |
| 3205 TestPairingDelegate pairing_delegate; | 3214 TestPairingDelegate pairing_delegate; |
| 3206 device->Connect(&pairing_delegate, GetCallback(), | 3215 device->Connect(&pairing_delegate, GetCallback(), |
| 3207 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3216 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3208 base::Unretained(this))); | 3217 base::Unretained(this))); |
| 3209 | 3218 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3227 } | 3236 } |
| 3228 | 3237 |
| 3229 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { | 3238 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { |
| 3230 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3239 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3231 | 3240 |
| 3232 GetAdapter(); | 3241 GetAdapter(); |
| 3233 DiscoverDevices(); | 3242 DiscoverDevices(); |
| 3234 | 3243 |
| 3235 // Reject the pairing after we receive a request for passkey confirmation. | 3244 // Reject the pairing after we receive a request for passkey confirmation. |
| 3236 BluetoothDevice* device = adapter_->GetDevice( | 3245 BluetoothDevice* device = adapter_->GetDevice( |
| 3237 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3246 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3238 ASSERT_TRUE(device != nullptr); | 3247 ASSERT_TRUE(device != nullptr); |
| 3239 ASSERT_FALSE(device->IsPaired()); | 3248 ASSERT_FALSE(device->IsPaired()); |
| 3240 | 3249 |
| 3241 TestBluetoothAdapterObserver observer(adapter_); | 3250 TestBluetoothAdapterObserver observer(adapter_); |
| 3242 | 3251 |
| 3243 TestPairingDelegate pairing_delegate; | 3252 TestPairingDelegate pairing_delegate; |
| 3244 device->Connect(&pairing_delegate, GetCallback(), | 3253 device->Connect(&pairing_delegate, GetCallback(), |
| 3245 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3254 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3246 base::Unretained(this))); | 3255 base::Unretained(this))); |
| 3247 | 3256 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3265 } | 3274 } |
| 3266 | 3275 |
| 3267 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { | 3276 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { |
| 3268 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3277 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3269 | 3278 |
| 3270 GetAdapter(); | 3279 GetAdapter(); |
| 3271 DiscoverDevices(); | 3280 DiscoverDevices(); |
| 3272 | 3281 |
| 3273 // Cancel the pairing after we receive a request for the passkey. | 3282 // Cancel the pairing after we receive a request for the passkey. |
| 3274 BluetoothDevice* device = adapter_->GetDevice( | 3283 BluetoothDevice* device = adapter_->GetDevice( |
| 3275 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3284 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3276 ASSERT_TRUE(device != nullptr); | 3285 ASSERT_TRUE(device != nullptr); |
| 3277 ASSERT_FALSE(device->IsPaired()); | 3286 ASSERT_FALSE(device->IsPaired()); |
| 3278 | 3287 |
| 3279 TestBluetoothAdapterObserver observer(adapter_); | 3288 TestBluetoothAdapterObserver observer(adapter_); |
| 3280 | 3289 |
| 3281 TestPairingDelegate pairing_delegate; | 3290 TestPairingDelegate pairing_delegate; |
| 3282 device->Connect(&pairing_delegate, GetCallback(), | 3291 device->Connect(&pairing_delegate, GetCallback(), |
| 3283 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3292 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3284 base::Unretained(this))); | 3293 base::Unretained(this))); |
| 3285 | 3294 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3303 } | 3312 } |
| 3304 | 3313 |
| 3305 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { | 3314 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { |
| 3306 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3315 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3307 | 3316 |
| 3308 GetAdapter(); | 3317 GetAdapter(); |
| 3309 DiscoverDevices(); | 3318 DiscoverDevices(); |
| 3310 | 3319 |
| 3311 // Cancel the pairing while we're waiting for the remote host. | 3320 // Cancel the pairing while we're waiting for the remote host. |
| 3312 BluetoothDevice* device = adapter_->GetDevice( | 3321 BluetoothDevice* device = adapter_->GetDevice( |
| 3313 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 3322 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 3314 ASSERT_TRUE(device != nullptr); | 3323 ASSERT_TRUE(device != nullptr); |
| 3315 ASSERT_FALSE(device->IsPaired()); | 3324 ASSERT_FALSE(device->IsPaired()); |
| 3316 | 3325 |
| 3317 TestBluetoothAdapterObserver observer(adapter_); | 3326 TestBluetoothAdapterObserver observer(adapter_); |
| 3318 | 3327 |
| 3319 TestPairingDelegate pairing_delegate; | 3328 TestPairingDelegate pairing_delegate; |
| 3320 device->Connect(&pairing_delegate, GetCallback(), | 3329 device->Connect(&pairing_delegate, GetCallback(), |
| 3321 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3330 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3322 base::Unretained(this))); | 3331 base::Unretained(this))); |
| 3323 | 3332 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3344 | 3353 |
| 3345 GetAdapter(); | 3354 GetAdapter(); |
| 3346 | 3355 |
| 3347 TestPairingDelegate pairing_delegate; | 3356 TestPairingDelegate pairing_delegate; |
| 3348 adapter_->AddPairingDelegate( | 3357 adapter_->AddPairingDelegate( |
| 3349 &pairing_delegate, | 3358 &pairing_delegate, |
| 3350 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3359 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3351 | 3360 |
| 3352 // Requires that we provide a PIN code. | 3361 // Requires that we provide a PIN code. |
| 3353 fake_bluetooth_device_client_->CreateDevice( | 3362 fake_bluetooth_device_client_->CreateDevice( |
| 3354 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3363 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3355 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3364 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3356 BluetoothDevice* device = adapter_->GetDevice( | 3365 BluetoothDevice* device = adapter_->GetDevice( |
| 3357 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3366 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3358 ASSERT_TRUE(device != nullptr); | 3367 ASSERT_TRUE(device != nullptr); |
| 3359 ASSERT_FALSE(device->IsPaired()); | 3368 ASSERT_FALSE(device->IsPaired()); |
| 3360 | 3369 |
| 3361 TestBluetoothAdapterObserver observer(adapter_); | 3370 TestBluetoothAdapterObserver observer(adapter_); |
| 3362 | 3371 |
| 3363 fake_bluetooth_device_client_->SimulatePairing( | 3372 fake_bluetooth_device_client_->SimulatePairing( |
| 3364 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true, | 3373 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), |
| 3365 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3374 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3366 base::Unretained(this))); | 3375 base::Unretained(this))); |
| 3367 | 3376 |
| 3368 EXPECT_EQ(1, pairing_delegate.call_count_); | 3377 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3369 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 3378 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
| 3370 | 3379 |
| 3371 // Set the PIN. | 3380 // Set the PIN. |
| 3372 device->SetPinCode("1234"); | 3381 device->SetPinCode("1234"); |
| 3373 message_loop_.Run(); | 3382 message_loop_.Run(); |
| 3374 | 3383 |
| 3375 EXPECT_EQ(1, callback_count_); | 3384 EXPECT_EQ(1, callback_count_); |
| 3376 EXPECT_EQ(0, error_callback_count_); | 3385 EXPECT_EQ(0, error_callback_count_); |
| 3377 | 3386 |
| 3378 // One change for paired, and one for trusted. | 3387 // One change for paired, and one for trusted. |
| 3379 EXPECT_EQ(2, observer.device_changed_count()); | 3388 EXPECT_EQ(2, observer.device_changed_count()); |
| 3380 EXPECT_EQ(device, observer.last_device()); | 3389 EXPECT_EQ(device, observer.last_device()); |
| 3381 | 3390 |
| 3382 EXPECT_TRUE(device->IsPaired()); | 3391 EXPECT_TRUE(device->IsPaired()); |
| 3383 | 3392 |
| 3384 // Make sure the trusted property has been set to true. | 3393 // Make sure the trusted property has been set to true. |
| 3385 FakeBluetoothDeviceClient::Properties* properties = | 3394 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3386 fake_bluetooth_device_client_->GetProperties( | 3395 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3387 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3396 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3388 ASSERT_TRUE(properties->trusted.value()); | 3397 ASSERT_TRUE(properties->trusted.value()); |
| 3389 | 3398 |
| 3390 // No pairing context should remain on the device. | 3399 // No pairing context should remain on the device. |
| 3391 BluetoothDeviceChromeOS* device_chromeos = | 3400 BluetoothDeviceChromeOS* device_chromeos = |
| 3392 static_cast<BluetoothDeviceChromeOS*>(device); | 3401 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3393 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3402 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3394 } | 3403 } |
| 3395 | 3404 |
| 3396 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { | 3405 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { |
| 3397 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3406 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3398 | 3407 |
| 3399 GetAdapter(); | 3408 GetAdapter(); |
| 3400 | 3409 |
| 3401 TestPairingDelegate pairing_delegate; | 3410 TestPairingDelegate pairing_delegate; |
| 3402 adapter_->AddPairingDelegate( | 3411 adapter_->AddPairingDelegate( |
| 3403 &pairing_delegate, | 3412 &pairing_delegate, |
| 3404 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3413 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3405 | 3414 |
| 3406 // Requests that we confirm a displayed passkey. | 3415 // Requests that we confirm a displayed passkey. |
| 3407 fake_bluetooth_device_client_->CreateDevice( | 3416 fake_bluetooth_device_client_->CreateDevice( |
| 3408 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3417 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3409 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3418 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3410 BluetoothDevice* device = adapter_->GetDevice( | 3419 BluetoothDevice* device = adapter_->GetDevice( |
| 3411 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3420 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3412 ASSERT_TRUE(device != nullptr); | 3421 ASSERT_TRUE(device != nullptr); |
| 3413 ASSERT_FALSE(device->IsPaired()); | 3422 ASSERT_FALSE(device->IsPaired()); |
| 3414 | 3423 |
| 3415 TestBluetoothAdapterObserver observer(adapter_); | 3424 TestBluetoothAdapterObserver observer(adapter_); |
| 3416 | 3425 |
| 3417 fake_bluetooth_device_client_->SimulatePairing( | 3426 fake_bluetooth_device_client_->SimulatePairing( |
| 3418 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true, | 3427 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), |
| 3419 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3428 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3420 base::Unretained(this))); | 3429 base::Unretained(this))); |
| 3421 | 3430 |
| 3422 EXPECT_EQ(1, pairing_delegate.call_count_); | 3431 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3423 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 3432 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
| 3424 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 3433 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
| 3425 | 3434 |
| 3426 // Confirm the passkey. | 3435 // Confirm the passkey. |
| 3427 device->ConfirmPairing(); | 3436 device->ConfirmPairing(); |
| 3428 message_loop_.Run(); | 3437 message_loop_.Run(); |
| 3429 | 3438 |
| 3430 EXPECT_EQ(1, callback_count_); | 3439 EXPECT_EQ(1, callback_count_); |
| 3431 EXPECT_EQ(0, error_callback_count_); | 3440 EXPECT_EQ(0, error_callback_count_); |
| 3432 | 3441 |
| 3433 // One change for paired, and one for trusted. | 3442 // One change for paired, and one for trusted. |
| 3434 EXPECT_EQ(2, observer.device_changed_count()); | 3443 EXPECT_EQ(2, observer.device_changed_count()); |
| 3435 EXPECT_EQ(device, observer.last_device()); | 3444 EXPECT_EQ(device, observer.last_device()); |
| 3436 | 3445 |
| 3437 EXPECT_TRUE(device->IsPaired()); | 3446 EXPECT_TRUE(device->IsPaired()); |
| 3438 | 3447 |
| 3439 // Make sure the trusted property has been set to true. | 3448 // Make sure the trusted property has been set to true. |
| 3440 FakeBluetoothDeviceClient::Properties* properties = | 3449 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3441 fake_bluetooth_device_client_->GetProperties( | 3450 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3442 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3451 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3443 ASSERT_TRUE(properties->trusted.value()); | 3452 ASSERT_TRUE(properties->trusted.value()); |
| 3444 | 3453 |
| 3445 // No pairing context should remain on the device. | 3454 // No pairing context should remain on the device. |
| 3446 BluetoothDeviceChromeOS* device_chromeos = | 3455 BluetoothDeviceChromeOS* device_chromeos = |
| 3447 static_cast<BluetoothDeviceChromeOS*>(device); | 3456 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3448 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3457 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3449 } | 3458 } |
| 3450 | 3459 |
| 3451 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { | 3460 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { |
| 3452 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3461 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3453 | 3462 |
| 3454 GetAdapter(); | 3463 GetAdapter(); |
| 3455 | 3464 |
| 3456 TestPairingDelegate pairing_delegate; | 3465 TestPairingDelegate pairing_delegate; |
| 3457 adapter_->AddPairingDelegate( | 3466 adapter_->AddPairingDelegate( |
| 3458 &pairing_delegate, | 3467 &pairing_delegate, |
| 3459 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3468 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3460 | 3469 |
| 3461 // Requests that we provide a Passkey. | 3470 // Requests that we provide a Passkey. |
| 3462 fake_bluetooth_device_client_->CreateDevice( | 3471 fake_bluetooth_device_client_->CreateDevice( |
| 3463 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3472 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3464 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3473 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3465 BluetoothDevice* device = adapter_->GetDevice( | 3474 BluetoothDevice* device = adapter_->GetDevice( |
| 3466 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3475 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3467 ASSERT_TRUE(device != nullptr); | 3476 ASSERT_TRUE(device != nullptr); |
| 3468 ASSERT_FALSE(device->IsPaired()); | 3477 ASSERT_FALSE(device->IsPaired()); |
| 3469 | 3478 |
| 3470 TestBluetoothAdapterObserver observer(adapter_); | 3479 TestBluetoothAdapterObserver observer(adapter_); |
| 3471 | 3480 |
| 3472 fake_bluetooth_device_client_->SimulatePairing( | 3481 fake_bluetooth_device_client_->SimulatePairing( |
| 3473 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, | 3482 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
| 3474 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3483 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3475 base::Unretained(this))); | 3484 base::Unretained(this))); |
| 3476 | 3485 |
| 3477 EXPECT_EQ(1, pairing_delegate.call_count_); | 3486 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3478 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3487 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 3479 | 3488 |
| 3480 // Set the Passkey. | 3489 // Set the Passkey. |
| 3481 device->SetPasskey(1234); | 3490 device->SetPasskey(1234); |
| 3482 message_loop_.Run(); | 3491 message_loop_.Run(); |
| 3483 | 3492 |
| 3484 EXPECT_EQ(1, callback_count_); | 3493 EXPECT_EQ(1, callback_count_); |
| 3485 EXPECT_EQ(0, error_callback_count_); | 3494 EXPECT_EQ(0, error_callback_count_); |
| 3486 | 3495 |
| 3487 // One change for paired, and one for trusted. | 3496 // One change for paired, and one for trusted. |
| 3488 EXPECT_EQ(2, observer.device_changed_count()); | 3497 EXPECT_EQ(2, observer.device_changed_count()); |
| 3489 EXPECT_EQ(device, observer.last_device()); | 3498 EXPECT_EQ(device, observer.last_device()); |
| 3490 | 3499 |
| 3491 EXPECT_TRUE(device->IsPaired()); | 3500 EXPECT_TRUE(device->IsPaired()); |
| 3492 | 3501 |
| 3493 // Make sure the trusted property has been set to true. | 3502 // Make sure the trusted property has been set to true. |
| 3494 FakeBluetoothDeviceClient::Properties* properties = | 3503 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3495 fake_bluetooth_device_client_->GetProperties( | 3504 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3496 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3505 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3497 ASSERT_TRUE(properties->trusted.value()); | 3506 ASSERT_TRUE(properties->trusted.value()); |
| 3498 | 3507 |
| 3499 // No pairing context should remain on the device. | 3508 // No pairing context should remain on the device. |
| 3500 BluetoothDeviceChromeOS* device_chromeos = | 3509 BluetoothDeviceChromeOS* device_chromeos = |
| 3501 static_cast<BluetoothDeviceChromeOS*>(device); | 3510 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3502 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3511 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3503 } | 3512 } |
| 3504 | 3513 |
| 3505 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { | 3514 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { |
| 3506 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3515 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3507 | 3516 |
| 3508 GetAdapter(); | 3517 GetAdapter(); |
| 3509 | 3518 |
| 3510 TestPairingDelegate pairing_delegate; | 3519 TestPairingDelegate pairing_delegate; |
| 3511 adapter_->AddPairingDelegate( | 3520 adapter_->AddPairingDelegate( |
| 3512 &pairing_delegate, | 3521 &pairing_delegate, |
| 3513 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3522 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3514 | 3523 |
| 3515 // Uses just-works pairing so, sinec this an incoming pairing, require | 3524 // Uses just-works pairing so, sinec this an incoming pairing, require |
| 3516 // authorization from the user. | 3525 // authorization from the user. |
| 3517 fake_bluetooth_device_client_->CreateDevice( | 3526 fake_bluetooth_device_client_->CreateDevice( |
| 3518 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3527 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3519 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 3528 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3520 BluetoothDevice* device = adapter_->GetDevice( | 3529 BluetoothDevice* device = |
| 3521 FakeBluetoothDeviceClient::kJustWorksAddress); | 3530 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
| 3522 ASSERT_TRUE(device != nullptr); | 3531 ASSERT_TRUE(device != nullptr); |
| 3523 ASSERT_FALSE(device->IsPaired()); | 3532 ASSERT_FALSE(device->IsPaired()); |
| 3524 | 3533 |
| 3525 TestBluetoothAdapterObserver observer(adapter_); | 3534 TestBluetoothAdapterObserver observer(adapter_); |
| 3526 | 3535 |
| 3527 fake_bluetooth_device_client_->SimulatePairing( | 3536 fake_bluetooth_device_client_->SimulatePairing( |
| 3528 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true, | 3537 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, |
| 3529 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3538 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3530 base::Unretained(this))); | 3539 base::Unretained(this))); |
| 3531 | 3540 |
| 3532 EXPECT_EQ(1, pairing_delegate.call_count_); | 3541 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3533 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); | 3542 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); |
| 3534 | 3543 |
| 3535 // Confirm the pairing. | 3544 // Confirm the pairing. |
| 3536 device->ConfirmPairing(); | 3545 device->ConfirmPairing(); |
| 3537 message_loop_.Run(); | 3546 message_loop_.Run(); |
| 3538 | 3547 |
| 3539 EXPECT_EQ(1, callback_count_); | 3548 EXPECT_EQ(1, callback_count_); |
| 3540 EXPECT_EQ(0, error_callback_count_); | 3549 EXPECT_EQ(0, error_callback_count_); |
| 3541 | 3550 |
| 3542 // One change for paired, and one for trusted. | 3551 // One change for paired, and one for trusted. |
| 3543 EXPECT_EQ(2, observer.device_changed_count()); | 3552 EXPECT_EQ(2, observer.device_changed_count()); |
| 3544 EXPECT_EQ(device, observer.last_device()); | 3553 EXPECT_EQ(device, observer.last_device()); |
| 3545 | 3554 |
| 3546 EXPECT_TRUE(device->IsPaired()); | 3555 EXPECT_TRUE(device->IsPaired()); |
| 3547 | 3556 |
| 3548 // Make sure the trusted property has been set to true. | 3557 // Make sure the trusted property has been set to true. |
| 3549 FakeBluetoothDeviceClient::Properties* properties = | 3558 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3550 fake_bluetooth_device_client_->GetProperties( | 3559 fake_bluetooth_device_client_->GetProperties( |
| 3551 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 3560 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3552 ASSERT_TRUE(properties->trusted.value()); | 3561 ASSERT_TRUE(properties->trusted.value()); |
| 3553 | 3562 |
| 3554 // No pairing context should remain on the device. | 3563 // No pairing context should remain on the device. |
| 3555 BluetoothDeviceChromeOS* device_chromeos = | 3564 BluetoothDeviceChromeOS* device_chromeos = |
| 3556 static_cast<BluetoothDeviceChromeOS*>(device); | 3565 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3557 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3566 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3558 } | 3567 } |
| 3559 | 3568 |
| 3560 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { | 3569 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { |
| 3561 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3570 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3562 | 3571 |
| 3563 GetAdapter(); | 3572 GetAdapter(); |
| 3564 | 3573 |
| 3565 // Requires that we provide a PIN Code, without a pairing delegate, | 3574 // Requires that we provide a PIN Code, without a pairing delegate, |
| 3566 // that will be rejected. | 3575 // that will be rejected. |
| 3567 fake_bluetooth_device_client_->CreateDevice( | 3576 fake_bluetooth_device_client_->CreateDevice( |
| 3568 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3577 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3569 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3578 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3570 BluetoothDevice* device = adapter_->GetDevice( | 3579 BluetoothDevice* device = adapter_->GetDevice( |
| 3571 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3580 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3572 ASSERT_TRUE(device != nullptr); | 3581 ASSERT_TRUE(device != nullptr); |
| 3573 ASSERT_FALSE(device->IsPaired()); | 3582 ASSERT_FALSE(device->IsPaired()); |
| 3574 | 3583 |
| 3575 TestBluetoothAdapterObserver observer(adapter_); | 3584 TestBluetoothAdapterObserver observer(adapter_); |
| 3576 | 3585 |
| 3577 fake_bluetooth_device_client_->SimulatePairing( | 3586 fake_bluetooth_device_client_->SimulatePairing( |
| 3578 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true, | 3587 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), |
| 3579 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3588 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3580 base::Unretained(this))); | 3589 base::Unretained(this))); |
| 3581 | 3590 |
| 3582 message_loop_.Run(); | 3591 message_loop_.Run(); |
| 3583 | 3592 |
| 3584 EXPECT_EQ(0, callback_count_); | 3593 EXPECT_EQ(0, callback_count_); |
| 3585 EXPECT_EQ(1, error_callback_count_); | 3594 EXPECT_EQ(1, error_callback_count_); |
| 3586 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3595 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3587 | 3596 |
| 3588 // No changes should be observer. | 3597 // No changes should be observer. |
| 3589 EXPECT_EQ(0, observer.device_changed_count()); | 3598 EXPECT_EQ(0, observer.device_changed_count()); |
| 3590 | 3599 |
| 3591 EXPECT_FALSE(device->IsPaired()); | 3600 EXPECT_FALSE(device->IsPaired()); |
| 3592 | 3601 |
| 3593 // No pairing context should remain on the device. | 3602 // No pairing context should remain on the device. |
| 3594 BluetoothDeviceChromeOS* device_chromeos = | 3603 BluetoothDeviceChromeOS* device_chromeos = |
| 3595 static_cast<BluetoothDeviceChromeOS*>(device); | 3604 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3596 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3605 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3597 } | 3606 } |
| 3598 | 3607 |
| 3599 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { | 3608 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { |
| 3600 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3609 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3601 | 3610 |
| 3602 GetAdapter(); | 3611 GetAdapter(); |
| 3603 | 3612 |
| 3604 // Requests that we confirm a displayed passkey, without a pairing delegate, | 3613 // Requests that we confirm a displayed passkey, without a pairing delegate, |
| 3605 // that will be rejected. | 3614 // that will be rejected. |
| 3606 fake_bluetooth_device_client_->CreateDevice( | 3615 fake_bluetooth_device_client_->CreateDevice( |
| 3607 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3616 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3608 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3617 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3609 BluetoothDevice* device = adapter_->GetDevice( | 3618 BluetoothDevice* device = adapter_->GetDevice( |
| 3610 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3619 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3611 ASSERT_TRUE(device != nullptr); | 3620 ASSERT_TRUE(device != nullptr); |
| 3612 ASSERT_FALSE(device->IsPaired()); | 3621 ASSERT_FALSE(device->IsPaired()); |
| 3613 | 3622 |
| 3614 TestBluetoothAdapterObserver observer(adapter_); | 3623 TestBluetoothAdapterObserver observer(adapter_); |
| 3615 | 3624 |
| 3616 fake_bluetooth_device_client_->SimulatePairing( | 3625 fake_bluetooth_device_client_->SimulatePairing( |
| 3617 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true, | 3626 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), |
| 3618 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3627 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3619 base::Unretained(this))); | 3628 base::Unretained(this))); |
| 3620 | 3629 |
| 3621 message_loop_.Run(); | 3630 message_loop_.Run(); |
| 3622 | 3631 |
| 3623 EXPECT_EQ(0, callback_count_); | 3632 EXPECT_EQ(0, callback_count_); |
| 3624 EXPECT_EQ(1, error_callback_count_); | 3633 EXPECT_EQ(1, error_callback_count_); |
| 3625 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3634 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3626 | 3635 |
| 3627 // No changes should be observer. | 3636 // No changes should be observer. |
| 3628 EXPECT_EQ(0, observer.device_changed_count()); | 3637 EXPECT_EQ(0, observer.device_changed_count()); |
| 3629 | 3638 |
| 3630 EXPECT_FALSE(device->IsPaired()); | 3639 EXPECT_FALSE(device->IsPaired()); |
| 3631 | 3640 |
| 3632 // No pairing context should remain on the device. | 3641 // No pairing context should remain on the device. |
| 3633 BluetoothDeviceChromeOS* device_chromeos = | 3642 BluetoothDeviceChromeOS* device_chromeos = |
| 3634 static_cast<BluetoothDeviceChromeOS*>(device); | 3643 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3635 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3644 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3636 } | 3645 } |
| 3637 | 3646 |
| 3638 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { | 3647 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { |
| 3639 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3648 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3640 | 3649 |
| 3641 GetAdapter(); | 3650 GetAdapter(); |
| 3642 | 3651 |
| 3643 // Requests that we provide a displayed passkey, without a pairing delegate, | 3652 // Requests that we provide a displayed passkey, without a pairing delegate, |
| 3644 // that will be rejected. | 3653 // that will be rejected. |
| 3645 fake_bluetooth_device_client_->CreateDevice( | 3654 fake_bluetooth_device_client_->CreateDevice( |
| 3646 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3655 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3647 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3656 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3648 BluetoothDevice* device = adapter_->GetDevice( | 3657 BluetoothDevice* device = adapter_->GetDevice( |
| 3649 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3658 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3650 ASSERT_TRUE(device != nullptr); | 3659 ASSERT_TRUE(device != nullptr); |
| 3651 ASSERT_FALSE(device->IsPaired()); | 3660 ASSERT_FALSE(device->IsPaired()); |
| 3652 | 3661 |
| 3653 TestBluetoothAdapterObserver observer(adapter_); | 3662 TestBluetoothAdapterObserver observer(adapter_); |
| 3654 | 3663 |
| 3655 fake_bluetooth_device_client_->SimulatePairing( | 3664 fake_bluetooth_device_client_->SimulatePairing( |
| 3656 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, | 3665 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
| 3657 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3666 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3658 base::Unretained(this))); | 3667 base::Unretained(this))); |
| 3659 | 3668 |
| 3660 message_loop_.Run(); | 3669 message_loop_.Run(); |
| 3661 | 3670 |
| 3662 EXPECT_EQ(0, callback_count_); | 3671 EXPECT_EQ(0, callback_count_); |
| 3663 EXPECT_EQ(1, error_callback_count_); | 3672 EXPECT_EQ(1, error_callback_count_); |
| 3664 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3673 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3665 | 3674 |
| 3666 // No changes should be observer. | 3675 // No changes should be observer. |
| 3667 EXPECT_EQ(0, observer.device_changed_count()); | 3676 EXPECT_EQ(0, observer.device_changed_count()); |
| 3668 | 3677 |
| 3669 EXPECT_FALSE(device->IsPaired()); | 3678 EXPECT_FALSE(device->IsPaired()); |
| 3670 | 3679 |
| 3671 // No pairing context should remain on the device. | 3680 // No pairing context should remain on the device. |
| 3672 BluetoothDeviceChromeOS* device_chromeos = | 3681 BluetoothDeviceChromeOS* device_chromeos = |
| 3673 static_cast<BluetoothDeviceChromeOS*>(device); | 3682 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3674 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3683 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3675 } | 3684 } |
| 3676 | 3685 |
| 3677 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { | 3686 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { |
| 3678 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3687 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3679 | 3688 |
| 3680 GetAdapter(); | 3689 GetAdapter(); |
| 3681 | 3690 |
| 3682 // Uses just-works pairing and thus requires authorization for incoming | 3691 // Uses just-works pairing and thus requires authorization for incoming |
| 3683 // pairings, without a pairing delegate, that will be rejected. | 3692 // pairings, without a pairing delegate, that will be rejected. |
| 3684 fake_bluetooth_device_client_->CreateDevice( | 3693 fake_bluetooth_device_client_->CreateDevice( |
| 3685 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3694 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3686 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 3695 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3687 BluetoothDevice* device = adapter_->GetDevice( | 3696 BluetoothDevice* device = |
| 3688 FakeBluetoothDeviceClient::kJustWorksAddress); | 3697 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
| 3689 ASSERT_TRUE(device != nullptr); | 3698 ASSERT_TRUE(device != nullptr); |
| 3690 ASSERT_FALSE(device->IsPaired()); | 3699 ASSERT_FALSE(device->IsPaired()); |
| 3691 | 3700 |
| 3692 TestBluetoothAdapterObserver observer(adapter_); | 3701 TestBluetoothAdapterObserver observer(adapter_); |
| 3693 | 3702 |
| 3694 fake_bluetooth_device_client_->SimulatePairing( | 3703 fake_bluetooth_device_client_->SimulatePairing( |
| 3695 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true, | 3704 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, |
| 3696 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3705 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3697 base::Unretained(this))); | 3706 base::Unretained(this))); |
| 3698 | 3707 |
| 3699 message_loop_.Run(); | 3708 message_loop_.Run(); |
| 3700 | 3709 |
| 3701 EXPECT_EQ(0, callback_count_); | 3710 EXPECT_EQ(0, callback_count_); |
| 3702 EXPECT_EQ(1, error_callback_count_); | 3711 EXPECT_EQ(1, error_callback_count_); |
| 3703 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3712 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3704 | 3713 |
| 3705 // No changes should be observer. | 3714 // No changes should be observer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3718 | 3727 |
| 3719 GetAdapter(); | 3728 GetAdapter(); |
| 3720 | 3729 |
| 3721 TestPairingDelegate pairing_delegate; | 3730 TestPairingDelegate pairing_delegate; |
| 3722 adapter_->AddPairingDelegate( | 3731 adapter_->AddPairingDelegate( |
| 3723 &pairing_delegate, | 3732 &pairing_delegate, |
| 3724 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3733 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3725 | 3734 |
| 3726 // Requests that we provide a Passkey. | 3735 // Requests that we provide a Passkey. |
| 3727 fake_bluetooth_device_client_->CreateDevice( | 3736 fake_bluetooth_device_client_->CreateDevice( |
| 3728 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3737 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3729 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3738 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3730 BluetoothDevice* device = adapter_->GetDevice( | 3739 BluetoothDevice* device = adapter_->GetDevice( |
| 3731 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3740 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3732 ASSERT_TRUE(device != nullptr); | 3741 ASSERT_TRUE(device != nullptr); |
| 3733 ASSERT_FALSE(device->IsPaired()); | 3742 ASSERT_FALSE(device->IsPaired()); |
| 3734 | 3743 |
| 3735 TestBluetoothAdapterObserver observer(adapter_); | 3744 TestBluetoothAdapterObserver observer(adapter_); |
| 3736 | 3745 |
| 3737 fake_bluetooth_device_client_->SimulatePairing( | 3746 fake_bluetooth_device_client_->SimulatePairing( |
| 3738 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, | 3747 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
| 3739 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3748 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3740 base::Unretained(this))); | 3749 base::Unretained(this))); |
| 3741 | 3750 |
| 3742 EXPECT_EQ(1, pairing_delegate.call_count_); | 3751 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3743 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3752 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 3744 | 3753 |
| 3745 // A pairing context should now be set on the device. | 3754 // A pairing context should now be set on the device. |
| 3746 BluetoothDeviceChromeOS* device_chromeos = | 3755 BluetoothDeviceChromeOS* device_chromeos = |
| 3747 static_cast<BluetoothDeviceChromeOS*>(device); | 3756 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3748 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); | 3757 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); |
| 3749 | 3758 |
| 3750 // Removing the pairing delegate should remove that pairing context. | 3759 // Removing the pairing delegate should remove that pairing context. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3762 | 3771 |
| 3763 EXPECT_FALSE(device->IsPaired()); | 3772 EXPECT_FALSE(device->IsPaired()); |
| 3764 } | 3773 } |
| 3765 | 3774 |
| 3766 TEST_F(BluetoothChromeOSTest, DeviceId) { | 3775 TEST_F(BluetoothChromeOSTest, DeviceId) { |
| 3767 GetAdapter(); | 3776 GetAdapter(); |
| 3768 | 3777 |
| 3769 // Use the built-in paired device for this test, grab its Properties | 3778 // Use the built-in paired device for this test, grab its Properties |
| 3770 // structure so we can adjust the underlying modalias property. | 3779 // structure so we can adjust the underlying modalias property. |
| 3771 BluetoothDevice* device = adapter_->GetDevice( | 3780 BluetoothDevice* device = adapter_->GetDevice( |
| 3772 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3781 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3773 FakeBluetoothDeviceClient::Properties* properties = | 3782 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3774 fake_bluetooth_device_client_->GetProperties( | 3783 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3775 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 3784 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 3776 | 3785 |
| 3777 ASSERT_TRUE(device != nullptr); | 3786 ASSERT_TRUE(device != nullptr); |
| 3778 ASSERT_TRUE(properties != nullptr); | 3787 ASSERT_TRUE(properties != nullptr); |
| 3779 | 3788 |
| 3780 // Valid USB IF-assigned identifier. | 3789 // Valid USB IF-assigned identifier. |
| 3781 ASSERT_EQ("usb:v05ACp030Dd0306", properties->modalias.value()); | 3790 ASSERT_EQ("usb:v05ACp030Dd0306", properties->modalias.value()); |
| 3782 | 3791 |
| 3783 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, device->GetVendorIDSource()); | 3792 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, device->GetVendorIDSource()); |
| 3784 EXPECT_EQ(0x05ac, device->GetVendorID()); | 3793 EXPECT_EQ(0x05ac, device->GetVendorID()); |
| 3785 EXPECT_EQ(0x030d, device->GetProductID()); | 3794 EXPECT_EQ(0x030d, device->GetProductID()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3813 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); | 3822 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); |
| 3814 | 3823 |
| 3815 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); | 3824 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); |
| 3816 EXPECT_EQ(0, device->GetVendorID()); | 3825 EXPECT_EQ(0, device->GetVendorID()); |
| 3817 EXPECT_EQ(0, device->GetProductID()); | 3826 EXPECT_EQ(0, device->GetProductID()); |
| 3818 EXPECT_EQ(0, device->GetDeviceID()); | 3827 EXPECT_EQ(0, device->GetDeviceID()); |
| 3819 } | 3828 } |
| 3820 | 3829 |
| 3821 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { | 3830 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { |
| 3822 GetAdapter(); | 3831 GetAdapter(); |
| 3823 BluetoothDevice* device = | 3832 BluetoothDevice* device = adapter_->GetDevice( |
| 3824 adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3833 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3825 | 3834 |
| 3826 // Calling GetConnectionInfo for an unconnected device should return a result | 3835 // Calling GetConnectionInfo for an unconnected device should return a result |
| 3827 // in which all fields are filled with BluetoothDevice::kUnknownPower. | 3836 // in which all fields are filled with BluetoothDevice::kUnknownPower. |
| 3828 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); | 3837 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); |
| 3829 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3838 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
| 3830 int unknown_power = BluetoothDevice::kUnknownPower; | 3839 int unknown_power = BluetoothDevice::kUnknownPower; |
| 3831 EXPECT_NE(0, unknown_power); | 3840 EXPECT_NE(0, unknown_power); |
| 3832 EXPECT_EQ(unknown_power, conn_info.rssi); | 3841 EXPECT_EQ(unknown_power, conn_info.rssi); |
| 3833 EXPECT_EQ(unknown_power, conn_info.transmit_power); | 3842 EXPECT_EQ(unknown_power, conn_info.transmit_power); |
| 3834 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); | 3843 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); |
| 3835 } | 3844 } |
| 3836 | 3845 |
| 3837 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { | 3846 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { |
| 3838 GetAdapter(); | 3847 GetAdapter(); |
| 3839 BluetoothDevice* device = | 3848 BluetoothDevice* device = adapter_->GetDevice( |
| 3840 adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3849 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3841 | 3850 |
| 3842 device->Connect(nullptr, GetCallback(), | 3851 device->Connect(nullptr, GetCallback(), |
| 3843 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3852 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3844 base::Unretained(this))); | 3853 base::Unretained(this))); |
| 3845 EXPECT_TRUE(device->IsConnected()); | 3854 EXPECT_TRUE(device->IsConnected()); |
| 3846 | 3855 |
| 3847 // Calling GetConnectionInfo for a connected device should return valid | 3856 // Calling GetConnectionInfo for a connected device should return valid |
| 3848 // results. | 3857 // results. |
| 3849 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); | 3858 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); |
| 3850 BluetoothDevice::ConnectionInfo conn_info; | 3859 BluetoothDevice::ConnectionInfo conn_info; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3875 | 3884 |
| 3876 // Validate running adapter state. | 3885 // Validate running adapter state. |
| 3877 EXPECT_NE("", adapter_->GetAddress()); | 3886 EXPECT_NE("", adapter_->GetAddress()); |
| 3878 EXPECT_NE("", adapter_->GetName()); | 3887 EXPECT_NE("", adapter_->GetName()); |
| 3879 EXPECT_TRUE(adapter_->IsInitialized()); | 3888 EXPECT_TRUE(adapter_->IsInitialized()); |
| 3880 EXPECT_TRUE(adapter_->IsPresent()); | 3889 EXPECT_TRUE(adapter_->IsPresent()); |
| 3881 EXPECT_TRUE(adapter_->IsPowered()); | 3890 EXPECT_TRUE(adapter_->IsPowered()); |
| 3882 EXPECT_TRUE(adapter_->IsDiscoverable()); | 3891 EXPECT_TRUE(adapter_->IsDiscoverable()); |
| 3883 EXPECT_TRUE(adapter_->IsDiscovering()); | 3892 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 3884 EXPECT_EQ(2U, adapter_->GetDevices().size()); | 3893 EXPECT_EQ(2U, adapter_->GetDevices().size()); |
| 3885 EXPECT_NE(nullptr, adapter_->GetDevice( | 3894 EXPECT_NE(nullptr, |
| 3886 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 3895 adapter_->GetDevice( |
| 3896 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3887 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | 3897 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
| 3888 adapter_.get())->object_path()); | 3898 adapter_.get())->object_path()); |
| 3889 | 3899 |
| 3890 // Shutdown | 3900 // Shutdown |
| 3891 adapter_->Shutdown(); | 3901 adapter_->Shutdown(); |
| 3892 | 3902 |
| 3893 // Validate post shutdown state by calling all BluetoothAdapterChromeOS | 3903 // Validate post shutdown state by calling all BluetoothAdapterChromeOS |
| 3894 // members, in declaration order: | 3904 // members, in declaration order: |
| 3895 | 3905 |
| 3896 adapter_->Shutdown(); | 3906 adapter_->Shutdown(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3953 // NotifyGattCharacteristicValueChanged | 3963 // NotifyGattCharacteristicValueChanged |
| 3954 // NotifyGattDescriptorValueChanged | 3964 // NotifyGattDescriptorValueChanged |
| 3955 | 3965 |
| 3956 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); | 3966 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); |
| 3957 | 3967 |
| 3958 adapter_profile_ = nullptr; | 3968 adapter_profile_ = nullptr; |
| 3959 | 3969 |
| 3960 FakeBluetoothProfileServiceProviderDelegate profile_delegate; | 3970 FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
| 3961 adapter_chrome_os->UseProfile( | 3971 adapter_chrome_os->UseProfile( |
| 3962 BluetoothUUID(), dbus::ObjectPath(""), | 3972 BluetoothUUID(), dbus::ObjectPath(""), |
| 3963 BluetoothProfileManagerClient::Options(), &profile_delegate, | 3973 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 3964 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 3974 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3965 base::Unretained(this)), | 3975 base::Unretained(this)), |
| 3966 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 3976 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3967 base::Unretained(this))); | 3977 base::Unretained(this))); |
| 3968 | 3978 |
| 3969 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 3979 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
| 3970 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 3980 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
| 3971 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 3981 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
| 3972 | 3982 |
| 3973 // Protected and private methods: | 3983 // Protected and private methods: |
| 3974 | 3984 |
| 3975 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); | 3985 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); |
| 3976 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. | 3986 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. |
| 3977 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); | 3987 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); |
| 3978 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); | 3988 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); |
| 3979 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); | 3989 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); |
| 3980 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); | 3990 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); |
| 3981 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); | 3991 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); |
| 3982 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); | 3992 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); |
| 3983 // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown, | 3993 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be |
| 3994 // shutdown, |
| 3984 // with the exception of Released. | 3995 // with the exception of Released. |
| 3985 adapter_chrome_os->Released(); | 3996 adapter_chrome_os->Released(); |
| 3986 | 3997 |
| 3987 adapter_chrome_os->OnRegisterAgent(); | 3998 adapter_chrome_os->OnRegisterAgent(); |
| 3988 adapter_chrome_os->OnRegisterAgentError("", ""); | 3999 adapter_chrome_os->OnRegisterAgentError("", ""); |
| 3989 adapter_chrome_os->OnRequestDefaultAgent(); | 4000 adapter_chrome_os->OnRequestDefaultAgent(); |
| 3990 adapter_chrome_os->OnRequestDefaultAgentError("", ""); | 4001 adapter_chrome_os->OnRequestDefaultAgentError("", ""); |
| 3991 | 4002 |
| 3992 adapter_chrome_os->OnRegisterAudioSink( | 4003 adapter_chrome_os->OnRegisterAudioSink( |
| 3993 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, | 4004 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4030 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError | 4041 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError |
| 4031 // OnStopDiscovery tested in Shutdown_OnStopDiscovery | 4042 // OnStopDiscovery tested in Shutdown_OnStopDiscovery |
| 4032 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError | 4043 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError |
| 4033 | 4044 |
| 4034 adapter_profile_ = nullptr; | 4045 adapter_profile_ = nullptr; |
| 4035 | 4046 |
| 4036 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require | 4047 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require |
| 4037 // UseProfile to be set first, do so again here just before calling them. | 4048 // UseProfile to be set first, do so again here just before calling them. |
| 4038 adapter_chrome_os->UseProfile( | 4049 adapter_chrome_os->UseProfile( |
| 4039 BluetoothUUID(), dbus::ObjectPath(""), | 4050 BluetoothUUID(), dbus::ObjectPath(""), |
| 4040 BluetoothProfileManagerClient::Options(), &profile_delegate, | 4051 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 4041 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 4052 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 4042 base::Unretained(this)), | 4053 base::Unretained(this)), |
| 4043 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 4054 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 4044 base::Unretained(this))); | 4055 base::Unretained(this))); |
| 4045 | 4056 |
| 4046 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 4057 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
| 4047 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 4058 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
| 4048 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 4059 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
| 4049 | 4060 |
| 4050 adapter_chrome_os->SetProfileDelegate( | 4061 adapter_chrome_os->SetProfileDelegate( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4065 // From BluetoothAdapater: | 4076 // From BluetoothAdapater: |
| 4066 | 4077 |
| 4067 adapter_->StartDiscoverySession( | 4078 adapter_->StartDiscoverySession( |
| 4068 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 4079 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 4069 base::Unretained(this)), | 4080 base::Unretained(this)), |
| 4070 GetErrorCallback()); | 4081 GetErrorCallback()); |
| 4071 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; | 4082 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
| 4072 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; | 4083 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; |
| 4073 | 4084 |
| 4074 EXPECT_EQ(0U, adapter_->GetDevices().size()); | 4085 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 4075 EXPECT_EQ(nullptr, adapter_->GetDevice( | 4086 EXPECT_EQ(nullptr, |
| 4076 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 4087 adapter_->GetDevice( |
| 4088 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 4077 TestPairingDelegate pairing_delegate2; | 4089 TestPairingDelegate pairing_delegate2; |
| 4078 adapter_->AddPairingDelegate( | 4090 adapter_->AddPairingDelegate( |
| 4079 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 4091 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 4080 adapter_->RemovePairingDelegate(&pairing_delegate2); | 4092 adapter_->RemovePairingDelegate(&pairing_delegate2); |
| 4081 } | 4093 } |
| 4082 | 4094 |
| 4083 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. | 4095 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
| 4084 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { | 4096 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { |
| 4085 const int kNumberOfDiscoverySessions = 10; | 4097 const int kNumberOfDiscoverySessions = 10; |
| 4086 GetAdapter(); | 4098 GetAdapter(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4174 adapter_->Shutdown(); | 4186 adapter_->Shutdown(); |
| 4175 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4187 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
| 4176 | 4188 |
| 4177 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4189 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
| 4178 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4190 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
| 4179 EXPECT_EQ(0, callback_count_); | 4191 EXPECT_EQ(0, callback_count_); |
| 4180 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4192 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
| 4181 } | 4193 } |
| 4182 | 4194 |
| 4183 } // namespace chromeos | 4195 } // namespace chromeos |
| OLD | NEW |