dom/mobilemessage/tests/marionette/test_mmdb_setmessagedeliverybyid_sms.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:01b7ef689314
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 MARIONETTE_TIMEOUT = 60000;
5 MARIONETTE_HEAD_JS = 'head.js';
6
7 const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID =
8 "@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1";
9
10 const RECEIVER = "+1234567890";
11 const TEXT = "The quick brown fox jumps over the lazy dog.";
12
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";
18
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";
23
24 let dbService;
25
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 }
41
42 let deferred = Promise.defer();
43
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 }
52
53 is(aDomMessage.delivery, aParams[2], "message.delivery");
54 is(aDomMessage.deliveryStatus, aParams[3], "message.deliveryStatus");
55
56 deferred.resolve([aRv, aDomMessage]);
57 });
58
59 return deferred.promise;
60 }
61
62 function test(aTitle, aParamArray) {
63 log(aTitle);
64
65 return sendSmsWithSuccess(RECEIVER, TEXT)
66 .then(function(aDomMessage) {
67 let id = aDomMessage.id;
68
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 }
75
76 return promise;
77 });
78 }
79
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