dom/mobilemessage/tests/test_smsservice_createsmsmessage.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 const ICC_ID = "123456789";
     6 function do_check_throws(f, result, stack) {
     7   if (!stack) {
     8     stack = Components.stack.caller;
     9   }
    11   try {
    12     f();
    13   } catch (exc) {
    14     if (exc.result == result)
    15       return;
    16     do_throw("expected result " + result + ", caught " + exc, stack);
    17   }
    18   do_throw("expected result " + result + ", none thrown", stack);
    19 }
    21 let gMobileMessageService = Cc["@mozilla.org/mobilemessage/mobilemessageservice;1"]
    22                             .getService(Ci.nsIMobileMessageService);
    23 function newMessage() {
    24   return gMobileMessageService.createSmsMessage.apply(gMobileMessageService, arguments);
    25 }
    27 function run_test() {
    28   run_next_test();
    29 }
    31 /**
    32  * Ensure an SmsMessage object created has sensible initial values.
    33  */
    34 add_test(function test_interface() {
    35   let sms = newMessage(null, null, ICC_ID, "sent", "success", null, null, null,
    36                        "normal", Date.now(), Date.now(), Date.now(), true);
    37   do_check_true(sms instanceof Ci.nsIDOMMozSmsMessage);
    38   do_check_eq(sms.id, 0);
    39   do_check_eq(sms.threadId, 0);
    40   do_check_eq(sms.iccId, ICC_ID);
    41   do_check_eq(sms.delivery, "sent");
    42   do_check_eq(sms.deliveryStatus, "success");
    43   do_check_eq(sms.receiver, null);
    44   do_check_eq(sms.sender, null);
    45   do_check_eq(sms.body, null);
    46   do_check_eq(sms.messageClass, "normal");
    47   do_check_true(sms.read);
    48   run_next_test();
    49 });
    51 /**
    52  * Test if ICC ID is null when it's not available.
    53  */
    54 add_test(function test_icc_id_not_available() {
    55   let sms = newMessage(null, null, null, "sent", "success", null, null, null,
    56                        "normal", Date.now(), Date.now(), Date.now(), true);
    57   do_check_true(sms instanceof Ci.nsIDOMMozSmsMessage);
    58   do_check_eq(sms.id, 0);
    59   do_check_eq(sms.threadId, 0);
    60   do_check_eq(sms.iccId, null);
    61   do_check_eq(sms.delivery, "sent");
    62   do_check_eq(sms.deliveryStatus, "success");
    63   do_check_eq(sms.receiver, null);
    64   do_check_eq(sms.sender, null);
    65   do_check_eq(sms.body, null);
    66   do_check_eq(sms.messageClass, "normal");
    67   do_check_true(sms.read);
    68   run_next_test();
    69 });
    71 /**
    72  * Verify that attributes are read-only.
    73  */
    74 add_test(function test_readonly_attributes() {
    75   let sms = newMessage(null, null, ICC_ID, "sent", "success", null, null, null,
    76                        "normal", Date.now(), Date.now(), Date.now(), true);
    78   sms.id = 1;
    79   do_check_eq(sms.id, 0);
    81   sms.threadId = 1;
    82   do_check_eq(sms.threadId, 0);
    84   sms.iccId = "987654321";
    85   do_check_eq(sms.iccId, ICC_ID);
    87   sms.delivery = "received";
    88   do_check_eq(sms.delivery, "sent");
    90   sms.deliveryStatus = "pending";
    91   do_check_eq(sms.deliveryStatus, "success");
    93   sms.receiver = "a receiver";
    94   do_check_eq(sms.receiver, null);
    96   sms.sender = "a sender";
    97   do_check_eq(sms.sender, null);
    99   sms.body = "a body";
   100   do_check_eq(sms.body, null);
   102   sms.messageClass = "class-0";
   103   do_check_eq(sms.messageClass, "normal");
   105   let oldTimestamp = sms.timestamp;
   106   sms.timestamp = Date.now();
   107   do_check_eq(sms.timestamp, oldTimestamp);
   109   let oldSentTimestamp = sms.sentTimestamp;
   110   sms.sentTimestamp = Date.now();
   111   do_check_eq(sms.sentTimestamp, oldSentTimestamp);
   113   let oldDeliveryTimestamp = sms.deliveryTimestamp;
   114   sms.deliveryTimestamp = Date.now();
   115   do_check_eq(sms.deliveryTimestamp, oldDeliveryTimestamp);
   117   sms.read = false;
   118   do_check_true(sms.read);
   120   run_next_test();
   121 });
   123 /**
   124  * Test supplying the timestamp as a number of milliseconds.
   125  */
   126 add_test(function test_timestamp_number() {
   127   let ts = Date.now();
   128   let sms = newMessage(42, 1, ICC_ID, "sent", "success", "the sender", "the receiver",
   129                        "the body", "normal", ts, ts, ts, true);
   130   do_check_eq(sms.id, 42);
   131   do_check_eq(sms.threadId, 1);
   132   do_check_eq(sms.iccId, ICC_ID);
   133   do_check_eq(sms.delivery, "sent");
   134   do_check_eq(sms.deliveryStatus, "success");
   135   do_check_eq(sms.sender, "the sender");
   136   do_check_eq(sms.receiver, "the receiver");
   137   do_check_eq(sms.body, "the body");
   138   do_check_eq(sms.messageClass, "normal");
   139   do_check_eq(sms.timestamp, ts);
   140   do_check_eq(sms.sentTimestamp, ts);
   141   do_check_eq(sms.deliveryTimestamp, ts);
   142   do_check_true(sms.read);
   143   run_next_test();
   144 });
   146 /**
   147  * Test supplying the timestamp as a Date object, which will be automatically
   148  * casted to unsigned long long.
   149  */
   150 add_test(function test_timestamp_date() {
   151   let date = new Date();
   152   let sms = newMessage(42, 1, ICC_ID, "sent", "success", "the sender", "the receiver",
   153                        "the body", "normal", date, date, date, true);
   154   do_check_eq(sms.id, 42);
   155   do_check_eq(sms.threadId, 1);
   156   do_check_eq(sms.iccId, ICC_ID);
   157   do_check_eq(sms.delivery, "sent");
   158   do_check_eq(sms.deliveryStatus, "success");
   159   do_check_eq(sms.sender, "the sender");
   160   do_check_eq(sms.receiver, "the receiver");
   161   do_check_eq(sms.body, "the body");
   162   do_check_eq(sms.messageClass, "normal");
   163   do_check_eq(sms.timestamp, date.getTime());
   164   do_check_eq(sms.sentTimestamp, date.getTime());
   165   do_check_eq(sms.deliveryTimestamp, date.getTime());
   166   do_check_true(sms.read);
   167   run_next_test();
   168 });
   170 /**
   171  * Test that an invalid delivery string is not accepted.
   172  */
   173 add_test(function test_invalid_delivery_string() {
   174   do_check_throws(function() {
   175     newMessage(42, 1, ICC_ID, "this is invalid", "pending", "the sender",
   176                "the receiver", "the body", "normal", Date.now(), 0, 0, true);
   177   }, Cr.NS_ERROR_INVALID_ARG);
   178   run_next_test();
   179 });
   181 /**
   182  * Test that a number is not accepted for the 'delivery' argument.
   183  */
   184 add_test(function test_invalid_delivery_string() {
   185   do_check_throws(function() {
   186     newMessage(42, 1, ICC_ID, 1, "pending", "the sender", "the receiver", "the body",
   187                "normal", Date.now(), 0, 0, true);
   188   }, Cr.NS_ERROR_INVALID_ARG);
   189   run_next_test();
   190 });
   192 /**
   193  * Test that an invalid delivery status string is not accepted.
   194  */
   195 add_test(function test_invalid_delivery_status_string() {
   196   do_check_throws(function() {
   197     newMessage(42, 1, ICC_ID, "sent", "this is invalid", "the sender", "the receiver",
   198                "the body", "normal", Date.now(), Date.now(), 0, true);
   199   }, Cr.NS_ERROR_INVALID_ARG);
   200   run_next_test();
   201 });
   203 /**
   204  * Test that a number is not accepted for the 'deliveryStatus' argument.
   205  */
   206 add_test(function test_invalid_delivery_status_string() {
   207   do_check_throws(function() {
   208     newMessage(42, 1, ICC_ID, "sent", 1, "the sender", "the receiver", "the body",
   209                "normal", Date.now(), Date.now(), 0, true);
   210   }, Cr.NS_ERROR_INVALID_ARG);
   211   run_next_test();
   212 });
   214 /**
   215  * Test that an invalid message class string is not accepted.
   216  */
   217 add_test(function test_invalid_message_class_string() {
   218   do_check_throws(function() {
   219     newMessage(42, 1, ICC_ID, "sent", "success", "the sender", "the receiver",
   220                "the body", "this is invalid", Date.now(), Date.now(), Date.now(), true);
   221   }, Cr.NS_ERROR_INVALID_ARG);
   222   run_next_test();
   223 });
   225 /**
   226  * Test that a number is not accepted for the 'messageClass' argument.
   227  */
   228 add_test(function test_invalid_message_class_string() {
   229   do_check_throws(function() {
   230     newMessage(42, 1, ICC_ID, "sent", "success", "the sender", "the receiver",
   231                "the body", 1, Date.now(), Date.now(), Date.now(), true);
   232   }, Cr.NS_ERROR_INVALID_ARG);
   233   run_next_test();
   234 });

mercurial