summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/name/test_general.xhtml
blob: 3c5bb233092a6bcdc970615fdcfb6cf33d448da4 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?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 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        xmlns:html="http://www.w3.org/1999/xhtml"
        title="Accessibility Name Calculating Test.">

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../name.js"></script>

  <script type="application/javascript">
  <![CDATA[
    function doTest()
    {
      // aria-label

      // Simple label provided via ARIA
      testName("btn_simple_aria_label", "I am a button");

      // aria-label and aria-labelledby, expect aria-labelledby
      testName("btn_both_aria_labels", "text I am a button, two");

      //////////////////////////////////////////////////////////////////////////
      // aria-labelledby

      // Single relation. The value of 'aria-labelledby' contains the ID of
      // an element. Gets the name from text node of that element.
      testName("btn_labelledby_text", "text");

      // Multiple relations. The value of 'aria-labelledby' contains the IDs
      // of elements. Gets the name from text nodes of those elements.
      testName("btn_labelledby_texts", "text1 text2");

      // Trick cases. Self and recursive referencing.
      testName("rememberHistoryDays", "Remember 3 days");
      testName("historyDays", "Remember 3 days");
      testName("rememberAfter", "days");

      //////////////////////////////////////////////////////////////////////////
      // Name from subtree (single relation labelled_by).

      // Gets the name from text nodes contained by nested elements.
      testName("btn_labelledby_mixed", "no more text");

      // Gets the name from text nodes and selected item of menulist
      // (other items are ignored).
      testName("btn_labelledby_mixed_menulist",
               "no more text selected item more text");

      // Gets the name from text nodes contained by nested elements, ignores
      // hidden elements (bug 443081).
      testName("btn_labelledby_mixed_hidden_child", "no more text2");

      // Gets the name from hidden text nodes contained by nested elements,
      // (label element is hidden entirely), (bug 443081)
      testName("btn_labelledby_mixed_hidden", "lala more hidden text");


      //////////////////////////////////////////////////////////////////////////
      // Name from @label attribute.

      // Gets the name from @label attribute.
      testName("btn_labelattr", "labeled element");


      //////////////////////////////////////////////////////////////////////////
      // Name for nsIDOMXULSelectControlItemElement.

      // Gets the name from @label attribute.
      testName("li_nsIDOMXULSelectControlItemElement", "select control item");


      //////////////////////////////////////////////////////////////////////////
      // Name if the XUL element doesn't implement nsIDOMXULSelectControlElement
      // and has @label attribute.

      testName("box_not_nsIDOMXULSelectControlElement", "box");


      //////////////////////////////////////////////////////////////////////////
      // Name from the label element.

      // The label and button are placed on 2nd level relative common parent.
      testName("btn_label_1", "label1");

      // The label is on 1st, the button is on 5th level relative common parent.
      testName("btn_label_2", "label2");

      // The label and button are siblings.
      testName("btn_label_3", "label3");

      // Multiple labels for single button: XUL button takes the last one.
      testName("btn_label_4", "label5");

      // Label associated with HTML element.
      testName("input_label", "input label");


      //////////////////////////////////////////////////////////////////////////
      // tooltiptext (if nothing above isn't presented then tooltiptext is used)
      testName("box_tooltiptext", "tooltiptext label");


      //////////////////////////////////////////////////////////////////////////
      // Name from the @title attribute of <toolbaritem/> (original bug 237249).

      // Direct child of toolbaritem.
      testName("toolbaritem_child", null);

      // Child from subtree of toolbaritem.
      testName("toolbaritem_hboxbutton", "button");


      //////////////////////////////////////////////////////////////////////////
      // name from label inside toolbar button
      testName("toolbarbuttonwithlabel", "I am the button");


      //////////////////////////////////////////////////////////////////////////
      // Name from children

      // ARIA role button is presented allowing the name calculation from
      // children.
      testName("box_children", "14");

      // Button labelled by a text child.
      testName("button_text", "Text");
      testName("toolbarbutton_text", "Text");

      // ARIA role option is presented allowing the name calculation from
      // the visible children (bug 443081)
      testName("lb_opt1_children_hidden", "i am visible");


      //////////////////////////////////////////////////////////////////////////
      // Name from aria-labelledby: menuitem label+ listitem label
      testName("li_labelledby", "Show an Alert The moment the event starts");

      //////////////////////////////////////////////////////////////////////////
      // groupbox labeling from first label
      testName("groupbox", "Some caption");

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  ]]>
  </script>

  <hbox flex="1" style="overflow: auto;">

  <body xmlns="http://www.w3.org/1999/xhtml">
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=444279"
       title="mochitest for accessible name calculating">
      Mozilla Bug 444279
    </a>
    <a target="_blank"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=441991"
      title="nsXULListitemAccessible::GetName prefers label \
      		   attribute over aria-labelledby and doesn't allow recursion">
      Mozilla Bug 441991
    </a>
  <p id="display"></p>
    <div id="content" style="display: none">
    </div>
    <pre id="test">
    </pre>
  </body>

  <vbox flex="1">

  <!-- aria-label, simple label -->
  <button id="btn_simple_aria_label" aria-label="I am a button"/>

  <!-- aria-label plus aria-labelledby -->
  <button id="btn_both_aria_labels" aria-label="I am a button, two"
          aria-labelledby="labelledby_text btn_both_aria_labels"/>

  <!-- aria-labelledby, single relation -->
  <description id="labelledby_text">text</description>
  <button id="btn_labelledby_text"
          aria-labelledby="labelledby_text"/>

  <!-- aria-labelledby, multiple relations -->
  <description id="labelledby_text1">text1</description>
  <description id="labelledby_text2">text2</description>
  <button id="btn_labelledby_texts"
          aria-labelledby="labelledby_text1 labelledby_text2"/>

  <!-- trick aria-labelledby -->
  <checkbox id="rememberHistoryDays"
            label="Remember "
            aria-labelledby="rememberHistoryDays historyDays rememberAfter"/>
  <html:input id="historyDays" value="3"
              aria-labelledby="rememberHistoryDays historyDays rememberAfter"/>
  <label id="rememberAfter">days</label>

  <!-- the name from subtree, mixed content -->
  <description id="labelledby_mixed">
    no<description>more text</description>
  </description>
  <button id="btn_labelledby_mixed"
          aria-labelledby="labelledby_mixed"/>

  <!-- the name from subtree, mixed/hidden content -->
  <description id="labelledby_mixed_hidden_child">no<description>more <description hidden="true">hidden</description>text2</description></description>
  <button id="btn_labelledby_mixed_hidden_child"
          aria-labelledby="labelledby_mixed_hidden_child"/>

  <!-- the name from subtree, mixed/completely hidden content -->
  <description id="labelledby_mixed_hidden"
               hidden="true">lala <description>more hidden </description>text</description>
  <button id="btn_labelledby_mixed_hidden"
          aria-labelledby="labelledby_mixed_hidden"/>
  <br/>

  <!-- the name from subtree, mixed content, ignore items of menulist -->
  <description id="labelledby_mixed_menulist">
    no<description>more text</description>
    <menulist>
      <menupopup>
        <menuitem label="selected item"/>
        <menuitem label="item"/>
      </menupopup>
    </menulist>
    more text
  </description>
  <button id="btn_labelledby_mixed_menulist"
          aria-labelledby="labelledby_mixed_menulist"/>

  <!-- @label -->
  <button id="btn_labelattr"
          label="labeled element"/>

  <!-- nsIDOMXULSelectControlItemElement -->
  <richlistbox>
    <richlistitem id="li_nsIDOMXULSelectControlItemElement">
      <label value="select control item"/>
    </richlistitem>
  </richlistbox>

  <!-- not nsIDOMXULSelectControlElement -->
  <box id="box_not_nsIDOMXULSelectControlElement" role="group" label="box"/>

  <!-- label element  -->
  <hbox>
    <box>
      <label control="btn_label_1">label1</label>
    </box>
    <label control="btn_label_2">label2</label>
    <box>
      <button id="btn_label_1"/>
      <box>
        <box>
          <box>
            <button id="btn_label_2"/>
          </box>
        </box>
      </box>
    </box>
    <label control="btn_label_3">label3</label>
    <button id="btn_label_3"/>

    <label control="btn_label_4">label4</label>
    <label control="btn_label_4">label5</label>
    <button id="btn_label_4"/>

    <label control="input_label">input label</label>
    <html:input id="input_label"/>
  </hbox>

  <!-- tooltiptext -->
  <box id="box_tooltiptext"
       role="group"
       tooltiptext="tooltiptext label"/>

  <!-- the name from @title of toolbaritem -->
  <!-- and the name from label of a toolbarbutton -->
  <toolbar>
    <toolbaritem title="ooospspss">
      <box id="toolbaritem_child"
           role="group"
           flex="1">
        <hbox role="button" id="toolbaritem_hboxbutton">
          <description value="button"/>
        </hbox>
      </box>
    </toolbaritem>
    <toolbarbutton id="toolbarbuttonwithlabel">
      <label flex="1">I am the button</label>
    </toolbarbutton>
  </toolbar>

  <!-- name from children -->
  <box id="box_children" role="button">14</box>
  <button id="button_text">Text</button>
  <toolbarbutton id="toolbarbutton_text">Text</toolbarbutton>

  <!-- name from children, hidden children -->
  <vbox role="listbox" tabindex="0">
    <hbox id="lb_opt1_children_hidden" role="option" tabindex="0">
      <description>i am visible</description>
      <description style="display:none">i am hidden</description>
    </hbox>

    <!-- Name from caption sub tree -->
    <groupbox id="groupbox">
      <label>Some caption</label>
      <checkbox label="some checkbox label" />
    </groupbox>
  </vbox>

  <!-- bug 441991; create name from other menuitem label listitem's own label -->
  <hbox>
    <richlistbox>
      <richlistitem id="li_labelledby"
                    aria-labelledby="menuitem-DISPLAY li_labelledby">
        <label value="The moment the event starts"/>
      </richlistitem>
    </richlistbox>
    <menulist>
      <menupopup>
        <menuitem id="menuitem-DISPLAY"
                  value="DISPLAY"
                  label="Show an Alert"/>
        <menuitem id="menuitem-EMAIL"
                  value="EMAIL"
                  label="Send an E-mail"/>
      </menupopup>
    </menulist>
  </hbox>

  </vbox> <!-- close tests area -->
  </hbox> <!-- close main area -->
</window>