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
This commit is contained in:
Szu-Yu Chen [:aknow] 2014-11-04 15:44:14 +08:00
parent eb2b44aca6
commit ae1bbf3359
3 changed files with 30 additions and 109 deletions

View File

@ -61,7 +61,6 @@ disabled = Bug 821958
[test_conference_add_twice_error.js] [test_conference_add_twice_error.js]
[test_outgoing_when_two_calls_on_line.js] [test_outgoing_when_two_calls_on_line.js]
[test_call_presentation.js] [test_call_presentation.js]
[test_incomingcall_phonestate_speaker.js]
[test_temporary_clir.js] [test_temporary_clir.js]
[test_outgoing_error_state.js] [test_outgoing_error_state.js]
[test_outgoing_auto_hold.js] [test_outgoing_auto_hold.js]

View File

@ -14,37 +14,25 @@ const PHONE_STATE_RINGTONE = 1;
const PHONE_STATE_IN_CALL = 2; const PHONE_STATE_IN_CALL = 2;
const PHONE_STATE_IN_COMMUNICATION = 3; const PHONE_STATE_IN_COMMUNICATION = 3;
let audioManager; let audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID]
function checkStates(speakerEnabled, phoneState) {
if (!audioManager) {
audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID]
.getService(SpecialPowers.Ci.nsIAudioManager); .getService(SpecialPowers.Ci.nsIAudioManager);
ok(audioManager, "nsIAudioManager instance");
}
is(telephony.speakerEnabled, speakerEnabled, "telephony.speakerEnabled"); ok(audioManager, "nsIAudioManager instance");
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");
}
}
function check(phoneStateOrig, phoneStateEnabled, phoneStateDisabled) { function check(phoneState) {
checkStates(false, phoneStateOrig); 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; return (phoneState == currentPhoneState ||
telephony.speakerEnabled = true; (phoneState == PHONE_STATE_CURRENT &&
if (canEnableSpeaker) { currentPhoneState == PHONE_STATE_NORMAL));
checkStates(true, phoneStateEnabled); });
} else { });
checkStates(false, phoneStateOrig);
return;
}
telephony.speakerEnabled = false;
checkStates(false, arguments.length > 2 ? phoneStateDisabled : phoneStateOrig);
} }
// Start the test // Start the test
@ -55,50 +43,50 @@ startTest(function() {
let inCall; let inCall;
Promise.resolve() Promise.resolve()
.then(() => check(PHONE_STATE_CURRENT, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) .then(() => check(PHONE_STATE_CURRENT))
// Dial in // Dial in
.then(() => gRemoteDial(inNumber)) .then(() => gRemoteDial(inNumber))
.then(call => { inCall = call; }) .then(call => { inCall = call; })
.then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE)) .then(() => check(PHONE_STATE_RINGTONE))
.then(() => gAnswer(inCall)) .then(() => gAnswer(inCall))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
// Hang up all // Hang up all
.then(() => gRemoteHangUp(inCall)) .then(() => gRemoteHangUp(inCall))
.then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) .then(() => check(PHONE_STATE_NORMAL))
// Dial out // Dial out
.then(() => gDial(outNumber)) .then(() => gDial(outNumber))
.then(call => { outCall = call; }) .then(call => { outCall = call; })
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
.then(() => gRemoteAnswer(outCall)) .then(() => gRemoteAnswer(outCall))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
// Hang up all // Hang up all
.then(() => gRemoteHangUp(outCall)) .then(() => gRemoteHangUp(outCall))
.then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) .then(() => check(PHONE_STATE_NORMAL))
// Dial out // Dial out
.then(() => gDial(outNumber)) .then(() => gDial(outNumber))
.then(call => { outCall = call; }) .then(call => { outCall = call; })
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
.then(() => gRemoteAnswer(outCall)) .then(() => gRemoteAnswer(outCall))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
.then(() => gHold(outCall)) .then(() => gHold(outCall))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
.then(() => gResume(outCall)) .then(() => gResume(outCall))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
// Dial out and dial in // Dial out and dial in
.then(() => gRemoteDial(inNumber)) .then(() => gRemoteDial(inNumber))
.then(call => { inCall = call; }) .then(call => { inCall = call; })
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
.then(() => gAnswer(inCall)) .then(() => gAnswer(inCall))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
// Conference // Conference
.then(() => gAddCallsToConference([outCall, inCall])) .then(() => gAddCallsToConference([outCall, inCall]))
.then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL)) .then(() => check(PHONE_STATE_IN_CALL))
// Hang up all // Hang up all
.then(() => gRemoteHangUpCalls([outCall, inCall])) .then(() => gRemoteHangUpCalls([outCall, inCall]))
.then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL)) .then(() => check(PHONE_STATE_NORMAL))
// End // End
.then(null, error => { .then(null, error => {

View File

@ -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);
});