 Chromium Code Reviews
 Chromium Code Reviews Issue 1842223003:
  Remove outdated devices from Android device chooser  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1842223003:
  Remove outdated devices from Android device chooser  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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(); | |
| 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); | |
| 
ortuno
2016/06/14 15:29:33
Please add a test to make sure gatt connected devi
 
perja
2016/06/15 13:03:40
I'm not sure how to test for classic connected dev
 
ortuno
2016/06/15 17:20:16
I would add two new functions to bluetooth_test.h
 
perja
2016/06/17 13:39:26
OK, do you know what class should be used for a fa
 | |
| 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. | |
| 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 | |
| 772 } // namespace device | 836 } // namespace device | 
| OLD | NEW |