1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Menulist Tests"
onload="setTimeout(runTest, 0);"
onpopupshown="menulistShown()" onpopuphidden="runTest()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<menulist id="menulist1">
<menupopup id="menulist-popup1">
<menuitem label="One"/>
<menuitem label="Two"/>
<menuitem label="Three"/>
<menuitem label="Four"/>
<menuitem label="Five"/>
<menuitem label="Six"/>
<menuitem label="Seven"/>
<menuitem label="Eight"/>
<menuitem label="Nine"/>
<menuitem label="Ten"/>
</menupopup>
</menulist>
<menulist id="menulist2">
<menupopup id="menulist-popup2">
<menuitem label="One" disabled="true"/>
<menuitem label="Two" selected="true"/>
<menuitem label="Three"/>
<menuitem label="Four"/>
<menuitem label="Five"/>
<menuitem label="Six"/>
<menuitem label="Seven"/>
<menuitem label="Eight"/>
<menuitem label="Nine"/>
<menuitem label="Ten" disabled="true"/>
</menupopup>
</menulist>
<menulist id="menulist3">
<menupopup id="menulist-popup3">
<label value="One"/>
<menuitem label="Two" selected="true"/>
<menuitem label="Three"/>
<menuitem label="Four"/>
<menuitem label="Five" disabled="true"/>
<menuitem label="Six" disabled="true"/>
<menuitem label="Seven"/>
<menuitem label="Eight"/>
<menuitem label="Nine"/>
<label value="Ten"/>
</menupopup>
</menulist>
<menulist id="menulist4">
<menupopup id="menulist-popup4">
<label value="One"/>
<menuitem label="Two"/>
<menuitem label="Three"/>
<menuitem label="Four"/>
<menuitem label="Five"/>
<menuitem label="Six" selected="true"/>
<menuitem label="Seven"/>
<menuitem label="Eight"/>
<menuitem label="Nine"/>
<label value="Ten"/>
</menupopup>
</menulist>
<script class="testbody" type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
let test;
// Fields:
// list - menulist id
// initial - initial selected index
// scroll - index of item at top of the visible scrolled area, -1 to skip this test
// downs - array of indicies that will be selected when pressing down in sequence
// ups - array of indicies that will be selected when pressing up in sequence
let tests = [
{ list: "menulist1", initial: 0, scroll: 0, downs: [3, 6, 9, 9],
ups: [6, 3, 0, 0] },
{ list: "menulist2", initial: 1, scroll: 0, downs: [4, 7, 8, 8],
ups: [5, 2, 1] },
{ list: "menulist3", initial: 1, scroll: -1, downs: [3, 6, 8, 8],
ups: [6, 3, 1] },
{ list: "menulist4", initial: 5, scroll: 2, downs: [], ups: [] }
];
let gMeasured = false;
function measureMenuItemHeightIfNeeded() {
if (gMeasured) {
return;
}
gMeasured = true;
let popup = document.getElementById("menulist-popup1");
let menuitemHeight = popup.firstChild.getBoundingClientRect().height;
let cs = window.getComputedStyle(popup);
let csArrow = window.getComputedStyle(popup.scrollBox);
let bpmTop = parseFloat(cs.paddingTop) + parseFloat(cs.borderTopWidth) +
parseFloat(csArrow.paddingTop) + parseFloat(csArrow.borderTopWidth) +
parseFloat(csArrow.marginTop);
let bpmBottom = parseFloat(cs.paddingBottom) + parseFloat(cs.borderBottomWidth) +
parseFloat(csArrow.paddingBottom) + parseFloat(csArrow.borderBottomWidth) +
parseFloat(csArrow.marginBottom);
// First, set the height of each popup to the height of four menuitems plus
// any padding / border / margin on the menupopup.
let height = menuitemHeight * 4 + bpmTop + bpmBottom;
popup.style.height = height + "px";
document.getElementById("menulist-popup2").style.height = height + "px";
document.getElementById("menulist-popup3").style.height = height + "px";
document.getElementById("menulist-popup4").style.height = height + "px";
}
function runTest() {
if (!tests.length) {
SimpleTest.finish();
return;
}
test = tests.shift();
document.getElementById(test.list).open = true;
}
function menulistShown()
{
measureMenuItemHeightIfNeeded();
let menulist = document.getElementById(test.list);
is(menulist.activeChild.label, menulist.getItemAtIndex(test.initial).label, test.list + " initial selection");
let cs = window.getComputedStyle(menulist.menupopup);
let csArrow = window.getComputedStyle(menulist.menupopup.scrollBox);
let bpmTop = parseFloat(cs.paddingTop) + parseFloat(cs.borderTopWidth) +
parseFloat(csArrow.paddingTop) + parseFloat(csArrow.borderTopWidth) +
parseFloat(csArrow.marginTop);
// Skip menulist3 as it has a label that scrolling doesn't need normally deal with.
if (test.scroll >= 0) {
is(menulist.menupopup.childNodes[test.scroll].getBoundingClientRect().top,
menulist.menupopup.getBoundingClientRect().top + bpmTop,
"Popup scroll at correct position");
}
for (let i = 0; i < test.downs.length; i++) {
sendKey("PAGE_DOWN");
is(menulist.activeChild.label, menulist.getItemAtIndex(test.downs[i]).label, test.list + " page down " + i);
}
for (let i = 0; i < test.ups.length; i++) {
sendKey("PAGE_UP");
is(menulist.activeChild.label, menulist.getItemAtIndex(test.ups[i]).label, test.list + " page up " + i);
}
menulist.open = false;
}
]]>
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>
|