Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /infrastructure/testdriver/bidi/bluetooth/simulate_characteristic_response.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8" />
<meta name="timeout" content="long">
<title>TestDriver bidi.bluetooth.simulate_characteristic_response method</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js?feature=bidi"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/bidi-bluetooth-helper.js"></script>
<script>
promise_setup(async () => {
await test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe();
await test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe();
await test_driver.bidi.bluetooth.characteristic_event_generated.subscribe();
});
bluetooth_test(async (t) => {
const expected_value = [0, 1, 2];
const handle_prompt_promise = selectFirstDeviceOnDevicePromptUpdated();
const [device] = await Promise.all([requestDeviceWithTrustedClick({
acceptAllDevices: true,
optionalServices: [HEART_RATE_SERVICE_UUID]
}), handle_prompt_promise]);
await createGattConnection(device);
await test_driver.bidi.bluetooth.simulate_service({
address: DEVICE_ADDRESS,
uuid: HEART_RATE_SERVICE_UUID,
type: 'add',
});
await test_driver.bidi.bluetooth.simulate_characteristic({
address: DEVICE_ADDRESS,
serviceUuid: HEART_RATE_SERVICE_UUID,
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
characteristicProperties: {
'read': true
},
type: 'add',
});
const simulationProcessedPromise =
test_driver.bidi.bluetooth.characteristic_event_generated.once().then(
(event) => {
return test_driver.bidi.bluetooth.simulate_characteristic_response({
address: event.address,
serviceUuid: event.serviceUuid,
characteristicUuid: event.characteristicUuid,
type: 'read',
code: 0x0,
data: expected_value,
});
});
service = await device.gatt.getPrimaryService(HEART_RATE_SERVICE_UUID);
characteristic = await service.getCharacteristic(DATE_TIME_CHARACTERISTIC_UUID);
[value] = await Promise.all([characteristic.readValue(), simulationProcessedPromise]);
assert_array_equals(new Uint8Array(value.buffer), expected_value)
}, "simulate a GATT characteristic response");
</script>