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.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 MSG_TEXT = "Mozilla Firefox OS!"; |
michael@0 | 14 | let SMS_NUMBER = 100; |
michael@0 | 15 | |
michael@0 | 16 | let SmsList = []; |
michael@0 | 17 | let checkDone = true; |
michael@0 | 18 | let emulatorReady = true; |
michael@0 | 19 | |
michael@0 | 20 | let pendingEmulatorCmdCount = 0; |
michael@0 | 21 | function sendSmsToEmulator(from, text) { |
michael@0 | 22 | ++pendingEmulatorCmdCount; |
michael@0 | 23 | |
michael@0 | 24 | let cmd = "sms send " + from + " " + text; |
michael@0 | 25 | runEmulatorCmd(cmd, function(result) { |
michael@0 | 26 | --pendingEmulatorCmdCount; |
michael@0 | 27 | |
michael@0 | 28 | is(result[0], "OK", "Emulator response"); |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | let tasks = { |
michael@0 | 33 | // List of test fuctions. Each of them should call |tasks.next()| when |
michael@0 | 34 | // completed or |tasks.finish()| to jump to the last one. |
michael@0 | 35 | _tasks: [], |
michael@0 | 36 | _nextTaskIndex: 0, |
michael@0 | 37 | |
michael@0 | 38 | push: function(func) { |
michael@0 | 39 | this._tasks.push(func); |
michael@0 | 40 | }, |
michael@0 | 41 | |
michael@0 | 42 | next: function() { |
michael@0 | 43 | let index = this._nextTaskIndex++; |
michael@0 | 44 | let task = this._tasks[index]; |
michael@0 | 45 | try { |
michael@0 | 46 | task(); |
michael@0 | 47 | } catch (ex) { |
michael@0 | 48 | ok(false, "test task[" + index + "] throws: " + ex); |
michael@0 | 49 | // Run last task as clean up if possible. |
michael@0 | 50 | if (index != this._tasks.length - 1) { |
michael@0 | 51 | this.finish(); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | finish: function() { |
michael@0 | 57 | this._tasks[this._tasks.length - 1](); |
michael@0 | 58 | }, |
michael@0 | 59 | |
michael@0 | 60 | run: function() { |
michael@0 | 61 | this.next(); |
michael@0 | 62 | } |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | function taskNextWrapper() { |
michael@0 | 66 | tasks.next(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function verifySmsExists(incomingSms) { |
michael@0 | 70 | log("Getting SMS (id: " + incomingSms.id + ")."); |
michael@0 | 71 | let requestRet = manager.getMessage(incomingSms.id); |
michael@0 | 72 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 73 | |
michael@0 | 74 | requestRet.onsuccess = function(event) { |
michael@0 | 75 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 76 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 77 | let foundSms = event.target.result; |
michael@0 | 78 | is(foundSms.id, incomingSms.id, "found SMS id matches"); |
michael@0 | 79 | is(foundSms.threadId, incomingSms.threadId, "found SMS thread id matches"); |
michael@0 | 80 | is(foundSms.body, MSG_TEXT, "found SMS msg text matches"); |
michael@0 | 81 | is(foundSms.delivery, "received", "delivery"); |
michael@0 | 82 | is(foundSms.deliveryStatus, "success", "deliveryStatus"); |
michael@0 | 83 | is(foundSms.read, false, "read"); |
michael@0 | 84 | is(foundSms.receiver, RECEIVER, "receiver"); |
michael@0 | 85 | is(foundSms.sender, SENDER, "sender"); |
michael@0 | 86 | is(foundSms.messageClass, "normal", "messageClass"); |
michael@0 | 87 | log("Got SMS (id: " + foundSms.id + ") as expected."); |
michael@0 | 88 | |
michael@0 | 89 | SmsList.push(incomingSms); |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | requestRet.onerror = function(event) { |
michael@0 | 93 | log("Received 'onerror' smsrequest event."); |
michael@0 | 94 | ok(event.target.error, "domerror obj"); |
michael@0 | 95 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 96 | log("Could not get SMS (id: " + incomingSms.id + ") but should have."); |
michael@0 | 97 | ok(false,"SMS was not found"); |
michael@0 | 98 | tasks.finish(); |
michael@0 | 99 | }; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | let verifDeletedCount = 0; |
michael@0 | 103 | function verifySmsDeleted(smsId) { |
michael@0 | 104 | log("Getting SMS (id: " + smsId + ")."); |
michael@0 | 105 | let requestRet = manager.getMessage(smsId); |
michael@0 | 106 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 107 | |
michael@0 | 108 | requestRet.onsuccess = function(event) { |
michael@0 | 109 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 110 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 111 | let foundSms = event.target.result; |
michael@0 | 112 | is(foundSms.id, smsId, "found SMS id matches"); |
michael@0 | 113 | is(foundSms.body, MSG_TEXT, "found SMS msg text matches"); |
michael@0 | 114 | log("Got SMS (id: " + foundSms.id + ") but should not have."); |
michael@0 | 115 | ok(false, "SMS was not deleted"); |
michael@0 | 116 | tasks.finish(); |
michael@0 | 117 | }; |
michael@0 | 118 | |
michael@0 | 119 | requestRet.onerror = function(event) { |
michael@0 | 120 | log("Received 'onerror' smsrequest event."); |
michael@0 | 121 | ok(event.target.error, "domerror obj"); |
michael@0 | 122 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 123 | log("Could not get SMS (id: " + smsId + ") as expected."); |
michael@0 | 124 | verifDeletedCount++; |
michael@0 | 125 | }; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | tasks.push(function init() { |
michael@0 | 129 | log("Initialize test object."); |
michael@0 | 130 | ok(manager instanceof MozMobileMessageManager, |
michael@0 | 131 | "manager is instance of " + manager.constructor); |
michael@0 | 132 | |
michael@0 | 133 | // Callback for incoming sms |
michael@0 | 134 | manager.onreceived = function onreceived(event) { |
michael@0 | 135 | log("Received 'onreceived' event."); |
michael@0 | 136 | let incomingSms = event.message; |
michael@0 | 137 | ok(incomingSms, "incoming sms"); |
michael@0 | 138 | ok(incomingSms.id, "sms id"); |
michael@0 | 139 | log("Received SMS (id: " + incomingSms.id + ")."); |
michael@0 | 140 | ok(incomingSms.threadId, "thread id"); |
michael@0 | 141 | is(incomingSms.body, MSG_TEXT, "msg body"); |
michael@0 | 142 | is(incomingSms.delivery, "received", "delivery"); |
michael@0 | 143 | is(incomingSms.deliveryStatus, "success", "deliveryStatus"); |
michael@0 | 144 | is(incomingSms.read, false, "read"); |
michael@0 | 145 | is(incomingSms.receiver, RECEIVER, "receiver"); |
michael@0 | 146 | is(incomingSms.sender, SENDER, "sender"); |
michael@0 | 147 | is(incomingSms.messageClass, "normal", "messageClass"); |
michael@0 | 148 | is(incomingSms.deliveryTimestamp, 0, "deliveryTimestamp is 0"); |
michael@0 | 149 | |
michael@0 | 150 | verifySmsExists(incomingSms); |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | tasks.next(); |
michael@0 | 154 | }); |
michael@0 | 155 | |
michael@0 | 156 | tasks.push(function sendAllSms() { |
michael@0 | 157 | log("Send " + SMS_NUMBER + " SMS"); |
michael@0 | 158 | for (let i = 0; i < SMS_NUMBER; i++) { |
michael@0 | 159 | sendSmsToEmulator(SENDER, MSG_TEXT); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | waitFor(taskNextWrapper, function() { |
michael@0 | 163 | return (pendingEmulatorCmdCount === 0) && (SmsList.length === SMS_NUMBER); |
michael@0 | 164 | }); |
michael@0 | 165 | }); |
michael@0 | 166 | |
michael@0 | 167 | tasks.push(function deleteAllSms() { |
michael@0 | 168 | log("Deleting SMS using smsmsg obj array parameter."); |
michael@0 | 169 | let deleteStart = Date.now(); |
michael@0 | 170 | log("deleteStart: " + deleteStart); |
michael@0 | 171 | log("SmsList: " + JSON.stringify(SmsList)); |
michael@0 | 172 | let requestRet = manager.delete(SmsList); |
michael@0 | 173 | ok(requestRet,"smsrequest obj returned"); |
michael@0 | 174 | |
michael@0 | 175 | requestRet.onsuccess = function(event) { |
michael@0 | 176 | let deleteDone = Date.now(); |
michael@0 | 177 | log("Delete " + SMS_NUMBER + " SMS takes " + (deleteDone - deleteStart) + " ms."); |
michael@0 | 178 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 179 | if (event.target.result) { |
michael@0 | 180 | for (let i = 0; i < SmsList.length; i++) { |
michael@0 | 181 | verifySmsDeleted(SmsList[i].id); |
michael@0 | 182 | } |
michael@0 | 183 | } else { |
michael@0 | 184 | log("smsrequest returned false for manager.delete"); |
michael@0 | 185 | ok(false, "SMS delete failed"); |
michael@0 | 186 | } |
michael@0 | 187 | }; |
michael@0 | 188 | |
michael@0 | 189 | requestRet.onerror = function(event) { |
michael@0 | 190 | log("Received 'onerror' smsrequest event."); |
michael@0 | 191 | ok(event.target.error, "domerror obj"); |
michael@0 | 192 | ok(false, "manager.delete request returned unexpected error: " |
michael@0 | 193 | + event.target.error.name); |
michael@0 | 194 | tasks.finish(); |
michael@0 | 195 | }; |
michael@0 | 196 | |
michael@0 | 197 | waitFor(taskNextWrapper, function() { |
michael@0 | 198 | return verifDeletedCount === SMS_NUMBER; |
michael@0 | 199 | }); |
michael@0 | 200 | }); |
michael@0 | 201 | |
michael@0 | 202 | // WARNING: All tasks should be pushed before this!!! |
michael@0 | 203 | tasks.push(function cleanUp() { |
michael@0 | 204 | if (pendingEmulatorCmdCount) { |
michael@0 | 205 | window.setTimeout(cleanUp, 100); |
michael@0 | 206 | return; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | manager.onreceived = null; |
michael@0 | 210 | SpecialPowers.removePermission("sms", document); |
michael@0 | 211 | SpecialPowers.setBoolPref("dom.sms.enabled", false); |
michael@0 | 212 | log("Finish!!!"); |
michael@0 | 213 | finish(); |
michael@0 | 214 | }); |
michael@0 | 215 | |
michael@0 | 216 | // Start the test |
michael@0 | 217 | tasks.run(); |