1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/window_keys.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,192 @@ 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 +<window title="Key Tests" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.10 + 1.11 + <script type="application/javascript" 1.12 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + <script type="application/javascript" 1.14 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.15 + 1.16 +<script> 1.17 +<![CDATA[ 1.18 + 1.19 +SimpleTest.waitForExplicitFinish(); 1.20 + 1.21 +var gExpected = null; 1.22 + 1.23 +var keysToTest = [ 1.24 + ["k-v", "V", { } ], 1.25 + ["", "V", { shiftKey: true } ], 1.26 + ["k-v-scy", "V", { ctrlKey: true } ], 1.27 + ["", "V", { altKey: true } ], 1.28 + ["", "V", { metaKey: true } ], 1.29 + ["", "V", { osKey: true } ], 1.30 + ["k-v-scy", "V", { shiftKey: true, ctrlKey: true } ], 1.31 + ["", "V", { shiftKey: true, ctrlKey: true, altKey: true } ], 1.32 + ["k-e-y", "E", { } ], 1.33 + ["", "E", { shiftKey: true } ], 1.34 + ["", "E", { ctrlKey: true } ], 1.35 + ["", "E", { altKey: true } ], 1.36 + ["", "E", { metaKey: true } ], 1.37 + ["", "E", { osKey: true } ], 1.38 + ["k-d-a", "D", { altKey: true } ], 1.39 + ["k-8-m", "8", { metaKey: true } ], 1.40 + ["", "8", { metaKey: true, osKey: true } ], 1.41 + ["k-a-o", "A", { osKey: true } ], 1.42 + ["", "A", { osKey: true, metaKey: true } ], 1.43 + ["k-b-myo", "B", { osKey: true } ], 1.44 + ["k-b-myo", "B", { osKey: true, metaKey: true } ], 1.45 + ["k-f-oym", "F", { metaKey: true } ], 1.46 + ["k-f-oym", "F", { metaKey: true, osKey: true } ], 1.47 + ["k-c-scaym", "C", { metaKey: true } ], 1.48 + ["k-c-scaym", "C", { shiftKey: true, ctrlKey: true, altKey: true, metaKey: true } ], 1.49 + ["", "V", { shiftKey: true, ctrlKey: true, altKey: true } ], 1.50 + ["k-h-l", "H", { accelKey: true } ], 1.51 +// ["k-j-s", "J", { accessKey: true } ], 1.52 + ["", "T", { } ], 1.53 + ["scommand", "Y", { } ], 1.54 + ["", "U", { } ], 1.55 +]; 1.56 + 1.57 +function runTest() 1.58 +{ 1.59 + iterateKeys(true, "normal"); 1.60 + 1.61 + var keyset = document.getElementById("keyset"); 1.62 + keyset.setAttribute("disabled", "true"); 1.63 + iterateKeys(false, "disabled"); 1.64 + 1.65 + var keyset = document.getElementById("keyset"); 1.66 + keyset.removeAttribute("disabled"); 1.67 + iterateKeys(true, "reenabled"); 1.68 + 1.69 + keyset.parentNode.removeChild(keyset); 1.70 + iterateKeys(false, "removed"); 1.71 + 1.72 + document.documentElement.appendChild(keyset); 1.73 + iterateKeys(true, "appended"); 1.74 + 1.75 + var accelText = function(menuitem) menuitem.getAttribute("acceltext").toLowerCase(); 1.76 + 1.77 + $("menubutton").open = true; 1.78 + 1.79 + // now check if a menu updates its accelerator text when a key attribute is changed 1.80 + var menuitem1 = $("menuitem1"); 1.81 + ok(accelText(menuitem1).indexOf("d") >= 0, "menuitem1 accelText before"); 1.82 + if (navigator.platform.indexOf("Win") != -1) { 1.83 + ok(accelText(menuitem1).indexOf("alt") >= 0, "menuitem1 accelText modifier before"); 1.84 + } 1.85 + 1.86 + menuitem1.setAttribute("key", "k-s-c"); 1.87 + ok(accelText(menuitem1).indexOf("s") >= 0, "menuitem1 accelText after"); 1.88 + if (navigator.platform.indexOf("Win") != -1) { 1.89 + ok(accelText(menuitem1).indexOf("ctrl") >= 0, "menuitem1 accelText modifier after"); 1.90 + } 1.91 + 1.92 + menuitem1.setAttribute("acceltext", "custom"); 1.93 + is(accelText(menuitem1), "custom", "menuitem1 accelText set custom"); 1.94 + menuitem1.removeAttribute("acceltext"); 1.95 + ok(accelText(menuitem1).indexOf("s") >= 0, "menuitem1 accelText remove"); 1.96 + if (navigator.platform.indexOf("Win") != -1) { 1.97 + ok(accelText(menuitem1).indexOf("ctrl") >= 0, "menuitem1 accelText modifier remove"); 1.98 + } 1.99 + 1.100 + var menuitem2 = $("menuitem2"); 1.101 + is(accelText(menuitem2), "", "menuitem2 accelText before"); 1.102 + menuitem2.setAttribute("key", "k-s-c"); 1.103 + ok(accelText(menuitem2).indexOf("s") >= 0, "menuitem2 accelText before"); 1.104 + if (navigator.platform.indexOf("Win") != -1) { 1.105 + ok(accelText(menuitem2).indexOf("ctrl") >= 0, "menuitem2 accelText modifier before"); 1.106 + } 1.107 + 1.108 + menuitem2.setAttribute("key", "k-h-l"); 1.109 + ok(accelText(menuitem2).indexOf("h") >= 0, "menuitem2 accelText after"); 1.110 + if (navigator.platform.indexOf("Win") != -1) { 1.111 + ok(accelText(menuitem2).indexOf("ctrl") >= 0, "menuitem2 accelText modifier after"); 1.112 + } 1.113 + 1.114 + menuitem2.removeAttribute("key"); 1.115 + is(accelText(menuitem2), "", "menuitem2 accelText after remove"); 1.116 + 1.117 + $("menubutton").open = false; 1.118 + 1.119 + window.close(); 1.120 + window.opener.wrappedJSObject.SimpleTest.finish(); 1.121 +} 1.122 + 1.123 +function iterateKeys(enabled, testid) 1.124 +{ 1.125 + for (var k = 0; k < keysToTest.length; k++) { 1.126 + gExpected = keysToTest[k]; 1.127 + var expectedKey = gExpected[0]; 1.128 + if (!gExpected[2].accessKey || navigator.platform.indexOf("Mac") == -1) { 1.129 + synthesizeKey(gExpected[1], gExpected[2]); 1.130 + ok((enabled && expectedKey) || expectedKey == "k-d-a" ? 1.131 + !gExpected : gExpected, testid + " key step " + (k + 1)); 1.132 + } 1.133 + } 1.134 +} 1.135 + 1.136 +function checkKey(event) 1.137 +{ 1.138 + // the first element of the gExpected array holds the id of the <key> element 1.139 + // that was expected. If this is empty, a handler wasn't expected to be called 1.140 + if (gExpected[0]) 1.141 + is(event.originalTarget.id, gExpected[0], "key " + gExpected[1]); 1.142 + else 1.143 + is("key " + event.originalTarget.id + " was activated", "", "key " + gExpected[1]); 1.144 + gExpected = null; 1.145 +} 1.146 + 1.147 +function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); } 1.148 +function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); } 1.149 + 1.150 +SimpleTest.waitForFocus(runTest); 1.151 + 1.152 +]]> 1.153 +</script> 1.154 + 1.155 +<command id="scommand" oncommand="checkKey(event)"/> 1.156 +<command id="scommand-disabled" disabled="true"/> 1.157 + 1.158 +<keyset id="keyset"> 1.159 + <key id="k-v" key="v" oncommand="checkKey(event)"/> 1.160 + <key id="k-v-scy" key="v" modifiers="shift any control" oncommand="checkKey(event)"/> 1.161 + <key id="k-e-y" key="e" modifiers="any" oncommand="checkKey(event)"/> 1.162 + <key id="k-8-m" key="8" modifiers="meta" oncommand="checkKey(event)"/> 1.163 + <key id="k-a-o" key="a" modifiers="os" oncommand="checkKey(event)"/> 1.164 + <key id="k-b-myo" key="b" modifiers="meta any os" oncommand="checkKey(event)"/> 1.165 + <key id="k-f-oym" key="f" modifiers="os any meta" oncommand="checkKey(event)"/> 1.166 + <key id="k-c-scaym" key="c" modifiers="shift control alt any meta" oncommand="checkKey(event)"/> 1.167 + <key id="k-h-l" key="h" modifiers="accel" oncommand="checkKey(event)"/> 1.168 + <key id="k-j-s" key="j" modifiers="access" oncommand="checkKey(event)"/> 1.169 + <key id="k-t-y" disabled="true" key="t" oncommand="checkKey(event)"/> 1.170 + <key id="k-y" key="y" command="scommand"/> 1.171 + <key id="k-u" key="u" command="scommand-disabled"/> 1.172 +</keyset> 1.173 + 1.174 +<keyset id="keyset2"> 1.175 + <key id="k-d-a" key="d" modifiers="alt" oncommand="checkKey(event)"/> 1.176 + <key id="k-s-c" key="s" modifiers="control" oncommand="checkKey(event)"/> 1.177 +</keyset> 1.178 + 1.179 +<button id="menubutton" label="Menu" type="menu"> 1.180 + <menupopup> 1.181 + <menuitem id="menuitem1" label="Item 1" key="k-d-a"/> 1.182 + <menuitem id="menuitem2" label="Item 2"/> 1.183 + </menupopup> 1.184 +</button> 1.185 + 1.186 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.187 +<p id="display"> 1.188 +</p> 1.189 +<div id="content" style="display: none"> 1.190 +</div> 1.191 +<pre id="test"> 1.192 +</pre> 1.193 +</body> 1.194 + 1.195 +</window>