mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 860697 - B2G Bluetooth: Add test cases to set/get properties of BluetoothAdapter. r=vyang, r=echou
This commit is contained in:
parent
9951077be9
commit
26e7826180
@ -4,11 +4,128 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://github.com/mozilla-b2g/platform_external_qemu/blob/master/vl-android.c#L765
|
||||
// static int bt_hci_parse(const char *str) {
|
||||
// ...
|
||||
// bdaddr.b[0] = 0x52;
|
||||
// bdaddr.b[1] = 0x54;
|
||||
// bdaddr.b[2] = 0x00;
|
||||
// bdaddr.b[3] = 0x12;
|
||||
// bdaddr.b[4] = 0x34;
|
||||
// bdaddr.b[5] = 0x56 + nb_hcis;
|
||||
const EMULATOR_ADDRESS = "56:34:12:00:54:52";
|
||||
|
||||
// $ adb shell hciconfig /dev/ttyS2 name
|
||||
// hci0: Type: BR/EDR Bus: UART
|
||||
// BD Address: 56:34:12:00:54:52 ACL MTU: 512:1 SCO MTU: 0:0
|
||||
// Name: 'Full Android on Emulator'
|
||||
const EMULATOR_NAME = "Full Android on Emulator";
|
||||
|
||||
// $ adb shell hciconfig /dev/ttyS2 class
|
||||
// hci0: Type: BR/EDR Bus: UART
|
||||
// BD Address: 56:34:12:00:54:52 ACL MTU: 512:1 SCO MTU: 0:0
|
||||
// Class: 0x58020c
|
||||
// Service Classes: Capturing, Object Transfer, Telephony
|
||||
// Device Class: Phone, Smart phone
|
||||
const EMULATOR_CLASS = 0x58020c;
|
||||
|
||||
// Use same definition in QEMU for special bluetooth address,
|
||||
// which were defined at external/qemu/hw/bt.h:
|
||||
const BDADDR_ANY = "00:00:00:00:00:00";
|
||||
const BDADDR_ALL = "ff:ff:ff:ff:ff:ff";
|
||||
const BDADDR_LOCAL = "ff:ff:ff:00:00:00";
|
||||
|
||||
let Promise =
|
||||
SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
|
||||
|
||||
let bluetoothManager;
|
||||
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
|
||||
/**
|
||||
* Send emulator command with safe guard.
|
||||
*
|
||||
* We should only call |finish()| after all emulator command transactions
|
||||
* end, so here comes with the pending counter. Resolve when the emulator
|
||||
* gives positive response, and reject otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function runEmulatorCmdSafe(aCommand) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
++pendingEmulatorCmdCount;
|
||||
runEmulatorCmd(aCommand, function(aResult) {
|
||||
--pendingEmulatorCmdCount;
|
||||
|
||||
ok(true, "Emulator response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult) && aResult[aResult.length - 1] === "OK") {
|
||||
deferred.resolve(aResult);
|
||||
} else {
|
||||
ok(false, "Got an abnormal response from emulator.");
|
||||
log("Fail to execute emulator command: [" + aCommand + "]");
|
||||
deferred.reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property for a Bluetooth device.
|
||||
*
|
||||
* Use QEMU command 'bt property <bd_addr> <prop_name> <value>' to set property.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @param aAddress
|
||||
* The string of Bluetooth address with format xx:xx:xx:xx:xx:xx.
|
||||
* @param aPropertyName
|
||||
* The property name of Bluetooth device.
|
||||
* @param aValue
|
||||
* The new value of the specifc property.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function setEmulatorDeviceProperty(aAddress, aPropertyName, aValue) {
|
||||
let cmd = "bt property " + aAddress + " " + aPropertyName + " " + aValue;
|
||||
return runEmulatorCmdSafe(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a property from a Bluetooth device.
|
||||
*
|
||||
* Use QEMU command 'bt property <bd_addr> <prop_name>' to get properties.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- a string with format <prop_name>: <value_of_prop>
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @param aAddress
|
||||
* The string of Bluetooth address with format xx:xx:xx:xx:xx:xx.
|
||||
* @param aPropertyName
|
||||
* The property name of Bluetooth device.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getEmulatorDeviceProperty(aAddress, aPropertyName) {
|
||||
let cmd = "bt property " + aAddress + " " + aPropertyName;
|
||||
return runEmulatorCmdSafe(cmd)
|
||||
.then(function(aResults) {
|
||||
return aResults[0];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mozSettings value specified by @aKey.
|
||||
*
|
||||
@ -163,6 +280,9 @@ function ensureBluetoothManager(aPermissions) {
|
||||
*
|
||||
* Fulfill params: the DOMEvent passed.
|
||||
*
|
||||
* @param aEventName
|
||||
* The name of the EventHandler.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function waitForManagerEvent(aEventName) {
|
||||
@ -178,6 +298,33 @@ function waitForManagerEvent(aEventName) {
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for one named BluetoothAdapter event.
|
||||
*
|
||||
* Resolve if that named event occurs. Never reject.
|
||||
*
|
||||
* Fulfill params: the DOMEvent passed.
|
||||
*
|
||||
* @param aAdapter
|
||||
* The BluetoothAdapter you want to use.
|
||||
* @param aEventName
|
||||
* The name of the EventHandler.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function waitForAdapterEvent(aAdapter, aEventName) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
aAdapter.addEventListener(aEventName, function onevent(aEvent) {
|
||||
aAdapter.removeEventListener(aEventName, onevent);
|
||||
|
||||
ok(true, "BluetoothAdapter event '" + aEventName + "' got.");
|
||||
deferred.resolve(aEvent);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient function for setBluetoothEnabled and waitForManagerEvent
|
||||
* combined.
|
||||
@ -249,11 +396,15 @@ function getDefaultAdapter() {
|
||||
* Flush permission settings and call |finish()|.
|
||||
*/
|
||||
function cleanUp() {
|
||||
SpecialPowers.flushPermissions(function() {
|
||||
// Use ok here so that we have at least one test run.
|
||||
ok(true, "permissions flushed");
|
||||
waitFor(function() {
|
||||
SpecialPowers.flushPermissions(function() {
|
||||
// Use ok here so that we have at least one test run.
|
||||
ok(true, "permissions flushed");
|
||||
|
||||
finish();
|
||||
finish();
|
||||
});
|
||||
}, function() {
|
||||
return pendingEmulatorCmdCount === 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -5,3 +5,5 @@ qemu = true
|
||||
|
||||
[test_dom_BluetoothManager_enabled.js]
|
||||
[test_dom_BluetoothManager_adapteradded.js]
|
||||
[test_dom_BluetoothAdapter_setters.js]
|
||||
[test_dom_BluetoothAdapter_getters.js]
|
||||
|
@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 et filetype=javascript
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test Purpose:
|
||||
// To verify that the properties of BluetoothAdapter can be updated and
|
||||
// retrieved correctly. Use B2G emulator commands to set properties for this
|
||||
// test case.
|
||||
//
|
||||
// Test Coverage:
|
||||
// - BluetoothAdapter.name
|
||||
// - BluetoothAdapter.address
|
||||
// - BluetoothAdapter.class
|
||||
// - BluetoothAdapter.discoverable
|
||||
// - BluetoothAdapter.discovering
|
||||
// ( P.S. Don't include [BluetoothAdapter.uuids], [BluetoothAdapter.devices] )
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
function testAdapterGetter(aAdapter, aPropertyName, aParamName, aExpected) {
|
||||
let cmd = "bt property " + BDADDR_LOCAL + " " + aParamName;
|
||||
return runEmulatorCmdSafe(cmd)
|
||||
.then(function(aResults) {
|
||||
is(aResults[1], "OK", "The status report from emulator command.");
|
||||
log(" Got adapter " + aResults[0]);
|
||||
is(aResults[0], aParamName + ": " + aExpected, "BluetoothAdapter." + aPropertyName);
|
||||
});
|
||||
}
|
||||
|
||||
startBluetoothTest(true, function testCaseMain(aAdapter) {
|
||||
log("Checking the correctness of BluetoothAdapter properties ...");
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => testAdapterGetter(aAdapter, "name", "name", aAdapter.name))
|
||||
.then(() => testAdapterGetter(aAdapter, "address", "address", aAdapter.address))
|
||||
.then(() => testAdapterGetter(aAdapter, "class", "cod", "0x" + aAdapter.class.toString(16)))
|
||||
.then(() => testAdapterGetter(aAdapter, "discoverable", "discoverable", aAdapter.discoverable.toString()))
|
||||
.then(() => testAdapterGetter(aAdapter, "discovering", "discovering", aAdapter.discovering.toString()));
|
||||
});
|
@ -0,0 +1,85 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=2 sts=2 et filetype=javascript
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test Purpose:
|
||||
// To verify that all setters of BluetoothAdapter (except for pairing related
|
||||
// APIs) can change properties correctly.
|
||||
//
|
||||
// Test Coverage:
|
||||
// - BluetoothAdapter.setName()
|
||||
// - BluetoothAdapter.setDiscoverable()
|
||||
// - BluetoothAdapter.setDiscoverableTimeout()
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const BT_DEVICE_NAME = "User friendly name of local BT device";
|
||||
|
||||
function setName(aAdapter, aName) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let request = aAdapter.setName(aName);
|
||||
request.onsuccess = function () {
|
||||
log(" setName succeed: " + aName);
|
||||
is(aAdapter.name, aName, "aAdapter.name");
|
||||
deferred.resolve();
|
||||
}
|
||||
request.onerror = function () {
|
||||
ok(false, "setName failed")
|
||||
deferred.reject();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function setDiscoverable(aAdapter, aIsDiscoverable) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let request = aAdapter.setDiscoverable(aIsDiscoverable);
|
||||
request.onsuccess = function () {
|
||||
log(" setDiscoverable succeed: " + aIsDiscoverable);
|
||||
is(aAdapter.discoverable, aIsDiscoverable, "aAdapter.discoverable");
|
||||
deferred.resolve();
|
||||
}
|
||||
request.onerror = function () {
|
||||
ok(false, "setDiscoverable failed")
|
||||
deferred.reject();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function setDiscoverableTimeout(aAdapter, aTimeout) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let request = aAdapter.setDiscoverableTimeout(aTimeout);
|
||||
request.onsuccess = function () {
|
||||
log(" setDiscoverableTimeout succeed: " + aTimeout);
|
||||
is(aAdapter.discoverableTimeout, aTimeout, "aAdapter.discoverableTimeout");
|
||||
deferred.resolve();
|
||||
}
|
||||
request.onerror = function () {
|
||||
ok(false, "setDiscoverableTimeout failed")
|
||||
deferred.reject();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
startBluetoothTest(true, function testCaseMain(aAdapter) {
|
||||
log("Testing BluetoothAdapter setters ...");
|
||||
|
||||
return Promise.resolve()
|
||||
.then( () => setName(aAdapter, BT_DEVICE_NAME) )
|
||||
.then( () => setDiscoverableTimeout(aAdapter, 180) )
|
||||
.then( () => setDiscoverable(aAdapter, true) )
|
||||
.then( () => setName(aAdapter, EMULATOR_NAME) )
|
||||
.then( () => setDiscoverable(aAdapter, false) )
|
||||
.then( () => setDiscoverableTimeout(aAdapter, 120) );
|
||||
});
|
@ -7,31 +7,6 @@
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
// https://github.com/mozilla-b2g/platform_external_qemu/blob/master/vl-android.c#L765
|
||||
// static int bt_hci_parse(const char *str) {
|
||||
// ...
|
||||
// bdaddr.b[0] = 0x52;
|
||||
// bdaddr.b[1] = 0x54;
|
||||
// bdaddr.b[2] = 0x00;
|
||||
// bdaddr.b[3] = 0x12;
|
||||
// bdaddr.b[4] = 0x34;
|
||||
// bdaddr.b[5] = 0x56 + nb_hcis;
|
||||
const EMULATOR_ADDRESS = "56:34:12:00:54:52";
|
||||
|
||||
// $ adb shell hciconfig /dev/ttyS2 name
|
||||
// hci0: Type: BR/EDR Bus: UART
|
||||
// BD Address: 56:34:12:00:54:52 ACL MTU: 512:1 SCO MTU: 0:0
|
||||
// Name: 'Full Android on Emulator'
|
||||
const EMULATOR_NAME = "Full Android on Emulator";
|
||||
|
||||
// $ adb shell hciconfig /dev/ttyS2 class
|
||||
// hci0: Type: BR/EDR Bus: UART
|
||||
// BD Address: 56:34:12:00:54:52 ACL MTU: 512:1 SCO MTU: 0:0
|
||||
// Class: 0x58020c
|
||||
// Service Classes: Capturing, Object Transfer, Telephony
|
||||
// Device Class: Phone, Smart phone
|
||||
const EMULATOR_CLASS = 0x58020c;
|
||||
|
||||
startBluetoothTest(true, function testCaseMain(aAdapter) {
|
||||
log("Checking adapter attributes ...");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user