|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 60000; |
|
5 |
|
6 SpecialPowers.setBoolPref("dom.sms.enabled", true); |
|
7 SpecialPowers.addPermission("sms", true, document); |
|
8 |
|
9 let manager = window.navigator.mozMobileMessage; |
|
10 ok(manager instanceof MozMobileMessageManager, |
|
11 "manager is instance of " + manager.constructor); |
|
12 |
|
13 // Note: 378 chars and below is fine, but 379 and above will cause the issue. |
|
14 // Sending first message works, but second one we get emulator callback but |
|
15 // the actual SMS is never received, so script will timeout waiting for the |
|
16 // onreceived event. Also note that a single larger message (i.e. 1600 |
|
17 // characters) works; so it is not a compounded send limit. |
|
18 let fromNumber = "5551110000"; |
|
19 let msgLength = 379; |
|
20 let msgText = new Array(msgLength + 1).join('a'); |
|
21 |
|
22 let pendingEmulatorCmdCount = 0; |
|
23 function sendSmsToEmulator(from, text) { |
|
24 ++pendingEmulatorCmdCount; |
|
25 |
|
26 let cmd = "sms send " + from + " " + text; |
|
27 runEmulatorCmd(cmd, function(result) { |
|
28 --pendingEmulatorCmdCount; |
|
29 |
|
30 is(result[0], "OK", "Emulator response"); |
|
31 }); |
|
32 } |
|
33 |
|
34 function firstIncomingSms() { |
|
35 simulateIncomingSms(secondIncomingSms); |
|
36 } |
|
37 |
|
38 function secondIncomingSms() { |
|
39 simulateIncomingSms(cleanUp); |
|
40 } |
|
41 |
|
42 function simulateIncomingSms(nextFunction) { |
|
43 log("Simulating incoming multipart SMS (" + msgText.length |
|
44 + " chars total)."); |
|
45 |
|
46 manager.onreceived = function onreceived(event) { |
|
47 log("Received 'onreceived' event."); |
|
48 manager.onreceived = null; |
|
49 |
|
50 let incomingSms = event.message; |
|
51 ok(incomingSms, "incoming sms"); |
|
52 is(incomingSms.body, msgText, "msg body"); |
|
53 |
|
54 window.setTimeout(nextFunction, 0); |
|
55 }; |
|
56 |
|
57 sendSmsToEmulator(fromNumber, msgText); |
|
58 } |
|
59 |
|
60 function cleanUp() { |
|
61 if (pendingEmulatorCmdCount) { |
|
62 window.setTimeout(cleanUp, 100); |
|
63 return; |
|
64 } |
|
65 |
|
66 SpecialPowers.removePermission("sms", document); |
|
67 SpecialPowers.clearUserPref("dom.sms.enabled"); |
|
68 finish(); |
|
69 } |
|
70 |
|
71 // Start the test |
|
72 firstIncomingSms(); |