summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_valuechange.html
blob: 1ad3c0359d91e123fe08ed7749d0b315ba81fb21 (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
<html>

<head>
  <title>Accessible value change events testing</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

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

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

  <script type="application/javascript"
          src="../value.js"></script>

  <script type="application/javascript">
    /**
     * Do tests.
     */
    var gQueue = null;

    // Value change invoker
    function changeARIAValue(aNodeOrID, aValuenow, aValuetext) {
      this.DOMNode = getNode(aNodeOrID);
      this.eventSeq = [ new invokerChecker(aValuetext ?
                                           EVENT_TEXT_VALUE_CHANGE :
                                           EVENT_VALUE_CHANGE, this.DOMNode),
        ];

      this.invoke = function changeARIAValue_invoke() {
        // Note: this should not fire an EVENT_VALUE_CHANGE when aria-valuetext
        // is not empty
        if (aValuenow != undefined)
          this.DOMNode.setAttribute("aria-valuenow", aValuenow);

        // Note: this should always fire an EVENT_VALUE_CHANGE
        if (aValuetext != undefined)
          this.DOMNode.setAttribute("aria-valuetext", aValuetext);
      };

      this.check = function changeARIAValue_check() {
        var acc = getAccessible(aNodeOrID, [nsIAccessibleValue]);
        if (!acc)
          return;

        // Note: always test against valuetext first because the existence of
        // aria-valuetext takes precedence over aria-valuenow in gecko.
        is(acc.value, (aValuetext != undefined) ? aValuetext : aValuenow,
            "Wrong value of " + prettyName(aNodeOrID));
      };

      this.getID = function changeARIAValue_getID() {
        return prettyName(aNodeOrID) + " value changed";
      };
    }

    function changeValue(aID, aValue) {
      this.DOMNode = getNode(aID);
      this.eventSeq = [new invokerChecker(EVENT_TEXT_VALUE_CHANGE,
                                          this.DOMNode),
        ];

      this.invoke = function changeValue_invoke() {
        this.DOMNode.value = aValue;
      };

      this.check = function changeValue_check() {
        var acc = getAccessible(this.DOMNode);
        is(acc.value, aValue, "Wrong value for " + prettyName(aID));
      };

      this.getID = function changeValue_getID() {
        return prettyName(aID) + " value changed";
      };
    }

    function changeProgressValue(aID, aValue) {
      this.DOMNode = getNode(aID);
      this.eventSeq = [new invokerChecker(EVENT_VALUE_CHANGE, this.DOMNode)];

      this.invoke = function changeProgressValue_invoke() {
         this.DOMNode.value = aValue;
      };

      this.check = function changeProgressValue_check() {
        var acc = getAccessible(this.DOMNode);
        is(acc.value, aValue + "%", "Wrong value for " + prettyName(aID));
      };

      this.getID = function changeProgressValue_getID() {
        return prettyName(aID) + " value changed";
      };
    }

    function changeRangeValueWithMouse(aID) {
      this.DOMNode = getNode(aID);
      this.eventSeq = [new invokerChecker(EVENT_VALUE_CHANGE, this.DOMNode)];

      this.invoke = function changeRangeValue_invoke() {
        synthesizeMouse(getNode(aID), 5, 5, { });
      };

      this.finalCheck = function changeRangeValue_finalCheck() {
        var acc = getAccessible(this.DOMNode);
        is(acc.value, "0", "Wrong value for " + prettyName(aID));
      };

      this.getID = function changeRangeValue_getID() {
        return prettyName(aID) + " range value changed";
      };
    }

    function changeRangeValueWithA11yAPI(aID) {
      this.DOMNode = getNode(aID);
      let inputChecker = new invokerChecker("input", this.DOMNode);
      inputChecker.eventTarget = "element";

      let changeChecker = new invokerChecker("change", this.DOMNode);
      changeChecker.eventTarget = "element";

      this.eventSeq = [
        inputChecker,
        changeChecker,
        new invokerChecker(EVENT_VALUE_CHANGE, this.DOMNode),
      ];

      this.invoke = function changeRangeValue_invoke() {
        this.DOMNode.focus();
        let acc = getAccessible(this.DOMNode, [nsIAccessibleValue]);
        acc.currentValue = 0;
        this.DOMNode.blur();
      };

      this.finalCheck = function changeRangeValue_finalCheck() {
        var acc = getAccessible(this.DOMNode);
        is(acc.value, "0", "Wrong value for " + prettyName(aID));
      };

      this.getID = function changeRangeValue_getID() {
        return prettyName(aID) + " range value changed";
      };
    }

    function changeSelectValue(aID, aKey, aValue) {
      this.eventSeq =
        [ new invokerChecker(EVENT_TEXT_VALUE_CHANGE, getAccessible(aID)) ];

      this.invoke = function changeSelectValue_invoke() {
        getAccessible(aID).takeFocus();
        synthesizeKey(aKey, {}, window);
      };

      this.finalCheck = function changeSelectValue_finalCheck() {
        is(getAccessible(aID).value, aValue, "Wrong value for " + prettyName(aID));
      };

      this.getID = function changeSelectValue_getID() {
        return `${prettyName(aID)} closed select value change on '${aKey}'' key press`;
      };
    }

    // enableLogging("DOMEvents");
    // gA11yEventDumpToConsole = true;
    function doTests() {

      // Test initial values
      testValue("slider_vn", "5", 5, 0, 1000, 0);
      testValue("slider_vnvt", "plain", 0, 0, 5, 0);
      testValue("slider_vt", "hi", 1.5, 0, 3, 0);
      testValue("scrollbar", "5", 5, 0, 1000, 0);
      testValue("splitter", "5", 5, 0, 1000, 0);
      testValue("progress", "22%", 22, 0, 100, 0);
      testValue("range", "6", 6, 0, 10, 1);
      testValue("range2", "6", 6, 0, 10, 1);

      // Test that elements which should not expose values do not
      let separatorVal = getAccessible("separator", [nsIAccessibleValue], null, DONOTFAIL_IF_NO_INTERFACE);
      ok(!separatorVal, "value interface is not exposed for separator");
      let separatorAcc = getAccessible("separator");
      ok(!separatorAcc.value, "Value text is not exposed for separator");

      // Test value change events
      gQueue = new eventQueue();

      gQueue.push(new changeARIAValue("slider_vn", "6", undefined));
      gQueue.push(new changeARIAValue("slider_vt", undefined, "hey!"));
      gQueue.push(new changeARIAValue("slider_vnvt", "3", "sweet"));
      gQueue.push(new changeARIAValue("scrollbar", "6", undefined));
      gQueue.push(new changeARIAValue("splitter", "6", undefined));

      gQueue.push(new changeValue("combobox", "hello"));

      gQueue.push(new changeProgressValue("progress", "50"));
      gQueue.push(new changeRangeValueWithMouse("range"));
      gQueue.push(new changeRangeValueWithA11yAPI("range2"));

      gQueue.push(new changeSelectValue("select", "VK_DOWN", "2nd"));
      gQueue.push(new changeSelectValue("select", "3", "3rd"));

      let iframeSelect = getAccessible("selectIframe").firstChild.firstChild;
      gQueue.push(new changeSelectValue(iframeSelect, "VK_DOWN", "2"));

      let shadowSelect = getAccessible("selectShadow").firstChild;
      gQueue.push(new changeSelectValue(shadowSelect, "VK_DOWN", "2"));
      gQueue.push(new changeValue("number", "2"));

      gQueue.invoke(); // Will call SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  </script>
</head>

<body>

  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=478032"
     title=" Fire delayed value changed event for aria-valuetext changes">
    Mozilla Bug 478032
  </a>
  <a target="_blank"
    href="https://bugzilla.mozilla.org/show_bug.cgi?id=529289"
    title="We dont expose new aria role 'scrollbar' and property aria-orientation">
   Mozilla Bug 529289
  </a>
  <a target="_blank"
    href="https://bugzilla.mozilla.org/show_bug.cgi?id=559764"
    title="Make HTML5 input@type=range element accessible">
   Mozilla Bug 559764
  </a>
  <a target="_blank"
    href="https://bugzilla.mozilla.org/show_bug.cgi?id=703202"
    title="ARIA comboboxes don't fire value change events">
   Mozilla Bug 703202
  </a>
  <a target="_blank"
    href="https://bugzilla.mozilla.org/show_bug.cgi?id=761901"
    title=" HTML5 progress accessible should fire value change event">
   Mozilla Bug 761901
  </a>


  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>
  <div id="eventdump"></div>

  <!-- ARIA sliders -->
  <div id="slider_vn" role="slider" aria-valuenow="5"
       aria-valuemin="0" aria-valuemax="1000">slider</div>

  <div id="slider_vt" role="slider" aria-valuetext="hi"
       aria-valuemin="0" aria-valuemax="3">greeting slider</div>

  <div id="slider_vnvt" role="slider" aria-valuenow="0" aria-valuetext="plain"
       aria-valuemin="0" aria-valuemax="5">sweetness slider</div>

  <!-- ARIA scrollbar -->
  <div id="scrollbar" role="scrollbar" aria-valuenow="5"
       aria-valuemin="0" aria-valuemax="1000">slider</div>

  <!-- ARIA separator which is focusable (i.e. a splitter) -->
  <div id="splitter" role="separator" tabindex="0" aria-valuenow="5"
       aria-valuemin="0" aria-valuemax="1000">splitter</div>

  <!-- ARIA separator which is not focusable and should not expose values -->
  <div id="separator" role="separator" aria-valuenow="5"
       aria-valuemin="0" aria-valuemax="1000">splitter</div>

  <!-- ARIA combobox -->
  <input id="combobox" role="combobox" aria-autocomplete="inline">

  <!-- progress bar -->
  <progress id="progress" value="22" max="100"></progress>

  <!-- input@type="range" -->
  <input type="range" id="range" min="0" max="10" value="6">

  <!-- input@type="range" -->
  <input type="range" id="range2" min="0" max="10" value="6">

  <select id="select">
    <option>1st</option>
    <option>2nd</option>
    <option>3rd</option>
  </select>

  <iframe id="selectIframe"
    src="data:text/html,<select id='iframeSelect'><option>1</option><option>2</option></select>">
  </iframe>

  <div id="selectShadow"></div>
  <script>
    let host = document.getElementById("selectShadow");
    let shadow = host.attachShadow({mode: "open"});
    let select = document.createElement("select");
    select.id = "shadowSelect";
    let option = document.createElement("option");
    option.textContent = "1";
    select.appendChild(option);
    option = document.createElement("option");
    option.textContent = "2";
    select.appendChild(option);
    shadow.appendChild(select);
  </script>

  <input type="number" id="number" value="1">
</body>
</html>