Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring the WebBluetooth html tests.
- Loading branch information
Showing
23 changed files
with
1,112 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
tests/html/bluetooth/bluetooth_characteristic_read_value_test_cases.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
80 changes: 80 additions & 0 deletions
80
tests/html/bluetooth/bluetooth_characteristic_write_value_test_cases.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.