1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_scale.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,277 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 +<!-- 1.8 + XUL Widget Test for scale 1.9 + --> 1.10 +<window title="scale" width="500" height="600" 1.11 + onload="setTimeout(testtag_scale, 0);" 1.12 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.15 + 1.16 +<hbox> 1.17 + <vbox> 1.18 + <scale id="scale-horizontal-normal"/> 1.19 + <scale id="scale-horizontal-reverse" dir="reverse"/> 1.20 + </vbox> 1.21 + <scale id="scale-vertical-normal" orient="vertical"/> 1.22 + <scale id="scale-vertical-reverse" orient="vertical" dir="reverse"/> 1.23 +</hbox> 1.24 + 1.25 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.26 +<p id="display"></p> 1.27 +<div id="content" style="display: none"> 1.28 +</div> 1.29 +<pre id="test"> 1.30 +</pre> 1.31 +</body> 1.32 + 1.33 +<script> 1.34 +<![CDATA[ 1.35 + 1.36 +SimpleTest.waitForExplicitFinish(); 1.37 + 1.38 +function testtag_scale() 1.39 +{ 1.40 + testtag_scale_inner("scale-horizontal-normal", true, false); 1.41 + testtag_scale_inner("scale-horizontal-reverse", true, true); 1.42 + testtag_scale_inner("scale-vertical-normal", false, false); 1.43 + testtag_scale_inner("scale-vertical-reverse", false, true); 1.44 + 1.45 + SimpleTest.finish(); 1.46 +} 1.47 + 1.48 +function testtag_scale_inner(elementid, horiz, reverse) 1.49 +{ 1.50 + var testid = (horiz ? "horizontal " : "vertical ") + 1.51 + (reverse ? "reverse " : "normal "); 1.52 + 1.53 + var element = document.getElementById(elementid); 1.54 + 1.55 + testtag_scale_States(element, 0, "", 0, 100, testid + "initial"); 1.56 + 1.57 + element.min = 0; 1.58 + element.max = 10; 1.59 + testtag_scale_States(element, 0, "", 0, 10, testid + "first set"); 1.60 + 1.61 + element.decrease(); 1.62 + is(element.value, 0, testid + "decrease"); 1.63 + element.increase(); 1.64 + is(element.value, 1, testid + "increase"); 1.65 + element.value = 0; 1.66 + is(element.value, 0, testid + "set value"); 1.67 + 1.68 + testtag_scale_Increments(element, 0, 10, 6, 7, testid + "increase decrease"); 1.69 + 1.70 + // check if changing the min and max adjusts the value to fit in range 1.71 + element.min = 5; 1.72 + testtag_scale_States(element, 5, "5", 5, 10, testid + "change min"); 1.73 + element.value = 15; 1.74 + is(element.value, 10, testid + "change minmax value set too high"); 1.75 + element.max = 8; 1.76 + is(element.value, 8, testid + "change max"); 1.77 + element.value = 2; 1.78 + is(element.value, 5, testid + "change minmax set too low"); 1.79 + 1.80 + // check negative values 1.81 + element.min = -15; 1.82 + element.max = -5; 1.83 + testtag_scale_States(element, -5, "-5", -15, -5, testid + "minmax negative"); 1.84 + element.value = -15; 1.85 + is(element.value, -15, testid + "change max negative"); 1.86 + testtag_scale_Increments(element, -15, -5, 7, 8, testid + "increase decrease negative"); 1.87 + 1.88 + // check case when min is negative and max is positive 1.89 + element.min = -10; 1.90 + element.max = 35; 1.91 + testtag_scale_States(element, -10, "-10", -10, 35, testid + "minmax mixed sign"); 1.92 + testtag_scale_Increments(element, -10, 35, 25, 30, testid + "increase decrease mixed sign"); 1.93 + 1.94 + testtag_scale_UI(element, testid, horiz, reverse); 1.95 +} 1.96 + 1.97 +function testtag_scale_UI(element, testid, horiz, reverse) 1.98 +{ 1.99 + element.min = 0; 1.100 + element.max = 20; 1.101 + element.value = 7; 1.102 + element.increment = 2; 1.103 + element.pageIncrement = 4; 1.104 + 1.105 + element.focus(); 1.106 + 1.107 + var leftIncrements = horiz && reverse; 1.108 + var upDecrements = !horiz && !reverse; 1.109 + synthesizeKeyExpectEvent("VK_LEFT", { }, element, "change", testid + "key left"); 1.110 + is(element.value, leftIncrements ? 9 : 5, testid + " key left"); 1.111 + synthesizeKeyExpectEvent("VK_RIGHT", { }, element, "change", testid + "key right"); 1.112 + is(element.value, 7, testid + " key right"); 1.113 + synthesizeKeyExpectEvent("VK_UP", { }, element, "change", testid + "key up"); 1.114 + is(element.value, upDecrements ? 5 : 9, testid + " key up"); 1.115 + synthesizeKeyExpectEvent("VK_DOWN", { }, element, "change", testid + "key down"); 1.116 + is(element.value, 7, testid + " key down"); 1.117 + 1.118 + synthesizeKeyExpectEvent("VK_PAGE_UP", { }, element, "change", testid + "key page up"); 1.119 + is(element.value, upDecrements ? 3 : 11, testid + " key page up"); 1.120 + synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, element, "change", testid + "key page down"); 1.121 + is(element.value, 7, testid + " key page down"); 1.122 + 1.123 + synthesizeKeyExpectEvent("VK_HOME", { }, element, "change", testid + "key home"); 1.124 + is(element.value, reverse ? 20 : 0, testid + " key home"); 1.125 + synthesizeKeyExpectEvent("VK_END", { }, element, "change", testid + "key end"); 1.126 + is(element.value, reverse ? 0 : 20, testid + " key end"); 1.127 + 1.128 + testtag_scale_UI_Mouse(element, testid, horiz, reverse, 4); 1.129 + 1.130 + element.min = 4; 1.131 + element.pageIncrement = 3; 1.132 + testtag_scale_UI_Mouse(element, testid + " with min", horiz, reverse, 3); 1.133 + 1.134 + element.pageIncrement = 30; 1.135 + testtag_scale_UI_Mouse(element, testid + " with min past", horiz, reverse, 30); 1.136 +} 1.137 + 1.138 +function testtag_scale_UI_Mouse(element, testid, horiz, reverse, pinc) 1.139 +{ 1.140 + var initial = reverse ? 8 : 12; 1.141 + var newval = initial + (reverse ? pinc : -pinc); 1.142 + var endval = initial; 1.143 + // in the pinc == 30 case, the page increment is large enough that it would 1.144 + // just cause the thumb to reach the end of the scale. Make sure that the 1.145 + // mouse click does not go past the end. 1.146 + if (pinc == 30) { 1.147 + newval = reverse ? 20 : 4; 1.148 + endval = reverse ? 4 : 20; 1.149 + } 1.150 + element.value = initial; 1.151 + 1.152 + var hmove = horiz ? 25 : 10; 1.153 + var vmove = horiz ? 10 : 25; 1.154 + 1.155 + var leftFn = function () { return reverse ? element.value < newval + 3 : element.value > newval - 3; } 1.156 + var rightFn = function () { return reverse ? element.value < endval - 3 : element.value < endval + 3; } 1.157 + 1.158 + // check that clicking the mouse on the trough moves the thumb properly 1.159 + synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=default"); 1.160 + 1.161 + if (navigator.platform.indexOf("Mac") >= 0) { 1.162 + if (pinc == 30) 1.163 + ok(element.value > 4, testid + " mouse on left movetoclick=default"); 1.164 + else 1.165 + ok(leftFn, testid + " mouse on left movetoclick=default"); 1.166 + } 1.167 + else { 1.168 + is(element.value, newval, testid + " mouse on left movetoclick=default"); 1.169 + } 1.170 + 1.171 + var rect = element.getBoundingClientRect(); 1.172 + synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, 1.173 + rect.bottom - rect.top - vmove, { }, 1.174 + element, "change", testid + " mouse on right movetoclick=default"); 1.175 + 1.176 + if (navigator.platform.indexOf("Mac") >= 0) { 1.177 + if (pinc == 30) 1.178 + ok(element.value < 20, testid + " mouse on right movetoclick=default"); 1.179 + else 1.180 + ok(rightFn, testid + " mouse on right movetoclick=default"); 1.181 + } 1.182 + else { 1.183 + is(element.value, endval, testid + " mouse on right movetoclick=default"); 1.184 + } 1.185 + 1.186 + element.setAttribute("movetoclick", "true"); 1.187 + element.value = initial; 1.188 + 1.189 + synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=true"); 1.190 + if (pinc == 30) 1.191 + ok(element.value > 4, testid + " mouse on left movetoclick=true"); 1.192 + else 1.193 + ok(leftFn, testid + " mouse on left movetoclick=true"); 1.194 + 1.195 + var rect = element.getBoundingClientRect(); 1.196 + synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, 1.197 + rect.bottom - rect.top - vmove, { }, 1.198 + element, "change", testid + " mouse on right movetoclick=true"); 1.199 + if (pinc == 30) 1.200 + ok(element.value < 20, testid + " mouse on right movetoclick=true"); 1.201 + else 1.202 + ok(rightFn, testid + " mouse on right movetoclick=true"); 1.203 + 1.204 + element.setAttribute("movetoclick", "false"); 1.205 + element.value = initial; 1.206 + 1.207 + synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=false"); 1.208 + is(element.value, newval, testid + " mouse on left movetoclick=false"); 1.209 + 1.210 + var rect = element.getBoundingClientRect(); 1.211 + synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, 1.212 + rect.bottom - rect.top - vmove, { }, 1.213 + element, "change", testid + " mouse on right movetoclick=false"); 1.214 + is(element.value, endval, testid + " mouse on right movetoclick=false"); 1.215 + 1.216 + element.removeAttribute("movetoclick"); 1.217 + 1.218 + element.value = reverse ? element.max : element.min; 1.219 + 1.220 + synthesizeMouse(element, 8, 8, { type: "mousedown" }); 1.221 + synthesizeMouse(element, horiz ? 2000 : 8, horiz ? 8 : 2000, { type: "mousemove" }); 1.222 + is(element.value, reverse ? element.min : element.max, testid + " move mouse too far after end"); 1.223 + synthesizeMouse(element, 2, 2, { type: "mouseup" }); 1.224 + 1.225 + synthesizeMouse(element, rect.width - 8, rect.height - 8, { type: "mousedown" }); 1.226 + synthesizeMouse(element, horiz ? -2000 : rect.width - 8, horiz ? rect.height - 8 : -2000, { type: "mousemove" }); 1.227 + is(element.value, reverse ? element.max : element.min, testid + " move mouse too far before start"); 1.228 + 1.229 + synthesizeMouse(element, 2, 2, { type: "mouseup" }); 1.230 + 1.231 + // now check if moving outside in both directions works. On Windows, 1.232 + // it should snap back to the original location. 1.233 + element.value = reverse ? element.max : element.min; 1.234 + 1.235 + var expected = (navigator.platform.indexOf("Win") >= 0) ? element.value : 1.236 + (reverse ? element.min : element.max); 1.237 + synthesizeMouse(element, 7, 7, { type: "mousedown" }); 1.238 + synthesizeMouse(element, 2000, 2000, { type: "mousemove" }); 1.239 + is(element.value, expected, testid + " move mouse ouside in both directions"); 1.240 + synthesizeMouse(element, 2, 2, { type: "mouseup" }); 1.241 +} 1.242 + 1.243 +function testtag_scale_States(element, evalue, evalueattr, emin, emax, testid) 1.244 +{ 1.245 + is(element.getAttribute("value"), evalueattr, testid + " value attribute"); 1.246 + is(element.value, evalue, testid + " value"); 1.247 + is(element.min, emin, testid + " min"); 1.248 + is(element.max, emax, testid + " max"); 1.249 +} 1.250 + 1.251 +function testtag_scale_Increments(element, min, max, increment, pageIncrement, testid) 1.252 +{ 1.253 + // check the increase and decrease methods 1.254 + element.increment = increment; 1.255 + element.increase(); 1.256 + is(element.value, min + increment, testid + " increase 1"); 1.257 + element.increase(); 1.258 + is(element.value, max, testid + " increase 2"); 1.259 + element.decrease(); 1.260 + is(element.value, max - increment, testid + " decrease 1"); 1.261 + element.decrease(); 1.262 + is(element.value, min, testid + " decrease 2"); 1.263 + 1.264 + // check the increasePage and decreasePage methods 1.265 + element.pageIncrement = pageIncrement; 1.266 + element.increasePage(); 1.267 + is(element.value, min + pageIncrement, testid + " increasePage 1"); 1.268 + element.increasePage(); 1.269 + is(element.value, max, testid + " increasePage 2"); 1.270 + element.decreasePage(); 1.271 + is(element.value, max - pageIncrement, testid + " decreasePage 1"); 1.272 + element.decreasePage(); 1.273 + is(element.value, min, testid + " decreasePage 2"); 1.274 +} 1.275 + 1.276 +]]> 1.277 + 1.278 +</script> 1.279 + 1.280 +</window>