#include "device/fido/cable/fido_ble_connection.h"
#include <bitset>
#include <cstdint>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "build/build_config.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
#include "device/bluetooth/test/bluetooth_test.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
#include "device/fido/cable/fido_ble_uuids.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_ANDROID)
#include "device/bluetooth/test/bluetooth_test_android.h"
#elif BUILDFLAG(IS_MAC)
#include "device/bluetooth/test/bluetooth_test_mac.h"
#elif BUILDFLAG(IS_WIN)
#include "device/bluetooth/test/bluetooth_test_win.h"
#elif BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
#include "device/bluetooth/test/bluetooth_test_bluez.h"
#elif BUILDFLAG(IS_FUCHSIA)
#include "device/bluetooth/test/bluetooth_test_fuchsia.h"
#endif
namespace device {
_;
ElementsAre;
Invoke;
IsEmpty;
Return;
NiceMockBluetoothAdapter;
NiceMockBluetoothDevice;
NiceMockBluetoothGattService;
NiceMockBluetoothGattCharacteristic;
NiceMockBluetoothGattConnection;
NiceMockBluetoothGattNotifySession;
namespace {
constexpr auto kDefaultServiceRevision = …;
std::vector<uint8_t> ToByteVector(std::string_view str) { … }
BluetoothDevice* GetMockDevice(MockBluetoothAdapter* adapter,
const std::string& address) { … }
class TestReadCallback { … };
TestConnectionFuture;
TestReadControlPointLengthFuture;
TestReadServiceRevisionsFuture;
TestWriteCallback;
}
class FidoBleConnectionTest : public ::testing::Test { … };
TEST_F(FidoBleConnectionTest, Address) { … }
TEST_F(FidoBleConnectionTest, DeviceNotPresent) { … }
TEST_F(FidoBleConnectionTest, PreConnected) { … }
TEST_F(FidoBleConnectionTest, NoConnectionWithoutCompletedGattDiscovery) { … }
TEST_F(FidoBleConnectionTest, GattServicesDiscoveredIgnoredBeforeConnection) { … }
TEST_F(FidoBleConnectionTest, GattServicesDiscoveredAgain) { … }
TEST_F(FidoBleConnectionTest, SimulateGattConnectionError) { … }
TEST_F(FidoBleConnectionTest, SimulateGattNotifySessionStartError) { … }
TEST_F(FidoBleConnectionTest, MultipleServiceRevisions) { … }
TEST_F(FidoBleConnectionTest, UnsupportedServiceRevisions) { … }
TEST_F(FidoBleConnectionTest, ReadServiceRevisionsFails) { … }
TEST_F(FidoBleConnectionTest, WriteServiceRevisionsFails) { … }
TEST_F(FidoBleConnectionTest, ReadStatusNotifications) { … }
TEST_F(FidoBleConnectionTest, ReadControlPointLength) { … }
TEST_F(FidoBleConnectionTest, WriteControlPoint) { … }
TEST_F(FidoBleConnectionTest, ReadsAndWriteFailWhenDisconnected) { … }
TEST_F(FidoBleConnectionTest, ConnectionAddressChangeWhenDeviceAddressChanges) { … }
}