Bug 1147842 - Test system message telephony-call-ended. r=hsinyi

This commit is contained in:
Szu-Yu Chen [:aknow] 2015-04-08 18:01:28 +08:00
Родитель 59c7f51af3
Коммит 35e7f7c4b4
3 изменённых файлов: 144 добавлений и 0 удалений

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

@ -118,6 +118,44 @@ let emulator = (function() {
});
}
/**
* Wait for one named system message.
*
* Resolve if that named message is received. Never reject.
*
* Fulfill params: the message passed.
*
* @param aEventName
* A string message name.
* @param aMatchFun [optional]
* A matching function returns true or false to filter the message. If no
* matching function passed the promise is resolved after receiving the
* first message.
*
* @return Promise<Message>
*/
function waitForSystemMessage(aMessageName, aMatchFun = null) {
// Current page may not register to receiving the message. We should
// register it first.
let systemMessenger = SpecialPowers.Cc["@mozilla.org/system-message-internal;1"]
.getService(SpecialPowers.Ci.nsISystemMessagesInternal);
// TODO: Find a better way to get current pageURI and manifestURI.
systemMessenger.registerPage(aMessageName,
SpecialPowers.Services.io.newURI("app://system.gaiamobile.org/index.html", null, null),
SpecialPowers.Services.io.newURI("app://system.gaiamobile.org/manifest.webapp", null, null));
return new Promise(function(aResolve, aReject) {
window.navigator.mozSetMessageHandler(aMessageName, function(aMessage) {
if (!aMatchFun || aMatchFun(aMessage)) {
log("System message '" + aMessageName + "' got.");
window.navigator.mozSetMessageHandler(aMessageName, null);
aResolve(aMessage);
}
});
});
}
/**
* Wait for one named event.
*
@ -1098,6 +1136,7 @@ let emulator = (function() {
*/
this.gDelay = delay;
this.gWaitForSystemMessage = waitForSystemMessage;
this.gWaitForEvent = waitForEvent;
this.gWaitForCallsChangedEvent = waitForCallsChangedEvent;
this.gWaitForNamedStateEvent = waitForNamedStateEvent;

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

@ -51,4 +51,5 @@ qemu = true
[test_ready.js]
[test_redundant_operations.js]
[test_swap_held_and_active.js]
[test_system_message_telephony_call_ended.js]
[test_temporary_clir.js]

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

@ -0,0 +1,104 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 90000;
MARIONETTE_HEAD_JS = 'head.js';
const inNumber = "5555552222";
const inInfo = gInCallStrPool(inNumber);
let inCall;
/**
* telephony-call-ended message contains the following fields:
* - serviceId
* - number
* - emergency
* - duration
* - direction
* - hangUpLocal
*/
function testIncomingReject() {
log("= testIncomingReject =");
let p1 = gWaitForSystemMessage("telephony-call-ended")
.then(message => {
is(message.number, inNumber);
is(message.duration, 0);
is(message.direction, "incoming");
is(message.hangUpLocal, true);
});
let p2 = gRemoteDial(inNumber)
.then(call => inCall = call)
.then(() => gHangUp(inCall));
return Promise.all([p1, p2]);
}
function testIncomingCancel() {
log("= testIncomingCancel =");
let p1 = gWaitForSystemMessage("telephony-call-ended")
.then(message => {
is(message.number, inNumber);
is(message.duration, 0);
is(message.direction, "incoming");
is(message.hangUpLocal, false);
});
let p2 = gRemoteDial(inNumber)
.then(call => inCall = call)
.then(() => gRemoteHangUp(inCall));
return Promise.all([p1, p2]);
}
function testIncomingAnswerHangUp() {
log("= testIncomingAnswerHangUp =");
p1 = gWaitForSystemMessage("telephony-call-ended")
.then(message => {
is(message.number, inNumber);
ok(message.duration > 0);
is(message.direction, "incoming");
is(message.hangUpLocal, true);
});
p2 = gRemoteDial(inNumber)
.then(call => inCall = call)
.then(() => gAnswer(inCall))
.then(() => gHangUp(inCall));
return Promise.all([p1, p2]);
}
function testIncomingAnswerRemoteHangUp() {
log("= testIncomingAnswerRemoteHangUp =");
p1 = gWaitForSystemMessage("telephony-call-ended")
.then(message => {
is(message.number, inNumber);
ok(message.duration > 0);
is(message.direction, "incoming");
is(message.hangUpLocal, false);
});
p2 = gRemoteDial(inNumber)
.then(call => inCall = call)
.then(() => gAnswer(inCall))
.then(() => gRemoteHangUp(inCall));
return Promise.all([p1, p2]);
}
startTest(function() {
Promise.resolve()
.then(() => testIncomingReject())
.then(() => testIncomingCancel())
.then(() => testIncomingAnswerHangUp())
.then(() => testIncomingAnswerRemoteHangUp())
.catch(error => ok(false, "Promise reject: " + error))
.then(finish);
});