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 "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" |
| 11 #include "device/bluetooth/bluetooth_discovery_session.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace device { | 14 namespace device { |
13 | 15 |
14 class BluetoothAdapter; | 16 class BluetoothAdapter; |
15 | 17 |
16 // A test fixture for Bluetooth that abstracts platform specifics for creating | 18 // A test fixture for Bluetooth that abstracts platform specifics for creating |
17 // and controlling fake low level objects. | 19 // and controlling fake low level objects. |
18 // | 20 // |
19 // Subclasses on each platform implement this, and are then typedef-ed to | 21 // Subclasses on each platform implement this, and are then typedef-ed to |
20 // BluetoothTest. | 22 // BluetoothTest. |
21 class BluetoothTestBase : public testing::Test { | 23 class BluetoothTestBase : public testing::Test { |
22 public: | 24 public: |
23 BluetoothTestBase(); | 25 BluetoothTestBase(); |
24 ~BluetoothTestBase() override; | 26 ~BluetoothTestBase() override; |
25 | 27 |
26 // Initializes the BluetoothAdapter |adapter_| with the system adapter. | 28 // Initializes the BluetoothAdapter |adapter_| with the system adapter. |
27 virtual void InitWithDefaultAdapter(){}; | 29 virtual void InitWithDefaultAdapter(){}; |
28 | 30 |
29 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced | 31 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced |
30 // to be ignored as if it did not exist. This enables tests for when an | 32 // to be ignored as if it did not exist. This enables tests for when an |
31 // adapter is not present on the system. | 33 // adapter is not present on the system. |
32 virtual void InitWithoutDefaultAdapter(){}; | 34 virtual void InitWithoutDefaultAdapter(){}; |
33 | 35 |
34 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be | 36 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be |
35 // controlled by this test fixture. | 37 // controlled by this test fixture. |
36 virtual void InitWithFakeAdapter(){}; | 38 virtual void InitWithFakeAdapter(){}; |
37 | 39 |
| 40 // Callbacks that increment |callback_count_|, |error_callback_count_|: |
| 41 void Callback(); |
| 42 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); |
| 43 void ErrorCallback(); |
| 44 |
| 45 // Accessors to get callbacks bound to this fixture: |
| 46 base::Closure GetCallback(); |
| 47 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); |
| 48 BluetoothAdapter::ErrorCallback GetErrorCallback(); |
| 49 |
| 50 // A Message loop is required by some implementations that will PostTasks and |
| 51 // by base::RunLoop().RunUntilIdle() use in this fixuture. |
| 52 base::MessageLoop message_loop_; |
| 53 |
38 scoped_refptr<BluetoothAdapter> adapter_; | 54 scoped_refptr<BluetoothAdapter> adapter_; |
| 55 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
| 56 int callback_count_ = 0; |
| 57 int error_callback_count_ = 0; |
| 58 bool run_message_loop_to_wait_for_callbacks_ = true; |
39 }; | 59 }; |
40 | 60 |
41 } // namespace device | 61 } // namespace device |
42 | 62 |
43 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 63 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
OLD | NEW |