Sat, 03 Jan 2015 20:18:00 +0100
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 REMOTE = "5559997777"; // the remote number |
michael@0 | 11 | const EMULATOR = "15555215554"; // the emulator's number |
michael@0 | 12 | |
michael@0 | 13 | let manager = window.navigator.mozMobileMessage; |
michael@0 | 14 | let inText = "Incoming SMS message. Mozilla Firefox OS!"; |
michael@0 | 15 | let outText = "Outgoing SMS message. Mozilla Firefox OS!"; |
michael@0 | 16 | let gotSmsOnsent = false; |
michael@0 | 17 | let gotReqOnsuccess = false; |
michael@0 | 18 | let inSmsId = 0; |
michael@0 | 19 | let outSmsId = 0; |
michael@0 | 20 | let inThreadId = 0; |
michael@0 | 21 | let outThreadId = 0; |
michael@0 | 22 | let inSmsTimeStamp; |
michael@0 | 23 | let inSmsSentTimeStamp; |
michael@0 | 24 | let outSmsTimeStamp; |
michael@0 | 25 | let outSmsSentTimeStamp; |
michael@0 | 26 | |
michael@0 | 27 | function verifyInitialState() { |
michael@0 | 28 | log("Verifying initial state."); |
michael@0 | 29 | ok(manager instanceof MozMobileMessageManager, |
michael@0 | 30 | "manager is instance of " + manager.constructor); |
michael@0 | 31 | simulateIncomingSms(); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function simulateIncomingSms() { |
michael@0 | 35 | log("Simulating incoming SMS."); |
michael@0 | 36 | |
michael@0 | 37 | manager.onreceived = function onreceived(event) { |
michael@0 | 38 | log("Received 'onreceived' event."); |
michael@0 | 39 | let incomingSms = event.message; |
michael@0 | 40 | ok(incomingSms, "incoming sms"); |
michael@0 | 41 | ok(incomingSms.id, "sms id"); |
michael@0 | 42 | inSmsId = incomingSms.id; |
michael@0 | 43 | log("Received SMS (id: " + inSmsId + ")."); |
michael@0 | 44 | ok(incomingSms.threadId, "thread id"); |
michael@0 | 45 | inThreadId = incomingSms.threadId; |
michael@0 | 46 | is(incomingSms.body, inText, "msg body"); |
michael@0 | 47 | is(incomingSms.delivery, "received", "delivery"); |
michael@0 | 48 | is(incomingSms.deliveryStatus, "success", "deliveryStatus"); |
michael@0 | 49 | is(incomingSms.read, false, "read"); |
michael@0 | 50 | is(incomingSms.receiver, EMULATOR, "receiver"); |
michael@0 | 51 | is(incomingSms.sender, REMOTE, "sender"); |
michael@0 | 52 | is(incomingSms.messageClass, "normal", "messageClass"); |
michael@0 | 53 | inSmsTimeStamp = incomingSms.timestamp; |
michael@0 | 54 | inSmsSentTimeStamp = incomingSms.sentTimestamp; |
michael@0 | 55 | sendSms(); |
michael@0 | 56 | }; |
michael@0 | 57 | // Simulate incoming sms sent from remoteNumber to our emulator |
michael@0 | 58 | runEmulatorCmd("sms send " + REMOTE + " " + inText, function(result) { |
michael@0 | 59 | is(result[0], "OK", "emulator output"); |
michael@0 | 60 | }); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function sendSms() { |
michael@0 | 64 | log("Sending an SMS."); |
michael@0 | 65 | manager.onsent = function(event) { |
michael@0 | 66 | log("Received 'onsent' event."); |
michael@0 | 67 | gotSmsOnsent = true; |
michael@0 | 68 | let sentSms = event.message; |
michael@0 | 69 | ok(sentSms, "outgoing sms"); |
michael@0 | 70 | ok(sentSms.id, "sms id"); |
michael@0 | 71 | outSmsId = sentSms.id; |
michael@0 | 72 | log("Sent SMS (id: " + outSmsId + ")."); |
michael@0 | 73 | ok(sentSms.threadId, "thread id"); |
michael@0 | 74 | outThreadId = sentSms.threadId; |
michael@0 | 75 | is(sentSms.body, outText, "msg body"); |
michael@0 | 76 | is(sentSms.delivery, "sent", "delivery"); |
michael@0 | 77 | is(sentSms.deliveryStatus, "pending", "deliveryStatus"); |
michael@0 | 78 | is(sentSms.read, true, "read"); |
michael@0 | 79 | is(sentSms.receiver, REMOTE, "receiver"); |
michael@0 | 80 | is(sentSms.sender, EMULATOR, "sender"); |
michael@0 | 81 | is(sentSms.messageClass, "normal", "messageClass"); |
michael@0 | 82 | outSmsTimeStamp = sentSms.timestamp; |
michael@0 | 83 | outSmsSentTimeStamp = sentSms.sentTimestamp; |
michael@0 | 84 | is(sentSms.deliveryTimestamp, 0, "deliveryTimestamp is 0"); |
michael@0 | 85 | |
michael@0 | 86 | if (gotSmsOnsent && gotReqOnsuccess) { getReceivedSms(); } |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | let requestRet = manager.send(REMOTE, outText); |
michael@0 | 90 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 91 | |
michael@0 | 92 | requestRet.onsuccess = function(event) { |
michael@0 | 93 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 94 | gotReqOnsuccess = true; |
michael@0 | 95 | if(event.target.result){ |
michael@0 | 96 | if (gotSmsOnsent && gotReqOnsuccess) { getReceivedSms(); } |
michael@0 | 97 | } else { |
michael@0 | 98 | log("smsrequest returned false for manager.send"); |
michael@0 | 99 | ok(false,"SMS send failed"); |
michael@0 | 100 | cleanUp(); |
michael@0 | 101 | } |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | requestRet.onerror = function(event) { |
michael@0 | 105 | log("Received 'onerror' smsrequest event."); |
michael@0 | 106 | ok(event.target.error, "domerror obj"); |
michael@0 | 107 | ok(false, "manager.send request returned unexpected error: " |
michael@0 | 108 | + event.target.error.name ); |
michael@0 | 109 | cleanUp(); |
michael@0 | 110 | }; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | function getReceivedSms() { |
michael@0 | 114 | log("Getting the received SMS message (id: " + inSmsId + ")."); |
michael@0 | 115 | |
michael@0 | 116 | let requestRet = manager.getMessage(inSmsId); |
michael@0 | 117 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 118 | |
michael@0 | 119 | requestRet.onsuccess = function(event) { |
michael@0 | 120 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 121 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 122 | let foundSms = event.target.result; |
michael@0 | 123 | is(foundSms.id, inSmsId, "SMS id matches"); |
michael@0 | 124 | log("Got SMS (id: " + foundSms.id + ")."); |
michael@0 | 125 | is(foundSms.threadId, inThreadId, "thread id matches"); |
michael@0 | 126 | is(foundSms.body, inText, "SMS msg text matches"); |
michael@0 | 127 | is(foundSms.delivery, "received", "delivery"); |
michael@0 | 128 | is(foundSms.deliveryStatus, "success", "deliveryStatus"); |
michael@0 | 129 | is(foundSms.read, false, "read"); |
michael@0 | 130 | is(foundSms.receiver, EMULATOR, "receiver"); |
michael@0 | 131 | is(foundSms.sender, REMOTE, "sender"); |
michael@0 | 132 | is(foundSms.messageClass, "normal", "messageClass"); |
michael@0 | 133 | is(foundSms.timestamp, inSmsTimeStamp, "timestamp matches"); |
michael@0 | 134 | is(foundSms.sentTimestamp, inSmsSentTimeStamp, "sentTimestamp matches"); |
michael@0 | 135 | getSentSms(); |
michael@0 | 136 | }; |
michael@0 | 137 | |
michael@0 | 138 | requestRet.onerror = function(event) { |
michael@0 | 139 | log("Received 'onerror' smsrequest event."); |
michael@0 | 140 | ok(event.target.error, "domerror obj"); |
michael@0 | 141 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 142 | log("Could not get SMS (id: " + inSmsId + ") but should have."); |
michael@0 | 143 | ok(false,"Could not get received SMS"); |
michael@0 | 144 | cleanUp(); |
michael@0 | 145 | }; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | function getSentSms() { |
michael@0 | 149 | log("Getting the sent SMS message (id: " + outSmsId + ")."); |
michael@0 | 150 | let requestRet = manager.getMessage(outSmsId); |
michael@0 | 151 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 152 | |
michael@0 | 153 | requestRet.onsuccess = function(event) { |
michael@0 | 154 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 155 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 156 | let foundSms = event.target.result; |
michael@0 | 157 | is(foundSms.id, outSmsId, "SMS id matches"); |
michael@0 | 158 | log("Got SMS (id: " + foundSms.id + ")."); |
michael@0 | 159 | is(foundSms.threadId, outThreadId, "thread id matches"); |
michael@0 | 160 | is(foundSms.body, outText, "SMS msg text matches"); |
michael@0 | 161 | is(foundSms.delivery, "sent", "delivery"); |
michael@0 | 162 | is(foundSms.deliveryStatus, "pending", "deliveryStatus"); |
michael@0 | 163 | is(foundSms.read, true, "read"); |
michael@0 | 164 | is(foundSms.receiver, REMOTE, "receiver"); |
michael@0 | 165 | is(foundSms.sender, EMULATOR, "sender"); |
michael@0 | 166 | is(foundSms.messageClass, "normal", "messageClass"); |
michael@0 | 167 | is(foundSms.timestamp, outSmsTimeStamp, "timestamp matches"); |
michael@0 | 168 | is(foundSms.sentTimestamp, outSmsSentTimeStamp, "sentTimestamp matches"); |
michael@0 | 169 | deleteMsgs(); |
michael@0 | 170 | }; |
michael@0 | 171 | |
michael@0 | 172 | requestRet.onerror = function(event) { |
michael@0 | 173 | log("Received 'onerror' smsrequest event."); |
michael@0 | 174 | ok(event.target.error, "domerror obj"); |
michael@0 | 175 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 176 | log("Could not get SMS (id: " + outSmsId + ") but should have."); |
michael@0 | 177 | ok(false,"Could not get sent SMS"); |
michael@0 | 178 | cleanUp(); |
michael@0 | 179 | }; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | function deleteMsgs() { |
michael@0 | 183 | log("Deleting SMS (id: " + inSmsId + ")."); |
michael@0 | 184 | let requestRet = manager.delete(inSmsId); |
michael@0 | 185 | ok(requestRet,"smsrequest obj returned"); |
michael@0 | 186 | |
michael@0 | 187 | requestRet.onsuccess = function(event) { |
michael@0 | 188 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 189 | if(event.target.result){ |
michael@0 | 190 | log("Deleting SMS (id: " + outSmsId + ")."); |
michael@0 | 191 | let nextReqRet = manager.delete(outSmsId); |
michael@0 | 192 | ok(nextReqRet,"smsrequest obj returned"); |
michael@0 | 193 | |
michael@0 | 194 | nextReqRet.onsuccess = function(event) { |
michael@0 | 195 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 196 | if(event.target.result) { |
michael@0 | 197 | cleanUp(); |
michael@0 | 198 | } else { |
michael@0 | 199 | log("smsrequest returned false for manager.delete"); |
michael@0 | 200 | ok(false,"SMS delete failed"); |
michael@0 | 201 | } |
michael@0 | 202 | }; |
michael@0 | 203 | } else { |
michael@0 | 204 | log("smsrequest returned false for manager.delete"); |
michael@0 | 205 | ok(false,"SMS delete failed"); |
michael@0 | 206 | } |
michael@0 | 207 | }; |
michael@0 | 208 | |
michael@0 | 209 | requestRet.onerror = function(event) { |
michael@0 | 210 | log("Received 'onerror' smsrequest event."); |
michael@0 | 211 | ok(event.target.error, "domerror obj"); |
michael@0 | 212 | ok(false, "manager.delete request returned unexpected error: " |
michael@0 | 213 | + event.target.error.name ); |
michael@0 | 214 | cleanUp(); |
michael@0 | 215 | }; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | function cleanUp() { |
michael@0 | 219 | manager.onreceived = null; |
michael@0 | 220 | SpecialPowers.removePermission("sms", document); |
michael@0 | 221 | SpecialPowers.clearUserPref("dom.sms.enabled"); |
michael@0 | 222 | SpecialPowers.clearUserPref("dom.sms.requestStatusReport"); |
michael@0 | 223 | |
michael@0 | 224 | finish(); |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | // Start the test |
michael@0 | 228 | verifyInitialState(); |