2013-01-22 20:48:53 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2013-04-09 19:48:36 +04:00
|
|
|
MARIONETTE_TIMEOUT = 60000;
|
2013-01-22 20:48:53 +04:00
|
|
|
|
|
|
|
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
|
|
|
SpecialPowers.addPermission("sms", true, document);
|
|
|
|
|
|
|
|
let sms = window.navigator.mozSms;
|
|
|
|
// https://developer.mozilla.org/en-US/docs/DOM/SmsManager
|
|
|
|
let maxCharsPerSms = 160;
|
|
|
|
let maxSegments = 10; // 10 message segments concatenated into 1 multipart SMS
|
|
|
|
|
2013-03-07 20:12:56 +04:00
|
|
|
const REMOTE = "5551234567"; // the remote number
|
|
|
|
const EMULATOR = "15555215554"; // the emulator's number
|
2013-01-23 13:40:48 +04:00
|
|
|
|
2013-01-22 20:48:53 +04:00
|
|
|
function verifyInitialState() {
|
|
|
|
log("Verifying initial state.");
|
|
|
|
ok(sms, "mozSms");
|
|
|
|
simulateIncomingSms();
|
|
|
|
}
|
|
|
|
|
|
|
|
function simulateIncomingSms() {
|
|
|
|
let msgText = "";
|
|
|
|
|
|
|
|
// Build the message text
|
|
|
|
msgText = new Array((maxCharsPerSms * maxSegments) + 1).join('a');
|
|
|
|
log("Simulating incoming multipart SMS (" + msgText.length +
|
|
|
|
" chars total).");
|
|
|
|
|
|
|
|
sms.onreceived = function onreceived(event) {
|
2013-01-23 13:40:48 +04:00
|
|
|
sms.onreceived = null;
|
2013-01-22 20:48:53 +04:00
|
|
|
log("Received 'onreceived' smsmanager event.");
|
2013-01-23 13:40:48 +04:00
|
|
|
|
2013-01-22 20:48:53 +04:00
|
|
|
let incomingSms = event.message;
|
|
|
|
ok(incomingSms, "incoming sms");
|
|
|
|
ok(incomingSms.id, "sms id");
|
|
|
|
log("Received SMS (id: " + incomingSms.id + ").");
|
2013-04-05 16:16:01 +04:00
|
|
|
ok(incomingSms.threadId, "thread id");
|
2013-01-22 20:48:53 +04:00
|
|
|
is(incomingSms.body.length, msgText.length, "msg body length");
|
|
|
|
is(incomingSms.body, msgText, "msg body");
|
|
|
|
is(incomingSms.delivery, "received", "delivery");
|
|
|
|
is(incomingSms.read, false, "read");
|
2013-03-07 20:12:56 +04:00
|
|
|
is(incomingSms.receiver, EMULATOR, "receiver");
|
|
|
|
is(incomingSms.sender, REMOTE, "sender");
|
2013-01-22 20:48:53 +04:00
|
|
|
ok(incomingSms.timestamp instanceof Date, "timestamp is instanceof date");
|
|
|
|
|
|
|
|
verifySmsExists(incomingSms);
|
|
|
|
};
|
2013-01-23 13:40:48 +04:00
|
|
|
runEmulatorCmd("sms send " + REMOTE + " " + msgText, function(result) {
|
2013-01-22 20:48:53 +04:00
|
|
|
is(result[0], "OK", "emulator output");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifySmsExists(incomingSms) {
|
|
|
|
log("Getting SMS (id: " + incomingSms.id + ").");
|
|
|
|
let requestRet = sms.getMessage(incomingSms.id);
|
|
|
|
ok(requestRet, "smsrequest obj returned");
|
|
|
|
|
|
|
|
requestRet.onsuccess = function(event) {
|
|
|
|
log("Received 'onsuccess' smsrequest event.");
|
|
|
|
ok(event.target.result, "smsrequest event.target.result");
|
|
|
|
let foundSms = event.target.result;
|
|
|
|
is(foundSms.id, incomingSms.id, "found SMS id matches");
|
|
|
|
is(foundSms.body.length, incomingSms.body.length, "SMS text length");
|
|
|
|
is(foundSms.body, incomingSms.body, "found SMS msg text matches");
|
|
|
|
log("Got SMS (id: " + foundSms.id + ") as expected.");
|
|
|
|
deleteSms(incomingSms);
|
|
|
|
};
|
|
|
|
|
|
|
|
requestRet.onerror = function(event) {
|
|
|
|
log("Received 'onerror' smsrequest event.");
|
|
|
|
ok(event.target.error, "domerror obj");
|
|
|
|
is(event.target.error.name, "NotFoundError", "error returned");
|
|
|
|
log("Could not get SMS (id: " + incomingSms.id + ") but should have.");
|
|
|
|
ok(false, "SMS was not found");
|
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSms(smsMsgObj){
|
|
|
|
log("Deleting SMS (id: " + smsMsgObj.id + ") using smsmsg obj parameter.");
|
|
|
|
let requestRet = sms.delete(smsMsgObj);
|
|
|
|
ok(requestRet, "smsrequest obj returned");
|
|
|
|
|
|
|
|
requestRet.onsuccess = function(event) {
|
|
|
|
log("Received 'onsuccess' smsrequest event.");
|
|
|
|
if (event.target.result) {
|
|
|
|
cleanUp();
|
|
|
|
} else {
|
|
|
|
log("smsrequest returned false for sms.delete");
|
|
|
|
ok(false, "SMS delete failed");
|
|
|
|
cleanUp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
requestRet.onerror = function(event) {
|
|
|
|
log("Received 'onerror' smsrequest event.");
|
|
|
|
ok(event.target.error, "domerror obj");
|
|
|
|
ok(false, "sms.delete request returned unexpected error: " +
|
|
|
|
event.target.error.name);
|
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp() {
|
|
|
|
SpecialPowers.removePermission("sms", document);
|
|
|
|
SpecialPowers.clearUserPref("dom.sms.enabled");
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the test
|
|
|
|
verifyInitialState();
|