Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: device/bluetooth/test/fake_bluetooth.h

Issue 2722473002: DO NOT SUBMIT. Stub implementation of FakeBluetooth mojo interface (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/public/interfaces/fake_bluetooth.mojom ('k') | device/bluetooth/test/fake_bluetooth.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/test/fake_bluetooth.h
diff --git a/device/bluetooth/test/fake_bluetooth.h b/device/bluetooth/test/fake_bluetooth.h
new file mode 100644
index 0000000000000000000000000000000000000000..94b2a58f20eb071fb6d69d2e7d19c66e131e86b2
--- /dev/null
+++ b/device/bluetooth/test/fake_bluetooth.h
@@ -0,0 +1,317 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_TEST_FAKE_BLUETOOTH_H_
+#define DEVICE_BLUETOOTH_TEST_FAKE_BLUETOOTH_H_
+
+#include <memory>
+#include <string>
+
+#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
+#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
+#include "device/bluetooth/bluetooth_export.h"
+#include "device/bluetooth/bluetooth_uuid.h"
+#include "device/bluetooth/public/interfaces/fake_bluetooth.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace bluetooth {
+
+class DEVICE_BLUETOOTH_EXPORT FakeBluetooth : public mojom::FakeBluetooth {
+ public:
+ FakeBluetooth();
+ ~FakeBluetooth() override;
+
+ static void Create(mojom::FakeBluetoothRequest request);
+
+ void SetLEAvailability(bool available,
+ const SetLEAvailabilityCallback& callback) override;
+ void SimulateLECentralManager(
+ mojom::FakeLECentralManagerOptionsPtr options,
+ const SimulateLECentralManagerCallback& callback) override;
+};
+
+class DEVICE_BLUETOOTH_EXPORT FakeLECentralManager
+ : public mojom::FakeLECentralManager,
+ device::BluetoothAdapter {
+ public:
+ FakeLECentralManager(mojom::FakeLECentralManagerOptionsPtr options,
+ mojom::FakeLECentralManagerRequest request);
+
+ // mojom::FakeLECentralManger overrides
+ void SimulateAdvertisementReceived(
+ mojom::ScanResultPtr result,
+ const SimulateAdvertisementReceivedCallback& callback) override;
+ void AddConnectedLEPeripheral(
+ mojom::FakeLEPeripheralOptionsPtr options,
+ const AddConnectedLEPeripheralCallback& callback) override;
+ void SetState(mojom::FakeLECentralManagerState state,
+ const SetStateCallback& callback) override;
+ void GetStartScanCalls(const GetStartScanCallsCallback& callback) override;
+ void GetStopScanCalls(const GetStopScanCallsCallback& callback) override;
+
+ // device::BluetoothAdapter overrides
+ std::string GetAddress() const override;
+ std::string GetName() const override;
+ void SetName(
+ const std::string& name,
+ const base::Closure& callback,
+ const device::BluetoothAdapter::ErrorCallback& error_callback) override;
+ bool IsInitialized() const override;
+ bool IsPresent() const override;
+ bool IsPowered() const override;
+ void SetPowered(
+ bool powered,
+ const base::Closure& callback,
+ const device::BluetoothAdapter::ErrorCallback& error_callback) override;
+ bool IsDiscoverable() const override;
+ void SetDiscoverable(bool discoverable,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) override;
+ bool IsDiscovering() const override;
+ device::BluetoothAdapter::UUIDList GetUUIDs() const override;
+ void CreateRfcommService(
+ const device::BluetoothUUID& uuid,
+ const device::BluetoothAdapter::ServiceOptions& options,
+ const device::BluetoothAdapter::CreateServiceCallback& callback,
+ const device::BluetoothAdapter::CreateServiceErrorCallback&
+ error_callback) override;
+ void CreateL2capService(
+ const device::BluetoothUUID& uuid,
+ const device::BluetoothAdapter::ServiceOptions& options,
+ const device::BluetoothAdapter::CreateServiceCallback& callback,
+ const device::BluetoothAdapter::CreateServiceErrorCallback&
+ error_callback) override;
+ void SetAdvertisingInterval(
+ const base::TimeDelta& min,
+ const base::TimeDelta& max,
+ const base::Closure& callback,
+ const device::BluetoothAdapter::AdvertisementErrorCallback&
+ error_callback) override;
+ void RegisterAdvertisement(
+ std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
+ const device::BluetoothAdapter::CreateAdvertisementCallback& callback,
+ const device::BluetoothAdapter::AdvertisementErrorCallback& error_callback) override;
+ device::BluetoothLocalGattService* GetGattService(
+ const std::string& identifier) const override;
+ void AddDiscoverySession(
+ device::BluetoothDiscoveryFilter* discovery_filter,
+ const base::Closure& callback,
+ const device::BluetoothAdapter::DiscoverySessionErrorCallback&
+ error_callback) override;
+ void RemoveDiscoverySession(
+ device::BluetoothDiscoveryFilter* discovery_filter,
+ const base::Closure& callback,
+ const device::BluetoothAdapter::DiscoverySessionErrorCallback&
+ error_callback) override;
+ void SetDiscoveryFilter(
+ std::unique_ptr<device::BluetoothDiscoveryFilter>
+ discovery_filter,
+ const base::Closure& callback,
+ const device::BluetoothAdapter::DiscoverySessionErrorCallback&
+ error_callback) override;
+ void RemovePairingDelegateInternal(
+ device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
+
+ private:
+ ~FakeLECentralManager() override;
+
+ mojom::FakeLECentralManagerState state_;
+ mojo::Binding<mojom::FakeLECentralManager> binding_;
+
+ size_t start_scan_calls_;
+ size_t stop_scan_calls_;
+};
+
+class DEVICE_BLUETOOTH_EXPORT FakeLEPeripheral
+ : public mojom::FakeLEPeripheral , device::BluetoothDevice {
+ public:
+ explicit FakeLEPeripheral(const std::string& device_address);
+ ~FakeLEPeripheral() override;
+
+ void SimulateGATTConnection(
+ mojom::GATTConnectionResult result,
+ const SimulateGATTConnectionCallback& callback) override;
+ void SimulateGATTDiscoveryComplete(
+ const SimulateGATTDiscoveryCompleteCallback& callback) override;
+ void SimulateGATTServicesChanged(
+ const SimulateGATTServicesChangedCallback& callback) override;
+ void AddFakeService(mojom::FakeRemoteGATTServiceOptionsPtr options,
+ const AddFakeServiceCallback& callback) override;
+ void GetConnectCalls(const GetConnectCallsCallback& callback) override;
+ void GetDisconnectCalls(const GetDisconnectCallsCallback& callback) override;
+
+ uint32_t GetBluetoothClass() const override;
+#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+ device::BluetoothTransport GetType() const override;
+#endif
+ std::string GetIdentifier() const override;
+ std::string GetAddress() const override;
+ device::BluetoothDevice::VendorIDSource GetVendorIDSource() const override;
+ uint16_t GetVendorID() const override;
+ uint16_t GetProductID() const override;
+ uint16_t GetDeviceID() const override;
+ uint16_t GetAppearance() const override;
+ base::Optional<std::string> GetName() const override;
+ bool IsPaired() const override;
+ bool IsConnected() const override;
+ bool IsGattConnected() const override;
+ bool IsConnectable() const override;
+ bool IsConnecting() const override;
+ bool ExpectingPinCode() const override;
+ bool ExpectingPasskey() const override;
+ bool ExpectingConfirmation() const override;
+ void GetConnectionInfo(const device::BluetoothDevice::ConnectionInfoCallback& callback) override;
+ void Connect(device::BluetoothDevice::PairingDelegate* pairing_delegate,
+ const base::Closure& callback,
+ const device::BluetoothDevice::ConnectErrorCallback& error_callback) override;
+ void SetPinCode(const std::string& pincode) override;
+ void SetPasskey(uint32_t passkey) override;
+ void ConfirmPairing() override;
+ void RejectPairing() override;
+ void CancelPairing() override;
+ void Disconnect(const base::Closure& callback,
+ const device::BluetoothDevice::ErrorCallback& error_callback) override;
+ void Forget(const base::Closure& callback,
+ const device::BluetoothDevice::ErrorCallback& error_callback) override;
+ void ConnectToService(
+ const device::BluetoothUUID& uuid,
+ const device::BluetoothDevice::ConnectToServiceCallback& callback,
+ const device::BluetoothDevice::ConnectToServiceErrorCallback& error_callback) override;
+ void ConnectToServiceInsecurely(
+ const device::BluetoothUUID& uuid,
+ const device::BluetoothDevice::ConnectToServiceCallback& callback,
+ const device::BluetoothDevice::ConnectToServiceErrorCallback& error_callback) override;
+
+ void CreateGattConnectionImpl() override;
+ void DisconnectGatt() override;
+
+ private:
+ std::string address_;
+
+ size_t connect_calls_;
+ size_t disconnect_calls_;
+};
+
+class DEVICE_BLUETOOTH_EXPORT FakeRemoteGATTService
+ : public mojom::FakeRemoteGATTService, device::BluetoothRemoteGattService {
+ public:
+ explicit FakeRemoteGATTService(
+ mojom::FakeRemoteGATTServiceOptionsPtr options);
+
+ void AddFakeCharacteristic(
+ mojom::FakeRemoteGATTCharacteristicOptionsPtr options,
+ const AddFakeCharacteristicCallback& callback) override;
+ void AddFakeIncludedService(
+ mojom::FakeRemoteGATTServiceOptionsPtr options,
+ const AddFakeIncludedServiceCallback& callback) override;
+
+ std::string GetIdentifier() const override;
+ device::BluetoothUUID GetUUID() const override;
+ device::BluetoothDevice* GetDevice() const override;
+ bool IsPrimary() const override;
+ std::vector<device::BluetoothRemoteGattCharacteristic*> GetCharacteristics() const override;
+ std::vector<device::BluetoothRemoteGattService*> GetIncludedServices() const override;
+ device::BluetoothRemoteGattCharacteristic* GetCharacteristic(const std::string& identifier) const override;
+
+private:
+ std::string uuid_;
+};
+
+class DEVICE_BLUETOOTH_EXPORT FakeRemoteGATTCharacteristic
+ : public mojom::FakeRemoteGATTCharacteristic, device::BluetoothRemoteGattCharacteristic {
+ public:
+ explicit FakeRemoteGATTCharacteristic(
+ mojom::FakeRemoteGATTCharacteristicOptionsPtr options);
+ ~FakeRemoteGATTCharacteristic() override;
+
+ void SimulateRead(mojom::GATTOperationResult result,
+ const base::Optional<std::vector<uint8_t>>& value,
+ const SimulateReadCallback& callback) override;
+ void SimulateWrite(mojom::GATTOperationResult result,
+ const SimulateWriteCallback& callback) override;
+ void SimulateNotificationsStarted(
+ mojom::GATTOperationResult result,
+ const SimulateNotificationsStartedCallback& callback) override;
+ void SimulateNotificationsStopped(
+ mojom::GATTOperationResult result,
+ const SimulateNotificationsStoppedCallback& callback) override;
+ void SimulateNotification(
+ mojom::FakeNotificationOptionsPtr options,
+ const SimulateNotificationCallback& callback) override;
+ void AddFakeDescriptor(mojom::FakeRemoteGATTDescriptorOptionsPtr options,
+ const AddFakeDescriptorCallback& callback) override;
+ void GetReadCalls(const GetReadCallsCallback& callback) override;
+ void GetWriteCalls(const GetWriteCallsCallback& callback) override;
+ void GetStartNotificationsCalls(
+ const GetStartNotificationsCallsCallback& callback) override;
+ void GetStopNotificationsCalls(
+ const GetStopNotificationsCallsCallback& callback) override;
+
+ std::string GetIdentifier() const override;
+ device::BluetoothUUID GetUUID() const override;
+ device::BluetoothGattCharacteristic::Properties GetProperties() const override;
+ device::BluetoothRemoteGattCharacteristic::Permissions GetPermissions() const override;
+ const std::vector<uint8_t>& GetValue() const override;
+ device::BluetoothRemoteGattService* GetService() const override;
+ std::vector<device::BluetoothRemoteGattDescriptor*> GetDescriptors() const override;
+ device::BluetoothRemoteGattDescriptor* GetDescriptor(const std::string& identifier) const override;
+ void ReadRemoteCharacteristic(const device::BluetoothRemoteGattCharacteristic::ValueCallback& callback,
+ const device::BluetoothRemoteGattCharacteristic::ErrorCallback& error_callback) override;
+ void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
+ const base::Closure& callback,
+ const device::BluetoothRemoteGattCharacteristic::ErrorCallback& error_callback) override;
+protected:
+ void SubscribeToNotifications(device::BluetoothRemoteGattDescriptor* ccc_descriptor,
+ const base::Closure& callback,
+ const device::BluetoothRemoteGattCharacteristic::ErrorCallback& error_callback) override;
+ void UnsubscribeFromNotifications(
+ device::BluetoothRemoteGattDescriptor* ccc_descriptor,
+ const base::Closure& callback,
+ const device::BluetoothRemoteGattCharacteristic::ErrorCallback& error_callback) override;
+
+ private:
+ std::vector<uint8_t> value_;
+
+ std::string uuid_;
+ int32_t permissions_;
+
+ size_t read_calls_;
+ size_t write_calls_;
+ size_t start_notifications_calls_;
+ size_t stop_notifications_calls_;
+};
+
+class DEVICE_BLUETOOTH_EXPORT FakeRemoteGATTDescriptor
+ : public mojom::FakeRemoteGATTDescriptor, device::BluetoothRemoteGattDescriptor{
+ public:
+ explicit FakeRemoteGATTDescriptor(
+ mojom::FakeRemoteGATTDescriptorOptionsPtr options);
+ ~FakeRemoteGATTDescriptor() override;
+
+ void SimulateRead(mojom::GATTOperationResult result,
+ const base::Optional<std::vector<uint8_t>>& value,
+ const SimulateReadCallback& callback) override;
+ void SimulateWrite(mojom::GATTOperationResult result,
+ const SimulateWriteCallback& callback) override;
+
+ std::string GetIdentifier() const override;
+ device::BluetoothUUID GetUUID() const override;
+ device::BluetoothRemoteGattCharacteristic::Permissions GetPermissions() const override;
+ const std::vector<uint8_t>& GetValue() const override;
+ device::BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
+ void ReadRemoteDescriptor(const device::BluetoothRemoteGattCharacteristic::ValueCallback& callback,
+ const device::BluetoothRemoteGattCharacteristic::ErrorCallback& error_callback) override;
+ void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value,
+ const base::Closure& callback,
+ const device::BluetoothRemoteGattCharacteristic::ErrorCallback& error_callback) override;
+
+private:
+ std::string uuid_;
+
+ std::vector<uint8_t> value_;
+};
+
+} // namespace bluetooth
+#endif
« no previous file with comments | « device/bluetooth/public/interfaces/fake_bluetooth.mojom ('k') | device/bluetooth/test/fake_bluetooth.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698