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.addPermission("sms", true, document); |
michael@0 | 7 | SpecialPowers.setBoolPref("dom.sms.enabled", true); |
michael@0 | 8 | |
michael@0 | 9 | let manager = window.navigator.mozMobileMessage; |
michael@0 | 10 | let smsList = new Array(); |
michael@0 | 11 | |
michael@0 | 12 | function verifyInitialState() { |
michael@0 | 13 | log("Verifying initial state."); |
michael@0 | 14 | ok(manager instanceof MozMobileMessageManager, |
michael@0 | 15 | "manager is instance of " + manager.constructor); |
michael@0 | 16 | simulateIncomingSms(); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function simulateIncomingSms() { |
michael@0 | 20 | let text = "Incoming SMS courtesy of Firefox OS"; |
michael@0 | 21 | let remoteNumber = "5557779999"; |
michael@0 | 22 | |
michael@0 | 23 | log("Simulating incoming SMS."); |
michael@0 | 24 | |
michael@0 | 25 | // Simulate incoming SMS sent from remoteNumber to our emulator |
michael@0 | 26 | rcvdEmulatorCallback = false; |
michael@0 | 27 | runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) { |
michael@0 | 28 | is(result[0], "OK", "emulator callback"); |
michael@0 | 29 | rcvdEmulatorCallback = true; |
michael@0 | 30 | }); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // Callback for incoming SMS |
michael@0 | 34 | manager.onreceived = function onreceived(event) { |
michael@0 | 35 | log("Received 'onreceived' sms event."); |
michael@0 | 36 | let incomingSms = event.message; |
michael@0 | 37 | log("Received SMS (id: " + incomingSms.id + ")."); |
michael@0 | 38 | is(incomingSms.read, false, "incoming message read"); |
michael@0 | 39 | log("SMS read attribute: " + incomingSms.read + "."); |
michael@0 | 40 | |
michael@0 | 41 | // Add newly received message id to array of msgs |
michael@0 | 42 | smsList.push(incomingSms.id); |
michael@0 | 43 | |
michael@0 | 44 | // Wait for emulator to catch up before continuing |
michael@0 | 45 | waitFor(sendSms, function() { |
michael@0 | 46 | return(rcvdEmulatorCallback); |
michael@0 | 47 | }); |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | function sendSms() { |
michael@0 | 51 | let gotSmsSent = false; |
michael@0 | 52 | let gotRequestSuccess = false; |
michael@0 | 53 | let remoteNumber = "5557779999"; |
michael@0 | 54 | let text = "Mo Mo Mo Zilla Zilla Zilla!"; |
michael@0 | 55 | |
michael@0 | 56 | log("Sending an SMS."); |
michael@0 | 57 | |
michael@0 | 58 | manager.onsent = function(event) { |
michael@0 | 59 | log("Received 'onsent' event."); |
michael@0 | 60 | gotSmsSent = true; |
michael@0 | 61 | let sentSms = event.message; |
michael@0 | 62 | log("Sent SMS (id: " + sentSms.id + ")."); |
michael@0 | 63 | is(sentSms.read, true, "sent sms read"); |
michael@0 | 64 | log("SMS read attribute: " + sentSms.read + "."); |
michael@0 | 65 | |
michael@0 | 66 | // Add newly received message id to array of msgs |
michael@0 | 67 | smsList.push(sentSms.id); |
michael@0 | 68 | |
michael@0 | 69 | if (gotSmsSent && gotRequestSuccess) { |
michael@0 | 70 | test1(); |
michael@0 | 71 | } |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | let request = manager.send(remoteNumber, text); |
michael@0 | 75 | |
michael@0 | 76 | request.onsuccess = function(event) { |
michael@0 | 77 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 78 | if(event.target.result) { |
michael@0 | 79 | gotRequestSuccess = true; |
michael@0 | 80 | if (gotSmsSent && gotRequestSuccess) { |
michael@0 | 81 | test1(); |
michael@0 | 82 | } |
michael@0 | 83 | } else { |
michael@0 | 84 | log("smsrequest returned false for manager.send"); |
michael@0 | 85 | ok(false, "SMS send failed"); |
michael@0 | 86 | deleteMsgs(); |
michael@0 | 87 | } |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | request.onerror = function(event) { |
michael@0 | 91 | log("Received 'onerror' smsrequest event."); |
michael@0 | 92 | ok(event.target.error, "domerror obj"); |
michael@0 | 93 | ok(false, "manager.send request returned unexpected error: " |
michael@0 | 94 | + event.target.error.name ); |
michael@0 | 95 | deleteMsgs(); |
michael@0 | 96 | }; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function markMessageAndVerify(smsId, readBool, nextFunction) { |
michael@0 | 100 | let request = manager.markMessageRead(smsId, readBool); |
michael@0 | 101 | ok(request instanceof DOMRequest, |
michael@0 | 102 | "request is instanceof " + request.constructor); |
michael@0 | 103 | |
michael@0 | 104 | request.onsuccess = function(event) { |
michael@0 | 105 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 106 | |
michael@0 | 107 | // Success from MarkMessageRead, the result should match what we set |
michael@0 | 108 | is(event.target.result, readBool, "result matches what was set"); |
michael@0 | 109 | |
michael@0 | 110 | // Message marked read/unread, now verify |
michael@0 | 111 | log("Getting SMS message (id: " + smsId + ")."); |
michael@0 | 112 | let requestRet = manager.getMessage(smsId); |
michael@0 | 113 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 114 | |
michael@0 | 115 | requestRet.onsuccess = function(event) { |
michael@0 | 116 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 117 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 118 | let foundSms = event.target.result; |
michael@0 | 119 | is(foundSms.id, smsId, "SMS id matches"); |
michael@0 | 120 | log("SMS read attribute: " + foundSms.read + "."); |
michael@0 | 121 | let text = readBool ? "read" : "unread"; |
michael@0 | 122 | if (foundSms.read == readBool) { |
michael@0 | 123 | ok(true, "marked sms " + text); |
michael@0 | 124 | } else { |
michael@0 | 125 | ok(false, "marking sms " + text + " didn't work"); |
michael@0 | 126 | log("Expected SMS (id: " + foundSms.id + ") to be marked " + text |
michael@0 | 127 | + " but it is not."); |
michael@0 | 128 | } |
michael@0 | 129 | nextFunction(); |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | requestRet.onerror = function(event) { |
michael@0 | 133 | log("Received 'onerror' smsrequest event."); |
michael@0 | 134 | ok(event.target.error, "domerror obj"); |
michael@0 | 135 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 136 | log("Could not get SMS (id: " + outSmsId + ") but should have."); |
michael@0 | 137 | ok(false, "Could not get SMS"); |
michael@0 | 138 | deleteMsgs(); |
michael@0 | 139 | }; |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | request.onerror = function(event) { |
michael@0 | 143 | log("Received 'onerror' smsrequest event."); |
michael@0 | 144 | ok(event.target.error, "domerror obj"); |
michael@0 | 145 | ok(false, "manager.markMessageRead request returned unexpected error: " |
michael@0 | 146 | + event.target.error.name ); |
michael@0 | 147 | nextFunction(); |
michael@0 | 148 | }; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function test1() { |
michael@0 | 152 | rcvdSms = smsList[0]; |
michael@0 | 153 | log("Test 1: Marking received SMS (id: " + rcvdSms + ") read."); |
michael@0 | 154 | markMessageAndVerify(rcvdSms, true, test2); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | function test2() { |
michael@0 | 158 | rcvdSms = smsList[0]; |
michael@0 | 159 | log("Test 2: Marking received SMS (id: " + rcvdSms + ") unread."); |
michael@0 | 160 | markMessageAndVerify(rcvdSms, false, test3); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | function test3() { |
michael@0 | 164 | sentSms = smsList[1]; |
michael@0 | 165 | log("Test 3: Marking sent SMS (id: " + sentSms + ") unread."); |
michael@0 | 166 | markMessageAndVerify(sentSms, false, test4); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function test4() { |
michael@0 | 170 | sentSms = smsList[1]; |
michael@0 | 171 | log("Test 4: Marking sent SMS (id: " + sentSms + ") read."); |
michael@0 | 172 | markMessageAndVerify(sentSms, true, test5); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | function test5() { |
michael@0 | 176 | sentSms = smsList[1]; |
michael@0 | 177 | log("Test 5: Marking an already read SMS (id: " + sentSms + ") read."); |
michael@0 | 178 | markMessageAndVerify(sentSms, true, test6); |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | function test6() { |
michael@0 | 182 | rcvdSms = smsList[0]; |
michael@0 | 183 | log("Test 6: Marking an already unread SMS (id: " + rcvdSms + ") unread."); |
michael@0 | 184 | markMessageAndVerify(rcvdSms, false, deleteMsgs); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | function deleteMsgs() { |
michael@0 | 188 | let smsId = smsList.shift(); |
michael@0 | 189 | |
michael@0 | 190 | log("Deleting SMS (id: " + smsId + ")."); |
michael@0 | 191 | let request = manager.delete(smsId); |
michael@0 | 192 | ok(request instanceof DOMRequest, |
michael@0 | 193 | "request is instanceof " + request.constructor); |
michael@0 | 194 | |
michael@0 | 195 | request.onsuccess = function(event) { |
michael@0 | 196 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 197 | if (event.target.result) { |
michael@0 | 198 | // Message deleted, continue until none are left |
michael@0 | 199 | if (smsList.length) { |
michael@0 | 200 | deleteMsgs(); |
michael@0 | 201 | } else { |
michael@0 | 202 | cleanUp(); |
michael@0 | 203 | } |
michael@0 | 204 | } else { |
michael@0 | 205 | log("SMS delete failed."); |
michael@0 | 206 | ok(false, "manager.delete request returned false"); |
michael@0 | 207 | cleanUp(); |
michael@0 | 208 | } |
michael@0 | 209 | }; |
michael@0 | 210 | |
michael@0 | 211 | request.onerror = function(event) { |
michael@0 | 212 | log("Received 'onerror' smsrequest event."); |
michael@0 | 213 | ok(event.target.error, "domerror obj"); |
michael@0 | 214 | ok(false, "manager.delete request returned unexpected error: " |
michael@0 | 215 | + event.target.error.name ); |
michael@0 | 216 | cleanUp(); |
michael@0 | 217 | }; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | function cleanUp() { |
michael@0 | 221 | manager.onreceived = null; |
michael@0 | 222 | SpecialPowers.removePermission("sms", document); |
michael@0 | 223 | SpecialPowers.clearUserPref("dom.sms.enabled"); |
michael@0 | 224 | finish(); |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | // Start the test |
michael@0 | 228 | verifyInitialState(); |