michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 60000; michael@0: michael@0: // Copied from ril_consts.js. Some entries are commented out in ril_const.js, michael@0: // but we still want to test them here. michael@0: const GSM_SMS_STRICT_7BIT_CHARMAP = { michael@0: "\u0024": "\u0024", // "$" => "$", already in default alphabet michael@0: "\u00a5": "\u00a5", // "¥" => "¥", already in default alphabet michael@0: "\u00c0": "\u0041", // "À" => "A" michael@0: "\u00c1": "\u0041", // "Á" => "A" michael@0: "\u00c2": "\u0041", // "Â" => "A" michael@0: "\u00c3": "\u0041", // "Ã" => "A" michael@0: "\u00c4": "\u00c4", // "Ä" => "Ä", already in default alphabet michael@0: "\u00c5": "\u00c5", // "Å" => "Å", already in default alphabet michael@0: "\u00c6": "\u00c6", // "Æ" => "Æ", already in default alphabet michael@0: "\u00c7": "\u00c7", // "Ç" => "Ç", already in default alphabet michael@0: "\u00c8": "\u0045", // "È" => "E" michael@0: "\u00c9": "\u00c9", // "É" => "É", already in default alphabet michael@0: "\u00ca": "\u0045", // "Ê" => "E" michael@0: "\u00cb": "\u0045", // "Ë" => "E" michael@0: "\u00cc": "\u0049", // "Ì" => "I" michael@0: "\u00cd": "\u0049", // "Í" => "I" michael@0: "\u00ce": "\u0049", // "Î" => "I" michael@0: "\u00cf": "\u0049", // "Ï" => "I" michael@0: "\u00d1": "\u00d1", // "Ñ" => "Ñ", already in default alphabet michael@0: "\u00d2": "\u004f", // "Ò" => "O" michael@0: "\u00d3": "\u004f", // "Ó" => "O" michael@0: "\u00d4": "\u004f", // "Ô" => "O" michael@0: "\u00d5": "\u004f", // "Õ" => "O" michael@0: "\u00d6": "\u00d6", // "Ö" => "Ö", already in default alphabet michael@0: "\u00d9": "\u0055", // "Ù" => "U" michael@0: "\u00da": "\u0055", // "Ú" => "U" michael@0: "\u00db": "\u0055", // "Û" => "U" michael@0: "\u00dc": "\u00dc", // "Ü" => "Ü", already in default alphabet michael@0: "\u00df": "\u00df", // "ß" => "ß", already in default alphabet michael@0: "\u00e0": "\u00e0", // "à" => "à", already in default alphabet michael@0: "\u00e1": "\u0061", // "á" => "a" michael@0: "\u00e2": "\u0061", // "â" => "a" michael@0: "\u00e3": "\u0061", // "ã" => "a" michael@0: "\u00e4": "\u00e4", // "ä" => "ä", already in default alphabet michael@0: "\u00e5": "\u00e5", // "å" => "å", already in default alphabet michael@0: "\u00e6": "\u00e6", // "æ" => "æ", already in default alphabet michael@0: "\u00e7": "\u00c7", // "ç" => "Ç" michael@0: "\u00e8": "\u00e8", // "è" => "è", already in default alphabet michael@0: "\u00e9": "\u00e9", // "é" => "é", already in default alphabet michael@0: "\u00ea": "\u0065", // "ê" => "e" michael@0: "\u00eb": "\u0065", // "ë" => "e" michael@0: "\u00ec": "\u00ec", // "ì" => "ì", already in default alphabet michael@0: "\u00ed": "\u0069", // "í" => "i" michael@0: "\u00ee": "\u0069", // "î" => "i" michael@0: "\u00ef": "\u0069", // "ï" => "i" michael@0: "\u00f1": "\u00f1", // "ñ" => "ñ", already in default alphabet michael@0: "\u00f2": "\u00f2", // "ò" => "ò", already in default alphabet michael@0: "\u00f3": "\u006f", // "ó" => "o" michael@0: "\u00f4": "\u006f", // "ô" => "o" michael@0: "\u00f5": "\u006f", // "õ" => "o" michael@0: "\u00f6": "\u00f6", // "ö" => "ö", already in default alphabet michael@0: "\u00f8": "\u00f8", // "ø" => "ø", already in default alphabet michael@0: "\u00f9": "\u00f9", // "ù" => "ù", already in default alphabet michael@0: "\u00fa": "\u0075", // "ú" => "u" michael@0: "\u00fb": "\u0075", // "û" => "u" michael@0: "\u00fc": "\u00fc", // "ü" => "ü", already in default alphabet michael@0: "\u00fe": "\u0074", // "þ" => "t" michael@0: "\u0100": "\u0041", // "Ā" => "A" michael@0: "\u0101": "\u0061", // "ā" => "a" michael@0: "\u0106": "\u0043", // "Ć" => "C" michael@0: "\u0107": "\u0063", // "ć" => "c" michael@0: "\u010c": "\u0043", // "Č" => "C" michael@0: "\u010d": "\u0063", // "č" => "c" michael@0: "\u010f": "\u0064", // "ď" => "d" michael@0: "\u0110": "\u0044", // "Đ" => "D" michael@0: "\u0111": "\u0064", // "đ" => "d" michael@0: "\u0112": "\u0045", // "Ē" => "E" michael@0: "\u0113": "\u0065", // "ē" => "e" michael@0: "\u0118": "\u0045", // "Ę" => "E" michael@0: "\u0119": "\u0065", // "ę" => "e" michael@0: "\u0128": "\u0049", // "Ĩ" => "I" michael@0: "\u0129": "\u0069", // "ĩ" => "i" michael@0: "\u012a": "\u0049", // "Ī" => "I" michael@0: "\u012b": "\u0069", // "ī" => "i" michael@0: "\u012e": "\u0049", // "Į" => "I" michael@0: "\u012f": "\u0069", // "į" => "i" michael@0: "\u0141": "\u004c", // "Ł" => "L" michael@0: "\u0142": "\u006c", // "ł" => "l" michael@0: "\u0143": "\u004e", // "Ń" => "N" michael@0: "\u0144": "\u006e", // "ń" => "n" michael@0: "\u0147": "\u004e", // "Ň" => "N" michael@0: "\u0148": "\u006e", // "ň" => "n" michael@0: "\u014c": "\u004f", // "Ō" => "O" michael@0: "\u014d": "\u006f", // "ō" => "o" michael@0: "\u0152": "\u004f", // "Œ" => "O" michael@0: "\u0153": "\u006f", // "œ" => "o" michael@0: "\u0158": "\u0052", // "Ř" => "R" michael@0: "\u0159": "\u0072", // "ř" => "r" michael@0: "\u0160": "\u0053", // "Š" => "S" michael@0: "\u0161": "\u0073", // "š" => "s" michael@0: "\u0165": "\u0074", // "ť" => "t" michael@0: "\u0168": "\u0055", // "Ū" => "U" michael@0: "\u0169": "\u0075", // "ū" => "u" michael@0: "\u016a": "\u0055", // "Ū" => "U" michael@0: "\u016b": "\u0075", // "ū" => "u" michael@0: "\u0178": "\u0059", // "Ÿ" => "Y" michael@0: "\u0179": "\u005a", // "Ź" => "Z" michael@0: "\u017a": "\u007a", // "ź" => "z" michael@0: "\u017b": "\u005a", // "Ż" => "Z" michael@0: "\u017c": "\u007a", // "ż" => "z" michael@0: "\u017d": "\u005a", // "Ž" => "Z" michael@0: "\u017e": "\u007a", // "ž" => "z" michael@0: "\u025b": "\u0045", // "ɛ" => "E" michael@0: "\u0398": "\u0398", // "Θ" => "Θ", already in default alphabet michael@0: "\u1e7c": "\u0056", // "Ṽ" => "V" michael@0: "\u1e7d": "\u0076", // "ṽ" => "v" michael@0: "\u1ebc": "\u0045", // "Ẽ" => "E" michael@0: "\u1ebd": "\u0065", // "ẽ" => "e" michael@0: "\u1ef8": "\u0059", // "Ỹ" => "Y" michael@0: "\u1ef9": "\u0079", // "ỹ" => "y" michael@0: "\u20a4": "\u00a3", // "₤" => "£" michael@0: "\u20ac": "\u20ac", // "€" => "€", already in default alphabet michael@0: }; michael@0: michael@0: // Emulator will loop back the outgoing SMS if the phone number equals to its michael@0: // control port, which is 5554 for the first emulator instance. michael@0: const SELF = "5554"; michael@0: michael@0: SpecialPowers.setBoolPref("dom.sms.enabled", true); michael@0: SpecialPowers.addPermission("sms", true, document); michael@0: michael@0: let manager = window.navigator.mozMobileMessage; michael@0: ok(manager instanceof MozMobileMessageManager, michael@0: "manager is instance of " + manager.constructor); michael@0: michael@0: let tasks = { michael@0: // List of test fuctions. Each of them should call |tasks.next()| when michael@0: // completed or |tasks.finish()| to jump to the last one. michael@0: _tasks: [], michael@0: _nextTaskIndex: 0, michael@0: michael@0: push: function(func) { michael@0: this._tasks.push(func); michael@0: }, michael@0: michael@0: next: function() { michael@0: let index = this._nextTaskIndex++; michael@0: let task = this._tasks[index]; michael@0: try { michael@0: task(); michael@0: } catch (ex) { michael@0: ok(false, "test task[" + index + "] throws: " + ex); michael@0: // Run last task as clean up if possible. michael@0: if (index != this._tasks.length - 1) { michael@0: this.finish(); michael@0: } michael@0: } michael@0: }, michael@0: michael@0: finish: function() { michael@0: this._tasks[this._tasks.length - 1](); michael@0: }, michael@0: michael@0: run: function() { michael@0: this.next(); michael@0: } michael@0: }; michael@0: michael@0: function testStrict7BitEncodingHelper(sent, received) { michael@0: // The log message contains unicode and Marionette seems unable to process michael@0: // it and throws: |UnicodeEncodeError: 'ascii' codec can't encode character michael@0: // u'\xa5' in position 14: ordinal not in range(128)|. michael@0: // michael@0: //log("Testing '" + sent + "' => '" + received + "'"); michael@0: michael@0: let count = 0; michael@0: function done(step) { michael@0: count += step; michael@0: if (count >= 2) { michael@0: window.setTimeout(tasks.next.bind(tasks), 0); michael@0: } michael@0: } michael@0: michael@0: manager.addEventListener("received", function onReceived(event) { michael@0: event.target.removeEventListener("received", onReceived); michael@0: michael@0: let message = event.message; michael@0: is(message.body, received, "received message.body"); michael@0: michael@0: done(1); michael@0: }); michael@0: michael@0: let request = manager.send(SELF, sent); michael@0: request.addEventListener("success", function onRequestSuccess(event) { michael@0: let message = event.target.result; michael@0: is(message.body, sent, "sent message.body"); michael@0: michael@0: done(1); michael@0: }); michael@0: request.addEventListener("error", function onRequestError(event) { michael@0: ok(false, "Can't send message out!!!"); michael@0: done(2); michael@0: }); michael@0: } michael@0: michael@0: // Bug 877141 - If you send several spaces together in a sms, the other michael@0: // dipositive receives a "*" for each space. michael@0: // michael@0: // This function is called twice, with strict 7bit encoding enabled or michael@0: // disabled. Expect the same result in both sent and received text and with michael@0: // either strict 7bit encoding enabled or disabled. michael@0: function testBug877141() { michael@0: log("Testing bug 877141"); michael@0: let sent = "1 2 3"; michael@0: testStrict7BitEncodingHelper(sent, sent); michael@0: } michael@0: michael@0: tasks.push(function() { michael@0: log("Testing with dom.sms.strict7BitEncoding enabled"); michael@0: SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", true); michael@0: tasks.next(); michael@0: }); michael@0: michael@0: michael@0: // Test for combined string. michael@0: tasks.push(function() { michael@0: let sent = "", received = ""; michael@0: for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) { michael@0: sent += c; michael@0: received += GSM_SMS_STRICT_7BIT_CHARMAP[c]; michael@0: } michael@0: testStrict7BitEncodingHelper(sent, received); michael@0: }); michael@0: michael@0: // When strict7BitEncoding is enabled, we should replace characters that michael@0: // can't be encoded with GSM 7-Bit alphabets with '*'. michael@0: tasks.push(function() { michael@0: // "Happy New Year" in Chinese. michael@0: let sent = "\u65b0\u5e74\u5feb\u6a02", received = "****"; michael@0: testStrict7BitEncodingHelper(sent, received); michael@0: }); michael@0: michael@0: tasks.push(testBug877141); michael@0: michael@0: tasks.push(function() { michael@0: log("Testing with dom.sms.strict7BitEncoding disabled"); michael@0: SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", false); michael@0: tasks.next(); michael@0: }); michael@0: michael@0: // Test for combined string. michael@0: tasks.push(function() { michael@0: let sent = ""; michael@0: for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) { michael@0: sent += c; michael@0: } michael@0: testStrict7BitEncodingHelper(sent, sent); michael@0: }); michael@0: michael@0: tasks.push(function() { michael@0: // "Happy New Year" in Chinese. michael@0: let sent = "\u65b0\u5e74\u5feb\u6a02"; michael@0: testStrict7BitEncodingHelper(sent, sent); michael@0: }); michael@0: michael@0: tasks.push(testBug877141); michael@0: michael@0: // WARNING: All tasks should be pushed before this!!! michael@0: tasks.push(function cleanUp() { michael@0: SpecialPowers.removePermission("sms", document); michael@0: SpecialPowers.clearUserPref("dom.sms.enabled"); michael@0: SpecialPowers.clearUserPref("dom.sms.strict7BitEncoding"); michael@0: michael@0: finish(); michael@0: }); michael@0: michael@0: tasks.run();