dom/mobilemessage/tests/marionette/test_mmdb_setmessagedeliverybyid_sms.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 60000;
     5 MARIONETTE_HEAD_JS = 'head.js';
     7 const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID =
     8   "@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1";
    10 const RECEIVER = "+1234567890";
    11 const TEXT = "The quick brown fox jumps over the lazy dog.";
    13 const DELIVERY_SENDING = "sending";
    14 const DELIVERY_SENT = "sent";
    15 const DELIVERY_RECEIVED = "received";
    16 const DELIVERY_NOT_DOWNLOADED = "not-downloaded";
    17 const DELIVERY_ERROR = "error";
    19 const DELIVERY_STATUS_NOT_APPLICABLE = "not-applicable";
    20 const DELIVERY_STATUS_SUCCESS = "success";
    21 const DELIVERY_STATUS_PENDING = "pending";
    22 const DELIVERY_STATUS_ERROR = "error";
    24 let dbService;
    26 /**
    27  * @param aMessageId
    28  * @param aParams
    29  *        An array of four elements [<delivery>, <deliveryStatus>,
    30  *        <expected delivery>, <expected deliveryStatus>].
    31  */
    32 function setMessageDeliveryByMessageId(aMessageId, aParams) {
    33   if (!dbService) {
    34     dbService = Cc[RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID]
    35                 .getService(Ci.nsIRilMobileMessageDatabaseService);
    36     if (!dbService) {
    37       log("  Failed to get database service.");
    38       return Promise.reject();
    39     }
    40   }
    42   let deferred = Promise.defer();
    44   log("  Set to " + aParams[0] + ":" + aParams[1]);
    45   dbService.setMessageDeliveryByMessageId(aMessageId, null, aParams[0],
    46                                           aParams[1], null,
    47                                           function(aRv, aDomMessage) {
    48     if (aRv !== Cr.NS_OK) {
    49       deferred.reject(aRv);
    50       return;
    51     }
    53     is(aDomMessage.delivery, aParams[2], "message.delivery");
    54     is(aDomMessage.deliveryStatus, aParams[3], "message.deliveryStatus");
    56     deferred.resolve([aRv, aDomMessage]);
    57   });
    59   return deferred.promise;
    60 }
    62 function test(aTitle, aParamArray) {
    63   log(aTitle);
    65   return sendSmsWithSuccess(RECEIVER, TEXT)
    66     .then(function(aDomMessage) {
    67       let id = aDomMessage.id;
    69       let promise = Promise.resolve();
    70       while (aParamArray.length) {
    71         let params = aParamArray.shift();
    72         promise =
    73           promise.then(setMessageDeliveryByMessageId.bind(null, id, params));
    74       }
    76       return promise;
    77     });
    78 }
    80 startTestCommon(function testCaseMain() {
    81   return Promise.resolve()
    82     .then(test.bind(null, "Simulate send failed without delivery report requisition", [
    83       [DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE,
    84        DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE],
    85       [DELIVERY_ERROR, DELIVERY_STATUS_ERROR,
    86        DELIVERY_ERROR, DELIVERY_STATUS_ERROR],
    87     ]))
    88     .then(test.bind(null, "Simulate send failed with delivery report requisition", [
    89       [DELIVERY_SENDING, DELIVERY_STATUS_PENDING,
    90        DELIVERY_SENDING, DELIVERY_STATUS_PENDING],
    91       [DELIVERY_ERROR, DELIVERY_STATUS_ERROR,
    92        DELIVERY_ERROR, DELIVERY_STATUS_ERROR],
    93     ]))
    94     .then(test.bind(null, "Simulate sent without delivery report requisition", [
    95       [DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE,
    96        DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE],
    97       [DELIVERY_SENT, null,
    98        DELIVERY_SENT, DELIVERY_STATUS_NOT_APPLICABLE],
    99     ]))
   100     .then(test.bind(null, "Simulate sent with delivery report success", [
   101       [DELIVERY_SENDING, DELIVERY_STATUS_PENDING,
   102        DELIVERY_SENDING, DELIVERY_STATUS_PENDING],
   103       [DELIVERY_SENT, null,
   104        DELIVERY_SENT, DELIVERY_STATUS_PENDING],
   105       [null, DELIVERY_STATUS_SUCCESS,
   106        DELIVERY_SENT, DELIVERY_STATUS_SUCCESS],
   107     ]))
   108     .then(test.bind(null, "Simulate sent with delivery report error", [
   109       [DELIVERY_SENDING, DELIVERY_STATUS_PENDING,
   110        DELIVERY_SENDING, DELIVERY_STATUS_PENDING],
   111       [DELIVERY_SENT, null,
   112        DELIVERY_SENT, DELIVERY_STATUS_PENDING],
   113       [null, DELIVERY_ERROR,
   114        DELIVERY_SENT, DELIVERY_ERROR],
   115     ]));
   116 });

mercurial