From 8674d758f4148a52ef42ec2771d308d6aa67316c Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Wed, 26 Sep 2012 14:56:35 +0800 Subject: [PATCH] Bug 736706 - Part 5: test cases, r=philikon --- dom/sms/tests/marionette/manifest.ini | 1 + .../tests/marionette/test_message_classes.js | 235 ++++++++++++++++++ dom/system/gonk/tests/test_ril_worker_sms.js | 105 ++++++++ 3 files changed, 341 insertions(+) create mode 100644 dom/sms/tests/marionette/test_message_classes.js diff --git a/dom/sms/tests/marionette/manifest.ini b/dom/sms/tests/marionette/manifest.ini index 1ecb4d23d677..0054e83f2df0 100644 --- a/dom/sms/tests/marionette/manifest.ini +++ b/dom/sms/tests/marionette/manifest.ini @@ -6,3 +6,4 @@ qemu = true [test_between_emulators.py] [test_incoming.js] [test_outgoing.js] +[test_message_classes.js] diff --git a/dom/sms/tests/marionette/test_message_classes.js b/dom/sms/tests/marionette/test_message_classes.js new file mode 100644 index 000000000000..6bff38a184f0 --- /dev/null +++ b/dom/sms/tests/marionette/test_message_classes.js @@ -0,0 +1,235 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +MARIONETTE_TIMEOUT = 60000; + +const PDU_SMSC = "00"; // No SMSC Address +const PDU_FIRST_OCTET = "00"; // RP:no, UDHI:no, SRI:no, MMS:no, MTI:SMS-DELIVER +const PDU_SENDER = "0191F1"; // +1 +const PDU_PID_NORMAL = "00"; +const PDU_PID_ANSI_136_R_DATA = "7C"; +const PDU_PID_USIM_DATA_DOWNLOAD = "7F"; +const PDU_TIMESTAMP = "00101000000000"; // 2000/01/01 +const PDU_UDL = "01"; +const PDU_UD = "41"; + +SpecialPowers.addPermission("sms", true, document); + +let sms = window.navigator.mozSms; +ok(sms instanceof MozSmsManager); + +let pendingEmulatorCmdCount = 0; +function sendSmsPduToEmulator(pdu) { + ++pendingEmulatorCmdCount; + + let cmd = "sms pdu " + pdu; + runEmulatorCmd(cmd, function (result) { + --pendingEmulatorCmdCount; + + is(result[0], "OK", "Emulator response"); + }); +} + +const TIMESTAMP = Date.UTC(2000, 0, 1); +function checkMessage(message, id) { + ok(message instanceof MozSmsMessage, + "message is instanceof " + message.constructor); + if (id == null) { + ok(message.id > 0, "message.id"); + } else { + is(message.id, -1, "message.id"); + } + is(message.delivery, "received", "message.delivery"); + is(message.sender, "+1", "message.sender"); + is(message.body, "A", "message.body"); + ok(message.timestamp instanceof Date, + "message.timestamp is instanceof " + message.timestamp.constructor); + is(message.timestamp.getTime(), TIMESTAMP, "message.timestamp"); + is(message.read, false, "message.read"); +} + +function test_message_class_0() { + let allDCSs = [ + "10", // General Group: 00xx + "50", // Automatica Deletion Group: 01xx + "F0" // (no name) Group: 1111 + ]; + + function do_test(dcsIndex) { + sms.addEventListener("received", function onReceived(event) { + sms.removeEventListener("received", onReceived); + + let message = event.message; + checkMessage(message, -1); + + // Make sure the message is not stored. + let request = sms.getMessages(null, false); + request.onsuccess = function onsuccess() { + let cursor = request.result; + if (cursor.message) { + // Here we check whether there is any message of the same sender. + isnot(cursor.message.sender, message.sender, "cursor.message.sender"); + + cursor.continue(); + return; + } + + // All messages checked. Done. + ++dcsIndex; + if (dcsIndex >= allDCSs.length) { + window.setTimeout(test_message_class_1, 0); + } else { + window.setTimeout(do_test.bind(null, dcsIndex), 0); + } + }; + request.onerror = function onerror() { + ok(false, "Can't fetch messages from SMS database"); + }; + }); + + let dcs = allDCSs[dcsIndex]; + log(" Testing DCS " + dcs); + let pdu = PDU_SMSC + PDU_FIRST_OCTET + PDU_SENDER + PDU_PID_NORMAL + + dcs + PDU_TIMESTAMP + PDU_UDL + PDU_UD; + + sendSmsPduToEmulator(pdu); + } + + log("Checking Message Class 0"); + do_test(0); +} + +function doTestMessageClassGeneric(allDCSs, next) { + function do_test(dcsIndex) { + sms.addEventListener("received", function onReceived(event) { + sms.removeEventListener("received", onReceived); + + // Make sure we can correctly receive the message + checkMessage(event.message); + + ++dcsIndex; + if (dcsIndex >= allDCSs.length) { + window.setTimeout(next, 0); + } else { + window.setTimeout(do_test.bind(null, dcsIndex), 0); + } + }); + + let dcs = allDCSs[dcsIndex]; + log(" Testing DCS " + dcs); + let pdu = PDU_SMSC + PDU_FIRST_OCTET + PDU_SENDER + PDU_PID_NORMAL + + dcs + PDU_TIMESTAMP + PDU_UDL + PDU_UD; + + sendSmsPduToEmulator(pdu); + } + + do_test(0); +} + +function test_message_class_1() { + let allDCSs = [ + "11", // General Group: 00xx + "51", // Automatica Deletion Group: 01xx + "F1" // (no name) Group: 1111 + ]; + + log("Checking Message Class 1"); + doTestMessageClassGeneric(allDCSs, test_message_class_2); +} + +function test_message_class_2() { + let allDCSs = [ + "12", // General Group: 00xx + "52", // Automatica Deletion Group: 01xx + "F2" // (no name) Group: 1111 + ]; + + let allPIDs = [ + PDU_PID_NORMAL, + PDU_PID_ANSI_136_R_DATA, + PDU_PID_USIM_DATA_DOWNLOAD + ]; + + function do_test_dcs(dcsIndex) { + function do_test_pid(pidIndex) { + function onReceived(event) { + if (pidIndex == 0) { + // Make sure we can correctly receive the message + checkMessage(event.message); + + next(); + return; + } + + // TODO: Bug 792798 - B2G SMS: develop test cases for Message Class 2 + // Since we have "data download via SMS Point-to-Point" service enabled + // but no working implementation in emulator SIM, all class 2 messages + // bug normal ones should goto `dataDownloadViaSMSPP()` and we should + // not receive the message in content page. + ok(false, "SMS-PP messages shouldn't be sent to content"); + } + + function next() { + sms.removeEventListener("received", onReceived); + + ++pidIndex; + if (pidIndex >= allPIDs.length) { + ++dcsIndex; + if (dcsIndex >= allDCSs.length) { + window.setTimeout(test_message_class_3, 0); + } else { + window.setTimeout(do_test_dcs.bind(null, dcsIndex), 0); + } + } else { + window.setTimeout(do_test_pid.bind(null, pidIndex), 0); + } + } + + sms.addEventListener("received", onReceived); + + if (pidIndex != 0) { + // Wait for three seconds to ensure we don't receive the message. + window.setTimeout(next, 3000); + } + + let pid = allPIDs[pidIndex]; + log(" Testing PID " + pid); + + let pdu = PDU_SMSC + PDU_FIRST_OCTET + PDU_SENDER + pid + dcs + + PDU_TIMESTAMP + PDU_UDL + PDU_UD; + + sendSmsPduToEmulator(pdu); + } + + let dcs = allDCSs[dcsIndex]; + log(" Testing DCS " + dcs); + + do_test_pid(0); + } + + log("Checking Message Class 2"); + do_test_dcs(0); +} + +function test_message_class_3() { + let allDCSs = [ + "13", // General Group: 00xx + "53", // Automatica Deletion Group: 01xx + "F3" // (no name) Group: 1111 + ]; + + log("Checking Message Class 3"); + doTestMessageClassGeneric(allDCSs, cleanUp); +} + +function cleanUp() { + if (pendingEmulatorCmdCount) { + window.setTimeout(cleanUp, 100); + return; + } + + SpecialPowers.removePermission("sms", document); + finish(); +} + +test_message_class_0(); diff --git a/dom/system/gonk/tests/test_ril_worker_sms.js b/dom/system/gonk/tests/test_ril_worker_sms.js index 53c0196f2005..69c2e454e54c 100644 --- a/dom/system/gonk/tests/test_ril_worker_sms.js +++ b/dom/system/gonk/tests/test_ril_worker_sms.js @@ -54,6 +54,111 @@ add_test(function test_nl_single_shift_tables_validity() { run_next_test(); }); +/** + * Verify GsmPDUHelper#readDataCodingScheme. + */ +add_test(function test_GsmPDUHelper_readDataCodingScheme() { + let worker = newWorker({ + postRILMessage: function fakePostRILMessage(data) { + // Do nothing + }, + postMessage: function fakePostMessage(message) { + // Do nothing + } + }); + + let helper = worker.GsmPDUHelper; + function test_dcs(dcs, encoding, messageClass, mwi) { + helper.readHexOctet = function () { + return dcs; + } + + let msg = {}; + helper.readDataCodingScheme(msg); + + do_check_eq(msg.dcs, dcs); + do_check_eq(msg.encoding, encoding); + do_check_eq(msg.messageClass, messageClass); + do_check_eq(msg.mwi == null, mwi == null); + if (mwi != null) { + do_check_eq(msg.mwi.active, mwi.active); + do_check_eq(msg.mwi.discard, mwi.discard); + do_check_eq(msg.mwi.msgCount, mwi.msgCount); + } + } + + // Group 00xx + // Bit 3 and 2 indicate the character set being used. + test_dcs(0x00, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0x04, PDU_DCS_MSG_CODING_8BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0x08, PDU_DCS_MSG_CODING_16BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0x0C, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + // Bit 4, if set to 0, indicates that bits 1 to 0 are reserved and have no + // message class meaning. + test_dcs(0x01, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0x02, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0x03, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + // Bit 4, if set to 1, indicates that bits 1 to 0 have a message class meaning. + test_dcs(0x10, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_0); + test_dcs(0x11, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_ME_SPECIFIC); + test_dcs(0x12, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_SIM_SPECIFIC); + test_dcs(0x13, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_TE_SPECIFIC); + + // Group 01xx + test_dcs(0x50, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_0); + + // Group 1000..1011: reserved + test_dcs(0x8F, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0x9F, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0xAF, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + test_dcs(0xBF, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN); + + // Group 1100: Message Waiting Indication Group: Discard Message + // Bit 3 indicates Indication Sense: + test_dcs(0xC0, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: false, discard: true, msgCount: 0}); + test_dcs(0xC8, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: true, discard: true, msgCount: -1}); + // Bit 2 is reserved, and set to 0: + test_dcs(0xCC, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: true, discard: true, msgCount: -1}); + + // Group 1101: Message Waiting Indication Group: Store Message + // Bit 3 indicates Indication Sense: + test_dcs(0xD0, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: false, discard: false, msgCount: 0}); + test_dcs(0xD8, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: true, discard: false, msgCount: -1}); + // Bit 2 is reserved, and set to 0: + test_dcs(0xDC, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: true, discard: false, msgCount: -1}); + + // Group 1110: Message Waiting Indication Group: Store Message, UCS2 + // Bit 3 indicates Indication Sense: + test_dcs(0xE0, PDU_DCS_MSG_CODING_16BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: false, discard: false, msgCount: 0}); + test_dcs(0xE8, PDU_DCS_MSG_CODING_16BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: true, discard: false, msgCount: -1}); + // Bit 2 is reserved, and set to 0: + test_dcs(0xEC, PDU_DCS_MSG_CODING_16BITS_ALPHABET, PDU_DCS_MSG_CLASS_UNKNOWN, + {active: true, discard: false, msgCount: -1}); + + // Group 1111 + test_dcs(0xF0, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_0); + test_dcs(0xF1, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_ME_SPECIFIC); + test_dcs(0xF2, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_SIM_SPECIFIC); + test_dcs(0xF3, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_TE_SPECIFIC); + test_dcs(0xF4, PDU_DCS_MSG_CODING_8BITS_ALPHABET, PDU_DCS_MSG_CLASS_0); + test_dcs(0xF5, PDU_DCS_MSG_CODING_8BITS_ALPHABET, PDU_DCS_MSG_CLASS_ME_SPECIFIC); + test_dcs(0xF6, PDU_DCS_MSG_CODING_8BITS_ALPHABET, PDU_DCS_MSG_CLASS_SIM_SPECIFIC); + test_dcs(0xF7, PDU_DCS_MSG_CODING_8BITS_ALPHABET, PDU_DCS_MSG_CLASS_TE_SPECIFIC); + // Bit 3 is reserved and should be set to 0, but if it doesn't we should + // ignore it. + test_dcs(0xF8, PDU_DCS_MSG_CODING_7BITS_ALPHABET, PDU_DCS_MSG_CLASS_0); + + run_next_test(); +}); + /** * Verify RadioInterfaceLayer#_countGsm7BitSeptets() and * GsmPDUHelper#writeStringAsSeptets() algorithm match each other.