| 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 "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace device { | 14 namespace device { |
| 15 | 15 |
| 16 class BluetoothAdapter; | 16 class BluetoothAdapter; |
| 17 | 17 |
| 18 // A test fixture for Bluetooth that abstracts platform specifics for creating | 18 // A test fixture for Bluetooth that abstracts platform specifics for creating |
| 19 // and controlling fake low level objects. | 19 // and controlling fake low level objects. |
| 20 // | 20 // |
| 21 // 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 |
| 22 // BluetoothTest. | 22 // BluetoothTest. |
| 23 class BluetoothTestBase : public testing::Test { | 23 class BluetoothTestBase : public testing::Test { |
| 24 public: | 24 public: |
| 25 static const std::string kTestAdapterName; | 25 static const std::string kTestAdapterName; |
| 26 static const std::string kTestAdapterAddress; | 26 static const std::string kTestAdapterAddress; |
| 27 | 27 |
| 28 static const std::string kTestDeviceName; | |
| 29 static const std::string kTestDeviceNameEmpty; | |
| 30 | |
| 31 static const std::string kTestDeviceAddress1; | |
| 32 static const std::string kTestDeviceAddress2; | |
| 33 | |
| 34 static const std::string kTestUUIDGenericAccess; | |
| 35 static const std::string kTestUUIDGenericAttribute; | |
| 36 static const std::string kTestUUIDImmediateAlert; | |
| 37 static const std::string kTestUUIDLinkLoss; | |
| 38 | |
| 39 BluetoothTestBase(); | 28 BluetoothTestBase(); |
| 40 ~BluetoothTestBase() override; | 29 ~BluetoothTestBase() override; |
| 41 | 30 |
| 42 // Check if Low Energy is available. On Mac, we require OS X >= 10.10. | |
| 43 virtual bool PlatformSupportsLowEnergy() = 0; | |
| 44 | |
| 45 // Initializes the BluetoothAdapter |adapter_| with the system adapter. | 31 // Initializes the BluetoothAdapter |adapter_| with the system adapter. |
| 46 virtual void InitWithDefaultAdapter(){}; | 32 virtual void InitWithDefaultAdapter(){}; |
| 47 | 33 |
| 48 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced | 34 // 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 | 35 // to be ignored as if it did not exist. This enables tests for when an |
| 50 // adapter is not present on the system. | 36 // adapter is not present on the system. |
| 51 virtual void InitWithoutDefaultAdapter(){}; | 37 virtual void InitWithoutDefaultAdapter(){}; |
| 52 | 38 |
| 53 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be | 39 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be |
| 54 // controlled by this test fixture. | 40 // controlled by this test fixture. |
| 55 virtual void InitWithFakeAdapter(){}; | 41 virtual void InitWithFakeAdapter(){}; |
| 56 | 42 |
| 57 // Create a fake Low Energy device and discover it. | 43 // Create a fake Low Energy device and discover it. |
| 58 // |device_ordinal| selects between multiple fake device data sets to produce: | 44 // |device_ordinal| selects between multiple fake device data sets to produce. |
| 59 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess, | 45 // 1: AA:00:00:00:00:01 with simple default values. |
| 60 // kTestUUIDGenericAttribute and address kTestDeviceAddress1. | 46 // 2: AA:00:00:00:00:01 with different advertised Service UUIDs vs 1. |
| 61 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert, | 47 // 3: AA:00:00:00:00:01 with empty name, empty UUIDs. |
| 62 // kTestUUIDLinkLoss and address kTestDeviceAddress1. | 48 // 4: BB:00:00:00:00:02 with empty name, empty UUIDs. |
| 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){}; | 49 virtual void DiscoverLowEnergyDevice(int device_ordinal){}; |
| 68 | 50 |
| 69 // Callbacks that increment |callback_count_|, |error_callback_count_|: | 51 // Callbacks that increment |callback_count_|, |error_callback_count_|: |
| 70 void Callback(); | 52 void Callback(); |
| 71 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); | 53 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); |
| 72 void ErrorCallback(); | 54 void ErrorCallback(); |
| 73 | 55 |
| 74 // Accessors to get callbacks bound to this fixture: | 56 // Accessors to get callbacks bound to this fixture: |
| 75 base::Closure GetCallback(); | 57 base::Closure GetCallback(); |
| 76 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); | 58 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); |
| 77 BluetoothAdapter::ErrorCallback GetErrorCallback(); | 59 BluetoothAdapter::ErrorCallback GetErrorCallback(); |
| 78 | 60 |
| 79 // A Message loop is required by some implementations that will PostTasks and | 61 // A Message loop is required by some implementations that will PostTasks and |
| 80 // by base::RunLoop().RunUntilIdle() use in this fixuture. | 62 // by base::RunLoop().RunUntilIdle() use in this fixuture. |
| 81 base::MessageLoop message_loop_; | 63 base::MessageLoop message_loop_; |
| 82 | 64 |
| 83 scoped_refptr<BluetoothAdapter> adapter_; | 65 scoped_refptr<BluetoothAdapter> adapter_; |
| 84 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 66 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
| 85 int callback_count_ = 0; | 67 int callback_count_ = 0; |
| 86 int error_callback_count_ = 0; | 68 int error_callback_count_ = 0; |
| 87 bool run_message_loop_to_wait_for_callbacks_ = true; | 69 bool run_message_loop_to_wait_for_callbacks_ = true; |
| 88 }; | 70 }; |
| 89 | 71 |
| 90 } // namespace device | 72 } // namespace device |
| 91 | 73 |
| 92 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 74 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
| OLD | NEW |