1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobilemessage/tests/marionette/test_emulator_loopback.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 60000; 1.8 + 1.9 +const SELF = "5554"; 1.10 + 1.11 +SpecialPowers.setBoolPref("dom.sms.enabled", true); 1.12 +SpecialPowers.addPermission("sms", true, document); 1.13 + 1.14 +function cleanUp() { 1.15 + SpecialPowers.removePermission("sms", document); 1.16 + SpecialPowers.clearUserPref("dom.sms.enabled"); 1.17 + finish(); 1.18 +} 1.19 + 1.20 +let manager = window.navigator.mozMobileMessage; 1.21 +ok(manager instanceof MozMobileMessageManager, 1.22 + "manager is instance of " + manager.constructor); 1.23 + 1.24 +function randomString16() { 1.25 + return Math.random().toString(36).substr(2, 16); 1.26 +} 1.27 + 1.28 +function times(str, n) { 1.29 + return (new Array(n + 1)).join(str); 1.30 +} 1.31 + 1.32 +function repeat(func, array, oncomplete) { 1.33 + (function do_call(index) { 1.34 + let next = index < (array.length - 1) ? do_call.bind(null, index + 1) : oncomplete; 1.35 + func.apply(null, [array[index], next]); 1.36 + })(0); 1.37 +} 1.38 + 1.39 +function doTest(body, callback) { 1.40 + manager.addEventListener("received", function onReceived(event) { 1.41 + event.target.removeEventListener(event.type, arguments.callee); 1.42 + 1.43 + let message = event.message; 1.44 + is(message.body, body, "message.body"); 1.45 + 1.46 + window.setTimeout(callback, 0); 1.47 + }); 1.48 + 1.49 + let request = manager.send(SELF, body); 1.50 + request.onerror = function onerror() { 1.51 + ok(false, "failed to send message '" + body + "' to '" + SELF + "'"); 1.52 + }; 1.53 +} 1.54 + 1.55 +repeat(doTest, [ 1.56 + // Random alphanumeric string of 16 characters. 1.57 + randomString16(), 1.58 + // Long long text message for multipart messages. 1.59 + times(randomString16(), 100), 1.60 + 1.61 + // UCS2 string for the first sentence of "The Cooing", Classic of Poetry. 1.62 + "\u95dc\u95dc\u96ce\u9ce9\uff0c\u5728\u6cb3\u4e4b\u6d32\u3002", 1.63 + // Long long UCS2 text message for multipart messages. 1.64 + times("\u95dc\u95dc\u96ce\u9ce9\uff0c\u5728\u6cb3\u4e4b\u6d32\u3002", 100), 1.65 + 1.66 + // Test case from Bug 809553 1.67 + "zertuuuppzuzyeueieieyeieoeiejeheejrueufjfjfjjfjfkxifjfjfufjjfjfufujdjduxxjdu" 1.68 + + "djdjdjdudhdjdhdjdbddhbfjfjxbuwjdjdudjddjdhdhdvdyudusjdudhdjjfjdvdudbddjdbd" 1.69 + + "usjfbjdfudjdhdjbzuuzyzehdjjdjwybwudjvwywuxjdbfudsbwuwbwjdjdbwywhdbddudbdjd" 1.70 + + "uejdhdudbdduwjdbjddudjdjdjdudjdbdjdhdhdjjdjbxudjdbxufjudbdjhdjdisjsjzusbzh" 1.71 + + "xbdudksksuqjgdjdb jeudi jeudis duhebevzcevevsvs DVD suscite eh du d des jv" 1.72 + + " y b Dj. Du wh. Hu Deb wh. Du web h w show d DVD h w v. Th\u00e9 \u00e9c" 1.73 + + "hec d whdvdj. Wh d'h\u00f4tel DVD. IMAX eusjw ii ce", 1.74 + 1.75 + // Android Emulator specific problems: 1.76 + // 1) wrong default 7Bit alphabet character for "Ň"(U+0147). 1.77 + "\u0147", 1.78 + // 2) problem in decoding strings encoded with GSM 7Bit Alphabets and 1.79 + // containing characters on extension tables. 1.80 + "\u20ac****", 1.81 +], cleanUp);