toolkit/content/tests/chrome/test_hiddenpaging.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_hiddenpaging.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     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 +https://bugzilla.mozilla.org/show_bug.cgi?id=317422
     1.9 +-->
    1.10 +<window title="Mozilla Bug 317422"
    1.11 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.14 +
    1.15 +  <style xmlns="http://www.w3.org/1999/xhtml">
    1.16 +    /* This makes the richlistbox about 4.5 rows high */
    1.17 +    richlistitem {
    1.18 +      height: 30px;
    1.19 +    }
    1.20 +    richlistbox {
    1.21 +      height: 135px;
    1.22 +    }
    1.23 +  </style>
    1.24 +  
    1.25 +  <!-- test results are displayed in the html:body -->
    1.26 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.27 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=317422"
    1.28 +     target="_blank">Mozilla Bug 317422</a>
    1.29 +  </body>
    1.30 +
    1.31 +  <richlistbox id="richlistbox" seltype="multiple">
    1.32 +    <richlistitem id="richlistbox_item1"><label value="Item 1"/></richlistitem>
    1.33 +    <richlistitem id="richlistbox_item2"><label value="Item 2"/></richlistitem>
    1.34 +    <richlistitem id="richlistbox_item3" hidden="true"><label value="Item 3"/></richlistitem>
    1.35 +    <richlistitem id="richlistbox_item4"><label value="Item 4"/></richlistitem>
    1.36 +    <richlistitem id="richlistbox_item5" collapsed="true"><label value="Item 5"/></richlistitem>
    1.37 +    <richlistitem id="richlistbox_item6"><label value="Item 6"/></richlistitem>
    1.38 +    <richlistitem id="richlistbox_item7"><label value="Item 7"/></richlistitem>
    1.39 +    <richlistitem id="richlistbox_item8"><label value="Item 8"/></richlistitem>
    1.40 +    <richlistitem id="richlistbox_item9"><label value="Item 9"/></richlistitem>
    1.41 +    <richlistitem id="richlistbox_item10"><label value="Item 10"/></richlistitem>
    1.42 +    <richlistitem id="richlistbox_item11"><label value="Item 11"/></richlistitem>
    1.43 +    <richlistitem id="richlistbox_item12"><label value="Item 12"/></richlistitem>
    1.44 +    <richlistitem id="richlistbox_item13"><label value="Item 13"/></richlistitem>
    1.45 +    <richlistitem id="richlistbox_item14"><label value="Item 14"/></richlistitem>
    1.46 +    <richlistitem id="richlistbox_item15" hidden="true"><label value="Item 15"/></richlistitem>
    1.47 +  </richlistbox>
    1.48 +  
    1.49 +  <listbox id="listbox" seltype="multiple" rows="5">
    1.50 +    <listitem id="listbox_item1" label="Item 1"/>
    1.51 +    <listitem id="listbox_item2" label="Item 2"/>
    1.52 +    <listitem id="listbox_item3" label="Item 3" hidden="true"/>
    1.53 +    <listitem id="listbox_item4" label="Item 4"/>
    1.54 +    <listitem id="listbox_item5" label="Item 5" hidden="true"/>
    1.55 +    <listitem id="listbox_item6" label="Item 6"/>
    1.56 +    <listitem id="listbox_item7" label="Item 7"/>
    1.57 +    <listitem id="listbox_item8" label="Item 8"/>
    1.58 +    <listitem id="listbox_item9" label="Item 9"/>
    1.59 +    <listitem id="listbox_item10" label="Item 10"/>
    1.60 +    <listitem id="listbox_item11" label="Item 11"/>
    1.61 +    <listitem id="listbox_item12" label="Item 12"/>
    1.62 +    <listitem id="listbox_item13" label="Item 13"/>
    1.63 +    <listitem id="listbox_item14" label="Item 14"/>
    1.64 +    <listitem id="listbox_item15" label="Item 15" hidden="true"/>
    1.65 +  </listbox>
    1.66 +  
    1.67 +  <!-- test code goes here -->
    1.68 +  <script type="application/javascript"><![CDATA[
    1.69 +
    1.70 +/** Test for Bug 317422 **/
    1.71 +SimpleTest.waitForExplicitFinish();
    1.72 +
    1.73 +function testRichlistbox()
    1.74 +{
    1.75 +  var id = "richlistbox";
    1.76 +  var listbox = document.getElementById(id);
    1.77 +  listbox.focus();
    1.78 +  listbox.selectedIndex = 0;
    1.79 +  sendKey("PAGE_DOWN");
    1.80 +  is(listbox.selectedItem.id, id + "_item7", id + ": Page down should go to the item one visible page away");
    1.81 +  is(listbox.getIndexOfFirstVisibleRow(), 6, id + ": Page down should have scrolled down a visible page");
    1.82 +  sendKey("PAGE_DOWN");
    1.83 +  is(listbox.selectedItem.id, id + "_item11", id + ": Second page down should go to the item two visible pages away");
    1.84 +  is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Second page down should not scroll beyond the end");
    1.85 +  sendKey("PAGE_DOWN");
    1.86 +  is(listbox.selectedItem.id, id + "_item14", id + ": Third page down should go to the last visible item");
    1.87 +  is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Third page down should not have scrolled at all");
    1.88 +  sendKey("PAGE_UP");
    1.89 +  is(listbox.selectedItem.id, id + "_item10", id + ": Page up should go to the item one visible page away");
    1.90 +  is(listbox.getIndexOfFirstVisibleRow(), 5, id + ": Page up should scroll up a visible page");
    1.91 +  sendKey("PAGE_UP");
    1.92 +  is(listbox.selectedItem.id, id + "_item6", id + ": Second page up should go to the item two visible pages away");
    1.93 +  is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Second page up should not scroll beyond the start");
    1.94 +  sendKey("PAGE_UP");
    1.95 +  is(listbox.selectedItem.id, id + "_item1", id + ": Third page up should return to the first visible item");
    1.96 +  is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Third page up should not have scrolled at all");
    1.97 +}
    1.98 +
    1.99 +function testListbox()
   1.100 +{
   1.101 +  var id = "listbox";
   1.102 +  var listbox = document.getElementById(id);
   1.103 +
   1.104 +  if (!window.matchMedia("(-moz-overlay-scrollbars)").matches) {
   1.105 +   // Check that a scrollbar is visible by comparing the width of the listitem
   1.106 +   // with the width of the listbox. This is a simple way to do this without
   1.107 +   // checking the anonymous content.
   1.108 +   ok(listbox.firstChild.getBoundingClientRect().width < listbox.getBoundingClientRect().width - 10,
   1.109 +      id + ": Scrollbar visible");
   1.110 + }
   1.111 +
   1.112 +  var rowHeight = listbox.firstChild.getBoundingClientRect().height;
   1.113 +
   1.114 +  listbox.focus();
   1.115 +  listbox.selectedIndex = 0;
   1.116 +  sendKey("PAGE_DOWN");
   1.117 +  is(listbox.selectedItem.id, id + "_item8", id + ": Page down should go to the item one visible page away");
   1.118 +  is(listbox.getIndexOfFirstVisibleRow(), 7, id + ": Page down should have scrolled down a visible page");
   1.119 +  sendKey("PAGE_DOWN");
   1.120 +  is(listbox.selectedItem.id, id + "_item13", id + ": Second page down should go to the item two visible pages away");
   1.121 +  is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Second page down should not scroll beyond the end");
   1.122 +  sendKey("PAGE_DOWN");
   1.123 +  is(listbox.selectedItem.id, id + "_item14", id + ": Third page down should go to the last visible item");
   1.124 +  is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Third page down should not have scrolled at all");
   1.125 +  sendKey("PAGE_UP");
   1.126 +  is(listbox.selectedItem.id, id + "_item9", id + ": Page up should go to the item one visible page away");
   1.127 +  // the listScrollbox seems to go haywire when scrolling up with hidden listitems
   1.128 +  todo_is(listbox.getIndexOfFirstVisibleRow(), 3, id + ": Page up should scroll up a visible page");
   1.129 +  sendKey("PAGE_UP");
   1.130 +  is(listbox.selectedItem.id, id + "_item2", id + ": Second page up should go to the item two visible pages away");
   1.131 +  is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Second page up should not scroll beyond the start");
   1.132 +  sendKey("PAGE_UP");
   1.133 +  is(listbox.selectedItem.id, id + "_item1", id + ": Third page up should return to the first visible item");
   1.134 +  is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Third page up should not have scrolled at all");
   1.135 +
   1.136 +  var scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight;
   1.137 +  is(scrollHeight, rowHeight * 15, id + ": scrollHeight when rows set");
   1.138 +
   1.139 +  listbox.minHeight = 50;
   1.140 +  scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight;
   1.141 +  is(scrollHeight, rowHeight * 15, id + ": scrollHeight when rows and minimium height set");
   1.142 +
   1.143 +  listbox.removeAttribute("rows");
   1.144 +
   1.145 +  var availHeight = document.getAnonymousNodes(listbox)[1].lastChild.getBoundingClientRect().height;
   1.146 +  // The listbox layout adds this extra height in GetPrefSize. Not sure what it's for though.
   1.147 +  var e = (rowHeight * 15 - availHeight) % rowHeight;
   1.148 +  var extraHeight = (e == 0) ? 0 : rowHeight - e;
   1.149 +
   1.150 +  scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight;
   1.151 +  is(scrollHeight, rowHeight * 15 + extraHeight, id + ": scrollHeight when minimium height set");
   1.152 +
   1.153 +  listbox.removeAttribute("minheight");
   1.154 +  scrollHeight = document.getAnonymousNodes(listbox)[1].lastChild.scrollHeight;
   1.155 +  is(scrollHeight, rowHeight * 15 + extraHeight, id + ": scrollHeight");
   1.156 +}
   1.157 +
   1.158 +window.onload = function runTests() {
   1.159 +  testRichlistbox();
   1.160 +  testListbox();
   1.161 +  SimpleTest.finish();
   1.162 +};
   1.163 +  ]]></script>
   1.164 +</window>

mercurial