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.

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

mercurial