From 5d43612b5f689e687532f494bddc243ef53c00ba Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Tue, 30 Oct 2012 18:53:35 +0800 Subject: [PATCH] Bug 742790 - Part 5/5: test cases, r=marshall_law --- dom/sms/tests/marionette/test_getmessage.js | 4 ++ dom/sms/tests/marionette/test_incoming.js | 1 + .../tests/marionette/test_incoming_delete.js | 1 + .../tests/marionette/test_message_classes.js | 1 + dom/sms/tests/marionette/test_outgoing.js | 1 + .../tests/marionette/test_outgoing_delete.js | 1 + .../tests/test_smsservice_createsmsmessage.js | 64 ++++++++++++++----- 7 files changed, 57 insertions(+), 16 deletions(-) diff --git a/dom/sms/tests/marionette/test_getmessage.js b/dom/sms/tests/marionette/test_getmessage.js index b8eb538cfe6..fae93285f5a 100644 --- a/dom/sms/tests/marionette/test_getmessage.js +++ b/dom/sms/tests/marionette/test_getmessage.js @@ -36,6 +36,7 @@ function simulateIncomingSms() { log("Received SMS (id: " + inSmsId + ")."); is(incomingSms.body, inText, "msg body"); is(incomingSms.delivery, "received", "delivery"); + is(incomingSms.deliveryStatus, "success", "deliveryStatus"); is(incomingSms.read, false, "read"); is(incomingSms.receiver, null, "receiver"); is(incomingSms.sender, remoteNumber, "sender"); @@ -61,6 +62,7 @@ function sendSms() { log("Sent SMS (id: " + outSmsId + ")."); is(sentSms.body, outText, "msg body"); is(sentSms.delivery, "sent", "delivery"); + is(sentSms.deliveryStatus, "pending", "deliveryStatus"); is(sentSms.read, true, "read"); is(sentSms.receiver, remoteNumber, "receiver"); is(sentSms.sender, null, "sender"); @@ -108,6 +110,7 @@ function getReceivedSms() { log("Got SMS (id: " + foundSms.id + ")."); is(foundSms.body, inText, "SMS msg text matches"); is(foundSms.delivery, "received", "delivery"); + is(foundSms.deliveryStatus, "success", "deliveryStatus"); is(foundSms.read, false, "read"); is(foundSms.receiver, myNumber, "receiver"); is(foundSms.sender, remoteNumber, "sender"); @@ -139,6 +142,7 @@ function getSentSms() { log("Got SMS (id: " + foundSms.id + ")."); is(foundSms.body, outText, "SMS msg text matches"); is(foundSms.delivery, "sent", "delivery"); + is(foundSms.deliveryStatus, "pending", "deliveryStatus"); is(foundSms.read, true, "read"); is(foundSms.receiver, remoteNumber, "receiver"); is(foundSms.sender, myNumber, "sender"); diff --git a/dom/sms/tests/marionette/test_incoming.js b/dom/sms/tests/marionette/test_incoming.js index a6f6a0193a9..26cd36cbee1 100644 --- a/dom/sms/tests/marionette/test_incoming.js +++ b/dom/sms/tests/marionette/test_incoming.js @@ -25,6 +25,7 @@ sms.onreceived = function onreceived(event) { ok(message instanceof MozSmsMessage); is(message.delivery, "received"); + is(message.deliveryStatus, "success"); is(message.sender, sender); is(message.receiver, null); is(message.body, body); diff --git a/dom/sms/tests/marionette/test_incoming_delete.js b/dom/sms/tests/marionette/test_incoming_delete.js index aac06bc9d30..a6f52e24673 100644 --- a/dom/sms/tests/marionette/test_incoming_delete.js +++ b/dom/sms/tests/marionette/test_incoming_delete.js @@ -27,6 +27,7 @@ function simulateIncomingSms() { log("Received SMS (id: " + incomingSms.id + ")."); is(incomingSms.body, msgText, "msg body"); is(incomingSms.delivery, "received", "delivery"); + is(incomingSms.deliveryStatus, "success", "deliveryStatus"); is(incomingSms.read, false, "read"); is(incomingSms.receiver, null, "receiver"); is(incomingSms.sender, fromNumber, "sender"); diff --git a/dom/sms/tests/marionette/test_message_classes.js b/dom/sms/tests/marionette/test_message_classes.js index 6bff38a184f..3219b0c897c 100644 --- a/dom/sms/tests/marionette/test_message_classes.js +++ b/dom/sms/tests/marionette/test_message_classes.js @@ -40,6 +40,7 @@ function checkMessage(message, id) { is(message.id, -1, "message.id"); } is(message.delivery, "received", "message.delivery"); + is(message.deliveryStatus, "success", "message.deliveryStatus"); is(message.sender, "+1", "message.sender"); is(message.body, "A", "message.body"); ok(message.timestamp instanceof Date, diff --git a/dom/sms/tests/marionette/test_outgoing.js b/dom/sms/tests/marionette/test_outgoing.js index 1ebb15af9a0..5440baaf4be 100644 --- a/dom/sms/tests/marionette/test_outgoing.js +++ b/dom/sms/tests/marionette/test_outgoing.js @@ -33,6 +33,7 @@ function checkSentMessage(message, body, sentDate) { ok(message.id, "message.id is valid"); is(message.delivery, "sent", "message.delivery"); + is(message.deliveryStatus, "pending", "message.deliveryStatus"); is(message.sender, null, "message.sender"); is(message.receiver, receiver, "message.receiver"); is(message.body, body, "message.body"); diff --git a/dom/sms/tests/marionette/test_outgoing_delete.js b/dom/sms/tests/marionette/test_outgoing_delete.js index fac709ba1d6..ae73e265c58 100644 --- a/dom/sms/tests/marionette/test_outgoing_delete.js +++ b/dom/sms/tests/marionette/test_outgoing_delete.js @@ -32,6 +32,7 @@ function sendSms() { log("Sent SMS (id: " + smsId + ")."); is(sentSms.body, msgText, "msg body"); is(sentSms.delivery, "sent", "delivery"); + is(sentSms.deliveryStatus, "pending", "deliveryStatus"); is(sentSms.read, true, "read"); is(sentSms.receiver, destNumber, "receiver"); is(sentSms.sender, null, "sender"); diff --git a/dom/sms/tests/test_smsservice_createsmsmessage.js b/dom/sms/tests/test_smsservice_createsmsmessage.js index 7e3257ad2e2..3d40d2d6634 100644 --- a/dom/sms/tests/test_smsservice_createsmsmessage.js +++ b/dom/sms/tests/test_smsservice_createsmsmessage.js @@ -32,10 +32,12 @@ function run_test() { * Ensure an SmsMessage object created has sensible initial values. */ 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_eq(sms.id, 0); do_check_eq(sms.delivery, "sent"); + do_check_eq(sms.deliveryStatus, "pending"); do_check_eq(sms.receiver, null); do_check_eq(sms.sender, null); do_check_eq(sms.body, null); @@ -48,7 +50,8 @@ add_test(function test_interface() { * Verify that attributes are read-only. */ 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; do_check_eq(sms.id, 0); @@ -56,6 +59,9 @@ add_test(function test_readonly_attributes() { sms.delivery = "sent"; do_check_eq(sms.delivery, "received"); + sms.deliveryStatus = "pending"; + do_check_eq(sms.deliveryStatus, "success"); + sms.receiver = "a receiver"; do_check_eq(sms.receiver, null); @@ -80,10 +86,11 @@ add_test(function test_readonly_attributes() { */ add_test(function test_timestamp_number() { let ts = Date.now(); - let sms = newMessage(42, "sent", "the sender", "the receiver", "the body", ts, - true); + let sms = newMessage(42, "sent", "pending", "the sender", "the receiver", + "the body", ts, true); do_check_eq(sms.id, 42); do_check_eq(sms.delivery, "sent"); + do_check_eq(sms.deliveryStatus, "pending"); do_check_eq(sms.sender, "the sender"); do_check_eq(sms.receiver, "the receiver"); do_check_eq(sms.body, "the body"); @@ -98,10 +105,11 @@ add_test(function test_timestamp_number() { */ add_test(function test_timestamp_date() { let date = new Date(); - let sms = newMessage(42, "sent", "the sender", "the receiver", "the body", - date, true); + let sms = newMessage(42, "sent", "pending", "the sender", "the receiver", + "the body", date, true); do_check_eq(sms.id, 42); do_check_eq(sms.delivery, "sent"); + do_check_eq(sms.deliveryStatus, "pending"); do_check_eq(sms.sender, "the sender"); do_check_eq(sms.receiver, "the receiver"); do_check_eq(sms.body, "the body"); @@ -116,8 +124,8 @@ add_test(function test_timestamp_date() { */ add_test(function test_invalid_timestamp_float() { do_check_throws(function() { - newMessage(42, "sent", "the sender", "the receiver", "the body", 3.1415, - true); + newMessage(42, "sent", "pending", "the sender", "the receiver", "the body", + 3.1415, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -127,8 +135,8 @@ add_test(function test_invalid_timestamp_float() { */ add_test(function test_invalid_timestamp_null() { do_check_throws(function() { - newMessage(42, "sent", "the sender", "the receiver", "the body", null, - true); + newMessage(42, "sent", "pending", "the sender", "the receiver", "the body", + null, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -138,8 +146,8 @@ add_test(function test_invalid_timestamp_null() { */ add_test(function test_invalid_timestamp_undefined() { do_check_throws(function() { - newMessage(42, "sent", "the sender", "the receiver", "the body", undefined, - true); + newMessage(42, "sent", "pending", "the sender", "the receiver", "the body", + undefined, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -149,7 +157,8 @@ add_test(function test_invalid_timestamp_undefined() { */ add_test(function test_invalid_timestamp_object() { 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); run_next_test(); }); @@ -159,8 +168,8 @@ add_test(function test_invalid_timestamp_object() { */ add_test(function test_invalid_delivery_string() { do_check_throws(function() { - newMessage(42, "this is invalid", "the sender", "the receiver", "the body", - new Date(), true); + newMessage(42, "this is invalid", "pending", "the sender", "the receiver", + "the body", new Date(), true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -170,7 +179,30 @@ add_test(function test_invalid_delivery_string() { */ add_test(function test_invalid_delivery_string() { 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); run_next_test(); });