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