blob: 55df78e75f69c118cca1049fe0980fac20660b29 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/bluetooth-helpers.js"></script>
<script>
'use strict';
test(t => { assert_true(window.testRunner instanceof Object); t.done(); },
'window.testRunner is required for the following tests.');
// Tests that we are handling values returned from the underlying platform
// correctly. Only meant to be used by chromium.
[{
name: 'Tx Power too low must result in nulled txPower.',
tx_power: -128,
expected_tx_power: null,
rssi: 0,
expected_rssi: 0
}, {
name: 'RSSI too low must result in nulled rssi.',
tx_power: 0,
expected_tx_power: 0,
rssi: -128,
expected_rssi: null
}, {
name: 'Low Tx Power should appear in adData.',
tx_power: -127,
expected_tx_power: -127,
rssi: 0,
expected_rssi: 0
}, {
name: 'Low RSSI should appear in adData.',
tx_power: 0,
expected_tx_power: 0,
rssi: -127,
expected_rssi: -127
}, {
name: 'High Tx Power should appear in adData.',
// TODO(ortuno): According to the Bluetooth Spec Supplement, 127 is the
// the hightest possible valid value for Tx Power. Change to 127 when
// fixed: http://crbug.com/551572
tx_power: 126,
expected_tx_power: 126,
rssi: 0,
expected_rssi: 0
}, {
name: 'High RSSI should appear in adData.',
tx_power: 0,
expected_tx_power: 0,
rssi: 126,
expected_rssi: 126
}, {
// TODO(ortuno): Remove this test since 127 is both a valid Tx Power
// and the max value of a int8.
// http://crbug.com/551572
name: 'Tx Power too high must result in nulled txPower.',
tx_power: 127,
expected_tx_power: null,
rssi: 0,
expected_rssi: 0
}, {
name: 'RSSI too high must result in nulled rssi.',
tx_power: 0,
expected_tx_power: 0,
rssi: 127,
expected_rssi: null
}].forEach(power_test => {
promise_test(() => {
testRunner.setBluetoothMockDataSet('PowerValueAdapter:' +
power_test.tx_power + ':' +
power_test.rssi);
return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
.then(device => {
let adv_data = device.adData;
assert_equals(adv_data.txPower, power_test.expected_tx_power);
assert_equals(adv_data.rssi, power_test.expected_rssi);
});
}, power_test.name);
});
// Tests for all platforms.
[{
name: 'TxPower not present, RSSI not present.',
tx_power_present: false,
rssi_present: false
}, {
name: 'TxPower not present, RSSI present.',
tx_power_present: false,
rssi_present: true
}, {
name: 'TxPower present, RSSI not present.',
tx_power_present: true,
rssi_present: false,
}, {
name: 'TxPower present, RSSI present.',
tx_power_present: true,
rssi_present: true
}].forEach(power_test => {
promise_test(() => {
testRunner.setBluetoothMockDataSet('PowerPresenceAdapter:' +
power_test.tx_power_present + ':' +
power_test.rssi_present);
return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
.then(device => {
let adv_data = device.adData;
let expected_tx_power = power_test.tx_power_present ?
-10 /* broadcasting at 0.1mW */
: null;
let expected_rssi = power_test.rssi_present ?
-51 /* power at 1m from device broadcasting at 0.1mW */
: null;
assert_equals(adv_data.txPower, expected_tx_power);
assert_equals(adv_data.rssi, expected_rssi);
});
}, power_test.name)
});
</script>