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