mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 736708 - 3/3: test cases. r=gene
This commit is contained in:
parent
9b0236510d
commit
defbd0f514
@ -196,7 +196,7 @@ function getThreadById(aThreadId) {
|
||||
return getAllThreads()
|
||||
.then(function(aThreads) {
|
||||
for (let thread of aThreads) {
|
||||
if (thread.id == aThreadId) {
|
||||
if (thread.id === aThreadId) {
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
@ -267,6 +267,70 @@ function deleteAllMessages() {
|
||||
return getAllMessages().then(deleteMessages);
|
||||
}
|
||||
|
||||
let pendingEmulatorCmdCount = 0;
|
||||
|
||||
/* Send emulator command with safe guard.
|
||||
*
|
||||
* We should only call |finish()| after all emulator command transactions
|
||||
* end, so here comes with the pending counter. Resolve when the emulator
|
||||
* gives positive response, and reject otherwise.
|
||||
*
|
||||
* Forfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function runEmulatorCmdSafe(aCommand) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
++pendingEmulatorCmdCount;
|
||||
runEmulatorCmd(aCommand, function(aResult) {
|
||||
--pendingEmulatorCmdCount;
|
||||
|
||||
ok(true, "Emulator response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult) && aResult[0] === "OK") {
|
||||
deferred.resolve(aResult);
|
||||
} else {
|
||||
deferred.reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/* Send simple text SMS to emulator.
|
||||
*
|
||||
* Forfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendTextSmsToEmulator(aFrom, aText) {
|
||||
let command = "sms send " + aFrom + " " + aText;
|
||||
return runEmulatorCmdSafe(command);
|
||||
}
|
||||
|
||||
/* Send raw SMS TPDU to emulator.
|
||||
*
|
||||
* Forfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendRawSmsToEmulator(aPdu) {
|
||||
let command = "sms pdu " + aPdu;
|
||||
return runEmulatorCmdSafe(command);
|
||||
}
|
||||
|
||||
/* Create a new array of id attribute of input messages.
|
||||
*
|
||||
* @param aMessages an array of {Sms,Mms}Message instances.
|
||||
@ -284,11 +348,15 @@ function messagesToIds(aMessages) {
|
||||
/* Flush permission settings and call |finish()|.
|
||||
*/
|
||||
function cleanUp() {
|
||||
SpecialPowers.flushPermissions(function() {
|
||||
// Use ok here so that we have at least one test run.
|
||||
ok(true, "permissions flushed");
|
||||
waitFor(function() {
|
||||
SpecialPowers.flushPermissions(function() {
|
||||
// Use ok here so that we have at least one test run.
|
||||
ok(true, "permissions flushed");
|
||||
|
||||
finish();
|
||||
finish();
|
||||
});
|
||||
}, function() {
|
||||
return pendingEmulatorCmdCount === 0;
|
||||
});
|
||||
}
|
||||
|
||||
@ -297,5 +365,8 @@ function startTestCommon(aTestCaseMain) {
|
||||
.then(deleteAllMessages)
|
||||
.then(aTestCaseMain)
|
||||
.then(deleteAllMessages)
|
||||
.then(cleanUp, cleanUp);
|
||||
.then(cleanUp, function() {
|
||||
ok(false, 'promise rejects during test.');
|
||||
cleanUp();
|
||||
});
|
||||
}
|
||||
|
@ -40,3 +40,4 @@ qemu = true
|
||||
[test_dsds_default_service_id.js]
|
||||
[test_thread_subject.js]
|
||||
[test_mmdb_setmessagedeliverybyid_sms.js]
|
||||
[test_replace_short_message_type.js]
|
||||
|
@ -0,0 +1,121 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const PDU_SMSC_NONE = "00"; // no SMSC Address
|
||||
|
||||
const PDU_FIRST_OCTET = "00"; // RP:no, UDHI:no, SRI:no, MMS:no, MTI:SMS-DELIVER
|
||||
|
||||
const PDU_SENDER_0 = "0A912143658709"; // +1234567890
|
||||
const PDU_SENDER_1 = "0A912143658719"; // +1234567891
|
||||
const SENDER_0 = "+1234567890";
|
||||
const SENDER_1 = "+1234567891";
|
||||
|
||||
const PDU_PID_NORMAL = "00";
|
||||
const PDU_PIDS = ["00", "41", "42", "43", "44", "45", "46", "47"];
|
||||
|
||||
const PDU_DCS_NORMAL = "00";
|
||||
|
||||
const PDU_TIMESTAMP = "00101000000000"; // 2000/01/01
|
||||
|
||||
const PDU_UDL = "01";
|
||||
const PDU_UD_A = "41"; // "A"
|
||||
const PDU_UD_B = "42"; // "B"
|
||||
const BODY_A = "A";
|
||||
const BODY_B = "B";
|
||||
|
||||
function buildPdu(aSender, aPid, aBody) {
|
||||
return PDU_SMSC_NONE + PDU_FIRST_OCTET + aSender + aPid + PDU_DCS_NORMAL +
|
||||
PDU_TIMESTAMP + PDU_UDL + aBody;
|
||||
}
|
||||
|
||||
let receivedMessage;
|
||||
function consumeReceivedMessage() {
|
||||
let message = receivedMessage;
|
||||
receivedMessage = null;
|
||||
return message;
|
||||
}
|
||||
|
||||
function waitForIncomingMessage() {
|
||||
if (receivedMessage) {
|
||||
return consumeReceivedMessage();
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
||||
waitFor(function() {
|
||||
deferred.resolve(consumeReceivedMessage());
|
||||
}, function() {
|
||||
return receivedMessage != null;
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function sendRawSmsAndWait(aPdu) {
|
||||
sendRawSmsToEmulator(aPdu);
|
||||
return waitForIncomingMessage();
|
||||
}
|
||||
|
||||
function verifyReplacing(aVictim, aSender, aPid, aCompare) {
|
||||
let readableSender = aSender === PDU_SENDER_0 ? SENDER_0 : SENDER_1;
|
||||
log(" Checking ('" + readableSender + "', '" + aPid + "', '" + BODY_B + "')");
|
||||
|
||||
let pdu = buildPdu(aSender, aPid, PDU_UD_B);
|
||||
ok(true, "Sending " + pdu);
|
||||
|
||||
return sendRawSmsAndWait(pdu)
|
||||
.then(function(aReceivedMessage) {
|
||||
is(aReceivedMessage.sender, readableSender, "SmsMessage sender");
|
||||
is(aReceivedMessage.body, BODY_B, "SmsMessage body");
|
||||
|
||||
aCompare(aReceivedMessage.id, aVictim.id, "SmsMessage id");
|
||||
});
|
||||
}
|
||||
|
||||
function verifyNotReplaced(aVictim, aSender, aPid) {
|
||||
return verifyReplacing(aVictim, aSender, aPid, isnot);
|
||||
}
|
||||
|
||||
function verifyReplaced(aVictim, aSender, aPid) {
|
||||
return verifyReplacing(aVictim, aSender, aPid, is);
|
||||
}
|
||||
|
||||
function testPid(aPid) {
|
||||
log("Test message PID '" + aPid + "'");
|
||||
|
||||
return sendRawSmsAndWait(buildPdu(PDU_SENDER_0, aPid, PDU_UD_A))
|
||||
.then(function(aReceivedMessage) {
|
||||
let promise = Promise.resolve();
|
||||
|
||||
for (let pid of PDU_PIDS) {
|
||||
let verify = (aPid !== PDU_PID_NORMAL && pid === aPid)
|
||||
? verifyReplaced : verifyNotReplaced;
|
||||
promise =
|
||||
promise.then(verify.bind(null, aReceivedMessage, PDU_SENDER_0, pid))
|
||||
.then(verifyNotReplaced.bind(null, aReceivedMessage,
|
||||
PDU_SENDER_1, pid));
|
||||
}
|
||||
|
||||
return promise;
|
||||
});
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
manager.onreceived = function(event) {
|
||||
receivedMessage = event.message;
|
||||
};
|
||||
|
||||
let promise = Promise.resolve();
|
||||
for (let pid of PDU_PIDS) {
|
||||
promise = promise.then(testPid.bind(null, pid))
|
||||
.then(deleteAllMessages);
|
||||
}
|
||||
|
||||
// Clear |manager.onreceived| handler.
|
||||
return promise.then(function() {
|
||||
manager.onreceived = null;
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user