toolkit/content/tests/chrome/test_menulist_null_value.xul

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:811d1e3c9ee2
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 <window title="Menulist value property"
6 onload="setTimeout(runTests, 0);"
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
8
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>
11
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>
21
22 <script class="testbody" type="application/javascript">
23 <![CDATA[
24
25 SimpleTest.waitForExplicitFinish();
26
27 function runTests()
28 {
29 var list = document.getElementById("list");
30
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");
34
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");
38
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");
43
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");
48
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");
53
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");
58
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");
65
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");
72
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");
80
81 SimpleTest.finish();
82 }
83
84 ]]>
85 </script>
86
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>
95
96 </window>

mercurial