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

Unified Diff: device/bluetooth/bluetooth_gatt_chromeos_unittest.cc

Issue 333983003: device/bluetooth: Implement BluetoothGattConnection on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
Index: device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
diff --git a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
index 235cc72110c39fafdea35f3100f121e2f72ff6f3..0454399e117b96603986f74518d079879c669bf4 100644
--- a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
+++ b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
@@ -17,6 +17,7 @@
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_gatt_characteristic.h"
+#include "device/bluetooth/bluetooth_gatt_connection.h"
#include "device/bluetooth/bluetooth_gatt_descriptor.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
#include "device/bluetooth/bluetooth_uuid.h"
@@ -25,6 +26,7 @@
using device::BluetoothAdapter;
using device::BluetoothDevice;
using device::BluetoothGattCharacteristic;
+using device::BluetoothGattConnection;
using device::BluetoothGattDescriptor;
using device::BluetoothGattService;
using device::BluetoothUUID;
@@ -341,6 +343,7 @@ class BluetoothGattChromeOSTest : public testing::Test {
virtual void TearDown() {
adapter_ = NULL;
+ gatt_conn_.reset();
DBusThreadManager::Shutdown();
}
@@ -366,10 +369,19 @@ class BluetoothGattChromeOSTest : public testing::Test {
last_read_value_ = value;
}
+ void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) {
+ ++success_callback_count_;
+ gatt_conn_ = conn.Pass();
+ }
+
void ErrorCallback() {
++error_callback_count_;
}
+ void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) {
+ ++error_callback_count_;
+ }
+
protected:
base::MessageLoop message_loop_;
@@ -378,6 +390,7 @@ class BluetoothGattChromeOSTest : public testing::Test {
FakeBluetoothGattCharacteristicClient*
fake_bluetooth_gatt_characteristic_client_;
FakeBluetoothGattDescriptorClient* fake_bluetooth_gatt_descriptor_client_;
+ scoped_ptr<device::BluetoothGattConnection> gatt_conn_;
scoped_refptr<BluetoothAdapter> adapter_;
int success_callback_count_;
@@ -385,6 +398,81 @@ class BluetoothGattChromeOSTest : public testing::Test {
std::vector<uint8> last_read_value_;
};
+TEST_F(BluetoothGattChromeOSTest, GattConnection) {
+ fake_bluetooth_device_client_->CreateDevice(
+ dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath));
+ BluetoothDevice* device = adapter_->GetDevice(
+ FakeBluetoothDeviceClient::kLowEnergyAddress);
+ ASSERT_TRUE(device);
+ ASSERT_FALSE(device->IsConnected());
+ ASSERT_FALSE(gatt_conn_.get());
+ ASSERT_EQ(0, success_callback_count_);
+ ASSERT_EQ(0, error_callback_count_);
+
+ device->CreateGattConnection(
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
+
+ EXPECT_EQ(1, success_callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(device->IsConnected());
+ ASSERT_TRUE(gatt_conn_.get());
+ EXPECT_TRUE(gatt_conn_->IsConnected());
+ EXPECT_EQ(FakeBluetoothDeviceClient::kLowEnergyAddress,
+ gatt_conn_->GetDeviceAddress());
+
+ gatt_conn_->Disconnect(
+ base::Bind(&BluetoothGattChromeOSTest::SuccessCallback,
+ base::Unretained(this)));
+ EXPECT_EQ(2, success_callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(device->IsConnected());
+ EXPECT_FALSE(gatt_conn_->IsConnected());
+
+ device->CreateGattConnection(
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
+
+ EXPECT_EQ(3, success_callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(device->IsConnected());
+ ASSERT_TRUE(gatt_conn_.get());
+ EXPECT_TRUE(gatt_conn_->IsConnected());
+
+ device->Disconnect(
+ base::Bind(&BluetoothGattChromeOSTest::SuccessCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
+ base::Unretained(this)));
+
+ EXPECT_EQ(4, success_callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ ASSERT_TRUE(gatt_conn_.get());
+ EXPECT_FALSE(gatt_conn_->IsConnected());
+
+ device->CreateGattConnection(
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
+
+ EXPECT_EQ(5, success_callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(device->IsConnected());
+ EXPECT_TRUE(gatt_conn_->IsConnected());
+
+ fake_bluetooth_device_client_->RemoveDevice(
+ dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath));
+ ASSERT_TRUE(gatt_conn_.get());
+ EXPECT_FALSE(gatt_conn_->IsConnected());
+}
+
TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) {
// Create a fake LE device. We store the device pointer here because this is a
// test. It's unsafe to do this in production as the device might get deleted.
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.cc ('k') | device/bluetooth/bluetooth_gatt_connection_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698