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

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: Created 6 years, 1 month 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
Index: device/bluetooth/bluetooth_chromeos_unittest.cc
diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc
index 3bb252e09f0647514a2a5eae0b90328670087afd..7bc345344e8d8b278ca057c7113f1a2184ca37e3 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,
+ BluetoothDevice::ConnectionInfo conn_info) {
Ilya Sherman 2014/11/19 22:18:07 nit: Pass by const-reference?
Tim Song 2014/12/06 00:51:37 Done.
+ *out = conn_info;
+};
+
} // namespace
class TestPairingDelegate : public BluetoothDevice::PairingDelegate {
@@ -3182,4 +3189,38 @@ TEST_F(BluetoothChromeOSTest, DeviceId) {
EXPECT_EQ(0, device->GetDeviceID());
}
+TEST_F(BluetoothChromeOSTest, GetConnectionInfo) {
+ 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 unkown_power = BluetoothDevice::kUnknownPower;
Ilya Sherman 2014/11/19 22:18:07 nit: Please add an explicit check that the unknown
Ilya Sherman 2014/11/19 22:18:07 nit: "unkown" -> "unknown"
Tim Song 2014/12/06 00:51:37 Done.
Tim Song 2014/12/06 00:51:37 Done.
+ ASSERT_EQ(unkown_power, conn_info.rssi);
+ ASSERT_EQ(unkown_power, conn_info.transmit_power);
+ ASSERT_EQ(unkown_power, conn_info.max_transmit_power);
Ilya Sherman 2014/11/19 22:18:07 nit: s/ASSERT/EXPECT.
Tim Song 2014/12/06 00:51:37 Done.
+ }
+
+ device->Connect(NULL, base::Bind(&BluetoothChromeOSTest::Callback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
+ ASSERT_TRUE(device->IsConnected());
+
+ // Calling GetConnectionInfo for an unconnected device should return valid
Ilya Sherman 2014/11/19 22:18:07 nit: "an unconnected" -> "a connected"
Tim Song 2014/12/06 00:51:37 Done.
+ // results.
+ {
+ fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4);
+ BluetoothDevice::ConnectionInfo conn_info;
+ device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
+ ASSERT_EQ(-10, conn_info.rssi);
+ ASSERT_EQ(3, conn_info.transmit_power);
+ ASSERT_EQ(4, conn_info.max_transmit_power);
Ilya Sherman 2014/11/19 22:18:07 nit: s/ASSERT/EXPECT.
Tim Song 2014/12/06 00:51:37 Done.
+ }
Ilya Sherman 2014/11/19 22:18:07 Optional nit: I'd write this as two separate tests
Tim Song 2014/12/06 00:51:37 Done.
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698