1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobilemessage/tests/marionette/test_bug814761.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 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 +SpecialPowers.setBoolPref("dom.sms.enabled", true); 1.10 +SpecialPowers.addPermission("sms", true, document); 1.11 + 1.12 +let manager = window.navigator.mozMobileMessage; 1.13 +ok(manager instanceof MozMobileMessageManager, 1.14 + "manager is instance of " + manager.constructor); 1.15 + 1.16 +// Note: 378 chars and below is fine, but 379 and above will cause the issue. 1.17 +// Sending first message works, but second one we get emulator callback but 1.18 +// the actual SMS is never received, so script will timeout waiting for the 1.19 +// onreceived event. Also note that a single larger message (i.e. 1600 1.20 +// characters) works; so it is not a compounded send limit. 1.21 +let fromNumber = "5551110000"; 1.22 +let msgLength = 379; 1.23 +let msgText = new Array(msgLength + 1).join('a'); 1.24 + 1.25 +let pendingEmulatorCmdCount = 0; 1.26 +function sendSmsToEmulator(from, text) { 1.27 + ++pendingEmulatorCmdCount; 1.28 + 1.29 + let cmd = "sms send " + from + " " + text; 1.30 + runEmulatorCmd(cmd, function(result) { 1.31 + --pendingEmulatorCmdCount; 1.32 + 1.33 + is(result[0], "OK", "Emulator response"); 1.34 + }); 1.35 +} 1.36 + 1.37 +function firstIncomingSms() { 1.38 + simulateIncomingSms(secondIncomingSms); 1.39 +} 1.40 + 1.41 +function secondIncomingSms() { 1.42 + simulateIncomingSms(cleanUp); 1.43 +} 1.44 + 1.45 +function simulateIncomingSms(nextFunction) { 1.46 + log("Simulating incoming multipart SMS (" + msgText.length 1.47 + + " chars total)."); 1.48 + 1.49 + manager.onreceived = function onreceived(event) { 1.50 + log("Received 'onreceived' event."); 1.51 + manager.onreceived = null; 1.52 + 1.53 + let incomingSms = event.message; 1.54 + ok(incomingSms, "incoming sms"); 1.55 + is(incomingSms.body, msgText, "msg body"); 1.56 + 1.57 + window.setTimeout(nextFunction, 0); 1.58 + }; 1.59 + 1.60 + sendSmsToEmulator(fromNumber, msgText); 1.61 +} 1.62 + 1.63 +function cleanUp() { 1.64 + if (pendingEmulatorCmdCount) { 1.65 + window.setTimeout(cleanUp, 100); 1.66 + return; 1.67 + } 1.68 + 1.69 + SpecialPowers.removePermission("sms", document); 1.70 + SpecialPowers.clearUserPref("dom.sms.enabled"); 1.71 + finish(); 1.72 +} 1.73 + 1.74 +// Start the test 1.75 +firstIncomingSms();