| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test/bluetooth_test.h" | 5 #include "device/bluetooth/test/bluetooth_test.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 BluetoothGattService::GattErrorCode error_code) { | 151 BluetoothGattService::GattErrorCode error_code) { |
| 152 ++error_callback_count_; | 152 ++error_callback_count_; |
| 153 last_gatt_error_code_ = error_code; | 153 last_gatt_error_code_ = error_code; |
| 154 | 154 |
| 155 if (expected == Call::EXPECTED) | 155 if (expected == Call::EXPECTED) |
| 156 ++actual_error_callback_calls_; | 156 ++actual_error_callback_calls_; |
| 157 else | 157 else |
| 158 unexpected_error_callback_ = true; | 158 unexpected_error_callback_ = true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void BluetoothTestBase::ReentrantStartNotifySessionErrorCallback( |
| 162 Call expected, |
| 163 BluetoothGattCharacteristic* characteristic, |
| 164 BluetoothGattService::GattErrorCode error_code) { |
| 165 ++error_callback_count_; |
| 166 last_gatt_error_code_ = error_code; |
| 167 |
| 168 if (expected == Call::EXPECTED) |
| 169 ++actual_error_callback_calls_; |
| 170 else |
| 171 unexpected_error_callback_ = true; |
| 172 |
| 173 characteristic->StartNotifySession(GetNotifyCallback(Call::EXPECTED), |
| 174 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 175 } |
| 176 |
| 161 base::Closure BluetoothTestBase::GetCallback(Call expected) { | 177 base::Closure BluetoothTestBase::GetCallback(Call expected) { |
| 162 if (expected == Call::EXPECTED) | 178 if (expected == Call::EXPECTED) |
| 163 ++expected_success_callback_calls_; | 179 ++expected_success_callback_calls_; |
| 164 return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr(), | 180 return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr(), |
| 165 expected); | 181 expected); |
| 166 } | 182 } |
| 167 | 183 |
| 168 BluetoothAdapter::DiscoverySessionCallback | 184 BluetoothAdapter::DiscoverySessionCallback |
| 169 BluetoothTestBase::GetDiscoverySessionCallback(Call expected) { | 185 BluetoothTestBase::GetDiscoverySessionCallback(Call expected) { |
| 170 if (expected == Call::EXPECTED) | 186 if (expected == Call::EXPECTED) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 230 } |
| 215 | 231 |
| 216 base::Callback<void(BluetoothGattService::GattErrorCode)> | 232 base::Callback<void(BluetoothGattService::GattErrorCode)> |
| 217 BluetoothTestBase::GetGattErrorCallback(Call expected) { | 233 BluetoothTestBase::GetGattErrorCallback(Call expected) { |
| 218 if (expected == Call::EXPECTED) | 234 if (expected == Call::EXPECTED) |
| 219 ++expected_error_callback_calls_; | 235 ++expected_error_callback_calls_; |
| 220 return base::Bind(&BluetoothTestBase::GattErrorCallback, | 236 return base::Bind(&BluetoothTestBase::GattErrorCallback, |
| 221 weak_factory_.GetWeakPtr(), expected); | 237 weak_factory_.GetWeakPtr(), expected); |
| 222 } | 238 } |
| 223 | 239 |
| 240 base::Callback<void(BluetoothGattService::GattErrorCode)> |
| 241 BluetoothTestBase::GetReentrantStartNotifySessionErrorCallback( |
| 242 Call expected, |
| 243 BluetoothGattCharacteristic* characteristic) { |
| 244 if (expected == Call::EXPECTED) |
| 245 ++expected_error_callback_calls_; |
| 246 return base::Bind( |
| 247 &BluetoothTestBase::ReentrantStartNotifySessionErrorCallback, |
| 248 weak_factory_.GetWeakPtr(), expected, characteristic); |
| 249 } |
| 250 |
| 224 void BluetoothTestBase::ResetEventCounts() { | 251 void BluetoothTestBase::ResetEventCounts() { |
| 225 last_connect_error_code_ = BluetoothDevice::ERROR_UNKNOWN; | 252 last_connect_error_code_ = BluetoothDevice::ERROR_UNKNOWN; |
| 226 callback_count_ = 0; | 253 callback_count_ = 0; |
| 227 error_callback_count_ = 0; | 254 error_callback_count_ = 0; |
| 228 gatt_connection_attempts_ = 0; | 255 gatt_connection_attempts_ = 0; |
| 229 gatt_disconnection_attempts_ = 0; | 256 gatt_disconnection_attempts_ = 0; |
| 230 gatt_discovery_attempts_ = 0; | 257 gatt_discovery_attempts_ = 0; |
| 231 gatt_notify_characteristic_attempts_ = 0; | 258 gatt_notify_characteristic_attempts_ = 0; |
| 232 gatt_read_characteristic_attempts_ = 0; | 259 gatt_read_characteristic_attempts_ = 0; |
| 233 gatt_write_characteristic_attempts_ = 0; | 260 gatt_write_characteristic_attempts_ = 0; |
| 234 gatt_read_descriptor_attempts_ = 0; | 261 gatt_read_descriptor_attempts_ = 0; |
| 235 gatt_write_descriptor_attempts_ = 0; | 262 gatt_write_descriptor_attempts_ = 0; |
| 236 } | 263 } |
| 237 | 264 |
| 238 } // namespace device | 265 } // namespace device |
| OLD | NEW |