Bug 915638 - part2 - test case. r=vicamo

This commit is contained in:
Hsin-Yi Tsai 2013-09-16 14:04:43 +08:00
Родитель 97f256f2ed
Коммит 84d8e7452c
1 изменённых файлов: 120 добавлений и 29 удалений

Просмотреть файл

@ -58,12 +58,17 @@ function verifyInitialState() {
ok(telephony);
ok(conference);
checkState(null, [], '', []);
sendCmdToEmulator("gsm clear", function(result) {
log("Clear up calls from a previous test if any.");
is(result[0], "OK");
dial();
// No more calls in the list; give time for emulator to catch up.
waitFor(function next() {
checkState(null, [], '', []);
dial();
}, function isDone() {
return (telephony.calls.length == 0);
});
});
}
@ -200,6 +205,7 @@ function conferenceAddTwoCalls() {
let pending = ["conference.oncallschanged", "conference.onconnected",
"outgoingCall.onstatechange", "outgoingCall.ongroupchange",
"incomingCall.onstatechange", "incomingCall.ongroupchange"];
let nextTest = conferenceHold;
// We are expecting to receive conference.oncallschanged two times since
// two calls are added into conference.
@ -214,7 +220,7 @@ function conferenceAddTwoCalls() {
if (expected.length == 0) {
conference.oncallschanged = null;
receivedPending("conference.oncallschanged", pending, conferenceHold);
receivedPending("conference.oncallschanged", pending, nextTest);
}
};
@ -232,7 +238,7 @@ function conferenceAddTwoCalls() {
is(result[1], "inbound from " + inNumber + " : active");
is(result[2], "OK");
receivedPending("conference.onconnected", pending, conferenceHold);
receivedPending("conference.onconnected", pending, nextTest);
});
};
@ -243,7 +249,7 @@ function conferenceAddTwoCalls() {
ok(outgoingCall.group);
is(outgoingCall.group, conference);
receivedPending("outgoingCall.ongroupchange", pending, conferenceHold);
receivedPending("outgoingCall.ongroupchange", pending, nextTest);
};
outgoingCall.onstatechange = function(event) {
@ -253,7 +259,7 @@ function conferenceAddTwoCalls() {
ok(!outgoingCall.ongroupchange);
is(outgoingCall.state, conference.state);
receivedPending("outgoingCall.onstatechange", pending, conferenceHold);
receivedPending("outgoingCall.onstatechange", pending, nextTest);
};
incomingCall.ongroupchange = function(event) {
@ -263,7 +269,7 @@ function conferenceAddTwoCalls() {
ok(incomingCall.group);
is(incomingCall.group, conference);
receivedPending("incomingCall.ongroupchange", pending, conferenceHold);
receivedPending("incomingCall.ongroupchange", pending, nextTest);
};
incomingCall.onstatechange = function(event) {
@ -273,7 +279,7 @@ function conferenceAddTwoCalls() {
ok(!incomingCall.ongroupchange);
is(incomingCall.state, conference.state);
receivedPending("incomingCall.onstatechange", pending, conferenceHold);
receivedPending("incomingCall.onstatechange", pending, nextTest);
};
conference.add(outgoingCall, incomingCall);
@ -285,6 +291,7 @@ function conferenceHold() {
let pending = ["conference.onholding", "conference.onheld",
"outgoingCall.onholding", "outgoingCall.onheld",
"incomingCall.onholding", "incomingCall.onheld"];
let nextTest = conferenceResume;
conference.onholding = function(event) {
log("Received 'holding' event for the conference call.");
@ -292,7 +299,7 @@ function conferenceHold() {
is(conference.state, 'holding');
receivedPending("conference.onholding", pending, conferenceResume);
receivedPending("conference.onholding", pending, nextTest);
};
conference.onheld = function(event) {
@ -308,7 +315,7 @@ function conferenceHold() {
is(result[1], "inbound from " + inNumber + " : held");
is(result[2], "OK");
receivedPending("conference.onheld", pending, conferenceResume);
receivedPending("conference.onheld", pending, nextTest);
});
};
@ -318,7 +325,7 @@ function conferenceHold() {
is(outgoingCall.state, 'holding');
receivedPending("outgoingCall.onholding", pending, conferenceResume);
receivedPending("outgoingCall.onholding", pending, nextTest);
};
outgoingCall.onheld = function(event) {
@ -328,7 +335,7 @@ function conferenceHold() {
ok(!outgoingCall.onholding);
is(outgoingCall.state, 'held');
receivedPending("outgoingCall.onheld", pending, conferenceResume);
receivedPending("outgoingCall.onheld", pending, nextTest);
};
incomingCall.onholding = function(event) {
@ -337,7 +344,7 @@ function conferenceHold() {
is(incomingCall.state, 'holding');
receivedPending("incomingCall.onholding", pending, conferenceResume);
receivedPending("incomingCall.onholding", pending, nextTest);
};
incomingCall.onheld = function(event) {
@ -347,7 +354,7 @@ function conferenceHold() {
ok(!incomingCall.onholding);
is(incomingCall.state, 'held');
receivedPending("incomingCall.onheld", pending, conferenceResume);
receivedPending("incomingCall.onheld", pending, nextTest);
};
conference.hold();
@ -359,6 +366,7 @@ function conferenceResume() {
let pending = ["conference.onresuming", "conference.onconnected",
"outgoingCall.onresuming", "outgoingCall.onconnected",
"incomingCall.onresuming", "incomingCall.onconnected"];
let nextTest = simulate2ndIncoming;
conference.onresuming = function(event) {
log("Received 'resuming' event for the conference call.");
@ -366,7 +374,7 @@ function conferenceResume() {
is(conference.state, 'resuming');
receivedPending("conference.onresuming", pending, simulate2ndIncoming);
receivedPending("conference.onresuming", pending, nextTest);
};
conference.onconnected = function(event) {
@ -382,7 +390,7 @@ function conferenceResume() {
is(result[1], "inbound from " + inNumber + " : active");
is(result[2], "OK");
receivedPending("conference.onconnected", pending, simulate2ndIncoming);
receivedPending("conference.onconnected", pending, nextTest);
});
};
@ -392,7 +400,7 @@ function conferenceResume() {
is(outgoingCall.state, 'resuming');
receivedPending("outgoingCall.onresuming", pending, simulate2ndIncoming);
receivedPending("outgoingCall.onresuming", pending, nextTest);
};
outgoingCall.onconnected = function(event) {
@ -402,7 +410,7 @@ function conferenceResume() {
ok(!outgoingCall.onresuming);
is(outgoingCall.state, 'connected');
receivedPending("outgoingCall.onconnected", pending, simulate2ndIncoming);
receivedPending("outgoingCall.onconnected", pending, nextTest);
};
incomingCall.onresuming = function(event) {
@ -411,7 +419,7 @@ function conferenceResume() {
is(incomingCall.state, 'resuming');
receivedPending("incomingCall.onresuming", pending, simulate2ndIncoming);
receivedPending("incomingCall.onresuming", pending, nextTest);
};
incomingCall.onconnected = function(event) {
@ -421,7 +429,7 @@ function conferenceResume() {
ok(!incomingCall.onresuming);
is(incomingCall.state, 'connected');
receivedPending("incomingCall.onconnected", pending, simulate2ndIncoming);
receivedPending("incomingCall.onconnected", pending, nextTest);
};
conference.resume();
@ -496,6 +504,7 @@ function conferenceAddOneCall() {
let callToAdd = incomingCall2;
let pending = ["conference.oncallschanged", "conference.onconnected",
"callToAdd.ongroupchange", "callToAdd.onconnected"];
let nextTest = conferenceRemove;
ok(!callToAdd.group);
@ -507,7 +516,7 @@ function conferenceAddOneCall() {
is(conference.calls.length, 3);
is(conference.calls[2].number, event.call.number);
receivedPending("conference.oncallschanged", pending, conferenceRemove);
receivedPending("conference.oncallschanged", pending, nextTest);
};
conference.onconnected = function(event) {
@ -526,7 +535,7 @@ function conferenceAddOneCall() {
is(result[2], "inbound from " + inNumber2 + " : active");
is(result[3], "OK");
receivedPending("conference.onconnected", pending, conferenceRemove);
receivedPending("conference.onconnected", pending, nextTest);
});
};
@ -535,7 +544,7 @@ function conferenceAddOneCall() {
callToAdd.ongroupchange = null;
is(callToAdd.group, conference);
receivedPending("callToAdd.ongroupchange", pending, conferenceRemove);
receivedPending("callToAdd.ongroupchange", pending, nextTest);
};
callToAdd.onconnected = function(event) {
@ -545,7 +554,7 @@ function conferenceAddOneCall() {
ok(!callToAdd.ongroupchange);
is(callToAdd.state, 'connected');
receivedPending("callToAdd.onconnected", pending, conferenceRemove);
receivedPending("callToAdd.onconnected", pending, nextTest);
};
conference.add(callToAdd);
}
@ -560,6 +569,7 @@ function conferenceRemove() {
let callToRemove = conference.calls[0];
let pending = ["callToRemove.ongroupchange", "telephony.oncallschanged",
"conference.oncallschanged", "conference.onstatechange"];
let nextTest = emptyConference;
callToRemove.ongroupchange = function(event) {
log("Received 'groupchange' event for the call to remove.");
@ -568,7 +578,7 @@ function conferenceRemove() {
ok(!callToRemove.group);
is(callToRemove.state, 'connected');
receivedPending("callToRemove.ongroupchange", pending, cleanUp);
receivedPending("callToRemove.ongroupchange", pending, nextTest);
};
telephony.oncallschanged = function(event) {
@ -582,7 +592,7 @@ function conferenceRemove() {
is(telephony.calls.length, 1);
is(telephony.calls[0].number, event.call.number);
receivedPending("telephony.oncallschanged", pending, cleanUp);
receivedPending("telephony.oncallschanged", pending, nextTest);
}
};
@ -593,7 +603,7 @@ function conferenceRemove() {
is(event.call.number, callToRemove.number);
is(conference.calls.length, 2);
receivedPending("conference.oncallschanged", pending, cleanUp);
receivedPending("conference.oncallschanged", pending, nextTest);
};
conference.onstatechange = function(event) {
@ -612,13 +622,94 @@ function conferenceRemove() {
is(result[2], "inbound from " + inNumber2 + " : held");
is(result[3], "OK");
receivedPending("conference.onstatechange", pending, cleanUp);
receivedPending("conference.onstatechange", pending, nextTest);
});
};
conference.remove(callToRemove);
}
// We first release a call in telephony, then release a call in conference.
// The only call left in conference will be automatically moved from conference
// to the calls list of telephony.
function emptyConference() {
log("Release one call in conference.");
outgoingCall.ondisconnected = function(event) {
log("Received 'disconnected' event for the outgoing call.");
outgoingCall.ondisconnected = null;
checkState(null, [], 'held',
[incomingCall, incomingCall2]);
// We are going to release incomingCall. Once released, incomingCall2
// is going to be moved out of the conference call automatically.
sendCmdToEmulator("gsm cancel " + inNumber);
};
let pending = ["conference.oncallschanged", "conference.onstatechange",
"incomingCall2.ongroupchange"];
let nextTest = hangUpLastCall;
incomingCall2.ongroupchange = function(event) {
log("Received 'groupchange' event for the outgoing call.");
incomingCall2.ongroupchange = null;
ok(!incomingCall2.group);
is(incomingCall2.state, 'held');
receivedPending("incomingCall2.ongroupchange", pending, nextTest);
};
// We are expecting to receive conference.oncallschanged two times since
// two calls are removed from conference.
let expected = [incomingCall, incomingCall2];
conference.oncallschanged = function(event) {
log("Received 'callschanged' event for the conference call.");
let index = expected.indexOf(event.call);
ok(index != -1);
expected.splice(index, 1);
if (expected.length == 0) {
conference.oncallschanged = null;
is(conference.calls.length, 0);
receivedPending("conference.oncallschanged", pending, nextTest);
}
};
conference.onstatechange = function(event) {
log("Received 'statechange' event for the conference call.");
conference.onstatechange = null;
ok(!conference.oncallschanged);
checkState(null, [incomingCall2], '', []);
receivedPending("conference.onstatechange", pending, nextTest);
};
sendCmdToEmulator("gsm cancel " + outNumber);
}
function hangUpLastCall() {
log("Going to leave the test. Hanging up the last call.");
incomingCall2.ondisconnected = function(event) {
incomingCall2.ondisconnected = null;
checkState(null, [], '', []);
sendCmdToEmulator("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
sendCmdToEmulator("gsm cancel " + inNumber2);
}
function cleanUp() {
if (pendingEmulatorCmdCount) {
window.setTimeout(cleanUp, 100);