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

Unified Diff: device/bluetooth/bluetooth_adapter_unittest.cc

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't purge devices continuously. Added more tests. Created 4 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_adapter_unittest.cc
diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc
index 834859c101e2acced911bb14a508fec27da19422..787e9211dc1e50ec16f19fb44c07645f3f5777ec 100644
--- a/device/bluetooth/bluetooth_adapter_unittest.cc
+++ b/device/bluetooth/bluetooth_adapter_unittest.cc
@@ -769,4 +769,111 @@ TEST_F(BluetoothTest, RegisterLocalGattServices) {
}
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
+// This test should only be enabled for platforms that uses the
+// BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
+// devices.
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
+TEST_F(BluetoothTest, EnsureUpdatedTimestamps) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ // Test that the timestamp of a device is updated during multiple
+ // discovery sessions.
+ StartLowEnergyDiscoverySession();
+ BluetoothDevice* device = SimulateLowEnergyDevice(1);
+
+ EXPECT_EQ(1, observer.device_added_count());
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+ base::Time first_timestamp = device->GetLastUpdateTime();
+
+ // Do a new discovery and check that the timestamp is updated.
+ StartLowEnergyDiscoverySession();
+ observer.Reset();
ortuno 2016/06/15 17:20:16 Move this above StartLowEnergyDiscoverySession().
+ SimulateLowEnergyDevice(1);
+ EXPECT_EQ(0, observer.device_added_count());
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+ base::Time second_timestamp = device->GetLastUpdateTime();
+ EXPECT_TRUE(second_timestamp > first_timestamp);
+
+ // Check that timestamp doesn't change when there is no discovery.
+ base::Time third_timestamp = device->GetLastUpdateTime();
+ EXPECT_TRUE(second_timestamp == third_timestamp);
+}
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+
+// This test should only be enabled for platforms that uses the
+// BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
+// devices.
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
+TEST_F(BluetoothTest, RemoveOutdatedDevices) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ StartLowEnergyDiscoverySession();
+ BluetoothDevice* device1 = SimulateLowEnergyDevice(1);
+ BluetoothDevice* device2 = SimulateLowEnergyDevice(4);
+
+ EXPECT_EQ(2u, adapter_->GetDevices().size());
+
+ // Set timestamp of device1 so that it appears as expired.
+ device1->last_update_time_ =
+ base::Time::NowFromSystemTime() -
+ (BluetoothAdapter::timeoutSec + base::TimeDelta::FromSeconds(1));
+
+ // Check that outdated devices are removed.
ortuno 2016/06/15 17:20:16 Also add a check to make sure DeviceRemoved was ca
perja 2016/06/17 13:39:27 Done.
+ RemoveTimedOutDevices();
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+ EXPECT_EQ(adapter_->GetDevices()[0]->GetAddress(), device2->GetAddress());
+}
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+
+// This test should only be enabled for platforms that uses the
+// BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
+// devices.
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
+TEST_F(BluetoothTest, RemoveOutdatedDeviceGattConnect) {
+ // Test that a device with GATT connection isn't removed.
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ StartLowEnergyDiscoverySession();
+ BluetoothDevice* device = SimulateLowEnergyDevice(1);
+ device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
+ GetConnectErrorCallback(Call::NOT_EXPECTED));
+ SimulateGattConnection(device);
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
ortuno 2016/06/15 17:20:16 Set last_update_time_ to be bigger than timeoutSe
perja 2016/06/17 13:39:27 Good catch.
+ RemoveTimedOutDevices();
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+}
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+
+// This test should only be enabled for platforms that uses the
+// BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
+// devices.
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
ortuno 2016/06/15 17:20:16 Only OS_MACOSX, since we don't support classic blu
+TEST_F(BluetoothTest, RemoveOutdatedDevicePaired) {
+ // Test that a paired device isn't removed.
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ StartLowEnergyDiscoverySession();
+ BluetoothDevice* device = SimulateLowEnergyDevice(1);
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+ SetBonded(device);
+ EXPECT_TRUE(device->IsPaired());
+ RemoveTimedOutDevices();
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+}
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698