summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_menulist_paging.xul
blob: c58e0328f185ad983391b848cb190ee5ad39c005 (plain)
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
<?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(startTest, 0);"
        onpopupshown="menulistShown()" onpopuphidden="runTest()"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
  <script type="application/javascript" 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: [6, 8, 8],
                                   ups: [3, 1, 1] },
  { list: "menulist4", initial: 5, scroll: 2, downs: [], ups: [] }
];

function startTest()
{
  let popup = document.getElementById("menulist-popup1");
  let menupopupHeight = popup.getBoundingClientRect().height;
  let menuitemHeight = popup.firstChild.getBoundingClientRect().height;

  // First, set the height of each popup to the height of four menuitems plus
  // any padding and border on the menupopup.
  let height = menuitemHeight * 4 + (menupopupHeight - menuitemHeight * 10);
  popup.height = height;
  document.getElementById("menulist-popup2").height = height;
  document.getElementById("menulist-popup3").height = height;
  document.getElementById("menulist-popup4").height = height;

  runTest();
}

function runTest()
{
  if (!tests.length) {
    SimpleTest.finish();
    return;
  }

  test = tests.shift();
  document.getElementById(test.list).open = true;
}

function menulistShown()
{
  let menulist = document.getElementById(test.list);
  is(menulist.menuBoxObject.activeChild.label, menulist.getItemAtIndex(test.initial).label, test.list + " initial selection");

  let cs = window.getComputedStyle(menulist.menupopup);
  let bpTop = parseFloat(cs.paddingTop) + parseFloat(cs.borderTopWidth);

  // 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 + bpTop,
       "Popup scroll at correct position");
  }

  for (let i = 0; i < test.downs.length; i++) {
    sendKey("PAGE_DOWN");
    is(menulist.menuBoxObject.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.menuBoxObject.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>