Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / device / bluetooth / test / bluetooth_test.h
blob7a0ed0e29f4d06d278ab356f50088815ea90a80d
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"
14 namespace device {
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
22 // BluetoothTest.
23 class BluetoothTestBase : public testing::Test {
24 public:
25 static const std::string kTestAdapterName;
26 static const std::string kTestAdapterAddress;
28 static const std::string kTestDeviceName;
29 static const std::string kTestDeviceNameEmpty;
31 static const std::string kTestDeviceAddress1;
32 static const std::string kTestDeviceAddress2;
34 static const std::string kTestUUIDGenericAccess;
35 static const std::string kTestUUIDGenericAttribute;
36 static const std::string kTestUUIDImmediateAlert;
37 static const std::string kTestUUIDLinkLoss;
39 BluetoothTestBase();
40 ~BluetoothTestBase() override;
42 // Check if Low Energy is available. On Mac, we require OS X >= 10.10.
43 virtual bool PlatformSupportsLowEnergy() = 0;
45 // Initializes the BluetoothAdapter |adapter_| with the system adapter.
46 virtual void InitWithDefaultAdapter(){};
48 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced
49 // to be ignored as if it did not exist. This enables tests for when an
50 // adapter is not present on the system.
51 virtual void InitWithoutDefaultAdapter(){};
53 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be
54 // controlled by this test fixture.
55 virtual void InitWithFakeAdapter(){};
57 // Create a fake Low Energy device and discover it.
58 // |device_ordinal| selects between multiple fake device data sets to produce:
59 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess,
60 // kTestUUIDGenericAttribute and address kTestDeviceAddress1.
61 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert,
62 // kTestUUIDLinkLoss and address kTestDeviceAddress1.
63 // 3: kTestDeviceNameEmpty with no advertised UUIDs and address
64 // kTestDeviceAddress1.
65 // 4: kTestDeviceNameEmpty with no advertised UUIDs and address
66 // kTestDeviceAddress2.
67 virtual void DiscoverLowEnergyDevice(int device_ordinal){};
69 // Callbacks that increment |callback_count_|, |error_callback_count_|:
70 void Callback();
71 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>);
72 void ErrorCallback();
74 // Accessors to get callbacks bound to this fixture:
75 base::Closure GetCallback();
76 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback();
77 BluetoothAdapter::ErrorCallback GetErrorCallback();
79 // A Message loop is required by some implementations that will PostTasks and
80 // by base::RunLoop().RunUntilIdle() use in this fixuture.
81 base::MessageLoop message_loop_;
83 scoped_refptr<BluetoothAdapter> adapter_;
84 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
85 int callback_count_ = 0;
86 int error_callback_count_ = 0;
87 bool run_message_loop_to_wait_for_callbacks_ = true;
90 } // namespace device
92 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_