Bug 850127 - 3/3: RIL & test cases. r=gwagner

This commit is contained in:
Vicamo Yang 2013-04-05 20:16:01 +08:00
parent 7d605a92d6
commit 8e7d8d6d08
13 changed files with 62 additions and 26 deletions

View File

@ -565,6 +565,7 @@ MobileMessageDatabaseService.prototype = {
}
if (aMessageRecord.type == "sms") {
return gMobileMessageService.createSmsMessage(aMessageRecord.id,
aMessageRecord.threadId,
aMessageRecord.delivery,
aMessageRecord.deliveryStatus,
aMessageRecord.sender,
@ -609,6 +610,7 @@ MobileMessageDatabaseService.prototype = {
}
}
return gMobileMessageService.createMmsMessage(aMessageRecord.id,
aMessageRecord.threadId,
aMessageRecord.delivery,
aMessageRecord.deliveryStatus,
aMessageRecord.sender,
@ -1929,6 +1931,7 @@ MobileMessageDatabaseService.prototype = {
let results = [];
for each (let item in event.target.result) {
results.push({
id: item.id,
senderOrReceiver: item.participantAddresses[0],
timestamp: item.lastTimestamp,
body: item.subject,

View File

@ -16,6 +16,8 @@ let gotSmsOnsent = false;
let gotReqOnsuccess = false;
let inSmsId = 0;
let outSmsId = 0;
let inThreadId = 0;
let outThreadId = 0;
let inSmsTimeStamp;
let outSmsTimeStamp;
@ -35,6 +37,8 @@ function simulateIncomingSms() {
ok(incomingSms.id, "sms id");
inSmsId = incomingSms.id;
log("Received SMS (id: " + inSmsId + ").");
ok(incomingSms.threadId, "thread id");
inThreadId = incomingSms.threadId;
is(incomingSms.body, inText, "msg body");
is(incomingSms.delivery, "received", "delivery");
is(incomingSms.deliveryStatus, "success", "deliveryStatus");
@ -62,6 +66,8 @@ function sendSms() {
ok(sentSms.id, "sms id");
outSmsId = sentSms.id;
log("Sent SMS (id: " + outSmsId + ").");
ok(sentSms.threadId, "thread id");
outThreadId = sentSms.threadId;
is(sentSms.body, outText, "msg body");
is(sentSms.delivery, "sent", "delivery");
is(sentSms.deliveryStatus, "pending", "deliveryStatus");
@ -111,6 +117,7 @@ function getReceivedSms() {
let foundSms = event.target.result;
is(foundSms.id, inSmsId, "SMS id matches");
log("Got SMS (id: " + foundSms.id + ").");
is(foundSms.threadId, inThreadId, "thread id matches");
is(foundSms.body, inText, "SMS msg text matches");
is(foundSms.delivery, "received", "delivery");
is(foundSms.deliveryStatus, "success", "deliveryStatus");
@ -144,6 +151,7 @@ function getSentSms() {
let foundSms = event.target.result;
is(foundSms.id, outSmsId, "SMS id matches");
log("Got SMS (id: " + foundSms.id + ").");
is(foundSms.threadId, outThreadId, "thread id matches");
is(foundSms.body, outText, "SMS msg text matches");
is(foundSms.delivery, "sent", "delivery");
is(foundSms.deliveryStatus, "pending", "deliveryStatus");

View File

@ -190,6 +190,7 @@ function verifyFoundMsgs(foundSmsList, reverse) {
}
for (var x = 0; x < numberMsgs; x++) {
is(foundSmsList[x].id, smsList[x].id, "id");
is(foundSmsList[x].threadId, smsList[x].threadId, "thread id");
is(foundSmsList[x].body, smsList[x].body, "body");
is(foundSmsList[x].delivery, smsList[x].delivery, "delivery");
is(foundSmsList[x].read, smsList[x].read, "read");

View File

@ -25,6 +25,7 @@ sms.onreceived = function onreceived(event) {
let message = event.message;
ok(message instanceof MozSmsMessage, "Message is instanceof MozSmsMessage");
ok(message.threadId, "thread id");
is(message.delivery, "received", "Message delivery");
is(message.deliveryStatus, "success", "Delivery status");
is(message.sender, SENDER, "Message sender");

View File

@ -27,6 +27,7 @@ function simulateIncomingSms() {
ok(incomingSms, "incoming sms");
ok(incomingSms.id, "sms id");
log("Received SMS (id: " + incomingSms.id + ").");
ok(incomingSms.threadId, "thread id");
is(incomingSms.body, msgText, "msg body");
is(incomingSms.delivery, "received", "delivery");
is(incomingSms.deliveryStatus, "success", "deliveryStatus");
@ -53,6 +54,7 @@ function verifySmsExists(incomingSms) {
ok(event.target.result, "smsrequest event.target.result");
let foundSms = event.target.result;
is(foundSms.id, incomingSms.id, "found SMS id matches");
is(foundSms.threadId, incomingSms.threadId, "found SMS thread id matches");
is(foundSms.body, msgText, "found SMS msg text matches");
is(foundSms.delivery, "received", "delivery");
is(foundSms.deliveryStatus, "success", "deliveryStatus");

View File

@ -36,6 +36,7 @@ function simulateIncomingSms() {
ok(incomingSms, "incoming sms");
ok(incomingSms.id, "sms id");
log("Received SMS (id: " + incomingSms.id + ").");
ok(incomingSms.threadId, "thread id");
is(incomingSms.body.length, msgText.length, "msg body length");
is(incomingSms.body, msgText, "msg body");
is(incomingSms.delivery, "received", "delivery");

View File

@ -33,6 +33,7 @@ function simulateIncomingSms() {
ok(incomingSms, "incoming sms");
ok(incomingSms.id, "sms id");
log("Received SMS (id: " + incomingSms.id + ").");
ok(incomingSms.threadId, "thread id");
is(incomingSms.body, msgText, "msg body");
is(incomingSms.delivery, "received", "delivery");
is(incomingSms.read, false, "read");
@ -57,6 +58,7 @@ function verifySmsExists(incomingSms) {
ok(event.target.result, "smsrequest event.target.result");
let foundSms = event.target.result;
is(foundSms.id, incomingSms.id, "found SMS id matches");
is(foundSms.threadId, incomingSms.threadId, "found SMS thread id matches");
is(foundSms.body, incomingSms.body, "found SMS msg text matches");
is(foundSms.delivery, "received", "delivery");
is(foundSms.read, false, "read");

View File

@ -31,13 +31,18 @@ function sendSmsPduToEmulator(pdu) {
}
const TIMESTAMP = Date.UTC(2000, 0, 1);
function checkMessage(message, id, messageClass) {
function checkMessage(message, id, threadId, messageClass) {
ok(message instanceof MozSmsMessage,
"message is instanceof " + message.constructor);
if (id == null) {
ok(message.id > 0, "message.id");
} else {
is(message.id, -1, "message.id");
is(message.id, id, "message.id");
}
if (threadId == null) {
ok(message.threadId > 0, "message.threadId");
} else {
is(message.threadId, threadId, "message.threadId");
}
is(message.delivery, "received", "message.delivery");
is(message.deliveryStatus, "success", "message.deliveryStatus");
@ -62,7 +67,7 @@ function test_message_class_0() {
sms.removeEventListener("received", onReceived);
let message = event.message;
checkMessage(message, -1, "class-0");
checkMessage(message, -1, 0, "class-0");
// Make sure the message is not stored.
let request = sms.getMessages(null, false);
@ -107,7 +112,7 @@ function doTestMessageClassGeneric(allDCSs, messageClass, next) {
sms.removeEventListener("received", onReceived);
// Make sure we can correctly receive the message
checkMessage(event.message, null, messageClass);
checkMessage(event.message, null, null, messageClass);
++dcsIndex;
if (dcsIndex >= allDCSs.length) {
@ -157,7 +162,7 @@ function test_message_class_2() {
function onReceived(event) {
if (pidIndex == 0) {
// Make sure we can correctly receive the message
checkMessage(event.message, null, "class-2");
checkMessage(event.message, null, null, "class-2");
next();
return;

View File

@ -32,6 +32,7 @@ function checkMessage(message, delivery, body) {
"message is instanceof " + message.constructor);
ok(message.id, "message.id");
ok(message.threadId, "message.threadId");
is(message.delivery, delivery, "message.delivery");
is(message.deliveryStatus, "pending", "message.deliveryStatus");
is(message.sender, SENDER, "message.sender");

View File

@ -32,6 +32,7 @@ function sendSms() {
ok(sentSms.id, "sms id");
smsId = sentSms.id;
log("Sent SMS (id: " + smsId + ").");
ok(sentSms.threadId, "thread id");
is(sentSms.body, msgText, "msg body");
is(sentSms.delivery, "sent", "delivery");
is(sentSms.deliveryStatus, "pending", "deliveryStatus");

View File

@ -37,6 +37,7 @@ function sendSms() {
ok(sentSms, "outgoing sms");
ok(sentSms.id, "sms id");
log("Sent SMS (id: " + sentSms.id + ").");
ok(sentSms.threadId, "thread id");
is(sentSms.body.length, msgText.length, "text length");
is(sentSms.body, msgText, "msg body");
is(sentSms.delivery, "sent", "delivery");
@ -78,6 +79,7 @@ function verifySmsExists(sentSms) {
ok(event.target.result, "smsrequest event.target.result");
let foundSms = event.target.result;
is(foundSms.id, sentSms.id, "found SMS id matches");
is(foundSms.threadId, sentSms.threadId, "found SMS thread id matches");
is(foundSms.body.length, sentSms.body.length, "found SMS text length");
is(foundSms.body, sentSms.body, "found SMS msg text matches");
log("Got SMS (id: " + foundSms.id + ") as expected.");

View File

@ -32,10 +32,11 @@ function run_test() {
* Ensure an SmsMessage object created has sensible initial values.
*/
add_test(function test_interface() {
let sms = newMessage(null, "sent", "pending", null, null, null, "normal",
new Date(), true);
let sms = newMessage(null, null, "sent", "pending", null, null, null,
"normal", new Date(), true);
do_check_true(sms instanceof Ci.nsIDOMMozSmsMessage);
do_check_eq(sms.id, 0);
do_check_eq(sms.threadId, 0);
do_check_eq(sms.delivery, "sent");
do_check_eq(sms.deliveryStatus, "pending");
do_check_eq(sms.receiver, null);
@ -51,12 +52,15 @@ add_test(function test_interface() {
* Verify that attributes are read-only.
*/
add_test(function test_readonly_attributes() {
let sms = newMessage(null, "received", "success", null, null, null,
let sms = newMessage(null, null, "received", "success", null, null, null,
"normal", new Date(), true);
sms.id = 1;
do_check_eq(sms.id, 0);
sms.threadId = 1;
do_check_eq(sms.threadId, 0);
sms.delivery = "sent";
do_check_eq(sms.delivery, "received");
@ -90,9 +94,10 @@ add_test(function test_readonly_attributes() {
*/
add_test(function test_timestamp_number() {
let ts = Date.now();
let sms = newMessage(42, "sent", "pending", "the sender", "the receiver",
let sms = newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "normal", ts, true);
do_check_eq(sms.id, 42);
do_check_eq(sms.threadId, 1);
do_check_eq(sms.delivery, "sent");
do_check_eq(sms.deliveryStatus, "pending");
do_check_eq(sms.sender, "the sender");
@ -110,9 +115,10 @@ add_test(function test_timestamp_number() {
*/
add_test(function test_timestamp_date() {
let date = new Date();
let sms = newMessage(42, "sent", "pending", "the sender", "the receiver",
let sms = newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "normal", date, true);
do_check_eq(sms.id, 42);
do_check_eq(sms.threadId, 1);
do_check_eq(sms.delivery, "sent");
do_check_eq(sms.deliveryStatus, "pending");
do_check_eq(sms.sender, "the sender");
@ -130,8 +136,8 @@ add_test(function test_timestamp_date() {
*/
add_test(function test_invalid_timestamp_float() {
do_check_throws(function() {
newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
"normal", 3.1415, true);
newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "normal", 3.1415, true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
@ -141,8 +147,8 @@ add_test(function test_invalid_timestamp_float() {
*/
add_test(function test_invalid_timestamp_null() {
do_check_throws(function() {
newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
"normal", null, true);
newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "normal", null, true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
@ -152,8 +158,8 @@ add_test(function test_invalid_timestamp_null() {
*/
add_test(function test_invalid_timestamp_undefined() {
do_check_throws(function() {
newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
"normal", undefined, true);
newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "normal", undefined, true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
@ -163,8 +169,8 @@ add_test(function test_invalid_timestamp_undefined() {
*/
add_test(function test_invalid_timestamp_object() {
do_check_throws(function() {
newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
"normal", {}, true);
newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "normal", {}, true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
@ -174,8 +180,8 @@ add_test(function test_invalid_timestamp_object() {
*/
add_test(function test_invalid_delivery_string() {
do_check_throws(function() {
newMessage(42, "this is invalid", "pending", "the sender", "the receiver",
"the body", "normal", new Date(), true);
newMessage(42, 1, "this is invalid", "pending", "the sender",
"the receiver", "the body", "normal", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
@ -185,7 +191,7 @@ add_test(function test_invalid_delivery_string() {
*/
add_test(function test_invalid_delivery_string() {
do_check_throws(function() {
newMessage(42, 1, "pending", "the sender", "the receiver", "the body",
newMessage(42, 1, 1, "pending", "the sender", "the receiver", "the body",
"normal", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
@ -196,7 +202,7 @@ add_test(function test_invalid_delivery_string() {
*/
add_test(function test_invalid_delivery_status_string() {
do_check_throws(function() {
newMessage(42, "sent", "this is invalid", "the sender", "the receiver",
newMessage(42, 1, "sent", "this is invalid", "the sender", "the receiver",
"the body", "normal", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
@ -207,7 +213,7 @@ add_test(function test_invalid_delivery_status_string() {
*/
add_test(function test_invalid_delivery_status_string() {
do_check_throws(function() {
newMessage(42, "sent", 1, "the sender", "the receiver", "the body",
newMessage(42, 1, "sent", 1, "the sender", "the receiver", "the body",
"normal", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
@ -218,7 +224,7 @@ add_test(function test_invalid_delivery_status_string() {
*/
add_test(function test_invalid_message_class_string() {
do_check_throws(function() {
newMessage(42, "sent", "pending", "the sender", "the receiver",
newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", "this is invalid", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
@ -229,8 +235,8 @@ add_test(function test_invalid_message_class_string() {
*/
add_test(function test_invalid_message_class_string() {
do_check_throws(function() {
newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
1, new Date(), true);
newMessage(42, 1, "sent", "pending", "the sender", "the receiver",
"the body", 1, new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});

View File

@ -1511,6 +1511,7 @@ RadioInterfaceLayer.prototype = {
gSystemMessenger.broadcastMessage(aName, {
type: aDomMessage.type,
id: aDomMessage.id,
threadId: aDomMessage.threadId,
delivery: aDomMessage.delivery,
deliveryStatus: aDomMessage.deliveryStatus,
sender: aDomMessage.sender,
@ -1591,12 +1592,14 @@ RadioInterfaceLayer.prototype = {
notifyReceived);
} else {
message.id = -1;
message.threadId = 0;
message.delivery = DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED;
message.deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS;
message.read = false;
let domMessage =
gMobileMessageService.createSmsMessage(message.id,
message.threadId,
message.delivery,
message.deliveryStatus,
message.sender,