toolkit/content/tests/chrome/test_menulist_null_value.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_menulist_null_value.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     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 +<window title="Menulist value property"
     1.9 +  onload="setTimeout(runTests, 0);"
    1.10 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
    1.13 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
    1.14 +
    1.15 +<menulist id="list">
    1.16 +  <menupopup>
    1.17 +    <menuitem id="i0" label="Zero" value="0"/>
    1.18 +    <menuitem id="i1" label="One" value="item1"/>
    1.19 +    <menuitem id="i2" label="Two" value="item2"/>
    1.20 +    <menuitem id="ifalse" label="False" value="false"/>
    1.21 +    <menuitem id="iempty" label="Empty" value=""/>
    1.22 +  </menupopup>
    1.23 +</menulist>
    1.24 +
    1.25 +<script class="testbody" type="application/javascript">
    1.26 +<![CDATA[
    1.27 +
    1.28 +SimpleTest.waitForExplicitFinish();
    1.29 +
    1.30 +function runTests()
    1.31 +{
    1.32 +  var list = document.getElementById("list");
    1.33 +
    1.34 +  list.value = "item2";
    1.35 +  is(list.value, "item2", "Check list value after setting value");
    1.36 +  is(list.getAttribute("label"), "Two", "Check list label after setting value");
    1.37 +
    1.38 +  list.selectedItem = null;
    1.39 +  is(list.value, "", "Check list value after setting selectedItem to null");
    1.40 +  is(list.getAttribute("label"), "", "Check list label after setting selectedItem to null");
    1.41 +
    1.42 +  // select something again to make sure the label is not already empty
    1.43 +  list.selectedIndex = 1;
    1.44 +  is(list.value, "item1", "Check list value after setting selectedIndex");
    1.45 +  is(list.getAttribute("label"), "One", "Check list label after setting selectedIndex");
    1.46 +
    1.47 +  // check that an item can have the "false" value
    1.48 +  list.value = false;
    1.49 +  is(list.value, "false", "Check list value after setting it to false");
    1.50 +  is(list.getAttribute("label"), "False", "Check list labem after setting value to false");
    1.51 +
    1.52 +  // check that an item can have the "0" value
    1.53 +  list.value = 0;
    1.54 +  is(list.value, "0", "Check list value after setting it to 0");
    1.55 +  is(list.getAttribute("label"), "Zero", "Check list label after setting value to 0");
    1.56 +
    1.57 +  // check that an item can have the empty string value.
    1.58 +  list.value = "";
    1.59 +  is(list.value, "", "Check list value after setting it to an empty string");
    1.60 +  is(list.getAttribute("label"), "Empty", "Check list label after setting value to an empty string");
    1.61 +
    1.62 +  // select something again to make sure the label is not already empty
    1.63 +  list.selectedIndex = 1;
    1.64 +  // set the value to null and test it (bug 408940)
    1.65 +  list.value = null;
    1.66 +  is(list.value, "", "Check list value after setting value to null");
    1.67 +  is(list.getAttribute("label"), "", "Check list label after setting value to null");
    1.68 +
    1.69 +  // select something again to make sure the label is not already empty
    1.70 +  list.selectedIndex = 1;
    1.71 +  // set the value to undefined and test it (bug 408940)
    1.72 +  list.value = undefined;
    1.73 +  is(list.value, "", "Check list value after setting value to undefined");
    1.74 +  is(list.getAttribute("label"), "", "Check list label after setting value to undefined");
    1.75 +
    1.76 +  // select something again to make sure the label is not already empty
    1.77 +  list.selectedIndex = 1;
    1.78 +  // set the value to something that does not exist in any menuitem of the list
    1.79 +  // and make sure the previous label is removed
    1.80 +  list.value = "this does not exist";
    1.81 +  is(list.value, "this does not exist", "Check the list value after setting it to something not associated witn an existing menuitem");
    1.82 +  is(list.getAttribute("label"), "", "Check that the list label is empty after selecting a nonexistent item");
    1.83 +
    1.84 +  SimpleTest.finish();
    1.85 +}
    1.86 +
    1.87 +]]>
    1.88 +</script>
    1.89 +
    1.90 +<body xmlns="http://www.w3.org/1999/xhtml">
    1.91 +<p id="display">
    1.92 +</p>
    1.93 +<div id="content" style="display: none">
    1.94 +</div>
    1.95 +<pre id="test">
    1.96 +</pre>
    1.97 +</body>
    1.98 +
    1.99 +</window>

mercurial