зеркало из https://github.com/mozilla/gecko-dev.git
Bug 866938 - 4.c/4: rewrite test_mmdb_setmessagedeliverybyid_sms.js to use mmdb_head.js. r=gene
This commit is contained in:
Родитель
95ec3a9fb9
Коммит
f6c1d8f94f
|
@ -2,14 +2,15 @@
|
|||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
MARIONETTE_HEAD_JS = 'mmdb_head.js';
|
||||
|
||||
const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID =
|
||||
"@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1";
|
||||
const DBNAME = "test_mmdb_setmessagedeliverybyid_sms:" + newUUID();
|
||||
|
||||
const RECEIVER = "+1234567890";
|
||||
const TEXT = "The quick brown fox jumps over the lazy dog.";
|
||||
|
||||
const MESSAGE_STORE_NAME = "sms";
|
||||
|
||||
const DELIVERY_SENDING = "sending";
|
||||
const DELIVERY_SENT = "sent";
|
||||
const DELIVERY_RECEIVED = "received";
|
||||
|
@ -21,96 +22,113 @@ const DELIVERY_STATUS_SUCCESS = "success";
|
|||
const DELIVERY_STATUS_PENDING = "pending";
|
||||
const DELIVERY_STATUS_ERROR = "error";
|
||||
|
||||
let dbService;
|
||||
function verify(aMmdb, aMessageId, aDelivery, aDeliveryStatus, aRv, aDomMessage) {
|
||||
log(" Verify(" + aMessageId + ", " + aDelivery + ", " + aDeliveryStatus + ")");
|
||||
|
||||
/**
|
||||
* @param aMessageId
|
||||
* @param aParams
|
||||
* An array of four elements [<delivery>, <deliveryStatus>,
|
||||
* <expected delivery>, <expected deliveryStatus>].
|
||||
*/
|
||||
function setMessageDeliveryByMessageId(aMessageId, aParams) {
|
||||
if (!dbService) {
|
||||
dbService = Cc[RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID]
|
||||
.getService(Ci.nsIRilMobileMessageDatabaseService);
|
||||
if (!dbService) {
|
||||
log(" Failed to get database service.");
|
||||
return Promise.reject();
|
||||
}
|
||||
}
|
||||
ok(Components.isSuccessCode(aRv), "Components.isSuccessCode(" + aRv + ")");
|
||||
ok(aDomMessage, "DOM message validity");
|
||||
is(aDomMessage.delivery, aDelivery, "message.delivery");
|
||||
is(aDomMessage.deliveryStatus, aDeliveryStatus, "message.deliveryStatus");
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
||||
log(" Set to " + aParams[0] + ":" + aParams[1]);
|
||||
dbService.setMessageDeliveryByMessageId(aMessageId, null, aParams[0],
|
||||
aParams[1], null,
|
||||
function(aRv, aDomMessage) {
|
||||
if (aRv !== Cr.NS_OK) {
|
||||
deferred.reject(aRv);
|
||||
return;
|
||||
}
|
||||
// Verify deliveryIndex, sentTimestamp and deliveryTimestamp
|
||||
aMmdb.newTxn("readonly", function(aError, aTransaction, aMessageStore) {
|
||||
let messageRecord;
|
||||
aTransaction.oncomplete = function() {
|
||||
ok(true, "transaction complete");
|
||||
|
||||
is(aDomMessage.delivery, aParams[2], "message.delivery");
|
||||
is(aDomMessage.deliveryStatus, aParams[3], "message.deliveryStatus");
|
||||
is(messageRecord.deliveryIndex[0], aDelivery,
|
||||
"messageRecord.deliveryIndex[0]");
|
||||
is(messageRecord.deliveryIndex[1], messageRecord.timestamp,
|
||||
"messageRecord.deliveryIndex[1]");
|
||||
if (aDelivery == DELIVERY_SENT) {
|
||||
ok(messageRecord.sentTimestamp >= messageRecord.timestamp,
|
||||
"messageRecord.sentTimestamp");
|
||||
}
|
||||
if (aDeliveryStatus == DELIVERY_STATUS_SUCCESS) {
|
||||
ok(messageRecord.deliveryTimestamp >= messageRecord.timestamp,
|
||||
"messageRecord.deliveryTimestamp");
|
||||
}
|
||||
|
||||
deferred.resolve([aRv, aDomMessage]);
|
||||
});
|
||||
deferred.resolve(aMmdb);
|
||||
};
|
||||
|
||||
aMessageStore.get(aMessageId).onsuccess = function(event) {
|
||||
messageRecord = event.target.result;
|
||||
ok(true, "Got messageRecord " + messageRecord.id);
|
||||
};
|
||||
}, [MESSAGE_STORE_NAME]);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function test(aTitle, aParamArray) {
|
||||
function test(aTitle, aMmdb, aDeliveryStatusRequested, aParamArray) {
|
||||
log(aTitle);
|
||||
|
||||
return sendSmsWithSuccess(RECEIVER, TEXT)
|
||||
.then(function(aDomMessage) {
|
||||
let id = aDomMessage.id;
|
||||
|
||||
let promise = Promise.resolve();
|
||||
let message = {
|
||||
type: "sms",
|
||||
sender: null,
|
||||
timestamp: Date.now(),
|
||||
deliveryStatusRequested: aDeliveryStatusRequested,
|
||||
receiver: RECEIVER,
|
||||
iccId: null,
|
||||
body: TEXT,
|
||||
};
|
||||
return saveSendingMessage(aMmdb, message)
|
||||
.then(function(aValues) {
|
||||
let [resultCode, domMessage] = aValues;
|
||||
let promise =
|
||||
verify(aMmdb, domMessage.id, DELIVERY_SENDING,
|
||||
(aDeliveryStatusRequested ? DELIVERY_STATUS_PENDING
|
||||
: DELIVERY_STATUS_NOT_APPLICABLE),
|
||||
resultCode, domMessage);
|
||||
while (aParamArray.length) {
|
||||
let params = aParamArray.shift();
|
||||
promise =
|
||||
promise.then(setMessageDeliveryByMessageId.bind(null, id, params));
|
||||
let v = verify.bind(null, aMmdb, domMessage.id, params[2], params[3]);
|
||||
promise = promise
|
||||
.then(() => {
|
||||
log(" Set to " + params[0] + ":" + params[1]);
|
||||
return setMessageDeliveryByMessageId(aMmdb, domMessage.id, null,
|
||||
params[0], params[1], null);
|
||||
})
|
||||
.then((aValues) => v(aValues[0], aValues[1]));
|
||||
}
|
||||
|
||||
return promise;
|
||||
});
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
return Promise.resolve()
|
||||
.then(test.bind(null, "Simulate send failed without delivery report requisition", [
|
||||
[DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE,
|
||||
DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE],
|
||||
startTestBase(function testCaseMain() {
|
||||
return initMobileMessageDB(newMobileMessageDB(), DBNAME, 0)
|
||||
.then((aMmdb) => test("Simulate send failed without delivery report requisition",
|
||||
aMmdb, false, [
|
||||
[DELIVERY_ERROR, DELIVERY_STATUS_ERROR,
|
||||
DELIVERY_ERROR, DELIVERY_STATUS_ERROR],
|
||||
]))
|
||||
.then(test.bind(null, "Simulate send failed with delivery report requisition", [
|
||||
[DELIVERY_SENDING, DELIVERY_STATUS_PENDING,
|
||||
DELIVERY_SENDING, DELIVERY_STATUS_PENDING],
|
||||
.then((aMmdb) => test("Simulate send failed with delivery report requisition",
|
||||
aMmdb, true, [
|
||||
[DELIVERY_ERROR, DELIVERY_STATUS_ERROR,
|
||||
DELIVERY_ERROR, DELIVERY_STATUS_ERROR],
|
||||
]))
|
||||
.then(test.bind(null, "Simulate sent without delivery report requisition", [
|
||||
[DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE,
|
||||
DELIVERY_SENDING, DELIVERY_STATUS_NOT_APPLICABLE],
|
||||
.then((aMmdb) => test("Simulate sent without delivery report requisition",
|
||||
aMmdb, false, [
|
||||
[DELIVERY_SENT, null,
|
||||
DELIVERY_SENT, DELIVERY_STATUS_NOT_APPLICABLE],
|
||||
]))
|
||||
.then(test.bind(null, "Simulate sent with delivery report success", [
|
||||
[DELIVERY_SENDING, DELIVERY_STATUS_PENDING,
|
||||
DELIVERY_SENDING, DELIVERY_STATUS_PENDING],
|
||||
.then((aMmdb) => test("Simulate sent with delivery report success",
|
||||
aMmdb, true, [
|
||||
[DELIVERY_SENT, null,
|
||||
DELIVERY_SENT, DELIVERY_STATUS_PENDING],
|
||||
[null, DELIVERY_STATUS_SUCCESS,
|
||||
DELIVERY_SENT, DELIVERY_STATUS_SUCCESS],
|
||||
]))
|
||||
.then(test.bind(null, "Simulate sent with delivery report error", [
|
||||
[DELIVERY_SENDING, DELIVERY_STATUS_PENDING,
|
||||
DELIVERY_SENDING, DELIVERY_STATUS_PENDING],
|
||||
.then((aMmdb) => test("Simulate sent with delivery report error",
|
||||
aMmdb, true, [
|
||||
[DELIVERY_SENT, null,
|
||||
DELIVERY_SENT, DELIVERY_STATUS_PENDING],
|
||||
[null, DELIVERY_ERROR,
|
||||
DELIVERY_SENT, DELIVERY_ERROR],
|
||||
]));
|
||||
]))
|
||||
.then(closeMobileMessageDB);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче