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 | const DATA_KEY = "ril.data.enabled"; |
michael@0 | 7 | const DATA_ROAMING_KEY = "ril.data.roaming_enabled"; |
michael@0 | 8 | const APN_KEY = "ril.data.apnSettings"; |
michael@0 | 9 | |
michael@0 | 10 | SpecialPowers.setBoolPref("dom.mozSettings.enabled", true); |
michael@0 | 11 | SpecialPowers.addPermission("mobileconnection", true, document); |
michael@0 | 12 | SpecialPowers.addPermission("settings-read", true, document); |
michael@0 | 13 | SpecialPowers.addPermission("settings-write", true, document); |
michael@0 | 14 | |
michael@0 | 15 | let settings = window.navigator.mozSettings; |
michael@0 | 16 | let connection = window.navigator.mozMobileConnections[0]; |
michael@0 | 17 | ok(connection instanceof MozMobileConnection, |
michael@0 | 18 | "connection is instanceof " + connection.constructor); |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | let pendingEmulatorCmdCount = 0; |
michael@0 | 22 | function sendCmdToEmulator(cmd, callback) { |
michael@0 | 23 | ++pendingEmulatorCmdCount; |
michael@0 | 24 | |
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 | if (callback) { |
michael@0 | 31 | callback(); |
michael@0 | 32 | } |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | let tasks = { |
michael@0 | 37 | // List of test fuctions. Each of them should call |tasks.next()| when |
michael@0 | 38 | // completed or |tasks.finish()| to jump to the last one. |
michael@0 | 39 | _tasks: [], |
michael@0 | 40 | _nextTaskIndex: 0, |
michael@0 | 41 | |
michael@0 | 42 | push: function(func) { |
michael@0 | 43 | this._tasks.push(func); |
michael@0 | 44 | }, |
michael@0 | 45 | |
michael@0 | 46 | next: function() { |
michael@0 | 47 | let index = this._nextTaskIndex++; |
michael@0 | 48 | let task = this._tasks[index]; |
michael@0 | 49 | try { |
michael@0 | 50 | task(); |
michael@0 | 51 | } catch (ex) { |
michael@0 | 52 | ok(false, "test task[" + index + "] throws: " + ex); |
michael@0 | 53 | // Run last task as clean up if possible. |
michael@0 | 54 | if (index != this._tasks.length - 1) { |
michael@0 | 55 | this.finish(); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | }, |
michael@0 | 59 | |
michael@0 | 60 | finish: function() { |
michael@0 | 61 | this._tasks[this._tasks.length - 1](); |
michael@0 | 62 | }, |
michael@0 | 63 | |
michael@0 | 64 | run: function() { |
michael@0 | 65 | this.next(); |
michael@0 | 66 | } |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | function setSetting(key, value, callback) { |
michael@0 | 70 | let setLock = settings.createLock(); |
michael@0 | 71 | let obj = {}; |
michael@0 | 72 | obj[key] = value; |
michael@0 | 73 | |
michael@0 | 74 | let setReq = setLock.set(obj); |
michael@0 | 75 | setReq.addEventListener("success", function onSetSuccess() { |
michael@0 | 76 | ok(true, "set '" + key + "' to " + obj[key]); |
michael@0 | 77 | if (callback) { |
michael@0 | 78 | callback(); |
michael@0 | 79 | } |
michael@0 | 80 | }); |
michael@0 | 81 | setReq.addEventListener("error", function onSetError() { |
michael@0 | 82 | ok(false, "cannot set '" + key + "'"); |
michael@0 | 83 | tasks.finish(); |
michael@0 | 84 | }); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function getSetting(key, callback) { |
michael@0 | 88 | let getLock = settings.createLock(); |
michael@0 | 89 | |
michael@0 | 90 | let getReq = getLock.get(key); |
michael@0 | 91 | getReq.addEventListener("success", function onGetSuccess() { |
michael@0 | 92 | ok(true, "get " + key + " setting okay"); |
michael@0 | 93 | let value = getReq.result[key]; |
michael@0 | 94 | callback(value); |
michael@0 | 95 | }); |
michael@0 | 96 | getReq.addEventListener("error", function onGetError() { |
michael@0 | 97 | ok(false, "cannot get '" + key + "'"); |
michael@0 | 98 | tasks.finish(); |
michael@0 | 99 | }); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function setEmulatorAPN(callback) { |
michael@0 | 103 | let apn = |
michael@0 | 104 | [ |
michael@0 | 105 | [ |
michael@0 | 106 | {"carrier":"T-Mobile US", |
michael@0 | 107 | "apn":"epc.tmobile.com", |
michael@0 | 108 | "mmsc":"http://mms.msg.eng.t-mobile.com/mms/wapenc", |
michael@0 | 109 | "types":["default","supl","mms"]} |
michael@0 | 110 | ] |
michael@0 | 111 | ]; |
michael@0 | 112 | setSetting(APN_KEY, apn, callback); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function setEmulatorRoaming(roaming, callback) { |
michael@0 | 116 | log("Setting emulator roaming state: " + roaming + "."); |
michael@0 | 117 | |
michael@0 | 118 | // Set voice registration state first and then data registration state. |
michael@0 | 119 | let cmd = "gsm voice " + (roaming ? "roaming" : "home"); |
michael@0 | 120 | sendCmdToEmulator(cmd, function() { |
michael@0 | 121 | |
michael@0 | 122 | connection.addEventListener("voicechange", function onvoicechange() { |
michael@0 | 123 | connection.removeEventListener("voicechange", onvoicechange); |
michael@0 | 124 | log("mobileConnection.voice.roaming is now '" |
michael@0 | 125 | + connection.voice.roaming + "'."); |
michael@0 | 126 | is(connection.voice.roaming, roaming, "voice.roaming"); |
michael@0 | 127 | |
michael@0 | 128 | let cmd = "gsm data " + (roaming ? "roaming" : "home"); |
michael@0 | 129 | sendCmdToEmulator(cmd, function() { |
michael@0 | 130 | |
michael@0 | 131 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 132 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 133 | log("mobileConnection.data.roaming is now '" |
michael@0 | 134 | + connection.data.roaming + "'."); |
michael@0 | 135 | is(connection.data.roaming, roaming, "data.roaming"); |
michael@0 | 136 | if (callback) { |
michael@0 | 137 | callback(); |
michael@0 | 138 | } |
michael@0 | 139 | }); |
michael@0 | 140 | }); |
michael@0 | 141 | }); |
michael@0 | 142 | }); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function setEmulatorHome(callback) { |
michael@0 | 146 | let voiceRegistration = false; |
michael@0 | 147 | let dataRegistration = false; |
michael@0 | 148 | |
michael@0 | 149 | if (connection.voice.state != "registered") { |
michael@0 | 150 | sendCmdToEmulator("gsm voice home", function() { |
michael@0 | 151 | connection.addEventListener("voicechange", function onvoicechange() { |
michael@0 | 152 | connection.removeEventListener("voicechange", onvoicechange); |
michael@0 | 153 | log("mobileConnection.voice.state is now '" |
michael@0 | 154 | + connection.voice.state + "'."); |
michael@0 | 155 | is(connection.voice.state, "registered", "voice.state"); |
michael@0 | 156 | voiceRegistration = true; |
michael@0 | 157 | }); |
michael@0 | 158 | }); |
michael@0 | 159 | } else { |
michael@0 | 160 | voiceRegistration = true; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | if (connection.data.state != "registered") { |
michael@0 | 164 | sendCmdToEmulator("gsm data home", function() { |
michael@0 | 165 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 166 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 167 | log("mobileConnection.data.state is now '" |
michael@0 | 168 | + connection.data.state + "'."); |
michael@0 | 169 | is(connection.data.state, "registered", "data.state"); |
michael@0 | 170 | dataRegistration = true; |
michael@0 | 171 | }); |
michael@0 | 172 | }); |
michael@0 | 173 | } else { |
michael@0 | 174 | dataRegistration = true; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | waitFor(callback, function() { |
michael@0 | 178 | return (voiceRegistration && dataRegistration); |
michael@0 | 179 | }); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | |
michael@0 | 183 | tasks.push(function verifyInitialState() { |
michael@0 | 184 | log("Verifying initial state."); |
michael@0 | 185 | |
michael@0 | 186 | // Want to start test with mobileConnection.data.state 'registered', |
michael@0 | 187 | // This is the default state; if it is not currently this value then set it. |
michael@0 | 188 | setEmulatorHome(function() { |
michael@0 | 189 | // Want to start test with data off, |
michael@0 | 190 | // This is the default state; if it is not currently this value then set it. |
michael@0 | 191 | getSetting(DATA_KEY, function(result) { |
michael@0 | 192 | let value = result; |
michael@0 | 193 | log("Starting data enabled: " + value); |
michael@0 | 194 | if (value) { |
michael@0 | 195 | setSetting(DATA_KEY, false); |
michael@0 | 196 | |
michael@0 | 197 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 198 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 199 | log("mobileConnection.data.connected is now '" |
michael@0 | 200 | + connection.data.connected + "'."); |
michael@0 | 201 | is(connection.data.connected, false, "data.connected"); |
michael@0 | 202 | setEmulatorAPN(function() { |
michael@0 | 203 | tasks.next(); |
michael@0 | 204 | }); |
michael@0 | 205 | }); |
michael@0 | 206 | } else { |
michael@0 | 207 | setEmulatorAPN(function() { |
michael@0 | 208 | tasks.next(); |
michael@0 | 209 | }); |
michael@0 | 210 | } |
michael@0 | 211 | }); |
michael@0 | 212 | }); |
michael@0 | 213 | }); |
michael@0 | 214 | |
michael@0 | 215 | tasks.push(function testEnableData() { |
michael@0 | 216 | log("Turn data on."); |
michael@0 | 217 | |
michael@0 | 218 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 219 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 220 | log("mobileConnection.data.connected is now '" |
michael@0 | 221 | + connection.data.connected + "'."); |
michael@0 | 222 | is(connection.data.connected, true, "data.connected"); |
michael@0 | 223 | tasks.next(); |
michael@0 | 224 | }); |
michael@0 | 225 | |
michael@0 | 226 | setSetting(DATA_KEY, true); |
michael@0 | 227 | }); |
michael@0 | 228 | |
michael@0 | 229 | tasks.push(function testUnregisterDataWhileDataEnabled() { |
michael@0 | 230 | log("Set data registration unregistered while data enabled."); |
michael@0 | 231 | |
michael@0 | 232 | // When data registration is unregistered, all data calls |
michael@0 | 233 | // will be automatically deactivated. |
michael@0 | 234 | sendCmdToEmulator("gsm data unregistered", function() { |
michael@0 | 235 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 236 | log("mobileConnection.data.state is now '" |
michael@0 | 237 | + connection.data.state + "'."); |
michael@0 | 238 | if (connection.data.state == "notSearching") { |
michael@0 | 239 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 240 | log("mobileConnection.data.connected is now '" |
michael@0 | 241 | + connection.data.connected + "'."); |
michael@0 | 242 | is(connection.data.connected, false, "data.connected"); |
michael@0 | 243 | tasks.next(); |
michael@0 | 244 | } |
michael@0 | 245 | }); |
michael@0 | 246 | }); |
michael@0 | 247 | }); |
michael@0 | 248 | |
michael@0 | 249 | tasks.push(function testRegisterDataWhileDataEnabled() { |
michael@0 | 250 | log("Set data registration home while data enabled."); |
michael@0 | 251 | |
michael@0 | 252 | // When data registration is registered, data call will be |
michael@0 | 253 | // (re)activated by gecko if ril.data.enabled is set to true. |
michael@0 | 254 | sendCmdToEmulator("gsm data home", function() { |
michael@0 | 255 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 256 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 257 | log("mobileConnection.data.state is now '" |
michael@0 | 258 | + connection.data.state + "'."); |
michael@0 | 259 | is(connection.data.state, "registered", "data.state"); |
michael@0 | 260 | |
michael@0 | 261 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 262 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 263 | log("mobileConnection.data.connected is now '" |
michael@0 | 264 | + connection.data.connected + "'."); |
michael@0 | 265 | is(connection.data.connected, true, "data.connected"); |
michael@0 | 266 | tasks.next(); |
michael@0 | 267 | }); |
michael@0 | 268 | }); |
michael@0 | 269 | }); |
michael@0 | 270 | }); |
michael@0 | 271 | |
michael@0 | 272 | tasks.push(function testDisableDataRoamingWhileRoaming() { |
michael@0 | 273 | log("Disable data roaming while roaming."); |
michael@0 | 274 | |
michael@0 | 275 | setSetting(DATA_ROAMING_KEY, false); |
michael@0 | 276 | |
michael@0 | 277 | // Wait for roaming state to change, then data connection should |
michael@0 | 278 | // be disconnected due to data roaming set to off. |
michael@0 | 279 | setEmulatorRoaming(true, function() { |
michael@0 | 280 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 281 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 282 | log("mobileConnection.data.connected is now '" |
michael@0 | 283 | + connection.data.connected + "'."); |
michael@0 | 284 | is(connection.data.connected, false, "data.connected"); |
michael@0 | 285 | tasks.next(); |
michael@0 | 286 | }); |
michael@0 | 287 | }); |
michael@0 | 288 | }); |
michael@0 | 289 | |
michael@0 | 290 | tasks.push(function testEnableDataRoamingWhileRoaming() { |
michael@0 | 291 | log("Enable data roaming while roaming."); |
michael@0 | 292 | |
michael@0 | 293 | // Data should be re-connected as we enabled data roaming. |
michael@0 | 294 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 295 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 296 | log("mobileConnection.data.connected is now '" |
michael@0 | 297 | + connection.data.connected + "'."); |
michael@0 | 298 | is(connection.data.connected, true, "data.connected"); |
michael@0 | 299 | tasks.next(); |
michael@0 | 300 | }); |
michael@0 | 301 | |
michael@0 | 302 | setSetting(DATA_ROAMING_KEY, true); |
michael@0 | 303 | }); |
michael@0 | 304 | |
michael@0 | 305 | tasks.push(function testDisableDataRoamingWhileNotRoaming() { |
michael@0 | 306 | log("Disable data roaming while not roaming."); |
michael@0 | 307 | |
michael@0 | 308 | // Wait for roaming state to change then set data roaming back |
michael@0 | 309 | // to off. |
michael@0 | 310 | setEmulatorRoaming(false, function() { |
michael@0 | 311 | setSetting(DATA_ROAMING_KEY, false); |
michael@0 | 312 | |
michael@0 | 313 | // No change event will be received cause data connection state |
michael@0 | 314 | // remains the same. |
michael@0 | 315 | window.setTimeout(function() { |
michael@0 | 316 | is(connection.data.connected, true, "data.connected"); |
michael@0 | 317 | tasks.next(); |
michael@0 | 318 | }, 1000); |
michael@0 | 319 | }); |
michael@0 | 320 | }); |
michael@0 | 321 | |
michael@0 | 322 | tasks.push(function testDisableData() { |
michael@0 | 323 | log("Turn data off."); |
michael@0 | 324 | |
michael@0 | 325 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 326 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 327 | log("mobileConnection.data.connected is now '" |
michael@0 | 328 | + connection.data.connected + "'."); |
michael@0 | 329 | is(connection.data.connected, false, "data.connected"); |
michael@0 | 330 | tasks.next(); |
michael@0 | 331 | }); |
michael@0 | 332 | |
michael@0 | 333 | setSetting(DATA_KEY, false); |
michael@0 | 334 | }); |
michael@0 | 335 | |
michael@0 | 336 | // WARNING: All tasks should be pushed before this!!! |
michael@0 | 337 | tasks.push(function cleanUp() { |
michael@0 | 338 | if (pendingEmulatorCmdCount) { |
michael@0 | 339 | window.setTimeout(cleanUp, 100); |
michael@0 | 340 | return; |
michael@0 | 341 | } |
michael@0 | 342 | |
michael@0 | 343 | SpecialPowers.removePermission("mobileconnection", document); |
michael@0 | 344 | SpecialPowers.removePermission("settings-write", document); |
michael@0 | 345 | SpecialPowers.removePermission("settings-read", document); |
michael@0 | 346 | SpecialPowers.clearUserPref("dom.mozSettings.enabled"); |
michael@0 | 347 | finish(); |
michael@0 | 348 | }); |
michael@0 | 349 | |
michael@0 | 350 | tasks.run(); |
michael@0 | 351 |