2013-12-13 11:31:16 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
MARIONETTE_TIMEOUT = 60000;
|
|
|
|
MARIONETTE_HEAD_JS = 'head.js';
|
|
|
|
|
2014-02-10 08:03:43 +04:00
|
|
|
function waitEitherEnabledOrDisabled() {
|
|
|
|
let deferred = Promise.defer();
|
|
|
|
|
|
|
|
function onEnabledDisabled(aEvent) {
|
2014-03-03 19:20:24 +04:00
|
|
|
bluetoothManager.removeEventListener("adapteradded", onEnabledDisabled);
|
2014-02-10 08:03:43 +04:00
|
|
|
bluetoothManager.removeEventListener("disabled", onEnabledDisabled);
|
|
|
|
|
|
|
|
ok(true, "Got event " + aEvent.type);
|
2014-03-03 19:20:24 +04:00
|
|
|
deferred.resolve(aEvent.type === "adapteradded");
|
2014-02-10 08:03:43 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 19:20:24 +04:00
|
|
|
// 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);
|
2014-02-10 08:03:43 +04:00
|
|
|
bluetoothManager.addEventListener("disabled", onEnabledDisabled);
|
2013-12-13 11:31:16 +04:00
|
|
|
|
2014-02-10 08:03:43 +04:00
|
|
|
return deferred.promise;
|
2013-12-13 11:31:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function test(aEnabled) {
|
|
|
|
log("Testing 'bluetooth.enabled' => " + aEnabled);
|
|
|
|
|
|
|
|
let deferred = Promise.defer();
|
|
|
|
|
2014-02-10 08:03:43 +04:00
|
|
|
Promise.all([setBluetoothEnabled(aEnabled),
|
|
|
|
waitEitherEnabledOrDisabled()])
|
|
|
|
.then(function(aResults) {
|
|
|
|
/* aResults is an array of two elements:
|
|
|
|
* [ <result of setBluetoothEnabled>,
|
|
|
|
* <result of waitEitherEnabledOrDisabled> ]
|
|
|
|
*/
|
|
|
|
log(" Examine results " + JSON.stringify(aResults));
|
2013-12-13 11:31:16 +04:00
|
|
|
|
|
|
|
is(bluetoothManager.enabled, aEnabled, "bluetoothManager.enabled");
|
2014-03-03 19:20:24 +04:00
|
|
|
is(aResults[1], aEnabled, "'adapteradded' event received");
|
2013-12-13 11:31:16 +04:00
|
|
|
|
2014-02-10 08:03:43 +04:00
|
|
|
if (bluetoothManager.enabled === aEnabled && aResults[1] === aEnabled) {
|
2013-12-13 11:31:16 +04:00
|
|
|
deferred.resolve();
|
|
|
|
} else {
|
|
|
|
deferred.reject();
|
|
|
|
}
|
2014-02-10 08:03:43 +04:00
|
|
|
});
|
2013-12-13 11:31:16 +04:00
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
startBluetoothTestBase(["settings-read", "settings-write"],
|
|
|
|
function testCaseMain() {
|
|
|
|
return getBluetoothEnabled()
|
|
|
|
.then(function(aEnabled) {
|
|
|
|
log("Original 'bluetooth.enabled' is " + aEnabled);
|
|
|
|
// Set to !aEnabled and reset back to aEnabled.
|
|
|
|
return test(!aEnabled).then(test.bind(null, aEnabled));
|
|
|
|
});
|
|
|
|
});
|