#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h"
#include "content/browser/bluetooth/bluetooth_allowed_devices.h"
#include "content/browser/bluetooth/web_bluetooth_pairing_manager.h"
#include "content/public/browser/bluetooth_delegate.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_web_contents_factory.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "device/bluetooth/public/cpp/bluetooth_uuid.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_notify_session.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/test_support/fake_message_dispatch_context.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
namespace content {
namespace {
TestFuture;
WebBluetoothCharacteristicClient;
WebBluetoothGATTQueryQuantity;
WebBluetoothRemoteGATTCharacteristicPtr;
WebBluetoothRemoteGATTServicePtr;
WebBluetoothResult;
BluetoothDevice;
BluetoothGattService;
BluetoothRemoteGattCharacteristic;
BluetoothRemoteGattService;
BluetoothUUID;
MockBluetoothAdapter;
MockBluetoothDevice;
MockBluetoothGattCharacteristic;
MockBluetoothGattNotifySession;
MockBluetoothGattService;
_;
Mock;
NiceMock;
Return;
WithParamInterface;
PromptEventCallback;
WatchAdvertisementsForDeviceCallback;
struct BluetoothDeviceBundleData { … };
constexpr BluetoothRemoteGattCharacteristic::Properties
kTestCharacteristicProperties = …;
const char kBatteryServiceUUIDString[] = …;
constexpr char kBatteryServiceId[] = …;
constexpr char kBatteryLevelCharacteristicId[] = …;
const device::BluetoothUUID kBatteryServiceUUID(kBatteryServiceUUIDString);
const device::BluetoothUUID kBatteryLevelCharacteristicUUID(
"00002a19-0000-1000-8000-00805f9b34fb");
const BluetoothDeviceBundleData battery_device_bundle_data = …;
const char kHeartRateServiceUUIDString[] = …;
constexpr char kHeartRateServiceId[] = …;
constexpr char kHeartRateMeasurementCharacteristicId[] = …;
const device::BluetoothUUID kHeartRateServiceUUID(kHeartRateServiceUUIDString);
const device::BluetoothUUID kHeartRateMeasurementCharacteristicUUID(
"00002a37-0000-1000-8000-00805f9b34fb");
const BluetoothDeviceBundleData heart_rate_device_bundle_data = …;
class MockWebBluetoothPairingManager : public WebBluetoothPairingManager { … };
class FakeBluetoothScanningPrompt : public BluetoothScanningPrompt { … };
class FakeWebBluetoothCharacteristicClient : WebBluetoothCharacteristicClient { … };
class FakeBluetoothAdapter : public device::MockBluetoothAdapter { … };
class FakeBluetoothGattService : public NiceMock<MockBluetoothGattService> { … };
class FakeBluetoothDevice : public NiceMock<MockBluetoothDevice> { … };
class FakeBluetoothCharacteristic
: public NiceMock<MockBluetoothGattCharacteristic> { … };
class TestBluetoothDelegate : public BluetoothDelegate { … };
class TestContentBrowserClient : public ContentBrowserClient { … };
class FakeWebBluetoothAdvertisementClient
: blink::mojom::WebBluetoothAdvertisementClient { … };
class FakeBluetoothDeviceBundle { … };
}
class WebBluetoothServiceImplTest : public RenderViewHostImplTestHarness,
public WithParamInterface<bool> { … };
TEST_F(WebBluetoothServiceImplTest, DestroyedDuringRequestDevice) { … }
TEST_F(WebBluetoothServiceImplTest, PermissionAllowed) { … }
TEST_F(WebBluetoothServiceImplTest, DestroyedDuringRequestScanningStart) { … }
TEST_F(WebBluetoothServiceImplTest, PermissionPromptCanceled) { … }
TEST_F(WebBluetoothServiceImplTest,
BluetoothScanningPermissionRevokedWhenTabHidden) { … }
TEST_F(WebBluetoothServiceImplTest,
BluetoothScanningPermissionRevokedWhenTabOccluded) { … }
TEST_F(WebBluetoothServiceImplTest,
BluetoothScanningPermissionRevokedWhenFocusIsLost) { … }
TEST_F(WebBluetoothServiceImplTest,
BluetoothScanningPermissionRevokedWhenBlocked) { … }
TEST_F(WebBluetoothServiceImplTest,
ReadCharacteristicValueErrorWithValueIgnored) { … }
#if PAIR_BLUETOOTH_ON_DEMAND()
TEST_F(WebBluetoothServiceImplTest, ReadCharacteristicValueNotAuthorized) { … }
TEST_F(WebBluetoothServiceImplTest, IncompletePairingOnShutdown) { … }
#endif
TEST_F(WebBluetoothServiceImplTest, DeferredStartNotifySession) { … }
TEST_F(WebBluetoothServiceImplTest, DeviceGattServicesDiscoveryTimeout) { … }
TEST_F(WebBluetoothServiceImplTest, DeviceDisconnected) { … }
TEST_F(WebBluetoothServiceImplTest, RejectOpaqueOrigin) { … }
TEST_F(WebBluetoothServiceImplTest, TwoWatchAdvertisementsReqSuccess) { … }
TEST_F(WebBluetoothServiceImplTest, TwoWatchAdvertisementsReqFail) { … }
TEST_F(WebBluetoothServiceImplTest,
SecWatchAdvertisementsReqAfterFirstSuccess) { … }
TEST_F(WebBluetoothServiceImplTest, ServiceDestroyedDuringAdapterAcquisition) { … }
class WebBluetoothServiceImplTestWithBaseAdapter
: public RenderViewHostImplTestHarness,
public WithParamInterface<bool> { … };
TEST_F(WebBluetoothServiceImplTestWithBaseAdapter,
EmulatedAdapterRemovalRestoresOriginalAdapter) { … }
}