1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobilemessage/tests/marionette/test_mmdb_setmessagedeliverybyid_sms.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 60000; 1.8 +MARIONETTE_HEAD_JS = 'head.js'; 1.9 + 1.10 +const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID = 1.11 + "@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1"; 1.12 + 1.13 +const RECEIVER = "+1234567890"; 1.14 +const TEXT = "The quick brown fox jumps over the lazy dog."; 1.15 + 1.16 +const DELIVERY_SENDING = "sending"; 1.17 +const DELIVERY_SENT = "sent"; 1.18 +const DELIVERY_RECEIVED = "received"; 1.19 +const DELIVERY_NOT_DOWNLOADED = "not-downloaded"; 1.20 +const DELIVERY_ERROR = "error"; 1.21 + 1.22 +const DELIVERY_STATUS_NOT_APPLICABLE = "not-applicable"; 1.23 +const DELIVERY_STATUS_SUCCESS = "success"; 1.24 +const DELIVERY_STATUS_PENDING = "pending"; 1.25 +const DELIVERY_STATUS_ERROR = "error"; 1.26 + 1.27 +let dbService; 1.28 + 1.29 +/** 1.30 + * @param aMessageId 1.31 + * @param aParams 1.32 + * An array of four elements [<delivery>, <deliveryStatus>, 1.33 + * <expected delivery>, <expected deliveryStatus>]. 1.34 + */ 1.35 +function setMessageDeliveryByMessageId(aMessageId, aParams) { 1.36 + if (!dbService) { 1.37 + dbService = Cc[RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID] 1.38 + .getService(Ci.nsIRilMobileMessageDatabaseService); 1.39 + if (!dbService) { 1.40 + log(" Failed to get database service."); 1.41 + return Promise.reject(); 1.42 + } 1.43 + } 1.44 + 1.45 + let deferred = Promise.defer(); 1.46 + 1.47 + log(" Set to " + aParams[0] + ":" + aParams[1]); 1.48 + dbService.setMessageDeliveryByMessageId(aMessageId, null, aParams[0], 1.49 + aParams[1], null, 1.50 + function(aRv, aDomMessage) { 1.51 + if (aRv !== Cr.NS_OK) { 1.52 + deferred.reject(aRv); 1.53 + return; 1.54 + } 1.55 + 1.56 + is(aDomMessage.delivery, aParams[2], "message.delivery"); 1.57 + is(aDomMessage.deliveryStatus, aParams[3], "message.deliveryStatus"); 1.58 + 1.59 + deferred.resolve([aRv, aDomMessage]); 1.60 + }); 1.61 + 1.62 + return deferred.promise; 1.63 +} 1.64 + 1.65 +function test(aTitle, aParamArray) { 1.66 + log(aTitle); 1.67 + 1.68 + return sendSmsWithSuccess(RECEIVER, TEXT) 1.69 + .then(function(aDomMessage) { 1.70 + let id = aDomMessage.id; 1.71 + 1.72 + let promise = Promise.resolve(); 1.73 + while (aParamArray.length) { 1.74 + let params = aParamArray.shift(); 1.75 + promise = 1.76 + promise.then(setMessageDeliveryByMessageId.bind(null, id, params)); 1.77 + } 1.78 + 1.79 + return promise; 1.80 + }); 1.81 +} 1.82 + 1.83 +startTestCommon(function testCaseMain() { 1.84 + return Promise.resolve() 1.85 + .then(test.bind(null, "Simulate send failed without delivery report requisition", [ 1.86 + [DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE, 1.87 + DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE], 1.88 + [DELIVERY_ERROR, DELIVERY_STATUS_ERROR, 1.89 + DELIVERY_ERROR, DELIVERY_STATUS_ERROR], 1.90 + ])) 1.91 + .then(test.bind(null, "Simulate send failed with delivery report requisition", [ 1.92 + [DELIVERY_SENDING, DELIVERY_STATUS_PENDING, 1.93 + DELIVERY_SENDING, DELIVERY_STATUS_PENDING], 1.94 + [DELIVERY_ERROR, DELIVERY_STATUS_ERROR, 1.95 + DELIVERY_ERROR, DELIVERY_STATUS_ERROR], 1.96 + ])) 1.97 + .then(test.bind(null, "Simulate sent without delivery report requisition", [ 1.98 + [DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE, 1.99 + DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE], 1.100 + [DELIVERY_SENT, null, 1.101 + DELIVERY_SENT, DELIVERY_STATUS_NOT_APPLICABLE], 1.102 + ])) 1.103 + .then(test.bind(null, "Simulate sent with delivery report success", [ 1.104 + [DELIVERY_SENDING, DELIVERY_STATUS_PENDING, 1.105 + DELIVERY_SENDING, DELIVERY_STATUS_PENDING], 1.106 + [DELIVERY_SENT, null, 1.107 + DELIVERY_SENT, DELIVERY_STATUS_PENDING], 1.108 + [null, DELIVERY_STATUS_SUCCESS, 1.109 + DELIVERY_SENT, DELIVERY_STATUS_SUCCESS], 1.110 + ])) 1.111 + .then(test.bind(null, "Simulate sent with delivery report error", [ 1.112 + [DELIVERY_SENDING, DELIVERY_STATUS_PENDING, 1.113 + DELIVERY_SENDING, DELIVERY_STATUS_PENDING], 1.114 + [DELIVERY_SENT, null, 1.115 + DELIVERY_SENT, DELIVERY_STATUS_PENDING], 1.116 + [null, DELIVERY_ERROR, 1.117 + DELIVERY_SENT, DELIVERY_ERROR], 1.118 + ])); 1.119 +});