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.setBoolPref("dom.sms.requestStatusReport", true); michael@0: SpecialPowers.addPermission("sms", true, document); michael@0: michael@0: const SENDER = "15555215554"; // the emulator's number michael@0: const RECEIVER = "5551117777"; // the destination number michael@0: michael@0: let manager = window.navigator.mozMobileMessage; michael@0: let msgText = "Mozilla Firefox OS!"; michael@0: let gotSmsOnsent = false; michael@0: let gotReqOnsuccess = false; 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: sendSms(); michael@0: } michael@0: michael@0: function sendSms() { michael@0: let smsId = 0; michael@0: michael@0: log("Sending an SMS."); michael@0: manager.onsent = function(event) { michael@0: log("Received 'onsent' event."); michael@0: gotSmsOnsent = true; michael@0: let sentSms = event.message; michael@0: ok(sentSms, "outgoing sms"); michael@0: ok(sentSms.id, "sms id"); michael@0: smsId = sentSms.id; michael@0: log("Sent SMS (id: " + smsId + ")."); michael@0: ok(sentSms.threadId, "thread id"); michael@0: is(sentSms.body, msgText, "msg body"); michael@0: is(sentSms.delivery, "sent", "delivery"); michael@0: is(sentSms.deliveryStatus, "pending", "deliveryStatus"); michael@0: is(sentSms.read, true, "read"); michael@0: is(sentSms.receiver, RECEIVER, "receiver"); michael@0: is(sentSms.sender, SENDER, "sender"); michael@0: is(sentSms.messageClass, "normal", "messageClass"); michael@0: is(sentSms.deliveryTimestamp, 0, "deliveryTimestamp is 0"); michael@0: michael@0: if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); } michael@0: }; michael@0: michael@0: let requestRet = manager.send(RECEIVER, msgText); michael@0: ok(requestRet, "smsrequest obj returned"); michael@0: michael@0: requestRet.onsuccess = function(event) { michael@0: log("Received 'onsuccess' smsrequest event."); michael@0: gotReqOnsuccess = true; michael@0: if(event.target.result){ michael@0: if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); } michael@0: } else { michael@0: log("smsrequest returned false for manager.send"); michael@0: ok(false,"SMS send 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.send request returned unexpected error: " michael@0: + event.target.error.name ); michael@0: cleanUp(); michael@0: }; michael@0: } michael@0: michael@0: function verifySmsExists(smsId) { michael@0: log("Getting SMS (id: " + smsId + ")."); michael@0: let requestRet = manager.getMessage(smsId); 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, smsId, "found SMS id matches"); michael@0: is(foundSms.body, msgText, "found SMS msg text matches"); michael@0: is(foundSms.delivery, "sent", "delivery"); michael@0: is(foundSms.read, true, "read"); michael@0: is(foundSms.receiver, RECEIVER, "receiver"); michael@0: is(foundSms.sender, SENDER, "sender"); michael@0: is(foundSms.messageClass, "normal", "messageClass"); michael@0: log("Got SMS (id: " + foundSms.id + ") as expected."); michael@0: deleteSms(smsId); 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: " + smsId + ") but should have."); michael@0: ok(false,"SMS was not found"); michael@0: cleanUp(); michael@0: }; michael@0: } michael@0: michael@0: function deleteSms(smsId){ michael@0: log("Deleting SMS (id: " + smsId + ") using sms id parameter."); michael@0: let requestRet = manager.delete(smsId); 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: verifySmsDeleted(smsId); 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 verifySmsDeleted(smsId) { michael@0: log("Getting SMS (id: " + smsId + ")."); michael@0: let requestRet = manager.getMessage(smsId); 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, smsId, "found SMS id matches"); michael@0: is(foundSms.body, msgText, "found SMS msg text matches"); michael@0: log("Got SMS (id: " + foundSms.id + ") but should not have."); michael@0: ok(false, "SMS was not deleted"); michael@0: cleanUp(); 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: " + smsId + ") as expected."); michael@0: cleanUp(); michael@0: }; michael@0: } michael@0: michael@0: function cleanUp() { michael@0: manager.onsent = null; michael@0: SpecialPowers.removePermission("sms", document); michael@0: SpecialPowers.clearUserPref("dom.sms.enabled"); michael@0: SpecialPowers.clearUserPref("dom.sms.requestStatusReport"); michael@0: finish(); michael@0: } michael@0: michael@0: // Start the test michael@0: verifyInitialState();