Skip to content

Commit c59f319

Browse files
authored
Add test_driver.bidi.bluetooth commands and event (#53204)
* More test_driver.bidi.bluetooth commands and event * Fix lint error * Fix bluetooth.py new line error * Add long timeout for simulate_characteristic_response.https.html * Address comments * add long timeout * add long timeout * Add long timeout * Add long timeout
1 parent e8f6c8d commit c59f319

36 files changed

+2639
-14
lines changed

docs/writing-tests/testdriver.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,23 @@ The module provides access to [Web Bluetooth](https://webbluetoothcg.github.io/w
314314
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_preconnected_peripheral
315315
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_gatt_connection_response
316316
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_gatt_disconnection
317+
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_service
318+
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_characteristic
319+
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_characteristic_response
320+
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_descriptor
321+
.. js:autofunction:: test_driver.bidi.bluetooth.simulate_descriptor_response
317322
.. js:autofunction:: test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe
318323
.. js:autofunction:: test_driver.bidi.bluetooth.request_device_prompt_updated.on
319324
.. js:autofunction:: test_driver.bidi.bluetooth.request_device_prompt_updated.once
320325
.. js:autofunction:: test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe
321326
.. js:autofunction:: test_driver.bidi.bluetooth.gatt_connection_attempted.on
322327
.. js:autofunction:: test_driver.bidi.bluetooth.gatt_connection_attempted.once
328+
.. js:autofunction:: test_driver.bidi.bluetooth.characteristic_event_generated.subscribe
329+
.. js:autofunction:: test_driver.bidi.bluetooth.characteristic_event_generated.on
330+
.. js:autofunction:: test_driver.bidi.bluetooth.characteristic_event_generated.once
331+
.. js:autofunction:: test_driver.bidi.bluetooth.descriptor_event_generated.subscribe
332+
.. js:autofunction:: test_driver.bidi.bluetooth.descriptor_event_generated.on
333+
.. js:autofunction:: test_driver.bidi.bluetooth.descriptor_event_generated.once
323334
```
324335

325336
### Emulation ###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[simulate_characteristic.https.html]
2+
expected:
3+
if product != "chrome": ERROR
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[simulate_characteristic_response.https.html]
2+
expected:
3+
if product != "chrome": ERROR
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[simulate_descriptor.https.html]
2+
expected:
3+
if product != "chrome": ERROR
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[simulate_descriptor_response.https.html]
2+
expected:
3+
if product != "chrome": ERROR
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[simulate_service.https.html]
2+
expected:
3+
if product != "chrome": ERROR

infrastructure/testdriver/bidi/bluetooth/resources/bidi-bluetooth-helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const DEVICE_NAME = 'LE Device';
44
const DEVICE_ADDRESS = '09:09:09:09:09:09';
5+
const HEART_RATE_SERVICE_UUID = '0000180d-0000-1000-8000-00805f9b34fb'
6+
const DATE_TIME_CHARACTERISTIC_UUID = '00002a08-0000-1000-8000-00805f9b34fb'
7+
const CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR_UUID = '00002901-0000-1000-8000-00805f9b34fb'
58

69
/**
710
* Waits until the document has finished loading.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
4+
<title>TestDriver bidi.bluetooth.simulate_characteristic method</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js?feature=bidi"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="resources/bidi-bluetooth-helper.js"></script>
10+
11+
<script>
12+
promise_setup(async () => {
13+
await test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe();
14+
await test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe();
15+
});
16+
17+
bluetooth_test(async (t) => {
18+
const handle_prompt_promise = selectFirstDeviceOnDevicePromptUpdated();
19+
const [device] = await Promise.all([requestDeviceWithTrustedClick({
20+
acceptAllDevices: true,
21+
optionalServices: [HEART_RATE_SERVICE_UUID]
22+
}), handle_prompt_promise]);
23+
24+
await createGattConnection(device);
25+
await test_driver.bidi.bluetooth.simulate_service({
26+
address: DEVICE_ADDRESS,
27+
uuid: HEART_RATE_SERVICE_UUID,
28+
type: 'add',
29+
});
30+
await test_driver.bidi.bluetooth.simulate_characteristic({
31+
address: DEVICE_ADDRESS,
32+
serviceUuid: HEART_RATE_SERVICE_UUID,
33+
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
34+
characteristicProperties: {
35+
'read': true
36+
},
37+
type: 'add',
38+
});
39+
service = await device.gatt.getPrimaryService(HEART_RATE_SERVICE_UUID);
40+
characteristics = await service.getCharacteristics();
41+
assert_equals(
42+
JSON.stringify(characteristics.map(characteristic => characteristic.uuid)),
43+
JSON.stringify([DATE_TIME_CHARACTERISTIC_UUID])
44+
);
45+
}, "simulate a GATT characteristic.");
46+
</script>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
4+
<title>TestDriver bidi.bluetooth.simulate_characteristic_response method</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js?feature=bidi"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="resources/bidi-bluetooth-helper.js"></script>
10+
11+
<script>
12+
promise_setup(async () => {
13+
await test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe();
14+
await test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe();
15+
await test_driver.bidi.bluetooth.characteristic_event_generated.subscribe();
16+
});
17+
18+
bluetooth_test(async (t) => {
19+
const expected_value = [0, 1, 2];
20+
const handle_prompt_promise = selectFirstDeviceOnDevicePromptUpdated();
21+
const [device] = await Promise.all([requestDeviceWithTrustedClick({
22+
acceptAllDevices: true,
23+
optionalServices: [HEART_RATE_SERVICE_UUID]
24+
}), handle_prompt_promise]);
25+
26+
await createGattConnection(device);
27+
await test_driver.bidi.bluetooth.simulate_service({
28+
address: DEVICE_ADDRESS,
29+
uuid: HEART_RATE_SERVICE_UUID,
30+
type: 'add',
31+
});
32+
await test_driver.bidi.bluetooth.simulate_characteristic({
33+
address: DEVICE_ADDRESS,
34+
serviceUuid: HEART_RATE_SERVICE_UUID,
35+
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
36+
characteristicProperties: {
37+
'read': true
38+
},
39+
type: 'add',
40+
});
41+
const simulationProcessedPromise =
42+
test_driver.bidi.bluetooth.characteristic_event_generated.once().then(
43+
(event) => {
44+
return test_driver.bidi.bluetooth.simulate_characteristic_response({
45+
address: event.address,
46+
serviceUuid: event.serviceUuid,
47+
characteristicUuid: event.characteristicUuid,
48+
type: 'read',
49+
code: 0x0,
50+
data: expected_value,
51+
});
52+
});
53+
service = await device.gatt.getPrimaryService(HEART_RATE_SERVICE_UUID);
54+
characteristic = await service.getCharacteristic(DATE_TIME_CHARACTERISTIC_UUID);
55+
[value] = await Promise.all([characteristic.readValue(), simulationProcessedPromise]);
56+
assert_array_equals(new Uint8Array(value.buffer), expected_value)
57+
}, "simulate a GATT characteristic response");
58+
</script>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
4+
<title>TestDriver bidi.bluetooth.simulate_descriptor method</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js?feature=bidi"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="resources/bidi-bluetooth-helper.js"></script>
10+
11+
<script>
12+
promise_setup(async () => {
13+
await test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe();
14+
await test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe();
15+
});
16+
17+
bluetooth_test(async (t) => {
18+
const handle_prompt_promise = selectFirstDeviceOnDevicePromptUpdated();
19+
const [device] = await Promise.all([requestDeviceWithTrustedClick({
20+
acceptAllDevices: true,
21+
optionalServices: [HEART_RATE_SERVICE_UUID]
22+
}), handle_prompt_promise]);
23+
24+
await createGattConnection(device);
25+
await test_driver.bidi.bluetooth.simulate_service({
26+
address: DEVICE_ADDRESS,
27+
uuid: HEART_RATE_SERVICE_UUID,
28+
type: 'add',
29+
});
30+
await test_driver.bidi.bluetooth.simulate_characteristic({
31+
address: DEVICE_ADDRESS,
32+
serviceUuid: HEART_RATE_SERVICE_UUID,
33+
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
34+
characteristicProperties: {
35+
'read': true
36+
},
37+
type: 'add',
38+
});
39+
await test_driver.bidi.bluetooth.simulate_descriptor({
40+
address: DEVICE_ADDRESS,
41+
serviceUuid: HEART_RATE_SERVICE_UUID,
42+
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
43+
descriptorUuid: CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR_UUID,
44+
type: 'add',
45+
});
46+
service = await device.gatt.getPrimaryService(HEART_RATE_SERVICE_UUID);
47+
characteristic = await service.getCharacteristic(DATE_TIME_CHARACTERISTIC_UUID);
48+
descriptors = await characteristic.getDescriptors();
49+
assert_equals(
50+
JSON.stringify(descriptors.map(descriptor => descriptor.uuid)),
51+
JSON.stringify([CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR_UUID])
52+
);
53+
}, "simulate a GATT descriptor.");
54+
</script>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
4+
<title>TestDriver bidi.bluetooth.simulate_descriptor_response method</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js?feature=bidi"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="resources/bidi-bluetooth-helper.js"></script>
10+
11+
<script>
12+
promise_setup(async () => {
13+
await test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe();
14+
await test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe();
15+
await test_driver.bidi.bluetooth.descriptor_event_generated.subscribe();
16+
});
17+
18+
bluetooth_test(async (t) => {
19+
const expected_value = [0, 1, 2];
20+
const handle_prompt_promise = selectFirstDeviceOnDevicePromptUpdated();
21+
const [device] = await Promise.all([requestDeviceWithTrustedClick({
22+
acceptAllDevices: true,
23+
optionalServices: [HEART_RATE_SERVICE_UUID]
24+
}), handle_prompt_promise]);
25+
26+
await createGattConnection(device);
27+
await test_driver.bidi.bluetooth.simulate_service({
28+
address: DEVICE_ADDRESS,
29+
uuid: HEART_RATE_SERVICE_UUID,
30+
type: 'add',
31+
});
32+
await test_driver.bidi.bluetooth.simulate_characteristic({
33+
address: DEVICE_ADDRESS,
34+
serviceUuid: HEART_RATE_SERVICE_UUID,
35+
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
36+
characteristicProperties: {
37+
'read': true
38+
},
39+
type: 'add',
40+
});
41+
await test_driver.bidi.bluetooth.simulate_descriptor({
42+
address: DEVICE_ADDRESS,
43+
serviceUuid: HEART_RATE_SERVICE_UUID,
44+
characteristicUuid: DATE_TIME_CHARACTERISTIC_UUID,
45+
descriptorUuid: CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR_UUID,
46+
type: 'add',
47+
});
48+
const simulationProcessedPromise =
49+
test_driver.bidi.bluetooth.descriptor_event_generated.once().then(
50+
(event) => {
51+
return test_driver.bidi.bluetooth.simulate_descriptor_response({
52+
address: event.address,
53+
serviceUuid: event.serviceUuid,
54+
characteristicUuid: event.characteristicUuid,
55+
descriptorUuid: event.descriptorUuid,
56+
type: 'read',
57+
code: 0x0,
58+
data: expected_value,
59+
});
60+
});
61+
service = await device.gatt.getPrimaryService(HEART_RATE_SERVICE_UUID);
62+
characteristic = await service.getCharacteristic(DATE_TIME_CHARACTERISTIC_UUID);
63+
descriptor = await characteristic.getDescriptor(CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR_UUID);
64+
[value] = await Promise.all([descriptor.readValue(), simulationProcessedPromise]);
65+
assert_array_equals(new Uint8Array(value.buffer), expected_value)
66+
}, "simulate a GATT descriptor response");
67+
</script>

infrastructure/testdriver/bidi/bluetooth/simulate_gatt_connection_response.https.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
34
<title>TestDriver bidi.bluetooth.simulate_gatt_connection_response method</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>

infrastructure/testdriver/bidi/bluetooth/simulate_gatt_disconnection.https.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
34
<title>TestDriver bidi.bluetooth.simulate_gatt_disconnection method</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8" />
3+
<meta name="timeout" content="long">
4+
<title>TestDriver bidi.bluetooth.simulate_service method</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js?feature=bidi"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="resources/bidi-bluetooth-helper.js"></script>
10+
11+
<script>
12+
promise_setup(async () => {
13+
await test_driver.bidi.bluetooth.request_device_prompt_updated.subscribe();
14+
await test_driver.bidi.bluetooth.gatt_connection_attempted.subscribe();
15+
});
16+
17+
bluetooth_test(async (t) => {
18+
const handle_prompt_promise = selectFirstDeviceOnDevicePromptUpdated();
19+
const [device] = await Promise.all([requestDeviceWithTrustedClick({
20+
acceptAllDevices: true,
21+
optionalServices: [HEART_RATE_SERVICE_UUID]
22+
}), handle_prompt_promise]);
23+
24+
await createGattConnection(device);
25+
await test_driver.bidi.bluetooth.simulate_service({
26+
address: DEVICE_ADDRESS,
27+
uuid: HEART_RATE_SERVICE_UUID,
28+
type: 'add',
29+
});
30+
services = await device.gatt.getPrimaryServices();
31+
assert_equals(
32+
JSON.stringify(services.map(service => service.uuid)),
33+
JSON.stringify([HEART_RATE_SERVICE_UUID])
34+
);
35+
}, "simulate a GATT service.");
36+
</script>

0 commit comments

Comments
 (0)