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

Side by Side 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: Fixed naming and type so that it follows C++ style guide. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_adapter.h" 5 #include "device/bluetooth/bluetooth_adapter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 GetGattErrorCallback(Call::NOT_EXPECTED)); 762 GetGattErrorCallback(Call::NOT_EXPECTED));
763 service->Register(GetCallback(Call::NOT_EXPECTED), 763 service->Register(GetCallback(Call::NOT_EXPECTED),
764 GetGattErrorCallback(Call::EXPECTED)); 764 GetGattErrorCallback(Call::EXPECTED));
765 service->Unregister(GetCallback(Call::EXPECTED), 765 service->Unregister(GetCallback(Call::EXPECTED),
766 GetGattErrorCallback(Call::NOT_EXPECTED)); 766 GetGattErrorCallback(Call::NOT_EXPECTED));
767 service->Unregister(GetCallback(Call::NOT_EXPECTED), 767 service->Unregister(GetCallback(Call::NOT_EXPECTED),
768 GetGattErrorCallback(Call::EXPECTED)); 768 GetGattErrorCallback(Call::EXPECTED));
769 } 769 }
770 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 770 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
771 771
772 // This test should only be enabled for platforms that uses the
773 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
774 // devices.
775 #if defined(OS_ANDROID) || defined(OS_MACOSX)
776 TEST_F(BluetoothTest, EnsureUpdatedTimestamps) {
777 if (!PlatformSupportsLowEnergy()) {
778 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
779 return;
780 }
781 InitWithFakeAdapter();
782 TestBluetoothAdapterObserver observer(adapter_);
783
784 // Test that the timestamp of a device is updated during multiple
785 // discovery sessions.
786 StartLowEnergyDiscoverySession();
787 BluetoothDevice* device = SimulateLowEnergyDevice(1);
788
789 EXPECT_EQ(1, observer.device_added_count());
790 EXPECT_EQ(1u, adapter_->GetDevices().size());
791 base::Time first_timestamp = device->GetLastUpdateTime();
792
793 // Do a new discovery and check that the timestamp is updated.
794 observer.Reset();
795 StartLowEnergyDiscoverySession();
796 SimulateLowEnergyDevice(1);
797 EXPECT_EQ(0, observer.device_added_count());
798 EXPECT_EQ(1u, adapter_->GetDevices().size());
799 base::Time second_timestamp = device->GetLastUpdateTime();
800 EXPECT_TRUE(second_timestamp > first_timestamp);
801
802 // Check that timestamp doesn't change when there is no discovery.
803 base::Time third_timestamp = device->GetLastUpdateTime();
804 EXPECT_TRUE(second_timestamp == third_timestamp);
805 }
806 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
807
808 // This test should only be enabled for platforms that uses the
809 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
810 // devices.
811 #if defined(OS_ANDROID) || defined(OS_MACOSX)
812 TEST_F(BluetoothTest, RemoveOutdatedDevices) {
813 if (!PlatformSupportsLowEnergy()) {
814 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
815 return;
816 }
817 InitWithFakeAdapter();
818 TestBluetoothAdapterObserver observer(adapter_);
819 StartLowEnergyDiscoverySession();
820 BluetoothDevice* device1 = SimulateLowEnergyDevice(1);
821 BluetoothDevice* device2 = SimulateLowEnergyDevice(4);
822
823 EXPECT_EQ(2u, adapter_->GetDevices().size());
824 device1->SetAsExpiredForTesting();
825
826 // Check that the outdated device is removed.
827 RemoveTimedOutDevices();
828 EXPECT_EQ(1, observer.device_removed_count());
829 EXPECT_EQ(1u, adapter_->GetDevices().size());
830 EXPECT_EQ(adapter_->GetDevices()[0]->GetAddress(), device2->GetAddress());
831 }
832 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
833
834 // This test should only be enabled for platforms that uses the
835 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
836 // devices.
837 #if defined(OS_ANDROID) || defined(OS_MACOSX)
838 TEST_F(BluetoothTest, RemoveOutdatedDeviceGattConnect) {
839 // Test that a device with GATT connection isn't removed.
840 if (!PlatformSupportsLowEnergy()) {
841 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
842 return;
843 }
844 InitWithFakeAdapter();
845 TestBluetoothAdapterObserver observer(adapter_);
846 StartLowEnergyDiscoverySession();
847 BluetoothDevice* device = SimulateLowEnergyDevice(1);
848 device->SetAsExpiredForTesting();
849 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
850 GetConnectErrorCallback(Call::NOT_EXPECTED));
851 SimulateGattConnection(device);
852 EXPECT_EQ(1u, adapter_->GetDevices().size());
853 RemoveTimedOutDevices();
854 EXPECT_EQ(0, observer.device_removed_count());
855 EXPECT_EQ(1u, adapter_->GetDevices().size());
856 }
857 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
858
772 } // namespace device 859 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698