Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | MARIONETTE_TIMEOUT = 60000; |
michael@0 | 5 | |
michael@0 | 6 | SpecialPowers.setBoolPref("dom.sms.enabled", true); |
michael@0 | 7 | SpecialPowers.addPermission("sms", true, document); |
michael@0 | 8 | |
michael@0 | 9 | let manager = window.navigator.mozMobileMessage; |
michael@0 | 10 | // https://developer.mozilla.org/en-US/docs/DOM/SmsManager |
michael@0 | 11 | let maxCharsPerSms = 160; |
michael@0 | 12 | let maxSegments = 10; // 10 message segments concatenated into 1 multipart SMS |
michael@0 | 13 | |
michael@0 | 14 | const REMOTE = "5551234567"; // the remote number |
michael@0 | 15 | const EMULATOR = "15555215554"; // the emulator's number |
michael@0 | 16 | |
michael@0 | 17 | function verifyInitialState() { |
michael@0 | 18 | log("Verifying initial state."); |
michael@0 | 19 | ok(manager instanceof MozMobileMessageManager, |
michael@0 | 20 | "manager is instance of " + manager.constructor); |
michael@0 | 21 | simulateIncomingSms(); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function simulateIncomingSms() { |
michael@0 | 25 | let msgText = ""; |
michael@0 | 26 | |
michael@0 | 27 | // Build the message text |
michael@0 | 28 | msgText = new Array((maxCharsPerSms * maxSegments) + 1).join('a'); |
michael@0 | 29 | log("Simulating incoming multipart SMS (" + msgText.length + |
michael@0 | 30 | " chars total)."); |
michael@0 | 31 | |
michael@0 | 32 | manager.onreceived = function onreceived(event) { |
michael@0 | 33 | manager.onreceived = null; |
michael@0 | 34 | log("Received 'onreceived' event."); |
michael@0 | 35 | |
michael@0 | 36 | let incomingSms = event.message; |
michael@0 | 37 | ok(incomingSms, "incoming sms"); |
michael@0 | 38 | ok(incomingSms.id, "sms id"); |
michael@0 | 39 | log("Received SMS (id: " + incomingSms.id + ")."); |
michael@0 | 40 | ok(incomingSms.threadId, "thread id"); |
michael@0 | 41 | is(incomingSms.body.length, msgText.length, "msg body length"); |
michael@0 | 42 | is(incomingSms.body, msgText, "msg body"); |
michael@0 | 43 | is(incomingSms.delivery, "received", "delivery"); |
michael@0 | 44 | is(incomingSms.read, false, "read"); |
michael@0 | 45 | is(incomingSms.receiver, EMULATOR, "receiver"); |
michael@0 | 46 | is(incomingSms.sender, REMOTE, "sender"); |
michael@0 | 47 | is(incomingSms.deliveryTimestamp, 0, "deliveryTimestamp is 0"); |
michael@0 | 48 | |
michael@0 | 49 | verifySmsExists(incomingSms); |
michael@0 | 50 | }; |
michael@0 | 51 | runEmulatorCmd("sms send " + REMOTE + " " + msgText, function(result) { |
michael@0 | 52 | is(result[0], "OK", "emulator output"); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function verifySmsExists(incomingSms) { |
michael@0 | 57 | log("Getting SMS (id: " + incomingSms.id + ")."); |
michael@0 | 58 | let requestRet = manager.getMessage(incomingSms.id); |
michael@0 | 59 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 60 | |
michael@0 | 61 | requestRet.onsuccess = function(event) { |
michael@0 | 62 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 63 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 64 | let foundSms = event.target.result; |
michael@0 | 65 | is(foundSms.id, incomingSms.id, "found SMS id matches"); |
michael@0 | 66 | is(foundSms.body.length, incomingSms.body.length, "SMS text length"); |
michael@0 | 67 | is(foundSms.body, incomingSms.body, "found SMS msg text matches"); |
michael@0 | 68 | log("Got SMS (id: " + foundSms.id + ") as expected."); |
michael@0 | 69 | deleteSms(incomingSms); |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | requestRet.onerror = function(event) { |
michael@0 | 73 | log("Received 'onerror' smsrequest event."); |
michael@0 | 74 | ok(event.target.error, "domerror obj"); |
michael@0 | 75 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 76 | log("Could not get SMS (id: " + incomingSms.id + ") but should have."); |
michael@0 | 77 | ok(false, "SMS was not found"); |
michael@0 | 78 | cleanUp(); |
michael@0 | 79 | }; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function deleteSms(smsMsgObj){ |
michael@0 | 83 | log("Deleting SMS (id: " + smsMsgObj.id + ") using smsmsg obj parameter."); |
michael@0 | 84 | let requestRet = manager.delete(smsMsgObj); |
michael@0 | 85 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 86 | |
michael@0 | 87 | requestRet.onsuccess = function(event) { |
michael@0 | 88 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 89 | if (event.target.result) { |
michael@0 | 90 | cleanUp(); |
michael@0 | 91 | } else { |
michael@0 | 92 | log("smsrequest returned false for manager.delete"); |
michael@0 | 93 | ok(false, "SMS delete failed"); |
michael@0 | 94 | cleanUp(); |
michael@0 | 95 | } |
michael@0 | 96 | }; |
michael@0 | 97 | |
michael@0 | 98 | requestRet.onerror = function(event) { |
michael@0 | 99 | log("Received 'onerror' smsrequest event."); |
michael@0 | 100 | ok(event.target.error, "domerror obj"); |
michael@0 | 101 | ok(false, "manager.delete request returned unexpected error: " + |
michael@0 | 102 | event.target.error.name); |
michael@0 | 103 | cleanUp(); |
michael@0 | 104 | }; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function cleanUp() { |
michael@0 | 108 | SpecialPowers.removePermission("sms", document); |
michael@0 | 109 | SpecialPowers.clearUserPref("dom.sms.enabled"); |
michael@0 | 110 | finish(); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | // Start the test |
michael@0 | 114 | verifyInitialState(); |