Bug 990368 - Add corresponding test case to verify error cases in sending MMS. r=vyang

This commit is contained in:
Bevis Tseng 2014-04-01 16:43:53 +08:00
parent ebeb973098
commit 692f3793b3
4 changed files with 88 additions and 10 deletions

View File

@ -104,26 +104,42 @@ function sendSmsWithSuccess(aReceiver, aText) {
* otherwise.
*
* Fulfill params:
* message -- the failed MmsMessage
* {
* message, -- the failed MmsMessage
* error, -- error of the send request
* }
*
* Reject params: (none)
*
* @param aMmsParameters a MmsParameters instance.
*
* @param aSendParameters a MmsSendParameters instance.
*
* @return A deferred promise.
*/
function sendMmsWithFailure(aMmsParameters) {
function sendMmsWithFailure(aMmsParameters, aSendParameters) {
let deferred = Promise.defer();
manager.onfailed = function(event) {
manager.onfailed = null;
deferred.resolve(event.message);
};
let result = { message: null, error: null };
function got(which, value) {
result[which] = value;
if (result.message != null && result.error != null) {
deferred.resolve(result);
}
}
let request = manager.sendMMS(aMmsParameters);
manager.addEventListener("failed", function onfailed(event) {
manager.removeEventListener("failed", onfailed);
got("message", event.message);
});
let request = manager.sendMMS(aMmsParameters, aSendParameters);
request.onsuccess = function(event) {
deferred.reject();
};
request.onerror = function(event) {
got("error", event.target.error);
}
return deferred.promise;
}
@ -464,3 +480,26 @@ function startTestCommon(aTestCaseMain) {
.then(deleteAllMessages);
});
}
/**
* Helper to run the test case only needed in Multi-SIM environment.
*
* @param aTest
* A function which will be invoked w/o parameter.
* @return a Promise object.
*/
function runIfMultiSIM(aTest) {
let numRIL;
try {
numRIL = SpecialPowers.getIntPref("ril.numRadioInterfaces");
} catch (ex) {
numRIL = 1; // Pref not set.
}
if (numRIL > 1) {
return aTest();
} else {
log("Not a Multi-SIM environment. Test is skipped.");
return Promise.resolve();
}
}

View File

@ -46,3 +46,4 @@ qemu = true
[test_replace_short_message_type.js]
[test_mt_sms_concatenation.js]
[test_error_of_mms_manual_retrieval.js]
[test_error_of_mms_send.js]

View File

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
const kPrefRilRadioDisabled = "ril.radio.disabled";
function testSendFailed(aCause, aServiceId) {
log("testSendFailed, aCause: " + aCause + ", aServiceId: " + aServiceId);
let sendParameters;
if (aServiceId) {
sendParameters = { serviceId: aServiceId };
}
let mmsParameters = { subject: "Test",
receivers: ["+0987654321"],
attachments: [] };
return sendMmsWithFailure(mmsParameters, sendParameters)
.then((result) => {
is(result.error.name, aCause, "Checking failure cause.");
});
}
startTestCommon(function testCaseMain() {
return Promise.resolve()
.then(() => {
SpecialPowers.setBoolPref(kPrefRilRadioDisabled, true);
})
.then(() => testSendFailed("RadioDisabledError"))
.then(() => {
SpecialPowers.setBoolPref(kPrefRilRadioDisabled, false);
})
.then(() => runIfMultiSIM(
() => testSendFailed("NonActiveSimCardError", 1)));
});

View File

@ -38,9 +38,9 @@ function testMms(aProgressStr, aSubject) {
// We use a long long message subject so it will always fail.
return sendMmsWithFailure(mmsParameters)
.then(function(message) {
log(" MMS sent, retrieving thread of id " + message.threadId);
return getThreadById(message.threadId);
.then(function(result) {
log(" MMS sent, retrieving thread of id " + result.message.threadId);
return getThreadById(result.message.threadId);
})
.then(function(thread) {
log(" Got thread.lastMessageSubject = '" + thread.lastMessageSubject + "'");