Bug 972730 - Avoid disabling BT before the BT adapter is initialized in marionette test. r=echou, f=vicamo

The current Bluetooth API can't allow user to disable BT before the BT
adapter is initialized.
In practice, We block the clicking event in gaia layer to prevent user
to turn off BT before BT enable procedure complete.
If we use marionette test to force emulator turn on and turn off BT in
a short period of time, it may crash emulator.

Listen to 'adapteradded' event rather than 'enabled' as the end of
BT enable to make sure we wouldn't disable BT when it's not ready.
This commit is contained in:
Jamin Liu 2014-03-03 10:20:24 -05:00
parent 18b8f5292d
commit 83f4d786be

View File

@ -11,14 +11,18 @@ function waitEitherEnabledOrDisabled() {
let deferred = Promise.defer();
function onEnabledDisabled(aEvent) {
bluetoothManager.removeEventListener("enabled", onEnabledDisabled);
bluetoothManager.removeEventListener("adapteradded", onEnabledDisabled);
bluetoothManager.removeEventListener("disabled", onEnabledDisabled);
ok(true, "Got event " + aEvent.type);
deferred.resolve(aEvent.type === "enabled");
deferred.resolve(aEvent.type === "adapteradded");
}
bluetoothManager.addEventListener("enabled", onEnabledDisabled);
// Listen 'adapteradded' rather than 'enabled' since the current API can't
// disable BT before the BT adapter is initialized.
// We should listen to 'enabled' when gecko can handle the case I mentioned
// above, please refer to the follow-up bug 973482.
bluetoothManager.addEventListener("adapteradded", onEnabledDisabled);
bluetoothManager.addEventListener("disabled", onEnabledDisabled);
return deferred.promise;
@ -39,7 +43,7 @@ function test(aEnabled) {
log(" Examine results " + JSON.stringify(aResults));
is(bluetoothManager.enabled, aEnabled, "bluetoothManager.enabled");
is(aResults[1], aEnabled, "'enabled' event received");
is(aResults[1], aEnabled, "'adapteradded' event received");
if (bluetoothManager.enabled === aEnabled && aResults[1] === aEnabled) {
deferred.resolve();