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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 ResetEventCounts(); | 709 ResetEventCounts(); |
710 StartLowEnergyDiscoverySession(); | 710 StartLowEnergyDiscoverySession(); |
711 EXPECT_EQ(1, callback_count_); | 711 EXPECT_EQ(1, callback_count_); |
712 EXPECT_EQ(0, error_callback_count_); | 712 EXPECT_EQ(0, error_callback_count_); |
713 EXPECT_TRUE(adapter_->IsDiscovering()); | 713 EXPECT_TRUE(adapter_->IsDiscovering()); |
714 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 714 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
715 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 715 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
716 } | 716 } |
717 #endif // defined(OS_ANDROID) | 717 #endif // defined(OS_ANDROID) |
718 | 718 |
| 719 // This test should only be enabled for platforms that uses the |
| 720 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated |
| 721 // devices. |
| 722 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 723 TEST_F(BluetoothTest, EnsureUpdatedTimestamps) { |
| 724 if (!PlatformSupportsLowEnergy()) { |
| 725 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 726 return; |
| 727 } |
| 728 InitWithFakeAdapter(); |
| 729 TestBluetoothAdapterObserver observer(adapter_); |
| 730 |
| 731 // Test that the timestamp of a device is updated during multiple |
| 732 // discovery sessions. |
| 733 StartLowEnergyDiscoverySession(); |
| 734 BluetoothDevice* device = DiscoverLowEnergyDevice(1); |
| 735 EXPECT_EQ(1, observer.device_added_count()); |
| 736 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 737 base::Time first_timestamp = device->GetLastUpdateTime(); |
| 738 |
| 739 // Do a new discovery and check that the timestamp is updated. |
| 740 StartLowEnergyDiscoverySession(); |
| 741 observer.Reset(); |
| 742 DiscoverLowEnergyDevice(1); |
| 743 EXPECT_EQ(0, observer.device_added_count()); |
| 744 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 745 base::Time second_timestamp = device->GetLastUpdateTime(); |
| 746 EXPECT_TRUE(second_timestamp > first_timestamp); |
| 747 |
| 748 // Check that timestamp doesn't change when there is no discovery. |
| 749 base::Time third_timestamp = device->GetLastUpdateTime(); |
| 750 EXPECT_TRUE(second_timestamp == third_timestamp); |
| 751 } |
| 752 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 753 |
| 754 // This test should only be enabled for platforms that uses the |
| 755 // BluetoothAdapter#RemoveOutdatedDevices function to purge outdated |
| 756 // devices. |
| 757 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 758 TEST_F(BluetoothTest, RemoveOutdatedDevices) { |
| 759 if (!PlatformSupportsLowEnergy()) { |
| 760 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 761 return; |
| 762 } |
| 763 InitWithFakeAdapter(); |
| 764 StartLowEnergyDiscoverySession(); |
| 765 BluetoothDevice* device1 = DiscoverLowEnergyDevice(1); |
| 766 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4); |
| 767 EXPECT_EQ(2u, adapter_->GetDevices().size()); |
| 768 |
| 769 // Set timestamp of device1 so that it appears as expired. |
| 770 device1->last_update_time_ = |
| 771 base::Time::NowFromSystemTime() - |
| 772 (BluetoothAdapter::timeoutSec + base::TimeDelta::FromSeconds(1)); |
| 773 |
| 774 // Check that outdated devices are removed. |
| 775 RemoveTimedOutDevices(); |
| 776 EXPECT_EQ(1u, adapter_->GetDevices().size()); |
| 777 EXPECT_EQ(adapter_->GetDevices()[0]->GetAddress(), device2->GetAddress()); |
| 778 } |
| 779 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 780 |
719 } // namespace device | 781 } // namespace device |
OLD | NEW |