diff --git a/dom/telephony/test/marionette/head.js b/dom/telephony/test/marionette/head.js index 0bf7972c46f..27b5166fbfd 100644 --- a/dom/telephony/test/marionette/head.js +++ b/dom/telephony/test/marionette/head.js @@ -167,7 +167,7 @@ let emulator = (function() { } else { return waitForEvent(aTarget, "callschanged", event => event.call == aExpectedCall) - .then(event => event.call) + .then(event => event.call); } } @@ -1053,6 +1053,21 @@ let emulator = (function() { return Promise.all(promises); } + function setRadioEnabledAll(enabled) { + let promises = []; + let numOfSim = navigator.mozMobileConnections.length; + + for (let i = 0; i < numOfSim; i++) { + let connection = navigator.mozMobileConnections[i]; + ok(connection instanceof MozMobileConnection, + "connection[" + i + "] is instanceof " + connection.constructor); + + promises.push(setRadioEnabled(connection, enabled)); + } + + return Promise.all(promises); + } + /** * Public members. */ @@ -1087,21 +1102,38 @@ let emulator = (function() { this.gHangUpConference = hangUpConference; this.gSetupConference = setupConference; this.gSetRadioEnabled = setRadioEnabled; + this.gSetRadioEnabledAll = setRadioEnabledAll; }()); function _startTest(permissions, test) { - function permissionSetUp() { - SpecialPowers.setBoolPref("dom.mozSettings.enabled", true); - for (let per of permissions) { - SpecialPowers.addPermission(per, true, document); - } + function typesToPermissions(types) { + return types.map(type => { + return { + "type": type, + "allow": 1, + "context": document + }; + }); } - function permissionTearDown() { - SpecialPowers.clearUserPref("dom.mozSettings.enabled"); - for (let per of permissions) { - SpecialPowers.removePermission(per, document); - } + function ensureRadio() { + log("== Ensure Radio =="); + return new Promise(function(resolve, reject) { + SpecialPowers.pushPermissions(typesToPermissions(["mobileconnection"]), () => { + gSetRadioEnabledAll(true).then(() => { + SpecialPowers.popPermissions(() => { + resolve(); + }); + }); + }); + }); + } + + function permissionSetUp() { + log("== Permission SetUp =="); + return new Promise(function(resolve, reject) { + SpecialPowers.pushPermissions(typesToPermissions(permissions), resolve); + }); } let debugPref; @@ -1114,14 +1146,18 @@ function _startTest(permissions, test) { SpecialPowers.setBoolPref(kPrefRilDebuggingEnabled, true); log("Set debugging pref: " + debugPref + " => true"); - permissionSetUp(); - - // Make sure that we get the telephony after adding permission. - telephony = window.navigator.mozTelephony; - ok(telephony); - conference = telephony.conferenceGroup; - ok(conference); - return gClearCalls().then(gCheckInitialState); + return Promise.resolve() + .then(ensureRadio) + .then(permissionSetUp) + .then(() => { + // Make sure that we get the telephony after adding permission. + telephony = window.navigator.mozTelephony; + ok(telephony); + conference = telephony.conferenceGroup; + ok(conference); + }) + .then(gClearCalls) + .then(gCheckInitialState); } // Extend finish() with tear down. @@ -1132,8 +1168,6 @@ function _startTest(permissions, test) { log("== Test TearDown =="); emulator.waitFinish() .then(() => { - permissionTearDown(); - // Restore debugging pref. SpecialPowers.setBoolPref(kPrefRilDebuggingEnabled, debugPref); log("Set debugging pref: true => " + debugPref); diff --git a/dom/telephony/test/marionette/test_outgoing_radio_off.js b/dom/telephony/test/marionette/test_outgoing_radio_off.js index a4a6bc15050..fbca4f7929d 100644 --- a/dom/telephony/test/marionette/test_outgoing_radio_off.js +++ b/dom/telephony/test/marionette/test_outgoing_radio_off.js @@ -8,23 +8,8 @@ const normalNumber = "0912345678"; const emergencyNumber = "112"; let outCall; -function setRadioEnabledAll(enabled) { - let promises = []; - let numOfSim = navigator.mozMobileConnections.length; - - for (let i = 0; i < numOfSim; i++) { - let connection = navigator.mozMobileConnections[i]; - ok(connection instanceof MozMobileConnection, - "connection[" + i + "] is instanceof " + connection.constructor); - - promises.push(gSetRadioEnabled(connection, enabled)); - } - - return Promise.all(promises); -} - function testDial_NormalNumber() { - return setRadioEnabledAll(false) + return gSetRadioEnabledAll(false) .then(() => gDial(normalNumber)) .catch(cause => { is(cause, "RadioNotAvailable"); @@ -33,7 +18,7 @@ function testDial_NormalNumber() { } function testDial_EmergencyNumber() { - return setRadioEnabledAll(false) + return gSetRadioEnabledAll(false) .then(() => gDial(emergencyNumber)) .then(call => { outCall = call; }) .then(() => gRemoteAnswer(outCall)) @@ -42,7 +27,7 @@ function testDial_EmergencyNumber() { } function testDialEmergency_NormalNumber() { - return setRadioEnabledAll(false) + return gSetRadioEnabledAll(false) .then(() => gDialEmergency(normalNumber)) .catch(cause => { is(cause, "RadioNotAvailable"); @@ -51,7 +36,7 @@ function testDialEmergency_NormalNumber() { } function testDialEmergency_EmergencyNumber() { - return setRadioEnabledAll(false) + return gSetRadioEnabledAll(false) .then(() => gDialEmergency(emergencyNumber)) .then(call => { outCall = call; }) .then(() => gRemoteAnswer(outCall)) @@ -66,7 +51,7 @@ startTestWithPermissions(['mobileconnection'], function() { .then(() => testDialEmergency_NormalNumber()) .then(() => testDialEmergency_EmergencyNumber()) .catch(error => ok(false, "Promise reject: " + error)) - .then(() => setRadioEnabledAll(true)) + .then(() => gSetRadioEnabledAll(true)) .catch(error => ok(false, "Promise reject: " + error)) .then(finish); });