dom/mobilemessage/tests/marionette/test_incoming_multipart.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 const SENDER = "5555552368"; // the remote number
michael@0 10 const RECEIVER = "15555215554"; // the emulator's number
michael@0 11
michael@0 12 let manager = window.navigator.mozMobileMessage;
michael@0 13
michael@0 14 function verifyInitialState() {
michael@0 15 log("Verifying initial state.");
michael@0 16 ok(manager instanceof MozMobileMessageManager,
michael@0 17 "manager is instance of " + manager.constructor);
michael@0 18 simulateIncomingSms();
michael@0 19 }
michael@0 20
michael@0 21 function simulateIncomingSms() {
michael@0 22 let msgText = "";
michael@0 23
michael@0 24 log("Simulating incoming SMS.");
michael@0 25
michael@0 26 // Have message text > max SMS size (160 char) so will be a multi-part SMS
michael@0 27 for (var x = 1; x <= 24; x++) {
michael@0 28 msgText += 'FirefoxOS ';
michael@0 29 }
michael@0 30
michael@0 31 manager.onreceived = function onreceived(event) {
michael@0 32 log("Received 'onreceived' event.");
michael@0 33 let incomingSms = event.message;
michael@0 34 ok(incomingSms, "incoming sms");
michael@0 35 ok(incomingSms.id, "sms id");
michael@0 36 log("Received SMS (id: " + incomingSms.id + ").");
michael@0 37 ok(incomingSms.threadId, "thread id");
michael@0 38 is(incomingSms.body, msgText, "msg body");
michael@0 39 is(incomingSms.delivery, "received", "delivery");
michael@0 40 is(incomingSms.read, false, "read");
michael@0 41 is(incomingSms.receiver, RECEIVER, "receiver");
michael@0 42 is(incomingSms.sender, SENDER, "sender");
michael@0 43 is(incomingSms.deliveryTimestamp, 0, "deliveryTimestamp is 0");
michael@0 44
michael@0 45 verifySmsExists(incomingSms);
michael@0 46 };
michael@0 47 runEmulatorCmd("sms send " + SENDER + " " + msgText, function(result) {
michael@0 48 is(result[0], "OK", "emulator output");
michael@0 49 });
michael@0 50 }
michael@0 51
michael@0 52 function verifySmsExists(incomingSms) {
michael@0 53 log("Getting SMS (id: " + incomingSms.id + ").");
michael@0 54 let requestRet = manager.getMessage(incomingSms.id);
michael@0 55 ok(requestRet, "smsrequest obj returned");
michael@0 56
michael@0 57 requestRet.onsuccess = function(event) {
michael@0 58 log("Received 'onsuccess' smsrequest event.");
michael@0 59 ok(event.target.result, "smsrequest event.target.result");
michael@0 60 let foundSms = event.target.result;
michael@0 61 is(foundSms.id, incomingSms.id, "found SMS id matches");
michael@0 62 is(foundSms.threadId, incomingSms.threadId, "found SMS thread id matches");
michael@0 63 is(foundSms.body, incomingSms.body, "found SMS msg text matches");
michael@0 64 is(foundSms.delivery, "received", "delivery");
michael@0 65 is(foundSms.read, false, "read");
michael@0 66 is(foundSms.receiver, RECEIVER, "receiver");
michael@0 67 is(foundSms.sender, SENDER, "sender");
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 manager.onreceived = null;
michael@0 109 SpecialPowers.removePermission("sms", document);
michael@0 110 SpecialPowers.clearUserPref("dom.sms.enabled");
michael@0 111 finish();
michael@0 112 }
michael@0 113
michael@0 114 // Start the test
michael@0 115 verifyInitialState();

mercurial