From ae1bbf33594d88256a7fb7b99e2013cf1e81c9cf Mon Sep 17 00:00:00 2001 From: "Szu-Yu Chen [:aknow]" Date: Tue, 4 Nov 2014 15:44:14 +0800 Subject: [PATCH] Bug 1091551 - Part 2: Correct test case. r=hsinyi 1. Speaker setting should not affect audio state 2. Use waitFor to check the phoneState change 3. Remove duplicated test case --- dom/telephony/test/marionette/manifest.ini | 1 - .../test_audiomanager_phonestate.js | 72 ++++++++----------- .../test_incomingcall_phonestate_speaker.js | 66 ----------------- 3 files changed, 30 insertions(+), 109 deletions(-) delete mode 100644 dom/telephony/test/marionette/test_incomingcall_phonestate_speaker.js diff --git a/dom/telephony/test/marionette/manifest.ini b/dom/telephony/test/marionette/manifest.ini index 62667106234..22672b67335 100644 --- a/dom/telephony/test/marionette/manifest.ini +++ b/dom/telephony/test/marionette/manifest.ini @@ -61,7 +61,6 @@ disabled = Bug 821958 [test_conference_add_twice_error.js] [test_outgoing_when_two_calls_on_line.js] [test_call_presentation.js] -[test_incomingcall_phonestate_speaker.js] [test_temporary_clir.js] [test_outgoing_error_state.js] [test_outgoing_auto_hold.js] diff --git a/dom/telephony/test/marionette/test_audiomanager_phonestate.js b/dom/telephony/test/marionette/test_audiomanager_phonestate.js index a582bc90ad9..ce62399df9c 100644 --- a/dom/telephony/test/marionette/test_audiomanager_phonestate.js +++ b/dom/telephony/test/marionette/test_audiomanager_phonestate.js @@ -14,37 +14,25 @@ const PHONE_STATE_RINGTONE = 1; const PHONE_STATE_IN_CALL = 2; const PHONE_STATE_IN_COMMUNICATION = 3; -let audioManager; -function checkStates(speakerEnabled, phoneState) { - if (!audioManager) { - audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID] +let audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID] .getService(SpecialPowers.Ci.nsIAudioManager); - ok(audioManager, "nsIAudioManager instance"); - } - is(telephony.speakerEnabled, speakerEnabled, "telephony.speakerEnabled"); - if (phoneState == PHONE_STATE_CURRENT) { - ok(audioManager.phoneState === PHONE_STATE_CURRENT || - audioManager.phoneState === PHONE_STATE_NORMAL, "audioManager.phoneState"); - } else { - is(audioManager.phoneState, phoneState, "audioManager.phoneState"); - } -} +ok(audioManager, "nsIAudioManager instance"); -function check(phoneStateOrig, phoneStateEnabled, phoneStateDisabled) { - checkStates(false, phoneStateOrig); +function check(phoneState) { + return new Promise(function(resolve, reject) { + waitFor(function() { + resolve(); + }, function() { + let currentPhoneState = audioManager.phoneState; + log("waiting.. audioState should change to " + phoneState + + ", current is" + currentPhoneState); - let canEnableSpeaker = arguments.length > 1; - telephony.speakerEnabled = true; - if (canEnableSpeaker) { - checkStates(true, phoneStateEnabled); - } else { - checkStates(false, phoneStateOrig); - return; - } - - telephony.speakerEnabled = false; - checkStates(false, arguments.length > 2 ? phoneStateDisabled : phoneStateOrig); + return (phoneState == currentPhoneState || + (phoneState == PHONE_STATE_CURRENT && + currentPhoneState == PHONE_STATE_NORMAL)); + }); + }); } // Start the test @@ -55,50 +43,50 @@ startTest(function() { let inCall; Promise.resolve() - .then(() => check(PHONE_STATE_CURRENT, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) + .then(() => check(PHONE_STATE_CURRENT)) // Dial in .then(() => gRemoteDial(inNumber)) .then(call => { inCall = call; }) - .then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE)) + .then(() => check(PHONE_STATE_RINGTONE)) .then(() => gAnswer(inCall)) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) // Hang up all .then(() => gRemoteHangUp(inCall)) - .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) + .then(() => check(PHONE_STATE_NORMAL)) // Dial out .then(() => gDial(outNumber)) .then(call => { outCall = call; }) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) .then(() => gRemoteAnswer(outCall)) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) // Hang up all .then(() => gRemoteHangUp(outCall)) - .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) + .then(() => check(PHONE_STATE_NORMAL)) // Dial out .then(() => gDial(outNumber)) .then(call => { outCall = call; }) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) .then(() => gRemoteAnswer(outCall)) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) .then(() => gHold(outCall)) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) .then(() => gResume(outCall)) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) // Dial out and dial in .then(() => gRemoteDial(inNumber)) .then(call => { inCall = call; }) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) .then(() => gAnswer(inCall)) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) // Conference .then(() => gAddCallsToConference([outCall, inCall])) - .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) + .then(() => check(PHONE_STATE_IN_CALL)) // Hang up all .then(() => gRemoteHangUpCalls([outCall, inCall])) - .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) + .then(() => check(PHONE_STATE_NORMAL)) // End .then(null, error => { diff --git a/dom/telephony/test/marionette/test_incomingcall_phonestate_speaker.js b/dom/telephony/test/marionette/test_incomingcall_phonestate_speaker.js deleted file mode 100644 index c4d6bc771f0..00000000000 --- a/dom/telephony/test/marionette/test_incomingcall_phonestate_speaker.js +++ /dev/null @@ -1,66 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -MARIONETTE_TIMEOUT = 60000; -MARIONETTE_HEAD_JS = 'head.js'; - -const AUDIO_MANAGER_CONTRACT_ID = "@mozilla.org/telephony/audiomanager;1"; - -// See nsIAudioManager -const PHONE_STATE_INVALID = -2; -const PHONE_STATE_CURRENT = -1; -const PHONE_STATE_NORMAL = 0; -const PHONE_STATE_RINGTONE = 1; -const PHONE_STATE_IN_CALL = 2; -const PHONE_STATE_IN_COMMUNICATION = 3; - -let audioManager; - -function checkSpeakerEnabled(phoneStatePrev, phoneStateNew, toggle, setSpeaker) { - if (!audioManager) { - audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID] - .getService(SpecialPowers.Ci.nsIAudioManager); - ok(audioManager, "nsIAudioManager instance"); - } - - is(audioManager.phoneState, phoneStatePrev, "audioManager.phoneState"); - if (toggle) { - telephony.speakerEnabled = setSpeaker; - } - is(audioManager.phoneState, phoneStateNew, "audioManager.phoneState"); -} - -// Start the test -startTest(function() { - let inNumber = "5555550201"; - let inCall; - - Promise.resolve() - .then(() => checkSpeakerEnabled(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL, false, false)) - // Dial in - .then(() => gRemoteDial(inNumber)) - .then(call => { inCall = call; }) - .then(() => checkSpeakerEnabled(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, false, false)) - .then(() => gAnswer(inCall)) - .then(() => checkSpeakerEnabled(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL, false, false)) - // Go on Speaker (Don't go off speaker before hanging up. This is to check - // the condition for bug 1021550) - .then(() => checkSpeakerEnabled(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL, true, true)) - // Hang up all - .then(() => gRemoteHangUp(inCall)) - .then(() => checkSpeakerEnabled(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL, false, false)) - // Make a second inbound call - .then(() => gRemoteDial(inNumber)) - .then(call => { inCall = call; }) - .then(() => checkSpeakerEnabled(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, false, false)) - .then(() => gAnswer(inCall)) - .then(() => checkSpeakerEnabled(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL, false, false)) - // Hang up the call - .then(() => gRemoteHangUp(inCall)) - .then(() => checkSpeakerEnabled(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL, false, false)) - // End - .then(null, error => { - ok(false, 'promise rejects during test.'); - }) - .then(finish); -});