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

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: Reverted two small unnecessary changes. Created 4 years, 5 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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 GetGattErrorCallback(Call::NOT_EXPECTED)); 756 GetGattErrorCallback(Call::NOT_EXPECTED));
757 service->Register(GetCallback(Call::NOT_EXPECTED), 757 service->Register(GetCallback(Call::NOT_EXPECTED),
758 GetGattErrorCallback(Call::EXPECTED)); 758 GetGattErrorCallback(Call::EXPECTED));
759 service->Unregister(GetCallback(Call::EXPECTED), 759 service->Unregister(GetCallback(Call::EXPECTED),
760 GetGattErrorCallback(Call::NOT_EXPECTED)); 760 GetGattErrorCallback(Call::NOT_EXPECTED));
761 service->Unregister(GetCallback(Call::NOT_EXPECTED), 761 service->Unregister(GetCallback(Call::NOT_EXPECTED),
762 GetGattErrorCallback(Call::EXPECTED)); 762 GetGattErrorCallback(Call::EXPECTED));
763 } 763 }
764 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 764 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
765 765
766 // This test should only be enabled for platforms that uses the
767 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
768 // devices.
769 #if defined(OS_ANDROID) || defined(OS_MACOSX)
770 TEST_F(BluetoothTest, EnsureUpdatedTimestamps) {
771 if (!PlatformSupportsLowEnergy()) {
772 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
773 return;
774 }
775 InitWithFakeAdapter();
776 TestBluetoothAdapterObserver observer(adapter_);
777
778 // Test that the timestamp of a device is updated during multiple
779 // discovery sessions.
780 StartLowEnergyDiscoverySession();
781 BluetoothDevice* device = SimulateLowEnergyDevice(1);
782
783 EXPECT_EQ(1, observer.device_added_count());
784 EXPECT_EQ(1u, adapter_->GetDevices().size());
785 base::Time first_timestamp = device->GetLastUpdateTime();
786
787 // Do a new discovery and check that the timestamp is updated.
788 observer.Reset();
789 StartLowEnergyDiscoverySession();
790 SimulateLowEnergyDevice(1);
791 EXPECT_EQ(0, observer.device_added_count());
792 EXPECT_EQ(1u, adapter_->GetDevices().size());
793 base::Time second_timestamp = device->GetLastUpdateTime();
794 EXPECT_TRUE(second_timestamp > first_timestamp);
795
796 // Check that timestamp doesn't change when there is no discovery.
797 base::Time third_timestamp = device->GetLastUpdateTime();
798 EXPECT_TRUE(second_timestamp == third_timestamp);
799 }
800 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
801
802 // This test should only be enabled for platforms that uses the
803 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
804 // devices.
805 #if defined(OS_ANDROID) || defined(OS_MACOSX)
806 TEST_F(BluetoothTest, RemoveOutdatedDevices) {
807 if (!PlatformSupportsLowEnergy()) {
808 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
809 return;
810 }
811 InitWithFakeAdapter();
812 TestBluetoothAdapterObserver observer(adapter_);
813 StartLowEnergyDiscoverySession();
814 BluetoothDevice* device1 = SimulateLowEnergyDevice(1);
815 BluetoothDevice* device2 = SimulateLowEnergyDevice(4);
816
817 EXPECT_EQ(2u, adapter_->GetDevices().size());
818 device1->SetAsExpiredForTesting();
819
820 // Check that the outdated device is removed.
821 RemoveTimedOutDevices();
822 EXPECT_EQ(1, observer.device_removed_count());
823 EXPECT_EQ(1u, adapter_->GetDevices().size());
824 EXPECT_EQ(adapter_->GetDevices()[0]->GetAddress(), device2->GetAddress());
825 }
826 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
827
828 // This test should only be enabled for platforms that uses the
829 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated
830 // devices.
831 #if defined(OS_ANDROID) || defined(OS_MACOSX)
832 TEST_F(BluetoothTest, RemoveOutdatedDeviceGattConnect) {
833 // Test that a device with GATT connection isn't removed.
834 if (!PlatformSupportsLowEnergy()) {
835 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
836 return;
837 }
838 InitWithFakeAdapter();
839 TestBluetoothAdapterObserver observer(adapter_);
840 StartLowEnergyDiscoverySession();
841 BluetoothDevice* device = SimulateLowEnergyDevice(1);
842 device->SetAsExpiredForTesting();
843 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
844 GetConnectErrorCallback(Call::NOT_EXPECTED));
845 SimulateGattConnection(device);
846 EXPECT_EQ(1u, adapter_->GetDevices().size());
847 RemoveTimedOutDevices();
848 EXPECT_EQ(0, observer.device_removed_count());
849 EXPECT_EQ(1u, adapter_->GetDevices().size());
850 }
851 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
852
766 } // namespace device 853 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac_unittest.mm ('k') | device/bluetooth/bluetooth_classic_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698