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);
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var manager = window.navigator.mozMobileMessage;
|
2013-01-22 20:48:53 +04:00
|
|
|
// https://developer.mozilla.org/en-US/docs/DOM/SmsManager
|
2015-09-15 21:19:45 +03:00
|
|
|
var maxCharsPerSms = 160;
|
|
|
|
var maxSegments = 10; // 10 message segments concatenated into 1 multipart SMS
|
2013-01-22 20:48:53 +04:00
|
|
|
|
|
|
|
function verifyInitialState() {
|
|
|
|
log("Verifying initial state.");
|
2013-07-26 14:40:27 +04:00
|
|
|
ok(manager instanceof MozMobileMessageManager,
|
|
|
|
"manager is instance of " + manager.constructor);
|
2013-01-22 20:48:53 +04:00
|
|
|
sendSms();
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendSms() {
|
|
|
|
let destNumber = "5551234567";
|
|
|
|
let msgText = "";
|
|
|
|
let gotReqOnSuccess = false;
|
|
|
|
let gotSmsOnSent = false;
|
|
|
|
let sentSms;
|
|
|
|
|
|
|
|
// Build the message text
|
|
|
|
msgText = new Array((maxCharsPerSms * maxSegments) + 1).join('a');
|
|
|
|
log("Sending multipart SMS (" + msgText.length + " chars total).");
|
|
|
|
|
2013-07-26 14:40:27 +04:00
|
|
|
manager.onsent = function(event) {
|
|
|
|
manager.onsent = null;
|
|
|
|
log("Received 'onsent' event.");
|
2013-01-23 13:40:48 +04:00
|
|
|
|
2013-01-22 20:48:53 +04:00
|
|
|
gotSmsOnSent = true;
|
|
|
|
sentSms = event.message;
|
|
|
|
ok(sentSms, "outgoing sms");
|
|
|
|
ok(sentSms.id, "sms id");
|
|
|
|
log("Sent SMS (id: " + sentSms.id + ").");
|
2013-04-05 16:16:01 +04:00
|
|
|
ok(sentSms.threadId, "thread id");
|
2013-01-22 20:48:53 +04:00
|
|
|
is(sentSms.body.length, msgText.length, "text length");
|
|
|
|
is(sentSms.body, msgText, "msg body");
|
|
|
|
is(sentSms.delivery, "sent", "delivery");
|
|
|
|
|
|
|
|
if (gotReqOnSuccess) { verifySmsExists(sentSms); }
|
|
|
|
};
|
|
|
|
|
2013-07-26 14:40:27 +04:00
|
|
|
let requestRet = manager.send(destNumber, msgText);
|
2013-01-22 20:48:53 +04:00
|
|
|
ok(requestRet, "smsrequest obj returned");
|
|
|
|
|
|
|
|
requestRet.onsuccess = function(event) {
|
|
|
|
log("Received 'onsuccess' smsrequest event.");
|
|
|
|
gotReqOnSuccess = true;
|
|
|
|
if (event.target.result) {
|
|
|
|
if (gotSmsOnSent) { verifySmsExists(sentSms); }
|
|
|
|
} else {
|
2013-07-26 14:40:27 +04:00
|
|
|
log("smsrequest returned false for manager.send");
|
2013-01-22 20:48:53 +04:00
|
|
|
ok(false, "SMS send failed");
|
|
|
|
cleanUp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
requestRet.onerror = function(event) {
|
|
|
|
log("Received 'onerror' smsrequest event.");
|
|
|
|
ok(event.target.error, "domerror obj");
|
2013-07-26 14:40:27 +04:00
|
|
|
ok(false, "manager.send request returned unexpected error: " +
|
2013-01-22 20:48:53 +04:00
|
|
|
event.target.error.name);
|
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifySmsExists(sentSms) {
|
|
|
|
log("Getting SMS (id: " + sentSms.id + ").");
|
2013-07-26 14:40:27 +04:00
|
|
|
let requestRet = manager.getMessage(sentSms.id);
|
2013-01-22 20:48:53 +04:00
|
|
|
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, sentSms.id, "found SMS id matches");
|
2013-04-05 16:16:01 +04:00
|
|
|
is(foundSms.threadId, sentSms.threadId, "found SMS thread id matches");
|
2013-01-22 20:48:53 +04:00
|
|
|
is(foundSms.body.length, sentSms.body.length, "found SMS text length");
|
|
|
|
is(foundSms.body, sentSms.body, "found SMS msg text matches");
|
|
|
|
log("Got SMS (id: " + foundSms.id + ") as expected.");
|
|
|
|
deleteSms(sentSms);
|
|
|
|
};
|
|
|
|
|
|
|
|
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: " + sentSms.id + ") but should have.");
|
|
|
|
ok(false, "SMS was not found");
|
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSms(smsMsgObj) {
|
|
|
|
log("Deleting SMS (id: " + smsMsgObj.id + ") using smsmsg obj parameter.");
|
2013-07-26 14:40:27 +04:00
|
|
|
let requestRet = manager.delete(smsMsgObj);
|
2013-01-22 20:48:53 +04:00
|
|
|
ok(requestRet,"smsrequest obj returned");
|
|
|
|
|
|
|
|
requestRet.onsuccess = function(event) {
|
|
|
|
log("Received 'onsuccess' smsrequest event.");
|
|
|
|
if (event.target.result) {
|
|
|
|
cleanUp();
|
|
|
|
} else {
|
2013-07-26 14:40:27 +04:00
|
|
|
log("smsrequest returned false for manager.delete");
|
2013-01-22 20:48:53 +04:00
|
|
|
ok(false, "SMS delete failed");
|
|
|
|
cleanUp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
requestRet.onerror = function(event) {
|
|
|
|
log("Received 'onerror' smsrequest event.");
|
|
|
|
ok(event.target.error, "domerror obj");
|
2013-07-26 14:40:27 +04:00
|
|
|
ok(false, "manager.delete request returned unexpected error: " +
|
2013-01-22 20:48:53 +04:00
|
|
|
event.target.error.name);
|
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp() {
|
|
|
|
SpecialPowers.removePermission("sms", document);
|
|
|
|
SpecialPowers.clearUserPref("dom.sms.enabled");
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the test
|
|
|
|
verifyInitialState();
|