Bug 981519 - number and name presentation - part 6 - test_call_presentation.js. r=vicamo

This commit is contained in:
Hsin-Yi Tsai 2014-05-15 14:37:19 +08:00
parent 97186eb499
commit 9e71c16297
33 changed files with 187 additions and 51 deletions

View File

@ -288,6 +288,38 @@ let emulator = (function() {
};
}
/**
* Convenient helper to check the expected call number and name.
*
* @param number
* A string sent to modem.
* @param numberPresentation
* An unsigned short integer sent to modem.
* @param name
* A string sent to modem.
* @param namePresentation
* An unsigned short integer sent to modem.
* @param receivedNumber
* A string exposed by Telephony API.
* @param receivedName
* A string exposed by Telephony API.
*/
function checkCallId(number, numberPresentation, name, namePresentation,
receivedNumber, receivedName) {
let expectedNum = !numberPresentation ? number : "";
is(receivedNumber, expectedNum, "check number per numberPresentation");
let expectedName;
if (numberPresentation) {
expectedName = "";
} else if (!namePresentation) {
expectedName = name ? name : "";
} else {
expectedName = "";
}
is(receivedName, expectedName, "check name per number/namePresentation");
}
/**
* Convenient helper to check the call list existing in the emulator.
*
@ -394,7 +426,7 @@ let emulator = (function() {
telephony.dial(number, serviceId).then(call => {
ok(call);
is(call.number, number);
is(call.id.number, number);
is(call.state, "dialing");
is(call.serviceId, serviceId);
@ -497,14 +529,41 @@ let emulator = (function() {
return deferred.promise;
}
/**
* Locally hang up a call.
*
* @param call
* A TelephonyCall object.
* @return A deferred promise.
*/
function hangUp(call) {
let deferred = Promise.defer();
call.ondisconnected = function(event) {
log("Received 'disconnected' call event");
call.ondisconnected = null;
checkEventCallState(event, call, "disconnected");
deferred.resolve(call);
};
call.hangUp();
return deferred.promise;
}
/**
* Simulate an incoming call.
*
* @param number
* A string.
* @param numberPresentation [optional]
* An unsigned short integer.
* @param name [optional]
* A string.
* @param namePresentation [optional]
* An unsigned short integer.
* @return A deferred promise.
*/
function remoteDial(number) {
function remoteDial(number, numberPresentation, name, namePresentation) {
log("Simulating an incoming call.");
let deferred = Promise.defer();
@ -516,13 +575,17 @@ let emulator = (function() {
let call = event.call;
ok(call);
is(call.number, number);
is(call.state, "incoming");
checkCallId(number, numberPresentation, name, namePresentation,
call.id.number, call.id.name);
deferred.resolve(call);
};
emulator.run("gsm call " + number);
numberPresentation = numberPresentation || "";
name = name || "";
namePresentation = namePresentation || "";
emulator.run("gsm call " + number + "," + numberPresentation + "," + name +
"," + namePresentation);
return deferred.promise;
}
@ -544,7 +607,7 @@ let emulator = (function() {
checkEventCallState(event, call, "connected");
deferred.resolve(call);
};
emulator.run("gsm accept " + call.number);
emulator.run("gsm accept " + call.id.number);
return deferred.promise;
}
@ -567,7 +630,7 @@ let emulator = (function() {
checkEventCallState(event, call, "disconnected");
deferred.resolve(call);
};
emulator.run("gsm cancel " + call.number);
emulator.run("gsm cancel " + call.id.number);
return deferred.promise;
}
@ -616,7 +679,7 @@ let emulator = (function() {
let check_onconnected = StateEventChecker('connected', 'onresuming');
for (let call of callsToAdd) {
let callName = "callToAdd (" + call.number + ')';
let callName = "callToAdd (" + call.id.number + ')';
let ongroupchange = callName + ".ongroupchange";
pending.push(ongroupchange);
@ -677,7 +740,7 @@ let emulator = (function() {
let check_onheld = StateEventChecker('held', 'onholding');
for (let call of calls) {
let callName = "call (" + call.number + ')';
let callName = "call (" + call.id.number + ')';
let onholding = callName + ".onholding";
pending.push(onholding);
@ -730,7 +793,7 @@ let emulator = (function() {
let check_onconnected = StateEventChecker('connected', 'onresuming');
for (let call of calls) {
let callName = "call (" + call.number + ')';
let callName = "call (" + call.id.number + ')';
let onresuming = callName + ".onresuming";
pending.push(onresuming);
@ -789,7 +852,7 @@ let emulator = (function() {
// Remained call in conference will be held.
for (let call of remainedCalls) {
let callName = "remainedCall (" + call.number + ')';
let callName = "remainedCall (" + call.id.number + ')';
let onstatechange = callName + ".onstatechange";
pending.push(onstatechange);
@ -800,7 +863,7 @@ let emulator = (function() {
// When a call is removed from conference with 2 calls, another one will be
// automatically removed from group and be put on hold.
for (let call of autoRemovedCalls) {
let callName = "autoRemovedCall (" + call.number + ')';
let callName = "autoRemovedCall (" + call.id.number + ')';
let ongroupchange = callName + ".ongroupchange";
pending.push(ongroupchange);
@ -873,7 +936,7 @@ let emulator = (function() {
// When a call is hang up from conference with 2 calls, another one will be
// automatically removed from group.
for (let call of autoRemovedCalls) {
let callName = "autoRemovedCall (" + call.number + ')';
let callName = "autoRemovedCall (" + call.id.number + ')';
let ongroupchange = callName + ".ongroupchange";
pending.push(ongroupchange);
@ -962,8 +1025,8 @@ let emulator = (function() {
function createCallAndAddToConference(inNumber, conferenceCalls) {
// Create an info array. allInfo = [info1, info2, ...].
let allInfo = conferenceCalls.map(function(call, i) {
return (i === 0) ? outCallStrPool(call.number)
: inCallStrPool(call.number);
return (i === 0) ? outCallStrPool(call.id.number)
: inCallStrPool(call.id.number);
});
// Define state property of the info array.
@ -1042,6 +1105,7 @@ let emulator = (function() {
this.gCheckAll = checkAll;
this.gDial = dial;
this.gAnswer = answer;
this.gHangUp = hangUp;
this.gHold = hold;
this.gRemoteDial = remoteDial;
this.gRemoteAnswer = remoteAnswer;

View File

@ -57,3 +57,4 @@ disabled = Bug 821958
[test_conference_three_hangup_one.js]
[test_conference_three_remove_one.js]
[test_outgoing_when_two_calls_on_line.js]
[test_call_presentation.js]

View File

@ -0,0 +1,71 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
const ALLOWED = 0;
const RESTRICTED = 1;
const UNKNOWN = 2;
const PAYPHONE =3;
function getPresentationStr(presentation) {
let str;
switch (presentation) {
case ALLOWED:
str = "allowed";
break;
case RESTRICTED:
str = "restricted";
break;
case UNKNOWN:
str = "unknown";
break;
case PAYPHONE:
str = "payphone";
break;
}
return str;
}
function getNamePresentation(numberPresentation, namePresentation) {
// See TS 23.096 Figure 3a and Annex A Note 1.
if (!numberPresentation) {
if (namePresentation == undefined) {
namePresentation = ALLOWED;
}
} else {
namePresentation = ALLOWED;
}
return getPresentationStr(namePresentation);
}
function test(number, numberPresentation, name, namePresentation) {
return gRemoteDial(number, numberPresentation, name, namePresentation)
.then(call => {
is(call.id.numberPresentation, getPresentationStr(numberPresentation),
"check numberPresentation");
is(call.id.namePresentation,
getNamePresentation(numberPresentation, namePresentation),
"check namePresentation");
return call;
})
.then(gHangUp);
}
startTest(function() {
let inNumber = "5555550201";
Promise.resolve()
.then(() => test(inNumber, ALLOWED))
.then(() => test(inNumber, RESTRICTED))
.then(() => test(inNumber, UNKNOWN))
.then(() => test(inNumber, PAYPHONE))
.then(() => test(inNumber, ALLOWED, "TestName"))
.then(() => test(inNumber, ALLOWED, "TestName", ALLOWED))
.then(() => test(inNumber, ALLOWED, "TestName", RESTRICTED))
.then(() => test(inNumber, ALLOWED, "TestName", UNKNOWN))
.then(() => test(inNumber, RESTRICTED, "TestName", ALLOWED))
.then(() => test(inNumber, RESTRICTED, "TestName", RESTRICTED))
.then(() => test(inNumber, RESTRICTED, "TestName", UNKNOWN))
.then(finish);
});

View File

@ -14,7 +14,7 @@ function dial() {
telephony.dialEmergency(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);

View File

@ -15,7 +15,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);
@ -74,7 +74,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
// Should be two calls now

View File

@ -15,7 +15,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);
@ -105,7 +105,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
// Should be two calls now

View File

@ -15,7 +15,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incoming = event.call;
ok(incoming);
is(incoming.number, number);
is(incoming.id.number, number);
is(incoming.state, "incoming");
//ok(telephony.calls === calls); // bug 717414

View File

@ -22,7 +22,7 @@ function simulateIncoming() {
incoming = event.call;
ok(incoming);
is(incoming.number, number);
is(incoming.id.number, number);
is(incoming.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -15,7 +15,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, number);
is(incomingCall.id.number, number);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -15,7 +15,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incoming = event.call;
ok(incoming);
is(incoming.number, number);
is(incoming.id.number, number);
is(incoming.state, "incoming");
//ok(telephony.calls === calls); // bug 717414

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -16,7 +16,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);
@ -99,7 +99,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);
is(telephony.calls.length, 2);

View File

@ -16,7 +16,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);
@ -112,7 +112,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);

View File

@ -14,7 +14,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);

View File

@ -25,7 +25,7 @@ function dial() {
if (event.call.state == "dialing") {
outgoing = event.call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing, telephony.active);
is(telephony.calls.length, 1);

View File

@ -13,7 +13,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);

View File

@ -32,7 +32,7 @@ function dial(number) {
let deferred = Promise.defer();
telephony.dial(number).then(call => {
ok(call);
is(call.number, number);
is(call.id.number, number);
is(call.state, "dialing");
call.onalerting = function(event) {
@ -59,7 +59,7 @@ function remoteAnswer(call) {
is(call.state, "connected");
deferred.resolve(call);
};
emulator.run("gsm accept " + call.number);
emulator.run("gsm accept " + call.id.number);
return deferred.promise;
}

View File

@ -17,7 +17,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);

View File

@ -13,7 +13,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);

View File

@ -14,7 +14,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);

View File

@ -14,7 +14,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);
//ok(telephony.calls === calls); // bug 717414

View File

@ -14,7 +14,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, number);
is(outgoingCall.id.number, number);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);

View File

@ -13,7 +13,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);

View File

@ -13,7 +13,7 @@ function dial() {
telephony.dial(number).then(call => {
outgoing = call;
ok(outgoing);
is(outgoing.number, number);
is(outgoing.id.number, number);
is(outgoing.state, "dialing");
is(outgoing, telephony.active);

View File

@ -12,7 +12,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
is(outgoingCall, telephony.active);

View File

@ -14,7 +14,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
is(telephony.calls.length, 1);

View File

@ -17,7 +17,7 @@ function dial() {
telephony.dial(outNumber).then(call => {
outgoingCall = call;
ok(outgoingCall);
is(outgoingCall.number, outNumber);
is(outgoingCall.id.number, outNumber);
is(outgoingCall.state, "dialing");
outgoingCall.onalerting = function onalerting(event) {
@ -107,7 +107,7 @@ function simulateIncoming() {
log("Received 'incoming' call event.");
incomingCall = event.call;
ok(incomingCall);
is(incomingCall.number, inNumber);
is(incomingCall.id.number, inNumber);
is(incomingCall.state, "incoming");
// Should be two calls now