Skip to content

Commit

Permalink
chore: parse bluetooth commands (#2764)
Browse files Browse the repository at this point in the history
Will be tested via WPT
  • Loading branch information
sadym-chromium authored Nov 8, 2024
1 parent 3963880 commit 84934d0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/bidiMapper/BidiNoOpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ export class BidiNoOpParser implements BidiCommandParameterParser {
): Bluetooth.HandleRequestDevicePromptParameters {
return params as Bluetooth.HandleRequestDevicePromptParameters;
}
parseSimulateAdapterParameters(
params: unknown,
): Bluetooth.SimulateAdapterParameters {
return params as Bluetooth.SimulateAdapterParameters;
}
parseSimulateAdvertisementParameters(
params: unknown,
): Bluetooth.SimulateAdvertisementParameters {
return params as Bluetooth.SimulateAdvertisementParameters;
}
parseSimulatePreconnectedPeripheralParameters(
params: unknown,
): Bluetooth.SimulatePreconnectedPeripheralParameters {
return params as Bluetooth.SimulatePreconnectedPeripheralParameters;
}
// keep-sorted end

// Browser domain
Expand Down
9 changes: 9 additions & 0 deletions src/bidiMapper/BidiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export interface BidiCommandParameterParser {
parseHandleRequestDevicePromptParams(
params: unknown,
): Bluetooth.HandleRequestDevicePromptParameters;
parseSimulateAdapterParameters(
params: unknown,
): Bluetooth.SimulateAdapterParameters;
parseSimulateAdvertisementParameters(
params: unknown,
): Bluetooth.SimulateAdvertisementParameters;
parseSimulatePreconnectedPeripheralParameters(
params: unknown,
): Bluetooth.SimulatePreconnectedPeripheralParameters;
// keep-sorted end

// Browser domain
Expand Down
10 changes: 7 additions & 3 deletions src/bidiMapper/CommandProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,18 @@ export class CommandProcessor extends EventEmitter<CommandProcessorEventsMap> {
this.#parser.parseHandleRequestDevicePromptParams(command.params),
);
case 'bluetooth.simulateAdapter':
return await this.#bluetoothProcessor.simulateAdapter(command.params);
return await this.#bluetoothProcessor.simulateAdapter(
this.#parser.parseSimulateAdapterParameters(command.params),
);
case 'bluetooth.simulateAdvertisement':
return await this.#bluetoothProcessor.simulateAdvertisement(
command.params,
this.#parser.parseSimulateAdvertisementParameters(command.params),
);
case 'bluetooth.simulatePreconnectedPeripheral':
return await this.#bluetoothProcessor.simulatePreconnectedPeripheral(
command.params,
this.#parser.parseSimulatePreconnectedPeripheralParameters(
command.params,
),
);
// keep-sorted end

Expand Down
15 changes: 15 additions & 0 deletions src/bidiTab/BidiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ export class BidiParser implements BidiCommandParameterParser {
): Bluetooth.HandleRequestDevicePromptParameters {
return Parser.Bluetooth.parseHandleRequestDevicePromptParams(params);
}
parseSimulateAdapterParameters(
params: unknown,
): Bluetooth.SimulateAdapterParameters {
return Parser.Bluetooth.parseSimulateAdapterParams(params);
}
parseSimulateAdvertisementParameters(
params: unknown,
): Bluetooth.SimulateAdvertisementParameters {
return Parser.Bluetooth.parseSimulateAdvertisementParams(params);
}
parseSimulatePreconnectedPeripheralParameters(
params: unknown,
): Bluetooth.SimulatePreconnectedPeripheralParameters {
return Parser.Bluetooth.parseSimulatePreconnectedPeripheralParams(params);
}
// keep-sorted end

// Browser domain
Expand Down
25 changes: 25 additions & 0 deletions src/protocol-parser/protocol-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,29 @@ export namespace Bluetooth {
.HandleRequestDevicePromptParametersSchema,
) as Protocol.Bluetooth.HandleRequestDevicePromptParameters;
}
export function parseSimulateAdapterParams(
params: unknown,
): Protocol.Bluetooth.SimulateAdapterParameters {
return parseObject(
params,
WebDriverBidiBluetooth.Bluetooth.SimulateAdapterParametersSchema,
) as Protocol.Bluetooth.SimulateAdapterParameters;
}
export function parseSimulateAdvertisementParams(
params: unknown,
): Protocol.Bluetooth.SimulateAdvertisementParameters {
return parseObject(
params,
WebDriverBidiBluetooth.Bluetooth.SimulateAdvertisementParametersSchema,
) as Protocol.Bluetooth.SimulateAdvertisementParameters;
}
export function parseSimulatePreconnectedPeripheralParams(
params: unknown,
): Protocol.Bluetooth.SimulatePreconnectedPeripheralParameters {
return parseObject(
params,
WebDriverBidiBluetooth.Bluetooth
.SimulatePreconnectedPeripheralParametersSchema,
) as Protocol.Bluetooth.SimulatePreconnectedPeripheralParameters;
}
}

0 comments on commit 84934d0

Please sign in to comment.