From c1c5575e481a26afc2bbfa95ed9578e9deca5442 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Fri, 23 Jan 2015 12:23:43 +0800 Subject: [PATCH] Bug 1124732 - Make test_outgoing_radio_off.js supporting running on emulator-kk. r=aknow --- .../marionette/test_outgoing_radio_off.js | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/dom/telephony/test/marionette/test_outgoing_radio_off.js b/dom/telephony/test/marionette/test_outgoing_radio_off.js index 506745e819ba..4053839617cb 100644 --- a/dom/telephony/test/marionette/test_outgoing_radio_off.js +++ b/dom/telephony/test/marionette/test_outgoing_radio_off.js @@ -4,13 +4,27 @@ MARIONETTE_TIMEOUT = 60000; MARIONETTE_HEAD_JS = 'head.js'; -let connection; 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 gSetRadioEnabled(connection, false) + return setRadioEnabledAll(false) .then(() => gDial(normalNumber)) .catch(cause => { is(cause, "RadioNotAvailable"); @@ -19,7 +33,7 @@ function testDial_NormalNumber() { } function testDial_EmergencyNumber() { - return gSetRadioEnabled(connection, false) + return setRadioEnabledAll(false) .then(() => gDial(emergencyNumber)) .then(call => { outCall = call; }) .then(() => gRemoteAnswer(outCall)) @@ -28,7 +42,7 @@ function testDial_EmergencyNumber() { } function testDialEmergency_NormalNumber() { - return gSetRadioEnabled(connection, false) + return setRadioEnabledAll(false) .then(() => gDialEmergency(normalNumber)) .catch(cause => { is(cause, "RadioNotAvailable"); @@ -37,7 +51,7 @@ function testDialEmergency_NormalNumber() { } function testDialEmergency_EmergencyNumber() { - return gSetRadioEnabled(connection, false) + return setRadioEnabledAll(false) .then(() => gDialEmergency(emergencyNumber)) .then(call => { outCall = call; }) .then(() => gRemoteAnswer(outCall)) @@ -46,16 +60,12 @@ function testDialEmergency_EmergencyNumber() { } startTestWithPermissions(['mobileconnection'], function() { - connection = navigator.mozMobileConnections[0]; - ok(connection instanceof MozMobileConnection, - "connection is instanceof " + connection.constructor); - Promise.resolve() .then(() => testDial_NormalNumber()) .then(() => testDial_EmergencyNumber()) .then(() => testDialEmergency_NormalNumber()) .then(() => testDialEmergency_EmergencyNumber()) - .then(() => gSetRadioEnabled(connection, true)) + .then(() => setRadioEnabledAll(true)) .catch(error => ok(false, "Promise reject: " + error)) .then(finish); });