mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 981577 - Part 3: Add Test case to verify RadioDisabledError. r=vyang
This commit is contained in:
parent
840c115c25
commit
4cebd5a07b
@ -372,6 +372,33 @@ function sendRawSmsToEmulator(aPdu) {
|
||||
return runEmulatorCmdSafe(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send multiple raw SMS TPDU to emulator and wait
|
||||
*
|
||||
* @param: aPdus
|
||||
* A array of hex strings. Each represents a SMS T-PDU.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- array of resolved Promise, where
|
||||
* result[0].message representing the received message.
|
||||
* result[1-n] represents the response of sent emulator command.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendMultipleRawSmsToEmulatorAndWait(aPdus) {
|
||||
let promises = [];
|
||||
|
||||
promises.push(waitForManagerEvent("received"));
|
||||
for (let pdu of aPdus) {
|
||||
promises.push(sendRawSmsToEmulator(pdu));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new array of id attribute of input messages.
|
||||
*
|
||||
|
@ -45,3 +45,4 @@ qemu = true
|
||||
[test_mmdb_full_storage.js]
|
||||
[test_replace_short_message_type.js]
|
||||
[test_mt_sms_concatenation.js]
|
||||
[test_error_of_mms_manual_retrieval.js]
|
||||
|
@ -0,0 +1,122 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
// We apply "chrome" context to be more flexible to
|
||||
// specify the content of M-Notification.ind such as iccId
|
||||
// for different kinds of testing.
|
||||
MARIONETTE_CONTEXT = "chrome";
|
||||
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
let MMS = {};
|
||||
Cu.import("resource://gre/modules/MmsPduHelper.jsm", MMS);
|
||||
|
||||
let gMobileMessageDatabaseService =
|
||||
Cc["@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1"]
|
||||
.getService(Ci.nsIRilMobileMessageDatabaseService);
|
||||
|
||||
let gUuidGenerator =
|
||||
Cc["@mozilla.org/uuid-generator;1"]
|
||||
.getService(Ci.nsIUUIDGenerator);
|
||||
|
||||
let gMmsService = Cc["@mozilla.org/mms/rilmmsservice;1"]
|
||||
.getService(Ci.nsIMmsService);
|
||||
|
||||
function saveMmsNotification() {
|
||||
log("saveMmsNotification()");
|
||||
let tid = gUuidGenerator.generateUUID().toString();
|
||||
tid = tid.substr(1, tid.length - 2); // strip parentheses {}.
|
||||
|
||||
let headers = {};
|
||||
headers["x-mms-message-type"] = MMS.MMS_PDU_TYPE_NOTIFICATION_IND;
|
||||
headers["x-mms-transaction-id"] = tid;
|
||||
headers["x-mms-mms-version"] = MMS.MMS_VERSION;
|
||||
headers["x-mms-message-class"] = "personal";
|
||||
headers["x-mms-message-size"] = 255;
|
||||
headers["x-mms-expiry"] = 24 * 60 * 60;
|
||||
headers["x-mms-content-location"] = "http://192.168.0.1/mms.cgi" + "?tid=" + tid;
|
||||
let notification = {
|
||||
headers: headers,
|
||||
type: "mms",
|
||||
delivery: "not-downloaded",
|
||||
deliveryStatus: "manual",
|
||||
timestamp: Date.now(),
|
||||
receivers: [],
|
||||
phoneNumber: "+0987654321",
|
||||
iccId: "01234567899876543210"
|
||||
};
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
||||
gMobileMessageDatabaseService
|
||||
.saveReceivedMessage(notification, function(aRv, aDomMessage) {
|
||||
log("saveReceivedMessage(): " + aRv);
|
||||
if (Components.isSuccessCode(aRv)) {
|
||||
deferred.resolve(aDomMessage);
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function deleteMessagesById(aIds) {
|
||||
log("deleteMessagesById()");
|
||||
let deferred = Promise.defer();
|
||||
let request = {
|
||||
notifyDeleteMessageFailed: function(aRv) {
|
||||
log("notifyDeleteMessageFailed()");
|
||||
deferred.reject();
|
||||
},
|
||||
notifyMessageDeleted: function(aDeleted, aLength) {
|
||||
log("notifyMessageDeleted()");
|
||||
deferred.resolve();
|
||||
},
|
||||
};
|
||||
gMobileMessageDatabaseService
|
||||
.deleteMessage(aIds, aIds.length, request);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function verifyErrorCause(aResponse, aCause) {
|
||||
is(aResponse, aCause, "Test error cause of retrieval.");
|
||||
|
||||
return deleteMessagesById([aResponse.id]);
|
||||
}
|
||||
|
||||
function retrieveMmsWithFailure(aId) {
|
||||
log("retrieveMmsWithFailure()");
|
||||
let deferred = Promise.defer();
|
||||
let request = {
|
||||
notifyGetMessageFailed: function(aRv) {
|
||||
log("notifyGetMessageFailed()");
|
||||
deferred.resolve(aRv);
|
||||
}
|
||||
};
|
||||
gMmsService.retrieve(aId, request);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function testRetrieve(aCause, aInit, aCleanup) {
|
||||
log("testRetrieve: aCause = " + aCause);
|
||||
return Promise.resolve()
|
||||
.then(() => { if (aInit) aInit(); })
|
||||
.then(saveMmsNotification)
|
||||
.then((message) => retrieveMmsWithFailure(message.id))
|
||||
.then((response) => verifyErrorCause(response, aCause))
|
||||
.then(() => { if (aCleanup) aCleanup(); });
|
||||
}
|
||||
|
||||
let setRadioDisabled = function(aDisabled) {
|
||||
log("set ril.radio.disabled to " + aDisabled);
|
||||
Services.prefs.setBoolPref("ril.radio.disabled", aDisabled);
|
||||
};
|
||||
|
||||
testRetrieve(Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR,
|
||||
setRadioDisabled.bind(null, true),
|
||||
setRadioDisabled.bind(null, false))
|
||||
.then(finish);
|
@ -87,17 +87,6 @@ function buildBinaryPdus(aDcs) {
|
||||
];
|
||||
}
|
||||
|
||||
function sendRawSmsAndWait(aPdus) {
|
||||
let promises = [];
|
||||
|
||||
promises.push(waitForManagerEvent("received"));
|
||||
for (let pdu of aPdus) {
|
||||
promises.push(sendRawSmsToEmulator(pdu));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
function verifyTextMessage(aMessage, aMessageClass) {
|
||||
is(aMessage.messageClass, aMessageClass, "SmsMessage class");
|
||||
is(aMessage.sender, SENDER, "SmsMessage sender");
|
||||
@ -114,14 +103,14 @@ function verifyBinaryMessage(aMessage) {
|
||||
|
||||
function testText(aDcs, aClass) {
|
||||
log("testText(): aDcs = " + aDcs + ", aClass = " + aClass);
|
||||
return sendRawSmsAndWait(buildTextPdus(aDcs))
|
||||
.then((resolutions) => verifyTextMessage(resolutions[0].message, aClass));
|
||||
return sendMultipleRawSmsToEmulatorAndWait(buildTextPdus(aDcs))
|
||||
.then((results) => verifyTextMessage(results[0].message, aClass));
|
||||
}
|
||||
|
||||
function testBinary(aDcs) {
|
||||
log("testBinary(): aDcs = " + aDcs);
|
||||
return sendRawSmsAndWait(buildBinaryPdus(aDcs))
|
||||
.then((resolutions) => verifyBinaryMessage(resolutions[0].message));
|
||||
return sendMultipleRawSmsToEmulatorAndWait(buildBinaryPdus(aDcs))
|
||||
.then((results) => verifyBinaryMessage(results[0].message));
|
||||
}
|
||||
|
||||
SpecialPowers.pushPrefEnv(
|
||||
|
@ -31,34 +31,6 @@ function buildPdu(aSender, aPid, aBody) {
|
||||
PDU_TIMESTAMP + PDU_UDL + aBody;
|
||||
}
|
||||
|
||||
let receivedMessage;
|
||||
function consumeReceivedMessage() {
|
||||
let message = receivedMessage;
|
||||
receivedMessage = null;
|
||||
return message;
|
||||
}
|
||||
|
||||
function waitForIncomingMessage() {
|
||||
if (receivedMessage) {
|
||||
return consumeReceivedMessage();
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
||||
waitFor(function() {
|
||||
deferred.resolve(consumeReceivedMessage());
|
||||
}, function() {
|
||||
return receivedMessage != null;
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function sendRawSmsAndWait(aPdu) {
|
||||
sendRawSmsToEmulator(aPdu);
|
||||
return waitForIncomingMessage();
|
||||
}
|
||||
|
||||
function verifyReplacing(aVictim, aSender, aPid, aCompare) {
|
||||
let readableSender = aSender === PDU_SENDER_0 ? SENDER_0 : SENDER_1;
|
||||
log(" Checking ('" + readableSender + "', '" + aPid + "', '" + BODY_B + "')");
|
||||
@ -66,12 +38,13 @@ function verifyReplacing(aVictim, aSender, aPid, aCompare) {
|
||||
let pdu = buildPdu(aSender, aPid, PDU_UD_B);
|
||||
ok(true, "Sending " + pdu);
|
||||
|
||||
return sendRawSmsAndWait(pdu)
|
||||
.then(function(aReceivedMessage) {
|
||||
is(aReceivedMessage.sender, readableSender, "SmsMessage sender");
|
||||
is(aReceivedMessage.body, BODY_B, "SmsMessage body");
|
||||
return sendMultipleRawSmsToEmulatorAndWait([pdu])
|
||||
.then(function(results) {
|
||||
let receivedMsg = results[0].message;
|
||||
is(receivedMsg.sender, readableSender, "SmsMessage sender");
|
||||
is(receivedMsg.body, BODY_B, "SmsMessage body");
|
||||
|
||||
aCompare(aReceivedMessage.id, aVictim.id, "SmsMessage id");
|
||||
aCompare(receivedMsg.id, aVictim.id, "SmsMessage id");
|
||||
});
|
||||
}
|
||||
|
||||
@ -86,16 +59,17 @@ function verifyReplaced(aVictim, aSender, aPid) {
|
||||
function testPid(aPid) {
|
||||
log("Test message PID '" + aPid + "'");
|
||||
|
||||
return sendRawSmsAndWait(buildPdu(PDU_SENDER_0, aPid, PDU_UD_A))
|
||||
.then(function(aReceivedMessage) {
|
||||
return sendMultipleRawSmsToEmulatorAndWait([buildPdu(PDU_SENDER_0, aPid, PDU_UD_A)])
|
||||
.then(function(results) {
|
||||
let receivedMsg = results[0].message;
|
||||
let promise = Promise.resolve();
|
||||
|
||||
for (let pid of PDU_PIDS) {
|
||||
let verify = (aPid !== PDU_PID_NORMAL && pid === aPid)
|
||||
? verifyReplaced : verifyNotReplaced;
|
||||
promise =
|
||||
promise.then(verify.bind(null, aReceivedMessage, PDU_SENDER_0, pid))
|
||||
.then(verifyNotReplaced.bind(null, aReceivedMessage,
|
||||
promise.then(verify.bind(null, receivedMsg, PDU_SENDER_0, pid))
|
||||
.then(verifyNotReplaced.bind(null, receivedMsg,
|
||||
PDU_SENDER_1, pid));
|
||||
}
|
||||
|
||||
@ -104,18 +78,11 @@ function testPid(aPid) {
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
manager.onreceived = function(event) {
|
||||
receivedMessage = event.message;
|
||||
};
|
||||
|
||||
let promise = Promise.resolve();
|
||||
for (let pid of PDU_PIDS) {
|
||||
promise = promise.then(testPid.bind(null, pid))
|
||||
.then(deleteAllMessages);
|
||||
}
|
||||
|
||||
// Clear |manager.onreceived| handler.
|
||||
return promise.then(function() {
|
||||
manager.onreceived = null;
|
||||
});
|
||||
return promise;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user