Bug 742790 - Part 5/5: test cases, r=marshall_law

This commit is contained in:
Vicamo Yang 2012-10-30 18:53:35 +08:00
parent e86f728f7a
commit 5d43612b5f
7 changed files with 57 additions and 16 deletions

View File

@ -36,6 +36,7 @@ function simulateIncomingSms() {
log("Received SMS (id: " + inSmsId + ")."); log("Received SMS (id: " + inSmsId + ").");
is(incomingSms.body, inText, "msg body"); is(incomingSms.body, inText, "msg body");
is(incomingSms.delivery, "received", "delivery"); is(incomingSms.delivery, "received", "delivery");
is(incomingSms.deliveryStatus, "success", "deliveryStatus");
is(incomingSms.read, false, "read"); is(incomingSms.read, false, "read");
is(incomingSms.receiver, null, "receiver"); is(incomingSms.receiver, null, "receiver");
is(incomingSms.sender, remoteNumber, "sender"); is(incomingSms.sender, remoteNumber, "sender");
@ -61,6 +62,7 @@ function sendSms() {
log("Sent SMS (id: " + outSmsId + ")."); log("Sent SMS (id: " + outSmsId + ").");
is(sentSms.body, outText, "msg body"); is(sentSms.body, outText, "msg body");
is(sentSms.delivery, "sent", "delivery"); is(sentSms.delivery, "sent", "delivery");
is(sentSms.deliveryStatus, "pending", "deliveryStatus");
is(sentSms.read, true, "read"); is(sentSms.read, true, "read");
is(sentSms.receiver, remoteNumber, "receiver"); is(sentSms.receiver, remoteNumber, "receiver");
is(sentSms.sender, null, "sender"); is(sentSms.sender, null, "sender");
@ -108,6 +110,7 @@ function getReceivedSms() {
log("Got SMS (id: " + foundSms.id + ")."); log("Got SMS (id: " + foundSms.id + ").");
is(foundSms.body, inText, "SMS msg text matches"); is(foundSms.body, inText, "SMS msg text matches");
is(foundSms.delivery, "received", "delivery"); is(foundSms.delivery, "received", "delivery");
is(foundSms.deliveryStatus, "success", "deliveryStatus");
is(foundSms.read, false, "read"); is(foundSms.read, false, "read");
is(foundSms.receiver, myNumber, "receiver"); is(foundSms.receiver, myNumber, "receiver");
is(foundSms.sender, remoteNumber, "sender"); is(foundSms.sender, remoteNumber, "sender");
@ -139,6 +142,7 @@ function getSentSms() {
log("Got SMS (id: " + foundSms.id + ")."); log("Got SMS (id: " + foundSms.id + ").");
is(foundSms.body, outText, "SMS msg text matches"); is(foundSms.body, outText, "SMS msg text matches");
is(foundSms.delivery, "sent", "delivery"); is(foundSms.delivery, "sent", "delivery");
is(foundSms.deliveryStatus, "pending", "deliveryStatus");
is(foundSms.read, true, "read"); is(foundSms.read, true, "read");
is(foundSms.receiver, remoteNumber, "receiver"); is(foundSms.receiver, remoteNumber, "receiver");
is(foundSms.sender, myNumber, "sender"); is(foundSms.sender, myNumber, "sender");

View File

@ -25,6 +25,7 @@ sms.onreceived = function onreceived(event) {
ok(message instanceof MozSmsMessage); ok(message instanceof MozSmsMessage);
is(message.delivery, "received"); is(message.delivery, "received");
is(message.deliveryStatus, "success");
is(message.sender, sender); is(message.sender, sender);
is(message.receiver, null); is(message.receiver, null);
is(message.body, body); is(message.body, body);

View File

@ -27,6 +27,7 @@ function simulateIncomingSms() {
log("Received SMS (id: " + incomingSms.id + ")."); log("Received SMS (id: " + incomingSms.id + ").");
is(incomingSms.body, msgText, "msg body"); is(incomingSms.body, msgText, "msg body");
is(incomingSms.delivery, "received", "delivery"); is(incomingSms.delivery, "received", "delivery");
is(incomingSms.deliveryStatus, "success", "deliveryStatus");
is(incomingSms.read, false, "read"); is(incomingSms.read, false, "read");
is(incomingSms.receiver, null, "receiver"); is(incomingSms.receiver, null, "receiver");
is(incomingSms.sender, fromNumber, "sender"); is(incomingSms.sender, fromNumber, "sender");

View File

@ -40,6 +40,7 @@ function checkMessage(message, id) {
is(message.id, -1, "message.id"); is(message.id, -1, "message.id");
} }
is(message.delivery, "received", "message.delivery"); is(message.delivery, "received", "message.delivery");
is(message.deliveryStatus, "success", "message.deliveryStatus");
is(message.sender, "+1", "message.sender"); is(message.sender, "+1", "message.sender");
is(message.body, "A", "message.body"); is(message.body, "A", "message.body");
ok(message.timestamp instanceof Date, ok(message.timestamp instanceof Date,

View File

@ -33,6 +33,7 @@ function checkSentMessage(message, body, sentDate) {
ok(message.id, "message.id is valid"); ok(message.id, "message.id is valid");
is(message.delivery, "sent", "message.delivery"); is(message.delivery, "sent", "message.delivery");
is(message.deliveryStatus, "pending", "message.deliveryStatus");
is(message.sender, null, "message.sender"); is(message.sender, null, "message.sender");
is(message.receiver, receiver, "message.receiver"); is(message.receiver, receiver, "message.receiver");
is(message.body, body, "message.body"); is(message.body, body, "message.body");

View File

@ -32,6 +32,7 @@ function sendSms() {
log("Sent SMS (id: " + smsId + ")."); log("Sent SMS (id: " + smsId + ").");
is(sentSms.body, msgText, "msg body"); is(sentSms.body, msgText, "msg body");
is(sentSms.delivery, "sent", "delivery"); is(sentSms.delivery, "sent", "delivery");
is(sentSms.deliveryStatus, "pending", "deliveryStatus");
is(sentSms.read, true, "read"); is(sentSms.read, true, "read");
is(sentSms.receiver, destNumber, "receiver"); is(sentSms.receiver, destNumber, "receiver");
is(sentSms.sender, null, "sender"); is(sentSms.sender, null, "sender");

View File

@ -32,10 +32,12 @@ function run_test() {
* Ensure an SmsMessage object created has sensible initial values. * Ensure an SmsMessage object created has sensible initial values.
*/ */
add_test(function test_interface() { add_test(function test_interface() {
let sms = newMessage(null, "sent", null, null, null, new Date(), true); let sms = newMessage(null, "sent", "pending", null, null, null, new Date(),
true);
do_check_true(sms instanceof Ci.nsIDOMMozSmsMessage); do_check_true(sms instanceof Ci.nsIDOMMozSmsMessage);
do_check_eq(sms.id, 0); do_check_eq(sms.id, 0);
do_check_eq(sms.delivery, "sent"); do_check_eq(sms.delivery, "sent");
do_check_eq(sms.deliveryStatus, "pending");
do_check_eq(sms.receiver, null); do_check_eq(sms.receiver, null);
do_check_eq(sms.sender, null); do_check_eq(sms.sender, null);
do_check_eq(sms.body, null); do_check_eq(sms.body, null);
@ -48,7 +50,8 @@ add_test(function test_interface() {
* Verify that attributes are read-only. * Verify that attributes are read-only.
*/ */
add_test(function test_readonly_attributes() { add_test(function test_readonly_attributes() {
let sms = newMessage(null, "received", null, null, null, new Date(), true); let sms = newMessage(null, "received", "success", null, null, null,
new Date(), true);
sms.id = 1; sms.id = 1;
do_check_eq(sms.id, 0); do_check_eq(sms.id, 0);
@ -56,6 +59,9 @@ add_test(function test_readonly_attributes() {
sms.delivery = "sent"; sms.delivery = "sent";
do_check_eq(sms.delivery, "received"); do_check_eq(sms.delivery, "received");
sms.deliveryStatus = "pending";
do_check_eq(sms.deliveryStatus, "success");
sms.receiver = "a receiver"; sms.receiver = "a receiver";
do_check_eq(sms.receiver, null); do_check_eq(sms.receiver, null);
@ -80,10 +86,11 @@ add_test(function test_readonly_attributes() {
*/ */
add_test(function test_timestamp_number() { add_test(function test_timestamp_number() {
let ts = Date.now(); let ts = Date.now();
let sms = newMessage(42, "sent", "the sender", "the receiver", "the body", ts, let sms = newMessage(42, "sent", "pending", "the sender", "the receiver",
true); "the body", ts, true);
do_check_eq(sms.id, 42); do_check_eq(sms.id, 42);
do_check_eq(sms.delivery, "sent"); do_check_eq(sms.delivery, "sent");
do_check_eq(sms.deliveryStatus, "pending");
do_check_eq(sms.sender, "the sender"); do_check_eq(sms.sender, "the sender");
do_check_eq(sms.receiver, "the receiver"); do_check_eq(sms.receiver, "the receiver");
do_check_eq(sms.body, "the body"); do_check_eq(sms.body, "the body");
@ -98,10 +105,11 @@ add_test(function test_timestamp_number() {
*/ */
add_test(function test_timestamp_date() { add_test(function test_timestamp_date() {
let date = new Date(); let date = new Date();
let sms = newMessage(42, "sent", "the sender", "the receiver", "the body", let sms = newMessage(42, "sent", "pending", "the sender", "the receiver",
date, true); "the body", date, true);
do_check_eq(sms.id, 42); do_check_eq(sms.id, 42);
do_check_eq(sms.delivery, "sent"); do_check_eq(sms.delivery, "sent");
do_check_eq(sms.deliveryStatus, "pending");
do_check_eq(sms.sender, "the sender"); do_check_eq(sms.sender, "the sender");
do_check_eq(sms.receiver, "the receiver"); do_check_eq(sms.receiver, "the receiver");
do_check_eq(sms.body, "the body"); do_check_eq(sms.body, "the body");
@ -116,8 +124,8 @@ add_test(function test_timestamp_date() {
*/ */
add_test(function test_invalid_timestamp_float() { add_test(function test_invalid_timestamp_float() {
do_check_throws(function() { do_check_throws(function() {
newMessage(42, "sent", "the sender", "the receiver", "the body", 3.1415, newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
true); 3.1415, true);
}, Cr.NS_ERROR_INVALID_ARG); }, Cr.NS_ERROR_INVALID_ARG);
run_next_test(); run_next_test();
}); });
@ -127,8 +135,8 @@ add_test(function test_invalid_timestamp_float() {
*/ */
add_test(function test_invalid_timestamp_null() { add_test(function test_invalid_timestamp_null() {
do_check_throws(function() { do_check_throws(function() {
newMessage(42, "sent", "the sender", "the receiver", "the body", null, newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
true); null, true);
}, Cr.NS_ERROR_INVALID_ARG); }, Cr.NS_ERROR_INVALID_ARG);
run_next_test(); run_next_test();
}); });
@ -138,8 +146,8 @@ add_test(function test_invalid_timestamp_null() {
*/ */
add_test(function test_invalid_timestamp_undefined() { add_test(function test_invalid_timestamp_undefined() {
do_check_throws(function() { do_check_throws(function() {
newMessage(42, "sent", "the sender", "the receiver", "the body", undefined, newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
true); undefined, true);
}, Cr.NS_ERROR_INVALID_ARG); }, Cr.NS_ERROR_INVALID_ARG);
run_next_test(); run_next_test();
}); });
@ -149,7 +157,8 @@ add_test(function test_invalid_timestamp_undefined() {
*/ */
add_test(function test_invalid_timestamp_object() { add_test(function test_invalid_timestamp_object() {
do_check_throws(function() { do_check_throws(function() {
newMessage(42, "sent", "the sender", "the receiver", "the body", {}, true); newMessage(42, "sent", "pending", "the sender", "the receiver", "the body",
{}, true);
}, Cr.NS_ERROR_INVALID_ARG); }, Cr.NS_ERROR_INVALID_ARG);
run_next_test(); run_next_test();
}); });
@ -159,8 +168,8 @@ add_test(function test_invalid_timestamp_object() {
*/ */
add_test(function test_invalid_delivery_string() { add_test(function test_invalid_delivery_string() {
do_check_throws(function() { do_check_throws(function() {
newMessage(42, "this is invalid", "the sender", "the receiver", "the body", newMessage(42, "this is invalid", "pending", "the sender", "the receiver",
new Date(), true); "the body", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG); }, Cr.NS_ERROR_INVALID_ARG);
run_next_test(); run_next_test();
}); });
@ -170,7 +179,30 @@ add_test(function test_invalid_delivery_string() {
*/ */
add_test(function test_invalid_delivery_string() { add_test(function test_invalid_delivery_string() {
do_check_throws(function() { do_check_throws(function() {
newMessage(42, 1, "the sender", "the receiver", "the body", new Date(), true); newMessage(42, 1, "pending", "the sender", "the receiver", "the body",
new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
/**
* Test that an invalid delivery status string is not accepted.
*/
add_test(function test_invalid_delivery_status_string() {
do_check_throws(function() {
newMessage(42, "sent", "this is invalid", "the sender", "the receiver",
"the body", new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG);
run_next_test();
});
/**
* Test that a number is not accepted for the 'deliveryStatus' argument.
*/
add_test(function test_invalid_delivery_status_string() {
do_check_throws(function() {
newMessage(42, "sent", 1, "the sender", "the receiver", "the body",
new Date(), true);
}, Cr.NS_ERROR_INVALID_ARG); }, Cr.NS_ERROR_INVALID_ARG);
run_next_test(); run_next_test();
}); });