michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 60000; michael@0: MARIONETTE_HEAD_JS = 'head.js'; michael@0: michael@0: let connection; michael@0: michael@0: function setRadioEnabled(enabled, callback) { michael@0: let request = connection.setRadioEnabled(enabled); michael@0: let desiredRadioState = enabled ? 'enabled' : 'disabled'; michael@0: michael@0: let pending = ['onradiostatechange', 'onsuccess']; michael@0: let done = callback; michael@0: michael@0: connection.onradiostatechange = function() { michael@0: let state = connection.radioState; michael@0: log("Received 'radiostatechange' event, radioState: " + state); michael@0: michael@0: if (state == desiredRadioState) { michael@0: gReceivedPending('onradiostatechange', pending, done); michael@0: } michael@0: }; michael@0: michael@0: request.onsuccess = function onsuccess() { michael@0: gReceivedPending('onsuccess', pending, done); michael@0: }; michael@0: michael@0: request.onerror = function onerror() { michael@0: ok(false, "setRadioEnabled should be ok"); michael@0: }; michael@0: } michael@0: michael@0: function dial(number) { michael@0: // Verify initial state before dial. michael@0: ok(telephony); michael@0: is(telephony.active, null); michael@0: ok(telephony.calls); michael@0: is(telephony.calls.length, 0); michael@0: michael@0: log("Make an outgoing call."); michael@0: michael@0: telephony.dial(number).then(null, cause => { michael@0: log("Received promise 'reject'"); michael@0: michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: is(cause, "RadioNotAvailable"); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Initial call list: " + result); michael@0: is(result[0], "OK"); michael@0: michael@0: setRadioEnabled(true, cleanUp); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: finish(); michael@0: } michael@0: michael@0: startTestWithPermissions(['mobileconnection'], function() { michael@0: connection = navigator.mozMobileConnections[0]; michael@0: ok(connection instanceof MozMobileConnection, michael@0: "connection is instanceof " + connection.constructor); michael@0: michael@0: setRadioEnabled(false, function() { michael@0: dial("0912345678"); michael@0: }); michael@0: });