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 | SpecialPowers.addPermission("voicemail", true, document); |
michael@0 | 5 | |
michael@0 | 6 | let voicemail = window.navigator.mozVoicemail; |
michael@0 | 7 | let serviceId = 0; |
michael@0 | 8 | |
michael@0 | 9 | ok(voicemail instanceof MozVoicemail); |
michael@0 | 10 | is(voicemail.status, null); |
michael@0 | 11 | |
michael@0 | 12 | function sendIndicatorPDU(pdu, listener, nextTest) { |
michael@0 | 13 | let smsCommand = "sms pdu " + pdu; |
michael@0 | 14 | let commandCompleted = false; |
michael@0 | 15 | let sawEvent = false; |
michael@0 | 16 | |
michael@0 | 17 | voicemail.addEventListener("statuschanged", function statusChanged(event) { |
michael@0 | 18 | voicemail.removeEventListener("statuschanged", statusChanged); |
michael@0 | 19 | |
michael@0 | 20 | try { |
michael@0 | 21 | listener(event); |
michael@0 | 22 | } catch (e) { |
michael@0 | 23 | ok(false, String(e)); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | sawEvent = true; |
michael@0 | 27 | if (commandCompleted) { |
michael@0 | 28 | nextTest(); |
michael@0 | 29 | } |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | log("-> " + smsCommand); |
michael@0 | 33 | runEmulatorCmd(smsCommand, function(result) { |
michael@0 | 34 | log("<- " + result); |
michael@0 | 35 | is(result[0], "OK"); |
michael@0 | 36 | commandCompleted = true; |
michael@0 | 37 | if (sawEvent) { |
michael@0 | 38 | nextTest(); |
michael@0 | 39 | } |
michael@0 | 40 | }); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | // TODO: Add tests for store/discard once they are implemented |
michael@0 | 44 | // See RadioInterfaceLayer.js / Bug #768441 |
michael@0 | 45 | |
michael@0 | 46 | function isVoicemailStatus(status) { |
michael@0 | 47 | is(voicemail.getStatus(), status); |
michael@0 | 48 | is(voicemail.getStatus(serviceId), status); |
michael@0 | 49 | |
michael@0 | 50 | is(voicemail.getStatus().hasMessages, status.hasMessages); |
michael@0 | 51 | is(voicemail.getStatus().messageCount, status.messageCount); |
michael@0 | 52 | is(voicemail.getStatus().returnNumber, status.returnNumber); |
michael@0 | 53 | is(voicemail.getStatus().returnMessage, status.returnMessage); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | const MWI_PDU_PREFIX = "0000"; |
michael@0 | 57 | const MWI_PDU_UDH_PREFIX = "0040"; |
michael@0 | 58 | const MWI_PID_DEFAULT = "00"; |
michael@0 | 59 | const MWI_DCS_DISCARD_INACTIVE = "C0"; |
michael@0 | 60 | const MWI_DCS_DISCARD_ACTIVE = "C8"; |
michael@0 | 61 | const MWI_TIMESTAMP = "00000000000000"; |
michael@0 | 62 | |
michael@0 | 63 | const MWI_DEFAULT_BODY = "1 new voicemail"; |
michael@0 | 64 | const MWI_UD_DEFAULT = PDUBuilder.buildUserData({ |
michael@0 | 65 | body: MWI_DEFAULT_BODY |
michael@0 | 66 | }); |
michael@0 | 67 | |
michael@0 | 68 | const MWI_LEVEL2_SENDER = "+15125551235"; |
michael@0 | 69 | const MWI_LEVEL2_PDU_ADDRESS = PDUBuilder.buildAddress(MWI_LEVEL2_SENDER); |
michael@0 | 70 | const MWI_LEVEL2_DISCARD_ACTIVE_PDU = |
michael@0 | 71 | MWI_PDU_PREFIX + |
michael@0 | 72 | MWI_LEVEL2_PDU_ADDRESS + |
michael@0 | 73 | MWI_PID_DEFAULT + |
michael@0 | 74 | MWI_DCS_DISCARD_ACTIVE + |
michael@0 | 75 | MWI_TIMESTAMP + |
michael@0 | 76 | MWI_UD_DEFAULT; |
michael@0 | 77 | |
michael@0 | 78 | function testLevel2DiscardActive() { |
michael@0 | 79 | |
michael@0 | 80 | function onLevel2Active(event) { |
michael@0 | 81 | let status = event.status; |
michael@0 | 82 | // TODO: bug 905228 - MozVoicemailStatus is not defined. |
michael@0 | 83 | //ok(status instanceof MozVoicemailStatus); |
michael@0 | 84 | is(status.hasMessages, true); |
michael@0 | 85 | is(status.messageCount, -1); |
michael@0 | 86 | is(status.returnNumber, MWI_LEVEL2_SENDER); |
michael@0 | 87 | is(status.returnMessage, MWI_DEFAULT_BODY); |
michael@0 | 88 | isVoicemailStatus(status); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | sendIndicatorPDU(MWI_LEVEL2_DISCARD_ACTIVE_PDU, |
michael@0 | 92 | onLevel2Active, |
michael@0 | 93 | testLevel2DiscardInactive); |
michael@0 | 94 | |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | const MWI_LEVEL2_DISCARD_INACTIVE_PDU = |
michael@0 | 98 | MWI_PDU_PREFIX + |
michael@0 | 99 | MWI_LEVEL2_PDU_ADDRESS + |
michael@0 | 100 | MWI_PID_DEFAULT + |
michael@0 | 101 | MWI_DCS_DISCARD_INACTIVE + |
michael@0 | 102 | MWI_TIMESTAMP + |
michael@0 | 103 | MWI_UD_DEFAULT; |
michael@0 | 104 | |
michael@0 | 105 | function testLevel2DiscardInactive() { |
michael@0 | 106 | function onLevel2Inactive(event) { |
michael@0 | 107 | let status = event.status; |
michael@0 | 108 | // TODO: bug 905228 - MozVoicemailStatus is not defined. |
michael@0 | 109 | //ok(status instanceof MozVoicemailStatus); |
michael@0 | 110 | is(status.hasMessages, false); |
michael@0 | 111 | is(status.messageCount, 0); |
michael@0 | 112 | is(status.returnNumber, MWI_LEVEL2_SENDER); |
michael@0 | 113 | is(status.returnMessage, MWI_DEFAULT_BODY); |
michael@0 | 114 | isVoicemailStatus(status); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | sendIndicatorPDU(MWI_LEVEL2_DISCARD_INACTIVE_PDU, |
michael@0 | 118 | onLevel2Inactive, |
michael@0 | 119 | testLevel3DiscardActive); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | |
michael@0 | 123 | // Tests for Level 3 MWI with a message count in the User Data Header |
michael@0 | 124 | const MWI_LEVEL3_SENDER = "+15125551236"; |
michael@0 | 125 | const MWI_LEVEL3_PDU_ADDRESS = PDUBuilder.buildAddress(MWI_LEVEL3_SENDER); |
michael@0 | 126 | |
michael@0 | 127 | const MWI_LEVEL3_ACTIVE_UDH_MSG_COUNT = 3; |
michael@0 | 128 | const MWI_LEVEL3_ACTIVE_BODY = "3 new voicemails"; |
michael@0 | 129 | const MWI_LEVEL3_ACTIVE_UD = PDUBuilder.buildUserData({ |
michael@0 | 130 | headers: [{ |
michael@0 | 131 | id: RIL.PDU_IEI_SPECIAL_SMS_MESSAGE_INDICATION, |
michael@0 | 132 | length: 2, |
michael@0 | 133 | octets: [ |
michael@0 | 134 | RIL.PDU_MWI_STORE_TYPE_DISCARD, |
michael@0 | 135 | MWI_LEVEL3_ACTIVE_UDH_MSG_COUNT |
michael@0 | 136 | ] |
michael@0 | 137 | }], |
michael@0 | 138 | body: MWI_LEVEL3_ACTIVE_BODY |
michael@0 | 139 | }); |
michael@0 | 140 | |
michael@0 | 141 | const MWI_LEVEL3_DISCARD_ACTIVE_PDU = |
michael@0 | 142 | MWI_PDU_UDH_PREFIX + |
michael@0 | 143 | MWI_LEVEL3_PDU_ADDRESS + |
michael@0 | 144 | MWI_PID_DEFAULT + |
michael@0 | 145 | MWI_DCS_DISCARD_ACTIVE + |
michael@0 | 146 | MWI_TIMESTAMP + |
michael@0 | 147 | MWI_LEVEL3_ACTIVE_UD; |
michael@0 | 148 | |
michael@0 | 149 | function testLevel3DiscardActive() { |
michael@0 | 150 | |
michael@0 | 151 | function onLevel3Active(event) { |
michael@0 | 152 | let status = event.status; |
michael@0 | 153 | // TODO: bug 905228 - MozVoicemailStatus is not defined. |
michael@0 | 154 | //ok(status instanceof MozVoicemailStatus); |
michael@0 | 155 | is(status.hasMessages, true); |
michael@0 | 156 | is(status.messageCount, MWI_LEVEL3_ACTIVE_UDH_MSG_COUNT); |
michael@0 | 157 | is(status.returnNumber, MWI_LEVEL3_SENDER); |
michael@0 | 158 | is(status.returnMessage, MWI_LEVEL3_ACTIVE_BODY); |
michael@0 | 159 | isVoicemailStatus(status); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | sendIndicatorPDU(MWI_LEVEL3_DISCARD_ACTIVE_PDU, |
michael@0 | 163 | onLevel3Active, |
michael@0 | 164 | testLevel3DiscardInactive); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | const MWI_LEVEL3_INACTIVE_BODY = "No unread voicemails"; |
michael@0 | 168 | const MWI_LEVEL3_INACTIVE_UD = PDUBuilder.buildUserData({ |
michael@0 | 169 | headers: [{ |
michael@0 | 170 | id: RIL.PDU_IEI_SPECIAL_SMS_MESSAGE_INDICATION, |
michael@0 | 171 | length: 2, |
michael@0 | 172 | octets: [ |
michael@0 | 173 | RIL.PDU_MWI_STORE_TYPE_DISCARD, |
michael@0 | 174 | 0 // messageCount |
michael@0 | 175 | ] |
michael@0 | 176 | }], |
michael@0 | 177 | body: MWI_LEVEL3_INACTIVE_BODY |
michael@0 | 178 | }); |
michael@0 | 179 | |
michael@0 | 180 | const MWI_LEVEL3_DISCARD_INACTIVE_PDU = |
michael@0 | 181 | MWI_PDU_UDH_PREFIX + |
michael@0 | 182 | MWI_LEVEL3_PDU_ADDRESS + |
michael@0 | 183 | MWI_PID_DEFAULT + |
michael@0 | 184 | MWI_DCS_DISCARD_ACTIVE + |
michael@0 | 185 | MWI_TIMESTAMP + |
michael@0 | 186 | MWI_LEVEL3_INACTIVE_UD; |
michael@0 | 187 | |
michael@0 | 188 | function testLevel3DiscardInactive() { |
michael@0 | 189 | function onLevel3Inactive(event) { |
michael@0 | 190 | let status = event.status; |
michael@0 | 191 | // TODO: bug 905228 - MozVoicemailStatus is not defined. |
michael@0 | 192 | //ok(status instanceof MozVoicemailStatus); |
michael@0 | 193 | is(status.hasMessages, false); |
michael@0 | 194 | is(status.messageCount, 0); |
michael@0 | 195 | is(status.returnNumber, MWI_LEVEL3_SENDER); |
michael@0 | 196 | is(status.returnMessage, MWI_LEVEL3_INACTIVE_BODY); |
michael@0 | 197 | isVoicemailStatus(status); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | sendIndicatorPDU(MWI_LEVEL3_DISCARD_INACTIVE_PDU, onLevel3Inactive, cleanUp); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | function cleanUp() { |
michael@0 | 204 | SpecialPowers.removePermission("voicemail", document); |
michael@0 | 205 | finish(); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | testLevel2DiscardActive(); |