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 cc5860dee0c2d138e4fc468d948488a7bb73d9f2..b01ef789819e473b85223b8e059ce01b86bdafdc 100644 |
--- a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc |
+++ b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc |
@@ -113,7 +113,6 @@ class BluetoothGattChromeOSTest : public testing::Test { |
void TearDown() override { |
adapter_ = NULL; |
update_sessions_.clear(); |
- gatt_conn_.reset(); |
bluez::BluezDBusManager::Shutdown(); |
} |
@@ -139,10 +138,7 @@ class BluetoothGattChromeOSTest : public testing::Test { |
last_read_value_ = value; |
} |
- void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) { |
- ++success_callback_count_; |
- gatt_conn_ = conn.Pass(); |
- } |
+ void GattConnectionCallback() { ++success_callback_count_; } |
void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) { |
++success_callback_count_; |
@@ -183,7 +179,6 @@ class BluetoothGattChromeOSTest : public testing::Test { |
fake_bluetooth_gatt_characteristic_client_; |
bluez::FakeBluetoothGattDescriptorClient* |
fake_bluetooth_gatt_descriptor_client_; |
- scoped_ptr<device::BluetoothGattConnection> gatt_conn_; |
ScopedVector<BluetoothGattNotifySession> update_sessions_; |
scoped_refptr<BluetoothAdapter> adapter_; |
@@ -194,6 +189,8 @@ class BluetoothGattChromeOSTest : public testing::Test { |
}; |
TEST_F(BluetoothGattChromeOSTest, GattConnection) { |
+ scoped_ptr<device::BluetoothGattConnection> gatt_conn_; |
+ |
fake_bluetooth_device_client_->CreateDevice( |
dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
@@ -205,7 +202,7 @@ TEST_F(BluetoothGattChromeOSTest, GattConnection) { |
ASSERT_EQ(0, success_callback_count_); |
ASSERT_EQ(0, error_callback_count_); |
- device->CreateGattConnection( |
+ gatt_conn_ = device->CreateGattConnection( |
base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
base::Unretained(this)), |
base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
@@ -216,14 +213,15 @@ TEST_F(BluetoothGattChromeOSTest, GattConnection) { |
EXPECT_TRUE(device->IsConnected()); |
ASSERT_TRUE(gatt_conn_.get()); |
EXPECT_TRUE(gatt_conn_->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_->InProgress()); |
EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
gatt_conn_->GetDeviceAddress()); |
gatt_conn_->Disconnect(); |
- EXPECT_TRUE(device->IsConnected()); |
+ EXPECT_FALSE(device->IsConnected()); |
EXPECT_FALSE(gatt_conn_->IsConnected()); |
- device->CreateGattConnection( |
+ gatt_conn_ = device->CreateGattConnection( |
base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
base::Unretained(this)), |
base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
@@ -243,10 +241,11 @@ TEST_F(BluetoothGattChromeOSTest, GattConnection) { |
EXPECT_EQ(3, success_callback_count_); |
EXPECT_EQ(0, error_callback_count_); |
+ EXPECT_FALSE(device->IsConnected()); |
ASSERT_TRUE(gatt_conn_.get()); |
EXPECT_FALSE(gatt_conn_->IsConnected()); |
- device->CreateGattConnection( |
+ gatt_conn_ = device->CreateGattConnection( |
base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
base::Unretained(this)), |
base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
@@ -264,6 +263,141 @@ TEST_F(BluetoothGattChromeOSTest, GattConnection) { |
EXPECT_FALSE(gatt_conn_->IsConnected()); |
} |
+TEST_F(BluetoothGattChromeOSTest, MultipleGattConnections) { |
+ scoped_ptr<device::BluetoothGattConnection> gatt_conn_1; |
+ scoped_ptr<device::BluetoothGattConnection> gatt_conn_2; |
+ |
+ fake_bluetooth_device_client_->CreateDevice( |
+ dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
+ dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
+ BluetoothDevice* device = |
+ adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
+ ASSERT_TRUE(device); |
+ ASSERT_FALSE(device->IsConnected()); |
+ ASSERT_FALSE(gatt_conn_1.get()); |
+ ASSERT_FALSE(gatt_conn_2.get()); |
+ ASSERT_EQ(0, success_callback_count_); |
+ ASSERT_EQ(0, error_callback_count_); |
+ |
+ // Connect first gatt client |
+ gatt_conn_1 = 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_1.get()); |
+ EXPECT_TRUE(gatt_conn_1->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_1->InProgress()); |
+ EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
+ gatt_conn_1->GetDeviceAddress()); |
+ |
+ // Connect second gatt client |
+ gatt_conn_2 = device->CreateGattConnection( |
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(2, success_callback_count_); |
+ EXPECT_EQ(0, error_callback_count_); |
+ EXPECT_TRUE(device->IsConnected()); |
+ ASSERT_TRUE(gatt_conn_2.get()); |
+ EXPECT_TRUE(gatt_conn_2->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_2->InProgress()); |
+ EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
+ gatt_conn_2->GetDeviceAddress()); |
+ |
+ // Disconnect first client |
+ gatt_conn_1->Disconnect(); |
+ EXPECT_TRUE(device->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_1->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_2->IsConnected()); |
+ |
+ // Connect firt client again |
+ gatt_conn_1 = 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_1.get()); |
+ EXPECT_TRUE(gatt_conn_1->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_2->IsConnected()); |
+ |
+ gatt_conn_1->Disconnect(); |
+ EXPECT_TRUE(device->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_1->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_2->IsConnected()); |
+ |
+ gatt_conn_2->Disconnect(); |
+ EXPECT_FALSE(device->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_1->IsConnected()); |
+ EXPECT_FALSE(gatt_conn_2->IsConnected()); |
+ |
+ // Connect both clients again |
+ gatt_conn_1 = device->CreateGattConnection( |
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
+ base::Unretained(this))); |
+ gatt_conn_2 = device->CreateGattConnection( |
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(5, success_callback_count_); |
+ EXPECT_TRUE(device->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_1->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_2->IsConnected()); |
+ |
+ // Disconnect whole device |
+ device->Disconnect(base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(6, success_callback_count_); |
+ EXPECT_EQ(0, error_callback_count_); |
+ EXPECT_FALSE(device->IsConnected()); |
+ ASSERT_TRUE(gatt_conn_1.get()); |
+ EXPECT_FALSE(gatt_conn_1->IsConnected()); |
+ ASSERT_TRUE(gatt_conn_1.get()); |
+ EXPECT_FALSE(gatt_conn_1->IsConnected()); |
+ |
+ // Connect both clients again |
+ gatt_conn_1 = device->CreateGattConnection( |
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
+ base::Unretained(this))); |
+ gatt_conn_2 = device->CreateGattConnection( |
+ base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
+ base::Unretained(this))); |
+ |
+ EXPECT_EQ(8, success_callback_count_); |
+ EXPECT_TRUE(device->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_1->IsConnected()); |
+ EXPECT_TRUE(gatt_conn_2->IsConnected()); |
+ |
+ fake_bluetooth_device_client_->RemoveDevice( |
+ dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
+ dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
+ ASSERT_TRUE(gatt_conn_1.get()); |
+ EXPECT_FALSE(gatt_conn_1->IsConnected()); |
+ ASSERT_TRUE(gatt_conn_2.get()); |
+ EXPECT_FALSE(gatt_conn_2->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. |