toolkit/content/tests/chrome/test_menulist_null_value.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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"?>
     5 <window title="Menulist value property"
     6   onload="setTimeout(runTests, 0);"
     7   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
    10   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
    12 <menulist id="list">
    13   <menupopup>
    14     <menuitem id="i0" label="Zero" value="0"/>
    15     <menuitem id="i1" label="One" value="item1"/>
    16     <menuitem id="i2" label="Two" value="item2"/>
    17     <menuitem id="ifalse" label="False" value="false"/>
    18     <menuitem id="iempty" label="Empty" value=""/>
    19   </menupopup>
    20 </menulist>
    22 <script class="testbody" type="application/javascript">
    23 <![CDATA[
    25 SimpleTest.waitForExplicitFinish();
    27 function runTests()
    28 {
    29   var list = document.getElementById("list");
    31   list.value = "item2";
    32   is(list.value, "item2", "Check list value after setting value");
    33   is(list.getAttribute("label"), "Two", "Check list label after setting value");
    35   list.selectedItem = null;
    36   is(list.value, "", "Check list value after setting selectedItem to null");
    37   is(list.getAttribute("label"), "", "Check list label after setting selectedItem to null");
    39   // select something again to make sure the label is not already empty
    40   list.selectedIndex = 1;
    41   is(list.value, "item1", "Check list value after setting selectedIndex");
    42   is(list.getAttribute("label"), "One", "Check list label after setting selectedIndex");
    44   // check that an item can have the "false" value
    45   list.value = false;
    46   is(list.value, "false", "Check list value after setting it to false");
    47   is(list.getAttribute("label"), "False", "Check list labem after setting value to false");
    49   // check that an item can have the "0" value
    50   list.value = 0;
    51   is(list.value, "0", "Check list value after setting it to 0");
    52   is(list.getAttribute("label"), "Zero", "Check list label after setting value to 0");
    54   // check that an item can have the empty string value.
    55   list.value = "";
    56   is(list.value, "", "Check list value after setting it to an empty string");
    57   is(list.getAttribute("label"), "Empty", "Check list label after setting value to an empty string");
    59   // select something again to make sure the label is not already empty
    60   list.selectedIndex = 1;
    61   // set the value to null and test it (bug 408940)
    62   list.value = null;
    63   is(list.value, "", "Check list value after setting value to null");
    64   is(list.getAttribute("label"), "", "Check list label after setting value to null");
    66   // select something again to make sure the label is not already empty
    67   list.selectedIndex = 1;
    68   // set the value to undefined and test it (bug 408940)
    69   list.value = undefined;
    70   is(list.value, "", "Check list value after setting value to undefined");
    71   is(list.getAttribute("label"), "", "Check list label after setting value to undefined");
    73   // select something again to make sure the label is not already empty
    74   list.selectedIndex = 1;
    75   // set the value to something that does not exist in any menuitem of the list
    76   // and make sure the previous label is removed
    77   list.value = "this does not exist";
    78   is(list.value, "this does not exist", "Check the list value after setting it to something not associated witn an existing menuitem");
    79   is(list.getAttribute("label"), "", "Check that the list label is empty after selecting a nonexistent item");
    81   SimpleTest.finish();
    82 }
    84 ]]>
    85 </script>
    87 <body xmlns="http://www.w3.org/1999/xhtml">
    88 <p id="display">
    89 </p>
    90 <div id="content" style="display: none">
    91 </div>
    92 <pre id="test">
    93 </pre>
    94 </body>
    96 </window>

mercurial