Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Unified Diff: device/bluetooth/bluetooth_chromeos_unittest.cc

Issue 735893002: Add GetConnectionInfo function for BluetoothDevice, replacing the existing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile errors on other platforms Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.cc ('k') | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_chromeos_unittest.cc
diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc
index 77027cbca278c2010b9d55cbb9936401518dad09..08c353e7a70866da612c1c8175a16708ec34c3d1 100644
--- a/device/bluetooth/bluetooth_chromeos_unittest.cc
+++ b/device/bluetooth/bluetooth_chromeos_unittest.cc
@@ -143,6 +143,13 @@ class TestObserver : public BluetoothAdapter::Observer {
scoped_refptr<BluetoothAdapter> adapter_;
};
+// Callback for BluetoothDevice::GetConnectionInfo() that simply saves the
+// connection info to the bound argument.
+void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out,
+ const BluetoothDevice::ConnectionInfo& conn_info) {
+ *out = conn_info;
+};
+
} // namespace
class TestPairingDelegate : public BluetoothDevice::PairingDelegate {
@@ -3272,4 +3279,43 @@ TEST_F(BluetoothChromeOSTest, DeviceId) {
EXPECT_EQ(0, device->GetDeviceID());
}
+TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) {
+ GetAdapter();
+ BluetoothDevice* device =
+ adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress);
+
+ // Calling GetConnectionInfo for an unconnected device should return a result
+ // in which all fields are filled with BluetoothDevice::kUnknownPower.
+ BluetoothDevice::ConnectionInfo conn_info(0, 0, 0);
+ device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
+ int unknown_power = BluetoothDevice::kUnknownPower;
+ EXPECT_NE(0, unknown_power);
+ EXPECT_EQ(unknown_power, conn_info.rssi);
+ EXPECT_EQ(unknown_power, conn_info.transmit_power);
+ EXPECT_EQ(unknown_power, conn_info.max_transmit_power);
+}
+
+TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) {
+ GetAdapter();
+ BluetoothDevice* device =
+ adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress);
+
+ device->Connect(
+ NULL,
+ base::Bind(&BluetoothChromeOSTest::Callback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
+ EXPECT_TRUE(device->IsConnected());
+
+ // Calling GetConnectionInfo for a connected device should return valid
+ // results.
+ fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4);
+ BluetoothDevice::ConnectionInfo conn_info;
+ device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
+ EXPECT_EQ(-10, conn_info.rssi);
+ EXPECT_EQ(3, conn_info.transmit_power);
+ EXPECT_EQ(4, conn_info.max_transmit_power);
+}
+
} // namespace chromeos
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.cc ('k') | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698