summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/resources/bluetooth-scanning-helpers.js
blob: f474c9c3066f247f8f28558284e4de5d6326ff79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';

const company_id = '224';
const data = new TextEncoder().encode('foo');
const manufacturerDataMap = {[company_id]: data};
const health_uuid = health_thermometer.uuid;
const serviceDataMap = {[health_uuid]: data};
const scanRecord = {
  name: 'Health Thermometer',
  uuids: ['generic_access', health_uuid],
  txPower: 20,
  appearance: 100,
  manufacturerData: manufacturerDataMap,
  serviceData: serviceDataMap,
};
const scanResult = {
  deviceAddress: '09:09:09:09:09:09',
  rssi: 100,
  scanRecord: scanRecord,
};

function verifyBluetoothAdvertisingEvent(e) {
  assert_equals(e.constructor.name, 'BluetoothAdvertisingEvent')
  assert_equals(e.device.name, scanRecord.name)
  assert_equals(e.name, scanRecord.name)
  assert_array_equals(e.uuids,
    ["00001800-0000-1000-8000-00805f9b34fb",
     "00001809-0000-1000-8000-00805f9b34fb"])
  assert_equals(e.txPower, 20)
  assert_equals(e.rssi, 100)

  assert_equals(e.manufacturerData.constructor.name,
                'BluetoothManufacturerDataMap')
  assert_equals(data[0], e.manufacturerData.get(224).getUint8(0))
  assert_equals(data[1], e.manufacturerData.get(224).getUint8(1))
  assert_equals(data[2], e.manufacturerData.get(224).getUint8(2))

  assert_equals(e.serviceData.constructor.name, 'BluetoothServiceDataMap')
  assert_equals(data[0], e.serviceData.get(health_uuid).getUint8(0))
  assert_equals(data[1], e.serviceData.get(health_uuid).getUint8(1))
  assert_equals(data[2], e.serviceData.get(health_uuid).getUint8(2))
}