From c4132381f035225c2c8560341721b56646eb0cf3 Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Fri, 9 Aug 2024 17:51:35 -0700 Subject: [PATCH 01/29] Initial cut --- index.bs | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/index.bs b/index.bs index b6d16b8..781063d 100644 --- a/index.bs +++ b/index.bs @@ -4938,6 +4938,28 @@ To serialize prompt devices given [=device prompt=] |prompt|: +#### The bluetooth.ScanRecord Type #### {#bluetooth-scanrecord-type} + +
+bluetooth.ScanRecord = {
+  name: text / null,
+  uuids: [] / null,
+  appearance: integer / null,
+  manufacturerData: BluetoothManufacturerDataMap / null,
+}
+
+ +A bluetooth.ScanRecord represents data of the advertisement packet sent by a Bluetooth device. + +
+To serialize a device given a {{BluetoothDevice}} |device|: + +1. Let |name| be |device|.{{BluetoothDevice/name}}. +1. Return a [=map=] matching the bluetooth.RequestDeviceInfo production, `"name"` set to |name|. + +
+ + ### Errors ### {#bidi-errors} This specification extends the set of [=error codes=] from @@ -5013,6 +5035,93 @@ A [=local end=] could dismiss a prompt by sending the following message: +#### The bluetooth.simulateCentral Command #### {#bluetooth-simulatecentral-command} + +
+bluetooth.simulateCentral = (
+   method: "bluetooth.simulateCentral",
+   state: "absent", "powered-off", or "powered-on"
+)
+
+ +
+The [=remote end steps=] with |command parameters| are: + +1. Let |state| be |params|[`"state"`]. +1. Return [=success=] with data `null`. + +
+ +
+A [=local end=] could simulate a central by sending the following message: + +
+{
+  "method": "bluetooth.simulateCentral",
+  "state": "powered-on"
+}
+
+
+ +#### The bluetooth.simulatePreconnectedPeripheral Command #### {#bluetooth-simulateconnectedperipheral-command} + +
+bluetooth.simulatePreconnectedPeripheral = (
+   method: "bluetooth.simulatePreconnectedPeripheral",
+   address: string,
+   name: string,
+   manufacturerData: manufacturerData,
+   knownServiceUuids: string[]
+)
+
+ +
+The [=remote end steps=] with |command parameters| are: + +1. Let |state| be |params|[`"state"`]. +1. Return [=success=] with data `null`. + +
+ +
+A [=local end=] could simulate a central by sending the following message: + +
+{
+  "method": "bluetooth.simulatePreconnectedPeripheral",
+  "state": "powered-on"
+}
+
+
+ +#### The bluetooth.simulateAdvertisement Command #### {#bluetooth-simulateadvertisement-command} + +
+bluetooth.simulateAdvertisement = (
+   method: "bluetooth.simulateAdvertisement",
+   entry: ScanEntry[]
+)
+
+ +
+The [=remote end steps=] with |command parameters| are: + +1. Let |entry| be |params|[`"entry"`]. +1. Return [=success=] with data `null`. + +
+ +
+A [=local end=] could simulate a central by sending the following message: + +
+{
+  "method": "bluetooth.simulateAdvertisement",
+  "entry": {}
+}
+
+
+ ### Events ### {#bidi-events} #### The bluetooth.requestDevicePromptUpdated Event #### {#bluetooth-requestdevicepromptupdated-event} From 35e3421ee00de3d99d4a129001a7b2d566cc9fd7 Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Thu, 15 Aug 2024 21:01:58 -0700 Subject: [PATCH 02/29] Add semantics and examples --- index.bs | 58 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/index.bs b/index.bs index 781063d..e08620d 100644 --- a/index.bs +++ b/index.bs @@ -4951,15 +4951,6 @@ bluetooth.ScanRecord = { A bluetooth.ScanRecord represents data of the advertisement packet sent by a Bluetooth device. -
-To serialize a device given a {{BluetoothDevice}} |device|: - -1. Let |name| be |device|.{{BluetoothDevice/name}}. -1. Return a [=map=] matching the bluetooth.RequestDeviceInfo production, `"name"` set to |name|. - -
- - ### Errors ### {#bidi-errors} This specification extends the set of [=error codes=] from @@ -5040,6 +5031,10 @@ A [=local end=] could dismiss a prompt by sending the following message:
 bluetooth.simulateCentral = (
    method: "bluetooth.simulateCentral",
+   params: bluetooth.SimulateCentralParameters,
+)
+
+bluetooth.SimulateCentralParameters = (
    state: "absent", "powered-off", or "powered-on"
 )
 
@@ -5068,6 +5063,10 @@ A [=local end=] could simulate a central by sending the following message:
 bluetooth.simulatePreconnectedPeripheral = (
    method: "bluetooth.simulatePreconnectedPeripheral",
+   params: bluetooth.SimulatePreconnectedPeripheralParameters,
+)
+
+bluetooth.SimulatePreconnectedPeripheralParameters = (
    address: string,
    name: string,
    manufacturerData: manufacturerData,
@@ -5078,18 +5077,26 @@ bluetooth.simulatePreconnectedPeripheral = (
 
The [=remote end steps=] with |command parameters| are: -1. Let |state| be |params|[`"state"`]. +1. Let |address| be |params|[`"address"`]. +1. Let |name| be |params|[`"name"`]. +1. Let |manufacturerData| be |params|[`"manufacturerData"`]. +1. Let |knownServiceUuids| be |params|[`"knownServiceUuids"`]. 1. Return [=success=] with data `null`.
-A [=local end=] could simulate a central by sending the following message: +A [=local end=] could simulate a preconnected Peripheral by sending the following message:
 {
   "method": "bluetooth.simulatePreconnectedPeripheral",
-  "state": "powered-on"
+  "address": "09:09:09:09:09:09",
+  "name": "Some Device",
+  "manufacturerData": [{ "companyIdentifier": 17 }],
+  "knownServiceUuids": [
+     "12345678-1234-5678-9abc-def123456789",
+  ]
 }
 
@@ -5099,8 +5106,19 @@ A [=local end=] could simulate a central by sending the following message:
 bluetooth.simulateAdvertisement = (
    method: "bluetooth.simulateAdvertisement",
-   entry: ScanEntry[]
+   params: bluetooth.SimulateAdvertisementParameters,
+)
+
+bluetooth.SimulateAdvertisementParameters = (
+   entry: bluetooth.SimulateAdvertisementScanEntryParameters[]
 )
+
+bluetooth.SimulateAdvertisementScanEntryParameters = (
+   deviceAddress: string,
+   rssi: integer,
+   scanRecord: bluetooth.ScanRecord
+)
+
 
@@ -5112,12 +5130,22 @@ The [=remote end steps=] with |command parameters| are:
-A [=local end=] could simulate a central by sending the following message: +A [=local end=] could simulate a device advertisement by sending the following message:
 {
   "method": "bluetooth.simulateAdvertisement",
-  "entry": {}
+  "entry": {
+    "deviceAddress": "08:08:08:08:08:08",
+    "rssi": -10,
+    "scanRecord": {
+      "name": "Heart Rate",
+      "uuids": ["0000180d-0000-1000-8000-00805f9b34fb"],
+      "manufacturerData": [{ "companyIdentifier": 17 }],
+      "appearance": 1,
+      "txPower": 1
+    }
+  }
 }
 
From 9e201a6dbb5c9029b27b34874129191ee838b970 Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Mon, 19 Aug 2024 12:22:54 -0700 Subject: [PATCH 03/29] Review changes. --- index.bs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.bs b/index.bs index e08620d..dd1e183 100644 --- a/index.bs +++ b/index.bs @@ -4942,10 +4942,10 @@ To serialize prompt devices given [=device prompt=] |prompt|:
 bluetooth.ScanRecord = {
-  name: text / null,
-  uuids: [] / null,
-  appearance: integer / null,
-  manufacturerData: BluetoothManufacturerDataMap / null,
+  optional name: text,
+  optional uuids: BluetoothServiceUuid[],
+  optional appearance: integer,
+  optional manufacturerData: BluetoothManufacturerDataMap,
 }
 
@@ -5034,13 +5034,13 @@ bluetooth.simulateCentral = ( params: bluetooth.SimulateCentralParameters, ) -bluetooth.SimulateCentralParameters = ( - state: "absent", "powered-off", or "powered-on" -) +bluetooth.SimulateCentralParameters = { + state: "absent" / "powered-off" / "powered-on" +}
-The [=remote end steps=] with |command parameters| are: +The [=remote end steps=] with command parameters |params| are: 1. Let |state| be |params|[`"state"`]. 1. Return [=success=] with data `null`. @@ -5066,16 +5066,16 @@ bluetooth.simulatePreconnectedPeripheral = ( params: bluetooth.SimulatePreconnectedPeripheralParameters, ) -bluetooth.SimulatePreconnectedPeripheralParameters = ( +bluetooth.SimulatePreconnectedPeripheralParameters = { address: string, name: string, - manufacturerData: manufacturerData, + manufacturerData: BluetoothManufacturerDataMap, knownServiceUuids: string[] -) +}
-The [=remote end steps=] with |command parameters| are: +The [=remote end steps=] with command parameters |params| are: 1. Let |address| be |params|[`"address"`]. 1. Let |name| be |params|[`"name"`]. @@ -5086,14 +5086,14 @@ The [=remote end steps=] with |command parameters| are:
-A [=local end=] could simulate a preconnected Peripheral by sending the following message: +A [=local end=] could simulate a preconnected peripheral by sending the following message:
 {
   "method": "bluetooth.simulatePreconnectedPeripheral",
   "address": "09:09:09:09:09:09",
   "name": "Some Device",
-  "manufacturerData": [{ "companyIdentifier": 17 }],
+  "manufacturerData": { "companyIdentifier": 17 },
   "knownServiceUuids": [
      "12345678-1234-5678-9abc-def123456789",
   ]
@@ -5113,16 +5113,16 @@ bluetooth.SimulateAdvertisementParameters = (
    entry: bluetooth.SimulateAdvertisementScanEntryParameters[]
 )
 
-bluetooth.SimulateAdvertisementScanEntryParameters = (
+bluetooth.SimulateAdvertisementScanEntryParameters = {
    deviceAddress: string,
    rssi: integer,
    scanRecord: bluetooth.ScanRecord
-)
+}
 
 
-The [=remote end steps=] with |command parameters| are: +The [=remote end steps=] with command parameters |params| are: 1. Let |entry| be |params|[`"entry"`]. 1. Return [=success=] with data `null`. @@ -5141,7 +5141,7 @@ A [=local end=] could simulate a device advertisement by sending the following m "scanRecord": { "name": "Heart Rate", "uuids": ["0000180d-0000-1000-8000-00805f9b34fb"], - "manufacturerData": [{ "companyIdentifier": 17 }], + "manufacturerData": { "companyIdentifier": 17 }, "appearance": 1, "txPower": 1 } From 9bd0bf42257cdbe344abbb90eb53b8e660aff90a Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Mon, 19 Aug 2024 12:26:58 -0700 Subject: [PATCH 04/29] Curly brace for SimulateAdvertisementParameters --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index dd1e183..e666353 100644 --- a/index.bs +++ b/index.bs @@ -5109,9 +5109,9 @@ bluetooth.simulateAdvertisement = ( params: bluetooth.SimulateAdvertisementParameters, ) -bluetooth.SimulateAdvertisementParameters = ( +bluetooth.SimulateAdvertisementParameters = { entry: bluetooth.SimulateAdvertisementScanEntryParameters[] -) +} bluetooth.SimulateAdvertisementScanEntryParameters = { deviceAddress: string, From a5217c4c8030fa705462ea1591b6a4129f9aff1f Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Wed, 4 Sep 2024 10:11:42 -0700 Subject: [PATCH 05/29] Add algorithm for adding a virtual peripheral Also remove simluateCentral implementation detail. --- index.bs | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/index.bs b/index.bs index e666353..b283236 100644 --- a/index.bs +++ b/index.bs @@ -4850,6 +4850,8 @@ The default allowlist for this feature is ["self"]. For the purposes of user-agent automation and application testing, this document defines extensions to the [[WebDriver-BiDi]] specification. +The web-bluetooth API and its extension specifications pose a challenge to test authors, as fully exercising those interfaces requires physical hardware devices that respond in predictable ways. To address this challenge this document defines a number of WebDriver-BiDi extension commands that allow defining and controlling virtual peripherals and advertisements that behave like physical device peripherals and their advertisements. These virtual peripherals and advertisements represent devices with particular properties and whose readings can be entirely defined by users. + Issue: CDDL snippetes use the "text" type instead of "browsingContext.BrowsingContext" to allow indepedent programmatic processing of CDDL snippets. Currently, other modules cannot be @@ -5026,38 +5028,6 @@ A [=local end=] could dismiss a prompt by sending the following message:
-#### The bluetooth.simulateCentral Command #### {#bluetooth-simulatecentral-command} - -
-bluetooth.simulateCentral = (
-   method: "bluetooth.simulateCentral",
-   params: bluetooth.SimulateCentralParameters,
-)
-
-bluetooth.SimulateCentralParameters = {
-   state: "absent" / "powered-off" / "powered-on"
-}
-
- -
-The [=remote end steps=] with command parameters |params| are: - -1. Let |state| be |params|[`"state"`]. -1. Return [=success=] with data `null`. - -
- -
-A [=local end=] could simulate a central by sending the following message: - -
-{
-  "method": "bluetooth.simulateCentral",
-  "state": "powered-on"
-}
-
-
- #### The bluetooth.simulatePreconnectedPeripheral Command #### {#bluetooth-simulateconnectedperipheral-command}
@@ -5081,8 +5051,13 @@ The [=remote end steps=] with command parameters |params| are:
 1. Let |name| be |params|[`"name"`].
 1. Let |manufacturerData| be |params|[`"manufacturerData"`].
 1. Let |knownServiceUuids| be |params|[`"knownServiceUuids"`].
+1. Let |virtualBluetoothDevice| be a new software defined {{BluetoothDevice}}.
+1. Set |virtualBluetoothDevice|'s name be |name|.
+1. Set |virtualBluetoothDevice|'s address be |address|.
+1. Set |virtualBluetoothDevice|'s manufacturer data be |manufacturerData|.
+1. Set |virtualBluetoothDevice|'s known service UUIDs be |knownServiceUuids|.
+1. Add |virtualBluetoothDevice| to |storage|.{{BluetoothPermissionStorage/allowedDevices}}.
 1. Return [=success=] with data `null`.
-
 
From b67a242531a7a61e3a88517fa4485b7b309ec48e Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Wed, 4 Sep 2024 10:23:07 -0700 Subject: [PATCH 06/29] Add remote algorithm for simulateAdvertisement --- index.bs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index b283236..08a9661 100644 --- a/index.bs +++ b/index.bs @@ -5099,9 +5099,20 @@ bluetooth.SimulateAdvertisementScanEntryParameters = {
The [=remote end steps=] with command parameters |params| are: -1. Let |entry| be |params|[`"entry"`]. +1. Let |scanEntry| be |params|[`"scanEntry"`]. +1. Let |virtualAdvertisement| be a new software defined advertising event. +1. Let device be the virtual Bluetooth device that sent the + advertising event. +1. For each {{BluetoothDevice}} deviceObj in the UA such that + device is the same device as + deviceObj.{{[[representedDevice]]}}, queue a + task on deviceObj's relevant settings object's + responsible event loop to do the following sub-steps: + 1. If deviceObj.{{watchingAdvertisements}} is + `false`, abort these sub-steps. + 1. Fire an `advertisementreceived` event for the advertising event at + |deviceObj|. 1. Return [=success=] with data `null`. -
From d99c3139890c304f05a08117fc95147e56b344c3 Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Wed, 4 Sep 2024 10:26:16 -0700 Subject: [PATCH 07/29] Review changes --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 08a9661..fa50de2 100644 --- a/index.bs +++ b/index.bs @@ -5031,7 +5031,7 @@ A [=local end=] could dismiss a prompt by sending the following message: #### The bluetooth.simulatePreconnectedPeripheral Command #### {#bluetooth-simulateconnectedperipheral-command}
-bluetooth.simulatePreconnectedPeripheral = (
+bluetooth.SimulatePreconnectedPeripheral = (
    method: "bluetooth.simulatePreconnectedPeripheral",
    params: bluetooth.SimulatePreconnectedPeripheralParameters,
 )
@@ -5079,7 +5079,7 @@ A [=local end=] could simulate a preconnected peripheral by sending the followin
 #### The bluetooth.simulateAdvertisement Command #### {#bluetooth-simulateadvertisement-command}
 
 
-bluetooth.simulateAdvertisement = (
+bluetooth.SimulateAdvertisement = (
    method: "bluetooth.simulateAdvertisement",
    params: bluetooth.SimulateAdvertisementParameters,
 )

From f2a35778ad2087b8ad2f1c435e9931bc8a9864eb Mon Sep 17 00:00:00 2001
From: "Alex N. Jose" 
Date: Thu, 5 Sep 2024 10:46:23 -0700
Subject: [PATCH 08/29] Review updates

---
 index.bs | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/index.bs b/index.bs
index fa50de2..245d7f0 100644
--- a/index.bs
+++ b/index.bs
@@ -1658,6 +1658,8 @@ following steps:
 1. Let nearbyDevices be a set of Bluetooth devices, initially
     equal to the set of devices that are connected (have an ATT Bearer)
     to the UA.
+1. Let virtualDevices be a set of simulated Bluetooth devices,
+    initially empty.
 1. If the UA supports the LE transport, perform the General Discovery
     Procedure, except that the UA may include devices that have no
     Discoverable Mode flag set, and add the discovered Bluetooth
@@ -1677,7 +1679,7 @@ following steps:
     immutable device address.
 1. Let result be a set of Bluetooth devices, initially empty.
 1. For each Bluetooth device device in
-    nearbyDevices, do the following sub-steps:
+    nearbyDevices and virtualDevices, do the following sub-steps:
     1. If device's supported physical transports include LE
         and its Bluetooth Device Name is partial or absent, the UA SHOULD
         perform the Name Discovery Procedure to acquire a complete name.
@@ -4850,7 +4852,7 @@ The default allowlist for this feature is ["self"].
 
 For the purposes of user-agent automation and application testing, this document defines extensions to the [[WebDriver-BiDi]] specification.
 
-The web-bluetooth API and its extension specifications pose a challenge to test authors, as fully exercising those interfaces requires physical hardware devices that respond in predictable ways. To address this challenge this document defines a number of WebDriver-BiDi extension commands that allow defining and controlling virtual peripherals and advertisements that behave like physical device peripherals and their advertisements. These virtual peripherals and advertisements represent devices with particular properties and whose readings can be entirely defined by users.
+The Web Bluetooth API and its extension specifications pose a challenge to test authors, as fully exercising those interfaces requires physical hardware devices that respond in predictable ways. To address this challenge this document defines a number of WebDriver-BiDi extension commands that allow defining and controlling virtual peripherals and advertisements that behave like physical device peripherals and their advertisements. These virtual peripherals and advertisements represent devices with particular properties and whose readings can be entirely defined by users.
 
 Issue: CDDL snippetes use the "text" type instead of
 "browsingContext.BrowsingContext" to allow indepedent programmatic
@@ -4940,7 +4942,7 @@ To serialize prompt devices given [=device prompt=] |prompt|:
 
 
-#### The bluetooth.ScanRecord Type #### {#bluetooth-scanrecord-type} +#### The {{bluetooth.ScanRecord}} Type #### {#bluetooth-scanrecord-type}
 bluetooth.ScanRecord = {
@@ -4951,7 +4953,24 @@ bluetooth.ScanRecord = {
 }
 
-A bluetooth.ScanRecord represents data of the advertisement packet sent by a Bluetooth device. +A {{bluetooth.ScanRecord}} represents data of the advertisement packet sent by a [=Bluetooth device=]. + +
+ +name is {{device}}'s local name, or a prefix of it. + +uuids lists the Service UUIDs that this scan record says +{{device}}'s GATT server supports. + +appearance is an Appearance, one of the values defined by the +{{gap.appearance}} characteristic. + +manufacturerData maps unsigned short Company Identifier +Codes to {{DataView}}s. + +
### Errors ### {#bidi-errors} @@ -5051,13 +5070,14 @@ The [=remote end steps=] with command parameters |params| are: 1. Let |name| be |params|[`"name"`]. 1. Let |manufacturerData| be |params|[`"manufacturerData"`]. 1. Let |knownServiceUuids| be |params|[`"knownServiceUuids"`]. -1. Let |virtualBluetoothDevice| be a new software defined {{BluetoothDevice}}. +1. Let |virtualBluetoothDevice| be a new simulated [=Bluetooth device=]. 1. Set |virtualBluetoothDevice|'s name be |name|. 1. Set |virtualBluetoothDevice|'s address be |address|. 1. Set |virtualBluetoothDevice|'s manufacturer data be |manufacturerData|. 1. Set |virtualBluetoothDevice|'s known service UUIDs be |knownServiceUuids|. -1. Add |virtualBluetoothDevice| to |storage|.{{BluetoothPermissionStorage/allowedDevices}}. +1. Add |virtualBluetoothDevice| to virtualDevices under [=scan for devices=]. 1. Return [=success=] with data `null`. +
@@ -5085,7 +5105,7 @@ bluetooth.SimulateAdvertisement = ( ) bluetooth.SimulateAdvertisementParameters = { - entry: bluetooth.SimulateAdvertisementScanEntryParameters[] + scanEntry: bluetooth.SimulateAdvertisementScanEntryParameters } bluetooth.SimulateAdvertisementScanEntryParameters = { @@ -5112,7 +5132,10 @@ The [=remote end steps=] with command parameters |params| are: `false`, abort these sub-steps. 1. Fire an `advertisementreceived` event for the advertising event at |deviceObj|. + 1. If one or more [=scan for devices=] are in progress, insert + deviceObj into virtualDevices under each. 1. Return [=success=] with data `null`. +
From 3c9eec669b1ccab7f980105194295c5824756459 Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Wed, 11 Sep 2024 12:53:59 -0700 Subject: [PATCH 09/29] Reintroduce simulateCentral + review feedback --- index.bs | 72 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/index.bs b/index.bs index 245d7f0..b55541a 100644 --- a/index.bs +++ b/index.bs @@ -110,6 +110,7 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/ type: dfn text: error; url: dfn-error text: local end; url: dfn-local-ends + text: remote end steps; url: dfn-remote-end-steps
+ +1. If [=this=]'s [=Window/navigable=]'s [=navigable/top-level traversable=] has + a simulated Bluetooth adapter set, queue a + task to resolve |promise| with `true` regardless of the powered + state of the simulated Bluetooth adapter. + 1. If the UA is running on a system that has a Bluetooth radio queue a task to resolve |promise| with `true` regardless of the powered state of the Bluetooth radio. @@ -4942,7 +4953,7 @@ To serialize prompt devices given [=device prompt=] |prompt|:
-#### The {{bluetooth.ScanRecord}} Type #### {#bluetooth-scanrecord-type} +#### The bluetooth.ScanRecord Type #### {#bluetooth-scanrecord-type}
 bluetooth.ScanRecord = {
@@ -4953,16 +4964,16 @@ bluetooth.ScanRecord = {
 }
 
-A {{bluetooth.ScanRecord}} represents data of the advertisement packet sent by a [=Bluetooth device=]. +A `bluetooth.ScanRecord` represents data of the advertisement packet sent by a [=Bluetooth device=]. -
-name is {{device}}'s local name, or a prefix of it. +name is {{BluetoothDevice}}'s local name, or a prefix of it. uuids lists the Service UUIDs that this scan record says -{{device}}'s GATT server supports. +{{BluetoothDevice}}'s GATT server supports. appearance is an Appearance, one of the values defined by the {{gap.appearance}} characteristic. @@ -5047,6 +5058,44 @@ A [=local end=] could dismiss a prompt by sending the following message:
+#### The bluetooth.simulateCentral Command #### {#bluetooth-simulatecentral-command} + +
+bluetooth.simulateCentral = (
+   method: "bluetooth.simulateCentral",
+   params: bluetooth.SimulateCentralParameters,
+)
+
+bluetooth.SimulateCentralParameters = {
+   state: "absent" / "powered-off" / "powered-on"
+}
+
+ +
+The [=remote end steps=] with command parameters |params| are: + +1. Let |state| be |params|[`"state"`]. +1. Let |virtualBluetoothAdapter| be a new [=simulated Bluetooth adapter=]. +1. Set |virtualBluetoothAdapter|'s state be |state|. +1. Let |topLevelTraversable| be window's [=Window/navigable=]'s + [=navigable/top-level traversable=]. +1. Set |virtualBluetoothAdapter| be |topLevelTraversable|'s + simulated Bluetooth adapter. +1. Return [=success=] with data `null`. + +
+ +
+A [=local end=] could simulate a central by sending the following message: + +
+{
+  "method": "bluetooth.simulateCentral",
+  "state": "powered-on"
+}
+
+
+ #### The bluetooth.simulatePreconnectedPeripheral Command #### {#bluetooth-simulateconnectedperipheral-command}
@@ -5070,7 +5119,7 @@ The [=remote end steps=] with command parameters |params| are:
 1. Let |name| be |params|[`"name"`].
 1. Let |manufacturerData| be |params|[`"manufacturerData"`].
 1. Let |knownServiceUuids| be |params|[`"knownServiceUuids"`].
-1. Let |virtualBluetoothDevice| be a new simulated [=Bluetooth device=].
+1. Let |virtualBluetoothDevice| be a new [=simulated Bluetooth device=].
 1. Set |virtualBluetoothDevice|'s name be |name|.
 1. Set |virtualBluetoothDevice|'s address be |address|.
 1. Set |virtualBluetoothDevice|'s manufacturer data be |manufacturerData|.
@@ -5120,7 +5169,6 @@ bluetooth.SimulateAdvertisementScanEntryParameters = {
 The [=remote end steps=] with command parameters |params| are:
 
 1. Let |scanEntry| be |params|[`"scanEntry"`].
-1. Let |virtualAdvertisement| be a new software defined advertising event.
 1. Let device be the virtual Bluetooth device that sent the
     advertising event.
 1. For each {{BluetoothDevice}} deviceObj in the UA such that
@@ -5128,12 +5176,12 @@ The [=remote end steps=] with command parameters |params| are:
     deviceObj.{{[[representedDevice]]}}, queue a
     task on deviceObj's relevant settings object's
     responsible event loop to do the following sub-steps:
-    1. If deviceObj.{{watchingAdvertisements}} is
+    1. If deviceObj.{{watchingAdvertisements}} is
         `false`, abort these sub-steps.
     1. Fire an `advertisementreceived` event for the advertising event at
-        |deviceObj|.
+        |deviceObj|, initialized with |scanEntry|[`"scanRecord"`].
     1. If one or more [=scan for devices=] are in progress, insert
-       deviceObj into virtualDevices under each.
+        deviceObj into [=simulated Bluetooth device=]s under each.
 1. Return [=success=] with data `null`.
 
 

From f8f6dc4580745d2d291a86915d7659c0addf93bb Mon Sep 17 00:00:00 2001
From: "Alex N. Jose" 
Date: Wed, 11 Sep 2024 13:32:43 -0700
Subject: [PATCH 10/29] Rename simulateCentral to simulateAdapter

---
 index.bs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/index.bs b/index.bs
index b55541a..c4fa1a7 100644
--- a/index.bs
+++ b/index.bs
@@ -5058,20 +5058,20 @@ A [=local end=] could dismiss a prompt by sending the following message:
 
-#### The bluetooth.simulateCentral Command #### {#bluetooth-simulatecentral-command} +#### The bluetooth.simulateAdapter Command #### {#bluetooth-simulateAdapter-command}
-bluetooth.simulateCentral = (
-   method: "bluetooth.simulateCentral",
-   params: bluetooth.SimulateCentralParameters,
+bluetooth.simulateAdapter = (
+   method: "bluetooth.simulateAdapter",
+   params: bluetooth.SimulateAdapterParameters,
 )
 
-bluetooth.SimulateCentralParameters = {
+bluetooth.SimulateAdapterParameters = {
    state: "absent" / "powered-off" / "powered-on"
 }
 
-
+
The [=remote end steps=] with command parameters |params| are: 1. Let |state| be |params|[`"state"`]. From ee735fd14d3c9a8cff7a0c04c0d730166206da8f Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Thu, 12 Sep 2024 09:46:30 -0700 Subject: [PATCH 11/29] Rename virtual prefix to simulated + review changes --- index.bs | 97 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/index.bs b/index.bs index c4fa1a7..31aca0b 100644 --- a/index.bs +++ b/index.bs @@ -1661,10 +1661,10 @@ following steps: to the UA. 1. Let |topLevelTraversable| be window's [=Window/navigable=]'s [=navigable/top-level traversable=]. -1. Let |virtualAdapter| be |topLevelTraversable|'s - simulated Bluetooth adapter, initially empty. -1. Let |virtualDevices| be a list of simulated Bluetooth devices - attached to |virtualAdapter|. +1. Let |simulatedBluetoothAdapter| be |topLevelTraversable|'s + simulated Bluetooth adapter, initially empty. +1. Let |simulatedBluetoothDevices| be a list of simulated Bluetooth devices + attached to |simulatedBluetoothAdapter|. 1. If the UA supports the LE transport, perform the General Discovery Procedure, except that the UA may include devices that have no Discoverable Mode flag set, and add the discovered Bluetooth @@ -1684,7 +1684,7 @@ following steps: immutable device address. 1. Let result be a set of Bluetooth devices, initially empty. 1. For each Bluetooth device device in - nearbyDevices and virtualDevices, do the following sub-steps: + nearbyDevices and simulatedBluetoothDevices, do the following sub-steps: 1. If device's supported physical transports include LE and its Bluetooth Device Name is partial or absent, the UA SHOULD perform the Name Discovery Procedure to acquire a complete name. @@ -1996,10 +1996,14 @@ steps in parallel: may resolve |promise| with `false`.
-1. If [=this=]'s [=Window/navigable=]'s [=navigable/top-level traversable=] has - a simulated Bluetooth adapter set, queue a - task to resolve |promise| with `true` regardless of the powered - state of the simulated Bluetooth adapter. +1. Let |simulatedBluetoothAdapter| be [=this=]'s [=Window/navigable=]'s + [=navigable/top-level traversable=] simulated Bluetooth adapter. +1. If |simulatedBluetoothAdapter| is not empty, and + |simulatedBluetoothAdapter|["state"] is equal to "absent", queue a + task to resolve |promise| with `false`. +1. If |simulatedBluetoothAdapter| is not empty, regardless of the powered + state of the simulated Bluetooth adapter, queue a + task to resolve |promise| with `true`. 1. If the UA is running on a system that has a Bluetooth radio queue a task to resolve |promise| with `true` regardless of the powered @@ -4863,7 +4867,11 @@ The default allowlist for this feature is ["self"]. For the purposes of user-agent automation and application testing, this document defines extensions to the [[WebDriver-BiDi]] specification. -The Web Bluetooth API and its extension specifications pose a challenge to test authors, as fully exercising those interfaces requires physical hardware devices that respond in predictable ways. To address this challenge this document defines a number of WebDriver-BiDi extension commands that allow defining and controlling virtual peripherals and advertisements that behave like physical device peripherals and their advertisements. These virtual peripherals and advertisements represent devices with particular properties and whose readings can be entirely defined by users. +The Web Bluetooth API and its extension specifications pose a challenge to test authors, as fully exercising those interfaces requires physical hardware devices that respond in predictable ways. To address this challenge this document defines a number of WebDriver-BiDi extension commands that allow defining and controlling simulated peripherals and advertisements that behave like physical device peripherals and their advertisements. These simulated peripherals and advertisements represent devices with particular properties and whose readings can be entirely defined by users. + + * A simulated Bluetooth adapter is a software defined Bluetooth adapter that can host a number of simulated Bluetooth devices and can assume roles like Central. + + * A simulated Bluetooth device is a software defined Bluetooth device that behaves like a physical device, and may be attached to a simulated Bluetooth adapter. Issue: CDDL snippetes use the "text" type instead of "browsingContext.BrowsingContext" to allow indepedent programmatic @@ -4964,24 +4972,20 @@ bluetooth.ScanRecord = { } -A `bluetooth.ScanRecord` represents data of the advertisement packet sent by a [=Bluetooth device=]. +A bluetooth.ScanRecord represents data of the advertisement packet sent by a [=Bluetooth device=]. -
+
+ : name + :: Local name of a [=Bluetooth device=], or a prefix of it. -name is {{BluetoothDevice}}'s local name, or a prefix of it. + : uuids + :: Lists the Service UUIDs that this scan record says [=Bluetooth device=]'s GATT server supports. + : appearance + :: Value of Appearance, one of the values defined by the {{gap.appearance}} characteristic. -uuids lists the Service UUIDs that this scan record says -{{BluetoothDevice}}'s GATT server supports. - -appearance is an Appearance, one of the values defined by the -{{gap.appearance}} characteristic. - -manufacturerData maps unsigned short Company Identifier -Codes to {{DataView}}s. - -
+ : manufacturerData + :: maps unsigned short Company Identifier Codes to {{DataView}}s. + ### Errors ### {#bidi-errors} @@ -5075,22 +5079,22 @@ bluetooth.SimulateAdapterParameters = { The [=remote end steps=] with command parameters |params| are: 1. Let |state| be |params|[`"state"`]. -1. Let |virtualBluetoothAdapter| be a new [=simulated Bluetooth adapter=]. -1. Set |virtualBluetoothAdapter|'s state be |state|. +1. Let |simulatedBluetoothAdapter| be a new [=simulated Bluetooth adapter=]. +1. Set |simulatedBluetoothAdapter|'s state be |state|. 1. Let |topLevelTraversable| be window's [=Window/navigable=]'s [=navigable/top-level traversable=]. -1. Set |virtualBluetoothAdapter| be |topLevelTraversable|'s +1. Set |simulatedBluetoothAdapter| be |topLevelTraversable|'s simulated Bluetooth adapter. 1. Return [=success=] with data `null`.
-A [=local end=] could simulate a central by sending the following message: +A [=local end=] could simulate an adapter by sending the following message:
 {
-  "method": "bluetooth.simulateCentral",
+  "method": "bluetooth.simulateAdapter",
   "state": "powered-on"
 }
 
@@ -5119,12 +5123,12 @@ The [=remote end steps=] with command parameters |params| are: 1. Let |name| be |params|[`"name"`]. 1. Let |manufacturerData| be |params|[`"manufacturerData"`]. 1. Let |knownServiceUuids| be |params|[`"knownServiceUuids"`]. -1. Let |virtualBluetoothDevice| be a new [=simulated Bluetooth device=]. -1. Set |virtualBluetoothDevice|'s name be |name|. -1. Set |virtualBluetoothDevice|'s address be |address|. -1. Set |virtualBluetoothDevice|'s manufacturer data be |manufacturerData|. -1. Set |virtualBluetoothDevice|'s known service UUIDs be |knownServiceUuids|. -1. Add |virtualBluetoothDevice| to virtualDevices under [=scan for devices=]. +1. Let |simulatedBluetoothDevice| be a new [=simulated Bluetooth device=]. +1. Set |simulatedBluetoothDevice|'s name be |name|. +1. Set |simulatedBluetoothDevice|'s address be |address|. +1. Set |simulatedBluetoothDevice|'s manufacturer data be |manufacturerData|. +1. Set |simulatedBluetoothDevice|'s known service UUIDs be |knownServiceUuids|. +1. Add |simulatedBluetoothDevice| to simulatedBluetoothDevices under [=scan for devices=]. 1. Return [=success=] with data `null`.
@@ -5166,22 +5170,27 @@ bluetooth.SimulateAdvertisementScanEntryParameters = {
-The [=remote end steps=] with command parameters |params| are: +The [=remote end steps=] with |session| and command parameters |params| are: 1. Let |scanEntry| be |params|[`"scanEntry"`]. -1. Let device be the virtual Bluetooth device that sent the +1. Let device be the simulated Bluetooth device that sent the advertising event. -1. For each {{BluetoothDevice}} deviceObj in the UA such that + +1. Let |global| be |session|'s [=current browsing context=]'s [=browsing context/active document=]'s [=relevant global object=]. +1. If |global| is not a {{Window}}, abort these steps. +1. Let |navigator| be |global|'s associated {{Navigator}}. +1. Let |deviceObjects| be the result of [=map/get the values=] for |navigator|.{{Navigator/bluetooth}}.{{Bluetooth/[[deviceInstanceMap]]}}. +1. [=list/For each=] |deviceObject| of |deviceObjects| such that device is the same device as - deviceObj.{{[[representedDevice]]}}, queue a - task on deviceObj's relevant settings object's + deviceObject.{{[[representedDevice]]}}, queue a + task on deviceObject's relevant settings object's responsible event loop to do the following sub-steps: - 1. If deviceObj.{{watchingAdvertisements}} is + 1. If deviceObject.{{watchingAdvertisements}} is `false`, abort these sub-steps. 1. Fire an `advertisementreceived` event for the advertising event at - |deviceObj|, initialized with |scanEntry|[`"scanRecord"`]. + |deviceObject|, initialized with |scanEntry|[`"scanRecord"`]. 1. If one or more [=scan for devices=] are in progress, insert - deviceObj into [=simulated Bluetooth device=]s under each. + deviceObject into [=simulated Bluetooth device=]s under each. 1. Return [=success=] with data `null`.
From 83d6e02d083b2bfd9b457a27b1ed67f9c9fa75e0 Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Thu, 12 Sep 2024 13:09:41 -0700 Subject: [PATCH 12/29] Review changes --- index.bs | 69 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/index.bs b/index.bs index 31aca0b..001538b 100644 --- a/index.bs +++ b/index.bs @@ -110,7 +110,6 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/ type: dfn text: error; url: dfn-error text: local end; url: dfn-local-ends - text: remote end steps; url: dfn-remote-end-steps