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