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

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 1592733002: Clear the BLE services list on disconnect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the bluetooth/getPrimaryService.html timeout issue Created 4 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_device_android.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_unittest.cc
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
index f395764df919cf492ace28bdd388f55d58e51c70..69410b55ad3904c1e6c017ed76c35a3ddec1b7e3 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -395,6 +395,55 @@ TEST_F(BluetoothTest,
#endif // defined(OS_ANDROID)
#if defined(OS_ANDROID)
+// Calls CreateGattConnection & DisconnectGatt, then checks that gatt services
+// have been cleaned up.
+TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) {
+ InitWithFakeAdapter();
+ StartLowEnergyDiscoverySession();
+ BluetoothDevice* device = DiscoverLowEnergyDevice(3);
+ EXPECT_FALSE(device->IsConnected());
+
+ // Connect to the device
+ ResetEventCounts();
+ device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
+ GetConnectErrorCallback(Call::NOT_EXPECTED));
+ TestBluetoothAdapterObserver observer(adapter_);
+ SimulateGattConnection(device);
+ EXPECT_TRUE(device->IsConnected());
+
+ // Discover services
+ std::vector<std::string> services;
+ services.push_back("00000000-0000-1000-8000-00805f9b34fb");
+ services.push_back("00000001-0000-1000-8000-00805f9b34fb");
+ SimulateGattServicesDiscovered(device, services);
+ EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
+ EXPECT_EQ(2u, device->GetGattServices().size());
+ EXPECT_EQ(1, observer.gatt_services_discovered_count());
+
+ // Disconnect from the device
+ device->DisconnectGatt();
+ SimulateGattDisconnection(device);
+ EXPECT_FALSE(device->IsConnected());
+ EXPECT_FALSE(device->IsGattServicesDiscoveryComplete());
+ EXPECT_EQ(0u, device->GetGattServices().size());
+
+ // Verify that the device can be connected to again
+ device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
+ GetConnectErrorCallback(Call::NOT_EXPECTED));
+ SimulateGattConnection(device);
+ EXPECT_TRUE(device->IsConnected());
+
+ // Verify that service discovery can be done again
+ std::vector<std::string> services2;
+ services2.push_back("00000002-0000-1000-8000-00805f9b34fb");
+ SimulateGattServicesDiscovered(device, services2);
+ EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
+ EXPECT_EQ(1u, device->GetGattServices().size());
+ EXPECT_EQ(2, observer.gatt_services_discovered_count());
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
// Calls CreateGattConnection, but simulate errors connecting. Also, verifies
// multiple errors should only invoke callbacks once.
TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) {
« no previous file with comments | « device/bluetooth/bluetooth_device_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698