Chromium Code Reviews| 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 kTestUUID1; | |
| 32 static const std::string kTestUUID2; | |
| 33 static const std::string kTestUUID3; | |
| 34 static const std::string kTestUUID4; | |
| 35 | |
| 28 BluetoothTestBase(); | 36 BluetoothTestBase(); |
| 29 ~BluetoothTestBase() override; | 37 ~BluetoothTestBase() override; |
| 30 | 38 |
| 31 // Initializes the BluetoothAdapter |adapter_| with the system adapter. | 39 // Initializes the BluetoothAdapter |adapter_| with the system adapter. |
| 32 virtual void InitWithDefaultAdapter(){}; | 40 virtual void InitWithDefaultAdapter(){}; |
| 33 | 41 |
| 34 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced | 42 // 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 | 43 // to be ignored as if it did not exist. This enables tests for when an |
| 36 // adapter is not present on the system. | 44 // adapter is not present on the system. |
| 37 virtual void InitWithoutDefaultAdapter(){}; | 45 virtual void InitWithoutDefaultAdapter(){}; |
| 38 | 46 |
| 39 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be | 47 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be |
| 40 // controlled by this test fixture. | 48 // controlled by this test fixture. |
| 41 virtual void InitWithFakeAdapter(){}; | 49 virtual void InitWithFakeAdapter(){}; |
| 42 | 50 |
| 43 // Create a fake Low Energy device and discover it. | 51 // Create a fake Low Energy device and discover it. |
| 44 // |device_ordinal| selects between multiple fake device data sets to produce. | 52 // |device_ordinal| selects between multiple fake device data sets to produce: |
| 45 // 1: AA:00:00:00:00:01 with simple default values. | 53 // 1: kTestDeviceName with advertised UUIDs kTestUUID1, kTestUUID2 |
| 46 // 2: AA:00:00:00:00:01 with different advertised Service UUIDs vs 1. | 54 // Address AA:00:00:00:00:01 on Android. 01:00:00:90:1E:BE on Mac. |
|
scheib
2015/07/23 18:15:25
Please change the address on Android as well so th
krstnmnlsn
2015/07/23 22:03:29
Done.
| |
| 47 // 3: AA:00:00:00:00:01 with empty name, empty UUIDs. | 55 // 2: kTestDeviceName with advertised UUIDs kTestUUID3, kTestUUID4 |
| 48 // 4: BB:00:00:00:00:02 with empty name, empty UUIDs. | 56 // Address AA:00:00:00:00:01 on Android. 01:00:00:90:1E:BE on Mac. |
| 57 // 3: kTestDeviceNameEmpty with no advertised UUIDs. | |
| 58 // Address AA:00:00:00:00:01 on Android. 01:00:00:90:1E:BE on Mac. | |
| 59 // 4: kTestDeviceNameEmpty with no advertised UUIDs. | |
| 60 // Address BB:00:00:00:00:02 on Android. 02:00:00:8B:74:63 on Mac. | |
| 49 virtual void DiscoverLowEnergyDevice(int device_ordinal){}; | 61 virtual void DiscoverLowEnergyDevice(int device_ordinal){}; |
| 50 | 62 |
| 63 // Check if Low Energy is available. On Mac, we require OS X >= 10.10. | |
|
scheib
2015/07/23 18:15:25
Logically this is used very early, so it fits bett
krstnmnlsn
2015/07/23 22:03:29
Done.
| |
| 64 virtual bool PlatformSupportsLowEnergy() = 0; | |
| 65 | |
| 51 // Callbacks that increment |callback_count_|, |error_callback_count_|: | 66 // Callbacks that increment |callback_count_|, |error_callback_count_|: |
| 52 void Callback(); | 67 void Callback(); |
| 53 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); | 68 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); |
| 54 void ErrorCallback(); | 69 void ErrorCallback(); |
| 55 | 70 |
| 56 // Accessors to get callbacks bound to this fixture: | 71 // Accessors to get callbacks bound to this fixture: |
| 57 base::Closure GetCallback(); | 72 base::Closure GetCallback(); |
| 58 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); | 73 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); |
| 59 BluetoothAdapter::ErrorCallback GetErrorCallback(); | 74 BluetoothAdapter::ErrorCallback GetErrorCallback(); |
| 60 | 75 |
| 61 // A Message loop is required by some implementations that will PostTasks and | 76 // A Message loop is required by some implementations that will PostTasks and |
| 62 // by base::RunLoop().RunUntilIdle() use in this fixuture. | 77 // by base::RunLoop().RunUntilIdle() use in this fixuture. |
| 63 base::MessageLoop message_loop_; | 78 base::MessageLoop message_loop_; |
| 64 | 79 |
| 65 scoped_refptr<BluetoothAdapter> adapter_; | 80 scoped_refptr<BluetoothAdapter> adapter_; |
| 66 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 81 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
| 67 int callback_count_ = 0; | 82 int callback_count_ = 0; |
| 68 int error_callback_count_ = 0; | 83 int error_callback_count_ = 0; |
| 69 bool run_message_loop_to_wait_for_callbacks_ = true; | 84 bool run_message_loop_to_wait_for_callbacks_ = true; |
| 70 }; | 85 }; |
| 71 | 86 |
| 72 } // namespace device | 87 } // namespace device |
| 73 | 88 |
| 74 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 89 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
| OLD | NEW |