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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h"
10 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_discovery_session.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 class BluetoothAdapter
;
18 // A test fixture for Bluetooth that abstracts platform specifics for creating
19 // and controlling fake low level objects.
21 // Subclasses on each platform implement this, and are then typedef-ed to
23 class BluetoothTestBase
: public testing::Test
{
25 static const std::string kTestAdapterName
;
26 static const std::string kTestAdapterAddress
;
29 ~BluetoothTestBase() override
;
31 // Initializes the BluetoothAdapter |adapter_| with the system adapter.
32 virtual void InitWithDefaultAdapter(){};
34 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced
35 // to be ignored as if it did not exist. This enables tests for when an
36 // adapter is not present on the system.
37 virtual void InitWithoutDefaultAdapter(){};
39 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be
40 // controlled by this test fixture.
41 virtual void InitWithFakeAdapter(){};
43 // Create a fake Low Energy device and discover it.
44 // |device_ordinal| selects between multiple fake device data sets to produce.
45 // 1: AA:00:00:00:00:01 with simple default values.
46 // 2: AA:00:00:00:00:01 with different advertised Service UUIDs vs 1.
47 // 3: AA:00:00:00:00:01 with empty name, empty UUIDs.
48 // 4: BB:00:00:00:00:02 with empty name, empty UUIDs.
49 virtual void DiscoverLowEnergyDevice(int device_ordinal
){};
51 // Callbacks that increment |callback_count_|, |error_callback_count_|:
53 void DiscoverySessionCallback(scoped_ptr
<BluetoothDiscoverySession
>);
56 // Accessors to get callbacks bound to this fixture:
57 base::Closure
GetCallback();
58 BluetoothAdapter::DiscoverySessionCallback
GetDiscoverySessionCallback();
59 BluetoothAdapter::ErrorCallback
GetErrorCallback();
61 // A Message loop is required by some implementations that will PostTasks and
62 // by base::RunLoop().RunUntilIdle() use in this fixuture.
63 base::MessageLoop message_loop_
;
65 scoped_refptr
<BluetoothAdapter
> adapter_
;
66 ScopedVector
<BluetoothDiscoverySession
> discovery_sessions_
;
67 int callback_count_
= 0;
68 int error_callback_count_
= 0;
69 bool run_message_loop_to_wait_for_callbacks_
= true;
74 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_