| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/test/test_simple_task_runner.h" | 6 #include "base/test/test_simple_task_runner.h" |
| 7 #include "device/bluetooth/bluetooth_adapter.h" | 7 #include "device/bluetooth/bluetooth_adapter.h" |
| 8 #include "device/bluetooth/bluetooth_adapter_mac.h" | 8 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 9 #include "device/bluetooth/bluetooth_discovery_session.h" | 9 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 10 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | 10 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 void RemoveTimedOutDevices() { adapter_mac_->RemoveTimedOutDevices(); } | 108 void RemoveTimedOutDevices() { adapter_mac_->RemoveTimedOutDevices(); } |
| 109 | 109 |
| 110 bool SetMockCentralManager() { | 110 bool SetMockCentralManager() { |
| 111 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { | 111 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { |
| 112 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 112 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 113 return false; | 113 return false; |
| 114 } | 114 } |
| 115 mock_central_manager_ = [[MockCentralManager alloc] init]; | 115 mock_central_manager_ = [[MockCentralManager alloc] init]; |
| 116 adapter_mac_->low_energy_discovery_manager_->SetManagerForTesting( | 116 adapter_mac_->SetCentralManagerForTesting(mock_central_manager_); |
| 117 mock_central_manager_); | |
| 118 return true; | 117 return true; |
| 119 } | 118 } |
| 120 | 119 |
| 121 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { | 120 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { |
| 122 adapter_mac_->AddDiscoverySession( | 121 adapter_mac_->AddDiscoverySession( |
| 123 discovery_filter, | 122 discovery_filter, |
| 124 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), | 123 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), |
| 125 base::Bind(&BluetoothAdapterMacTest::ErrorCallback, | 124 base::Bind(&BluetoothAdapterMacTest::ErrorCallback, |
| 126 base::Unretained(this))); | 125 base::Unretained(this))); |
| 127 } | 126 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 | 137 |
| 139 // Generic callbacks. | 138 // Generic callbacks. |
| 140 void Callback() { ++callback_count_; } | 139 void Callback() { ++callback_count_; } |
| 141 void ErrorCallback() { ++error_callback_count_; } | 140 void ErrorCallback() { ++error_callback_count_; } |
| 142 | 141 |
| 143 protected: | 142 protected: |
| 144 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; | 143 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; |
| 145 scoped_refptr<BluetoothAdapter> adapter_; | 144 scoped_refptr<BluetoothAdapter> adapter_; |
| 146 BluetoothAdapterMac* adapter_mac_; | 145 BluetoothAdapterMac* adapter_mac_; |
| 147 | 146 |
| 148 // Owned by |low_energy_discovery_manager_| on |adapter_mac_|. | 147 // Owned by |adapter_mac_|. |
| 149 id mock_central_manager_ = NULL; | 148 id mock_central_manager_ = NULL; |
| 150 | 149 |
| 151 int callback_count_; | 150 int callback_count_; |
| 152 int error_callback_count_; | 151 int error_callback_count_; |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 TEST_F(BluetoothAdapterMacTest, Poll) { | 154 TEST_F(BluetoothAdapterMacTest, Poll) { |
| 156 PollAdapter(); | 155 PollAdapter(); |
| 157 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty()); | 156 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty()); |
| 158 } | 157 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 EXPECT_EQ(1, NumDevices()); | 309 EXPECT_EQ(1, NumDevices()); |
| 311 EXPECT_TRUE(DevicePresent(mock_peripheral)); | 310 EXPECT_TRUE(DevicePresent(mock_peripheral)); |
| 312 | 311 |
| 313 // Check that object pointed to by |device| is deleted by the adapter. | 312 // Check that object pointed to by |device| is deleted by the adapter. |
| 314 RemoveTimedOutDevices(); | 313 RemoveTimedOutDevices(); |
| 315 EXPECT_EQ(0, NumDevices()); | 314 EXPECT_EQ(0, NumDevices()); |
| 316 EXPECT_FALSE(DevicePresent(mock_peripheral)); | 315 EXPECT_FALSE(DevicePresent(mock_peripheral)); |
| 317 } | 316 } |
| 318 | 317 |
| 319 } // namespace device | 318 } // namespace device |
| OLD | NEW |