dom/telephony/test/marionette/test_audiomanager_phonestate.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 60000;
michael@0 5 MARIONETTE_HEAD_JS = 'head.js';
michael@0 6
michael@0 7 const AUDIO_MANAGER_CONTRACT_ID = "@mozilla.org/telephony/audiomanager;1";
michael@0 8
michael@0 9 // See nsIAudioManager
michael@0 10 const PHONE_STATE_INVALID = -2;
michael@0 11 const PHONE_STATE_CURRENT = -1;
michael@0 12 const PHONE_STATE_NORMAL = 0;
michael@0 13 const PHONE_STATE_RINGTONE = 1;
michael@0 14 const PHONE_STATE_IN_CALL = 2;
michael@0 15 const PHONE_STATE_IN_COMMUNICATION = 3;
michael@0 16
michael@0 17 let audioManager;
michael@0 18 function checkStates(speakerEnabled, phoneState) {
michael@0 19 if (!audioManager) {
michael@0 20 audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID]
michael@0 21 .getService(SpecialPowers.Ci.nsIAudioManager);
michael@0 22 ok(audioManager, "nsIAudioManager instance");
michael@0 23 }
michael@0 24
michael@0 25 is(telephony.speakerEnabled, speakerEnabled, "telephony.speakerEnabled");
michael@0 26 if (phoneState == PHONE_STATE_CURRENT) {
michael@0 27 ok(audioManager.phoneState === PHONE_STATE_CURRENT ||
michael@0 28 audioManager.phoneState === PHONE_STATE_NORMAL, "audioManager.phoneState");
michael@0 29 } else {
michael@0 30 is(audioManager.phoneState, phoneState, "audioManager.phoneState");
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 function check(phoneStateOrig, phoneStateEnabled, phoneStateDisabled) {
michael@0 35 checkStates(false, phoneStateOrig);
michael@0 36
michael@0 37 let canEnableSpeaker = arguments.length > 1;
michael@0 38 telephony.speakerEnabled = true;
michael@0 39 if (canEnableSpeaker) {
michael@0 40 checkStates(true, phoneStateEnabled);
michael@0 41 } else {
michael@0 42 checkStates(false, phoneStateOrig);
michael@0 43 return;
michael@0 44 }
michael@0 45
michael@0 46 telephony.speakerEnabled = false;
michael@0 47 checkStates(false, arguments.length > 2 ? phoneStateDisabled : phoneStateOrig);
michael@0 48 }
michael@0 49
michael@0 50 // Start the test
michael@0 51 startTest(function() {
michael@0 52 let outNumber = "5555550101";
michael@0 53 let inNumber = "5555550201";
michael@0 54 let outCall;
michael@0 55 let inCall;
michael@0 56
michael@0 57 Promise.resolve()
michael@0 58 .then(() => check(PHONE_STATE_CURRENT, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
michael@0 59
michael@0 60 // Dial in
michael@0 61 .then(() => gRemoteDial(inNumber))
michael@0 62 .then(call => { inCall = call; })
michael@0 63 // TODO - Bug 948860: should this be {RINGTONE, RINGTONE, RINGTONE}?
michael@0 64 // From current UX spec, there is no chance that an user may enable speaker
michael@0 65 // during alerting, so basically this 'set speaker enable' action can't
michael@0 66 // happen in B2G.
michael@0 67 .then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
michael@0 68 .then(() => gAnswer(inCall))
michael@0 69 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 70 // Hang up all
michael@0 71 .then(() => gRemoteHangUp(inCall))
michael@0 72 .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
michael@0 73
michael@0 74 // Dial out
michael@0 75 .then(() => gDial(outNumber))
michael@0 76 .then(call => { outCall = call; })
michael@0 77 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 78 .then(() => gRemoteAnswer(outCall))
michael@0 79 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 80 // Hang up all
michael@0 81 .then(() => gRemoteHangUp(outCall))
michael@0 82 .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
michael@0 83
michael@0 84 // Dial out
michael@0 85 .then(() => gDial(outNumber))
michael@0 86 .then(call => { outCall = call; })
michael@0 87 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 88 .then(() => gRemoteAnswer(outCall))
michael@0 89 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 90 // Dial out and dial in
michael@0 91 .then(() => gRemoteDial(inNumber))
michael@0 92 .then(call => { inCall = call; })
michael@0 93 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 94 .then(() => gAnswer(inCall))
michael@0 95 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 96 // Conference
michael@0 97 .then(() => gAddCallsToConference([outCall, inCall]))
michael@0 98 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
michael@0 99 // Hang up all
michael@0 100 .then(() => gRemoteHangUpCalls([outCall, inCall]))
michael@0 101 .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
michael@0 102
michael@0 103 // End
michael@0 104 .then(null, error => {
michael@0 105 ok(false, 'promise rejects during test.');
michael@0 106 })
michael@0 107 .then(finish);
michael@0 108 });

mercurial