dom/mobilemessage/tests/marionette/test_incoming_delete.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 let msgText = "Mozilla Firefox OS!";
michael@0 14
michael@0 15 function verifyInitialState() {
michael@0 16 log("Verifying initial state.");
michael@0 17 ok(manager instanceof MozMobileMessageManager,
michael@0 18 "manager is instance of " + manager.constructor);
michael@0 19 simulateIncomingSms();
michael@0 20 }
michael@0 21
michael@0 22 function simulateIncomingSms() {
michael@0 23 log("Simulating incoming SMS.");
michael@0 24
michael@0 25 manager.onreceived = function onreceived(event) {
michael@0 26 log("Received 'onreceived' event.");
michael@0 27 let incomingSms = event.message;
michael@0 28 ok(incomingSms, "incoming sms");
michael@0 29 ok(incomingSms.id, "sms id");
michael@0 30 log("Received SMS (id: " + incomingSms.id + ").");
michael@0 31 ok(incomingSms.threadId, "thread id");
michael@0 32 is(incomingSms.body, msgText, "msg body");
michael@0 33 is(incomingSms.delivery, "received", "delivery");
michael@0 34 is(incomingSms.deliveryStatus, "success", "deliveryStatus");
michael@0 35 is(incomingSms.read, false, "read");
michael@0 36 is(incomingSms.receiver, RECEIVER, "receiver");
michael@0 37 is(incomingSms.sender, SENDER, "sender");
michael@0 38 is(incomingSms.messageClass, "normal", "messageClass");
michael@0 39 is(incomingSms.deliveryTimestamp, 0, "deliveryTimestamp is 0");
michael@0 40
michael@0 41 verifySmsExists(incomingSms);
michael@0 42 };
michael@0 43 runEmulatorCmd("sms send " + SENDER + " " + msgText, function(result) {
michael@0 44 is(result[0], "OK", "emulator output");
michael@0 45 });
michael@0 46 }
michael@0 47
michael@0 48 function verifySmsExists(incomingSms) {
michael@0 49 log("Getting SMS (id: " + incomingSms.id + ").");
michael@0 50 let requestRet = manager.getMessage(incomingSms.id);
michael@0 51 ok(requestRet, "smsrequest obj returned");
michael@0 52
michael@0 53 requestRet.onsuccess = function(event) {
michael@0 54 log("Received 'onsuccess' smsrequest event.");
michael@0 55 ok(event.target.result, "smsrequest event.target.result");
michael@0 56 let foundSms = event.target.result;
michael@0 57 is(foundSms.id, incomingSms.id, "found SMS id matches");
michael@0 58 is(foundSms.threadId, incomingSms.threadId, "found SMS thread id matches");
michael@0 59 is(foundSms.body, msgText, "found SMS msg text matches");
michael@0 60 is(foundSms.delivery, "received", "delivery");
michael@0 61 is(foundSms.deliveryStatus, "success", "deliveryStatus");
michael@0 62 is(foundSms.read, false, "read");
michael@0 63 is(foundSms.receiver, RECEIVER, "receiver");
michael@0 64 is(foundSms.sender, SENDER, "sender");
michael@0 65 is(foundSms.messageClass, "normal", "messageClass");
michael@0 66 log("Got SMS (id: " + foundSms.id + ") as expected.");
michael@0 67 deleteSms(incomingSms);
michael@0 68 };
michael@0 69
michael@0 70 requestRet.onerror = function(event) {
michael@0 71 log("Received 'onerror' smsrequest event.");
michael@0 72 ok(event.target.error, "domerror obj");
michael@0 73 is(event.target.error.name, "NotFoundError", "error returned");
michael@0 74 log("Could not get SMS (id: " + incomingSms.id + ") but should have.");
michael@0 75 ok(false,"SMS was not found");
michael@0 76 cleanUp();
michael@0 77 };
michael@0 78 }
michael@0 79
michael@0 80 function deleteSms(smsMsgObj){
michael@0 81 log("Deleting SMS (id: " + smsMsgObj.id + ") using smsmsg obj parameter.");
michael@0 82 let requestRet = manager.delete(smsMsgObj);
michael@0 83 ok(requestRet,"smsrequest obj returned");
michael@0 84
michael@0 85 requestRet.onsuccess = function(event) {
michael@0 86 log("Received 'onsuccess' smsrequest event.");
michael@0 87 if(event.target.result){
michael@0 88 verifySmsDeleted(smsMsgObj.id);
michael@0 89 } else {
michael@0 90 log("smsrequest returned false for manager.delete");
michael@0 91 ok(false,"SMS delete failed");
michael@0 92 cleanUp();
michael@0 93 }
michael@0 94 };
michael@0 95
michael@0 96 requestRet.onerror = function(event) {
michael@0 97 log("Received 'onerror' smsrequest event.");
michael@0 98 ok(event.target.error, "domerror obj");
michael@0 99 ok(false, "manager.delete request returned unexpected error: "
michael@0 100 + event.target.error.name );
michael@0 101 cleanUp();
michael@0 102 };
michael@0 103 }
michael@0 104
michael@0 105 function verifySmsDeleted(smsId) {
michael@0 106 log("Getting SMS (id: " + smsId + ").");
michael@0 107 let requestRet = manager.getMessage(smsId);
michael@0 108 ok(requestRet, "smsrequest obj returned");
michael@0 109
michael@0 110 requestRet.onsuccess = function(event) {
michael@0 111 log("Received 'onsuccess' smsrequest event.");
michael@0 112 ok(event.target.result, "smsrequest event.target.result");
michael@0 113 let foundSms = event.target.result;
michael@0 114 is(foundSms.id, smsId, "found SMS id matches");
michael@0 115 is(foundSms.body, msgText, "found SMS msg text matches");
michael@0 116 log("Got SMS (id: " + foundSms.id + ") but should not have.");
michael@0 117 ok(false, "SMS was not deleted");
michael@0 118 cleanUp();
michael@0 119 };
michael@0 120
michael@0 121 requestRet.onerror = function(event) {
michael@0 122 log("Received 'onerror' smsrequest event.");
michael@0 123 ok(event.target.error, "domerror obj");
michael@0 124 is(event.target.error.name, "NotFoundError", "error returned");
michael@0 125 log("Could not get SMS (id: " + smsId + ") as expected.");
michael@0 126 cleanUp();
michael@0 127 };
michael@0 128 }
michael@0 129
michael@0 130 function cleanUp() {
michael@0 131 manager.onreceived = null;
michael@0 132 SpecialPowers.removePermission("sms", document);
michael@0 133 SpecialPowers.setBoolPref("dom.sms.enabled", false);
michael@0 134 finish();
michael@0 135 }
michael@0 136
michael@0 137 // Start the test
michael@0 138 verifyInitialState();

mercurial