| 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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "device/bluetooth/bluetooth_adapter.h" | 11 #include "device/bluetooth/bluetooth_adapter.h" |
| 12 #include "device/bluetooth/bluetooth_device.h" |
| 11 #include "device/bluetooth/bluetooth_discovery_session.h" | 13 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 14 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 16 |
| 14 namespace device { | 17 namespace device { |
| 15 | 18 |
| 16 class BluetoothAdapter; | 19 class BluetoothAdapter; |
| 17 | 20 |
| 18 // A test fixture for Bluetooth that abstracts platform specifics for creating | 21 // A test fixture for Bluetooth that abstracts platform specifics for creating |
| 19 // and controlling fake low level objects. | 22 // and controlling fake low level objects. |
| 20 // | 23 // |
| 21 // Subclasses on each platform implement this, and are then typedef-ed to | 24 // Subclasses on each platform implement this, and are then typedef-ed to |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess, | 62 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess, |
| 60 // kTestUUIDGenericAttribute and address kTestDeviceAddress1. | 63 // kTestUUIDGenericAttribute and address kTestDeviceAddress1. |
| 61 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert, | 64 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert, |
| 62 // kTestUUIDLinkLoss and address kTestDeviceAddress1. | 65 // kTestUUIDLinkLoss and address kTestDeviceAddress1. |
| 63 // 3: kTestDeviceNameEmpty with no advertised UUIDs and address | 66 // 3: kTestDeviceNameEmpty with no advertised UUIDs and address |
| 64 // kTestDeviceAddress1. | 67 // kTestDeviceAddress1. |
| 65 // 4: kTestDeviceNameEmpty with no advertised UUIDs and address | 68 // 4: kTestDeviceNameEmpty with no advertised UUIDs and address |
| 66 // kTestDeviceAddress2. | 69 // kTestDeviceAddress2. |
| 67 virtual void DiscoverLowEnergyDevice(int device_ordinal){}; | 70 virtual void DiscoverLowEnergyDevice(int device_ordinal){}; |
| 68 | 71 |
| 72 // Simulates success of implementation details of CreateGattConnection. |
| 73 virtual void CompleteGattConnection(BluetoothDevice* device){}; |
| 74 |
| 75 // Simulates failure of CreateGattConnection with the given error code. |
| 76 virtual void FailGattConnection(BluetoothDevice* device, |
| 77 BluetoothDevice::ConnectErrorCode){}; |
| 78 |
| 79 // Simulates GattConnection disconnecting. |
| 80 virtual void CompleteGattDisconnection(BluetoothDevice* device){}; |
| 81 |
| 82 // Remove the device from the adapter and delete it. |
| 83 virtual void DeleteDevice(BluetoothDevice* device); |
| 84 |
| 69 // Callbacks that increment |callback_count_|, |error_callback_count_|: | 85 // Callbacks that increment |callback_count_|, |error_callback_count_|: |
| 70 void Callback(); | 86 void Callback(); |
| 71 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); | 87 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); |
| 88 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection>); |
| 72 void ErrorCallback(); | 89 void ErrorCallback(); |
| 90 void ConnectErrorCallback(enum BluetoothDevice::ConnectErrorCode); |
| 73 | 91 |
| 74 // Accessors to get callbacks bound to this fixture: | 92 // Accessors to get callbacks bound to this fixture: |
| 75 base::Closure GetCallback(); | 93 base::Closure GetCallback(); |
| 76 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); | 94 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); |
| 95 BluetoothDevice::GattConnectionCallback GetGattConnectionCallback(); |
| 77 BluetoothAdapter::ErrorCallback GetErrorCallback(); | 96 BluetoothAdapter::ErrorCallback GetErrorCallback(); |
| 97 BluetoothDevice::ConnectErrorCallback GetConnectErrorCallback(); |
| 78 | 98 |
| 79 // A Message loop is required by some implementations that will PostTasks and | 99 // A Message loop is required by some implementations that will PostTasks and |
| 80 // by base::RunLoop().RunUntilIdle() use in this fixuture. | 100 // by base::RunLoop().RunUntilIdle() use in this fixuture. |
| 81 base::MessageLoop message_loop_; | 101 base::MessageLoop message_loop_; |
| 82 | 102 |
| 83 scoped_refptr<BluetoothAdapter> adapter_; | 103 scoped_refptr<BluetoothAdapter> adapter_; |
| 84 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 104 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
| 105 ScopedVector<BluetoothGattConnection> gatt_connections_; |
| 106 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ = |
| 107 BluetoothDevice::ERROR_UNKNOWN; |
| 85 int callback_count_ = 0; | 108 int callback_count_ = 0; |
| 86 int error_callback_count_ = 0; | 109 int error_callback_count_ = 0; |
| 87 bool run_message_loop_to_wait_for_callbacks_ = true; | 110 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; |
| 88 }; | 111 }; |
| 89 | 112 |
| 90 } // namespace device | 113 } // namespace device |
| 91 | 114 |
| 92 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 115 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
| OLD | NEW |