dom/mobilemessage/tests/marionette/test_outgoing_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.setBoolPref("dom.sms.requestStatusReport", true);
michael@0 8 SpecialPowers.addPermission("sms", true, document);
michael@0 9
michael@0 10 const SENDER = "15555215554"; // the emulator's number
michael@0 11 const RECEIVER = "5551117777"; // the destination number
michael@0 12
michael@0 13 let manager = window.navigator.mozMobileMessage;
michael@0 14 let msgText = "Mozilla Firefox OS!";
michael@0 15 let gotSmsOnsent = false;
michael@0 16 let gotReqOnsuccess = false;
michael@0 17
michael@0 18 function verifyInitialState() {
michael@0 19 log("Verifying initial state.");
michael@0 20 ok(manager instanceof MozMobileMessageManager,
michael@0 21 "manager is instance of " + manager.constructor);
michael@0 22 sendSms();
michael@0 23 }
michael@0 24
michael@0 25 function sendSms() {
michael@0 26 let smsId = 0;
michael@0 27
michael@0 28 log("Sending an SMS.");
michael@0 29 manager.onsent = function(event) {
michael@0 30 log("Received 'onsent' event.");
michael@0 31 gotSmsOnsent = true;
michael@0 32 let sentSms = event.message;
michael@0 33 ok(sentSms, "outgoing sms");
michael@0 34 ok(sentSms.id, "sms id");
michael@0 35 smsId = sentSms.id;
michael@0 36 log("Sent SMS (id: " + smsId + ").");
michael@0 37 ok(sentSms.threadId, "thread id");
michael@0 38 is(sentSms.body, msgText, "msg body");
michael@0 39 is(sentSms.delivery, "sent", "delivery");
michael@0 40 is(sentSms.deliveryStatus, "pending", "deliveryStatus");
michael@0 41 is(sentSms.read, true, "read");
michael@0 42 is(sentSms.receiver, RECEIVER, "receiver");
michael@0 43 is(sentSms.sender, SENDER, "sender");
michael@0 44 is(sentSms.messageClass, "normal", "messageClass");
michael@0 45 is(sentSms.deliveryTimestamp, 0, "deliveryTimestamp is 0");
michael@0 46
michael@0 47 if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); }
michael@0 48 };
michael@0 49
michael@0 50 let requestRet = manager.send(RECEIVER, msgText);
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 gotReqOnsuccess = true;
michael@0 56 if(event.target.result){
michael@0 57 if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); }
michael@0 58 } else {
michael@0 59 log("smsrequest returned false for manager.send");
michael@0 60 ok(false,"SMS send failed");
michael@0 61 cleanUp();
michael@0 62 }
michael@0 63 };
michael@0 64
michael@0 65 requestRet.onerror = function(event) {
michael@0 66 log("Received 'onerror' smsrequest event.");
michael@0 67 ok(event.target.error, "domerror obj");
michael@0 68 ok(false, "manager.send request returned unexpected error: "
michael@0 69 + event.target.error.name );
michael@0 70 cleanUp();
michael@0 71 };
michael@0 72 }
michael@0 73
michael@0 74 function verifySmsExists(smsId) {
michael@0 75 log("Getting SMS (id: " + smsId + ").");
michael@0 76 let requestRet = manager.getMessage(smsId);
michael@0 77 ok(requestRet, "smsrequest obj returned");
michael@0 78
michael@0 79 requestRet.onsuccess = function(event) {
michael@0 80 log("Received 'onsuccess' smsrequest event.");
michael@0 81 ok(event.target.result, "smsrequest event.target.result");
michael@0 82 let foundSms = event.target.result;
michael@0 83 is(foundSms.id, smsId, "found SMS id matches");
michael@0 84 is(foundSms.body, msgText, "found SMS msg text matches");
michael@0 85 is(foundSms.delivery, "sent", "delivery");
michael@0 86 is(foundSms.read, true, "read");
michael@0 87 is(foundSms.receiver, RECEIVER, "receiver");
michael@0 88 is(foundSms.sender, SENDER, "sender");
michael@0 89 is(foundSms.messageClass, "normal", "messageClass");
michael@0 90 log("Got SMS (id: " + foundSms.id + ") as expected.");
michael@0 91 deleteSms(smsId);
michael@0 92 };
michael@0 93
michael@0 94 requestRet.onerror = function(event) {
michael@0 95 log("Received 'onerror' smsrequest event.");
michael@0 96 ok(event.target.error, "domerror obj");
michael@0 97 is(event.target.error.name, "NotFoundError", "error returned");
michael@0 98 log("Could not get SMS (id: " + smsId + ") but should have.");
michael@0 99 ok(false,"SMS was not found");
michael@0 100 cleanUp();
michael@0 101 };
michael@0 102 }
michael@0 103
michael@0 104 function deleteSms(smsId){
michael@0 105 log("Deleting SMS (id: " + smsId + ") using sms id parameter.");
michael@0 106 let requestRet = manager.delete(smsId);
michael@0 107 ok(requestRet,"smsrequest obj returned");
michael@0 108
michael@0 109 requestRet.onsuccess = function(event) {
michael@0 110 log("Received 'onsuccess' smsrequest event.");
michael@0 111 if(event.target.result){
michael@0 112 verifySmsDeleted(smsId);
michael@0 113 } else {
michael@0 114 log("smsrequest returned false for manager.delete");
michael@0 115 ok(false,"SMS delete failed");
michael@0 116 cleanUp();
michael@0 117 }
michael@0 118 };
michael@0 119
michael@0 120 requestRet.onerror = function(event) {
michael@0 121 log("Received 'onerror' smsrequest event.");
michael@0 122 ok(event.target.error, "domerror obj");
michael@0 123 ok(false, "manager.delete request returned unexpected error: "
michael@0 124 + event.target.error.name );
michael@0 125 cleanUp();
michael@0 126 };
michael@0 127 }
michael@0 128
michael@0 129 function verifySmsDeleted(smsId) {
michael@0 130 log("Getting SMS (id: " + smsId + ").");
michael@0 131 let requestRet = manager.getMessage(smsId);
michael@0 132 ok(requestRet, "smsrequest obj returned");
michael@0 133
michael@0 134 requestRet.onsuccess = function(event) {
michael@0 135 log("Received 'onsuccess' smsrequest event.");
michael@0 136 ok(event.target.result, "smsrequest event.target.result");
michael@0 137 let foundSms = event.target.result;
michael@0 138 is(foundSms.id, smsId, "found SMS id matches");
michael@0 139 is(foundSms.body, msgText, "found SMS msg text matches");
michael@0 140 log("Got SMS (id: " + foundSms.id + ") but should not have.");
michael@0 141 ok(false, "SMS was not deleted");
michael@0 142 cleanUp();
michael@0 143 };
michael@0 144
michael@0 145 requestRet.onerror = function(event) {
michael@0 146 log("Received 'onerror' smsrequest event.");
michael@0 147 ok(event.target.error, "domerror obj");
michael@0 148 is(event.target.error.name, "NotFoundError", "error returned");
michael@0 149 log("Could not get SMS (id: " + smsId + ") as expected.");
michael@0 150 cleanUp();
michael@0 151 };
michael@0 152 }
michael@0 153
michael@0 154 function cleanUp() {
michael@0 155 manager.onsent = null;
michael@0 156 SpecialPowers.removePermission("sms", document);
michael@0 157 SpecialPowers.clearUserPref("dom.sms.enabled");
michael@0 158 SpecialPowers.clearUserPref("dom.sms.requestStatusReport");
michael@0 159 finish();
michael@0 160 }
michael@0 161
michael@0 162 // Start the test
michael@0 163 verifyInitialState();

mercurial