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