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: MARIONETTE_HEAD_JS = 'head.js'; michael@0: michael@0: const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID = michael@0: "@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1"; michael@0: michael@0: const RECEIVER = "+1234567890"; michael@0: const TEXT = "The quick brown fox jumps over the lazy dog."; michael@0: michael@0: const DELIVERY_SENDING = "sending"; michael@0: const DELIVERY_SENT = "sent"; michael@0: const DELIVERY_RECEIVED = "received"; michael@0: const DELIVERY_NOT_DOWNLOADED = "not-downloaded"; michael@0: const DELIVERY_ERROR = "error"; michael@0: michael@0: const DELIVERY_STATUS_NOT_APPLICABLE = "not-applicable"; michael@0: const DELIVERY_STATUS_SUCCESS = "success"; michael@0: const DELIVERY_STATUS_PENDING = "pending"; michael@0: const DELIVERY_STATUS_ERROR = "error"; michael@0: michael@0: let dbService; michael@0: michael@0: /** michael@0: * @param aMessageId michael@0: * @param aParams michael@0: * An array of four elements [, , michael@0: * , ]. michael@0: */ michael@0: function setMessageDeliveryByMessageId(aMessageId, aParams) { michael@0: if (!dbService) { michael@0: dbService = Cc[RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID] michael@0: .getService(Ci.nsIRilMobileMessageDatabaseService); michael@0: if (!dbService) { michael@0: log(" Failed to get database service."); michael@0: return Promise.reject(); michael@0: } michael@0: } michael@0: michael@0: let deferred = Promise.defer(); michael@0: michael@0: log(" Set to " + aParams[0] + ":" + aParams[1]); michael@0: dbService.setMessageDeliveryByMessageId(aMessageId, null, aParams[0], michael@0: aParams[1], null, michael@0: function(aRv, aDomMessage) { michael@0: if (aRv !== Cr.NS_OK) { michael@0: deferred.reject(aRv); michael@0: return; michael@0: } michael@0: michael@0: is(aDomMessage.delivery, aParams[2], "message.delivery"); michael@0: is(aDomMessage.deliveryStatus, aParams[3], "message.deliveryStatus"); michael@0: michael@0: deferred.resolve([aRv, aDomMessage]); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function test(aTitle, aParamArray) { michael@0: log(aTitle); michael@0: michael@0: return sendSmsWithSuccess(RECEIVER, TEXT) michael@0: .then(function(aDomMessage) { michael@0: let id = aDomMessage.id; michael@0: michael@0: let promise = Promise.resolve(); michael@0: while (aParamArray.length) { michael@0: let params = aParamArray.shift(); michael@0: promise = michael@0: promise.then(setMessageDeliveryByMessageId.bind(null, id, params)); michael@0: } michael@0: michael@0: return promise; michael@0: }); michael@0: } michael@0: michael@0: startTestCommon(function testCaseMain() { michael@0: return Promise.resolve() michael@0: .then(test.bind(null, "Simulate send failed without delivery report requisition", [ michael@0: [DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE, michael@0: DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE], michael@0: [DELIVERY_ERROR, DELIVERY_STATUS_ERROR, michael@0: DELIVERY_ERROR, DELIVERY_STATUS_ERROR], michael@0: ])) michael@0: .then(test.bind(null, "Simulate send failed with delivery report requisition", [ michael@0: [DELIVERY_SENDING, DELIVERY_STATUS_PENDING, michael@0: DELIVERY_SENDING, DELIVERY_STATUS_PENDING], michael@0: [DELIVERY_ERROR, DELIVERY_STATUS_ERROR, michael@0: DELIVERY_ERROR, DELIVERY_STATUS_ERROR], michael@0: ])) michael@0: .then(test.bind(null, "Simulate sent without delivery report requisition", [ michael@0: [DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE, michael@0: DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE], michael@0: [DELIVERY_SENT, null, michael@0: DELIVERY_SENT, DELIVERY_STATUS_NOT_APPLICABLE], michael@0: ])) michael@0: .then(test.bind(null, "Simulate sent with delivery report success", [ michael@0: [DELIVERY_SENDING, DELIVERY_STATUS_PENDING, michael@0: DELIVERY_SENDING, DELIVERY_STATUS_PENDING], michael@0: [DELIVERY_SENT, null, michael@0: DELIVERY_SENT, DELIVERY_STATUS_PENDING], michael@0: [null, DELIVERY_STATUS_SUCCESS, michael@0: DELIVERY_SENT, DELIVERY_STATUS_SUCCESS], michael@0: ])) michael@0: .then(test.bind(null, "Simulate sent with delivery report error", [ michael@0: [DELIVERY_SENDING, DELIVERY_STATUS_PENDING, michael@0: DELIVERY_SENDING, DELIVERY_STATUS_PENDING], michael@0: [DELIVERY_SENT, null, michael@0: DELIVERY_SENT, DELIVERY_STATUS_PENDING], michael@0: [null, DELIVERY_ERROR, michael@0: DELIVERY_SENT, DELIVERY_ERROR], michael@0: ])); michael@0: });