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 APN_KEY = "ril.data.apnSettings"; |
michael@0 | 8 | |
michael@0 | 9 | let Promise = SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise; |
michael@0 | 10 | |
michael@0 | 11 | SpecialPowers.setBoolPref("dom.mozSettings.enabled", true); |
michael@0 | 12 | SpecialPowers.addPermission("mobileconnection", true, document); |
michael@0 | 13 | SpecialPowers.addPermission("settings-read", true, document); |
michael@0 | 14 | SpecialPowers.addPermission("settings-write", true, document); |
michael@0 | 15 | |
michael@0 | 16 | let settings = window.navigator.mozSettings; |
michael@0 | 17 | let connection = window.navigator.mozMobileConnections[0]; |
michael@0 | 18 | ok(connection instanceof MozMobileConnection, |
michael@0 | 19 | "connection is instanceof " + connection.constructor); |
michael@0 | 20 | |
michael@0 | 21 | function setSetting(key, value) { |
michael@0 | 22 | let deferred = Promise.defer(); |
michael@0 | 23 | |
michael@0 | 24 | let setLock = settings.createLock(); |
michael@0 | 25 | let obj = {}; |
michael@0 | 26 | obj[key] = value; |
michael@0 | 27 | |
michael@0 | 28 | let setReq = setLock.set(obj); |
michael@0 | 29 | setReq.addEventListener("success", function onSetSuccess() { |
michael@0 | 30 | ok(true, "set '" + key + "' to " + obj[key]); |
michael@0 | 31 | deferred.resolve(); |
michael@0 | 32 | }); |
michael@0 | 33 | setReq.addEventListener("error", function onSetError() { |
michael@0 | 34 | ok(false, "cannot set '" + key + "'"); |
michael@0 | 35 | deferred.reject(); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | return deferred.promise; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function setEmulatorAPN() { |
michael@0 | 42 | let apn = |
michael@0 | 43 | [ |
michael@0 | 44 | [ |
michael@0 | 45 | {"carrier":"T-Mobile US", |
michael@0 | 46 | "apn":"epc.tmobile.com", |
michael@0 | 47 | "mmsc":"http://mms.msg.eng.t-mobile.com/mms/wapenc", |
michael@0 | 48 | "types":["default","supl","mms"]} |
michael@0 | 49 | ] |
michael@0 | 50 | ]; |
michael@0 | 51 | return setSetting(APN_KEY, apn); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function enableData() { |
michael@0 | 55 | log("Turn data on."); |
michael@0 | 56 | |
michael@0 | 57 | let deferred = Promise.defer(); |
michael@0 | 58 | |
michael@0 | 59 | connection.addEventListener("datachange", function ondatachange() { |
michael@0 | 60 | if (connection.data.connected === true) { |
michael@0 | 61 | connection.removeEventListener("datachange", ondatachange); |
michael@0 | 62 | log("mobileConnection.data.connected is now '" |
michael@0 | 63 | + connection.data.connected + "'."); |
michael@0 | 64 | deferred.resolve(); |
michael@0 | 65 | } |
michael@0 | 66 | }); |
michael@0 | 67 | |
michael@0 | 68 | setEmulatorAPN() |
michael@0 | 69 | .then(() => setSetting(DATA_KEY, true)); |
michael@0 | 70 | |
michael@0 | 71 | return deferred.promise; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function receivedPending(received, pending, nextAction) { |
michael@0 | 75 | let index = pending.indexOf(received); |
michael@0 | 76 | if (index != -1) { |
michael@0 | 77 | pending.splice(index, 1); |
michael@0 | 78 | } |
michael@0 | 79 | if (pending.length === 0) { |
michael@0 | 80 | nextAction(); |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function waitRadioState(state) { |
michael@0 | 85 | let deferred = Promise.defer(); |
michael@0 | 86 | |
michael@0 | 87 | waitFor(function() { |
michael@0 | 88 | deferred.resolve(); |
michael@0 | 89 | }, function() { |
michael@0 | 90 | return connection.radioState == state; |
michael@0 | 91 | }); |
michael@0 | 92 | |
michael@0 | 93 | return deferred.promise; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function setRadioEnabled(enabled, transientState, finalState) { |
michael@0 | 97 | log("setRadioEnabled to " + enabled); |
michael@0 | 98 | |
michael@0 | 99 | let deferred = Promise.defer(); |
michael@0 | 100 | let done = function() { |
michael@0 | 101 | deferred.resolve(); |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | let pending = ["onradiostatechange", "onsuccess"]; |
michael@0 | 105 | |
michael@0 | 106 | let receivedTransient = false; |
michael@0 | 107 | connection.onradiostatechange = function() { |
michael@0 | 108 | let state = connection.radioState; |
michael@0 | 109 | log("Received 'radiostatechange' event, radioState: " + state); |
michael@0 | 110 | |
michael@0 | 111 | if (state == transientState) { |
michael@0 | 112 | receivedTransient = true; |
michael@0 | 113 | } else if (state == finalState) { |
michael@0 | 114 | ok(receivedTransient); |
michael@0 | 115 | receivedPending("onradiostatechange", pending, done); |
michael@0 | 116 | } |
michael@0 | 117 | }; |
michael@0 | 118 | |
michael@0 | 119 | let req = connection.setRadioEnabled(enabled); |
michael@0 | 120 | |
michael@0 | 121 | req.onsuccess = function() { |
michael@0 | 122 | log("setRadioEnabled success"); |
michael@0 | 123 | receivedPending("onsuccess", pending, done); |
michael@0 | 124 | }; |
michael@0 | 125 | |
michael@0 | 126 | req.onerror = function() { |
michael@0 | 127 | ok(false, "setRadioEnabled should not fail"); |
michael@0 | 128 | deferred.reject(); |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | return deferred.promise; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | function testSwitchRadio() { |
michael@0 | 135 | log("= testSwitchRadio ="); |
michael@0 | 136 | return waitRadioState("enabled") |
michael@0 | 137 | .then(setRadioEnabled.bind(null, false, "disabling", "disabled")) |
michael@0 | 138 | .then(setRadioEnabled.bind(null, true, "enabling", "enabled")); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | function testDisableRadioWhenDataConnected() { |
michael@0 | 142 | log("= testDisableRadioWhenDataConnected ="); |
michael@0 | 143 | return waitRadioState("enabled") |
michael@0 | 144 | .then(enableData) |
michael@0 | 145 | .then(setRadioEnabled.bind(null, false, "disabling", "disabled")) |
michael@0 | 146 | .then(() => { |
michael@0 | 147 | // Data should be disconnected. |
michael@0 | 148 | is(connection.data.connected, false); |
michael@0 | 149 | }) |
michael@0 | 150 | .then(setRadioEnabled.bind(null, true, "enabling", "enabled")) |
michael@0 | 151 | // Disable data |
michael@0 | 152 | .then(setSetting.bind(null, DATA_KEY, false)); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | function cleanUp() { |
michael@0 | 156 | SpecialPowers.removePermission("mobileconnection", document); |
michael@0 | 157 | SpecialPowers.removePermission("settings-write", document); |
michael@0 | 158 | SpecialPowers.removePermission("settings-read", document); |
michael@0 | 159 | SpecialPowers.clearUserPref("dom.mozSettings.enabled"); |
michael@0 | 160 | finish(); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | testSwitchRadio() |
michael@0 | 164 | .then(testDisableRadioWhenDataConnected) |
michael@0 | 165 | .then(null, () => { |
michael@0 | 166 | ok(false, "promise reject somewhere"); |
michael@0 | 167 | }) |
michael@0 | 168 | .then(cleanUp); |