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 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 4 | <!-- |
michael@0 | 5 | XUL Widget Test for scale |
michael@0 | 6 | --> |
michael@0 | 7 | <window title="scale" width="500" height="600" |
michael@0 | 8 | onload="setTimeout(testtag_scale, 0);" |
michael@0 | 9 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 10 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 12 | |
michael@0 | 13 | <hbox> |
michael@0 | 14 | <vbox> |
michael@0 | 15 | <scale id="scale-horizontal-normal"/> |
michael@0 | 16 | <scale id="scale-horizontal-reverse" dir="reverse"/> |
michael@0 | 17 | </vbox> |
michael@0 | 18 | <scale id="scale-vertical-normal" orient="vertical"/> |
michael@0 | 19 | <scale id="scale-vertical-reverse" orient="vertical" dir="reverse"/> |
michael@0 | 20 | </hbox> |
michael@0 | 21 | |
michael@0 | 22 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 23 | <p id="display"></p> |
michael@0 | 24 | <div id="content" style="display: none"> |
michael@0 | 25 | </div> |
michael@0 | 26 | <pre id="test"> |
michael@0 | 27 | </pre> |
michael@0 | 28 | </body> |
michael@0 | 29 | |
michael@0 | 30 | <script> |
michael@0 | 31 | <![CDATA[ |
michael@0 | 32 | |
michael@0 | 33 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 34 | |
michael@0 | 35 | function testtag_scale() |
michael@0 | 36 | { |
michael@0 | 37 | testtag_scale_inner("scale-horizontal-normal", true, false); |
michael@0 | 38 | testtag_scale_inner("scale-horizontal-reverse", true, true); |
michael@0 | 39 | testtag_scale_inner("scale-vertical-normal", false, false); |
michael@0 | 40 | testtag_scale_inner("scale-vertical-reverse", false, true); |
michael@0 | 41 | |
michael@0 | 42 | SimpleTest.finish(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function testtag_scale_inner(elementid, horiz, reverse) |
michael@0 | 46 | { |
michael@0 | 47 | var testid = (horiz ? "horizontal " : "vertical ") + |
michael@0 | 48 | (reverse ? "reverse " : "normal "); |
michael@0 | 49 | |
michael@0 | 50 | var element = document.getElementById(elementid); |
michael@0 | 51 | |
michael@0 | 52 | testtag_scale_States(element, 0, "", 0, 100, testid + "initial"); |
michael@0 | 53 | |
michael@0 | 54 | element.min = 0; |
michael@0 | 55 | element.max = 10; |
michael@0 | 56 | testtag_scale_States(element, 0, "", 0, 10, testid + "first set"); |
michael@0 | 57 | |
michael@0 | 58 | element.decrease(); |
michael@0 | 59 | is(element.value, 0, testid + "decrease"); |
michael@0 | 60 | element.increase(); |
michael@0 | 61 | is(element.value, 1, testid + "increase"); |
michael@0 | 62 | element.value = 0; |
michael@0 | 63 | is(element.value, 0, testid + "set value"); |
michael@0 | 64 | |
michael@0 | 65 | testtag_scale_Increments(element, 0, 10, 6, 7, testid + "increase decrease"); |
michael@0 | 66 | |
michael@0 | 67 | // check if changing the min and max adjusts the value to fit in range |
michael@0 | 68 | element.min = 5; |
michael@0 | 69 | testtag_scale_States(element, 5, "5", 5, 10, testid + "change min"); |
michael@0 | 70 | element.value = 15; |
michael@0 | 71 | is(element.value, 10, testid + "change minmax value set too high"); |
michael@0 | 72 | element.max = 8; |
michael@0 | 73 | is(element.value, 8, testid + "change max"); |
michael@0 | 74 | element.value = 2; |
michael@0 | 75 | is(element.value, 5, testid + "change minmax set too low"); |
michael@0 | 76 | |
michael@0 | 77 | // check negative values |
michael@0 | 78 | element.min = -15; |
michael@0 | 79 | element.max = -5; |
michael@0 | 80 | testtag_scale_States(element, -5, "-5", -15, -5, testid + "minmax negative"); |
michael@0 | 81 | element.value = -15; |
michael@0 | 82 | is(element.value, -15, testid + "change max negative"); |
michael@0 | 83 | testtag_scale_Increments(element, -15, -5, 7, 8, testid + "increase decrease negative"); |
michael@0 | 84 | |
michael@0 | 85 | // check case when min is negative and max is positive |
michael@0 | 86 | element.min = -10; |
michael@0 | 87 | element.max = 35; |
michael@0 | 88 | testtag_scale_States(element, -10, "-10", -10, 35, testid + "minmax mixed sign"); |
michael@0 | 89 | testtag_scale_Increments(element, -10, 35, 25, 30, testid + "increase decrease mixed sign"); |
michael@0 | 90 | |
michael@0 | 91 | testtag_scale_UI(element, testid, horiz, reverse); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function testtag_scale_UI(element, testid, horiz, reverse) |
michael@0 | 95 | { |
michael@0 | 96 | element.min = 0; |
michael@0 | 97 | element.max = 20; |
michael@0 | 98 | element.value = 7; |
michael@0 | 99 | element.increment = 2; |
michael@0 | 100 | element.pageIncrement = 4; |
michael@0 | 101 | |
michael@0 | 102 | element.focus(); |
michael@0 | 103 | |
michael@0 | 104 | var leftIncrements = horiz && reverse; |
michael@0 | 105 | var upDecrements = !horiz && !reverse; |
michael@0 | 106 | synthesizeKeyExpectEvent("VK_LEFT", { }, element, "change", testid + "key left"); |
michael@0 | 107 | is(element.value, leftIncrements ? 9 : 5, testid + " key left"); |
michael@0 | 108 | synthesizeKeyExpectEvent("VK_RIGHT", { }, element, "change", testid + "key right"); |
michael@0 | 109 | is(element.value, 7, testid + " key right"); |
michael@0 | 110 | synthesizeKeyExpectEvent("VK_UP", { }, element, "change", testid + "key up"); |
michael@0 | 111 | is(element.value, upDecrements ? 5 : 9, testid + " key up"); |
michael@0 | 112 | synthesizeKeyExpectEvent("VK_DOWN", { }, element, "change", testid + "key down"); |
michael@0 | 113 | is(element.value, 7, testid + " key down"); |
michael@0 | 114 | |
michael@0 | 115 | synthesizeKeyExpectEvent("VK_PAGE_UP", { }, element, "change", testid + "key page up"); |
michael@0 | 116 | is(element.value, upDecrements ? 3 : 11, testid + " key page up"); |
michael@0 | 117 | synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, element, "change", testid + "key page down"); |
michael@0 | 118 | is(element.value, 7, testid + " key page down"); |
michael@0 | 119 | |
michael@0 | 120 | synthesizeKeyExpectEvent("VK_HOME", { }, element, "change", testid + "key home"); |
michael@0 | 121 | is(element.value, reverse ? 20 : 0, testid + " key home"); |
michael@0 | 122 | synthesizeKeyExpectEvent("VK_END", { }, element, "change", testid + "key end"); |
michael@0 | 123 | is(element.value, reverse ? 0 : 20, testid + " key end"); |
michael@0 | 124 | |
michael@0 | 125 | testtag_scale_UI_Mouse(element, testid, horiz, reverse, 4); |
michael@0 | 126 | |
michael@0 | 127 | element.min = 4; |
michael@0 | 128 | element.pageIncrement = 3; |
michael@0 | 129 | testtag_scale_UI_Mouse(element, testid + " with min", horiz, reverse, 3); |
michael@0 | 130 | |
michael@0 | 131 | element.pageIncrement = 30; |
michael@0 | 132 | testtag_scale_UI_Mouse(element, testid + " with min past", horiz, reverse, 30); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function testtag_scale_UI_Mouse(element, testid, horiz, reverse, pinc) |
michael@0 | 136 | { |
michael@0 | 137 | var initial = reverse ? 8 : 12; |
michael@0 | 138 | var newval = initial + (reverse ? pinc : -pinc); |
michael@0 | 139 | var endval = initial; |
michael@0 | 140 | // in the pinc == 30 case, the page increment is large enough that it would |
michael@0 | 141 | // just cause the thumb to reach the end of the scale. Make sure that the |
michael@0 | 142 | // mouse click does not go past the end. |
michael@0 | 143 | if (pinc == 30) { |
michael@0 | 144 | newval = reverse ? 20 : 4; |
michael@0 | 145 | endval = reverse ? 4 : 20; |
michael@0 | 146 | } |
michael@0 | 147 | element.value = initial; |
michael@0 | 148 | |
michael@0 | 149 | var hmove = horiz ? 25 : 10; |
michael@0 | 150 | var vmove = horiz ? 10 : 25; |
michael@0 | 151 | |
michael@0 | 152 | var leftFn = function () { return reverse ? element.value < newval + 3 : element.value > newval - 3; } |
michael@0 | 153 | var rightFn = function () { return reverse ? element.value < endval - 3 : element.value < endval + 3; } |
michael@0 | 154 | |
michael@0 | 155 | // check that clicking the mouse on the trough moves the thumb properly |
michael@0 | 156 | synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=default"); |
michael@0 | 157 | |
michael@0 | 158 | if (navigator.platform.indexOf("Mac") >= 0) { |
michael@0 | 159 | if (pinc == 30) |
michael@0 | 160 | ok(element.value > 4, testid + " mouse on left movetoclick=default"); |
michael@0 | 161 | else |
michael@0 | 162 | ok(leftFn, testid + " mouse on left movetoclick=default"); |
michael@0 | 163 | } |
michael@0 | 164 | else { |
michael@0 | 165 | is(element.value, newval, testid + " mouse on left movetoclick=default"); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | var rect = element.getBoundingClientRect(); |
michael@0 | 169 | synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, |
michael@0 | 170 | rect.bottom - rect.top - vmove, { }, |
michael@0 | 171 | element, "change", testid + " mouse on right movetoclick=default"); |
michael@0 | 172 | |
michael@0 | 173 | if (navigator.platform.indexOf("Mac") >= 0) { |
michael@0 | 174 | if (pinc == 30) |
michael@0 | 175 | ok(element.value < 20, testid + " mouse on right movetoclick=default"); |
michael@0 | 176 | else |
michael@0 | 177 | ok(rightFn, testid + " mouse on right movetoclick=default"); |
michael@0 | 178 | } |
michael@0 | 179 | else { |
michael@0 | 180 | is(element.value, endval, testid + " mouse on right movetoclick=default"); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | element.setAttribute("movetoclick", "true"); |
michael@0 | 184 | element.value = initial; |
michael@0 | 185 | |
michael@0 | 186 | synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=true"); |
michael@0 | 187 | if (pinc == 30) |
michael@0 | 188 | ok(element.value > 4, testid + " mouse on left movetoclick=true"); |
michael@0 | 189 | else |
michael@0 | 190 | ok(leftFn, testid + " mouse on left movetoclick=true"); |
michael@0 | 191 | |
michael@0 | 192 | var rect = element.getBoundingClientRect(); |
michael@0 | 193 | synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, |
michael@0 | 194 | rect.bottom - rect.top - vmove, { }, |
michael@0 | 195 | element, "change", testid + " mouse on right movetoclick=true"); |
michael@0 | 196 | if (pinc == 30) |
michael@0 | 197 | ok(element.value < 20, testid + " mouse on right movetoclick=true"); |
michael@0 | 198 | else |
michael@0 | 199 | ok(rightFn, testid + " mouse on right movetoclick=true"); |
michael@0 | 200 | |
michael@0 | 201 | element.setAttribute("movetoclick", "false"); |
michael@0 | 202 | element.value = initial; |
michael@0 | 203 | |
michael@0 | 204 | synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=false"); |
michael@0 | 205 | is(element.value, newval, testid + " mouse on left movetoclick=false"); |
michael@0 | 206 | |
michael@0 | 207 | var rect = element.getBoundingClientRect(); |
michael@0 | 208 | synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, |
michael@0 | 209 | rect.bottom - rect.top - vmove, { }, |
michael@0 | 210 | element, "change", testid + " mouse on right movetoclick=false"); |
michael@0 | 211 | is(element.value, endval, testid + " mouse on right movetoclick=false"); |
michael@0 | 212 | |
michael@0 | 213 | element.removeAttribute("movetoclick"); |
michael@0 | 214 | |
michael@0 | 215 | element.value = reverse ? element.max : element.min; |
michael@0 | 216 | |
michael@0 | 217 | synthesizeMouse(element, 8, 8, { type: "mousedown" }); |
michael@0 | 218 | synthesizeMouse(element, horiz ? 2000 : 8, horiz ? 8 : 2000, { type: "mousemove" }); |
michael@0 | 219 | is(element.value, reverse ? element.min : element.max, testid + " move mouse too far after end"); |
michael@0 | 220 | synthesizeMouse(element, 2, 2, { type: "mouseup" }); |
michael@0 | 221 | |
michael@0 | 222 | synthesizeMouse(element, rect.width - 8, rect.height - 8, { type: "mousedown" }); |
michael@0 | 223 | synthesizeMouse(element, horiz ? -2000 : rect.width - 8, horiz ? rect.height - 8 : -2000, { type: "mousemove" }); |
michael@0 | 224 | is(element.value, reverse ? element.max : element.min, testid + " move mouse too far before start"); |
michael@0 | 225 | |
michael@0 | 226 | synthesizeMouse(element, 2, 2, { type: "mouseup" }); |
michael@0 | 227 | |
michael@0 | 228 | // now check if moving outside in both directions works. On Windows, |
michael@0 | 229 | // it should snap back to the original location. |
michael@0 | 230 | element.value = reverse ? element.max : element.min; |
michael@0 | 231 | |
michael@0 | 232 | var expected = (navigator.platform.indexOf("Win") >= 0) ? element.value : |
michael@0 | 233 | (reverse ? element.min : element.max); |
michael@0 | 234 | synthesizeMouse(element, 7, 7, { type: "mousedown" }); |
michael@0 | 235 | synthesizeMouse(element, 2000, 2000, { type: "mousemove" }); |
michael@0 | 236 | is(element.value, expected, testid + " move mouse ouside in both directions"); |
michael@0 | 237 | synthesizeMouse(element, 2, 2, { type: "mouseup" }); |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | function testtag_scale_States(element, evalue, evalueattr, emin, emax, testid) |
michael@0 | 241 | { |
michael@0 | 242 | is(element.getAttribute("value"), evalueattr, testid + " value attribute"); |
michael@0 | 243 | is(element.value, evalue, testid + " value"); |
michael@0 | 244 | is(element.min, emin, testid + " min"); |
michael@0 | 245 | is(element.max, emax, testid + " max"); |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | function testtag_scale_Increments(element, min, max, increment, pageIncrement, testid) |
michael@0 | 249 | { |
michael@0 | 250 | // check the increase and decrease methods |
michael@0 | 251 | element.increment = increment; |
michael@0 | 252 | element.increase(); |
michael@0 | 253 | is(element.value, min + increment, testid + " increase 1"); |
michael@0 | 254 | element.increase(); |
michael@0 | 255 | is(element.value, max, testid + " increase 2"); |
michael@0 | 256 | element.decrease(); |
michael@0 | 257 | is(element.value, max - increment, testid + " decrease 1"); |
michael@0 | 258 | element.decrease(); |
michael@0 | 259 | is(element.value, min, testid + " decrease 2"); |
michael@0 | 260 | |
michael@0 | 261 | // check the increasePage and decreasePage methods |
michael@0 | 262 | element.pageIncrement = pageIncrement; |
michael@0 | 263 | element.increasePage(); |
michael@0 | 264 | is(element.value, min + pageIncrement, testid + " increasePage 1"); |
michael@0 | 265 | element.increasePage(); |
michael@0 | 266 | is(element.value, max, testid + " increasePage 2"); |
michael@0 | 267 | element.decreasePage(); |
michael@0 | 268 | is(element.value, max - pageIncrement, testid + " decreasePage 1"); |
michael@0 | 269 | element.decreasePage(); |
michael@0 | 270 | is(element.value, min, testid + " decreasePage 2"); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | ]]> |
michael@0 | 274 | |
michael@0 | 275 | </script> |
michael@0 | 276 | |
michael@0 | 277 | </window> |