diff options
Diffstat (limited to 'tests/html')
23 files changed, 1112 insertions, 119 deletions
diff --git a/tests/html/bluetooth/bluetooth_battery_level.html b/tests/html/bluetooth/bluetooth_battery_level.html new file mode 100644 index 00000000000..77dccf1e40c --- /dev/null +++ b/tests/html/bluetooth/bluetooth_battery_level.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<html> +<title>Battery Level</title> +<body> + <button type="button" onclick="onButtonClick()">Get Bluetooth Device's Battery Level</button> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + function onButtonClick() { + clear(); + var options = {filters: [{services: ['battery_service']}], optionalServices: []}; + + try { + log('Requesting Bluetooth Device...'); + var bluetooth = window.navigator.bluetooth; + var device = bluetooth.requestDevice(options); + + log('Connecting to GATT Server on device...'); + var server = device.gatt.connect(); + + log('Getting Battery Service...'); + var service = server.getPrimaryService('battery_service'); + + log('Getting Battery Level Characteristic...'); + var characteristic = service.getCharacteristic('battery_level'); + + log('Reading Battery Level...'); + var value = asciiToDecimal(characteristic.readValue()); + log('> Battery Level is ' + value + '%'); + } catch(err) { + log(err); + } + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth_battery_level.html b/tests/html/bluetooth/bluetooth_battery_level_with_filter.html index 8618df07859..269aa4e5ab2 100644 --- a/tests/html/bluetooth_battery_level.html +++ b/tests/html/bluetooth/bluetooth_battery_level_with_filter.html @@ -1,23 +1,24 @@ <!DOCTYPE html> <html> -<title>Battery Level</title> +<title>Battery Level with filters</title> <body> <input id="name" type="text" placeholder="Device Name"> <input id="namePrefix" type="text" placeholder="Device Name Prefix"> <button type="button" onclick="onButtonClick()">Get Bluetooth Device's Battery Level</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> function onButtonClick() { clear(); - var options = {filters: [{services: ['battery_service']}], optinalServices: []}; + var options = {filters: [{services: ['battery_service']}], optionalServices: []}; var filterName = document.getElementById('name').value; if (filterName) - options.filters.push({name: filterName}); + options.filters[0].name = filterName; var filterNamePrefix = document.getElementById('namePrefix').value; if (filterNamePrefix) - options.filters.push({namePrefix: filterNamePrefix}); + options.filters[0].namePrefix = filterNamePrefix; try { log('Requesting Bluetooth Device...'); @@ -34,28 +35,12 @@ var characteristic = service.getCharacteristic('battery_level'); log('Reading Battery Level...'); - var value = AsciiToDecimal(characteristic.readValue()); + var value = asciiToDecimal(characteristic.readValue()); log('> Battery Level is ' + value + '%'); } catch(err) { log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } - - function AsciiToDecimal(bytestr) { - var result = []; - for(i = 0; i < bytestr.length; i++) { - result[i] = bytestr[i].charCodeAt(0) ; - } - return result; - } </script> </body> </html> diff --git a/tests/html/bluetooth_characteristic_info.html b/tests/html/bluetooth/bluetooth_characteristic_info.html index 84cebd83014..d3eb3a2d255 100644 --- a/tests/html/bluetooth_characteristic_info.html +++ b/tests/html/bluetooth/bluetooth_characteristic_info.html @@ -6,14 +6,19 @@ <input id="characteristic" type="text" autofocus placeholder="Bluetooth Characteristic"> <button type="button" onclick="onButtonClick()">Get Characteristic Info</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> function onButtonClick() { clear(); var serviceUuid = document.getElementById('service').value; + var characteristicUuid = document.getElementById('characteristic').value; + + if (!serviceUuid || !characteristicUuid) { + return log('All input field must be filled!'); + } if (serviceUuid.startsWith('0x')) serviceUuid = parseInt(serviceUuid, 16); - var characteristicUuid = document.getElementById('characteristic').value; if (characteristicUuid.startsWith('0x')) characteristicUuid = parseInt(characteristicUuid, 16); @@ -43,27 +48,11 @@ log('> Queued Write: ' + characteristic.properties.reliableWrite); log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries); characteristic.readValue(); - log('> Characteristic value: ' + AsciiToDecimal(characteristic.value)); + log('> Characteristic value: ' + asciiToDecimal(characteristic.value)); } catch(err) { log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } - - function AsciiToDecimal(bytestr) { - var result = []; - for(i = 0; i < bytestr.length; i++) { - result[i] = bytestr[i].charCodeAt(0) ; - } - return result; - } </script> </body> </html> diff --git a/tests/html/bluetooth/bluetooth_characteristic_read_value_test_cases.html b/tests/html/bluetooth/bluetooth_characteristic_read_value_test_cases.html new file mode 100644 index 00000000000..45b60128de9 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_characteristic_read_value_test_cases.html @@ -0,0 +1,66 @@ +<!DOCTYPE html> +<html> +<title>Characterstic's ReadValue Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({characteristic: 'body_sensor_location', mustDisconnect: true}); + //Test 2 + testCases.push({characteristic: 'gap.reconnection_address', mustDisconnect: false}); + //Test 3 + testCases.push({characteristic: 'serial_number_string', mustDisconnect: false}); + //Test 4 + testCases.push({characteristic: 0x00002a03, mustDisconnect: false}); + //Test 5 + testCases.push({characteristic: 0x00002a25, mustDisconnect: false}); + //Test 6 + testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', mustDisconnect: false}); + //Test 7 + testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', mustDisconnect: false}); + //Test 8 + testCases.push({characteristic: 'body_sensor_location', mustDisconnect: false}); + //Test 9 + testCases.push({characteristic: 0x00002a38, mustDisconnect: false}); + //Test 10 + testCases.push({characteristic: '00002a38-0000-1000-8000-00805f9b34fb', mustDisconnect: false}); + //Test 11 + testCases.push({characteristic: 'heart_rate_control_point', mustDisconnect: false}); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "heart_rate"...'); + var primaryService = server.getPrimaryService('heart_rate'); + + log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...'); + var characteristic = primaryService.getCharacteristic(testCases[testNumber].characteristic); + + log('Characteristic found!'); + + if (testCases[testNumber].mustDisconnect) { + log('Disconnecting from server...'); + device.gatt.disconnect(); + } + + log('Reading the value of the Characteristic...'); + characteristic.readValue(); + log('> Characteristic value: ' + asciiToDecimal(characteristic.value)); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_characteristic_write_value_test_cases.html b/tests/html/bluetooth/bluetooth_characteristic_write_value_test_cases.html new file mode 100644 index 00000000000..db9d9ce084f --- /dev/null +++ b/tests/html/bluetooth/bluetooth_characteristic_write_value_test_cases.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html> +<title>Characterstic's WriteValue Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({characteristic: 0x2345, valueToWrite: [11], mustDisconnect: true}); + //Test 2 + testCases.push({characteristic: 0x2345, valueToWrite: new Array(513), mustDisconnect: false}); + //Test 3 + testCases.push({characteristic: 'gap.reconnection_address', valueToWrite: [1], mustDisconnect: false}); + //Test 4 + testCases.push({characteristic: 'serial_number_string', valueToWrite: [2], mustDisconnect: false}); + //Test 5 + testCases.push({characteristic: 0x00002a02, valueToWrite: [3], mustDisconnect: false}); + //Test 6 + testCases.push({characteristic: 0x00002a03, valueToWrite: [3], mustDisconnect: false}); + //Test 7 + testCases.push({characteristic: 0x00002a25, valueToWrite: [4], mustDisconnect: false}); + //Test 8 + testCases.push({characteristic: '00002a02-0000-1000-8000-00805f9b34fb', valueToWrite: [6], mustDisconnect: false}); + //Test 9 + testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', valueToWrite: [5], mustDisconnect: false}); + //Test 10 + testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', valueToWrite: [6], mustDisconnect: false}); + //Test 11 + testCases.push({characteristic: 0x2345, valueToWrite: [11]}); + //Test 12 + testCases.push({characteristic: '00002345-0000-1000-8000-00805f9b34fb', valueToWrite: [22], mustDisconnect: false}); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "Test Service"...'); + var primaryService = server.getPrimaryService(0x1234); + + log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...'); + var characteristic = primaryService.getCharacteristic(testCases[testNumber].characteristic); + + log('Characteristic found!'); + + log('Reading the old value of the Characteristic...'); + characteristic.readValue(); + log('> Characteristic value: ' + asciiToDecimal(characteristic.value)); + + if (testCases[testNumber].mustDisconnect) { + log('Disconnecting from server...'); + device.gatt.disconnect(); + } + + if (testNumber !== 1) { + log('Writing the value of the Characteristic with: ' + testCases[testNumber].valueToWrite + '...'); + } else { + log('Writing the value of the Characteristic with a 513 long array...'); + } + + characteristic.writeValue(testCases[testNumber].valueToWrite); + + log('Reading the new value of the Characteristic...'); + characteristic.readValue(); + log('> Characteristic value: ' + asciiToDecimal(characteristic.value)); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth_descriptor_info.html b/tests/html/bluetooth/bluetooth_descriptor_info.html index c657d217697..47d9e294295 100644 --- a/tests/html/bluetooth_descriptor_info.html +++ b/tests/html/bluetooth/bluetooth_descriptor_info.html @@ -7,18 +7,23 @@ <input id="descriptor" type="text" autofocus placeholder="Bluetooth Descriptor"> <button type="button" onclick="onButtonClick()">Get Descriptor Info</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> function onButtonClick() { clear(); var serviceUuid = document.getElementById('service').value; + var characteristicUuid = document.getElementById('characteristic').value; + var descriptorUuid = document.getElementById('descriptor').value; + + if (!serviceUuid || !characteristicUuid || !descriptorUuid) { + return log('All input field must be filled!'); + } if (serviceUuid.startsWith('0x')) serviceUuid = parseInt(serviceUuid, 16); - var characteristicUuid = document.getElementById('characteristic').value; if (characteristicUuid.startsWith('0x')) characteristicUuid = parseInt(characteristicUuid, 16); - var descriptorUuid = document.getElementById('descriptor').value; if (descriptorUuid.startsWith('0x')) descriptorUuid = parseInt(descriptorUuid, 16); @@ -42,27 +47,11 @@ log('> Descriptor characteristic: ' + descriptor.characteristic.uuid); log('> Descriptor UUID: ' + descriptor.uuid); descriptor.readValue(); - log('> Descriptor value: ' + AsciiToDecimal(descriptor.value)); + log('> Descriptor value: ' + asciiToDecimal(descriptor.value)); } catch(err) { log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } - - function AsciiToDecimal(bytestr) { - var result = []; - for(i = 0; i < bytestr.length; i++) { - result[i] = bytestr[i].charCodeAt(0) ; - } - return result; - } </script> </body> </html> diff --git a/tests/html/bluetooth/bluetooth_descriptor_read_value_test_cases.html b/tests/html/bluetooth/bluetooth_descriptor_read_value_test_cases.html new file mode 100644 index 00000000000..8a2e553652b --- /dev/null +++ b/tests/html/bluetooth/bluetooth_descriptor_read_value_test_cases.html @@ -0,0 +1,57 @@ +<!DOCTYPE html> +<html> +<title>Descriptor's ReadValue Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({descriptor: 'gatt.client_characteristic_configuration', mustDisconnect: true}); + //Test 2 + testCases.push({descriptor: 0x2902, mustDisconnect: true}); + //Test 3 + testCases.push({descriptor: '00002902-0000-1000-8000-00805f9b34fb', mustDisconnect: true}); + //Test 4 + testCases.push({descriptor: 'gatt.client_characteristic_configuration', mustDisconnect: false}); + //Test 5 + testCases.push({descriptor: 0x2902, mustDisconnect: false}); + //Test 6 + testCases.push({descriptor: '00002902-0000-1000-8000-00805f9b34fb', mustDisconnect: false}); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "heart_rate"...'); + var primaryService = server.getPrimaryService('heart_rate'); + + log('Getting Characteristic "heart_rate_measurement"...'); + var characteristic = primaryService.getCharacteristic('heart_rate_measurement'); + + log('Getting Descriptor "' + testCases[testNumber].descriptor + '"...'); + var descriptor = characteristic.getDescriptor(testCases[testNumber].descriptor); + + log('Descriptor found!'); + if (testCases[testNumber].mustDisconnect) { + log('Disconecting from GATTserver'); + device.gatt.disconnect(); + } + log("Reading descriptor's value..."); + descriptor.readValue(); + log('> Descriptor value: ' + asciiToDecimal(descriptor.value)); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_descriptor_write_value_test_cases.html b/tests/html/bluetooth/bluetooth_descriptor_write_value_test_cases.html new file mode 100644 index 00000000000..0553023ca7c --- /dev/null +++ b/tests/html/bluetooth/bluetooth_descriptor_write_value_test_cases.html @@ -0,0 +1,71 @@ +<!DOCTYPE html> +<html> +<title>Descriptor's WriteValue Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({descriptor: '00003456-0000-1000-8000-00805f9b34fb', valueToWrite: [11], mustDisconnect: true}); + //Test 2 + testCases.push({descriptor: '00003456-0000-1000-8000-00805f9b34fb', valueToWrite: new Array(513), mustDisconnect: false}); + //Test 3 + testCases.push({descriptor: '00002902-0000-1000-8000-00805f9b34fb', valueToWrite: [1], mustDisconnect: false}); + //Test 4 + testCases.push({descriptor: 0x00002902, valueToWrite: [2], mustDisconnect: false}); + //Test 5 + testCases.push({descriptor: 0x3456, valueToWrite: [11], mustDisconnect: false}); + //Test 6 + testCases.push({descriptor: '00003456-0000-1000-8000-00805f9b34fb', valueToWrite: [22], mustDisconnect: false}); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "Test Service"...'); + var primaryService = server.getPrimaryService(0x1234); + + log('Getting Characteristic "Test Characteristic (0x2345)"...'); + var characteristic = primaryService.getCharacteristic(0x2345); + + log('Characteristic found!'); + + log('Getting Descriptor "' + testCases[testNumber].descriptor + '"...'); + var descriptor = characteristic.getDescriptor(testCases[testNumber].descriptor); + + log('Reading the old value of the Descriptor...'); + descriptor.readValue(); + log('> Descriptor value: ' + asciiToDecimal(descriptor.value)); + + if (testCases[testNumber].mustDisconnect) { + log('Disconnecting from server...'); + device.gatt.disconnect(); + } + + if (testNumber !== 1) { + log('Writing the value of the Descriptor with: ' + testCases[testNumber].valueToWrite + '...'); + } else { + log('Writing the value of the Descriptor with a 513 long array...'); + } + + descriptor.writeValue(testCases[testNumber].valueToWrite); + + log('Reading the new value of the Descriptor...'); + descriptor.readValue(); + log('> Descriptor value: ' + asciiToDecimal(descriptor.value)); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth_device_disconnect.html b/tests/html/bluetooth/bluetooth_device_disconnect.html index 715d3d16a24..3f9771dfee6 100644 --- a/tests/html/bluetooth_device_disconnect.html +++ b/tests/html/bluetooth/bluetooth_device_disconnect.html @@ -9,33 +9,34 @@ <button type="button" onclick="onDisconnectButtonClick()">Disconnect()</button> <button type="button" onclick="onReconnectButtonClick()">Reconnect()</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> var bluetoothDevice; function onScanButtonClick() { clear(); - var options = {filters: []}; + var options = {filters: [{}]}; var filterService = document.getElementById('service').value; - if (filterService.startsWith('0x')) - filterService = parseInt(filterService, 16); - - if (filterService) - options.filters.push({services: [filterService]}); + if (filterService) { + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); + options.filters[0].services = [filterService]; + } var filterName = document.getElementById('name').value; if (filterName) - options.filters.push({name: filterName}); + options.filters[0].name = filterName; var filterNamePrefix = document.getElementById('namePrefix').value; if (filterNamePrefix) - options.filters.push({namePrefix: filterNamePrefix}); - - bluetoothDevice = null; + options.filters[0].namePrefix = filterNamePrefix; try { + clear(); log('Requesting Bluetooth Device...'); bluetoothDevice = window.navigator.bluetooth.requestDevice(options); + log('Connecting to Bluetooth Device...'); connect(); } catch(err) { log(err); @@ -45,7 +46,7 @@ function onDisconnectButtonClick() { clear(); if (!bluetoothDevice) - return; + return log('> There is no connected Bluetooth Device instance, from which we can disconnect'); try { log('Disconnecting from Bluetooth Device...'); @@ -63,32 +64,24 @@ function onReconnectButtonClick() { clear(); if (!bluetoothDevice) - log('> There is no connected Bluetooth Device instance') + log('> There is no connected Bluetooth Device instance, so we cannot reconnect') if (bluetoothDevice.gatt.connected) { log('> Bluetooth Device is already connected'); return; } else { + log('Connecting to Bluetooth Device...'); connect(); } } function connect() { try { - log('Connecting to Bluetooth Device...'); - bluetoothDevice.gatt.connect(); + log('Result of the connect() method of the GATT Server: ' + bluetoothDevice.gatt.connect()); log('> Bluetooth Device connected: ' + bluetoothDevice.gatt.connected); } catch(err) { log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } </script> </body> </html> diff --git a/tests/html/bluetooth_device_info.html b/tests/html/bluetooth/bluetooth_device_info.html index 906dc200362..6df38acbeae 100644 --- a/tests/html/bluetooth_device_info.html +++ b/tests/html/bluetooth/bluetooth_device_info.html @@ -7,17 +7,18 @@ <input id="namePrefix" type="text" placeholder="Device Name Prefix"> <button type="button" onclick="onButtonClick()">Get Bluetooth Device Info</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> function onButtonClick() { clear(); - var options = {filters: [], optinalServices: []}; + var options = {filters: [], optionalServices: []}; var filterService = document.getElementById('service').value; - if (filterService.startsWith('0x')) - filterService = parseInt(filterService, 16); - - if (filterService) + if (filterService) { + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); options.filters.push({services: [filterService]}); + } var filterName = document.getElementById('name').value; if (filterName) @@ -41,14 +42,6 @@ log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } </script> </body> </html> diff --git a/tests/html/bluetooth/bluetooth_functions.js b/tests/html/bluetooth/bluetooth_functions.js new file mode 100644 index 00000000000..b0f73c79c0a --- /dev/null +++ b/tests/html/bluetooth/bluetooth_functions.js @@ -0,0 +1,32 @@ +function clear() { + document.getElementById("log").textContent = ""; +} + +function log(line) { + document.getElementById("log").textContent += timeStamp() + line + '\n'; +} + +function asciiToDecimal(bytestr) { + var result = []; + for(i = 0; i < bytestr.length; i++) { + result[i] = bytestr.charCodeAt(i) ; + } + return result; +} + +function populate(testCases){ + for(i = 0; i < testCases.length; ++i) { + var btn = document.createElement('button'); + btn.setAttribute('onclick','onButtonClick(' + i + ')'); + btn.innerHTML = 'Test '+ (i+1); + document.getElementById('buttons').appendChild(btn); + } +} + +function timeStamp() { + var date = new Date; + var hours = date.getHours(); + var minutes = "0" + date.getMinutes(); + var seconds = "0" + date.getSeconds(); + return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2) + ' '; +} diff --git a/tests/html/bluetooth/bluetooth_get_characteristic_test_cases.html b/tests/html/bluetooth/bluetooth_get_characteristic_test_cases.html new file mode 100644 index 00000000000..5c9c2fe4f73 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_characteristic_test_cases.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<html> +<title>GetCharacteristic Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({characteristic: 'not_a_characteristic_name', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 2 + testCases.push({characteristic: 'battery_level', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 3 + testCases.push({characteristic: '1234567891000-1000-8000-00805f9b34fb', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 4 + testCases.push({characteristic: '11', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 5 + testCases.push({characteristic: '12345678-1234-1234-1234-123456789abc', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 6 + testCases.push({characteristic: '00000000-0000-0000-0000-000000000000', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 7 + testCases.push({characteristic: 0x0000, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 8 + testCases.push({characteristic: 0x000000000, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 9 + testCases.push({characteristic: 0x2a19, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 10 + testCases.push({characteristic: 0x12345678, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 11 + testCases.push({characteristic: 0x00002a19, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 12 + testCases.push({characteristic: 0x00002a03, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 13 + testCases.push({characteristic: 0x00002a25, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 14 + testCases.push({characteristic: 0x2a03, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 15 + testCases.push({characteristic: 0x2a25, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 16 + testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 17 + testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "' + testCases[testNumber].service + '"...'); + var primaryService = server.getPrimaryService(testCases[testNumber].service); + + log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...'); + var characteristic = primaryService.getCharacteristic(testCases[testNumber].characteristic); + + log('Characteristic found!'); + log('> Characteristic service: ' + characteristic.service.uuid); + log('> Characteristic UUID: ' + characteristic.uuid); + log('> Broadcast: ' + characteristic.properties.broadcast); + log('> Read: ' + characteristic.properties.read); + log('> Write w/o response: ' + characteristic.properties.writeWithoutResponse); + log('> Write: ' + characteristic.properties.write); + log('> Notify: ' + characteristic.properties.notify); + log('> Indicate: ' + characteristic.properties.indicate); + log('> Signed Write: ' + characteristic.properties.authenticatedSignedWrites); + log('> Queued Write: ' + characteristic.properties.reliableWrite); + log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries); + characteristic.readValue(); + log('> Characteristic value: ' + asciiToDecimal(characteristic.value)); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_characteristics_test_cases.html b/tests/html/bluetooth/bluetooth_get_characteristics_test_cases.html new file mode 100644 index 00000000000..81c3e42bb47 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_characteristics_test_cases.html @@ -0,0 +1,87 @@ +<!DOCTYPE html> +<html> +<title>GetCharacteristics Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 2 + testCases.push({characteristic: 'not_a_characteristic_name', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 3 + testCases.push({characteristic: 'body_sensor_location', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 4 + testCases.push({characteristic: '1234567891000-1000-8000-00805f9b34fb', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 5 + testCases.push({characteristic: '11', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 6 + testCases.push({characteristic: '12345678-1234-1234-1234-123456789abc', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 7 + testCases.push({characteristic: '00000000-0000-0000-0000-000000000000', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 8 + testCases.push({characteristic: 0x0000, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 9 + testCases.push({characteristic: 0x000000000, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 10 + testCases.push({characteristic: 0x2a38, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 11 + testCases.push({characteristic: 0x12345678, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 12 + testCases.push({characteristic: 0x00002a38, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 13 + testCases.push({characteristic: 0x00002a03, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 14 + testCases.push({characteristic: 0x00002a25, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 15 + testCases.push({characteristic: 0x2a03, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 16 + testCases.push({characteristic: 0x2a25, service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 17 + testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + //Test 18 + testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} }); + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "' + testCases[testNumber].service + '"...'); + var primaryService = server.getPrimaryService(testCases[testNumber].service); + + log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...'); + var characteristics = primaryService.getCharacteristics(testCases[testNumber].characteristic); + + log('> List of Characteristics on the current device:'); + + for(i = 0; i < characteristics.length; ++i) { + log('> #' + (i+1)); + log('> Characteristic service: ' + characteristics[i].service.uuid); + log('> Characteristic UUID: ' + characteristics[i].uuid); + log('> Broadcast: ' + characteristics[i].properties.broadcast); + log('> Read: ' + characteristics[i].properties.read); + log('> Write w/o response: ' + characteristics[i].properties.writeWithoutResponse); + log('> Write: ' + characteristics[i].properties.write); + log('> Notify: ' + characteristics[i].properties.notify); + log('> Indicate: ' + characteristics[i].properties.indicate); + log('> Signed Write: ' + characteristics[i].properties.authenticatedSignedWrites); + log('> Queued Write: ' + characteristics[i].properties.reliableWrite); + log('> Writable Auxiliaries: ' + characteristics[i].properties.writableAuxiliaries); + characteristics[i].readValue(); + log('> Characteristic value: ' + asciiToDecimal(characteristics[i].value)); + } + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_descriptor_test_cases.html b/tests/html/bluetooth/bluetooth_get_descriptor_test_cases.html new file mode 100644 index 00000000000..e37a0dabd28 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_descriptor_test_cases.html @@ -0,0 +1,66 @@ +<!DOCTYPE html> +<html> +<title>GetDescriptor Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push('not_a_descriptor_name'); + //Test 2 + testCases.push('gatt.client_characteristic_configuration'); + //Test 3 + testCases.push('1234567891000-1000-8000-00805f9b34fb'); + //Test 4 + testCases.push('11'); + //Test 5 + testCases.push('12345678-1234-1234-1234-123456789abc'); + //Test 6 + testCases.push('00000000-0000-0000-0000-000000000000'); + //Test 7 + testCases.push(0x0000); + //Test 8 + testCases.push(0x00000000); + //Test 9 + testCases.push(0x2902); + //Test 10 + testCases.push('00002902-0000-1000-8000-00805f9b34fb'); + //Test 11 + testCases.push(0x12345678); + //Test 12 + testCases.push(0x00002902); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "heart_rate"...'); + var primaryService = server.getPrimaryService('heart_rate'); + + log('Getting Characteristic "heart_rate_measurement"...'); + var characteristic = primaryService.getCharacteristic('heart_rate_measurement'); + + log('Getting Descriptor "' + testCases[testNumber] + '"...'); + var descriptor = characteristic.getDescriptor(testCases[testNumber]); + + log('Descriptor found!'); + log('> Descriptor characteristic: ' + descriptor.characteristic.uuid); + log('> Descriptor UUID: ' + descriptor.uuid); + descriptor.readValue(); + log('> Descriptor value: ' + asciiToDecimal(descriptor.value)); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_descriptors_test_cases.html b/tests/html/bluetooth/bluetooth_get_descriptors_test_cases.html new file mode 100644 index 00000000000..3c71e27267c --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_descriptors_test_cases.html @@ -0,0 +1,68 @@ +<!DOCTYPE html> +<html> +<title>GetDescriptors Test Cases</title> +<body> + <div id="buttons"></div> + <button onclick="onButtonClick2()">Test 12</button> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push('not_a_descriptor_name'); + //Test 2 + testCases.push('gatt.client_characteristic_configuration'); + //Test 3 + testCases.push('1234567891000-1000-8000-00805f9b34fb'); + //Test 4 + testCases.push('11'); + //Test 5 + testCases.push('12345678-1234-1234-1234-123456789abc'); + //Test 6 + testCases.push('00000000-0000-0000-0000-000000000000'); + //Test 7 + testCases.push(0x0000); + //Test 8 + testCases.push(0x00000000); + //Test 9 + testCases.push(0x2902); + //Test 10 + testCases.push(0x12345678); + //Test 11 + testCases.push(0x00002902); + //Test 12 + testCases.push(undefined); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "heart_rate"...'); + var primaryService = server.getPrimaryService('heart_rate'); + + log('Getting Characteristic "heart_rate_measurement"...'); + var characteristic = primaryService.getCharacteristic('heart_rate_measurement'); + + log('Getting Descriptors "' + testCases[testNumber] + '"...'); + var descriptors = characteristic.getDescriptors(testCases[testNumber]); + + for(i = 0; i < descriptors.length; ++i) { + log('> #' + (i+1)); + log('> UUID: ' + descriptors[i].uuid); + descriptors[i].readValue(); + log('> Descriptor value: ' + asciiToDecimal(descriptors[i].value)); + } + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_included_service_test_cases.html b/tests/html/bluetooth/bluetooth_get_included_service_test_cases.html new file mode 100644 index 00000000000..54e877546b5 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_included_service_test_cases.html @@ -0,0 +1,66 @@ +<!DOCTYPE html> +<html> +<title>GetIncludedService Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 'not_a_service_name', options: {filters: [{services: ['battery_service']}]} }); + //Test 2 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '1234567891000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 3 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '11', options: {filters: [{services: ['battery_service']}]} }); + //Test 4 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '12345678-1234-1234-1234-123456789abc', options: {filters: [{services: ['battery_service']}]} }); + //Test 5 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '00000000-0000-0000-0000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 6 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x0000, options: {filters: [{services: ['battery_service']}]} }); + //Test 7 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00000000, options: {filters: [{services: ['battery_service']}]} }); + //Test 8 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x12345678, options: {filters: [{services: ['battery_service']}]} }); + //Test 9 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x0000180f, options: {filters: [{services: ['battery_service']}]} }); + //Test 10 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '00001812-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 11 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 'f000ffc0-0451-4000-b000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 12 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '00001530-1212-efde-1523-785feabcd123', options: {filters: [{services: ['battery_service']}]} }); + //Test 13 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00001812, options: {filters: [{services: ['battery_service']}]} }); + //Test 14 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0xf000ffc0, options: {filters: [{services: ['battery_service']}]} }); + //Test 15 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00001530, options: {filters: [{services: ['battery_service']}]} }); + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...'); + var primaryService = server.getPrimaryService(testCases[testNumber].requestedService); + + log('Getting Included Service "' + testCases[testNumber].requestedIncludedService + '"...') + var includedService = primaryService.getIncludedService(testCases[testNumber].requestedIncludedService); + + log('Primary Service found on device: ' + includedService.device.name); + log('> UUID: ' + includedService.uuid); + log('> Is primary: ' + includedService.isPrimary); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_included_services_test_cases.html b/tests/html/bluetooth/bluetooth_get_included_services_test_cases.html new file mode 100644 index 00000000000..f0291469de7 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_included_services_test_cases.html @@ -0,0 +1,68 @@ +<!DOCTYPE html> +<html> +<title>GetIncludedServices Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 'not_a_service_name', options: {filters: [{services: ['battery_service']}]} }); + //Test 2 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '1234567891000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 3 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '11', options: {filters: [{services: ['battery_service']}]} }); + //Test 4 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '12345678-1234-1234-1234-123456789abc', options: {filters: [{services: ['battery_service']}]} }); + //Test 5 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '00000000-0000-0000-0000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 6 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x0000, options: {filters: [{services: ['battery_service']}]} }); + //Test 7 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00000000, options: {filters: [{services: ['battery_service']}]} }); + //Test 8 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x12345678, options: {filters: [{services: ['battery_service']}]} }); + //Test 9 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x0000180f, options: {filters: [{services: ['battery_service']}]} }); + //Test 10 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '00001812-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 11 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 'f000ffc0-0451-4000-b000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 12 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: '00001530-1212-efde-1523-785feabcd123', options: {filters: [{services: ['battery_service']}]} }); + //Test 13 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00001812, options: {filters: [{services: ['battery_service']}]} }); + //Test 14 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0xf000ffc0, options: {filters: [{services: ['battery_service']}]} }); + //Test 15 + testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00001530, options: {filters: [{services: ['battery_service']}]} }); + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...'); + var primaryService = server.getPrimaryService(testCases[testNumber].requestedService); + + log('Getting Included Service "' + testCases[testNumber].requestedIncludedService + '"...') + var includedServices = primaryService.getIncludedServices(testCases[testNumber].requestedIncludedService); + + for(i = 0; i < includedServices.length; ++i) { + log('> #' + (i+1)); + log('> UUID: ' + includedServices[i].uuid); + log('> Is primary: ' + includedServices[i].isPrimary); + } + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_primary_service_test_cases.html b/tests/html/bluetooth/bluetooth_get_primary_service_test_cases.html new file mode 100644 index 00000000000..160703754cf --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_primary_service_test_cases.html @@ -0,0 +1,74 @@ +<!DOCTYPE html> +<html> +<title>GetPrimaryService Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({ requestedService: 'heart_rate', options: {filters: [{services: ['battery_service']}]} }); + //Test 2 + testCases.push({ requestedService: 'heart_rate', options: {filters: [{services: ['battery_service', 'heart_rate']}]} }); + //Test 3 + testCases.push({ requestedService: 'not_a_service_name', options: {filters: [{services: ['battery_service']}]} }); + //Test 4 + testCases.push({ requestedService: 'battery_service', options: {filters: [{services: ['battery_service']}]} }); + //Test 5 + testCases.push({ requestedService: '1234567891000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 6 + testCases.push({ requestedService: '11', options: {filters: [{services: ['battery_service']}]} }); + //Test 7 + testCases.push({ requestedService: '12345678-1234-1234-1234-123456789abc', options: {filters: [{services: ['battery_service']}]} }); + //Test 8 + testCases.push({ requestedService: 0x0000, options: {filters: [{services: ['battery_service']}]} }); + //Test 9 + testCases.push({ requestedService: 0x00000000, options: {filters: [{services: ['battery_service']}]} }); + //Test 10 + testCases.push({ requestedService: 0x180f, options: {filters: [{services: ['battery_service']}]} }); + //Test 11 + testCases.push({ requestedService: 0x12345678, options: {filters: [{services: ['battery_service']}]} }); + //Test 12 + testCases.push({ requestedService: 0x0000180f, options: {filters: [{services: ['battery_service']}]} }); + //Test 13 + testCases.push({ requestedService: 0x00001812, options: {filters: [{services: ['battery_service']}]} }); + //Test 14 + testCases.push({ requestedService: 'f000ffc0-0451-4000-b000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 15 + testCases.push({ requestedService: '00001530-1212-efde-1523-785feabcd123', options: {filters: [{services: ['battery_service']}]} }); + //Test 16 + testCases.push({ requestedService: 0xf000ffc0, options: {filters: [{services: ['battery_service']}], optionalServices: [0xf000ffc0]} }); + //Test 17 + testCases.push({ requestedService: 0x00001530, options: {filters: [{services: ['battery_service']}], optionalServices: [0x00001530]} }); + //Test 18 + testCases.push({ requestedService: '0000180f-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 19 + testCases.push({ requestedService: 'cycling_power', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 20 + testCases.push({ requestedService: '00001818-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...'); + var primaryService = server.getPrimaryService(testCases[testNumber].requestedService); + + log('Primary Service found on device: ' + primaryService.device.name); + log('> UUID: ' + primaryService.uuid); + log('> Is primary: ' + primaryService.isPrimary); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_get_primary_services_test_cases.html b/tests/html/bluetooth/bluetooth_get_primary_services_test_cases.html new file mode 100644 index 00000000000..4a00c0efa32 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_get_primary_services_test_cases.html @@ -0,0 +1,75 @@ +<!DOCTYPE html> +<html> +<title>GetPrimaryServices Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({ requestedService: 'heart_rate', options: {filters: [{services: ['battery_service']}]} }); + //Test 2 + testCases.push({ requestedService: 'not_a_service_name', options: {filters: [{services: ['battery_service']}]} }); + //Test 3 + testCases.push({ requestedService: 'battery_service', options: {filters: [{services: ['battery_service']}]} }); + //Test 4 + testCases.push({ requestedService: '1234567891000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 5 + testCases.push({ requestedService: '11', options: {filters: [{services: ['battery_service']}]} }); + //Test 6 + testCases.push({ requestedService: '12345678-1234-1234-1234-123456789abc', options: {filters: [{services: ['battery_service']}]} }); + //Test 7 + testCases.push({ requestedService: '00000000-0000-0000-0000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 8 + testCases.push({ requestedService: 0x0000, options: {filters: [{services: ['battery_service']}]} }); + //Test 9 + testCases.push({ requestedService: 0x00000000, options: {filters: [{services: ['battery_service']}]} }); + //Test 10 + testCases.push({ requestedService: 0x180f, options: {filters: [{services: ['battery_service']}]} }); + //Test 11 + testCases.push({ requestedService: 0x12345678, options: {filters: [{services: ['battery_service']}]} }); + //Test 12 + testCases.push({ requestedService: 0x0000180f, options: {filters: [{services: ['battery_service']}]} }); + //Test 13 + testCases.push({ requestedService: 0x00001812, options: {filters: [{services: ['battery_service']}]} }); + //Test 14 + testCases.push({ requestedService: 'f000ffc0-0451-4000-b000-000000000000', options: {filters: [{services: ['battery_service']}]} }); + //Test 15 + testCases.push({ requestedService: '00001530-1212-efde-1523-785feabcd123', options: {filters: [{services: ['battery_service']}]} }); + //Test 16 + testCases.push({ requestedService: 0xf000ffc0, options: {filters: [{services: ['battery_service']}], optionalServices: [0xf000ffc0]} }); + //Test 17 + testCases.push({ requestedService: 0x00001530, options: {filters: [{services: ['battery_service']}], optionalServices: [0x00001530]} }); + //Test 18 + testCases.push({ requestedService: '0000180f-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}]} }); + //Test 19 + testCases.push({ requestedService: 'cycling_power', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + //Test 20 + testCases.push({ requestedService: '00001818-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} }); + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...'); + var primaryServices = server.getPrimaryServices(testCases[testNumber].requestedService); + + for(i = 0; i < primaryServices.length; ++i) { + log('> #' + (i+1)); + log('> UUID: ' + primaryServices[i].uuid); + log('> Is primary: ' + primaryServices[i].isPrimary); + } + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> diff --git a/tests/html/bluetooth_included_service_info.html b/tests/html/bluetooth/bluetooth_included_service_info.html index 76a351606b7..094ce5fd6a5 100644 --- a/tests/html/bluetooth_included_service_info.html +++ b/tests/html/bluetooth/bluetooth_included_service_info.html @@ -7,17 +7,18 @@ <input id="namePrefix" type="text" placeholder="Device Name Prefix"> <button type="button" onclick="onButtonClick()">Get Primary Service Info</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> function onButtonClick() { clear(); - var options = {filters: [], optinalServices: []}; + var options = {filters: [], optionalServices: []}; var filterService = document.getElementById('service').value; - if (filterService.startsWith('0x')) - filterService = parseInt(filterService, 16); - - if (filterService) + if (filterService) { + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); options.filters.push({services: [filterService]}); + } var filterName = document.getElementById('name').value; if (filterName) @@ -49,14 +50,6 @@ log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } </script> </body> </html> diff --git a/tests/html/bluetooth_primary_service_info.html b/tests/html/bluetooth/bluetooth_primary_service_info.html index 606d342c85d..3187400b00a 100644 --- a/tests/html/bluetooth_primary_service_info.html +++ b/tests/html/bluetooth/bluetooth_primary_service_info.html @@ -7,17 +7,18 @@ <input id="namePrefix" type="text" placeholder="Device Name Prefix"> <button type="button" onclick="onButtonClick()">Get Primary Service Info</button> <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> <script> function onButtonClick() { clear(); - var options = {filters: [], optinalServices: []}; + var options = {filters: [], optionalServices: []}; var filterService = document.getElementById('service').value; - if (filterService.startsWith('0x')) - filterService = parseInt(filterService, 16); - - if (filterService) + if (filterService) { + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); options.filters.push({services: [filterService]}); + } var filterName = document.getElementById('name').value; if (filterName) @@ -44,14 +45,6 @@ log(err); } } - - function clear() { - document.getElementById("log").textContent = ""; - } - - function log(line) { - document.getElementById("log").textContent += line + '\n'; - } </script> </body> </html> diff --git a/tests/html/bluetooth/bluetooth_primary_services_info.html b/tests/html/bluetooth/bluetooth_primary_services_info.html new file mode 100644 index 00000000000..cab413f8360 --- /dev/null +++ b/tests/html/bluetooth/bluetooth_primary_services_info.html @@ -0,0 +1,57 @@ +<!DOCTYPE html> +<html> +<title>Primary Services info</title> +<body> + <input id="service" type="text" autofocus placeholder="Bluetooth Service"> + <input id="name" type="text" placeholder="Device Name"> + <input id="namePrefix" type="text" placeholder="Device Name Prefix"> + <button type="button" onclick="onButtonClick()">Get Primary Services Info</button> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + function onButtonClick() { + clear(); + var options = {filters: [], optionalServices: []}; + + var filterService = document.getElementById('service').value; + if (filterService) { + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); + options.filters.push({services: [filterService]}); + } + + var filterName = document.getElementById('name').value; + if (filterName) + options.filters.push({name: filterName}); + + var filterNamePrefix = document.getElementById('namePrefix').value; + if (filterNamePrefix) + options.filters.push({namePrefix: filterNamePrefix}); + + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service...'); + var primaryServices; + if (filterService) { + primaryServices = server.getPrimaryServices(filterService); + } else { + primaryServices = server.getPrimaryServices(); + } + log('> List of Services on the current device:'); + for(i = 0; i < primaryServices.length; ++i) { + log('> #' + (i+1)); + log('> UUID: ' + primaryServices[i].uuid); + log('> Is primary: ' + primaryServices[i].isPrimary); + } + } catch(err) { + log(err); + } + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth/bluetooth_request_device_test_cases.html b/tests/html/bluetooth/bluetooth_request_device_test_cases.html new file mode 100644 index 00000000000..4e42fdeeeab --- /dev/null +++ b/tests/html/bluetooth/bluetooth_request_device_test_cases.html @@ -0,0 +1,73 @@ +<!DOCTYPE html> +<html> +<title>RequestDevice Test Cases</title> +<body> + <div id="buttons"></div> + <pre id="log"></pre> + <script src="bluetooth_functions.js"></script> + <script> + var testCases = []; + //Test 1 + testCases.push({filters: []}); + //Test 2 + testCases.push({filters: [{notExpectedMember: []}]}); + //Test 3 + testCases.push({filters: [{services: ['battery_service']}]}); + //Test 4 + testCases.push({filters: [{name: 'raspberrypi'}]}); + //Test 5 + testCases.push({filters: [{namePrefix: 'rasp'}]}); + //Test 6 + testCases.push({filters:[{services: []}]}); + //Test 7 + testCases.push({filters:[{services: [], namePrefix:'rasp'}]}); + //Test 8 + testCases.push({filters: [{services: ['not_a_service_name']}]}); + //Test 9 + testCases.push({filters: [{services: ['1234567891000-1000-8000-00805f9b34fb']}]}); + //Test 10 + testCases.push({filters: [{services: ['12345678-1234-1234-1234-123456789abc']}]}); + //Test 11 + testCases.push({filters: [{services: [0x0000]}]}); + //Test 12 + testCases.push({filters: [{services: [0x180f]}]}); + //Test 13 + testCases.push({filters: [{services: [0x12345678]}]}); + //Test 14 + testCases.push({filters: [{services: [0x00001812]}]}); + //Test 15 + testCases.push({filters: [{services: ['f000ffc0-0451-4000-b000-000000000000']}]}); + //Test 16 + testCases.push({filters: [{name: 'this_device_name_is_longer_than_29_bytes'}]}); + //Test 17 + testCases.push({filters: [{namePrefix: 'this_device_name_prefix_is_longer_than_29_bytes'}]}); + //Test 18 + testCases.push({filters: [{namePrefix: ''}]}); + //Test 19 + testCases.push({filters: [{namePrefix: 'rasp'}], optionalServices: ['1234567891000-1000-8000-00805f9b34fb']}); + //Test 20 + testCases.push({filters: [{namePrefix: 'rasp'}], optionalServices: ['12345678-1234-1234-1234-123456789abc']}); + //Test 21 + testCases.push({filters: [{namePrefix: 'rasp'}], optionalServices: ['f000ffc0-0451-4000-b000-000000000000', 0x1812]}); + + function onButtonClick(testNumber) { + clear(); + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(testCases[testNumber]); + + log('Found a device!'); + log('> Name: ' + device.name); + log('> Id: ' + device.id); + log('> Appearance: ' + device.adData.appearance); + log('> Tx Power: ' + device.adData.txPower + ' dBm'); + log('> RSSI: ' + device.adData.rssi + ' dBm'); + } catch(err) { + log(err); + } + } + + populate(testCases); + </script> +</body> +</html> |