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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // - Services: [ kTestUUIDGenericAccess ] | 49 // - Services: [ kTestUUIDGenericAccess ] |
50 // HEART_RATE_DEVICE: | 50 // HEART_RATE_DEVICE: |
51 // - Name: kTestDeviceName | 51 // - Name: kTestDeviceName |
52 // - Address: kTestPeripheralUUID2 | 52 // - Address: kTestPeripheralUUID2 |
53 // - Services: [ kTestUUIDGenericAccess, kTestUUIDHeartRate] | 53 // - Services: [ kTestUUIDGenericAccess, kTestUUIDHeartRate] |
54 enum class ConnectedDeviceType { | 54 enum class ConnectedDeviceType { |
55 GENERIC_DEVICE, | 55 GENERIC_DEVICE, |
56 HEART_RATE_DEVICE, | 56 HEART_RATE_DEVICE, |
57 }; | 57 }; |
58 | 58 |
| 59 enum class NotifyValueState { |
| 60 NONE, |
| 61 NOTIFY, |
| 62 INDICATE, |
| 63 }; |
| 64 |
59 static const std::string kTestAdapterName; | 65 static const std::string kTestAdapterName; |
60 static const std::string kTestAdapterAddress; | 66 static const std::string kTestAdapterAddress; |
61 | 67 |
62 static const std::string kTestDeviceName; | 68 static const std::string kTestDeviceName; |
63 static const std::string kTestDeviceNameEmpty; | 69 static const std::string kTestDeviceNameEmpty; |
64 | 70 |
65 static const std::string kTestDeviceAddress1; | 71 static const std::string kTestDeviceAddress1; |
66 static const std::string kTestDeviceAddress2; | 72 static const std::string kTestDeviceAddress2; |
67 static const std::string kTestDeviceAddress3; | 73 static const std::string kTestDeviceAddress3; |
68 | 74 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // Simulates a Descriptor Write operation failing with a GattErrorCode. | 400 // Simulates a Descriptor Write operation failing with a GattErrorCode. |
395 virtual void SimulateGattDescriptorWriteError( | 401 virtual void SimulateGattDescriptorWriteError( |
396 BluetoothRemoteGattDescriptor* descriptor, | 402 BluetoothRemoteGattDescriptor* descriptor, |
397 BluetoothRemoteGattService::GattErrorCode) {} | 403 BluetoothRemoteGattService::GattErrorCode) {} |
398 | 404 |
399 // Simulates a Descriptor Write operation failing synchronously once for | 405 // Simulates a Descriptor Write operation failing synchronously once for |
400 // an unknown reason. | 406 // an unknown reason. |
401 virtual void SimulateGattDescriptorWriteWillFailSynchronouslyOnce( | 407 virtual void SimulateGattDescriptorWriteWillFailSynchronouslyOnce( |
402 BluetoothRemoteGattDescriptor* descriptor) {} | 408 BluetoothRemoteGattDescriptor* descriptor) {} |
403 | 409 |
| 410 // Tests if the notify value attemps. |
| 411 virtual void ExpectedChangeNotifyValueAttempts(int attempts); |
| 412 |
| 413 // Tests if the notify session has been changed. The default implementation |
| 414 // uses descriptors. |
| 415 virtual void ExpectedNotifyValue(NotifyValueState expected_value_state); |
| 416 |
404 // Returns a list of local GATT services registered with the adapter. | 417 // Returns a list of local GATT services registered with the adapter. |
405 virtual std::vector<BluetoothLocalGattService*> RegisteredGattServices(); | 418 virtual std::vector<BluetoothLocalGattService*> RegisteredGattServices(); |
406 | 419 |
407 // Removes the device from the adapter and deletes it. | 420 // Removes the device from the adapter and deletes it. |
408 virtual void DeleteDevice(BluetoothDevice* device); | 421 virtual void DeleteDevice(BluetoothDevice* device); |
409 | 422 |
410 // Callbacks that increment |callback_count_|, |error_callback_count_|: | 423 // Callbacks that increment |callback_count_|, |error_callback_count_|: |
411 void Callback(Call expected); | 424 void Callback(Call expected); |
412 void DiscoverySessionCallback(Call expected, | 425 void DiscoverySessionCallback(Call expected, |
413 std::unique_ptr<BluetoothDiscoverySession>); | 426 std::unique_ptr<BluetoothDiscoverySession>); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 GetReentrantStartNotifySessionSuccessCallback( | 471 GetReentrantStartNotifySessionSuccessCallback( |
459 Call expected, | 472 Call expected, |
460 BluetoothRemoteGattCharacteristic* characteristic); | 473 BluetoothRemoteGattCharacteristic* characteristic); |
461 base::Callback<void(BluetoothGattService::GattErrorCode)> | 474 base::Callback<void(BluetoothGattService::GattErrorCode)> |
462 GetReentrantStartNotifySessionErrorCallback( | 475 GetReentrantStartNotifySessionErrorCallback( |
463 Call expected, | 476 Call expected, |
464 BluetoothRemoteGattCharacteristic* characteristic, | 477 BluetoothRemoteGattCharacteristic* characteristic, |
465 bool error_in_reentrant); | 478 bool error_in_reentrant); |
466 | 479 |
467 // Reset all event count members to 0. | 480 // Reset all event count members to 0. |
468 void ResetEventCounts(); | 481 virtual void ResetEventCounts(); |
469 | 482 |
470 void RemoveTimedOutDevices(); | 483 void RemoveTimedOutDevices(); |
471 | 484 |
472 // A Message loop is required by some implementations that will PostTasks and | 485 // A Message loop is required by some implementations that will PostTasks and |
473 // by base::RunLoop().RunUntilIdle() use in this fixture. | 486 // by base::RunLoop().RunUntilIdle() use in this fixture. |
474 base::MessageLoop message_loop_; | 487 base::MessageLoop message_loop_; |
475 | 488 |
476 scoped_refptr<BluetoothAdapter> adapter_; | 489 scoped_refptr<BluetoothAdapter> adapter_; |
477 std::vector<std::unique_ptr<BluetoothDiscoverySession>> discovery_sessions_; | 490 std::vector<std::unique_ptr<BluetoothDiscoverySession>> discovery_sessions_; |
478 std::vector<std::unique_ptr<BluetoothGattConnection>> gatt_connections_; | 491 std::vector<std::unique_ptr<BluetoothGattConnection>> gatt_connections_; |
479 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ = | 492 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ = |
480 BluetoothDevice::ERROR_UNKNOWN; | 493 BluetoothDevice::ERROR_UNKNOWN; |
481 std::vector<std::unique_ptr<BluetoothGattNotifySession>> notify_sessions_; | 494 std::vector<std::unique_ptr<BluetoothGattNotifySession>> notify_sessions_; |
482 std::vector<uint8_t> last_read_value_; | 495 std::vector<uint8_t> last_read_value_; |
483 std::vector<uint8_t> last_write_value_; | 496 std::vector<uint8_t> last_write_value_; |
484 BluetoothRemoteGattService::GattErrorCode last_gatt_error_code_; | 497 BluetoothRemoteGattService::GattErrorCode last_gatt_error_code_; |
485 | 498 |
486 int callback_count_ = 0; | 499 int callback_count_ = 0; |
487 int error_callback_count_ = 0; | 500 int error_callback_count_ = 0; |
488 int gatt_connection_attempts_ = 0; | 501 int gatt_connection_attempts_ = 0; |
489 int gatt_disconnection_attempts_ = 0; | 502 int gatt_disconnection_attempts_ = 0; |
490 int gatt_discovery_attempts_ = 0; | 503 int gatt_discovery_attempts_ = 0; |
491 int gatt_notify_characteristic_attempts_ = 0; | |
492 int gatt_read_characteristic_attempts_ = 0; | 504 int gatt_read_characteristic_attempts_ = 0; |
493 int gatt_write_characteristic_attempts_ = 0; | 505 int gatt_write_characteristic_attempts_ = 0; |
494 int gatt_read_descriptor_attempts_ = 0; | 506 int gatt_read_descriptor_attempts_ = 0; |
495 int gatt_write_descriptor_attempts_ = 0; | 507 int gatt_write_descriptor_attempts_ = 0; |
496 | 508 |
497 // The following values are used to make sure the correct callbacks | 509 // The following values are used to make sure the correct callbacks |
498 // have been called. They are not reset when calling ResetEventCounts(). | 510 // have been called. They are not reset when calling ResetEventCounts(). |
499 int expected_success_callback_calls_ = 0; | 511 int expected_success_callback_calls_ = 0; |
500 int expected_error_callback_calls_ = 0; | 512 int expected_error_callback_calls_ = 0; |
501 int actual_success_callback_calls_ = 0; | 513 int actual_success_callback_calls_ = 0; |
502 int actual_error_callback_calls_ = 0; | 514 int actual_error_callback_calls_ = 0; |
503 bool unexpected_success_callback_ = false; | 515 bool unexpected_success_callback_ = false; |
504 bool unexpected_error_callback_ = false; | 516 bool unexpected_error_callback_ = false; |
505 | 517 |
506 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; | 518 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; |
507 }; | 519 }; |
508 | 520 |
509 } // namespace device | 521 } // namespace device |
510 | 522 |
511 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 523 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
OLD | NEW |