diff --git a/dom/mobilemessage/interfaces/nsIMobileMessageService.idl b/dom/mobilemessage/interfaces/nsIMobileMessageService.idl index d219071ee276..827a0dd53412 100644 --- a/dom/mobilemessage/interfaces/nsIMobileMessageService.idl +++ b/dom/mobilemessage/interfaces/nsIMobileMessageService.idl @@ -14,7 +14,7 @@ interface nsIDOMMozSmsSegmentInfo; #define MOBILE_MESSAGE_SERVICE_CONTRACTID "@mozilla.org/mobilemessage/mobilemessageservice;1" %} -[scriptable, builtinclass, uuid(2a231e8d-761d-47a9-8928-93de7b0cbaac)] +[scriptable, builtinclass, uuid(11b7bda8-414b-11e3-8781-1b737e7958ae)] interface nsIMobileMessageService : nsISupports { [implicit_jscontext] @@ -27,6 +27,7 @@ interface nsIMobileMessageService : nsISupports in DOMString body, in DOMString messageClass, in jsval timestamp, + in jsval deliveryTimestamp, in bool read); [implicit_jscontext] diff --git a/dom/mobilemessage/src/MobileMessageService.cpp b/dom/mobilemessage/src/MobileMessageService.cpp index 0e242ee08763..76ae8993477e 100644 --- a/dom/mobilemessage/src/MobileMessageService.cpp +++ b/dom/mobilemessage/src/MobileMessageService.cpp @@ -38,6 +38,7 @@ MobileMessageService::CreateSmsMessage(int32_t aId, const nsAString& aBody, const nsAString& aMessageClass, const JS::Value& aTimestamp, + const JS::Value& aDeliveryTimestamp, const bool aRead, JSContext* aCx, nsIDOMMozSmsMessage** aMessage) @@ -51,6 +52,7 @@ MobileMessageService::CreateSmsMessage(int32_t aId, aBody, aMessageClass, aTimestamp, + aDeliveryTimestamp, aRead, aCx, aMessage); diff --git a/dom/mobilemessage/src/SmsMessage.cpp b/dom/mobilemessage/src/SmsMessage.cpp index 77debf982134..53a10f5b282a 100644 --- a/dom/mobilemessage/src/SmsMessage.cpp +++ b/dom/mobilemessage/src/SmsMessage.cpp @@ -13,6 +13,43 @@ using namespace mozilla::dom::mobilemessage; DOMCI_DATA(MozSmsMessage, mozilla::dom::SmsMessage) +namespace { + +/** + * A helper function to convert the JS value to an integer value for time. + * + * @params aCx + * The JS context. + * @params aTime + * Can be an object or a number. + * @params aReturn + * The integer value to return. + * @return NS_OK if the convertion succeeds. + */ +static nsresult +convertTimeToInt(JSContext* aCx, const JS::Value& aTime, uint64_t& aReturn) +{ + if (aTime.isObject()) { + JS::Rooted timestampObj(aCx, &aTime.toObject()); + if (!JS_ObjectIsDate(aCx, timestampObj)) { + return NS_ERROR_INVALID_ARG; + } + aReturn = js_DateGetMsecSinceEpoch(timestampObj); + } else { + if (!aTime.isNumber()) { + return NS_ERROR_INVALID_ARG; + } + double number = aTime.toNumber(); + if (static_cast(number) != number) { + return NS_ERROR_INVALID_ARG; + } + aReturn = static_cast(number); + } + return NS_OK; +} + +} // anonymous namespace + namespace mozilla { namespace dom { @@ -34,9 +71,10 @@ SmsMessage::SmsMessage(int32_t aId, const nsString& aBody, MessageClass aMessageClass, uint64_t aTimestamp, + uint64_t aDeliveryTimestamp, bool aRead) : mData(aId, aThreadId, aDelivery, aDeliveryStatus, aSender, aReceiver, aBody, - aMessageClass, aTimestamp, aRead) + aMessageClass, aTimestamp, aDeliveryTimestamp, aRead) { } @@ -55,6 +93,7 @@ SmsMessage::Create(int32_t aId, const nsAString& aBody, const nsAString& aMessageClass, const JS::Value& aTimestamp, + const JS::Value& aDeliveryTimestamp, const bool aRead, JSContext* aCx, nsIDOMMozSmsMessage** aMessage) @@ -109,23 +148,13 @@ SmsMessage::Create(int32_t aId, return NS_ERROR_INVALID_ARG; } - // We support both a Date object and a millisecond timestamp as a number. - if (aTimestamp.isObject()) { - JS::Rooted obj(aCx, &aTimestamp.toObject()); - if (!JS_ObjectIsDate(aCx, obj)) { - return NS_ERROR_INVALID_ARG; - } - data.timestamp() = js_DateGetMsecSinceEpoch(obj); - } else { - if (!aTimestamp.isNumber()) { - return NS_ERROR_INVALID_ARG; - } - double number = aTimestamp.toNumber(); - if (static_cast(number) != number) { - return NS_ERROR_INVALID_ARG; - } - data.timestamp() = static_cast(number); - } + // Set |timestamp|. + nsresult rv = convertTimeToInt(aCx, aTimestamp, data.timestamp()); + NS_ENSURE_SUCCESS(rv, rv); + + // Set |deliveryTimestamp|. + rv = convertTimeToInt(aCx, aDeliveryTimestamp, data.deliveryTimestamp()); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr message = new SmsMessage(data); message.swap(*aMessage); @@ -265,6 +294,21 @@ SmsMessage::GetTimestamp(JSContext* cx, JS::Value* aDate) return NS_OK; } +NS_IMETHODIMP +SmsMessage::GetDeliveryTimestamp(JSContext* aCx, JS::Value* aDate) +{ + if (mData.deliveryTimestamp() == 0) { + *aDate = JSVAL_NULL; + return NS_OK; + } + + JSObject *obj = JS_NewDateObjectMsec(aCx, mData.deliveryTimestamp()); + NS_ENSURE_TRUE(obj, NS_ERROR_FAILURE); + + *aDate = OBJECT_TO_JSVAL(obj); + return NS_OK; +} + NS_IMETHODIMP SmsMessage::GetRead(bool* aRead) { diff --git a/dom/mobilemessage/src/SmsMessage.h b/dom/mobilemessage/src/SmsMessage.h index b05b20a3a7a0..f9afd8cc50f9 100644 --- a/dom/mobilemessage/src/SmsMessage.h +++ b/dom/mobilemessage/src/SmsMessage.h @@ -30,6 +30,7 @@ public: const nsString& aBody, mobilemessage::MessageClass aMessageClass, uint64_t aTimestamp, + uint64_t aDeliveryTimestamp, bool aRead); SmsMessage(const mobilemessage::SmsMessageData& aData); @@ -42,6 +43,7 @@ public: const nsAString& aBody, const nsAString& aMessageClass, const JS::Value& aTimestamp, + const JS::Value& aDeliveryTimestamp, const bool aRead, JSContext* aCx, nsIDOMMozSmsMessage** aMessage); diff --git a/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js b/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js index 2b0a55b974a5..1e266b2e46c2 100644 --- a/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js +++ b/dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js @@ -24,7 +24,7 @@ const DISABLE_MMS_GROUPING_FOR_RECEIVING = true; const DB_NAME = "sms"; -const DB_VERSION = 14; +const DB_VERSION = 15; const MESSAGE_STORE_NAME = "sms"; const THREAD_STORE_NAME = "thread"; const PARTICIPANT_STORE_NAME = "participant"; @@ -226,6 +226,10 @@ MobileMessageDatabaseService.prototype = { self.upgradeSchema13(event.target.transaction, next); break; case 14: + if (DEBUG) debug("Upgrade to version 15. Add deliveryTimestamp."); + self.upgradeSchema14(event.target.transaction, next); + break; + case 15: // This will need to be moved for each new version if (DEBUG) debug("Upgrade finished."); break; @@ -1018,6 +1022,33 @@ MobileMessageDatabaseService.prototype = { }; }, + /** + * Add deliveryTimestamp. + */ + upgradeSchema14: function upgradeSchema14(transaction, next) { + let messageStore = transaction.objectStore(MESSAGE_STORE_NAME); + + messageStore.openCursor().onsuccess = function(event) { + let cursor = event.target.result; + if (!cursor) { + next(); + return; + } + + let messageRecord = cursor.value; + if (messageRecord.type == "sms") { + messageRecord.deliveryTimestamp = 0; + } else if (messageRecord.type == "mms") { + let deliveryInfo = messageRecord.deliveryInfo; + for (let i = 0; i < deliveryInfo.length; i++) { + deliveryInfo[i].deliveryTimestamp = 0; + } + } + cursor.update(messageRecord); + cursor.continue(); + }; + }, + matchParsedPhoneNumbers: function matchParsedPhoneNumbers(addr1, parsedAddr1, addr2, parsedAddr2) { if ((parsedAddr1.internationalNumber && @@ -1080,6 +1111,7 @@ MobileMessageDatabaseService.prototype = { aMessageRecord.body, aMessageRecord.messageClass, aMessageRecord.timestamp, + aMessageRecord.deliveryTimestamp, aMessageRecord.read); } else if (aMessageRecord.type == "mms") { let headers = aMessageRecord["headers"]; @@ -1498,6 +1530,12 @@ MobileMessageDatabaseService.prototype = { if (messageRecord.type == "sms") { if (messageRecord.deliveryStatus != deliveryStatus) { messageRecord.deliveryStatus = deliveryStatus; + + // Update the delivery timestamp if it's successfully delivered. + if (deliveryStatus == DELIVERY_STATUS_SUCCESS) { + messageRecord.deliveryTimestamp = Date.now(); + } + isRecordUpdated = true; } } else if (messageRecord.type == "mms") { @@ -1674,6 +1712,11 @@ MobileMessageDatabaseService.prototype = { if (aMessage.type == "sms") { aMessage.delivery = DELIVERY_RECEIVED; aMessage.deliveryStatus = DELIVERY_STATUS_SUCCESS; + + // If |deliveryTimestamp| is not specified, use 0 as default. + if (aMessage.deliveryTimestamp == undefined) { + aMessage.deliveryTimestamp = 0; + } } aMessage.deliveryIndex = [aMessage.delivery, timestamp]; @@ -1699,6 +1742,10 @@ MobileMessageDatabaseService.prototype = { : DELIVERY_STATUS_NOT_APPLICABLE; if (aMessage.type == "sms") { aMessage.deliveryStatus = deliveryStatus; + // If |deliveryTimestamp| is not specified, use 0 as default. + if (aMessage.deliveryTimestamp == undefined) { + aMessage.deliveryTimestamp = 0; + } } else if (aMessage.type == "mms") { let receivers = aMessage.receivers if (!Array.isArray(receivers)) { diff --git a/dom/mobilemessage/src/ipc/SmsTypes.ipdlh b/dom/mobilemessage/src/ipc/SmsTypes.ipdlh index fa87cfdfe2aa..6ac02a125f3f 100644 --- a/dom/mobilemessage/src/ipc/SmsTypes.ipdlh +++ b/dom/mobilemessage/src/ipc/SmsTypes.ipdlh @@ -34,7 +34,8 @@ struct SmsMessageData nsString receiver; nsString body; MessageClass messageClass; - uint64_t timestamp; // ms since epoch. + uint64_t timestamp; // ms since epoch. + uint64_t deliveryTimestamp; // ms since epoch. bool read; }; diff --git a/dom/mobilemessage/tests/marionette/test_getmessage.js b/dom/mobilemessage/tests/marionette/test_getmessage.js index a3ed8d7acd23..527979f70a17 100644 --- a/dom/mobilemessage/tests/marionette/test_getmessage.js +++ b/dom/mobilemessage/tests/marionette/test_getmessage.js @@ -79,6 +79,7 @@ function sendSms() { is(sentSms.messageClass, "normal", "messageClass"); ok(sentSms.timestamp instanceof Date, "timestamp is instanceof date"); outSmsTimeStamp = sentSms.timestamp; + ok(sentSms.deliveryTimestamp === null, "deliveryTimestamp is null"); if (gotSmsOnsent && gotReqOnsuccess) { getReceivedSms(); } }; diff --git a/dom/mobilemessage/tests/marionette/test_incoming.js b/dom/mobilemessage/tests/marionette/test_incoming.js index 64f2bfd60bb6..839672f3d0aa 100644 --- a/dom/mobilemessage/tests/marionette/test_incoming.js +++ b/dom/mobilemessage/tests/marionette/test_incoming.js @@ -36,6 +36,7 @@ manager.onreceived = function onreceived(event) { is(message.body, body, "Message body"); is(message.messageClass, "normal", "Message class"); ok(message.timestamp instanceof Date, "Message timestamp is a date"); + ok(message.deliveryTimestamp === null, "Message deliveryTimestamp is null"); cleanUp(); }; diff --git a/dom/mobilemessage/tests/marionette/test_incoming_delete.js b/dom/mobilemessage/tests/marionette/test_incoming_delete.js index 77b4a4235e5b..70e8f0ea6f60 100644 --- a/dom/mobilemessage/tests/marionette/test_incoming_delete.js +++ b/dom/mobilemessage/tests/marionette/test_incoming_delete.js @@ -37,6 +37,7 @@ function simulateIncomingSms() { is(incomingSms.sender, SENDER, "sender"); is(incomingSms.messageClass, "normal", "messageClass"); ok(incomingSms.timestamp instanceof Date, "timestamp is istanceof date"); + ok(incomingSms.deliveryTimestamp === null, "deliveryTimestamp is null"); verifySmsExists(incomingSms); }; diff --git a/dom/mobilemessage/tests/marionette/test_incoming_max_segments.js b/dom/mobilemessage/tests/marionette/test_incoming_max_segments.js index 1c4b425f1669..f353233faa56 100644 --- a/dom/mobilemessage/tests/marionette/test_incoming_max_segments.js +++ b/dom/mobilemessage/tests/marionette/test_incoming_max_segments.js @@ -45,6 +45,7 @@ function simulateIncomingSms() { is(incomingSms.receiver, EMULATOR, "receiver"); is(incomingSms.sender, REMOTE, "sender"); ok(incomingSms.timestamp instanceof Date, "timestamp is instanceof date"); + ok(incomingSms.deliveryTimestamp === null, "deliveryTimestamp is null"); verifySmsExists(incomingSms); }; diff --git a/dom/mobilemessage/tests/marionette/test_incoming_multipart.js b/dom/mobilemessage/tests/marionette/test_incoming_multipart.js index 0a72d1f876ad..76221958e33e 100644 --- a/dom/mobilemessage/tests/marionette/test_incoming_multipart.js +++ b/dom/mobilemessage/tests/marionette/test_incoming_multipart.js @@ -41,6 +41,7 @@ function simulateIncomingSms() { is(incomingSms.receiver, RECEIVER, "receiver"); is(incomingSms.sender, SENDER, "sender"); ok(incomingSms.timestamp instanceof Date, "timestamp is istanceof date"); + ok(incomingSms.deliveryTimestamp === null, "deliveryTimestamp is null"); verifySmsExists(incomingSms); }; diff --git a/dom/mobilemessage/tests/marionette/test_massive_incoming_delete.js b/dom/mobilemessage/tests/marionette/test_massive_incoming_delete.js index d6d6081447c9..61f01299d82b 100644 --- a/dom/mobilemessage/tests/marionette/test_massive_incoming_delete.js +++ b/dom/mobilemessage/tests/marionette/test_massive_incoming_delete.js @@ -146,6 +146,7 @@ tasks.push(function init() { is(incomingSms.sender, SENDER, "sender"); is(incomingSms.messageClass, "normal", "messageClass"); ok(incomingSms.timestamp instanceof Date, "timestamp is istanceof date"); + ok(incomingSms.deliveryTimestamp === null, "deliveryTimestamp is null"); verifySmsExists(incomingSms); }; diff --git a/dom/mobilemessage/tests/marionette/test_message_classes.js b/dom/mobilemessage/tests/marionette/test_message_classes.js index cf0366b7d05b..8933d4eefda4 100644 --- a/dom/mobilemessage/tests/marionette/test_message_classes.js +++ b/dom/mobilemessage/tests/marionette/test_message_classes.js @@ -49,8 +49,8 @@ function checkMessage(message, id, threadId, messageClass) { is(message.sender, "+1", "message.sender"); is(message.body, "A", "message.body"); is(message.messageClass, messageClass, "message.messageClass"); - ok(message.timestamp instanceof Date, - "message.timestamp is instanceof " + message.timestamp.constructor); + ok(message.timestamp instanceof Date, "timestamp is instanceof Date"); + ok(message.deliveryTimestamp === null, "deliveryTimestamp is null"); is(message.read, false, "message.read"); } diff --git a/dom/mobilemessage/tests/marionette/test_outgoing.js b/dom/mobilemessage/tests/marionette/test_outgoing.js index 5f15747956d1..8bc35ca9659c 100644 --- a/dom/mobilemessage/tests/marionette/test_outgoing.js +++ b/dom/mobilemessage/tests/marionette/test_outgoing.js @@ -43,8 +43,11 @@ function checkMessage(message, delivery, body) { ok(message.receiver, "message.receiver"); is(message.body, body, "message.body"); is(message.messageClass, "normal", "message.messageClass"); - ok(message.timestamp instanceof Date, - "message.timestamp is instanceof " + message.timestamp.constructor); + ok(message.timestamp instanceof Date, "timestamp is instanceof Date"); + + // TODO: bug 788928 - add test cases for deliverysuccess event. + ok(message.deliveryTimestamp === null, "deliveryTimestamp is null"); + is(message.read, true, "message.read"); } @@ -116,7 +119,7 @@ function doSendMessageAndCheckSuccess(receivers, body, callback) { let message = event.message; checkMessage(message, "sending", body); - // SMSC timestamp is in seconds. + // timestamp is in seconds. ok(Math.floor(message.timestamp.getTime() / 1000) >= Math.floor(now / 1000), "sent timestamp is valid"); diff --git a/dom/mobilemessage/tests/marionette/test_outgoing_delete.js b/dom/mobilemessage/tests/marionette/test_outgoing_delete.js index 200e4a9aad49..5a012bd01996 100644 --- a/dom/mobilemessage/tests/marionette/test_outgoing_delete.js +++ b/dom/mobilemessage/tests/marionette/test_outgoing_delete.js @@ -43,6 +43,7 @@ function sendSms() { is(sentSms.sender, SENDER, "sender"); is(sentSms.messageClass, "normal", "messageClass"); ok(sentSms.timestamp instanceof Date, "timestamp is istanceof date"); + ok(sentSms.deliveryTimestamp === null, "deliveryTimestamp is null"); if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); } }; diff --git a/dom/mobilemessage/tests/test_smsservice_createsmsmessage.js b/dom/mobilemessage/tests/test_smsservice_createsmsmessage.js index 8ab862b2b97e..1d419f0b4ba0 100644 --- a/dom/mobilemessage/tests/test_smsservice_createsmsmessage.js +++ b/dom/mobilemessage/tests/test_smsservice_createsmsmessage.js @@ -30,18 +30,19 @@ function run_test() { * Ensure an SmsMessage object created has sensible initial values. */ add_test(function test_interface() { - let sms = newMessage(null, null, "sent", "pending", null, null, null, - "normal", new Date(), true); + let sms = newMessage(null, null, "sent", "success", null, null, null, + "normal", new Date(), 0, 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.deliveryStatus, "success"); do_check_eq(sms.receiver, null); do_check_eq(sms.sender, null); do_check_eq(sms.body, null); do_check_eq(sms.messageClass, "normal"); do_check_true(sms.timestamp instanceof Date); + do_check_true(sms.deliveryTimestamp === null); do_check_true(sms.read); run_next_test(); }); @@ -51,7 +52,7 @@ add_test(function test_interface() { */ add_test(function test_readonly_attributes() { let sms = newMessage(null, null, "received", "success", null, null, null, - "normal", new Date(), true); + "normal", new Date(), 0, true); sms.id = 1; do_check_eq(sms.id, 0); @@ -77,9 +78,13 @@ add_test(function test_readonly_attributes() { sms.messageClass = "class-0"; do_check_eq(sms.messageClass, "normal"); - let oldTimestamp = sms.timestamp.getTime(); + let oldTimestamp = sms.timestamp; sms.timestamp = new Date(); - do_check_eq(sms.timestamp.getTime(), oldTimestamp); + do_check_eq(sms.timestamp.getTime(), oldTimestamp.getTime()); + + let oldDeliveryTimestamp = sms.deliveryTimestamp; + sms.deliveryTimestamp = new Date(); + do_check_eq(sms.deliveryTimestamp, oldDeliveryTimestamp); sms.read = false; do_check_true(sms.read); @@ -92,18 +97,19 @@ add_test(function test_readonly_attributes() { */ add_test(function test_timestamp_number() { let ts = Date.now(); - let sms = newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "normal", ts, true); + let sms = newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", ts, 0, 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.deliveryStatus, "success"); do_check_eq(sms.sender, "the sender"); do_check_eq(sms.receiver, "the receiver"); do_check_eq(sms.body, "the body"); do_check_eq(sms.messageClass, "normal"); do_check_true(sms.timestamp instanceof Date); do_check_eq(sms.timestamp.getTime(), ts); + do_check_true(sms.deliveryTimestamp === null); do_check_true(sms.read); run_next_test(); }); @@ -113,18 +119,19 @@ add_test(function test_timestamp_number() { */ add_test(function test_timestamp_date() { let date = new Date(); - let sms = newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "normal", date, true); + let sms = newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", date, 0, 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.deliveryStatus, "success"); do_check_eq(sms.sender, "the sender"); do_check_eq(sms.receiver, "the receiver"); do_check_eq(sms.body, "the body"); do_check_eq(sms.messageClass, "normal"); do_check_true(sms.timestamp instanceof Date); do_check_eq(sms.timestamp.getTime(), date.getTime()); + do_check_true(sms.deliveryTimestamp === null); do_check_true(sms.read); run_next_test(); }); @@ -133,10 +140,18 @@ add_test(function test_timestamp_date() { * Test that a floating point number for the timestamp is not allowed. */ add_test(function test_invalid_timestamp_float() { + // Test timestamp. do_check_throws(function() { - newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "normal", 3.1415, true); + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", 3.1415, 0, true); }, Cr.NS_ERROR_INVALID_ARG); + + // Test deliveryTimestamp. + do_check_throws(function() { + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", 0, 3.1415, true); + }, Cr.NS_ERROR_INVALID_ARG); + run_next_test(); }); @@ -144,10 +159,18 @@ add_test(function test_invalid_timestamp_float() { * Test that a null value for the timestamp is not allowed. */ add_test(function test_invalid_timestamp_null() { + // Test timestamp. do_check_throws(function() { - newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "normal", null, true); + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", null, 0, true); }, Cr.NS_ERROR_INVALID_ARG); + + // Test deliveryTimestamp. + do_check_throws(function() { + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", 0, null, true); + }, Cr.NS_ERROR_INVALID_ARG); + run_next_test(); }); @@ -155,10 +178,18 @@ add_test(function test_invalid_timestamp_null() { * Test that undefined for the timestamp is not allowed. */ add_test(function test_invalid_timestamp_undefined() { + // Test timestamp. do_check_throws(function() { - newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "normal", undefined, true); + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", undefined, 0, true); }, Cr.NS_ERROR_INVALID_ARG); + + // Test deliveryTimestamp. + do_check_throws(function() { + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", 0, undefined, true); + }, Cr.NS_ERROR_INVALID_ARG); + run_next_test(); }); @@ -166,10 +197,18 @@ add_test(function test_invalid_timestamp_undefined() { * Test that a random object for the timestamp is not allowed. */ add_test(function test_invalid_timestamp_object() { + // Test timestamp. do_check_throws(function() { - newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "normal", {}, true); + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", {}, 0, true); }, Cr.NS_ERROR_INVALID_ARG); + + // Test deliveryTimestamp. + do_check_throws(function() { + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "normal", 0, {}, true); + }, Cr.NS_ERROR_INVALID_ARG); + run_next_test(); }); @@ -179,7 +218,7 @@ add_test(function test_invalid_timestamp_object() { add_test(function test_invalid_delivery_string() { do_check_throws(function() { newMessage(42, 1, "this is invalid", "pending", "the sender", - "the receiver", "the body", "normal", new Date(), true); + "the receiver", "the body", "normal", new Date(), 0, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -190,7 +229,7 @@ add_test(function test_invalid_delivery_string() { add_test(function test_invalid_delivery_string() { do_check_throws(function() { newMessage(42, 1, 1, "pending", "the sender", "the receiver", "the body", - "normal", new Date(), true); + "normal", new Date(), 0, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -201,7 +240,7 @@ add_test(function test_invalid_delivery_string() { add_test(function test_invalid_delivery_status_string() { do_check_throws(function() { newMessage(42, 1, "sent", "this is invalid", "the sender", "the receiver", - "the body", "normal", new Date(), true); + "the body", "normal", new Date(), 0, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -212,7 +251,7 @@ add_test(function test_invalid_delivery_status_string() { add_test(function test_invalid_delivery_status_string() { do_check_throws(function() { newMessage(42, 1, "sent", 1, "the sender", "the receiver", "the body", - "normal", new Date(), true); + "normal", new Date(), 0, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -222,8 +261,8 @@ add_test(function test_invalid_delivery_status_string() { */ add_test(function test_invalid_message_class_string() { do_check_throws(function() { - newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", "this is invalid", new Date(), true); + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", "this is invalid", new Date(), 0, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); @@ -233,8 +272,8 @@ add_test(function test_invalid_message_class_string() { */ add_test(function test_invalid_message_class_string() { do_check_throws(function() { - newMessage(42, 1, "sent", "pending", "the sender", "the receiver", - "the body", 1, new Date(), true); + newMessage(42, 1, "sent", "success", "the sender", "the receiver", + "the body", 1, new Date(), 0, true); }, Cr.NS_ERROR_INVALID_ARG); run_next_test(); }); diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index aec18f04f5c1..468046888958 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -1752,17 +1752,18 @@ RadioInterface.prototype = { // because the system message mechamism will rewrap the object // based on the content window, which needs to know the properties. gSystemMessenger.broadcastMessage(aName, { - type: aDomMessage.type, - id: aDomMessage.id, - threadId: aDomMessage.threadId, - delivery: aDomMessage.delivery, - deliveryStatus: aDomMessage.deliveryStatus, - sender: aDomMessage.sender, - receiver: aDomMessage.receiver, - body: aDomMessage.body, - messageClass: aDomMessage.messageClass, - timestamp: aDomMessage.timestamp, - read: aDomMessage.read + type: aDomMessage.type, + id: aDomMessage.id, + threadId: aDomMessage.threadId, + delivery: aDomMessage.delivery, + deliveryStatus: aDomMessage.deliveryStatus, + sender: aDomMessage.sender, + receiver: aDomMessage.receiver, + body: aDomMessage.body, + messageClass: aDomMessage.messageClass, + timestamp: aDomMessage.timestamp, + deliveryTimestamp: aDomMessage.deliveryTimestamp, + read: aDomMessage.read }); }, @@ -1848,6 +1849,7 @@ RadioInterface.prototype = { message.body, message.messageClass, message.timestamp, + 0, message.read); Services.obs.notifyObservers(domMessage, @@ -1912,6 +1914,7 @@ RadioInterface.prototype = { message.body, message.messageClass, message.timestamp, + 0, message.read); notifyReceived(Cr.NS_OK, domMessage); @@ -3021,9 +3024,9 @@ RadioInterface.prototype = { // Message sent. if (context.silent) { - // There is no way to modify nsIDOMMozSmsMessage attributes as they are - // read only so we just create a new sms instance to send along with - // the notification. + // There is no way to modify nsIDOMMozSmsMessage attributes as they + // are read only so we just create a new sms instance to send along + // with the notification. let sms = context.sms; context.request.notifyMessageSent( gMobileMessageService.createSmsMessage(sms.id, @@ -3035,6 +3038,7 @@ RadioInterface.prototype = { sms.body, sms.messageClass, sms.timestamp, + 0, sms.read)); // We don't wait for SMS-DELIVER-REPORT for silent one. return false; @@ -3085,6 +3089,7 @@ RadioInterface.prototype = { sendingMessage.body, "normal", // message class sendingMessage.timestamp, + 0, false); notifyResult(Cr.NS_OK, domMessage); return;