|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=317422 |
|
6 --> |
|
7 <window title="Mozilla Bug 317422" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
11 |
|
12 <style xmlns="http://www.w3.org/1999/xhtml"> |
|
13 /* This makes the richlistbox about 4.5 rows high */ |
|
14 richlistitem { |
|
15 height: 30px; |
|
16 } |
|
17 richlistbox { |
|
18 height: 135px; |
|
19 } |
|
20 </style> |
|
21 |
|
22 <!-- test results are displayed in the html:body --> |
|
23 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
24 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=317422" |
|
25 target="_blank">Mozilla Bug 317422</a> |
|
26 </body> |
|
27 |
|
28 <richlistbox id="richlistbox" seltype="multiple"> |
|
29 <richlistitem id="richlistbox_item1"><label value="Item 1"/></richlistitem> |
|
30 <richlistitem id="richlistbox_item2"><label value="Item 2"/></richlistitem> |
|
31 <richlistitem id="richlistbox_item3" hidden="true"><label value="Item 3"/></richlistitem> |
|
32 <richlistitem id="richlistbox_item4"><label value="Item 4"/></richlistitem> |
|
33 <richlistitem id="richlistbox_item5" collapsed="true"><label value="Item 5"/></richlistitem> |
|
34 <richlistitem id="richlistbox_item6"><label value="Item 6"/></richlistitem> |
|
35 <richlistitem id="richlistbox_item7"><label value="Item 7"/></richlistitem> |
|
36 <richlistitem id="richlistbox_item8"><label value="Item 8"/></richlistitem> |
|
37 <richlistitem id="richlistbox_item9"><label value="Item 9"/></richlistitem> |
|
38 <richlistitem id="richlistbox_item10"><label value="Item 10"/></richlistitem> |
|
39 <richlistitem id="richlistbox_item11"><label value="Item 11"/></richlistitem> |
|
40 <richlistitem id="richlistbox_item12"><label value="Item 12"/></richlistitem> |
|
41 <richlistitem id="richlistbox_item13"><label value="Item 13"/></richlistitem> |
|
42 <richlistitem id="richlistbox_item14"><label value="Item 14"/></richlistitem> |
|
43 <richlistitem id="richlistbox_item15" hidden="true"><label value="Item 15"/></richlistitem> |
|
44 </richlistbox> |
|
45 |
|
46 <listbox id="listbox" seltype="multiple" rows="5"> |
|
47 <listitem id="listbox_item1" label="Item 1"/> |
|
48 <listitem id="listbox_item2" label="Item 2"/> |
|
49 <listitem id="listbox_item3" label="Item 3" hidden="true"/> |
|
50 <listitem id="listbox_item4" label="Item 4"/> |
|
51 <listitem id="listbox_item5" label="Item 5" hidden="true"/> |
|
52 <listitem id="listbox_item6" label="Item 6"/> |
|
53 <listitem id="listbox_item7" label="Item 7"/> |
|
54 <listitem id="listbox_item8" label="Item 8"/> |
|
55 <listitem id="listbox_item9" label="Item 9"/> |
|
56 <listitem id="listbox_item10" label="Item 10"/> |
|
57 <listitem id="listbox_item11" label="Item 11"/> |
|
58 <listitem id="listbox_item12" label="Item 12"/> |
|
59 <listitem id="listbox_item13" label="Item 13"/> |
|
60 <listitem id="listbox_item14" label="Item 14"/> |
|
61 <listitem id="listbox_item15" label="Item 15" hidden="true"/> |
|
62 </listbox> |
|
63 |
|
64 <!-- test code goes here --> |
|
65 <script type="application/javascript"><![CDATA[ |
|
66 |
|
67 /** Test for Bug 317422 **/ |
|
68 SimpleTest.waitForExplicitFinish(); |
|
69 |
|
70 function testRichlistbox() |
|
71 { |
|
72 var id = "richlistbox"; |
|
73 var listbox = document.getElementById(id); |
|
74 listbox.focus(); |
|
75 listbox.selectedIndex = 0; |
|
76 sendKey("PAGE_DOWN"); |
|
77 is(listbox.selectedItem.id, id + "_item7", id + ": Page down should go to the item one visible page away"); |
|
78 is(listbox.getIndexOfFirstVisibleRow(), 6, id + ": Page down should have scrolled down a visible page"); |
|
79 sendKey("PAGE_DOWN"); |
|
80 is(listbox.selectedItem.id, id + "_item11", id + ": Second page down should go to the item two visible pages away"); |
|
81 is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Second page down should not scroll beyond the end"); |
|
82 sendKey("PAGE_DOWN"); |
|
83 is(listbox.selectedItem.id, id + "_item14", id + ": Third page down should go to the last visible item"); |
|
84 is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Third page down should not have scrolled at all"); |
|
85 sendKey("PAGE_UP"); |
|
86 is(listbox.selectedItem.id, id + "_item10", id + ": Page up should go to the item one visible page away"); |
|
87 is(listbox.getIndexOfFirstVisibleRow(), 5, id + ": Page up should scroll up a visible page"); |
|
88 sendKey("PAGE_UP"); |
|
89 is(listbox.selectedItem.id, id + "_item6", id + ": Second page up should go to the item two visible pages away"); |
|
90 is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Second page up should not scroll beyond the start"); |
|
91 sendKey("PAGE_UP"); |
|
92 is(listbox.selectedItem.id, id + "_item1", id + ": Third page up should return to the first visible item"); |
|
93 is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Third page up should not have scrolled at all"); |
|
94 } |
|
95 |
|
96 function testListbox() |
|
97 { |
|
98 var id = "listbox"; |
|
99 var listbox = document.getElementById(id); |
|
100 |
|
101 if (!window.matchMedia("(-moz-overlay-scrollbars)").matches) { |
|
102 // Check that a scrollbar is visible by comparing the width of the listitem |
|
103 // with the width of the listbox. This is a simple way to do this without |
|
104 // checking the anonymous content. |
|
105 ok(listbox.firstChild.getBoundingClientRect().width < listbox.getBoundingClientRect().width - 10, |
|
106 id + ": Scrollbar visible"); |
|
107 } |
|
108 |
|
109 var rowHeight = listbox.firstChild.getBoundingClientRect().height; |
|
110 |
|
111 listbox.focus(); |
|
112 listbox.selectedIndex = 0; |
|
113 sendKey("PAGE_DOWN"); |
|
114 is(listbox.selectedItem.id, id + "_item8", id + ": Page down should go to the item one visible page away"); |
|
115 is(listbox.getIndexOfFirstVisibleRow(), 7, id + ": Page down should have scrolled down a visible page"); |
|
116 sendKey("PAGE_DOWN"); |
|
117 is(listbox.selectedItem.id, id + "_item13", id + ": Second page down should go to the item two visible pages away"); |
|
118 is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Second page down should not scroll beyond the end"); |
|
119 sendKey("PAGE_DOWN"); |
|
120 is(listbox.selectedItem.id, id + "_item14", id + ": Third page down should go to the last visible item"); |
|
121 is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Third page down should not have scrolled at all"); |
|
122 sendKey("PAGE_UP"); |
|
123 is(listbox.selectedItem.id, id + "_item9", id + ": Page up should go to the item one visible page away"); |
|
124 // the listScrollbox seems to go haywire when scrolling up with hidden listitems |
|
125 todo_is(listbox.getIndexOfFirstVisibleRow(), 3, id + ": Page up should scroll up a visible page"); |
|
126 sendKey("PAGE_UP"); |
|
127 is(listbox.selectedItem.id, id + "_item2", id + ": Second page up should go to the item two visible pages away"); |
|
128 is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Second page up should not scroll beyond the start"); |
|
129 sendKey("PAGE_UP"); |
|
130 is(listbox.selectedItem.id, id + "_item1", id + ": Third page up should return to the first visible item"); |
|
131 is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Third page up should not have scrolled at all"); |
|
132 |
|
133 var scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight; |
|
134 is(scrollHeight, rowHeight * 15, id + ": scrollHeight when rows set"); |
|
135 |
|
136 listbox.minHeight = 50; |
|
137 scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight; |
|
138 is(scrollHeight, rowHeight * 15, id + ": scrollHeight when rows and minimium height set"); |
|
139 |
|
140 listbox.removeAttribute("rows"); |
|
141 |
|
142 var availHeight = document.getAnonymousNodes(listbox)[1].lastChild.getBoundingClientRect().height; |
|
143 // The listbox layout adds this extra height in GetPrefSize. Not sure what it's for though. |
|
144 var e = (rowHeight * 15 - availHeight) % rowHeight; |
|
145 var extraHeight = (e == 0) ? 0 : rowHeight - e; |
|
146 |
|
147 scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight; |
|
148 is(scrollHeight, rowHeight * 15 + extraHeight, id + ": scrollHeight when minimium height set"); |
|
149 |
|
150 listbox.removeAttribute("minheight"); |
|
151 scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight; |
|
152 is(scrollHeight, rowHeight * 15 + extraHeight, id + ": scrollHeight"); |
|
153 } |
|
154 |
|
155 window.onload = function runTests() { |
|
156 testRichlistbox(); |
|
157 testListbox(); |
|
158 SimpleTest.finish(); |
|
159 }; |
|
160 ]]></script> |
|
161 </window> |