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