OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_ |
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_ | 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_ |
7 | 7 |
8 #include "device/bluetooth/test/bluetooth_test.h" | 8 #include "device/bluetooth/test/bluetooth_test.h" |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/test/test_pending_task.h" | 11 #include "base/test/test_pending_task.h" |
12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
13 #include "device/bluetooth/bluetooth_classic_win_fake.h" | 13 #include "device/bluetooth/bluetooth_classic_win_fake.h" |
14 #include "device/bluetooth/bluetooth_low_energy_win_fake.h" | 14 #include "device/bluetooth/bluetooth_low_energy_win_fake.h" |
| 15 #include "device/bluetooth/bluetooth_task_manager_win.h" |
15 | 16 |
16 namespace device { | 17 namespace device { |
17 class BluetoothAdapterWin; | 18 class BluetoothAdapterWin; |
| 19 class BluetoothRemoteGattCharacteristicWin; |
18 | 20 |
19 // Windows implementation of BluetoothTestBase. | 21 // Windows implementation of BluetoothTestBase. |
20 class BluetoothTestWin : public BluetoothTestBase { | 22 class BluetoothTestWin : public BluetoothTestBase, |
| 23 public BluetoothTaskManagerWin::Observer, |
| 24 public win::BluetoothLowEnergyWrapperFake::Observer { |
21 public: | 25 public: |
22 BluetoothTestWin(); | 26 BluetoothTestWin(); |
23 ~BluetoothTestWin() override; | 27 ~BluetoothTestWin() override; |
24 | 28 |
25 // BluetoothTestBase overrides | 29 // BluetoothTestBase overrides |
26 bool PlatformSupportsLowEnergy() override; | 30 bool PlatformSupportsLowEnergy() override; |
27 void InitWithDefaultAdapter() override; | 31 void InitWithDefaultAdapter() override; |
28 void InitWithoutDefaultAdapter() override; | 32 void InitWithoutDefaultAdapter() override; |
29 void InitWithFakeAdapter() override; | 33 void InitWithFakeAdapter() override; |
30 bool DenyPermission() override; | 34 bool DenyPermission() override; |
31 void StartLowEnergyDiscoverySession() override; | 35 void StartLowEnergyDiscoverySession() override; |
32 BluetoothDevice* DiscoverLowEnergyDevice(int device_ordinal) override; | 36 BluetoothDevice* DiscoverLowEnergyDevice(int device_ordinal) override; |
33 void SimulateGattConnection(BluetoothDevice* device) override; | 37 void SimulateGattConnection(BluetoothDevice* device) override; |
34 void SimulateGattServicesDiscovered( | 38 void SimulateGattServicesDiscovered( |
35 BluetoothDevice* device, | 39 BluetoothDevice* device, |
36 const std::vector<std::string>& uuids) override; | 40 const std::vector<std::string>& uuids) override; |
37 void SimulateGattServiceRemoved(BluetoothGattService* service) override; | 41 void SimulateGattServiceRemoved(BluetoothGattService* service) override; |
38 void SimulateGattCharacteristic(BluetoothGattService* service, | 42 void SimulateGattCharacteristic(BluetoothGattService* service, |
39 const std::string& uuid, | 43 const std::string& uuid, |
40 int properties) override; | 44 int properties) override; |
41 void SimulateGattCharacteristicRemoved( | 45 void SimulateGattCharacteristicRemoved( |
42 BluetoothGattService* service, | 46 BluetoothGattService* service, |
43 BluetoothGattCharacteristic* characteristic) override; | 47 BluetoothGattCharacteristic* characteristic) override; |
| 48 void RememberCharacteristicForSubsequentAction( |
| 49 BluetoothGattCharacteristic* characteristic) override; |
| 50 void SimulateGattCharacteristicRead( |
| 51 BluetoothGattCharacteristic* characteristic, |
| 52 const std::vector<uint8_t>& value) override; |
| 53 void SimulateGattCharacteristicReadError( |
| 54 BluetoothGattCharacteristic* characteristic, |
| 55 BluetoothGattService::GattErrorCode error_code) override; |
| 56 void SimulateGattCharacteristicWrite( |
| 57 BluetoothGattCharacteristic* characteristic) override; |
| 58 void SimulateGattCharacteristicWriteError( |
| 59 BluetoothGattCharacteristic* characteristic, |
| 60 BluetoothGattService::GattErrorCode error_code) override; |
| 61 void DeleteDevice(BluetoothDevice* device) override; |
44 void SimulateGattDescriptor(BluetoothGattCharacteristic* characteristic, | 62 void SimulateGattDescriptor(BluetoothGattCharacteristic* characteristic, |
45 const std::string& uuid) override; | 63 const std::string& uuid) override; |
46 | 64 |
| 65 // BluetoothTaskManagerWin::Observer overrides. |
| 66 void OnAttemptReadGattCharacteristic() override; |
| 67 void OnAttemptWriteGattCharacteristic() override; |
| 68 |
| 69 // win::BluetoothLowEnergyWrapperFake::Observer overrides. |
| 70 void onWriteGattCharacteristicValue( |
| 71 const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) override; |
| 72 |
47 private: | 73 private: |
48 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; | 74 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; |
49 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_; | 75 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_; |
50 BluetoothAdapterWin* adapter_win_; | 76 BluetoothAdapterWin* adapter_win_; |
51 | 77 |
52 win::BluetoothClassicWrapperFake* fake_bt_classic_wrapper_; | 78 win::BluetoothClassicWrapperFake* fake_bt_classic_wrapper_; |
53 win::BluetoothLowEnergyWrapperFake* fake_bt_le_wrapper_; | 79 win::BluetoothLowEnergyWrapperFake* fake_bt_le_wrapper_; |
54 | 80 |
| 81 BluetoothRemoteGattCharacteristicWin* remembered_characteristic_; |
| 82 |
55 void AdapterInitCallback(); | 83 void AdapterInitCallback(); |
56 win::GattService* GetSimulatedService(win::BLEDevice* device, | 84 win::GattService* GetSimulatedService(win::BLEDevice* device, |
57 BluetoothGattService* service); | 85 BluetoothGattService* service); |
58 win::GattCharacteristic* GetSimulatedCharacteristic( | 86 win::GattCharacteristic* GetSimulatedCharacteristic( |
59 BluetoothGattCharacteristic* characteristic); | 87 BluetoothGattCharacteristic* characteristic); |
| 88 |
| 89 // Run pending Bluetooth tasks until the first callback that the test fixture |
| 90 // tracks is called. |
| 91 void RunPendingTasksUntilCallback(); |
60 void ForceRefreshDevice(); | 92 void ForceRefreshDevice(); |
61 void FinishPendingTasks(); | 93 void FinishPendingTasks(); |
62 }; | 94 }; |
63 | 95 |
64 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). | 96 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). |
65 typedef BluetoothTestWin BluetoothTest; | 97 typedef BluetoothTestWin BluetoothTest; |
66 | 98 |
67 } // namespace device | 99 } // namespace device |
68 | 100 |
69 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_ | 101 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_ |
OLD | NEW |