From c197b32f36f5a345f729818829aec115128c84ed Mon Sep 17 00:00:00 2001 From: Samael Wang Date: Mon, 16 Mar 2015 15:44:34 +0800 Subject: [PATCH] Bug 1138841 - Part 3: Add an XPCShell and a Marionette test case for encoding and decoding examination, respectively. r=btseng --HG-- extra : rebase_source : 2b52ec77288115d4434e30a65accccc451829c3c extra : histedit_source : fee6e436e2a68f521a7edabea65341daece62e27 --- .../tests/marionette/manifest.ini | 1 + .../test_decode_spanish_fallback.js | 52 +++++++++++++++++++ .../tests/test_ril_worker_sms_gsmpduhelper.js | 47 +++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 dom/mobilemessage/tests/marionette/test_decode_spanish_fallback.js diff --git a/dom/mobilemessage/tests/marionette/manifest.ini b/dom/mobilemessage/tests/marionette/manifest.ini index 79951703dd76..76d4652c49de 100644 --- a/dom/mobilemessage/tests/marionette/manifest.ini +++ b/dom/mobilemessage/tests/marionette/manifest.ini @@ -50,3 +50,4 @@ qemu = true [test_error_of_mms_send.js] [test_error_of_sms_send.js] [test_ondeleted_event.js] +[test_decode_spanish_fallback.js] diff --git a/dom/mobilemessage/tests/marionette/test_decode_spanish_fallback.js b/dom/mobilemessage/tests/marionette/test_decode_spanish_fallback.js new file mode 100644 index 000000000000..4baa2c0821f5 --- /dev/null +++ b/dom/mobilemessage/tests/marionette/test_decode_spanish_fallback.js @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +MARIONETTE_TIMEOUT = 60000; +MARIONETTE_HEAD_JS = 'head.js'; + +const PDU_SMSC_NONE = "00"; // no SMSC Address + +// | TP-RP|TP-UDHI| TP-SRI| Unused | TP-MMS| TP-MTI | +// | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | => 0x40 +const PDU_FIRST_OCTET = "40"; + +// | | <= TON => | <=== NOI ===> | +// | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | => 0xa8 +const PDU_OA = "0AA89021436587"; // 0912345678 + +const PDU_PID_NORMAL = "00"; +const PDU_DCS_GSM_7BIT = "00"; +const PDU_TIMESTAMP = "51302151740020"; // 2015/3/12 15:47:00 UTC+8 + +// ==> | <========== G ==========> | +// | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | => 0xc7 +// ======> | <========== S ========= +// | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | => 0x69 +// |<=padding=>| <========== M ===== +// | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | => 0x13 +const PDU_UD_GSM = "C76913"; + +const IE_USE_SPANISH_LOCKING_SHIFT_TABLE = "250102"; +const IE_USE_SPANISH_SINGLE_SHIFT_TABLE = "240102"; +const PDU_UDHL = "06"; + +const PDU_UDL = "0B"; // UDH occupies 7 octets = 8 septets, plus 3 septets data. + +const PDU = PDU_SMSC_NONE + PDU_FIRST_OCTET + PDU_OA + PDU_PID_NORMAL + + PDU_DCS_GSM_7BIT + PDU_TIMESTAMP + PDU_UDL + PDU_UDHL + + IE_USE_SPANISH_LOCKING_SHIFT_TABLE + IE_USE_SPANISH_SINGLE_SHIFT_TABLE + + PDU_UD_GSM; + +function verifyMessage(aMessage) { + is(aMessage.body, "GSM", "SmsMessage body"); +} + +/** + * Test and verify that user data encoded in GSM default alphabet can be + * correctly decoded with Spanish locking shift table. See bug 1138841. + */ +startTestCommon(function testCaseMain() { + return Promise.resolve() + .then(() => sendMultipleRawSmsToEmulatorAndWait([PDU])) + .then(results => verifyMessage(results[0].message)); +}); diff --git a/dom/system/gonk/tests/test_ril_worker_sms_gsmpduhelper.js b/dom/system/gonk/tests/test_ril_worker_sms_gsmpduhelper.js index 3b532362b3e6..f52c64cf85af 100644 --- a/dom/system/gonk/tests/test_ril_worker_sms_gsmpduhelper.js +++ b/dom/system/gonk/tests/test_ril_worker_sms_gsmpduhelper.js @@ -187,6 +187,53 @@ add_test(function test_GsmPDUHelper_writeStringAsSeptets() { run_next_test(); }); +/** + * Verify that encoding with Spanish locking shift table generates the same + * septets as with GSM default alphabet table. + * + * Bug 1138841 - Incorrect Spanish national language locking shift table + * definition. + */ +add_test(function test_GsmPDUHelper_writeStringAsSeptets_spanish_fallback() { + let worker = newWorker({ + postRILMessage: function(data) { + // Do nothing + }, + postMessage: function(message) { + // Do nothing + } + }); + + let context = worker.ContextPool._contexts[0]; + let helper = context.GsmPDUHelper; + let buf = []; + helper.writeHexOctet = function(octet) { + buf.push(octet); + } + + // Simple message string which is covered by GSM default alphabet. + let msg = "The quick brown fox jumps over the lazy dog"; + + // Encoded with GSM default alphabet. + helper.writeStringAsSeptets(msg, 0 /* paddingBits */, + PDU_NL_IDENTIFIER_DEFAULT, PDU_NL_IDENTIFIER_DEFAULT); + let octetsWithDefaultTable = buf; + buf = []; + + // Encoded with Spanish locking shift table. + helper.writeStringAsSeptets(msg, 0 /* paddingBits */, + PDU_NL_IDENTIFIER_SPANISH, PDU_NL_IDENTIFIER_SPANISH); + + // The length and content should be equal to what encoded with GSM default + // alphabet. + equal(octetsWithDefaultTable.length, buf.length); + for (let i = 0; i < buf.length; i++) { + equal(octetsWithDefaultTable[i], buf[i]); + } + + run_next_test(); +}); + /** * Verify GsmPDUHelper#readAddress */