bluetooth-scanning-helpers.js (1499B)
1 'use strict'; 2 3 const company_id = '224'; 4 const data = new TextEncoder().encode('foo'); 5 const manufacturerDataMap = {[company_id]: data}; 6 const health_uuid = health_thermometer.uuid; 7 const serviceDataMap = {[health_uuid]: data}; 8 const scanRecord = { 9 name: 'Health Thermometer', 10 uuids: ['generic_access', health_uuid], 11 txPower: 20, 12 appearance: 100, 13 manufacturerData: manufacturerDataMap, 14 serviceData: serviceDataMap, 15 }; 16 const scanResult = { 17 deviceAddress: '09:09:09:09:09:09', 18 rssi: 100, 19 scanRecord: scanRecord, 20 }; 21 22 function verifyBluetoothAdvertisingEvent(e) { 23 assert_equals(e.constructor.name, 'BluetoothAdvertisingEvent') 24 assert_equals(e.device.name, scanRecord.name) 25 assert_equals(e.name, scanRecord.name) 26 assert_array_equals(e.uuids, 27 ["00001800-0000-1000-8000-00805f9b34fb", 28 "00001809-0000-1000-8000-00805f9b34fb"]) 29 assert_equals(e.txPower, 20) 30 assert_equals(e.rssi, 100) 31 32 assert_equals(e.manufacturerData.constructor.name, 33 'BluetoothManufacturerDataMap') 34 assert_equals(data[0], e.manufacturerData.get(224).getUint8(0)) 35 assert_equals(data[1], e.manufacturerData.get(224).getUint8(1)) 36 assert_equals(data[2], e.manufacturerData.get(224).getUint8(2)) 37 38 assert_equals(e.serviceData.constructor.name, 'BluetoothServiceDataMap') 39 assert_equals(data[0], e.serviceData.get(health_uuid).getUint8(0)) 40 assert_equals(data[1], e.serviceData.get(health_uuid).getUint8(1)) 41 assert_equals(data[2], e.serviceData.get(health_uuid).getUint8(2)) 42 }