toolkit/content/tests/chrome/test_hiddenitems.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_hiddenitems.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     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 +  <!-- test results are displayed in the html:body -->
    1.16 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.17 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=317422"
    1.18 +     target="_blank">Mozilla Bug 317422</a>
    1.19 +  </body>
    1.20 +
    1.21 +  <richlistbox id="richlistbox" seltype="multiple">
    1.22 +    <richlistitem id="richlistbox_item1"><label value="Item 1"/></richlistitem>
    1.23 +    <richlistitem id="richlistbox_item2"><label value="Item 2"/></richlistitem>
    1.24 +    <richlistitem id="richlistbox_item3" hidden="true"><label value="Item 3"/></richlistitem>
    1.25 +    <richlistitem id="richlistbox_item4"><label value="Item 4"/></richlistitem>
    1.26 +    <richlistitem id="richlistbox_item5" collapsed="true"><label value="Item 5"/></richlistitem>
    1.27 +    <richlistitem id="richlistbox_item6"><label value="Item 6"/></richlistitem>
    1.28 +    <richlistitem id="richlistbox_item7" hidden="true"><label value="Item 7"/></richlistitem>
    1.29 +  </richlistbox>
    1.30 +  
    1.31 +  <listbox id="listbox" seltype="multiple">
    1.32 +    <listitem id="listbox_item1" label="Item 1"/>
    1.33 +    <listitem id="listbox_item2" label="Item 2"/>
    1.34 +    <listitem id="listbox_item3" label="Item 3" hidden="true"/>
    1.35 +    <listitem id="listbox_item4" label="Item 4"/>
    1.36 +    <listitem id="listbox_item5" label="Item 5" collapsed="true"/>
    1.37 +    <listitem id="listbox_item6" label="Item 6"/>
    1.38 +    <listitem id="listbox_item7" label="Item 7" hidden="true"/>
    1.39 +  </listbox>
    1.40 +  
    1.41 +  <!-- test code goes here -->
    1.42 +  <script type="application/javascript"><![CDATA[
    1.43 +
    1.44 +/** Test for Bug 317422 **/
    1.45 +SimpleTest.waitForExplicitFinish();
    1.46 +
    1.47 +function testListbox(id)
    1.48 +{
    1.49 +  var listbox = document.getElementById(id);
    1.50 +  listbox.focus();
    1.51 +  is(listbox.getRowCount(), 7, id + ": Returned the wrong number of rows");
    1.52 +  is(listbox.getItemAtIndex(2).id, id + "_item3", id + ": Should still return hidden items");
    1.53 +  listbox.selectedIndex = 0;
    1.54 +  is(listbox.selectedItem.id, id + "_item1", id + ": First item was not selected");
    1.55 +  sendKey("DOWN");
    1.56 +  is(listbox.selectedItem.id, id + "_item2", id + ": Down didn't move to second item");
    1.57 +  sendKey("DOWN");
    1.58 +  is(listbox.selectedItem.id, id + "_item4", id + ": Down didn't skip hidden item");
    1.59 +  sendKey("DOWN");
    1.60 +  is(listbox.selectedItem.id, id + "_item6", id + ": Down didn't skip collapsed item");
    1.61 +  sendKey("UP");
    1.62 +  is(listbox.selectedItem.id, id + "_item4", id + ": Up didn't skip collapsed item");
    1.63 +  sendKey("UP");
    1.64 +  is(listbox.selectedItem.id, id + "_item2", id + ": Up didn't skip hidden item");
    1.65 +  listbox.selectAll();
    1.66 +  is(listbox.selectedItems.length, 7, id + ": Should have still selected all items");
    1.67 +  listbox.invertSelection();
    1.68 +  is(listbox.selectedItems.length, 0, id + ": Should have unselected all items");
    1.69 +  listbox.selectedIndex = 2;
    1.70 +  ok(listbox.selectedItem == listbox.getItemAtIndex(2), id + ": Should have selected the hidden item");
    1.71 +  listbox.selectedIndex = 0;
    1.72 +  sendKey("END");
    1.73 +  is(listbox.selectedItem.id, id + "_item6", id + ": Should have moved to the last unhidden item");
    1.74 +  sendMouseEvent({type: 'click'}, id + "_item1");
    1.75 +  ok(listbox.selectedItem == listbox.getItemAtIndex(0), id + ": Should have selected the first item");
    1.76 +  is(listbox.selectedItems.length, 1, id + ": Should only be one selected item");
    1.77 +  sendMouseEvent({type: 'click', shiftKey: true}, id + "_item6");
    1.78 +  is(listbox.selectedItems.length, 4, id + ": Should have selected all visible items");
    1.79 +  listbox.selectedIndex = 0;
    1.80 +  sendKey("PAGE_DOWN");
    1.81 +  is(listbox.selectedItem.id, id + "_item6", id + ": Page down should go to the last visible item");
    1.82 +  sendKey("PAGE_UP");
    1.83 +  is(listbox.selectedItem.id, id + "_item1", id + ": Page up should go to the first visible item");
    1.84 +}
    1.85 +
    1.86 +window.onload = function runTests() {
    1.87 +  testListbox("richlistbox");
    1.88 +  testListbox("listbox");
    1.89 +  SimpleTest.finish();
    1.90 +};
    1.91 +  ]]></script>
    1.92 +</window>

mercurial