| 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, DeviceUuidsChanged) { | 2184 TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { |
| 2176 // Simulate a change of advertised services of a device. | 2185 // Simulate a change of advertised services 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 | 2192 |
| 2184 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); | 2193 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); |
| 2185 ASSERT_EQ(2U, uuids.size()); | 2194 ASSERT_EQ(2U, uuids.size()); |
| 2186 ASSERT_EQ(uuids[0], BluetoothUUID("1800")); | 2195 ASSERT_EQ(uuids[0], BluetoothUUID("1800")); |
| 2187 ASSERT_EQ(uuids[1], BluetoothUUID("1801")); | 2196 ASSERT_EQ(uuids[1], BluetoothUUID("1801")); |
| 2188 | 2197 |
| 2189 // Install an observer; expect the DeviceChanged method to be called when | 2198 // Install an observer; expect the DeviceChanged method to be called when |
| 2190 // we change the class of the device. | 2199 // we change the class of the device. |
| 2191 TestBluetoothAdapterObserver observer(adapter_); | 2200 TestBluetoothAdapterObserver observer(adapter_); |
| 2192 | 2201 |
| 2193 FakeBluetoothDeviceClient::Properties* properties = | 2202 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2194 fake_bluetooth_device_client_->GetProperties( | 2203 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2195 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2204 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2196 | 2205 |
| 2197 std::vector<std::string> new_uuids; | 2206 std::vector<std::string> new_uuids; |
| 2198 new_uuids.push_back(uuids[0].canonical_value()); | 2207 new_uuids.push_back(uuids[0].canonical_value()); |
| 2199 new_uuids.push_back(uuids[1].canonical_value()); | 2208 new_uuids.push_back(uuids[1].canonical_value()); |
| 2200 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); | 2209 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); |
| 2201 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); | 2210 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); |
| 2202 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); | 2211 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); |
| 2203 | 2212 |
| 2204 properties->uuids.ReplaceValue(new_uuids); | 2213 properties->uuids.ReplaceValue(new_uuids); |
| 2205 | 2214 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2216 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); | 2225 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); |
| 2217 } | 2226 } |
| 2218 | 2227 |
| 2219 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { | 2228 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { |
| 2220 // Simulate invalidation of inquiry RSSI of a device, as it occurs | 2229 // Simulate invalidation of inquiry RSSI of a device, as it occurs |
| 2221 // when discovery is finished. | 2230 // when discovery is finished. |
| 2222 GetAdapter(); | 2231 GetAdapter(); |
| 2223 | 2232 |
| 2224 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2233 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2225 ASSERT_EQ(2U, devices.size()); | 2234 ASSERT_EQ(2U, devices.size()); |
| 2226 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2235 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2227 devices[0]->GetAddress()); | 2236 devices[0]->GetAddress()); |
| 2228 | 2237 |
| 2229 FakeBluetoothDeviceClient::Properties* properties = | 2238 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2230 fake_bluetooth_device_client_->GetProperties( | 2239 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2231 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2240 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2232 | 2241 |
| 2233 // During discovery, rssi is a valid value (-75) | 2242 // During discovery, rssi is a valid value (-75) |
| 2234 properties->rssi.ReplaceValue(-75); | 2243 properties->rssi.ReplaceValue(-75); |
| 2235 properties->rssi.set_valid(true); | 2244 properties->rssi.set_valid(true); |
| 2236 | 2245 |
| 2237 ASSERT_EQ(-75, devices[0]->GetInquiryRSSI()); | 2246 ASSERT_EQ(-75, devices[0]->GetInquiryRSSI()); |
| 2238 | 2247 |
| 2239 // Install an observer; expect the DeviceChanged method to be called when | 2248 // Install an observer; expect the DeviceChanged method to be called when |
| 2240 // we invalidate the RSSI of the device. | 2249 // we invalidate the RSSI of the device. |
| 2241 TestBluetoothAdapterObserver observer(adapter_); | 2250 TestBluetoothAdapterObserver observer(adapter_); |
| 2242 | 2251 |
| 2243 // When discovery is over, the value should be invalidated. | 2252 // When discovery is over, the value should be invalidated. |
| 2244 properties->rssi.set_valid(false); | 2253 properties->rssi.set_valid(false); |
| 2245 properties->NotifyPropertyChanged(properties->rssi.name()); | 2254 properties->NotifyPropertyChanged(properties->rssi.name()); |
| 2246 | 2255 |
| 2247 EXPECT_EQ(1, observer.device_changed_count()); | 2256 EXPECT_EQ(1, observer.device_changed_count()); |
| 2248 EXPECT_EQ(devices[0], observer.last_device()); | 2257 EXPECT_EQ(devices[0], observer.last_device()); |
| 2249 | 2258 |
| 2250 int unknown_power = BluetoothDevice::kUnknownPower; | 2259 int unknown_power = BluetoothDevice::kUnknownPower; |
| 2251 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); | 2260 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); |
| 2252 } | 2261 } |
| 2253 | 2262 |
| 2254 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { | 2263 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { |
| 2255 // Simulate invalidation of inquiry TxPower of a device, as it occurs | 2264 // Simulate invalidation of inquiry TxPower of a device, as it occurs |
| 2256 // when discovery is finished. | 2265 // when discovery is finished. |
| 2257 GetAdapter(); | 2266 GetAdapter(); |
| 2258 | 2267 |
| 2259 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2268 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2260 ASSERT_EQ(2U, devices.size()); | 2269 ASSERT_EQ(2U, devices.size()); |
| 2261 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2270 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2262 devices[0]->GetAddress()); | 2271 devices[0]->GetAddress()); |
| 2263 | 2272 |
| 2264 FakeBluetoothDeviceClient::Properties* properties = | 2273 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2265 fake_bluetooth_device_client_->GetProperties( | 2274 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2266 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 2275 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2267 | 2276 |
| 2268 // During discovery, tx_power is a valid value (0) | 2277 // During discovery, tx_power is a valid value (0) |
| 2269 properties->tx_power.ReplaceValue(0); | 2278 properties->tx_power.ReplaceValue(0); |
| 2270 properties->tx_power.set_valid(true); | 2279 properties->tx_power.set_valid(true); |
| 2271 | 2280 |
| 2272 ASSERT_EQ(0, devices[0]->GetInquiryTxPower()); | 2281 ASSERT_EQ(0, devices[0]->GetInquiryTxPower()); |
| 2273 | 2282 |
| 2274 // Install an observer; expect the DeviceChanged method to be called when | 2283 // Install an observer; expect the DeviceChanged method to be called when |
| 2275 // we invalidate the tx_power of the device. | 2284 // we invalidate the tx_power of the device. |
| 2276 TestBluetoothAdapterObserver observer(adapter_); | 2285 TestBluetoothAdapterObserver observer(adapter_); |
| 2277 | 2286 |
| 2278 // When discovery is over, the value should be invalidated. | 2287 // When discovery is over, the value should be invalidated. |
| 2279 properties->tx_power.set_valid(false); | 2288 properties->tx_power.set_valid(false); |
| 2280 properties->NotifyPropertyChanged(properties->tx_power.name()); | 2289 properties->NotifyPropertyChanged(properties->tx_power.name()); |
| 2281 | 2290 |
| 2282 EXPECT_EQ(1, observer.device_changed_count()); | 2291 EXPECT_EQ(1, observer.device_changed_count()); |
| 2283 EXPECT_EQ(devices[0], observer.last_device()); | 2292 EXPECT_EQ(devices[0], observer.last_device()); |
| 2284 | 2293 |
| 2285 int unknown_power = BluetoothDevice::kUnknownPower; | 2294 int unknown_power = BluetoothDevice::kUnknownPower; |
| 2286 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); | 2295 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); |
| 2287 } | 2296 } |
| 2288 | 2297 |
| 2289 TEST_F(BluetoothChromeOSTest, ForgetDevice) { | 2298 TEST_F(BluetoothChromeOSTest, ForgetDevice) { |
| 2290 GetAdapter(); | 2299 GetAdapter(); |
| 2291 | 2300 |
| 2292 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2301 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2293 ASSERT_EQ(2U, devices.size()); | 2302 ASSERT_EQ(2U, devices.size()); |
| 2294 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, | 2303 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| 2295 devices[0]->GetAddress()); | 2304 devices[0]->GetAddress()); |
| 2296 | 2305 |
| 2297 std::string address = devices[0]->GetAddress(); | 2306 std::string address = devices[0]->GetAddress(); |
| 2298 | 2307 |
| 2299 // Install an observer; expect the DeviceRemoved method to be called | 2308 // Install an observer; expect the DeviceRemoved method to be called |
| 2300 // with the device we remove. | 2309 // with the device we remove. |
| 2301 TestBluetoothAdapterObserver observer(adapter_); | 2310 TestBluetoothAdapterObserver observer(adapter_); |
| 2302 | 2311 |
| 2303 devices[0]->Forget(GetErrorCallback()); | 2312 devices[0]->Forget(GetErrorCallback()); |
| 2304 EXPECT_EQ(0, error_callback_count_); | 2313 EXPECT_EQ(0, error_callback_count_); |
| 2305 | 2314 |
| 2306 EXPECT_EQ(1, observer.device_removed_count()); | 2315 EXPECT_EQ(1, observer.device_removed_count()); |
| 2307 EXPECT_EQ(address, observer.last_device_address()); | 2316 EXPECT_EQ(address, observer.last_device_address()); |
| 2308 | 2317 |
| 2309 // GetDevices shouldn't return the device either. | 2318 // GetDevices shouldn't return the device either. |
| 2310 devices = adapter_->GetDevices(); | 2319 devices = adapter_->GetDevices(); |
| 2311 ASSERT_EQ(1U, devices.size()); | 2320 ASSERT_EQ(1U, devices.size()); |
| 2312 } | 2321 } |
| 2313 | 2322 |
| 2314 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { | 2323 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { |
| 2315 GetAdapter(); | 2324 GetAdapter(); |
| 2316 DiscoverDevices(); | 2325 DiscoverDevices(); |
| 2317 | 2326 |
| 2318 BluetoothDevice* device = adapter_->GetDevice( | 2327 BluetoothDevice* device = adapter_->GetDevice( |
| 2319 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2328 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 2320 ASSERT_TRUE(device != nullptr); | 2329 ASSERT_TRUE(device != nullptr); |
| 2321 ASSERT_FALSE(device->IsPaired()); | 2330 ASSERT_FALSE(device->IsPaired()); |
| 2322 | 2331 |
| 2323 // Connect the device so it becomes trusted and remembered. | 2332 // Connect the device so it becomes trusted and remembered. |
| 2324 device->Connect(nullptr, GetCallback(), | 2333 device->Connect(nullptr, GetCallback(), |
| 2325 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2334 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2326 base::Unretained(this))); | 2335 base::Unretained(this))); |
| 2327 | 2336 |
| 2328 ASSERT_EQ(1, callback_count_); | 2337 ASSERT_EQ(1, callback_count_); |
| 2329 ASSERT_EQ(0, error_callback_count_); | 2338 ASSERT_EQ(0, error_callback_count_); |
| 2330 callback_count_ = 0; | 2339 callback_count_ = 0; |
| 2331 | 2340 |
| 2332 ASSERT_TRUE(device->IsConnected()); | 2341 ASSERT_TRUE(device->IsConnected()); |
| 2333 ASSERT_FALSE(device->IsConnecting()); | 2342 ASSERT_FALSE(device->IsConnecting()); |
| 2334 | 2343 |
| 2335 // Make sure the trusted property has been set to true. | 2344 // Make sure the trusted property has been set to true. |
| 2336 FakeBluetoothDeviceClient::Properties* properties = | 2345 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2337 fake_bluetooth_device_client_->GetProperties( | 2346 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2338 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); | 2347 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); |
| 2339 ASSERT_TRUE(properties->trusted.value()); | 2348 ASSERT_TRUE(properties->trusted.value()); |
| 2340 | 2349 |
| 2341 // Install an observer; expect the DeviceRemoved method to be called | 2350 // Install an observer; expect the DeviceRemoved method to be called |
| 2342 // with the device we remove. | 2351 // with the device we remove. |
| 2343 TestBluetoothAdapterObserver observer(adapter_); | 2352 TestBluetoothAdapterObserver observer(adapter_); |
| 2344 | 2353 |
| 2345 device->Forget(GetErrorCallback()); | 2354 device->Forget(GetErrorCallback()); |
| 2346 EXPECT_EQ(0, error_callback_count_); | 2355 EXPECT_EQ(0, error_callback_count_); |
| 2347 | 2356 |
| 2348 EXPECT_EQ(1, observer.device_removed_count()); | 2357 EXPECT_EQ(1, observer.device_removed_count()); |
| 2349 EXPECT_EQ(FakeBluetoothDeviceClient::kConnectUnpairableAddress, | 2358 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress, |
| 2350 observer.last_device_address()); | 2359 observer.last_device_address()); |
| 2351 | 2360 |
| 2352 // GetDevices shouldn't return the device either. | 2361 // GetDevices shouldn't return the device either. |
| 2353 device = adapter_->GetDevice( | 2362 device = adapter_->GetDevice( |
| 2354 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2363 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 2355 EXPECT_FALSE(device != nullptr); | 2364 EXPECT_FALSE(device != nullptr); |
| 2356 } | 2365 } |
| 2357 | 2366 |
| 2358 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { | 2367 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { |
| 2359 GetAdapter(); | 2368 GetAdapter(); |
| 2360 | 2369 |
| 2361 BluetoothDevice* device = adapter_->GetDevice( | 2370 BluetoothDevice* device = adapter_->GetDevice( |
| 2362 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2371 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2363 ASSERT_TRUE(device != nullptr); | 2372 ASSERT_TRUE(device != nullptr); |
| 2364 ASSERT_TRUE(device->IsPaired()); | 2373 ASSERT_TRUE(device->IsPaired()); |
| 2365 | 2374 |
| 2366 TestBluetoothAdapterObserver observer(adapter_); | 2375 TestBluetoothAdapterObserver observer(adapter_); |
| 2367 | 2376 |
| 2368 // Connect without a pairing delegate; since the device is already Paired | 2377 // Connect without a pairing delegate; since the device is already Paired |
| 2369 // this should succeed and the device should become connected. | 2378 // this should succeed and the device should become connected. |
| 2370 device->Connect(nullptr, GetCallback(), | 2379 device->Connect(nullptr, GetCallback(), |
| 2371 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2380 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2372 base::Unretained(this))); | 2381 base::Unretained(this))); |
| 2373 | 2382 |
| 2374 EXPECT_EQ(1, callback_count_); | 2383 EXPECT_EQ(1, callback_count_); |
| 2375 EXPECT_EQ(0, error_callback_count_); | 2384 EXPECT_EQ(0, error_callback_count_); |
| 2376 | 2385 |
| 2377 // Two changes for connecting, one for connected and one for for trusted | 2386 // Two changes for connecting, one for connected and one for for trusted |
| 2378 // after connecting. | 2387 // after connecting. |
| 2379 EXPECT_EQ(4, observer.device_changed_count()); | 2388 EXPECT_EQ(4, observer.device_changed_count()); |
| 2380 EXPECT_EQ(device, observer.last_device()); | 2389 EXPECT_EQ(device, observer.last_device()); |
| 2381 | 2390 |
| 2382 EXPECT_TRUE(device->IsConnected()); | 2391 EXPECT_TRUE(device->IsConnected()); |
| 2383 EXPECT_FALSE(device->IsConnecting()); | 2392 EXPECT_FALSE(device->IsConnecting()); |
| 2384 } | 2393 } |
| 2385 | 2394 |
| 2386 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { | 2395 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { |
| 2387 GetAdapter(); | 2396 GetAdapter(); |
| 2388 DiscoverDevices(); | 2397 DiscoverDevices(); |
| 2389 | 2398 |
| 2390 BluetoothDevice* device = adapter_->GetDevice( | 2399 BluetoothDevice* device = adapter_->GetDevice( |
| 2391 FakeBluetoothDeviceClient::kConnectUnpairableAddress); | 2400 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); |
| 2392 ASSERT_TRUE(device != nullptr); | 2401 ASSERT_TRUE(device != nullptr); |
| 2393 ASSERT_FALSE(device->IsPaired()); | 2402 ASSERT_FALSE(device->IsPaired()); |
| 2394 | 2403 |
| 2395 TestBluetoothAdapterObserver observer(adapter_); | 2404 TestBluetoothAdapterObserver observer(adapter_); |
| 2396 | 2405 |
| 2397 // Connect without a pairing delegate; since the device does not require | 2406 // Connect without a pairing delegate; since the device does not require |
| 2398 // pairing, this should succeed and the device should become connected. | 2407 // pairing, this should succeed and the device should become connected. |
| 2399 device->Connect(nullptr, GetCallback(), | 2408 device->Connect(nullptr, GetCallback(), |
| 2400 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2409 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2401 base::Unretained(this))); | 2410 base::Unretained(this))); |
| 2402 | 2411 |
| 2403 EXPECT_EQ(1, callback_count_); | 2412 EXPECT_EQ(1, callback_count_); |
| 2404 EXPECT_EQ(0, error_callback_count_); | 2413 EXPECT_EQ(0, error_callback_count_); |
| 2405 | 2414 |
| 2406 // Two changes for connecting, one for connected, one for for trusted after | 2415 // Two changes for connecting, one for connected, one for for trusted after |
| 2407 // connection, and one for the reconnect mode (IsConnectable). | 2416 // connection, and one for the reconnect mode (IsConnectable). |
| 2408 EXPECT_EQ(5, observer.device_changed_count()); | 2417 EXPECT_EQ(5, observer.device_changed_count()); |
| 2409 EXPECT_EQ(device, observer.last_device()); | 2418 EXPECT_EQ(device, observer.last_device()); |
| 2410 | 2419 |
| 2411 EXPECT_TRUE(device->IsConnected()); | 2420 EXPECT_TRUE(device->IsConnected()); |
| 2412 EXPECT_FALSE(device->IsConnecting()); | 2421 EXPECT_FALSE(device->IsConnecting()); |
| 2413 | 2422 |
| 2414 // Make sure the trusted property has been set to true. | 2423 // Make sure the trusted property has been set to true. |
| 2415 FakeBluetoothDeviceClient::Properties* properties = | 2424 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2416 fake_bluetooth_device_client_->GetProperties( | 2425 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2417 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); | 2426 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); |
| 2418 EXPECT_TRUE(properties->trusted.value()); | 2427 EXPECT_TRUE(properties->trusted.value()); |
| 2419 | 2428 |
| 2420 // Verify is a HID device and is not connectable. | 2429 // Verify is a HID device and is not connectable. |
| 2421 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2430 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2422 ASSERT_EQ(1U, uuids.size()); | 2431 ASSERT_EQ(1U, uuids.size()); |
| 2423 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2432 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2424 EXPECT_FALSE(device->IsConnectable()); | 2433 EXPECT_FALSE(device->IsConnectable()); |
| 2425 } | 2434 } |
| 2426 | 2435 |
| 2427 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { | 2436 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { |
| 2428 GetAdapter(); | 2437 GetAdapter(); |
| 2429 | 2438 |
| 2430 BluetoothDevice* device = adapter_->GetDevice( | 2439 BluetoothDevice* device = adapter_->GetDevice( |
| 2431 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2440 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2432 ASSERT_TRUE(device != nullptr); | 2441 ASSERT_TRUE(device != nullptr); |
| 2433 ASSERT_TRUE(device->IsPaired()); | 2442 ASSERT_TRUE(device->IsPaired()); |
| 2434 | 2443 |
| 2435 device->Connect(nullptr, GetCallback(), | 2444 device->Connect(nullptr, GetCallback(), |
| 2436 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2445 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2437 base::Unretained(this))); | 2446 base::Unretained(this))); |
| 2438 | 2447 |
| 2439 ASSERT_EQ(1, callback_count_); | 2448 ASSERT_EQ(1, callback_count_); |
| 2440 ASSERT_EQ(0, error_callback_count_); | 2449 ASSERT_EQ(0, error_callback_count_); |
| 2441 callback_count_ = 0; | 2450 callback_count_ = 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2459 | 2468 |
| 2460 EXPECT_TRUE(device->IsConnected()); | 2469 EXPECT_TRUE(device->IsConnected()); |
| 2461 EXPECT_FALSE(device->IsConnecting()); | 2470 EXPECT_FALSE(device->IsConnecting()); |
| 2462 } | 2471 } |
| 2463 | 2472 |
| 2464 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { | 2473 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { |
| 2465 GetAdapter(); | 2474 GetAdapter(); |
| 2466 DiscoverDevices(); | 2475 DiscoverDevices(); |
| 2467 | 2476 |
| 2468 BluetoothDevice* device = adapter_->GetDevice( | 2477 BluetoothDevice* device = adapter_->GetDevice( |
| 2469 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2478 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 2470 ASSERT_TRUE(device != nullptr); | 2479 ASSERT_TRUE(device != nullptr); |
| 2471 ASSERT_FALSE(device->IsPaired()); | 2480 ASSERT_FALSE(device->IsPaired()); |
| 2472 | 2481 |
| 2473 TestBluetoothAdapterObserver observer(adapter_); | 2482 TestBluetoothAdapterObserver observer(adapter_); |
| 2474 | 2483 |
| 2475 // Connect without a pairing delegate; since the device requires pairing, | 2484 // Connect without a pairing delegate; since the device requires pairing, |
| 2476 // this should fail with an error. | 2485 // this should fail with an error. |
| 2477 device->Connect(nullptr, GetCallback(), | 2486 device->Connect(nullptr, GetCallback(), |
| 2478 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2487 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2479 base::Unretained(this))); | 2488 base::Unretained(this))); |
| 2480 | 2489 |
| 2481 EXPECT_EQ(0, callback_count_); | 2490 EXPECT_EQ(0, callback_count_); |
| 2482 EXPECT_EQ(1, error_callback_count_); | 2491 EXPECT_EQ(1, error_callback_count_); |
| 2483 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); | 2492 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); |
| 2484 | 2493 |
| 2485 EXPECT_EQ(2, observer.device_changed_count()); | 2494 EXPECT_EQ(2, observer.device_changed_count()); |
| 2486 | 2495 |
| 2487 EXPECT_FALSE(device->IsConnected()); | 2496 EXPECT_FALSE(device->IsConnected()); |
| 2488 EXPECT_FALSE(device->IsConnecting()); | 2497 EXPECT_FALSE(device->IsConnecting()); |
| 2489 } | 2498 } |
| 2490 | 2499 |
| 2491 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { | 2500 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { |
| 2492 GetAdapter(); | 2501 GetAdapter(); |
| 2493 | 2502 |
| 2494 BluetoothDevice* device = adapter_->GetDevice( | 2503 BluetoothDevice* device = adapter_->GetDevice( |
| 2495 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2504 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2496 ASSERT_TRUE(device != nullptr); | 2505 ASSERT_TRUE(device != nullptr); |
| 2497 ASSERT_TRUE(device->IsPaired()); | 2506 ASSERT_TRUE(device->IsPaired()); |
| 2498 | 2507 |
| 2499 device->Connect(nullptr, GetCallback(), | 2508 device->Connect(nullptr, GetCallback(), |
| 2500 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2509 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2501 base::Unretained(this))); | 2510 base::Unretained(this))); |
| 2502 | 2511 |
| 2503 ASSERT_EQ(1, callback_count_); | 2512 ASSERT_EQ(1, callback_count_); |
| 2504 ASSERT_EQ(0, error_callback_count_); | 2513 ASSERT_EQ(0, error_callback_count_); |
| 2505 callback_count_ = 0; | 2514 callback_count_ = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2519 EXPECT_EQ(1, observer.device_changed_count()); | 2528 EXPECT_EQ(1, observer.device_changed_count()); |
| 2520 EXPECT_EQ(device, observer.last_device()); | 2529 EXPECT_EQ(device, observer.last_device()); |
| 2521 | 2530 |
| 2522 EXPECT_FALSE(device->IsConnected()); | 2531 EXPECT_FALSE(device->IsConnected()); |
| 2523 } | 2532 } |
| 2524 | 2533 |
| 2525 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { | 2534 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { |
| 2526 GetAdapter(); | 2535 GetAdapter(); |
| 2527 | 2536 |
| 2528 BluetoothDevice* device = adapter_->GetDevice( | 2537 BluetoothDevice* device = adapter_->GetDevice( |
| 2529 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2538 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2530 ASSERT_TRUE(device != nullptr); | 2539 ASSERT_TRUE(device != nullptr); |
| 2531 ASSERT_TRUE(device->IsPaired()); | 2540 ASSERT_TRUE(device->IsPaired()); |
| 2532 ASSERT_FALSE(device->IsConnected()); | 2541 ASSERT_FALSE(device->IsConnected()); |
| 2533 | 2542 |
| 2534 // Disconnect the device, we should see the observer method fire and the | 2543 // Disconnect the device, we should see the observer method fire and the |
| 2535 // device get dropped. | 2544 // device get dropped. |
| 2536 TestBluetoothAdapterObserver observer(adapter_); | 2545 TestBluetoothAdapterObserver observer(adapter_); |
| 2537 | 2546 |
| 2538 device->Disconnect(GetCallback(), GetErrorCallback()); | 2547 device->Disconnect(GetCallback(), GetErrorCallback()); |
| 2539 | 2548 |
| 2540 EXPECT_EQ(0, callback_count_); | 2549 EXPECT_EQ(0, callback_count_); |
| 2541 EXPECT_EQ(1, error_callback_count_); | 2550 EXPECT_EQ(1, error_callback_count_); |
| 2542 | 2551 |
| 2543 EXPECT_EQ(0, observer.device_changed_count()); | 2552 EXPECT_EQ(0, observer.device_changed_count()); |
| 2544 | 2553 |
| 2545 EXPECT_FALSE(device->IsConnected()); | 2554 EXPECT_FALSE(device->IsConnected()); |
| 2546 } | 2555 } |
| 2547 | 2556 |
| 2548 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { | 2557 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { |
| 2549 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2558 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2550 | 2559 |
| 2551 GetAdapter(); | 2560 GetAdapter(); |
| 2552 DiscoverDevices(); | 2561 DiscoverDevices(); |
| 2553 | 2562 |
| 2554 // The Legacy Autopair device requires no PIN or Passkey to pair because | 2563 // The Legacy Autopair device requires no PIN or Passkey to pair because |
| 2555 // the daemon provides 0000 to the device for us. | 2564 // the daemon provides 0000 to the device for us. |
| 2556 BluetoothDevice* device = adapter_->GetDevice( | 2565 BluetoothDevice* device = adapter_->GetDevice( |
| 2557 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 2566 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 2558 ASSERT_TRUE(device != nullptr); | 2567 ASSERT_TRUE(device != nullptr); |
| 2559 ASSERT_FALSE(device->IsPaired()); | 2568 ASSERT_FALSE(device->IsPaired()); |
| 2560 | 2569 |
| 2561 TestBluetoothAdapterObserver observer(adapter_); | 2570 TestBluetoothAdapterObserver observer(adapter_); |
| 2562 | 2571 |
| 2563 TestPairingDelegate pairing_delegate; | 2572 TestPairingDelegate pairing_delegate; |
| 2564 device->Connect(&pairing_delegate, GetCallback(), | 2573 device->Connect(&pairing_delegate, GetCallback(), |
| 2565 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2574 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2566 base::Unretained(this))); | 2575 base::Unretained(this))); |
| 2567 | 2576 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2584 | 2593 |
| 2585 EXPECT_TRUE(device->IsPaired()); | 2594 EXPECT_TRUE(device->IsPaired()); |
| 2586 | 2595 |
| 2587 // Verify is a HID device and is connectable. | 2596 // Verify is a HID device and is connectable. |
| 2588 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2597 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2589 ASSERT_EQ(1U, uuids.size()); | 2598 ASSERT_EQ(1U, uuids.size()); |
| 2590 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2599 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2591 EXPECT_TRUE(device->IsConnectable()); | 2600 EXPECT_TRUE(device->IsConnectable()); |
| 2592 | 2601 |
| 2593 // Make sure the trusted property has been set to true. | 2602 // Make sure the trusted property has been set to true. |
| 2594 FakeBluetoothDeviceClient::Properties* properties = | 2603 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2595 fake_bluetooth_device_client_->GetProperties( | 2604 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2596 dbus::ObjectPath(FakeBluetoothDeviceClient::kLegacyAutopairPath)); | 2605 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); |
| 2597 EXPECT_TRUE(properties->trusted.value()); | 2606 EXPECT_TRUE(properties->trusted.value()); |
| 2598 } | 2607 } |
| 2599 | 2608 |
| 2600 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { | 2609 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { |
| 2601 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2610 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2602 | 2611 |
| 2603 GetAdapter(); | 2612 GetAdapter(); |
| 2604 DiscoverDevices(); | 2613 DiscoverDevices(); |
| 2605 | 2614 |
| 2606 // Requires that we display a randomly generated PIN on the screen. | 2615 // Requires that we display a randomly generated PIN on the screen. |
| 2607 BluetoothDevice* device = adapter_->GetDevice( | 2616 BluetoothDevice* device = adapter_->GetDevice( |
| 2608 FakeBluetoothDeviceClient::kDisplayPinCodeAddress); | 2617 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress); |
| 2609 ASSERT_TRUE(device != nullptr); | 2618 ASSERT_TRUE(device != nullptr); |
| 2610 ASSERT_FALSE(device->IsPaired()); | 2619 ASSERT_FALSE(device->IsPaired()); |
| 2611 | 2620 |
| 2612 TestBluetoothAdapterObserver observer(adapter_); | 2621 TestBluetoothAdapterObserver observer(adapter_); |
| 2613 | 2622 |
| 2614 TestPairingDelegate pairing_delegate; | 2623 TestPairingDelegate pairing_delegate; |
| 2615 device->Connect(&pairing_delegate, GetCallback(), | 2624 device->Connect(&pairing_delegate, GetCallback(), |
| 2616 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2625 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2617 base::Unretained(this))); | 2626 base::Unretained(this))); |
| 2618 | 2627 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2637 | 2646 |
| 2638 EXPECT_TRUE(device->IsPaired()); | 2647 EXPECT_TRUE(device->IsPaired()); |
| 2639 | 2648 |
| 2640 // Verify is a HID device and is connectable. | 2649 // Verify is a HID device and is connectable. |
| 2641 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2650 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2642 ASSERT_EQ(1U, uuids.size()); | 2651 ASSERT_EQ(1U, uuids.size()); |
| 2643 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2652 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2644 EXPECT_TRUE(device->IsConnectable()); | 2653 EXPECT_TRUE(device->IsConnectable()); |
| 2645 | 2654 |
| 2646 // Make sure the trusted property has been set to true. | 2655 // Make sure the trusted property has been set to true. |
| 2647 FakeBluetoothDeviceClient::Properties* properties = | 2656 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2648 fake_bluetooth_device_client_->GetProperties( | 2657 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2649 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPinCodePath)); | 2658 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); |
| 2650 EXPECT_TRUE(properties->trusted.value()); | 2659 EXPECT_TRUE(properties->trusted.value()); |
| 2651 } | 2660 } |
| 2652 | 2661 |
| 2653 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { | 2662 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { |
| 2654 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2663 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2655 | 2664 |
| 2656 GetAdapter(); | 2665 GetAdapter(); |
| 2657 DiscoverDevices(); | 2666 DiscoverDevices(); |
| 2658 | 2667 |
| 2659 // Requires that we display a randomly generated Passkey on the screen, | 2668 // Requires that we display a randomly generated Passkey on the screen, |
| 2660 // and notifies us as it's typed in. | 2669 // and notifies us as it's typed in. |
| 2661 BluetoothDevice* device = adapter_->GetDevice( | 2670 BluetoothDevice* device = adapter_->GetDevice( |
| 2662 FakeBluetoothDeviceClient::kDisplayPasskeyAddress); | 2671 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress); |
| 2663 ASSERT_TRUE(device != nullptr); | 2672 ASSERT_TRUE(device != nullptr); |
| 2664 ASSERT_FALSE(device->IsPaired()); | 2673 ASSERT_FALSE(device->IsPaired()); |
| 2665 | 2674 |
| 2666 TestBluetoothAdapterObserver observer(adapter_); | 2675 TestBluetoothAdapterObserver observer(adapter_); |
| 2667 | 2676 |
| 2668 TestPairingDelegate pairing_delegate; | 2677 TestPairingDelegate pairing_delegate; |
| 2669 device->Connect(&pairing_delegate, GetCallback(), | 2678 device->Connect(&pairing_delegate, GetCallback(), |
| 2670 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2679 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2671 base::Unretained(this))); | 2680 base::Unretained(this))); |
| 2672 | 2681 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2712 | 2721 |
| 2713 // Verify is a HID device. | 2722 // Verify is a HID device. |
| 2714 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2723 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2715 ASSERT_EQ(1U, uuids.size()); | 2724 ASSERT_EQ(1U, uuids.size()); |
| 2716 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); | 2725 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); |
| 2717 | 2726 |
| 2718 // And usually not connectable. | 2727 // And usually not connectable. |
| 2719 EXPECT_FALSE(device->IsConnectable()); | 2728 EXPECT_FALSE(device->IsConnectable()); |
| 2720 | 2729 |
| 2721 // Make sure the trusted property has been set to true. | 2730 // Make sure the trusted property has been set to true. |
| 2722 FakeBluetoothDeviceClient::Properties* properties = | 2731 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2723 fake_bluetooth_device_client_->GetProperties( | 2732 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2724 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPasskeyPath)); | 2733 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); |
| 2725 EXPECT_TRUE(properties->trusted.value()); | 2734 EXPECT_TRUE(properties->trusted.value()); |
| 2726 } | 2735 } |
| 2727 | 2736 |
| 2728 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { | 2737 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { |
| 2729 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2738 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2730 | 2739 |
| 2731 GetAdapter(); | 2740 GetAdapter(); |
| 2732 DiscoverDevices(); | 2741 DiscoverDevices(); |
| 2733 | 2742 |
| 2734 // Requires that the user enters a PIN for them. | 2743 // Requires that the user enters a PIN for them. |
| 2735 BluetoothDevice* device = adapter_->GetDevice( | 2744 BluetoothDevice* device = adapter_->GetDevice( |
| 2736 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 2745 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 2737 ASSERT_TRUE(device != nullptr); | 2746 ASSERT_TRUE(device != nullptr); |
| 2738 ASSERT_FALSE(device->IsPaired()); | 2747 ASSERT_FALSE(device->IsPaired()); |
| 2739 | 2748 |
| 2740 TestBluetoothAdapterObserver observer(adapter_); | 2749 TestBluetoothAdapterObserver observer(adapter_); |
| 2741 | 2750 |
| 2742 TestPairingDelegate pairing_delegate; | 2751 TestPairingDelegate pairing_delegate; |
| 2743 device->Connect(&pairing_delegate, GetCallback(), | 2752 device->Connect(&pairing_delegate, GetCallback(), |
| 2744 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2753 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2745 base::Unretained(this))); | 2754 base::Unretained(this))); |
| 2746 | 2755 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2766 EXPECT_TRUE(device->IsPaired()); | 2775 EXPECT_TRUE(device->IsPaired()); |
| 2767 | 2776 |
| 2768 // Verify is not a HID device. | 2777 // Verify is not a HID device. |
| 2769 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 2778 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 2770 ASSERT_EQ(0U, uuids.size()); | 2779 ASSERT_EQ(0U, uuids.size()); |
| 2771 | 2780 |
| 2772 // Non HID devices are always connectable. | 2781 // Non HID devices are always connectable. |
| 2773 EXPECT_TRUE(device->IsConnectable()); | 2782 EXPECT_TRUE(device->IsConnectable()); |
| 2774 | 2783 |
| 2775 // Make sure the trusted property has been set to true. | 2784 // Make sure the trusted property has been set to true. |
| 2776 FakeBluetoothDeviceClient::Properties* properties = | 2785 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2777 fake_bluetooth_device_client_->GetProperties( | 2786 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2778 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 2787 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 2779 EXPECT_TRUE(properties->trusted.value()); | 2788 EXPECT_TRUE(properties->trusted.value()); |
| 2780 } | 2789 } |
| 2781 | 2790 |
| 2782 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { | 2791 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { |
| 2783 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2792 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2784 | 2793 |
| 2785 GetAdapter(); | 2794 GetAdapter(); |
| 2786 DiscoverDevices(); | 2795 DiscoverDevices(); |
| 2787 | 2796 |
| 2788 // Requests that we confirm a displayed passkey. | 2797 // Requests that we confirm a displayed passkey. |
| 2789 BluetoothDevice* device = adapter_->GetDevice( | 2798 BluetoothDevice* device = adapter_->GetDevice( |
| 2790 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 2799 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 2791 ASSERT_TRUE(device != nullptr); | 2800 ASSERT_TRUE(device != nullptr); |
| 2792 ASSERT_FALSE(device->IsPaired()); | 2801 ASSERT_FALSE(device->IsPaired()); |
| 2793 | 2802 |
| 2794 TestBluetoothAdapterObserver observer(adapter_); | 2803 TestBluetoothAdapterObserver observer(adapter_); |
| 2795 | 2804 |
| 2796 TestPairingDelegate pairing_delegate; | 2805 TestPairingDelegate pairing_delegate; |
| 2797 device->Connect(&pairing_delegate, GetCallback(), | 2806 device->Connect(&pairing_delegate, GetCallback(), |
| 2798 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2807 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2799 base::Unretained(this))); | 2808 base::Unretained(this))); |
| 2800 | 2809 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2817 | 2826 |
| 2818 EXPECT_TRUE(device->IsConnected()); | 2827 EXPECT_TRUE(device->IsConnected()); |
| 2819 EXPECT_FALSE(device->IsConnecting()); | 2828 EXPECT_FALSE(device->IsConnecting()); |
| 2820 | 2829 |
| 2821 EXPECT_TRUE(device->IsPaired()); | 2830 EXPECT_TRUE(device->IsPaired()); |
| 2822 | 2831 |
| 2823 // Non HID devices are always connectable. | 2832 // Non HID devices are always connectable. |
| 2824 EXPECT_TRUE(device->IsConnectable()); | 2833 EXPECT_TRUE(device->IsConnectable()); |
| 2825 | 2834 |
| 2826 // Make sure the trusted property has been set to true. | 2835 // Make sure the trusted property has been set to true. |
| 2827 FakeBluetoothDeviceClient::Properties* properties = | 2836 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2828 fake_bluetooth_device_client_->GetProperties( | 2837 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2829 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 2838 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 2830 EXPECT_TRUE(properties->trusted.value()); | 2839 EXPECT_TRUE(properties->trusted.value()); |
| 2831 } | 2840 } |
| 2832 | 2841 |
| 2833 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { | 2842 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { |
| 2834 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2843 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2835 | 2844 |
| 2836 GetAdapter(); | 2845 GetAdapter(); |
| 2837 DiscoverDevices(); | 2846 DiscoverDevices(); |
| 2838 | 2847 |
| 2839 // Requires that the user enters a Passkey, this would be some kind of | 2848 // Requires that the user enters a Passkey, this would be some kind of |
| 2840 // device that has a display, but doesn't use "just works" - maybe a car? | 2849 // device that has a display, but doesn't use "just works" - maybe a car? |
| 2841 BluetoothDevice* device = adapter_->GetDevice( | 2850 BluetoothDevice* device = adapter_->GetDevice( |
| 2842 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 2851 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 2843 ASSERT_TRUE(device != nullptr); | 2852 ASSERT_TRUE(device != nullptr); |
| 2844 ASSERT_FALSE(device->IsPaired()); | 2853 ASSERT_FALSE(device->IsPaired()); |
| 2845 | 2854 |
| 2846 TestBluetoothAdapterObserver observer(adapter_); | 2855 TestBluetoothAdapterObserver observer(adapter_); |
| 2847 | 2856 |
| 2848 TestPairingDelegate pairing_delegate; | 2857 TestPairingDelegate pairing_delegate; |
| 2849 device->Connect(&pairing_delegate, GetCallback(), | 2858 device->Connect(&pairing_delegate, GetCallback(), |
| 2850 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2859 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2851 base::Unretained(this))); | 2860 base::Unretained(this))); |
| 2852 | 2861 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2868 | 2877 |
| 2869 EXPECT_TRUE(device->IsConnected()); | 2878 EXPECT_TRUE(device->IsConnected()); |
| 2870 EXPECT_FALSE(device->IsConnecting()); | 2879 EXPECT_FALSE(device->IsConnecting()); |
| 2871 | 2880 |
| 2872 EXPECT_TRUE(device->IsPaired()); | 2881 EXPECT_TRUE(device->IsPaired()); |
| 2873 | 2882 |
| 2874 // Non HID devices are always connectable. | 2883 // Non HID devices are always connectable. |
| 2875 EXPECT_TRUE(device->IsConnectable()); | 2884 EXPECT_TRUE(device->IsConnectable()); |
| 2876 | 2885 |
| 2877 // Make sure the trusted property has been set to true. | 2886 // Make sure the trusted property has been set to true. |
| 2878 FakeBluetoothDeviceClient::Properties* properties = | 2887 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2879 fake_bluetooth_device_client_->GetProperties( | 2888 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2880 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 2889 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 2881 EXPECT_TRUE(properties->trusted.value()); | 2890 EXPECT_TRUE(properties->trusted.value()); |
| 2882 } | 2891 } |
| 2883 | 2892 |
| 2884 TEST_F(BluetoothChromeOSTest, PairJustWorks) { | 2893 TEST_F(BluetoothChromeOSTest, PairJustWorks) { |
| 2885 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2894 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2886 | 2895 |
| 2887 GetAdapter(); | 2896 GetAdapter(); |
| 2888 DiscoverDevices(); | 2897 DiscoverDevices(); |
| 2889 | 2898 |
| 2890 // Uses just-works pairing, since this is an outgoing pairing, no delegate | 2899 // Uses just-works pairing, since this is an outgoing pairing, no delegate |
| 2891 // interaction is required. | 2900 // interaction is required. |
| 2892 BluetoothDevice* device = adapter_->GetDevice( | 2901 BluetoothDevice* device = |
| 2893 FakeBluetoothDeviceClient::kJustWorksAddress); | 2902 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
| 2894 ASSERT_TRUE(device != nullptr); | 2903 ASSERT_TRUE(device != nullptr); |
| 2895 ASSERT_FALSE(device->IsPaired()); | 2904 ASSERT_FALSE(device->IsPaired()); |
| 2896 | 2905 |
| 2897 TestBluetoothAdapterObserver observer(adapter_); | 2906 TestBluetoothAdapterObserver observer(adapter_); |
| 2898 | 2907 |
| 2899 TestPairingDelegate pairing_delegate; | 2908 TestPairingDelegate pairing_delegate; |
| 2900 device->Connect(&pairing_delegate, GetCallback(), | 2909 device->Connect(&pairing_delegate, GetCallback(), |
| 2901 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2910 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2902 base::Unretained(this))); | 2911 base::Unretained(this))); |
| 2903 | 2912 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2915 | 2924 |
| 2916 EXPECT_TRUE(device->IsConnected()); | 2925 EXPECT_TRUE(device->IsConnected()); |
| 2917 EXPECT_FALSE(device->IsConnecting()); | 2926 EXPECT_FALSE(device->IsConnecting()); |
| 2918 | 2927 |
| 2919 EXPECT_TRUE(device->IsPaired()); | 2928 EXPECT_TRUE(device->IsPaired()); |
| 2920 | 2929 |
| 2921 // Non HID devices are always connectable. | 2930 // Non HID devices are always connectable. |
| 2922 EXPECT_TRUE(device->IsConnectable()); | 2931 EXPECT_TRUE(device->IsConnectable()); |
| 2923 | 2932 |
| 2924 // Make sure the trusted property has been set to true. | 2933 // Make sure the trusted property has been set to true. |
| 2925 FakeBluetoothDeviceClient::Properties* properties = | 2934 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2926 fake_bluetooth_device_client_->GetProperties( | 2935 fake_bluetooth_device_client_->GetProperties( |
| 2927 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 2936 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 2928 EXPECT_TRUE(properties->trusted.value()); | 2937 EXPECT_TRUE(properties->trusted.value()); |
| 2929 } | 2938 } |
| 2930 | 2939 |
| 2931 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { | 2940 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { |
| 2932 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2941 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2933 | 2942 |
| 2934 GetAdapter(); | 2943 GetAdapter(); |
| 2935 DiscoverDevice(FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 2944 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
| 2936 | 2945 |
| 2937 BluetoothDevice* device = adapter_->GetDevice( | 2946 BluetoothDevice* device = adapter_->GetDevice( |
| 2938 FakeBluetoothDeviceClient::kUnpairableDeviceAddress); | 2947 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress); |
| 2939 ASSERT_TRUE(device != nullptr); | 2948 ASSERT_TRUE(device != nullptr); |
| 2940 ASSERT_FALSE(device->IsPaired()); | 2949 ASSERT_FALSE(device->IsPaired()); |
| 2941 | 2950 |
| 2942 TestBluetoothAdapterObserver observer(adapter_); | 2951 TestBluetoothAdapterObserver observer(adapter_); |
| 2943 | 2952 |
| 2944 TestPairingDelegate pairing_delegate; | 2953 TestPairingDelegate pairing_delegate; |
| 2945 device->Connect(&pairing_delegate, GetCallback(), | 2954 device->Connect(&pairing_delegate, GetCallback(), |
| 2946 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2955 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2947 base::Unretained(this))); | 2956 base::Unretained(this))); |
| 2948 | 2957 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2959 | 2968 |
| 2960 EXPECT_FALSE(device->IsConnected()); | 2969 EXPECT_FALSE(device->IsConnected()); |
| 2961 EXPECT_FALSE(device->IsConnecting()); | 2970 EXPECT_FALSE(device->IsConnecting()); |
| 2962 EXPECT_FALSE(device->IsPaired()); | 2971 EXPECT_FALSE(device->IsPaired()); |
| 2963 } | 2972 } |
| 2964 | 2973 |
| 2965 TEST_F(BluetoothChromeOSTest, PairingFails) { | 2974 TEST_F(BluetoothChromeOSTest, PairingFails) { |
| 2966 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 2975 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 2967 | 2976 |
| 2968 GetAdapter(); | 2977 GetAdapter(); |
| 2969 DiscoverDevice(FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 2978 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
| 2970 | 2979 |
| 2971 // The vanishing device times out during pairing | 2980 // The vanishing device times out during pairing |
| 2972 BluetoothDevice* device = adapter_->GetDevice( | 2981 BluetoothDevice* device = adapter_->GetDevice( |
| 2973 FakeBluetoothDeviceClient::kVanishingDeviceAddress); | 2982 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); |
| 2974 ASSERT_TRUE(device != nullptr); | 2983 ASSERT_TRUE(device != nullptr); |
| 2975 ASSERT_FALSE(device->IsPaired()); | 2984 ASSERT_FALSE(device->IsPaired()); |
| 2976 | 2985 |
| 2977 TestBluetoothAdapterObserver observer(adapter_); | 2986 TestBluetoothAdapterObserver observer(adapter_); |
| 2978 | 2987 |
| 2979 TestPairingDelegate pairing_delegate; | 2988 TestPairingDelegate pairing_delegate; |
| 2980 device->Connect(&pairing_delegate, GetCallback(), | 2989 device->Connect(&pairing_delegate, GetCallback(), |
| 2981 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 2990 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 2982 base::Unretained(this))); | 2991 base::Unretained(this))); |
| 2983 | 2992 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2999 | 3008 |
| 3000 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { | 3009 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { |
| 3001 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3010 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3002 | 3011 |
| 3003 GetAdapter(); | 3012 GetAdapter(); |
| 3004 DiscoverDevices(); | 3013 DiscoverDevices(); |
| 3005 | 3014 |
| 3006 // Everything seems to go according to plan with the unconnectable device; | 3015 // Everything seems to go according to plan with the unconnectable device; |
| 3007 // it pairs, but then you can't make connections to it after. | 3016 // it pairs, but then you can't make connections to it after. |
| 3008 BluetoothDevice* device = adapter_->GetDevice( | 3017 BluetoothDevice* device = adapter_->GetDevice( |
| 3009 FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); | 3018 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); |
| 3010 ASSERT_TRUE(device != nullptr); | 3019 ASSERT_TRUE(device != nullptr); |
| 3011 ASSERT_FALSE(device->IsPaired()); | 3020 ASSERT_FALSE(device->IsPaired()); |
| 3012 | 3021 |
| 3013 TestBluetoothAdapterObserver observer(adapter_); | 3022 TestBluetoothAdapterObserver observer(adapter_); |
| 3014 | 3023 |
| 3015 TestPairingDelegate pairing_delegate; | 3024 TestPairingDelegate pairing_delegate; |
| 3016 device->Connect(&pairing_delegate, GetCallback(), | 3025 device->Connect(&pairing_delegate, GetCallback(), |
| 3017 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3026 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3018 base::Unretained(this))); | 3027 base::Unretained(this))); |
| 3019 | 3028 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3031 EXPECT_EQ(4, observer.device_changed_count()); | 3040 EXPECT_EQ(4, observer.device_changed_count()); |
| 3032 EXPECT_EQ(device, observer.last_device()); | 3041 EXPECT_EQ(device, observer.last_device()); |
| 3033 | 3042 |
| 3034 EXPECT_FALSE(device->IsConnected()); | 3043 EXPECT_FALSE(device->IsConnected()); |
| 3035 EXPECT_FALSE(device->IsConnecting()); | 3044 EXPECT_FALSE(device->IsConnecting()); |
| 3036 | 3045 |
| 3037 EXPECT_TRUE(device->IsPaired()); | 3046 EXPECT_TRUE(device->IsPaired()); |
| 3038 | 3047 |
| 3039 // Make sure the trusted property has been set to true still (since pairing | 3048 // Make sure the trusted property has been set to true still (since pairing |
| 3040 // worked). | 3049 // worked). |
| 3041 FakeBluetoothDeviceClient::Properties* properties = | 3050 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3042 fake_bluetooth_device_client_->GetProperties( | 3051 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3043 dbus::ObjectPath( | 3052 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath)); |
| 3044 FakeBluetoothDeviceClient::kUnconnectableDevicePath)); | |
| 3045 EXPECT_TRUE(properties->trusted.value()); | 3053 EXPECT_TRUE(properties->trusted.value()); |
| 3046 } | 3054 } |
| 3047 | 3055 |
| 3048 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { | 3056 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { |
| 3049 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3057 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3050 | 3058 |
| 3051 GetAdapter(); | 3059 GetAdapter(); |
| 3052 DiscoverDevices(); | 3060 DiscoverDevices(); |
| 3053 | 3061 |
| 3054 // Reject the pairing after we receive a request for the PIN code. | 3062 // Reject the pairing after we receive a request for the PIN code. |
| 3055 BluetoothDevice* device = adapter_->GetDevice( | 3063 BluetoothDevice* device = adapter_->GetDevice( |
| 3056 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3064 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3057 ASSERT_TRUE(device != nullptr); | 3065 ASSERT_TRUE(device != nullptr); |
| 3058 ASSERT_FALSE(device->IsPaired()); | 3066 ASSERT_FALSE(device->IsPaired()); |
| 3059 | 3067 |
| 3060 TestBluetoothAdapterObserver observer(adapter_); | 3068 TestBluetoothAdapterObserver observer(adapter_); |
| 3061 | 3069 |
| 3062 TestPairingDelegate pairing_delegate; | 3070 TestPairingDelegate pairing_delegate; |
| 3063 device->Connect(&pairing_delegate, GetCallback(), | 3071 device->Connect(&pairing_delegate, GetCallback(), |
| 3064 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3072 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3065 base::Unretained(this))); | 3073 base::Unretained(this))); |
| 3066 | 3074 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3084 } | 3092 } |
| 3085 | 3093 |
| 3086 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { | 3094 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { |
| 3087 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3095 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3088 | 3096 |
| 3089 GetAdapter(); | 3097 GetAdapter(); |
| 3090 DiscoverDevices(); | 3098 DiscoverDevices(); |
| 3091 | 3099 |
| 3092 // Cancel the pairing after we receive a request for the PIN code. | 3100 // Cancel the pairing after we receive a request for the PIN code. |
| 3093 BluetoothDevice* device = adapter_->GetDevice( | 3101 BluetoothDevice* device = adapter_->GetDevice( |
| 3094 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3102 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3095 ASSERT_TRUE(device != nullptr); | 3103 ASSERT_TRUE(device != nullptr); |
| 3096 ASSERT_FALSE(device->IsPaired()); | 3104 ASSERT_FALSE(device->IsPaired()); |
| 3097 | 3105 |
| 3098 TestBluetoothAdapterObserver observer(adapter_); | 3106 TestBluetoothAdapterObserver observer(adapter_); |
| 3099 | 3107 |
| 3100 TestPairingDelegate pairing_delegate; | 3108 TestPairingDelegate pairing_delegate; |
| 3101 device->Connect(&pairing_delegate, GetCallback(), | 3109 device->Connect(&pairing_delegate, GetCallback(), |
| 3102 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3110 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3103 base::Unretained(this))); | 3111 base::Unretained(this))); |
| 3104 | 3112 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3122 } | 3130 } |
| 3123 | 3131 |
| 3124 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { | 3132 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { |
| 3125 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3133 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3126 | 3134 |
| 3127 GetAdapter(); | 3135 GetAdapter(); |
| 3128 DiscoverDevices(); | 3136 DiscoverDevices(); |
| 3129 | 3137 |
| 3130 // Reject the pairing after we receive a request for the passkey. | 3138 // Reject the pairing after we receive a request for the passkey. |
| 3131 BluetoothDevice* device = adapter_->GetDevice( | 3139 BluetoothDevice* device = adapter_->GetDevice( |
| 3132 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3140 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3133 ASSERT_TRUE(device != nullptr); | 3141 ASSERT_TRUE(device != nullptr); |
| 3134 ASSERT_FALSE(device->IsPaired()); | 3142 ASSERT_FALSE(device->IsPaired()); |
| 3135 | 3143 |
| 3136 TestBluetoothAdapterObserver observer(adapter_); | 3144 TestBluetoothAdapterObserver observer(adapter_); |
| 3137 | 3145 |
| 3138 TestPairingDelegate pairing_delegate; | 3146 TestPairingDelegate pairing_delegate; |
| 3139 device->Connect(&pairing_delegate, GetCallback(), | 3147 device->Connect(&pairing_delegate, GetCallback(), |
| 3140 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3148 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3141 base::Unretained(this))); | 3149 base::Unretained(this))); |
| 3142 | 3150 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3160 } | 3168 } |
| 3161 | 3169 |
| 3162 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { | 3170 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { |
| 3163 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3171 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3164 | 3172 |
| 3165 GetAdapter(); | 3173 GetAdapter(); |
| 3166 DiscoverDevices(); | 3174 DiscoverDevices(); |
| 3167 | 3175 |
| 3168 // Cancel the pairing after we receive a request for the passkey. | 3176 // Cancel the pairing after we receive a request for the passkey. |
| 3169 BluetoothDevice* device = adapter_->GetDevice( | 3177 BluetoothDevice* device = adapter_->GetDevice( |
| 3170 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3178 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3171 ASSERT_TRUE(device != nullptr); | 3179 ASSERT_TRUE(device != nullptr); |
| 3172 ASSERT_FALSE(device->IsPaired()); | 3180 ASSERT_FALSE(device->IsPaired()); |
| 3173 | 3181 |
| 3174 TestBluetoothAdapterObserver observer(adapter_); | 3182 TestBluetoothAdapterObserver observer(adapter_); |
| 3175 | 3183 |
| 3176 TestPairingDelegate pairing_delegate; | 3184 TestPairingDelegate pairing_delegate; |
| 3177 device->Connect(&pairing_delegate, GetCallback(), | 3185 device->Connect(&pairing_delegate, GetCallback(), |
| 3178 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3186 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3179 base::Unretained(this))); | 3187 base::Unretained(this))); |
| 3180 | 3188 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3198 } | 3206 } |
| 3199 | 3207 |
| 3200 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { | 3208 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { |
| 3201 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3209 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3202 | 3210 |
| 3203 GetAdapter(); | 3211 GetAdapter(); |
| 3204 DiscoverDevices(); | 3212 DiscoverDevices(); |
| 3205 | 3213 |
| 3206 // Reject the pairing after we receive a request for passkey confirmation. | 3214 // Reject the pairing after we receive a request for passkey confirmation. |
| 3207 BluetoothDevice* device = adapter_->GetDevice( | 3215 BluetoothDevice* device = adapter_->GetDevice( |
| 3208 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3216 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3209 ASSERT_TRUE(device != nullptr); | 3217 ASSERT_TRUE(device != nullptr); |
| 3210 ASSERT_FALSE(device->IsPaired()); | 3218 ASSERT_FALSE(device->IsPaired()); |
| 3211 | 3219 |
| 3212 TestBluetoothAdapterObserver observer(adapter_); | 3220 TestBluetoothAdapterObserver observer(adapter_); |
| 3213 | 3221 |
| 3214 TestPairingDelegate pairing_delegate; | 3222 TestPairingDelegate pairing_delegate; |
| 3215 device->Connect(&pairing_delegate, GetCallback(), | 3223 device->Connect(&pairing_delegate, GetCallback(), |
| 3216 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3224 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3217 base::Unretained(this))); | 3225 base::Unretained(this))); |
| 3218 | 3226 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3236 } | 3244 } |
| 3237 | 3245 |
| 3238 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { | 3246 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { |
| 3239 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3247 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3240 | 3248 |
| 3241 GetAdapter(); | 3249 GetAdapter(); |
| 3242 DiscoverDevices(); | 3250 DiscoverDevices(); |
| 3243 | 3251 |
| 3244 // Cancel the pairing after we receive a request for the passkey. | 3252 // Cancel the pairing after we receive a request for the passkey. |
| 3245 BluetoothDevice* device = adapter_->GetDevice( | 3253 BluetoothDevice* device = adapter_->GetDevice( |
| 3246 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3254 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3247 ASSERT_TRUE(device != nullptr); | 3255 ASSERT_TRUE(device != nullptr); |
| 3248 ASSERT_FALSE(device->IsPaired()); | 3256 ASSERT_FALSE(device->IsPaired()); |
| 3249 | 3257 |
| 3250 TestBluetoothAdapterObserver observer(adapter_); | 3258 TestBluetoothAdapterObserver observer(adapter_); |
| 3251 | 3259 |
| 3252 TestPairingDelegate pairing_delegate; | 3260 TestPairingDelegate pairing_delegate; |
| 3253 device->Connect(&pairing_delegate, GetCallback(), | 3261 device->Connect(&pairing_delegate, GetCallback(), |
| 3254 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3262 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3255 base::Unretained(this))); | 3263 base::Unretained(this))); |
| 3256 | 3264 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3274 } | 3282 } |
| 3275 | 3283 |
| 3276 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { | 3284 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { |
| 3277 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3285 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3278 | 3286 |
| 3279 GetAdapter(); | 3287 GetAdapter(); |
| 3280 DiscoverDevices(); | 3288 DiscoverDevices(); |
| 3281 | 3289 |
| 3282 // Cancel the pairing while we're waiting for the remote host. | 3290 // Cancel the pairing while we're waiting for the remote host. |
| 3283 BluetoothDevice* device = adapter_->GetDevice( | 3291 BluetoothDevice* device = adapter_->GetDevice( |
| 3284 FakeBluetoothDeviceClient::kLegacyAutopairAddress); | 3292 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); |
| 3285 ASSERT_TRUE(device != nullptr); | 3293 ASSERT_TRUE(device != nullptr); |
| 3286 ASSERT_FALSE(device->IsPaired()); | 3294 ASSERT_FALSE(device->IsPaired()); |
| 3287 | 3295 |
| 3288 TestBluetoothAdapterObserver observer(adapter_); | 3296 TestBluetoothAdapterObserver observer(adapter_); |
| 3289 | 3297 |
| 3290 TestPairingDelegate pairing_delegate; | 3298 TestPairingDelegate pairing_delegate; |
| 3291 device->Connect(&pairing_delegate, GetCallback(), | 3299 device->Connect(&pairing_delegate, GetCallback(), |
| 3292 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3300 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3293 base::Unretained(this))); | 3301 base::Unretained(this))); |
| 3294 | 3302 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3315 | 3323 |
| 3316 GetAdapter(); | 3324 GetAdapter(); |
| 3317 | 3325 |
| 3318 TestPairingDelegate pairing_delegate; | 3326 TestPairingDelegate pairing_delegate; |
| 3319 adapter_->AddPairingDelegate( | 3327 adapter_->AddPairingDelegate( |
| 3320 &pairing_delegate, | 3328 &pairing_delegate, |
| 3321 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3329 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3322 | 3330 |
| 3323 // Requires that we provide a PIN code. | 3331 // Requires that we provide a PIN code. |
| 3324 fake_bluetooth_device_client_->CreateDevice( | 3332 fake_bluetooth_device_client_->CreateDevice( |
| 3325 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3333 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3326 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3334 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3327 BluetoothDevice* device = adapter_->GetDevice( | 3335 BluetoothDevice* device = adapter_->GetDevice( |
| 3328 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3336 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3329 ASSERT_TRUE(device != nullptr); | 3337 ASSERT_TRUE(device != nullptr); |
| 3330 ASSERT_FALSE(device->IsPaired()); | 3338 ASSERT_FALSE(device->IsPaired()); |
| 3331 | 3339 |
| 3332 TestBluetoothAdapterObserver observer(adapter_); | 3340 TestBluetoothAdapterObserver observer(adapter_); |
| 3333 | 3341 |
| 3334 fake_bluetooth_device_client_->SimulatePairing( | 3342 fake_bluetooth_device_client_->SimulatePairing( |
| 3335 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true, | 3343 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), |
| 3336 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3344 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3337 base::Unretained(this))); | 3345 base::Unretained(this))); |
| 3338 | 3346 |
| 3339 EXPECT_EQ(1, pairing_delegate.call_count_); | 3347 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3340 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); | 3348 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); |
| 3341 | 3349 |
| 3342 // Set the PIN. | 3350 // Set the PIN. |
| 3343 device->SetPinCode("1234"); | 3351 device->SetPinCode("1234"); |
| 3344 message_loop_.Run(); | 3352 message_loop_.Run(); |
| 3345 | 3353 |
| 3346 EXPECT_EQ(1, callback_count_); | 3354 EXPECT_EQ(1, callback_count_); |
| 3347 EXPECT_EQ(0, error_callback_count_); | 3355 EXPECT_EQ(0, error_callback_count_); |
| 3348 | 3356 |
| 3349 // One change for paired, and one for trusted. | 3357 // One change for paired, and one for trusted. |
| 3350 EXPECT_EQ(2, observer.device_changed_count()); | 3358 EXPECT_EQ(2, observer.device_changed_count()); |
| 3351 EXPECT_EQ(device, observer.last_device()); | 3359 EXPECT_EQ(device, observer.last_device()); |
| 3352 | 3360 |
| 3353 EXPECT_TRUE(device->IsPaired()); | 3361 EXPECT_TRUE(device->IsPaired()); |
| 3354 | 3362 |
| 3355 // Make sure the trusted property has been set to true. | 3363 // Make sure the trusted property has been set to true. |
| 3356 FakeBluetoothDeviceClient::Properties* properties = | 3364 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3357 fake_bluetooth_device_client_->GetProperties( | 3365 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3358 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3366 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3359 ASSERT_TRUE(properties->trusted.value()); | 3367 ASSERT_TRUE(properties->trusted.value()); |
| 3360 | 3368 |
| 3361 // No pairing context should remain on the device. | 3369 // No pairing context should remain on the device. |
| 3362 BluetoothDeviceChromeOS* device_chromeos = | 3370 BluetoothDeviceChromeOS* device_chromeos = |
| 3363 static_cast<BluetoothDeviceChromeOS*>(device); | 3371 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3364 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3372 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3365 } | 3373 } |
| 3366 | 3374 |
| 3367 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { | 3375 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { |
| 3368 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3376 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3369 | 3377 |
| 3370 GetAdapter(); | 3378 GetAdapter(); |
| 3371 | 3379 |
| 3372 TestPairingDelegate pairing_delegate; | 3380 TestPairingDelegate pairing_delegate; |
| 3373 adapter_->AddPairingDelegate( | 3381 adapter_->AddPairingDelegate( |
| 3374 &pairing_delegate, | 3382 &pairing_delegate, |
| 3375 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3383 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3376 | 3384 |
| 3377 // Requests that we confirm a displayed passkey. | 3385 // Requests that we confirm a displayed passkey. |
| 3378 fake_bluetooth_device_client_->CreateDevice( | 3386 fake_bluetooth_device_client_->CreateDevice( |
| 3379 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3387 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3380 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3388 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3381 BluetoothDevice* device = adapter_->GetDevice( | 3389 BluetoothDevice* device = adapter_->GetDevice( |
| 3382 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3390 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3383 ASSERT_TRUE(device != nullptr); | 3391 ASSERT_TRUE(device != nullptr); |
| 3384 ASSERT_FALSE(device->IsPaired()); | 3392 ASSERT_FALSE(device->IsPaired()); |
| 3385 | 3393 |
| 3386 TestBluetoothAdapterObserver observer(adapter_); | 3394 TestBluetoothAdapterObserver observer(adapter_); |
| 3387 | 3395 |
| 3388 fake_bluetooth_device_client_->SimulatePairing( | 3396 fake_bluetooth_device_client_->SimulatePairing( |
| 3389 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true, | 3397 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), |
| 3390 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3398 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3391 base::Unretained(this))); | 3399 base::Unretained(this))); |
| 3392 | 3400 |
| 3393 EXPECT_EQ(1, pairing_delegate.call_count_); | 3401 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3394 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); | 3402 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); |
| 3395 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 3403 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
| 3396 | 3404 |
| 3397 // Confirm the passkey. | 3405 // Confirm the passkey. |
| 3398 device->ConfirmPairing(); | 3406 device->ConfirmPairing(); |
| 3399 message_loop_.Run(); | 3407 message_loop_.Run(); |
| 3400 | 3408 |
| 3401 EXPECT_EQ(1, callback_count_); | 3409 EXPECT_EQ(1, callback_count_); |
| 3402 EXPECT_EQ(0, error_callback_count_); | 3410 EXPECT_EQ(0, error_callback_count_); |
| 3403 | 3411 |
| 3404 // One change for paired, and one for trusted. | 3412 // One change for paired, and one for trusted. |
| 3405 EXPECT_EQ(2, observer.device_changed_count()); | 3413 EXPECT_EQ(2, observer.device_changed_count()); |
| 3406 EXPECT_EQ(device, observer.last_device()); | 3414 EXPECT_EQ(device, observer.last_device()); |
| 3407 | 3415 |
| 3408 EXPECT_TRUE(device->IsPaired()); | 3416 EXPECT_TRUE(device->IsPaired()); |
| 3409 | 3417 |
| 3410 // Make sure the trusted property has been set to true. | 3418 // Make sure the trusted property has been set to true. |
| 3411 FakeBluetoothDeviceClient::Properties* properties = | 3419 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3412 fake_bluetooth_device_client_->GetProperties( | 3420 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3413 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3421 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3414 ASSERT_TRUE(properties->trusted.value()); | 3422 ASSERT_TRUE(properties->trusted.value()); |
| 3415 | 3423 |
| 3416 // No pairing context should remain on the device. | 3424 // No pairing context should remain on the device. |
| 3417 BluetoothDeviceChromeOS* device_chromeos = | 3425 BluetoothDeviceChromeOS* device_chromeos = |
| 3418 static_cast<BluetoothDeviceChromeOS*>(device); | 3426 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3419 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3427 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3420 } | 3428 } |
| 3421 | 3429 |
| 3422 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { | 3430 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { |
| 3423 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3431 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3424 | 3432 |
| 3425 GetAdapter(); | 3433 GetAdapter(); |
| 3426 | 3434 |
| 3427 TestPairingDelegate pairing_delegate; | 3435 TestPairingDelegate pairing_delegate; |
| 3428 adapter_->AddPairingDelegate( | 3436 adapter_->AddPairingDelegate( |
| 3429 &pairing_delegate, | 3437 &pairing_delegate, |
| 3430 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3438 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3431 | 3439 |
| 3432 // Requests that we provide a Passkey. | 3440 // Requests that we provide a Passkey. |
| 3433 fake_bluetooth_device_client_->CreateDevice( | 3441 fake_bluetooth_device_client_->CreateDevice( |
| 3434 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3442 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3435 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3443 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3436 BluetoothDevice* device = adapter_->GetDevice( | 3444 BluetoothDevice* device = adapter_->GetDevice( |
| 3437 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3445 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3438 ASSERT_TRUE(device != nullptr); | 3446 ASSERT_TRUE(device != nullptr); |
| 3439 ASSERT_FALSE(device->IsPaired()); | 3447 ASSERT_FALSE(device->IsPaired()); |
| 3440 | 3448 |
| 3441 TestBluetoothAdapterObserver observer(adapter_); | 3449 TestBluetoothAdapterObserver observer(adapter_); |
| 3442 | 3450 |
| 3443 fake_bluetooth_device_client_->SimulatePairing( | 3451 fake_bluetooth_device_client_->SimulatePairing( |
| 3444 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, | 3452 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
| 3445 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3453 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3446 base::Unretained(this))); | 3454 base::Unretained(this))); |
| 3447 | 3455 |
| 3448 EXPECT_EQ(1, pairing_delegate.call_count_); | 3456 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3449 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3457 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 3450 | 3458 |
| 3451 // Set the Passkey. | 3459 // Set the Passkey. |
| 3452 device->SetPasskey(1234); | 3460 device->SetPasskey(1234); |
| 3453 message_loop_.Run(); | 3461 message_loop_.Run(); |
| 3454 | 3462 |
| 3455 EXPECT_EQ(1, callback_count_); | 3463 EXPECT_EQ(1, callback_count_); |
| 3456 EXPECT_EQ(0, error_callback_count_); | 3464 EXPECT_EQ(0, error_callback_count_); |
| 3457 | 3465 |
| 3458 // One change for paired, and one for trusted. | 3466 // One change for paired, and one for trusted. |
| 3459 EXPECT_EQ(2, observer.device_changed_count()); | 3467 EXPECT_EQ(2, observer.device_changed_count()); |
| 3460 EXPECT_EQ(device, observer.last_device()); | 3468 EXPECT_EQ(device, observer.last_device()); |
| 3461 | 3469 |
| 3462 EXPECT_TRUE(device->IsPaired()); | 3470 EXPECT_TRUE(device->IsPaired()); |
| 3463 | 3471 |
| 3464 // Make sure the trusted property has been set to true. | 3472 // Make sure the trusted property has been set to true. |
| 3465 FakeBluetoothDeviceClient::Properties* properties = | 3473 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3466 fake_bluetooth_device_client_->GetProperties( | 3474 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3467 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3475 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3468 ASSERT_TRUE(properties->trusted.value()); | 3476 ASSERT_TRUE(properties->trusted.value()); |
| 3469 | 3477 |
| 3470 // No pairing context should remain on the device. | 3478 // No pairing context should remain on the device. |
| 3471 BluetoothDeviceChromeOS* device_chromeos = | 3479 BluetoothDeviceChromeOS* device_chromeos = |
| 3472 static_cast<BluetoothDeviceChromeOS*>(device); | 3480 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3473 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3481 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3474 } | 3482 } |
| 3475 | 3483 |
| 3476 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { | 3484 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { |
| 3477 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3485 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3478 | 3486 |
| 3479 GetAdapter(); | 3487 GetAdapter(); |
| 3480 | 3488 |
| 3481 TestPairingDelegate pairing_delegate; | 3489 TestPairingDelegate pairing_delegate; |
| 3482 adapter_->AddPairingDelegate( | 3490 adapter_->AddPairingDelegate( |
| 3483 &pairing_delegate, | 3491 &pairing_delegate, |
| 3484 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3492 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3485 | 3493 |
| 3486 // Uses just-works pairing so, sinec this an incoming pairing, require | 3494 // Uses just-works pairing so, sinec this an incoming pairing, require |
| 3487 // authorization from the user. | 3495 // authorization from the user. |
| 3488 fake_bluetooth_device_client_->CreateDevice( | 3496 fake_bluetooth_device_client_->CreateDevice( |
| 3489 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3497 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3490 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 3498 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3491 BluetoothDevice* device = adapter_->GetDevice( | 3499 BluetoothDevice* device = |
| 3492 FakeBluetoothDeviceClient::kJustWorksAddress); | 3500 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
| 3493 ASSERT_TRUE(device != nullptr); | 3501 ASSERT_TRUE(device != nullptr); |
| 3494 ASSERT_FALSE(device->IsPaired()); | 3502 ASSERT_FALSE(device->IsPaired()); |
| 3495 | 3503 |
| 3496 TestBluetoothAdapterObserver observer(adapter_); | 3504 TestBluetoothAdapterObserver observer(adapter_); |
| 3497 | 3505 |
| 3498 fake_bluetooth_device_client_->SimulatePairing( | 3506 fake_bluetooth_device_client_->SimulatePairing( |
| 3499 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true, | 3507 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, |
| 3500 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3508 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3501 base::Unretained(this))); | 3509 base::Unretained(this))); |
| 3502 | 3510 |
| 3503 EXPECT_EQ(1, pairing_delegate.call_count_); | 3511 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3504 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); | 3512 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); |
| 3505 | 3513 |
| 3506 // Confirm the pairing. | 3514 // Confirm the pairing. |
| 3507 device->ConfirmPairing(); | 3515 device->ConfirmPairing(); |
| 3508 message_loop_.Run(); | 3516 message_loop_.Run(); |
| 3509 | 3517 |
| 3510 EXPECT_EQ(1, callback_count_); | 3518 EXPECT_EQ(1, callback_count_); |
| 3511 EXPECT_EQ(0, error_callback_count_); | 3519 EXPECT_EQ(0, error_callback_count_); |
| 3512 | 3520 |
| 3513 // One change for paired, and one for trusted. | 3521 // One change for paired, and one for trusted. |
| 3514 EXPECT_EQ(2, observer.device_changed_count()); | 3522 EXPECT_EQ(2, observer.device_changed_count()); |
| 3515 EXPECT_EQ(device, observer.last_device()); | 3523 EXPECT_EQ(device, observer.last_device()); |
| 3516 | 3524 |
| 3517 EXPECT_TRUE(device->IsPaired()); | 3525 EXPECT_TRUE(device->IsPaired()); |
| 3518 | 3526 |
| 3519 // Make sure the trusted property has been set to true. | 3527 // Make sure the trusted property has been set to true. |
| 3520 FakeBluetoothDeviceClient::Properties* properties = | 3528 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3521 fake_bluetooth_device_client_->GetProperties( | 3529 fake_bluetooth_device_client_->GetProperties( |
| 3522 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 3530 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3523 ASSERT_TRUE(properties->trusted.value()); | 3531 ASSERT_TRUE(properties->trusted.value()); |
| 3524 | 3532 |
| 3525 // No pairing context should remain on the device. | 3533 // No pairing context should remain on the device. |
| 3526 BluetoothDeviceChromeOS* device_chromeos = | 3534 BluetoothDeviceChromeOS* device_chromeos = |
| 3527 static_cast<BluetoothDeviceChromeOS*>(device); | 3535 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3528 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3536 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3529 } | 3537 } |
| 3530 | 3538 |
| 3531 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { | 3539 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { |
| 3532 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3540 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3533 | 3541 |
| 3534 GetAdapter(); | 3542 GetAdapter(); |
| 3535 | 3543 |
| 3536 // Requires that we provide a PIN Code, without a pairing delegate, | 3544 // Requires that we provide a PIN Code, without a pairing delegate, |
| 3537 // that will be rejected. | 3545 // that will be rejected. |
| 3538 fake_bluetooth_device_client_->CreateDevice( | 3546 fake_bluetooth_device_client_->CreateDevice( |
| 3539 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3547 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3540 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 3548 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 3541 BluetoothDevice* device = adapter_->GetDevice( | 3549 BluetoothDevice* device = adapter_->GetDevice( |
| 3542 FakeBluetoothDeviceClient::kRequestPinCodeAddress); | 3550 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); |
| 3543 ASSERT_TRUE(device != nullptr); | 3551 ASSERT_TRUE(device != nullptr); |
| 3544 ASSERT_FALSE(device->IsPaired()); | 3552 ASSERT_FALSE(device->IsPaired()); |
| 3545 | 3553 |
| 3546 TestBluetoothAdapterObserver observer(adapter_); | 3554 TestBluetoothAdapterObserver observer(adapter_); |
| 3547 | 3555 |
| 3548 fake_bluetooth_device_client_->SimulatePairing( | 3556 fake_bluetooth_device_client_->SimulatePairing( |
| 3549 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true, | 3557 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), |
| 3550 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3558 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3551 base::Unretained(this))); | 3559 base::Unretained(this))); |
| 3552 | 3560 |
| 3553 message_loop_.Run(); | 3561 message_loop_.Run(); |
| 3554 | 3562 |
| 3555 EXPECT_EQ(0, callback_count_); | 3563 EXPECT_EQ(0, callback_count_); |
| 3556 EXPECT_EQ(1, error_callback_count_); | 3564 EXPECT_EQ(1, error_callback_count_); |
| 3557 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3565 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3558 | 3566 |
| 3559 // No changes should be observer. | 3567 // No changes should be observer. |
| 3560 EXPECT_EQ(0, observer.device_changed_count()); | 3568 EXPECT_EQ(0, observer.device_changed_count()); |
| 3561 | 3569 |
| 3562 EXPECT_FALSE(device->IsPaired()); | 3570 EXPECT_FALSE(device->IsPaired()); |
| 3563 | 3571 |
| 3564 // No pairing context should remain on the device. | 3572 // No pairing context should remain on the device. |
| 3565 BluetoothDeviceChromeOS* device_chromeos = | 3573 BluetoothDeviceChromeOS* device_chromeos = |
| 3566 static_cast<BluetoothDeviceChromeOS*>(device); | 3574 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3567 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3575 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3568 } | 3576 } |
| 3569 | 3577 |
| 3570 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { | 3578 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { |
| 3571 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3579 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3572 | 3580 |
| 3573 GetAdapter(); | 3581 GetAdapter(); |
| 3574 | 3582 |
| 3575 // Requests that we confirm a displayed passkey, without a pairing delegate, | 3583 // Requests that we confirm a displayed passkey, without a pairing delegate, |
| 3576 // that will be rejected. | 3584 // that will be rejected. |
| 3577 fake_bluetooth_device_client_->CreateDevice( | 3585 fake_bluetooth_device_client_->CreateDevice( |
| 3578 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3586 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3579 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 3587 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 3580 BluetoothDevice* device = adapter_->GetDevice( | 3588 BluetoothDevice* device = adapter_->GetDevice( |
| 3581 FakeBluetoothDeviceClient::kConfirmPasskeyAddress); | 3589 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); |
| 3582 ASSERT_TRUE(device != nullptr); | 3590 ASSERT_TRUE(device != nullptr); |
| 3583 ASSERT_FALSE(device->IsPaired()); | 3591 ASSERT_FALSE(device->IsPaired()); |
| 3584 | 3592 |
| 3585 TestBluetoothAdapterObserver observer(adapter_); | 3593 TestBluetoothAdapterObserver observer(adapter_); |
| 3586 | 3594 |
| 3587 fake_bluetooth_device_client_->SimulatePairing( | 3595 fake_bluetooth_device_client_->SimulatePairing( |
| 3588 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true, | 3596 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), |
| 3589 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3597 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3590 base::Unretained(this))); | 3598 base::Unretained(this))); |
| 3591 | 3599 |
| 3592 message_loop_.Run(); | 3600 message_loop_.Run(); |
| 3593 | 3601 |
| 3594 EXPECT_EQ(0, callback_count_); | 3602 EXPECT_EQ(0, callback_count_); |
| 3595 EXPECT_EQ(1, error_callback_count_); | 3603 EXPECT_EQ(1, error_callback_count_); |
| 3596 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3604 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3597 | 3605 |
| 3598 // No changes should be observer. | 3606 // No changes should be observer. |
| 3599 EXPECT_EQ(0, observer.device_changed_count()); | 3607 EXPECT_EQ(0, observer.device_changed_count()); |
| 3600 | 3608 |
| 3601 EXPECT_FALSE(device->IsPaired()); | 3609 EXPECT_FALSE(device->IsPaired()); |
| 3602 | 3610 |
| 3603 // No pairing context should remain on the device. | 3611 // No pairing context should remain on the device. |
| 3604 BluetoothDeviceChromeOS* device_chromeos = | 3612 BluetoothDeviceChromeOS* device_chromeos = |
| 3605 static_cast<BluetoothDeviceChromeOS*>(device); | 3613 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3606 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3614 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3607 } | 3615 } |
| 3608 | 3616 |
| 3609 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { | 3617 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { |
| 3610 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3618 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3611 | 3619 |
| 3612 GetAdapter(); | 3620 GetAdapter(); |
| 3613 | 3621 |
| 3614 // Requests that we provide a displayed passkey, without a pairing delegate, | 3622 // Requests that we provide a displayed passkey, without a pairing delegate, |
| 3615 // that will be rejected. | 3623 // that will be rejected. |
| 3616 fake_bluetooth_device_client_->CreateDevice( | 3624 fake_bluetooth_device_client_->CreateDevice( |
| 3617 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3625 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3618 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3626 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3619 BluetoothDevice* device = adapter_->GetDevice( | 3627 BluetoothDevice* device = adapter_->GetDevice( |
| 3620 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3628 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3621 ASSERT_TRUE(device != nullptr); | 3629 ASSERT_TRUE(device != nullptr); |
| 3622 ASSERT_FALSE(device->IsPaired()); | 3630 ASSERT_FALSE(device->IsPaired()); |
| 3623 | 3631 |
| 3624 TestBluetoothAdapterObserver observer(adapter_); | 3632 TestBluetoothAdapterObserver observer(adapter_); |
| 3625 | 3633 |
| 3626 fake_bluetooth_device_client_->SimulatePairing( | 3634 fake_bluetooth_device_client_->SimulatePairing( |
| 3627 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, | 3635 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
| 3628 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3636 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3629 base::Unretained(this))); | 3637 base::Unretained(this))); |
| 3630 | 3638 |
| 3631 message_loop_.Run(); | 3639 message_loop_.Run(); |
| 3632 | 3640 |
| 3633 EXPECT_EQ(0, callback_count_); | 3641 EXPECT_EQ(0, callback_count_); |
| 3634 EXPECT_EQ(1, error_callback_count_); | 3642 EXPECT_EQ(1, error_callback_count_); |
| 3635 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3643 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3636 | 3644 |
| 3637 // No changes should be observer. | 3645 // No changes should be observer. |
| 3638 EXPECT_EQ(0, observer.device_changed_count()); | 3646 EXPECT_EQ(0, observer.device_changed_count()); |
| 3639 | 3647 |
| 3640 EXPECT_FALSE(device->IsPaired()); | 3648 EXPECT_FALSE(device->IsPaired()); |
| 3641 | 3649 |
| 3642 // No pairing context should remain on the device. | 3650 // No pairing context should remain on the device. |
| 3643 BluetoothDeviceChromeOS* device_chromeos = | 3651 BluetoothDeviceChromeOS* device_chromeos = |
| 3644 static_cast<BluetoothDeviceChromeOS*>(device); | 3652 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3645 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); | 3653 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); |
| 3646 } | 3654 } |
| 3647 | 3655 |
| 3648 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { | 3656 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { |
| 3649 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 3657 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
| 3650 | 3658 |
| 3651 GetAdapter(); | 3659 GetAdapter(); |
| 3652 | 3660 |
| 3653 // Uses just-works pairing and thus requires authorization for incoming | 3661 // Uses just-works pairing and thus requires authorization for incoming |
| 3654 // pairings, without a pairing delegate, that will be rejected. | 3662 // pairings, without a pairing delegate, that will be rejected. |
| 3655 fake_bluetooth_device_client_->CreateDevice( | 3663 fake_bluetooth_device_client_->CreateDevice( |
| 3656 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3664 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3657 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath)); | 3665 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); |
| 3658 BluetoothDevice* device = adapter_->GetDevice( | 3666 BluetoothDevice* device = |
| 3659 FakeBluetoothDeviceClient::kJustWorksAddress); | 3667 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); |
| 3660 ASSERT_TRUE(device != nullptr); | 3668 ASSERT_TRUE(device != nullptr); |
| 3661 ASSERT_FALSE(device->IsPaired()); | 3669 ASSERT_FALSE(device->IsPaired()); |
| 3662 | 3670 |
| 3663 TestBluetoothAdapterObserver observer(adapter_); | 3671 TestBluetoothAdapterObserver observer(adapter_); |
| 3664 | 3672 |
| 3665 fake_bluetooth_device_client_->SimulatePairing( | 3673 fake_bluetooth_device_client_->SimulatePairing( |
| 3666 dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true, | 3674 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, |
| 3667 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3675 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3668 base::Unretained(this))); | 3676 base::Unretained(this))); |
| 3669 | 3677 |
| 3670 message_loop_.Run(); | 3678 message_loop_.Run(); |
| 3671 | 3679 |
| 3672 EXPECT_EQ(0, callback_count_); | 3680 EXPECT_EQ(0, callback_count_); |
| 3673 EXPECT_EQ(1, error_callback_count_); | 3681 EXPECT_EQ(1, error_callback_count_); |
| 3674 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); | 3682 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); |
| 3675 | 3683 |
| 3676 // No changes should be observer. | 3684 // No changes should be observer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3689 | 3697 |
| 3690 GetAdapter(); | 3698 GetAdapter(); |
| 3691 | 3699 |
| 3692 TestPairingDelegate pairing_delegate; | 3700 TestPairingDelegate pairing_delegate; |
| 3693 adapter_->AddPairingDelegate( | 3701 adapter_->AddPairingDelegate( |
| 3694 &pairing_delegate, | 3702 &pairing_delegate, |
| 3695 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 3703 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 3696 | 3704 |
| 3697 // Requests that we provide a Passkey. | 3705 // Requests that we provide a Passkey. |
| 3698 fake_bluetooth_device_client_->CreateDevice( | 3706 fake_bluetooth_device_client_->CreateDevice( |
| 3699 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 3707 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 3700 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath)); | 3708 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); |
| 3701 BluetoothDevice* device = adapter_->GetDevice( | 3709 BluetoothDevice* device = adapter_->GetDevice( |
| 3702 FakeBluetoothDeviceClient::kRequestPasskeyAddress); | 3710 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); |
| 3703 ASSERT_TRUE(device != nullptr); | 3711 ASSERT_TRUE(device != nullptr); |
| 3704 ASSERT_FALSE(device->IsPaired()); | 3712 ASSERT_FALSE(device->IsPaired()); |
| 3705 | 3713 |
| 3706 TestBluetoothAdapterObserver observer(adapter_); | 3714 TestBluetoothAdapterObserver observer(adapter_); |
| 3707 | 3715 |
| 3708 fake_bluetooth_device_client_->SimulatePairing( | 3716 fake_bluetooth_device_client_->SimulatePairing( |
| 3709 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true, | 3717 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), |
| 3710 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, | 3718 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, |
| 3711 base::Unretained(this))); | 3719 base::Unretained(this))); |
| 3712 | 3720 |
| 3713 EXPECT_EQ(1, pairing_delegate.call_count_); | 3721 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 3714 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); | 3722 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); |
| 3715 | 3723 |
| 3716 // A pairing context should now be set on the device. | 3724 // A pairing context should now be set on the device. |
| 3717 BluetoothDeviceChromeOS* device_chromeos = | 3725 BluetoothDeviceChromeOS* device_chromeos = |
| 3718 static_cast<BluetoothDeviceChromeOS*>(device); | 3726 static_cast<BluetoothDeviceChromeOS*>(device); |
| 3719 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); | 3727 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); |
| 3720 | 3728 |
| 3721 // Removing the pairing delegate should remove that pairing context. | 3729 // Removing the pairing delegate should remove that pairing context. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3733 | 3741 |
| 3734 EXPECT_FALSE(device->IsPaired()); | 3742 EXPECT_FALSE(device->IsPaired()); |
| 3735 } | 3743 } |
| 3736 | 3744 |
| 3737 TEST_F(BluetoothChromeOSTest, DeviceId) { | 3745 TEST_F(BluetoothChromeOSTest, DeviceId) { |
| 3738 GetAdapter(); | 3746 GetAdapter(); |
| 3739 | 3747 |
| 3740 // Use the built-in paired device for this test, grab its Properties | 3748 // Use the built-in paired device for this test, grab its Properties |
| 3741 // structure so we can adjust the underlying modalias property. | 3749 // structure so we can adjust the underlying modalias property. |
| 3742 BluetoothDevice* device = adapter_->GetDevice( | 3750 BluetoothDevice* device = adapter_->GetDevice( |
| 3743 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3751 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3744 FakeBluetoothDeviceClient::Properties* properties = | 3752 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 3745 fake_bluetooth_device_client_->GetProperties( | 3753 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 3746 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); | 3754 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 3747 | 3755 |
| 3748 ASSERT_TRUE(device != nullptr); | 3756 ASSERT_TRUE(device != nullptr); |
| 3749 ASSERT_TRUE(properties != nullptr); | 3757 ASSERT_TRUE(properties != nullptr); |
| 3750 | 3758 |
| 3751 // Valid USB IF-assigned identifier. | 3759 // Valid USB IF-assigned identifier. |
| 3752 ASSERT_EQ("usb:v05ACp030Dd0306", properties->modalias.value()); | 3760 ASSERT_EQ("usb:v05ACp030Dd0306", properties->modalias.value()); |
| 3753 | 3761 |
| 3754 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, device->GetVendorIDSource()); | 3762 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, device->GetVendorIDSource()); |
| 3755 EXPECT_EQ(0x05ac, device->GetVendorID()); | 3763 EXPECT_EQ(0x05ac, device->GetVendorID()); |
| 3756 EXPECT_EQ(0x030d, device->GetProductID()); | 3764 EXPECT_EQ(0x030d, device->GetProductID()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3784 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); | 3792 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); |
| 3785 | 3793 |
| 3786 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); | 3794 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); |
| 3787 EXPECT_EQ(0, device->GetVendorID()); | 3795 EXPECT_EQ(0, device->GetVendorID()); |
| 3788 EXPECT_EQ(0, device->GetProductID()); | 3796 EXPECT_EQ(0, device->GetProductID()); |
| 3789 EXPECT_EQ(0, device->GetDeviceID()); | 3797 EXPECT_EQ(0, device->GetDeviceID()); |
| 3790 } | 3798 } |
| 3791 | 3799 |
| 3792 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { | 3800 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { |
| 3793 GetAdapter(); | 3801 GetAdapter(); |
| 3794 BluetoothDevice* device = | 3802 BluetoothDevice* device = adapter_->GetDevice( |
| 3795 adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3803 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3796 | 3804 |
| 3797 // Calling GetConnectionInfo for an unconnected device should return a result | 3805 // Calling GetConnectionInfo for an unconnected device should return a result |
| 3798 // in which all fields are filled with BluetoothDevice::kUnknownPower. | 3806 // in which all fields are filled with BluetoothDevice::kUnknownPower. |
| 3799 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); | 3807 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); |
| 3800 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3808 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
| 3801 int unknown_power = BluetoothDevice::kUnknownPower; | 3809 int unknown_power = BluetoothDevice::kUnknownPower; |
| 3802 EXPECT_NE(0, unknown_power); | 3810 EXPECT_NE(0, unknown_power); |
| 3803 EXPECT_EQ(unknown_power, conn_info.rssi); | 3811 EXPECT_EQ(unknown_power, conn_info.rssi); |
| 3804 EXPECT_EQ(unknown_power, conn_info.transmit_power); | 3812 EXPECT_EQ(unknown_power, conn_info.transmit_power); |
| 3805 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); | 3813 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); |
| 3806 } | 3814 } |
| 3807 | 3815 |
| 3808 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { | 3816 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { |
| 3809 GetAdapter(); | 3817 GetAdapter(); |
| 3810 BluetoothDevice* device = | 3818 BluetoothDevice* device = adapter_->GetDevice( |
| 3811 adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); | 3819 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 3812 | 3820 |
| 3813 device->Connect(nullptr, GetCallback(), | 3821 device->Connect(nullptr, GetCallback(), |
| 3814 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, | 3822 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, |
| 3815 base::Unretained(this))); | 3823 base::Unretained(this))); |
| 3816 EXPECT_TRUE(device->IsConnected()); | 3824 EXPECT_TRUE(device->IsConnected()); |
| 3817 | 3825 |
| 3818 // Calling GetConnectionInfo for a connected device should return valid | 3826 // Calling GetConnectionInfo for a connected device should return valid |
| 3819 // results. | 3827 // results. |
| 3820 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); | 3828 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); |
| 3821 BluetoothDevice::ConnectionInfo conn_info; | 3829 BluetoothDevice::ConnectionInfo conn_info; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3846 | 3854 |
| 3847 // Validate running adapter state. | 3855 // Validate running adapter state. |
| 3848 EXPECT_NE("", adapter_->GetAddress()); | 3856 EXPECT_NE("", adapter_->GetAddress()); |
| 3849 EXPECT_NE("", adapter_->GetName()); | 3857 EXPECT_NE("", adapter_->GetName()); |
| 3850 EXPECT_TRUE(adapter_->IsInitialized()); | 3858 EXPECT_TRUE(adapter_->IsInitialized()); |
| 3851 EXPECT_TRUE(adapter_->IsPresent()); | 3859 EXPECT_TRUE(adapter_->IsPresent()); |
| 3852 EXPECT_TRUE(adapter_->IsPowered()); | 3860 EXPECT_TRUE(adapter_->IsPowered()); |
| 3853 EXPECT_TRUE(adapter_->IsDiscoverable()); | 3861 EXPECT_TRUE(adapter_->IsDiscoverable()); |
| 3854 EXPECT_TRUE(adapter_->IsDiscovering()); | 3862 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 3855 EXPECT_EQ(2U, adapter_->GetDevices().size()); | 3863 EXPECT_EQ(2U, adapter_->GetDevices().size()); |
| 3856 EXPECT_NE(nullptr, adapter_->GetDevice( | 3864 EXPECT_NE(nullptr, |
| 3857 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 3865 adapter_->GetDevice( |
| 3866 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3858 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( | 3867 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
| 3859 adapter_.get())->object_path()); | 3868 adapter_.get())->object_path()); |
| 3860 | 3869 |
| 3861 // Shutdown | 3870 // Shutdown |
| 3862 adapter_->Shutdown(); | 3871 adapter_->Shutdown(); |
| 3863 | 3872 |
| 3864 // Validate post shutdown state by calling all BluetoothAdapterChromeOS | 3873 // Validate post shutdown state by calling all BluetoothAdapterChromeOS |
| 3865 // members, in declaration order: | 3874 // members, in declaration order: |
| 3866 | 3875 |
| 3867 adapter_->Shutdown(); | 3876 adapter_->Shutdown(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3924 // NotifyGattCharacteristicValueChanged | 3933 // NotifyGattCharacteristicValueChanged |
| 3925 // NotifyGattDescriptorValueChanged | 3934 // NotifyGattDescriptorValueChanged |
| 3926 | 3935 |
| 3927 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); | 3936 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); |
| 3928 | 3937 |
| 3929 adapter_profile_ = nullptr; | 3938 adapter_profile_ = nullptr; |
| 3930 | 3939 |
| 3931 FakeBluetoothProfileServiceProviderDelegate profile_delegate; | 3940 FakeBluetoothProfileServiceProviderDelegate profile_delegate; |
| 3932 adapter_chrome_os->UseProfile( | 3941 adapter_chrome_os->UseProfile( |
| 3933 BluetoothUUID(), dbus::ObjectPath(""), | 3942 BluetoothUUID(), dbus::ObjectPath(""), |
| 3934 BluetoothProfileManagerClient::Options(), &profile_delegate, | 3943 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 3935 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 3944 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 3936 base::Unretained(this)), | 3945 base::Unretained(this)), |
| 3937 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 3946 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 3938 base::Unretained(this))); | 3947 base::Unretained(this))); |
| 3939 | 3948 |
| 3940 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 3949 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
| 3941 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 3950 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
| 3942 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 3951 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
| 3943 | 3952 |
| 3944 // Protected and private methods: | 3953 // Protected and private methods: |
| 3945 | 3954 |
| 3946 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); | 3955 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); |
| 3947 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. | 3956 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. |
| 3948 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); | 3957 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); |
| 3949 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); | 3958 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); |
| 3950 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); | 3959 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); |
| 3951 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); | 3960 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); |
| 3952 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); | 3961 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); |
| 3953 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); | 3962 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); |
| 3954 // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown, | 3963 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be |
| 3964 // shutdown, |
| 3955 // with the exception of Released. | 3965 // with the exception of Released. |
| 3956 adapter_chrome_os->Released(); | 3966 adapter_chrome_os->Released(); |
| 3957 | 3967 |
| 3958 adapter_chrome_os->OnRegisterAgent(); | 3968 adapter_chrome_os->OnRegisterAgent(); |
| 3959 adapter_chrome_os->OnRegisterAgentError("", ""); | 3969 adapter_chrome_os->OnRegisterAgentError("", ""); |
| 3960 adapter_chrome_os->OnRequestDefaultAgent(); | 3970 adapter_chrome_os->OnRequestDefaultAgent(); |
| 3961 adapter_chrome_os->OnRequestDefaultAgentError("", ""); | 3971 adapter_chrome_os->OnRequestDefaultAgentError("", ""); |
| 3962 | 3972 |
| 3963 adapter_chrome_os->OnRegisterAudioSink( | 3973 adapter_chrome_os->OnRegisterAudioSink( |
| 3964 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, | 3974 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4001 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError | 4011 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError |
| 4002 // OnStopDiscovery tested in Shutdown_OnStopDiscovery | 4012 // OnStopDiscovery tested in Shutdown_OnStopDiscovery |
| 4003 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError | 4013 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError |
| 4004 | 4014 |
| 4005 adapter_profile_ = nullptr; | 4015 adapter_profile_ = nullptr; |
| 4006 | 4016 |
| 4007 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require | 4017 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require |
| 4008 // UseProfile to be set first, do so again here just before calling them. | 4018 // UseProfile to be set first, do so again here just before calling them. |
| 4009 adapter_chrome_os->UseProfile( | 4019 adapter_chrome_os->UseProfile( |
| 4010 BluetoothUUID(), dbus::ObjectPath(""), | 4020 BluetoothUUID(), dbus::ObjectPath(""), |
| 4011 BluetoothProfileManagerClient::Options(), &profile_delegate, | 4021 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, |
| 4012 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, | 4022 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, |
| 4013 base::Unretained(this)), | 4023 base::Unretained(this)), |
| 4014 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, | 4024 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, |
| 4015 base::Unretained(this))); | 4025 base::Unretained(this))); |
| 4016 | 4026 |
| 4017 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; | 4027 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; |
| 4018 EXPECT_EQ(0, callback_count_) << "UseProfile error"; | 4028 EXPECT_EQ(0, callback_count_) << "UseProfile error"; |
| 4019 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; | 4029 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; |
| 4020 | 4030 |
| 4021 adapter_chrome_os->SetProfileDelegate( | 4031 adapter_chrome_os->SetProfileDelegate( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4036 // From BluetoothAdapater: | 4046 // From BluetoothAdapater: |
| 4037 | 4047 |
| 4038 adapter_->StartDiscoverySession( | 4048 adapter_->StartDiscoverySession( |
| 4039 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 4049 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 4040 base::Unretained(this)), | 4050 base::Unretained(this)), |
| 4041 GetErrorCallback()); | 4051 GetErrorCallback()); |
| 4042 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; | 4052 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; |
| 4043 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; | 4053 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; |
| 4044 | 4054 |
| 4045 EXPECT_EQ(0U, adapter_->GetDevices().size()); | 4055 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 4046 EXPECT_EQ(nullptr, adapter_->GetDevice( | 4056 EXPECT_EQ(nullptr, |
| 4047 FakeBluetoothDeviceClient::kPairedDeviceAddress)); | 4057 adapter_->GetDevice( |
| 4058 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 4048 TestPairingDelegate pairing_delegate2; | 4059 TestPairingDelegate pairing_delegate2; |
| 4049 adapter_->AddPairingDelegate( | 4060 adapter_->AddPairingDelegate( |
| 4050 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 4061 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 4051 adapter_->RemovePairingDelegate(&pairing_delegate2); | 4062 adapter_->RemovePairingDelegate(&pairing_delegate2); |
| 4052 } | 4063 } |
| 4053 | 4064 |
| 4054 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. | 4065 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. |
| 4055 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { | 4066 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { |
| 4056 const int kNumberOfDiscoverySessions = 10; | 4067 const int kNumberOfDiscoverySessions = 10; |
| 4057 GetAdapter(); | 4068 GetAdapter(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4145 adapter_->Shutdown(); | 4156 adapter_->Shutdown(); |
| 4146 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4157 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
| 4147 | 4158 |
| 4148 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4159 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
| 4149 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4160 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
| 4150 EXPECT_EQ(0, callback_count_); | 4161 EXPECT_EQ(0, callback_count_); |
| 4151 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4162 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
| 4152 } | 4163 } |
| 4153 | 4164 |
| 4154 } // namespace chromeos | 4165 } // namespace chromeos |
| OLD | NEW |