dom/mobilemessage/tests/marionette/test_message_classes.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 MARIONETTE_TIMEOUT = 60000;
     6 const PDU_SMSC = "00"; // No SMSC Address
     7 const PDU_FIRST_OCTET = "00"; // RP:no, UDHI:no, SRI:no, MMS:no, MTI:SMS-DELIVER
     8 const PDU_SENDER = "0191F1"; // +1
     9 const PDU_PID_NORMAL = "00";
    10 const PDU_PID_ANSI_136_R_DATA = "7C";
    11 const PDU_PID_USIM_DATA_DOWNLOAD = "7F";
    12 const PDU_TIMESTAMP = "00101000000000"; // 2000/01/01
    13 const PDU_UDL = "01";
    14 const PDU_UD = "41";
    16 const SENT_TIMESTAMP = Date.UTC(2000, 0, 1); // Must be equal to PDU_TIMESTAMP.
    18 SpecialPowers.addPermission("sms", true, document);
    20 let manager = window.navigator.mozMobileMessage;
    21 ok(manager instanceof MozMobileMessageManager,
    22    "manager is instance of " + manager.constructor);
    24 let pendingEmulatorCmdCount = 0;
    25 function sendSmsPduToEmulator(pdu) {
    26   ++pendingEmulatorCmdCount;
    28   let cmd = "sms pdu " + pdu;
    29   runEmulatorCmd(cmd, function(result) {
    30     --pendingEmulatorCmdCount;
    32     is(result[0], "OK", "Emulator response");
    33   });
    34 }
    36 function checkMessage(message, id, threadId, messageClass) {
    37   ok(message instanceof MozSmsMessage,
    38      "message is instanceof " + message.constructor);
    39   if (id == null) {
    40     ok(message.id > 0, "message.id");
    41   } else {
    42     is(message.id, id, "message.id");
    43   }
    44   if (threadId == null) {
    45     ok(message.threadId > 0, "message.threadId");
    46   } else {
    47     is(message.threadId, threadId, "message.threadId");
    48   }
    49   is(message.delivery, "received", "message.delivery");
    50   is(message.deliveryStatus, "success", "message.deliveryStatus");
    51   is(message.sender, "+1", "message.sender");
    52   is(message.body, "A", "message.body");
    53   is(message.messageClass, messageClass, "message.messageClass");
    54   is(message.deliveryTimestamp, 0, "deliveryTimestamp is 0");
    55   is(message.read, false, "message.read");
    56 }
    58 function test_message_class_0() {
    59   let allDCSs = [
    60     "10", // General Group: 00xx
    61     "50", // Automatica Deletion Group: 01xx
    62     "F0"  // (no name) Group: 1111
    63   ];
    65   function do_test(dcsIndex) {
    66     manager.addEventListener("received", function onReceived(event) {
    67       manager.removeEventListener("received", onReceived);
    69       let message = event.message;
    70       checkMessage(message, -1, 0, "class-0");
    71       ok(event.message.timestamp >= timeBeforeSend,
    72          "Message's timestamp should be greater then the timetamp of sending");
    73       ok(event.message.timestamp <= Date.now(),
    74          "Message's timestamp should be lesser than the timestamp of now");
    75       is(event.message.sentTimestamp, SENT_TIMESTAMP,
    76          "Message's sentTimestamp should be equal to SENT_TIMESTAMP");
    78       // Make sure the message is not stored.
    79       let cursor = manager.getMessages(null, false);
    80       cursor.onsuccess = function onsuccess() {
    81         if (cursor.result) {
    82           // Here we check whether there is any message of the same sender.
    83           isnot(cursor.result.sender, message.sender, "cursor.result.sender");
    85           cursor.continue();
    86           return;
    87         }
    89         // All messages checked. Done.
    90         ++dcsIndex;
    91         if (dcsIndex >= allDCSs.length) {
    92           window.setTimeout(test_message_class_1, 0);
    93         } else {
    94           window.setTimeout(do_test.bind(null, dcsIndex), 0);
    95         }
    96       };
    97       cursor.onerror = function onerror() {
    98         ok(false, "Can't fetch messages from SMS database");
    99       };
   100     });
   102     let dcs = allDCSs[dcsIndex];
   103     log("  Testing DCS " + dcs);
   104     let pdu = PDU_SMSC + PDU_FIRST_OCTET + PDU_SENDER + PDU_PID_NORMAL +
   105               dcs + PDU_TIMESTAMP + PDU_UDL + PDU_UD;
   106     let timeBeforeSend = Date.now();
   107     sendSmsPduToEmulator(pdu);
   108   }
   110   log("Checking Message Class 0");
   111   do_test(0);
   112 }
   114 function doTestMessageClassGeneric(allDCSs, messageClass, next) {
   115   function do_test(dcsIndex) {
   116     manager.addEventListener("received", function onReceived(event) {
   117       manager.removeEventListener("received", onReceived);
   119       // Make sure we can correctly receive the message
   120       checkMessage(event.message, null, null, messageClass);
   121       ok(event.message.timestamp >= timeBeforeSend,
   122          "Message's timestamp should be greater then the timetamp of sending");
   123       ok(event.message.timestamp <= Date.now(),
   124          "Message's timestamp should be lesser than the timestamp of now");
   125       is(event.message.sentTimestamp, SENT_TIMESTAMP,
   126          "Message's sentTimestamp should be equal to SENT_TIMESTAMP");
   128       ++dcsIndex;
   129       if (dcsIndex >= allDCSs.length) {
   130         window.setTimeout(next, 0);
   131       } else {
   132         window.setTimeout(do_test.bind(null, dcsIndex), 0);
   133       }
   134     });
   136     let dcs = allDCSs[dcsIndex];
   137     log("  Testing DCS " + dcs);
   138     let pdu = PDU_SMSC + PDU_FIRST_OCTET + PDU_SENDER + PDU_PID_NORMAL +
   139               dcs + PDU_TIMESTAMP + PDU_UDL + PDU_UD;
   141     let timeBeforeSend = Date.now();
   142     sendSmsPduToEmulator(pdu);
   143   }
   145   do_test(0);
   146 }
   148 function test_message_class_1() {
   149   let allDCSs = [
   150     "11", // General Group: 00xx
   151     "51", // Automatica Deletion Group: 01xx
   152     "F1"  // (no name) Group: 1111
   153   ];
   155   log("Checking Message Class 1");
   156   doTestMessageClassGeneric(allDCSs, "class-1", test_message_class_2);
   157 }
   159 function test_message_class_2() {
   160   let allDCSs = [
   161     "12", // General Group: 00xx
   162     "52", // Automatica Deletion Group: 01xx
   163     "F2"  // (no name) Group: 1111
   164   ];
   166   let allPIDs = [
   167     PDU_PID_NORMAL,
   168     PDU_PID_ANSI_136_R_DATA,
   169     PDU_PID_USIM_DATA_DOWNLOAD
   170   ];
   172   function do_test_dcs(dcsIndex) {
   173     function do_test_pid(pidIndex) {
   174       function onReceived(event) {
   175         if (pidIndex == 0) {
   176           // Make sure we can correctly receive the message
   177           checkMessage(event.message, null, null, "class-2");
   178           ok(event.message.timestamp >= timeBeforeSend,
   179              "Message's timestamp should be greater then the timetamp of sending");
   180           ok(event.message.timestamp <= Date.now(),
   181              "Message's timestamp should be lesser than the timestamp of now");
   182           is(event.message.sentTimestamp, SENT_TIMESTAMP,
   183              "Message's sentTimestamp should be equal to SENT_TIMESTAMP");
   185           next();
   186           return;
   187         }
   189         // TODO: Bug 792798 - B2G SMS: develop test cases for Message Class 2
   190         // Since we have "data download via SMS Point-to-Point" service enabled
   191         // but no working implementation in emulator SIM, all class 2 messages
   192         // bug normal ones should goto `dataDownloadViaSMSPP()` and we should
   193         // not receive the message in content page.
   194         ok(false, "SMS-PP messages shouldn't be sent to content");
   195       }
   197       function next() {
   198         manager.removeEventListener("received", onReceived);
   200         ++pidIndex;
   201         if (pidIndex >= allPIDs.length) {
   202           ++dcsIndex;
   203           if (dcsIndex >= allDCSs.length) {
   204             window.setTimeout(test_message_class_3, 0);
   205           } else {
   206             window.setTimeout(do_test_dcs.bind(null, dcsIndex), 0);
   207           }
   208         } else {
   209           window.setTimeout(do_test_pid.bind(null, pidIndex), 0);
   210         }
   211       }
   213       manager.addEventListener("received", onReceived);
   215       if (pidIndex != 0) {
   216         // Wait for three seconds to ensure we don't receive the message.
   217         window.setTimeout(next, 3000);
   218       }
   220       let pid = allPIDs[pidIndex];
   221       log("    Testing PID " + pid);
   223       let pdu = PDU_SMSC + PDU_FIRST_OCTET + PDU_SENDER + pid + dcs +
   224                 PDU_TIMESTAMP + PDU_UDL + PDU_UD;
   225       let timeBeforeSend = Date.now();
   226       sendSmsPduToEmulator(pdu);
   227     }
   229     let dcs = allDCSs[dcsIndex];
   230     log("  Testing DCS " + dcs);
   232     do_test_pid(0);
   233   }
   235   log("Checking Message Class 2");
   236   do_test_dcs(0);
   237 }
   239 function test_message_class_3() {
   240   let allDCSs = [
   241     "13", // General Group: 00xx
   242     "53", // Automatica Deletion Group: 01xx
   243     "F3"  // (no name) Group: 1111
   244   ];
   246   log("Checking Message Class 3");
   247   doTestMessageClassGeneric(allDCSs, "class-3", cleanUp);
   248 }
   250 function cleanUp() {
   251   if (pendingEmulatorCmdCount) {
   252     window.setTimeout(cleanUp, 100);
   253     return;
   254   }
   256   SpecialPowers.removePermission("sms", document);
   257   finish();
   258 }
   260 test_message_class_0();

mercurial