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 | MARIONETTE_HEAD_JS = 'head.js'; |
michael@0 | 6 | |
michael@0 | 7 | let outNumber = "5555551111"; |
michael@0 | 8 | let inNumber = "5555552222"; |
michael@0 | 9 | let outgoingCall; |
michael@0 | 10 | let incomingCall; |
michael@0 | 11 | let gotOriginalConnected = false; |
michael@0 | 12 | let gotHeld = false; |
michael@0 | 13 | let gotConnected = false; |
michael@0 | 14 | |
michael@0 | 15 | function dial() { |
michael@0 | 16 | log("Make an outgoing call."); |
michael@0 | 17 | telephony.dial(outNumber).then(call => { |
michael@0 | 18 | outgoingCall = call; |
michael@0 | 19 | ok(outgoingCall); |
michael@0 | 20 | is(outgoingCall.number, outNumber); |
michael@0 | 21 | is(outgoingCall.state, "dialing"); |
michael@0 | 22 | |
michael@0 | 23 | outgoingCall.onalerting = function onalerting(event) { |
michael@0 | 24 | log("Received 'alerting' call event."); |
michael@0 | 25 | |
michael@0 | 26 | is(outgoingCall, event.call); |
michael@0 | 27 | is(outgoingCall.state, "alerting"); |
michael@0 | 28 | is(outgoingCall, telephony.active); |
michael@0 | 29 | is(telephony.calls.length, 1); |
michael@0 | 30 | is(telephony.calls[0], outgoingCall); |
michael@0 | 31 | |
michael@0 | 32 | emulator.run("gsm list", function(result) { |
michael@0 | 33 | log("Call list is now: " + result); |
michael@0 | 34 | is(result[0], "outbound to " + outNumber + " : ringing"); |
michael@0 | 35 | is(result[1], "OK"); |
michael@0 | 36 | answer(); |
michael@0 | 37 | }); |
michael@0 | 38 | }; |
michael@0 | 39 | }); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function answer() { |
michael@0 | 43 | log("Answering the outgoing call."); |
michael@0 | 44 | |
michael@0 | 45 | // We get no "connecting" event when the remote party answers the call. |
michael@0 | 46 | outgoingCall.onconnected = function onconnectedOut(event) { |
michael@0 | 47 | log("Received 'connected' call event for the original outgoing call."); |
michael@0 | 48 | |
michael@0 | 49 | is(outgoingCall, event.call); |
michael@0 | 50 | is(outgoingCall.state, "connected"); |
michael@0 | 51 | is(outgoingCall, telephony.active); |
michael@0 | 52 | |
michael@0 | 53 | emulator.run("gsm list", function(result) { |
michael@0 | 54 | log("Call list is now: " + result); |
michael@0 | 55 | is(result[0], "outbound to " + outNumber + " : active"); |
michael@0 | 56 | is(result[1], "OK"); |
michael@0 | 57 | |
michael@0 | 58 | if(!gotOriginalConnected){ |
michael@0 | 59 | gotOriginalConnected = true; |
michael@0 | 60 | holdCall(); |
michael@0 | 61 | } else { |
michael@0 | 62 | // Received connected event for original call multiple times (fail) |
michael@0 | 63 | ok(false, |
michael@0 | 64 | "Received 'connected' event for original call multiple times."); |
michael@0 | 65 | } |
michael@0 | 66 | }); |
michael@0 | 67 | }; |
michael@0 | 68 | emulator.run("gsm accept " + outNumber); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function holdCall() { |
michael@0 | 72 | log("Putting the original (outgoing) call on hold."); |
michael@0 | 73 | |
michael@0 | 74 | let gotHolding = false; |
michael@0 | 75 | outgoingCall.onholding = function onholding(event) { |
michael@0 | 76 | log("Received 'holding' call event"); |
michael@0 | 77 | is(outgoingCall, event.call); |
michael@0 | 78 | is(outgoingCall.state, "holding"); |
michael@0 | 79 | gotHolding = true; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | outgoingCall.onheld = function onheld(event) { |
michael@0 | 83 | log("Received 'held' call event"); |
michael@0 | 84 | is(outgoingCall, event.call); |
michael@0 | 85 | is(outgoingCall.state, "held"); |
michael@0 | 86 | ok(gotHolding); |
michael@0 | 87 | |
michael@0 | 88 | is(telephony.active, null); |
michael@0 | 89 | is(telephony.calls.length, 1); |
michael@0 | 90 | is(telephony.calls[0], outgoingCall); |
michael@0 | 91 | |
michael@0 | 92 | emulator.run("gsm list", function(result) { |
michael@0 | 93 | log("Call list is now: " + result); |
michael@0 | 94 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 95 | is(result[1], "OK"); |
michael@0 | 96 | simulateIncoming(); |
michael@0 | 97 | }); |
michael@0 | 98 | }; |
michael@0 | 99 | outgoingCall.hold(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | // With one call on hold, simulate an incoming call |
michael@0 | 103 | function simulateIncoming() { |
michael@0 | 104 | log("Simulating an incoming call (with one call already held)."); |
michael@0 | 105 | |
michael@0 | 106 | telephony.onincoming = function onincoming(event) { |
michael@0 | 107 | log("Received 'incoming' call event."); |
michael@0 | 108 | incomingCall = event.call; |
michael@0 | 109 | ok(incomingCall); |
michael@0 | 110 | is(incomingCall.number, inNumber); |
michael@0 | 111 | is(incomingCall.state, "incoming"); |
michael@0 | 112 | |
michael@0 | 113 | // Should be two calls now |
michael@0 | 114 | is(telephony.calls.length, 2); |
michael@0 | 115 | is(telephony.calls[0], outgoingCall); |
michael@0 | 116 | is(telephony.calls[1], incomingCall); |
michael@0 | 117 | |
michael@0 | 118 | emulator.run("gsm list", function(result) { |
michael@0 | 119 | log("Call list is now: " + result); |
michael@0 | 120 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 121 | is(result[1], "inbound from " + inNumber + " : incoming"); |
michael@0 | 122 | is(result[2], "OK"); |
michael@0 | 123 | answerIncoming(); |
michael@0 | 124 | }); |
michael@0 | 125 | }; |
michael@0 | 126 | emulator.run("gsm call " + inNumber); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | // Answer incoming call; original outgoing call should be held |
michael@0 | 130 | function answerIncoming() { |
michael@0 | 131 | log("Answering the incoming call."); |
michael@0 | 132 | |
michael@0 | 133 | let gotConnecting = false; |
michael@0 | 134 | incomingCall.onconnecting = function onconnectingIn(event) { |
michael@0 | 135 | log("Received 'connecting' call event for incoming/2nd call."); |
michael@0 | 136 | is(incomingCall, event.call); |
michael@0 | 137 | is(incomingCall.state, "connecting"); |
michael@0 | 138 | gotConnecting = true; |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | incomingCall.onconnected = function onconnectedIn(event) { |
michael@0 | 142 | log("Received 'connected' call event for incoming/2nd call."); |
michael@0 | 143 | is(incomingCall, event.call); |
michael@0 | 144 | ok(gotConnecting); |
michael@0 | 145 | |
michael@0 | 146 | is(incomingCall, telephony.active); |
michael@0 | 147 | |
michael@0 | 148 | // Original outbound call now held, incoming call active |
michael@0 | 149 | is(outgoingCall.state, "held"); |
michael@0 | 150 | is(incomingCall.state, "connected"); |
michael@0 | 151 | |
michael@0 | 152 | emulator.run("gsm list", function(result) { |
michael@0 | 153 | log("Call list is now: " + result); |
michael@0 | 154 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 155 | is(result[1], "inbound from " + inNumber + " : active"); |
michael@0 | 156 | is(result[2], "OK"); |
michael@0 | 157 | swapCalls(); |
michael@0 | 158 | }); |
michael@0 | 159 | }; |
michael@0 | 160 | incomingCall.answer(); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | // Now swap the held and active calls |
michael@0 | 164 | function swapCalls() { |
michael@0 | 165 | log("Swapping the held and active calls."); |
michael@0 | 166 | |
michael@0 | 167 | // Swap calls by resuming the held (outgoing) call. Will force active |
michael@0 | 168 | // (incoming) call to hold. |
michael@0 | 169 | |
michael@0 | 170 | incomingCall.onheld = function onheldIn(event) { |
michael@0 | 171 | log("Received 'held' call event for incoming call."); |
michael@0 | 172 | gotHeld = true; |
michael@0 | 173 | |
michael@0 | 174 | if (gotHeld && gotConnected) { verifySwap(); } |
michael@0 | 175 | }; |
michael@0 | 176 | |
michael@0 | 177 | let gotResuming = false; |
michael@0 | 178 | outgoingCall.onresuming = function onresuming(event) { |
michael@0 | 179 | log("Received 'resuming' call event for outbound call."); |
michael@0 | 180 | is(outgoingCall, event.call); |
michael@0 | 181 | is(outgoingCall.state, "resuming"); |
michael@0 | 182 | gotResuming = true; |
michael@0 | 183 | }; |
michael@0 | 184 | |
michael@0 | 185 | outgoingCall.onconnected = function onconnected(event) { |
michael@0 | 186 | log("Received 'connected' call event for outbound call."); |
michael@0 | 187 | is(outgoingCall, event.call); |
michael@0 | 188 | ok(gotResuming); |
michael@0 | 189 | |
michael@0 | 190 | is(outgoingCall, telephony.active); |
michael@0 | 191 | is(telephony.calls.length, 2); |
michael@0 | 192 | is(telephony.calls[0], outgoingCall); |
michael@0 | 193 | is(telephony.calls[1], incomingCall); |
michael@0 | 194 | gotConnected = true; |
michael@0 | 195 | |
michael@0 | 196 | if (gotHeld && gotConnected) { verifySwap(); } |
michael@0 | 197 | }; |
michael@0 | 198 | outgoingCall.resume(); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | function verifySwap() { |
michael@0 | 202 | // Call status reflects swap |
michael@0 | 203 | is(outgoingCall.state, "connected"); |
michael@0 | 204 | is(incomingCall.state, "held"); |
michael@0 | 205 | |
michael@0 | 206 | emulator.run("gsm list", function(result) { |
michael@0 | 207 | log("Call list is now: " + result); |
michael@0 | 208 | is(result[0], "outbound to " + outNumber + " : active"); |
michael@0 | 209 | is(result[1], "inbound from " + inNumber + " : held"); |
michael@0 | 210 | |
michael@0 | 211 | // Begin hang-up |
michael@0 | 212 | hangUpOutgoing(); |
michael@0 | 213 | }); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | // Hang-up original outgoing (now active) call |
michael@0 | 217 | function hangUpOutgoing() { |
michael@0 | 218 | log("Hanging up the original outgoing (now active) call."); |
michael@0 | 219 | |
michael@0 | 220 | let gotDisconnecting = false; |
michael@0 | 221 | outgoingCall.ondisconnecting = function ondisconnectingOut(event) { |
michael@0 | 222 | log("Received 'disconnecting' call event for original outgoing call."); |
michael@0 | 223 | is(outgoingCall, event.call); |
michael@0 | 224 | is(outgoingCall.state, "disconnecting"); |
michael@0 | 225 | gotDisconnecting = true; |
michael@0 | 226 | }; |
michael@0 | 227 | |
michael@0 | 228 | outgoingCall.ondisconnected = function ondisconnectedOut(event) { |
michael@0 | 229 | log("Received 'disconnected' call event for original outgoing call."); |
michael@0 | 230 | is(outgoingCall, event.call); |
michael@0 | 231 | is(outgoingCall.state, "disconnected"); |
michael@0 | 232 | ok(gotDisconnecting); |
michael@0 | 233 | |
michael@0 | 234 | // Back to one call now |
michael@0 | 235 | is(telephony.calls.length, 1); |
michael@0 | 236 | is(incomingCall.state, "held"); |
michael@0 | 237 | |
michael@0 | 238 | emulator.run("gsm list", function(result) { |
michael@0 | 239 | log("Call list is now: " + result); |
michael@0 | 240 | is(result[0], "inbound from " + inNumber + " : held"); |
michael@0 | 241 | is(result[1], "OK"); |
michael@0 | 242 | hangUpIncoming(); |
michael@0 | 243 | }); |
michael@0 | 244 | }; |
michael@0 | 245 | outgoingCall.hangUp(); |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | // Hang-up remaining (now held) call |
michael@0 | 249 | function hangUpIncoming() { |
michael@0 | 250 | log("Hanging up the remaining (now held) call."); |
michael@0 | 251 | |
michael@0 | 252 | let gotDisconnecting = false; |
michael@0 | 253 | incomingCall.ondisconnecting = function ondisconnectingIn(event) { |
michael@0 | 254 | log("Received 'disconnecting' call event for remaining (held) call."); |
michael@0 | 255 | is(incomingCall, event.call); |
michael@0 | 256 | is(incomingCall.state, "disconnecting"); |
michael@0 | 257 | gotDisconnecting = true; |
michael@0 | 258 | }; |
michael@0 | 259 | |
michael@0 | 260 | incomingCall.ondisconnected = function ondisconnectedIn(event) { |
michael@0 | 261 | log("Received 'disconnected' call event for remaining (incoming) call."); |
michael@0 | 262 | is(incomingCall, event.call); |
michael@0 | 263 | is(incomingCall.state, "disconnected"); |
michael@0 | 264 | ok(gotDisconnecting); |
michael@0 | 265 | |
michael@0 | 266 | // Zero calls left |
michael@0 | 267 | is(telephony.active, null); |
michael@0 | 268 | is(telephony.calls.length, 0); |
michael@0 | 269 | |
michael@0 | 270 | emulator.run("gsm list", function(result) { |
michael@0 | 271 | log("Call list is now: " + result); |
michael@0 | 272 | is(result[0], "OK"); |
michael@0 | 273 | cleanUp(); |
michael@0 | 274 | }); |
michael@0 | 275 | }; |
michael@0 | 276 | incomingCall.hangUp(); |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | function cleanUp() { |
michael@0 | 280 | telephony.onincoming = null; |
michael@0 | 281 | finish(); |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | startTest(function() { |
michael@0 | 285 | dial(); |
michael@0 | 286 | }); |