OLD | NEW |
---|---|
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 Loading... | |
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 StartLowEnergyDiscoverySession(); | |
795 observer.Reset(); | |
ortuno
2016/06/15 17:20:16
Move this above 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 StartLowEnergyDiscoverySession(); | |
819 BluetoothDevice* device1 = SimulateLowEnergyDevice(1); | |
820 BluetoothDevice* device2 = SimulateLowEnergyDevice(4); | |
821 | |
822 EXPECT_EQ(2u, adapter_->GetDevices().size()); | |
823 | |
824 // Set timestamp of device1 so that it appears as expired. | |
825 device1->last_update_time_ = | |
826 base::Time::NowFromSystemTime() - | |
827 (BluetoothAdapter::timeoutSec + base::TimeDelta::FromSeconds(1)); | |
828 | |
829 // 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.
| |
830 RemoveTimedOutDevices(); | |
831 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
832 EXPECT_EQ(adapter_->GetDevices()[0]->GetAddress(), device2->GetAddress()); | |
833 } | |
834 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | |
835 | |
836 // This test should only be enabled for platforms that uses the | |
837 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated | |
838 // devices. | |
839 #if defined(OS_ANDROID) || defined(OS_MACOSX) | |
840 TEST_F(BluetoothTest, RemoveOutdatedDeviceGattConnect) { | |
841 // Test that a device with GATT connection isn't removed. | |
842 if (!PlatformSupportsLowEnergy()) { | |
843 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
844 return; | |
845 } | |
846 InitWithFakeAdapter(); | |
847 StartLowEnergyDiscoverySession(); | |
848 BluetoothDevice* device = SimulateLowEnergyDevice(1); | |
849 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
850 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
851 SimulateGattConnection(device); | |
852 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.
| |
853 RemoveTimedOutDevices(); | |
854 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
855 } | |
856 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | |
857 | |
858 // This test should only be enabled for platforms that uses the | |
859 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated | |
860 // devices. | |
861 #if defined(OS_ANDROID) || defined(OS_MACOSX) | |
ortuno
2016/06/15 17:20:16
Only OS_MACOSX, since we don't support classic blu
| |
862 TEST_F(BluetoothTest, RemoveOutdatedDevicePaired) { | |
863 // Test that a paired device isn't removed. | |
864 if (!PlatformSupportsLowEnergy()) { | |
865 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
866 return; | |
867 } | |
868 InitWithFakeAdapter(); | |
869 StartLowEnergyDiscoverySession(); | |
870 BluetoothDevice* device = SimulateLowEnergyDevice(1); | |
871 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
872 SetBonded(device); | |
873 EXPECT_TRUE(device->IsPaired()); | |
874 RemoveTimedOutDevices(); | |
875 EXPECT_EQ(1u, adapter_->GetDevices().size()); | |
876 } | |
877 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | |
878 | |
772 } // namespace device | 879 } // namespace device |
OLD | NEW |