mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1035652 - Write a marionette test for verifying the discovery process based on bluetooth API v2. r=btian
This commit is contained in:
parent
84e7293c15
commit
884344269b
@ -561,6 +561,43 @@ function waitForAdapterAttributeChanged(aAdapter, aAttrName, aExpectedValue) {
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for specified number of 'devicefound' events.
|
||||
*
|
||||
* Resolve if specified number of devices has been found. Never reject.
|
||||
*
|
||||
* Fulfill params: an array which contains BluetoothDeviceEvents that we
|
||||
* received from the BluetoothDiscoveryHandle.
|
||||
*
|
||||
* @param aDiscoveryHandle
|
||||
* A BluetoothDiscoveryHandle which is used to notify application of
|
||||
* discovered remote bluetooth devices.
|
||||
* @param aExpectedNumberOfDevices
|
||||
* The number of remote devices we expect to discovery.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function waitForDevicesFound(aDiscoveryHandle, aExpectedNumberOfDevices) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
ok(aDiscoveryHandle instanceof BluetoothDiscoveryHandle,
|
||||
"discoveryHandle should be a BluetoothDiscoveryHandle");
|
||||
|
||||
let devicesArray = [];
|
||||
aDiscoveryHandle.ondevicefound = function onDeviceFound(aEvent) {
|
||||
ok(aEvent instanceof BluetoothDeviceEvent,
|
||||
"aEvent should be a BluetoothDeviceEvent");
|
||||
|
||||
devicesArray.push(aEvent);
|
||||
if (devicesArray.length >= aExpectedNumberOfDevices) {
|
||||
aDiscoveryHandle.ondevicefound = null;
|
||||
deferred.resolve(devicesArray);
|
||||
}
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush permission settings and call |finish()|.
|
||||
*/
|
||||
|
@ -6,3 +6,4 @@ qemu = false
|
||||
[test_dom_BluetoothManager_API2.js]
|
||||
[test_dom_BluetoothAdapter_enable_API2.js]
|
||||
[test_dom_BluetoothAdapter_setters_API2.js]
|
||||
[test_dom_BluetoothAdapter_discovery_API2.js]
|
||||
|
@ -0,0 +1,124 @@
|
||||
/* 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 the discovery process of BluetoothAdapter.
|
||||
// Testers have to put the B2G devices in an environment which is surrounded
|
||||
// by N discoverable remote devices. To pass this test, the number N has to be
|
||||
// greater or equals than EXPECTED_NUMBER_OF_REMOTE_DEVICES.
|
||||
//
|
||||
// Test Procedure:
|
||||
// [0] Set Bluetooth permission and enable default adapter.
|
||||
// [1] Start discovery and verify the correctness.
|
||||
// [2] Attach event handler for 'ondevicefound'.
|
||||
// [3] Stop discovery and verify the correctness.
|
||||
// [4] Mark the BluetoothDiscoveryHandle from [1] as expired.
|
||||
// [5] Start discovery and verify the correctness.
|
||||
// [6] Wait for 'devicefound' events.
|
||||
// [7] Stop discovery and verify the correctness.
|
||||
// [8] Call 'startDiscovery' twice continuously.
|
||||
// [9] Call 'stopDiscovery' twice continuously.
|
||||
// [10] Clean up the event handler of [2].
|
||||
//
|
||||
// Test Coverage:
|
||||
// - BluetoothAdapter.discovering
|
||||
// - BluetoothAdapter.startDiscovery()
|
||||
// - BluetoothAdapter.stopDiscovery()
|
||||
// - BluetoothAdapter.onattributechanged()
|
||||
// - BluetoothDiscoveryHandle.ondevicefound()
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const EXPECTED_NUMBER_OF_REMOTE_DEVICES = 2;
|
||||
|
||||
startBluetoothTest(true, function testCaseMain(aAdapter) {
|
||||
log("Checking adapter attributes ...");
|
||||
|
||||
is(aAdapter.state, "enabled", "adapter.state");
|
||||
isnot(aAdapter.address, "", "adapter.address");
|
||||
|
||||
// Since adapter has just been re-enabled, these properties should be 'false'.
|
||||
is(aAdapter.discovering, false, "adapter.discovering");
|
||||
is(aAdapter.discoverable, false, "adapter.discoverable");
|
||||
|
||||
log("adapter.address: " + aAdapter.address);
|
||||
log("adapter.name: " + aAdapter.name);
|
||||
|
||||
let discoveryHandle = null;
|
||||
return Promise.resolve()
|
||||
.then(function() {
|
||||
log("[1] Start discovery and verify the correctness ... ");
|
||||
let promises = [];
|
||||
promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", true));
|
||||
promises.push(aAdapter.startDiscovery());
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then(function(aResults) {
|
||||
log("[2] Attach event handler for 'ondevicefound' ... ");
|
||||
discoveryHandle = aResults[1];
|
||||
isHandleExpired = false;
|
||||
discoveryHandle.ondevicefound = function onDeviceFound(aEvent) {
|
||||
if (isHandleExpired) {
|
||||
ok(false, "Expired BluetoothDiscoveryHandle received an event.");
|
||||
}
|
||||
};
|
||||
})
|
||||
.then(function() {
|
||||
log("[3] Stop discovery and and verify the correctness ... ");
|
||||
let promises = [];
|
||||
if (aAdapter.discovering) {
|
||||
promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", false));
|
||||
}
|
||||
promises.push(aAdapter.stopDiscovery());
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then(function() {
|
||||
log("[4] Mark the BluetoothDiscoveryHandle from [1] as expired ... ");
|
||||
isHandleExpired = true;
|
||||
})
|
||||
.then(function() {
|
||||
log("[5] Start discovery and verify the correctness ... ");
|
||||
let promises = [];
|
||||
promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", true));
|
||||
promises.push(aAdapter.startDiscovery());
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then(function(aResults) {
|
||||
log("[6] Wait for 'devicefound' events ... ");
|
||||
return waitForDevicesFound(aResults[1], EXPECTED_NUMBER_OF_REMOTE_DEVICES);
|
||||
})
|
||||
.then(function() {
|
||||
log("[7] Stop discovery and and verify the correctness ... ");
|
||||
let promises = [];
|
||||
if (aAdapter.discovering) {
|
||||
promises.push(waitForAdapterAttributeChanged(aAdapter, "discovering", false));
|
||||
}
|
||||
promises.push(aAdapter.stopDiscovery());
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then(function() {
|
||||
log("[8] Call 'startDiscovery' twice continuously ... ");
|
||||
return aAdapter.startDiscovery()
|
||||
.then(() => aAdapter.startDiscovery())
|
||||
.then(() => ok(false, "Call startDiscovery() when adapter is discovering. - Fail"),
|
||||
() => ok(true, "Call startDiscovery() when adapter is discovering. - Success"));
|
||||
})
|
||||
.then(function() {
|
||||
log("[9] Call 'stopDiscovery' twice continuously ... ");
|
||||
return aAdapter.stopDiscovery()
|
||||
.then(() => aAdapter.stopDiscovery())
|
||||
.then(() => ok(true, "Call stopDiscovery() when adapter isn't discovering. - Success"),
|
||||
() => ok(false, "Call stopDiscovery() when adapter isn't discovering. - Fail"));
|
||||
})
|
||||
.then(function() {
|
||||
log("[10] Clean up the event handler of [2] ... ");
|
||||
if (discoveryHandle) {
|
||||
discoveryHandle.ondevicefound = null;
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user