Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | <window title="Menulist Key Navigation Tests" |
michael@0 | 6 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 7 | |
michael@0 | 8 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | |
michael@0 | 11 | <button id="button1" label="One"/> |
michael@0 | 12 | <menulist id="list"> |
michael@0 | 13 | <menupopup id="popup" onpopupshowing="return gShowPopup;"> |
michael@0 | 14 | <menuitem id="i1" label="One"/> |
michael@0 | 15 | <menuitem id="i2" label="Two"/> |
michael@0 | 16 | <menuitem id="i2b" disabled="true" label="Two and a Half"/> |
michael@0 | 17 | <menuitem id="i3" label="Three"/> |
michael@0 | 18 | <menuitem id="i4" label="Four"/> |
michael@0 | 19 | </menupopup> |
michael@0 | 20 | </menulist> |
michael@0 | 21 | <button id="button2" label="Two"/> |
michael@0 | 22 | |
michael@0 | 23 | <script class="testbody" type="application/javascript"> |
michael@0 | 24 | <![CDATA[ |
michael@0 | 25 | |
michael@0 | 26 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 27 | |
michael@0 | 28 | var gShowPopup = false; |
michael@0 | 29 | var gModifiers = 0; |
michael@0 | 30 | |
michael@0 | 31 | var iswin = (navigator.platform.indexOf("Win") == 0); |
michael@0 | 32 | |
michael@0 | 33 | function runTests() |
michael@0 | 34 | { |
michael@0 | 35 | var list = $("list"); |
michael@0 | 36 | list.focus(); |
michael@0 | 37 | // on Mac, up and cursor keys open the menu, but on other platforms, the |
michael@0 | 38 | // cursor keys navigate between items without opening the menu |
michael@0 | 39 | if (navigator.platform.indexOf("Mac") == -1) { |
michael@0 | 40 | keyCheck(list, "VK_DOWN", 2, "cursor down"); |
michael@0 | 41 | keyCheck(list, "VK_DOWN", iswin ? "2b" : 3, "cursor down skip disabled"); |
michael@0 | 42 | keyCheck(list, "VK_UP", 2, "cursor up skip disabled"); |
michael@0 | 43 | keyCheck(list, "VK_UP", 1, "cursor up"); |
michael@0 | 44 | keyCheck(list, "VK_UP", 4, "cursor up wrap"); |
michael@0 | 45 | keyCheck(list, "VK_DOWN", 1, "cursor down wrap"); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // check that attempting to open the menulist does not change the selection |
michael@0 | 49 | synthesizeKey("VK_DOWN", { altKey: navigator.platform.indexOf("Mac") == -1 }); |
michael@0 | 50 | is(list.selectedItem, $("i1"), "open menulist down selectedItem"); |
michael@0 | 51 | synthesizeKey("VK_UP", { altKey: navigator.platform.indexOf("Mac") == -1 }); |
michael@0 | 52 | is(list.selectedItem, $("i1"), "open menulist up selectedItem"); |
michael@0 | 53 | |
michael@0 | 54 | synthesizeKey("G", { }); |
michael@0 | 55 | is(list.selectedItem, $("i1"), "letter pressed not found selectedItem"); |
michael@0 | 56 | |
michael@0 | 57 | keyCheck(list, "T", 2, "letter pressed"); |
michael@0 | 58 | keyCheck(list, "T", 2, "letter pressed"); |
michael@0 | 59 | setTimeout(pressedAgain, 1200); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function pressedAgain() |
michael@0 | 63 | { |
michael@0 | 64 | var list = $("list"); |
michael@0 | 65 | keyCheck(list, "T", iswin ? "2b" : 3, "letter pressed again"); |
michael@0 | 66 | keyCheck(list, "W", 2, "second letter pressed"); |
michael@0 | 67 | setTimeout(differentPressed, 1200); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function differentPressed() |
michael@0 | 71 | { |
michael@0 | 72 | var list = $("list"); |
michael@0 | 73 | keyCheck(list, "O", 1, "different letter pressed"); |
michael@0 | 74 | |
michael@0 | 75 | if (navigator.platform.indexOf("Mac") == -1) { |
michael@0 | 76 | $("button1").focus(); |
michael@0 | 77 | synthesizeKeyExpectEvent("VK_TAB", { }, list, "focus", "focus to menulist"); |
michael@0 | 78 | synthesizeKeyExpectEvent("VK_TAB", { }, $("button2"), "focus", "focus to button"); |
michael@0 | 79 | is(document.activeElement, $("button2"), "tab from menulist focused button"); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | // now make sure that using a key scrolls the menu correctly |
michael@0 | 83 | gShowPopup = true; |
michael@0 | 84 | |
michael@0 | 85 | for (let i = 0; i < 65; i++) { |
michael@0 | 86 | list.appendItem("Item" + i, "item" + i); |
michael@0 | 87 | } |
michael@0 | 88 | list.open = true; |
michael@0 | 89 | is(list.getBoundingClientRect().width, list.firstChild.getBoundingClientRect().width, |
michael@0 | 90 | "menu and popup width match"); |
michael@0 | 91 | var minScrollbarWidth = window.matchMedia("(-moz-overlay-scrollbars)").matches ? 0 : 3; |
michael@0 | 92 | ok(list.getBoundingClientRect().width >= list.getItemAtIndex(0).getBoundingClientRect().width + minScrollbarWidth, |
michael@0 | 93 | "menuitem width accounts for scrollbar"); |
michael@0 | 94 | list.open = false; |
michael@0 | 95 | |
michael@0 | 96 | list.menupopup.maxHeight = 100; |
michael@0 | 97 | list.open = true; |
michael@0 | 98 | |
michael@0 | 99 | var rowdiff = list.getItemAtIndex(1).getBoundingClientRect().top - |
michael@0 | 100 | list.getItemAtIndex(0).getBoundingClientRect().top; |
michael@0 | 101 | |
michael@0 | 102 | var item = list.getItemAtIndex(10); |
michael@0 | 103 | var originalPosition = item.getBoundingClientRect().top; |
michael@0 | 104 | |
michael@0 | 105 | list.menuBoxObject.activeChild = item; |
michael@0 | 106 | ok(item.getBoundingClientRect().top < originalPosition, |
michael@0 | 107 | "position of item 1: " + item.getBoundingClientRect().top + " -> " + originalPosition); |
michael@0 | 108 | |
michael@0 | 109 | originalPosition = item.getBoundingClientRect().top; |
michael@0 | 110 | |
michael@0 | 111 | synthesizeKey("VK_DOWN", { }); |
michael@0 | 112 | is(item.getBoundingClientRect().top, originalPosition - rowdiff, "position of item 10"); |
michael@0 | 113 | |
michael@0 | 114 | list.open = false; |
michael@0 | 115 | |
michael@0 | 116 | checkEnter(); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | function keyCheck(list, key, index, testname) |
michael@0 | 120 | { |
michael@0 | 121 | var item = $("i" + index); |
michael@0 | 122 | synthesizeKeyExpectEvent(key, { }, item, "command", testname); |
michael@0 | 123 | is(list.selectedItem, item, testname + " selectedItem"); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | function checkModifiers(event) |
michael@0 | 127 | { |
michael@0 | 128 | var expectedModifiers = (gModifiers == 1); |
michael@0 | 129 | is(event.shiftKey, expectedModifiers, "shift key pressed"); |
michael@0 | 130 | is(event.ctrlKey, expectedModifiers, "ctrl key pressed"); |
michael@0 | 131 | is(event.altKey, expectedModifiers, "alt key pressed"); |
michael@0 | 132 | is(event.metaKey, expectedModifiers, "meta key pressed"); |
michael@0 | 133 | gModifiers++; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | function checkEnter() |
michael@0 | 137 | { |
michael@0 | 138 | var list = $("list"); |
michael@0 | 139 | list.addEventListener("popuphidden", checkEnterWithModifiers, false); |
michael@0 | 140 | list.addEventListener("command", checkModifiers, false); |
michael@0 | 141 | list.open = true; |
michael@0 | 142 | synthesizeKey("VK_RETURN", { }); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function checkEnterWithModifiers() |
michael@0 | 146 | { |
michael@0 | 147 | is(gModifiers, 1, "modifiers checked when not set"); |
michael@0 | 148 | |
michael@0 | 149 | var list = $("list"); |
michael@0 | 150 | ok(!list.open, "list closed on enter press"); |
michael@0 | 151 | list.removeEventListener("popuphidden", checkEnterWithModifiers, false); |
michael@0 | 152 | |
michael@0 | 153 | list.addEventListener("popuphidden", done, false); |
michael@0 | 154 | list.open = true; |
michael@0 | 155 | |
michael@0 | 156 | synthesizeKey("VK_RETURN", { shiftKey: true, ctrlKey: true, altKey: true, metaKey: true }); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | function done() |
michael@0 | 160 | { |
michael@0 | 161 | is(gModifiers, 2, "modifiers checked when set"); |
michael@0 | 162 | |
michael@0 | 163 | var list = $("list"); |
michael@0 | 164 | ok(!list.open, "list closed on enter press with modifiers"); |
michael@0 | 165 | list.removeEventListener("popuphidden", done, false); |
michael@0 | 166 | |
michael@0 | 167 | SimpleTest.finish(); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | SimpleTest.waitForFocus(runTests); |
michael@0 | 171 | |
michael@0 | 172 | ]]> |
michael@0 | 173 | </script> |
michael@0 | 174 | |
michael@0 | 175 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 176 | <p id="display"> |
michael@0 | 177 | </p> |
michael@0 | 178 | <div id="content" style="display: none"> |
michael@0 | 179 | </div> |
michael@0 | 180 | <pre id="test"> |
michael@0 | 181 | </pre> |
michael@0 | 182 | </body> |
michael@0 | 183 | |
michael@0 | 184 | </window> |