Bug 786782 - Part 2/2: test case, r=marshall_law

This commit is contained in:
Vicamo Yang 2012-10-11 19:01:55 +08:00
parent a5da143cef
commit e040cf95b5

View File

@ -10,9 +10,23 @@ SpecialPowers.addPermission("mobileconnection", true, document);
let sms = window.navigator.mozSms;
let receiver = "5555552368";
let body = "Hello SMS world!";
const SHORT_BODY = "Hello SMS world!";
const LONG_BODY = "Let me not to the marriage of true minds\n"
+ "Admit impediments. Love is not love\n"
+ "Which alters when it alteration finds,\n"
+ "Or bends with the remover to remove:\n\n"
+ "O, no! it is an ever-fix`ed mark,\n"
+ "That looks on tempests and is never shaken;\n"
+ "It is the star to every wand'ring bark,\n"
+ "Whose worth's unknown, although his heighth be taken.\n\n"
+ "Love's not Time's fool, though rosy lips and cheeks\n"
+ "Within his bending sickle's compass come;\n"
+ "Love alters not with his brief hours and weeks,\n"
+ "But bears it out even to the edge of doom:\n\n"
+ "If this be error and upon me proved,\n"
+ "I never writ, nor no man ever loved. ";
function checkSentMessage(message, sentDate) {
function checkSentMessage(message, body, sentDate) {
ok(message, "message is valid");
ok(message instanceof MozSmsMessage,
"message is instanceof " + message.constructor);
@ -31,8 +45,8 @@ function checkSentMessage(message, sentDate) {
}
let sentMessages = null;
function checkSameSentMessage(message, now) {
checkSentMessage(message, now);
function checkSameSentMessage(message, body, now) {
checkSentMessage(message, body, now);
let sentMessage = sentMessages[message.id];
if (!sentMessage) {
@ -47,7 +61,7 @@ function checkSameSentMessage(message, now) {
"the messages got from onsent event and request result must be the same");
}
function doSendMessageAndCheckSuccess(receivers, callback) {
function doSendMessageAndCheckSuccess(receivers, body, callback) {
sentMessages = [];
let now = Date.now();
@ -69,7 +83,7 @@ function doSendMessageAndCheckSuccess(receivers, callback) {
"event is instanceof " + event.constructor);
// Event listener is removed in done().
checkSameSentMessage(event.message, now);
checkSameSentMessage(event.message, body, now);
done();
}
@ -81,7 +95,7 @@ function doSendMessageAndCheckSuccess(receivers, callback) {
"event.target is instanceof " + event.target.constructor);
event.target.removeEventListener("success", onRequestSuccess);
checkSameSentMessage(event.target.result, now);
checkSameSentMessage(event.target.result, body, now);
done();
}
@ -119,13 +133,19 @@ function doSendMessageAndCheckSuccess(receivers, callback) {
function testSendMessage() {
log("Testing sending message to one receiver:");
doSendMessageAndCheckSuccess(receiver, testSendMessageToMultipleRecipients);
doSendMessageAndCheckSuccess(receiver, SHORT_BODY, testSendMultipartMessage);
}
function testSendMultipartMessage() {
log("Testing sending message to one receiver:");
doSendMessageAndCheckSuccess(receiver, LONG_BODY,
testSendMessageToMultipleRecipients);
}
function testSendMessageToMultipleRecipients() {
log("Testing sending message to multiple receivers:");
// TODO: bug 788928 - add test cases for nsIDOMSmsManager.ondelivered event
doSendMessageAndCheckSuccess([receiver, receiver], cleanUp);
doSendMessageAndCheckSuccess([receiver, receiver], SHORT_BODY, cleanUp);
}
function cleanUp() {