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: const AUDIO_MANAGER_CONTRACT_ID = "@mozilla.org/telephony/audiomanager;1"; michael@0: michael@0: // See nsIAudioManager michael@0: const PHONE_STATE_INVALID = -2; michael@0: const PHONE_STATE_CURRENT = -1; michael@0: const PHONE_STATE_NORMAL = 0; michael@0: const PHONE_STATE_RINGTONE = 1; michael@0: const PHONE_STATE_IN_CALL = 2; michael@0: const PHONE_STATE_IN_COMMUNICATION = 3; michael@0: michael@0: let audioManager; michael@0: function checkStates(speakerEnabled, phoneState) { michael@0: if (!audioManager) { michael@0: audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID] michael@0: .getService(SpecialPowers.Ci.nsIAudioManager); michael@0: ok(audioManager, "nsIAudioManager instance"); michael@0: } michael@0: michael@0: is(telephony.speakerEnabled, speakerEnabled, "telephony.speakerEnabled"); michael@0: if (phoneState == PHONE_STATE_CURRENT) { michael@0: ok(audioManager.phoneState === PHONE_STATE_CURRENT || michael@0: audioManager.phoneState === PHONE_STATE_NORMAL, "audioManager.phoneState"); michael@0: } else { michael@0: is(audioManager.phoneState, phoneState, "audioManager.phoneState"); michael@0: } michael@0: } michael@0: michael@0: function check(phoneStateOrig, phoneStateEnabled, phoneStateDisabled) { michael@0: checkStates(false, phoneStateOrig); michael@0: michael@0: let canEnableSpeaker = arguments.length > 1; michael@0: telephony.speakerEnabled = true; michael@0: if (canEnableSpeaker) { michael@0: checkStates(true, phoneStateEnabled); michael@0: } else { michael@0: checkStates(false, phoneStateOrig); michael@0: return; michael@0: } michael@0: michael@0: telephony.speakerEnabled = false; michael@0: checkStates(false, arguments.length > 2 ? phoneStateDisabled : phoneStateOrig); michael@0: } michael@0: michael@0: // Start the test michael@0: startTest(function() { michael@0: let outNumber = "5555550101"; michael@0: let inNumber = "5555550201"; michael@0: let outCall; michael@0: let inCall; michael@0: michael@0: Promise.resolve() michael@0: .then(() => check(PHONE_STATE_CURRENT, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) michael@0: michael@0: // Dial in michael@0: .then(() => gRemoteDial(inNumber)) michael@0: .then(call => { inCall = call; }) michael@0: // TODO - Bug 948860: should this be {RINGTONE, RINGTONE, RINGTONE}? michael@0: // From current UX spec, there is no chance that an user may enable speaker michael@0: // during alerting, so basically this 'set speaker enable' action can't michael@0: // happen in B2G. michael@0: .then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) michael@0: .then(() => gAnswer(inCall)) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: // Hang up all michael@0: .then(() => gRemoteHangUp(inCall)) michael@0: .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) michael@0: michael@0: // Dial out michael@0: .then(() => gDial(outNumber)) michael@0: .then(call => { outCall = call; }) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: .then(() => gRemoteAnswer(outCall)) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: // Hang up all michael@0: .then(() => gRemoteHangUp(outCall)) michael@0: .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) michael@0: michael@0: // Dial out michael@0: .then(() => gDial(outNumber)) michael@0: .then(call => { outCall = call; }) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: .then(() => gRemoteAnswer(outCall)) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: // Dial out and dial in michael@0: .then(() => gRemoteDial(inNumber)) michael@0: .then(call => { inCall = call; }) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: .then(() => gAnswer(inCall)) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: // Conference michael@0: .then(() => gAddCallsToConference([outCall, inCall])) michael@0: .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) michael@0: // Hang up all michael@0: .then(() => gRemoteHangUpCalls([outCall, inCall])) michael@0: .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) michael@0: michael@0: // End michael@0: .then(null, error => { michael@0: ok(false, 'promise rejects during test.'); michael@0: }) michael@0: .then(finish); michael@0: });