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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=238987 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 238987</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=238987">Mozilla Bug 238987</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 238987 **/ |
michael@0 | 21 | |
michael@0 | 22 | var shouldStop = false; |
michael@0 | 23 | var modifier = 0; |
michael@0 | 24 | var expectedResult = "i1,i2,i3,i4,i5,i6,i7,i8,number,i9,i10,i11,i12"; |
michael@0 | 25 | var forwardFocusArray = expectedResult.split(","); |
michael@0 | 26 | var backwardFocusArray = expectedResult.split(","); |
michael@0 | 27 | var forwardBlurArray = expectedResult.split(","); |
michael@0 | 28 | var backwardBlurArray = expectedResult.split(","); |
michael@0 | 29 | // Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template, |
michael@0 | 30 | var expectedWindowFocusCount = forwardFocusArray.length + backwardFocusArray.length + 4; |
michael@0 | 31 | // but the last blur event goes to i1, not "begin". |
michael@0 | 32 | var expectedWindowBlurCount = forwardFocusArray.length + backwardFocusArray.length + 3; |
michael@0 | 33 | |
michael@0 | 34 | // accessibility.tabfocus must be set to value 7 before running test also |
michael@0 | 35 | // on a mac. |
michael@0 | 36 | function setOrRestoreTabFocus(newValue) { |
michael@0 | 37 | if (!newValue) { |
michael@0 | 38 | SpecialPowers.clearUserPref("accessibility.tabfocus"); |
michael@0 | 39 | } else { |
michael@0 | 40 | SpecialPowers.setIntPref("accessibility.tabfocus", newValue); |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function handleFocus(e) { |
michael@0 | 45 | if (e.target.id == "begin") { |
michael@0 | 46 | // if the modifier is set, the test is coming back from the end. |
michael@0 | 47 | if (modifier) { |
michael@0 | 48 | shouldStop = true; |
michael@0 | 49 | } |
michael@0 | 50 | } else if (e.target.id == "end") { |
michael@0 | 51 | modifier = Components.interfaces.nsIDOMEvent.SHIFT_MASK; |
michael@0 | 52 | } else if (modifier) { |
michael@0 | 53 | var expected = backwardFocusArray.pop(); |
michael@0 | 54 | ok(expected == e.target.id, |
michael@0 | 55 | "(focus) Backward tabbing, expected [" + |
michael@0 | 56 | expected + "], got [" + e.target.id + "]"); |
michael@0 | 57 | } else { |
michael@0 | 58 | var expected = forwardFocusArray.shift(); |
michael@0 | 59 | is(e.target, document.activeElement, "Wrong activeElement!"); |
michael@0 | 60 | ok(expected == e.target.id, |
michael@0 | 61 | "(focus) Forward tabbing, expected [" + |
michael@0 | 62 | expected + "], got [" + e.target.id + "]"); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function handleWindowFocus(e) { |
michael@0 | 67 | --expectedWindowFocusCount; |
michael@0 | 68 | var s = "target " + e.target; |
michael@0 | 69 | if ("id" in e.target) { |
michael@0 | 70 | s = s + ", id=\"" + e.target.id + "\""; |
michael@0 | 71 | } |
michael@0 | 72 | ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE, |
michael@0 | 73 | "|window| should not have got a focus event, " + s); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function handleBlur(e) { |
michael@0 | 77 | if (e.target.id == "begin" || e.target.id == "end") { |
michael@0 | 78 | return; |
michael@0 | 79 | } else if (modifier) { |
michael@0 | 80 | var expected = backwardBlurArray.pop(); |
michael@0 | 81 | ok(expected == e.target.id, |
michael@0 | 82 | "(blur) backward tabbing, expected [" + |
michael@0 | 83 | expected + "], got [" + e.target.id + "]"); |
michael@0 | 84 | } else { |
michael@0 | 85 | var expected = forwardBlurArray.shift(); |
michael@0 | 86 | ok(expected == e.target.id, |
michael@0 | 87 | "(blur) forward tabbing, expected [" + |
michael@0 | 88 | expected + "], got [" + e.target.id + "]"); |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function handleWindowBlur(e) { |
michael@0 | 93 | --expectedWindowBlurCount; |
michael@0 | 94 | var s = "target " + e.target; |
michael@0 | 95 | if ("id" in e.target) { |
michael@0 | 96 | s = s + ", id=\"" + e.target.id + "\""; |
michael@0 | 97 | } |
michael@0 | 98 | ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE, |
michael@0 | 99 | "|window| should not have got a blur event, " + s); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function tab() { |
michael@0 | 103 | var utils = SpecialPowers.DOMWindowUtils; |
michael@0 | 104 | // Send tab key events. |
michael@0 | 105 | var key = Components.interfaces.nsIDOMKeyEvent.DOM_VK_TAB; |
michael@0 | 106 | utils.sendKeyEvent("keydown", key, 0, modifier); |
michael@0 | 107 | utils.sendKeyEvent("keypress", key, 0, modifier); |
michael@0 | 108 | utils.sendKeyEvent("keyup", key, 0, modifier); |
michael@0 | 109 | if (shouldStop) { |
michael@0 | 110 | // Did focus handling succeed |
michael@0 | 111 | is(forwardFocusArray.length, 0, |
michael@0 | 112 | "Not all forward tabbing focus tests were run, " + |
michael@0 | 113 | forwardFocusArray.toString()); |
michael@0 | 114 | is(backwardFocusArray.length, 0, |
michael@0 | 115 | "Not all backward tabbing focus tests were run, " + |
michael@0 | 116 | backwardFocusArray.toString()); |
michael@0 | 117 | is(expectedWindowFocusCount, 0, |
michael@0 | 118 | "|window| didn't get the right amount of focus events"); |
michael@0 | 119 | |
michael@0 | 120 | // and blur. |
michael@0 | 121 | is(forwardBlurArray.length, 0, |
michael@0 | 122 | "Not all forward tabbing blur tests were run, " + |
michael@0 | 123 | forwardBlurArray.toString()); |
michael@0 | 124 | is(backwardBlurArray.length, 0, |
michael@0 | 125 | "Not all backward tabbing blur tests were run, " + |
michael@0 | 126 | backwardBlurArray.toString()); |
michael@0 | 127 | is(expectedWindowBlurCount, 0, |
michael@0 | 128 | "|window| didn't get the right amount of blur events"); |
michael@0 | 129 | |
michael@0 | 130 | // Cleanup |
michael@0 | 131 | setOrRestoreTabFocus(0); |
michael@0 | 132 | window.removeEventListener("focus", handleWindowFocus, true); |
michael@0 | 133 | window.removeEventListener("focus", handleWindowFocus, false); |
michael@0 | 134 | window.removeEventListener("blur", handleWindowBlur, true); |
michael@0 | 135 | window.removeEventListener("blur", handleWindowBlur, false); |
michael@0 | 136 | var elements = document.getElementsByTagName("*"); |
michael@0 | 137 | for (var i = 0; i < elements.length; ++i) { |
michael@0 | 138 | if (elements[i].hasAttribute("id")) { |
michael@0 | 139 | elements[i].removeEventListener("focus", handleFocus, false); |
michael@0 | 140 | elements[i].removeEventListener("blur", handleBlur, false); |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | SimpleTest.finish(); |
michael@0 | 145 | } else { |
michael@0 | 146 | setTimeout(tab, 0); |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function start() { |
michael@0 | 151 | window.focus(); |
michael@0 | 152 | window.addEventListener("focus", handleWindowFocus, true); |
michael@0 | 153 | window.addEventListener("focus", handleWindowFocus, false); |
michael@0 | 154 | window.addEventListener("blur", handleWindowBlur, true); |
michael@0 | 155 | window.addEventListener("blur", handleWindowBlur, false); |
michael@0 | 156 | var elements = document.getElementsByTagName("*"); |
michael@0 | 157 | for (var i = 0; i < elements.length; ++i) { |
michael@0 | 158 | if (elements[i].hasAttribute("id")) { |
michael@0 | 159 | elements[i].addEventListener("focus", handleFocus, false); |
michael@0 | 160 | elements[i].addEventListener("blur", handleBlur, false); |
michael@0 | 161 | } |
michael@0 | 162 | if (elements[i].getAttribute("tabindex") == "1") { |
michael@0 | 163 | elements[i].setAttribute("tabindex", "-1"); |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | tab(); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function doTest() { |
michael@0 | 170 | setOrRestoreTabFocus(7); |
michael@0 | 171 | setTimeout(start, 0); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 175 | addLoadEvent(doTest); |
michael@0 | 176 | |
michael@0 | 177 | </script> |
michael@0 | 178 | </pre> |
michael@0 | 179 | <h4 tabindex="0" id="begin">Test:</h4> |
michael@0 | 180 | <table> |
michael@0 | 181 | <tbody> |
michael@0 | 182 | <tr> |
michael@0 | 183 | <td>type="text"</td><td><input type="text" id="i1" value=""></td> |
michael@0 | 184 | </tr> |
michael@0 | 185 | <tr> |
michael@0 | 186 | <td>type="button"</td><td><input type="button" id="i2" value="type='button'"></td> |
michael@0 | 187 | </tr> |
michael@0 | 188 | <tr> |
michael@0 | 189 | <td>type="checkbox"</td><td><input type="checkbox" id="i3" ></td> |
michael@0 | 190 | </tr> |
michael@0 | 191 | <tr> |
michael@0 | 192 | <td>type="radio" checked</td><td><input type="radio" id="i4" name="radio" checked> |
michael@0 | 193 | <input type="radio" id="i4b" name="radio"></td> |
michael@0 | 194 | </tr> |
michael@0 | 195 | <tr> |
michael@0 | 196 | <td>type="radio"</td><td><input type="radio" id="i5" name="radio2"> |
michael@0 | 197 | <input type="radio" id="i6" name="radio2"></td> |
michael@0 | 198 | </tr> |
michael@0 | 199 | <tr> |
michael@0 | 200 | <td>type="password"</td><td><input type="password" id="i7"></td> |
michael@0 | 201 | </tr> |
michael@0 | 202 | <tr> |
michael@0 | 203 | <td>type="file"</td><td><input type="file" id="i8"></td> |
michael@0 | 204 | </tr> |
michael@0 | 205 | <tr> |
michael@0 | 206 | <td>type="number"</td><td><input type="number" id="number"></td> |
michael@0 | 207 | </tr> |
michael@0 | 208 | <tr> |
michael@0 | 209 | <td>button</td><td><button id="i9">button</button></td> |
michael@0 | 210 | </tr> |
michael@0 | 211 | <tr> |
michael@0 | 212 | <td>select</td><td><select id="i10"><option>select</option></select></td> |
michael@0 | 213 | </tr> |
michael@0 | 214 | <tr> |
michael@0 | 215 | <td>a</td><td><a href="#radio" id="i11">a link</a></td> |
michael@0 | 216 | </tr> |
michael@0 | 217 | <tr> |
michael@0 | 218 | <td>tabindex="0"</td><td><span tabindex="0" id="i12">span</span></td> |
michael@0 | 219 | </tr> |
michael@0 | 220 | |
michael@0 | 221 | <tr> |
michael@0 | 222 | <td><h3>Form elements with tabindex="-1"</h3></td> |
michael@0 | 223 | </tr> |
michael@0 | 224 | <tr> |
michael@0 | 225 | <td>type="text"</td><td><input type="text" tabindex="-1" value=""></td> |
michael@0 | 226 | </tr> |
michael@0 | 227 | <tr> |
michael@0 | 228 | <td>type="button"</td><td><input type="button" tabindex="-1" value="type='button'"></td> |
michael@0 | 229 | </tr> |
michael@0 | 230 | <tr> |
michael@0 | 231 | <td>type="checkbox"</td><td><input type="checkbox" tabindex="-1"></td> |
michael@0 | 232 | </tr> |
michael@0 | 233 | <tr> |
michael@0 | 234 | <td>type="radio" checked</td><td><input type="radio" tabindex="-1" name="radio3" checked> |
michael@0 | 235 | <input type="radio" tabindex="-1" name="radio3"></td> |
michael@0 | 236 | </tr> |
michael@0 | 237 | <tr> |
michael@0 | 238 | <td>type="radio"</td><td><input type="radio" tabindex="-1" name="radio4"> |
michael@0 | 239 | <input type="radio" tabindex="-1" name="radio4"></td> |
michael@0 | 240 | </tr> |
michael@0 | 241 | <tr> |
michael@0 | 242 | <td>type="password"</td><td><input type="password" tabindex="-1"></td> |
michael@0 | 243 | </tr> |
michael@0 | 244 | <tr> |
michael@0 | 245 | <td>type="file"</td><td><input type="file" tabindex="-1"></td> |
michael@0 | 246 | </tr> |
michael@0 | 247 | <tr> |
michael@0 | 248 | <td>button</td><td><button tabindex="-1">button</button></td> |
michael@0 | 249 | </tr> |
michael@0 | 250 | <tr> |
michael@0 | 251 | <td>select</td><td><select tabindex="-1"><option>select</option></select></td> |
michael@0 | 252 | </tr> |
michael@0 | 253 | |
michael@0 | 254 | <tr> |
michael@0 | 255 | <td><h3>Form elements with .setAttribute("tabindex", "-1")</h3></td> |
michael@0 | 256 | </tr> |
michael@0 | 257 | <tr> |
michael@0 | 258 | <td>type="text"</td><td><input type="text" tabindex="1" value=""></td> |
michael@0 | 259 | </tr> |
michael@0 | 260 | <tr> |
michael@0 | 261 | <td>type="button"</td><td><input type="button" tabindex="1" value="type='button'"></td> |
michael@0 | 262 | </tr> |
michael@0 | 263 | <tr> |
michael@0 | 264 | <td>type="checkbox"</td><td><input type="checkbox" tabindex="1"></td> |
michael@0 | 265 | </tr> |
michael@0 | 266 | <tr> |
michael@0 | 267 | <td>type="radio" checked</td><td><input type="radio" tabindex="1" name="radio5" checked> |
michael@0 | 268 | <input type="radio" tabindex="1" name="radio5"></td> |
michael@0 | 269 | </tr> |
michael@0 | 270 | <tr> |
michael@0 | 271 | <td>type="radio"</td><td><input type="radio" tabindex="1" name="radio6"> |
michael@0 | 272 | <input type="radio" tabindex="1" name="radio6"></td> |
michael@0 | 273 | </tr> |
michael@0 | 274 | <tr> |
michael@0 | 275 | <td>type="password"</td><td><input type="password" tabindex="1"></td> |
michael@0 | 276 | </tr> |
michael@0 | 277 | <tr> |
michael@0 | 278 | <td>type="file"</td><td><input type="file" tabindex="1"></td> |
michael@0 | 279 | </tr> |
michael@0 | 280 | <tr> |
michael@0 | 281 | <td>button</td><td><button tabindex="1">button</button></td> |
michael@0 | 282 | </tr> |
michael@0 | 283 | <tr> |
michael@0 | 284 | <td>select</td><td><select tabindex="1"><option>select</option></select></td> |
michael@0 | 285 | </tr> |
michael@0 | 286 | |
michael@0 | 287 | </tbody> |
michael@0 | 288 | </table> |
michael@0 | 289 | <h4 tabindex="0" id="end">done.</h4> |
michael@0 | 290 | </body> |
michael@0 | 291 | </html> |
michael@0 | 292 |