|
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="Menu Checkbox and Radio Tests" |
|
6 onload="runTest()" |
|
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 <hbox> |
|
13 <button id="menu" type="menu" label="View"> |
|
14 <menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()"> |
|
15 <menuitem id="toolbar" label="Show Toolbar" type="checkbox"/> |
|
16 <menuitem id="statusbar" label="Show Status Bar" type="checkbox" checked="true"/> |
|
17 <menuitem id="bookmarks" label="Show Bookmarks" type="checkbox" autocheck="false"/> |
|
18 <menuitem id="history" label="Show History" type="checkbox" autocheck="false" checked="true"/> |
|
19 <menuseparator/> |
|
20 <menuitem id="byname" label="By Name" type="radio" name="sort"/> |
|
21 <menuitem id="bydate" label="By Date" type="radio" name="sort" checked="true"/> |
|
22 <menuseparator/> |
|
23 <menuitem id="ascending" label="Ascending" type="radio" name="order" checked="true"/> |
|
24 <menuitem id="descending" label="Descending" type="radio" name="order" autocheck="false"/> |
|
25 <menuitem id="bysubject" label="By Subject" type="radio" name="sort"/> |
|
26 </menupopup> |
|
27 </button> |
|
28 |
|
29 </hbox> |
|
30 |
|
31 <!-- |
|
32 This test checks that checkbox and radio menu items work properly |
|
33 --> |
|
34 <script class="testbody" type="application/javascript"> |
|
35 <![CDATA[ |
|
36 |
|
37 SimpleTest.waitForExplicitFinish(); |
|
38 var gTestIndex = 0; |
|
39 |
|
40 // tests to perform |
|
41 var tests = [ |
|
42 { |
|
43 testname: "select unchecked checkbox", |
|
44 item: "toolbar", |
|
45 checked: ["toolbar", "statusbar", "history", "bydate", "ascending"] |
|
46 }, |
|
47 { |
|
48 testname: "select checked checkbox", |
|
49 item: "statusbar", |
|
50 checked: ["toolbar", "history", "bydate", "ascending"] |
|
51 }, |
|
52 { |
|
53 testname: "select unchecked autocheck checkbox", |
|
54 item: "bookmarks", |
|
55 checked: ["toolbar", "history", "bydate", "ascending"] |
|
56 }, |
|
57 { |
|
58 testname: "select checked autocheck checkbox", |
|
59 item: "history", |
|
60 checked: ["toolbar", "history", "bydate", "ascending"] |
|
61 }, |
|
62 { |
|
63 testname: "select unchecked radio", |
|
64 item: "byname", |
|
65 checked: ["toolbar", "history", "byname", "ascending"] |
|
66 }, |
|
67 { |
|
68 testname: "select checked radio", |
|
69 item: "byname", |
|
70 checked: ["toolbar", "history", "byname", "ascending"] |
|
71 }, |
|
72 { |
|
73 testname: "select out of order checked radio", |
|
74 item: "bysubject", |
|
75 checked: ["toolbar", "history", "bysubject", "ascending"] |
|
76 }, |
|
77 { |
|
78 testname: "select first radio again", |
|
79 item: "byname", |
|
80 checked: ["toolbar", "history", "byname", "ascending"] |
|
81 }, |
|
82 { |
|
83 testname: "select autocheck radio", |
|
84 item: "descending", |
|
85 checked: ["toolbar", "history", "byname", "ascending"] |
|
86 } |
|
87 ]; |
|
88 |
|
89 function runTest() |
|
90 { |
|
91 checkMenus(["statusbar", "history", "bydate", "ascending"], "initial"); |
|
92 document.getElementById("menu").open = true; |
|
93 } |
|
94 |
|
95 function checkMenus(checkedItems, testname) |
|
96 { |
|
97 var isok = true; |
|
98 var children = document.getElementById("popup").childNodes; |
|
99 for (var c = 0; c < children.length; c++) { |
|
100 var child = children[c]; |
|
101 if ((checkedItems.indexOf(child.id) != -1 && child.getAttribute("checked") != "true") || |
|
102 (checkedItems.indexOf(child.id) == -1 && child.hasAttribute("checked"))) { |
|
103 isok = false; |
|
104 break; |
|
105 } |
|
106 } |
|
107 |
|
108 ok(isok, testname); |
|
109 } |
|
110 |
|
111 function popupShown() |
|
112 { |
|
113 var test = tests[gTestIndex]; |
|
114 synthesizeMouse(document.getElementById(test.item), 4, 4, { }); |
|
115 } |
|
116 |
|
117 function popupHidden() |
|
118 { |
|
119 if (gTestIndex < tests.length) { |
|
120 var test = tests[gTestIndex]; |
|
121 checkMenus(test.checked, test.testname); |
|
122 gTestIndex++; |
|
123 if (gTestIndex < tests.length) { |
|
124 document.getElementById("menu").open = true; |
|
125 } |
|
126 else { |
|
127 // manually setting the checkbox should also update the radio state |
|
128 document.getElementById("bydate").setAttribute("checked", "true"); |
|
129 checkMenus(["toolbar", "history", "bydate", "ascending"], "set checked attribute on radio"); |
|
130 SimpleTest.finish(); |
|
131 } |
|
132 } |
|
133 } |
|
134 |
|
135 ]]> |
|
136 </script> |
|
137 |
|
138 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
139 <p id="display"> |
|
140 </p> |
|
141 <div id="content" style="display: none"> |
|
142 </div> |
|
143 <pre id="test"> |
|
144 </pre> |
|
145 </body> |
|
146 |
|
147 </window> |