summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/mac/browser_required.js
blob: 2109d265abab9a7dfbebf9f9572ce929a5fe5314 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts(
  { name: "role.js", dir: MOCHITESTS_DIR },
  { name: "states.js", dir: MOCHITESTS_DIR }
);

/**
 * Test required and aria-required attributes on checkboxes
 * and radio buttons.
 */
addAccessibleTask(
  `
  <form>
    <input type="checkbox" id="checkbox" required>
   <br>
    <input type="radio" id="radio" required>
   <br>
    <input type="checkbox" id="ariaCheckbox" aria-required="true">
   <br>
    <input type="radio" id="ariaRadio" aria-required="true">
  </form>
  `,
  async (browser, accDoc) => {
    // Check initial AXRequired values are correct
    let radio = getNativeInterface(accDoc, "radio");
    is(
      radio.getAttributeValue("AXRequired"),
      1,
      "Correct required val for radio"
    );

    let ariaRadio = getNativeInterface(accDoc, "ariaRadio");
    is(
      ariaRadio.getAttributeValue("AXRequired"),
      1,
      "Correct required val for ariaRadio"
    );

    let checkbox = getNativeInterface(accDoc, "checkbox");
    is(
      checkbox.getAttributeValue("AXRequired"),
      1,
      "Correct required val for checkbox"
    );

    let ariaCheckbox = getNativeInterface(accDoc, "ariaCheckbox");
    is(
      ariaCheckbox.getAttributeValue("AXRequired"),
      1,
      "Correct required val for ariaCheckbox"
    );

    // Change aria-required, verify AXRequired is updated
    let stateChanged = waitForEvent(EVENT_STATE_CHANGE, "ariaCheckbox");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("ariaCheckbox")
        .setAttribute("aria-required", "false");
    });
    await stateChanged;

    is(
      ariaCheckbox.getAttributeValue("AXRequired"),
      0,
      "Correct required after false set for ariaCheckbox"
    );

    // Change aria-required, verify AXRequired is updated
    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "ariaCheckbox");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("ariaCheckbox")
        .setAttribute("aria-required", "true");
    });
    await stateChanged;

    is(
      ariaCheckbox.getAttributeValue("AXRequired"),
      1,
      "Correct required after true set for ariaCheckbox"
    );

    // Remove aria-required, verify AXRequired is updated
    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "ariaCheckbox");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("ariaCheckbox")
        .removeAttribute("aria-required");
    });
    await stateChanged;

    is(
      ariaCheckbox.getAttributeValue("AXRequired"),
      0,
      "Correct required after removal for ariaCheckbox"
    );

    // Change aria-required, verify AXRequired is updated
    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "ariaRadio");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("ariaRadio")
        .setAttribute("aria-required", "false");
    });
    await stateChanged;

    is(
      ariaRadio.getAttributeValue("AXRequired"),
      0,
      "Correct required after false set for ariaRadio"
    );

    // Change aria-required, verify AXRequired is updated
    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "ariaRadio");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("ariaRadio")
        .setAttribute("aria-required", "true");
    });
    await stateChanged;

    is(
      ariaRadio.getAttributeValue("AXRequired"),
      1,
      "Correct required after true set for ariaRadio"
    );

    // Remove aria-required, verify AXRequired is updated
    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "ariaRadio");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("ariaRadio")
        .removeAttribute("aria-required");
    });
    await stateChanged;

    is(
      ariaRadio.getAttributeValue("AXRequired"),
      0,
      "Correct required after removal for ariaRadio"
    );

    // Remove required, verify AXRequired is updated
    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "checkbox");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("checkbox").removeAttribute("required");
    });
    await stateChanged;

    is(
      checkbox.getAttributeValue("AXRequired"),
      0,
      "Correct required after removal for checkbox"
    );

    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "radio");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("radio").removeAttribute("required");
    });
    await stateChanged;

    is(
      checkbox.getAttributeValue("AXRequired"),
      0,
      "Correct required after removal for radio"
    );
  }
);