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 <scale> dragging tests |
michael@0 | 6 | --> |
michael@0 | 7 | <window title="Dragging XUL scale tests" width="500" height="600" |
michael@0 | 8 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 11 | |
michael@0 | 12 | <hbox flex="1"> |
michael@0 | 13 | <scale id="scale1" orient="horizontal" flex="1" min="0" max="4" value="2"/> |
michael@0 | 14 | <scale id="scale2" orient="vertical" flex="1" min="0" max="4" value="2"/> |
michael@0 | 15 | <scale id="scale3" orient="horizontal" flex="1" movetoclick="true" min="0" max="4" value="2"/> |
michael@0 | 16 | </hbox> |
michael@0 | 17 | |
michael@0 | 18 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 19 | <p id="display"></p> |
michael@0 | 20 | <div id="content" style="display: none"> |
michael@0 | 21 | </div> |
michael@0 | 22 | <pre id="test"> |
michael@0 | 23 | </pre> |
michael@0 | 24 | </body> |
michael@0 | 25 | |
michael@0 | 26 | <script> |
michael@0 | 27 | <![CDATA[ |
michael@0 | 28 | |
michael@0 | 29 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 30 | function getThumb(aScale) { |
michael@0 | 31 | return document.getAnonymousElementByAttribute(aScale, "class", "scale-thumb"); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function sendTouch(aType, aRect, aDX, aDY, aMods) { |
michael@0 | 35 | var cwu = SpecialPowers.getDOMWindowUtils(window); |
michael@0 | 36 | var x = aRect.left + aRect.width/2 + aDX; |
michael@0 | 37 | var y = aRect.top + aRect.height/2 + aDY; |
michael@0 | 38 | if (/mouse/.test(aType)) |
michael@0 | 39 | cwu.sendMouseEvent(aType, x, y, 0, 1, aMods || 0, false); |
michael@0 | 40 | else |
michael@0 | 41 | cwu.sendTouchEvent(aType, [0], [x], [y], [1], [1], [0], [1], 1, aMods || 0, true); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function getOffset(aScale, aDir) { |
michael@0 | 45 | var rect = aScale.getBoundingClientRect(); |
michael@0 | 46 | var d = aScale.orient == "horizontal" ? rect.width/4 : rect.height/4; |
michael@0 | 47 | switch (aDir) { |
michael@0 | 48 | case "right": return [ d, 0]; |
michael@0 | 49 | case "left": return [-1*d, 0]; |
michael@0 | 50 | case "up": return [ 0,-1*d]; |
michael@0 | 51 | case "down": return [ 0, d]; |
michael@0 | 52 | case "downleft": return [ -1*d, d]; |
michael@0 | 53 | case "upleft": return [ -1*d,-1*d]; |
michael@0 | 54 | case "downright": return [d, d]; |
michael@0 | 55 | case "upright": return [d,-1*d]; |
michael@0 | 56 | } |
michael@0 | 57 | return [0,0]; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function testTouchDragThumb(aDesc, aId, aDir, aVal1, aVal2, aMods) { |
michael@0 | 61 | info(aDesc); |
michael@0 | 62 | var scale = document.getElementById(aId); |
michael@0 | 63 | var [x,y] = getOffset(scale, aDir); |
michael@0 | 64 | |
michael@0 | 65 | sendTouch("touchstart", getThumb(scale).getBoundingClientRect(), 0, 0, aMods); |
michael@0 | 66 | is(scale.value, aVal1, "Touchstart on thumb has correct value"); |
michael@0 | 67 | sendTouch("touchmove", getThumb(scale).getBoundingClientRect(), x, y, aMods); |
michael@0 | 68 | sendTouch("touchend", getThumb(scale).getBoundingClientRect(), 0, 0, aMods); |
michael@0 | 69 | is(scale.value, aVal2, "After touch " + (aDir ? ("and drag " + aDir + " ") : "") + "on thumb, scale has correct value"); |
michael@0 | 70 | |
michael@0 | 71 | scale.value = 2; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function testMouseDragThumb(aDesc, aId, aDir, aVal1, aVal2, aMods) { |
michael@0 | 75 | info(aDesc); |
michael@0 | 76 | var scale = document.getElementById(aId); |
michael@0 | 77 | var [x,y] = getOffset(scale, aDir); |
michael@0 | 78 | |
michael@0 | 79 | sendTouch("mousedown", getThumb(scale).getBoundingClientRect(), 0, 0, aMods); |
michael@0 | 80 | is(scale.value, aVal1, "Mousedown on thumb has correct value"); |
michael@0 | 81 | sendTouch("mousemove", getThumb(scale).getBoundingClientRect(), x, y, aMods); |
michael@0 | 82 | sendTouch("mouseup", getThumb(scale).getBoundingClientRect(), 0, 0, aMods); |
michael@0 | 83 | is(scale.value, aVal2, "After mouseup " + (aDir ? ("and drag " + aDir + " ") : "") + "on thumb, scale has correct value"); |
michael@0 | 84 | |
michael@0 | 85 | scale.value = 2; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | function testTouchDragSlider(aDesc, aId, aDir, aVal1, aVal2, aMods) { |
michael@0 | 89 | info(aDesc); |
michael@0 | 90 | var scale = document.getElementById(aId); |
michael@0 | 91 | var [x,y] = getOffset(scale, aDir); |
michael@0 | 92 | |
michael@0 | 93 | sendTouch("touchstart", getThumb(scale).getBoundingClientRect(), x, y, aMods); |
michael@0 | 94 | is(scale.value, aVal1, "Touchstart on slider has correct value"); |
michael@0 | 95 | sendTouch("touchmove", getThumb(scale).getBoundingClientRect(), -x, -y, aMods); |
michael@0 | 96 | sendTouch("touchend", getThumb(scale).getBoundingClientRect(), 0, 0, aMods); |
michael@0 | 97 | is(scale.value, aVal2, "After touch " + (aDir ? ("and drag " + aDir + " ") : "") + "on slider, scale has correct value"); |
michael@0 | 98 | |
michael@0 | 99 | scale.value = 2; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function testMouseDragSlider(aDesc, aId, aDir, aVal1, aVal2, aMods) { |
michael@0 | 103 | info(aDesc); |
michael@0 | 104 | var scale = document.getElementById(aId); |
michael@0 | 105 | var [x,y] = getOffset(scale, aDir); |
michael@0 | 106 | |
michael@0 | 107 | sendTouch("mousedown", getThumb(scale).getBoundingClientRect(), x, y, aMods); |
michael@0 | 108 | is(scale.value, aVal1, "Mousedown on slider has correct value"); |
michael@0 | 109 | sendTouch("mousemove", getThumb(scale).getBoundingClientRect(), -x, -y, aMods); |
michael@0 | 110 | sendTouch("mouseup", getThumb(scale).getBoundingClientRect(), 0, 0, aMods); |
michael@0 | 111 | is(scale.value, aVal2, "After mouseup " + (aDir ? ("and drag " + aDir + " ") : "") + "on slider, scale has correct value"); |
michael@0 | 112 | |
michael@0 | 113 | scale.value = 2; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function runTests() { |
michael@0 | 117 | // test dragging a horizontal slider with touch events by tapping on the thumb |
michael@0 | 118 | testTouchDragThumb("Touch Horizontal Thumb", "scale1", "", 2, 2); |
michael@0 | 119 | testTouchDragThumb("TouchDrag Horizontal Thumb Left", "scale1", "left", 2, 1); |
michael@0 | 120 | testTouchDragThumb("TouchDrag Horizontal Thumb Right", "scale1", "right", 2, 3); |
michael@0 | 121 | testTouchDragThumb("TouchDrag Horizontal Thumb Up", "scale1", "up", 2, 2); |
michael@0 | 122 | testTouchDragThumb("TouchDrag Horizontal Thumb Down", "scale1", "down", 2, 2); |
michael@0 | 123 | testTouchDragThumb("TouchDrag Horizontal Thumb Downleft", "scale1", "downleft", 2, 1); |
michael@0 | 124 | testTouchDragThumb("TouchDrag Horizontal Thumb Upleft", "scale1", "upleft", 2, 1); |
michael@0 | 125 | testTouchDragThumb("TouchDrag Horizontal Thumb Upright", "scale1", "upright", 2, 3); |
michael@0 | 126 | testTouchDragThumb("TouchDrag Horizontal Thumb Downright", "scale1", "downright", 2, 3); |
michael@0 | 127 | |
michael@0 | 128 | // test dragging a horizontal slider with mouse events by clicking on the thumb |
michael@0 | 129 | testMouseDragThumb("Click Horizontal Thumb", "scale1", "", 2, 2); |
michael@0 | 130 | testMouseDragThumb("MouseDrag Horizontal Thumb Left", "scale1", "left", 2, 1); |
michael@0 | 131 | testMouseDragThumb("MouseDrag Horizontal Thumb Right", "scale1", "right", 2, 3); |
michael@0 | 132 | testMouseDragThumb("MouseDrag Horizontal Thumb Up", "scale1", "up", 2, 2); |
michael@0 | 133 | testMouseDragThumb("MouseDrag Horizontal Thumb Down", "scale1", "down", 2, 2); |
michael@0 | 134 | testMouseDragThumb("MouseDrag Horizontal Thumb Downleft", "scale1", "downleft", 2, 1); |
michael@0 | 135 | testMouseDragThumb("MouseDrag Horizontal Thumb Upleft", "scale1", "upleft", 2, 1); |
michael@0 | 136 | testMouseDragThumb("MouseDrag Horizontal Thumb Upright", "scale1", "upright", 2, 3); |
michael@0 | 137 | testMouseDragThumb("MouseDrag Horizontal Thumb Downright", "scale1", "downright", 2, 3); |
michael@0 | 138 | |
michael@0 | 139 | // test dragging a vertical slider with touch events by tapping on the thumb |
michael@0 | 140 | testTouchDragThumb("Touch Vertical Thumb", "scale2", "", 2, 2); |
michael@0 | 141 | testTouchDragThumb("TouchDrag Vertical Thumb Left", "scale2", "left", 2, 2); |
michael@0 | 142 | testTouchDragThumb("TouchDrag Vertical Thumb Right", "scale2", "right", 2, 2); |
michael@0 | 143 | testTouchDragThumb("TouchDrag Vertical Thumb Up", "scale2", "up", 2, 1); |
michael@0 | 144 | testTouchDragThumb("TouchDrag Vertical Thumb Down", "scale2", "down", 2, 3); |
michael@0 | 145 | testTouchDragThumb("TouchDrag Vertical Thumb Downleft", "scale2", "downleft", 2, 3); |
michael@0 | 146 | testTouchDragThumb("TouchDrag Vertical Thumb Upleft", "scale2", "upleft", 2, 1); |
michael@0 | 147 | testTouchDragThumb("TouchDrag Vertical Thumb Upright", "scale2", "upright", 2, 1); |
michael@0 | 148 | testTouchDragThumb("TouchDrag Vertical Thumb Downright", "scale2", "downright", 2, 3); |
michael@0 | 149 | |
michael@0 | 150 | // test dragging a vertical slider with mouse events by clicking on the thumb |
michael@0 | 151 | testMouseDragThumb("Click Vertical Thumb", "scale2", "", 2, 2); |
michael@0 | 152 | testMouseDragThumb("MouseDrag Vertical Thumb Left", "scale2", "left", 2, 2); |
michael@0 | 153 | testMouseDragThumb("MouseDrag Vertical Thumb Right", "scale2", "right", 2, 2); |
michael@0 | 154 | testMouseDragThumb("MouseDrag Vertical Thumb Up", "scale2", "up", 2, 1); |
michael@0 | 155 | testMouseDragThumb("MouseDrag Vertical Thumb Down", "scale2", "down", 2, 3); |
michael@0 | 156 | testMouseDragThumb("MouseDrag Vertical Thumb Downleft", "scale2", "downleft", 2, 3); |
michael@0 | 157 | testMouseDragThumb("MouseDrag Vertical Thumb Upleft", "scale2", "upleft", 2, 1); |
michael@0 | 158 | testMouseDragThumb("MouseDrag Vertical Thumb Upright", "scale2", "upright", 2, 1); |
michael@0 | 159 | testMouseDragThumb("MouseDrag Vertical Thumb Downright", "scale2", "downright", 2, 3); |
michael@0 | 160 | |
michael@0 | 161 | var isMac = /Mac/.test(navigator.platform); |
michael@0 | 162 | |
michael@0 | 163 | // test dragging a slider by tapping off the thumb |
michael@0 | 164 | testTouchDragSlider("TouchDrag Slider Left", "scale1", "left", isMac ? 1 : 0, isMac ? 2 : 0); |
michael@0 | 165 | testTouchDragSlider("TouchDrag Slider Right", "scale1", "right", isMac ? 3 : 4, isMac ? 2 : 4); |
michael@0 | 166 | testMouseDragSlider("MouseDrag Slider Left", "scale1", "left", isMac ? 1 : 0, isMac ? 2 : 0); |
michael@0 | 167 | testMouseDragSlider("MouseDrag Slider Right", "scale1", "right", isMac ? 3 : 4, isMac ? 2 : 4); |
michael@0 | 168 | |
michael@0 | 169 | // test dragging a slider by tapping off the thumb and holding shift |
michael@0 | 170 | // modifiers don't affect touch events |
michael@0 | 171 | var mods = /Mac/.test(navigator.platform) ? Components.interfaces.nsIDOMNSEvent.ALT_MASK : |
michael@0 | 172 | Components.interfaces.nsIDOMNSEvent.SHIFT_MASK; |
michael@0 | 173 | testTouchDragSlider("TouchDrag Slider Left+Shift", "scale1", "left", isMac ? 1 : 0, isMac ? 2 : 0, mods); |
michael@0 | 174 | testTouchDragSlider("TouchDrag Slider Right+Shift", "scale1", "right", isMac ? 3 : 4, isMac ? 2 : 4, mods); |
michael@0 | 175 | testMouseDragSlider("MouseDrag Slider Left+Shift", "scale1", "left", isMac ? 0 : 1, isMac ? 0 : 2, mods); |
michael@0 | 176 | testMouseDragSlider("MouseDrag Slider Right+Shift", "scale1", "right", isMac ? 4 : 3, isMac ? 4 : 2, mods); |
michael@0 | 177 | |
michael@0 | 178 | // test dragging a slider with movetoclick="true" by tapping off the thumb |
michael@0 | 179 | testTouchDragSlider("TouchDrag Slider Left+MoveToClick", "scale3", "left", 1, 2); |
michael@0 | 180 | testTouchDragSlider("TouchDrag Slider Right+MoveToClick", "scale3", "right", 3, 2); |
michael@0 | 181 | testMouseDragSlider("MouseDrag Slider Left+MoveToClick", "scale3", "left", 1, 2); |
michael@0 | 182 | testMouseDragSlider("MouseDrag Slider Right+MoveToClick", "scale3", "right", 3, 2); |
michael@0 | 183 | |
michael@0 | 184 | // test dragging a slider by tapping off the thumb and holding shift |
michael@0 | 185 | // modifiers don't affect touch events |
michael@0 | 186 | testTouchDragSlider("MouseDrag Slider Left+MoveToClick+Shift", "scale3", "left", 1, 2, mods); |
michael@0 | 187 | testTouchDragSlider("MouseDrag Slider Right+MoveToClick+Shift", "scale3", "right", 3, 2, mods); |
michael@0 | 188 | testMouseDragSlider("MouseDrag Slider Left+MoveToClick+Shift", "scale3", "left", 0, 0, mods); |
michael@0 | 189 | testMouseDragSlider("MouseDrag Slider Right+MoveToClick+Shift", "scale3", "right", 4, 4, mods); |
michael@0 | 190 | |
michael@0 | 191 | SimpleTest.finish(); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | addLoadEvent(function() { SimpleTest.executeSoon(runTests); }); |
michael@0 | 195 | ]]></script> |
michael@0 | 196 | |
michael@0 | 197 | </window> |