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
|
/* 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';
/* global nsIAccessibleValue, EVENT_VALUE_CHANGE, EVENT_TEXT_VALUE_CHANGE */
loadScripts({ name: 'value.js', dir: MOCHITESTS_DIR });
/**
* Test data has the format of:
* {
* desc {String} description for better logging
* id {String} given accessible DOMNode ID
* expected {String} expected value for a given accessible
* action {?Function*} an optional action that yields a value change
* attrs {?Array} an optional list of attributes to update
* waitFor {?Number} an optional value change event to wait for
* }
*/
const valueTests = [{
desc: 'Initially value is set to 1st element of select',
id: 'select',
expected: '1st'
}, {
desc: 'Value should update to 3rd when 3 is pressed',
id: 'select',
action: function*(browser) {
yield invokeFocus(browser, 'select');
yield BrowserTestUtils.synthesizeKey('3', {}, browser);
},
waitFor: EVENT_TEXT_VALUE_CHANGE,
expected: '3rd'
}, {
desc: 'Initially value is set to @aria-valuenow for slider',
id: 'slider',
expected: ['5', 5, 0, 7, 0]
}, {
desc: 'Value should change when @aria-valuenow is updated',
id: 'slider',
attrs: [{
attr: 'aria-valuenow',
value: '6'
}],
waitFor: EVENT_VALUE_CHANGE,
expected: ['6', 6, 0, 7, 0]
}, {
desc: 'Value should change when @aria-valuetext is set',
id: 'slider',
attrs: [{
attr: 'aria-valuetext',
value: 'plain'
}],
waitFor: EVENT_TEXT_VALUE_CHANGE,
expected: ['plain', 6, 0, 7, 0]
}, {
desc: 'Value should change when @aria-valuetext is updated',
id: 'slider',
attrs: [{
attr: 'aria-valuetext',
value: 'hey!'
}],
waitFor: EVENT_TEXT_VALUE_CHANGE,
expected: ['hey!', 6, 0, 7, 0]
}, {
desc: 'Value should change to @aria-valuetext when @aria-valuenow is removed',
id: 'slider',
attrs: [{
attr: 'aria-valuenow'
}],
expected: ['hey!', 0, 0, 7, 0]
}, {
desc: 'Initially value is not set for combobox',
id: 'combobox',
expected: ''
}, {
desc: 'Value should change when @value attribute is updated',
id: 'combobox',
attrs: [{
attr: 'value',
value: 'hello'
}],
waitFor: EVENT_TEXT_VALUE_CHANGE,
expected: 'hello'
}, {
desc: 'Initially value corresponds to @value attribute for progress',
id: 'progress',
expected: '22%'
}, {
desc: 'Value should change when @value attribute is updated',
id: 'progress',
attrs: [{
attr: 'value',
value: '50'
}],
waitFor: EVENT_VALUE_CHANGE,
expected: '50%'
}, {
desc: 'Initially value corresponds to @value attribute for range',
id: 'range',
expected: '6'
}, {
desc: 'Value should change when slider is moved',
id: 'range',
action: function*(browser) {
yield invokeFocus(browser, 'range');
yield BrowserTestUtils.synthesizeKey('VK_LEFT', {}, browser);
},
waitFor: EVENT_VALUE_CHANGE,
expected: '5'
}];
/**
* Test caching of accessible object values
*/
addAccessibleTask(`
<div id="slider" role="slider" aria-valuenow="5"
aria-valuemin="0" aria-valuemax="7">slider</div>
<select id="select">
<option>1st</option>
<option>2nd</option>
<option>3rd</option>
</select>
<input id="combobox" role="combobox" aria-autocomplete="inline">
<progress id="progress" value="22" max="100"></progress>
<input type="range" id="range" min="0" max="10" value="6">`,
function* (browser, accDoc) {
for (let { desc, id, action, attrs, expected, waitFor } of valueTests) {
info(desc);
let acc = findAccessibleChildByID(accDoc, id);
let onUpdate;
if (waitFor) {
onUpdate = waitForEvent(waitFor, id);
}
if (action) {
yield action(browser);
} else if (attrs) {
for (let { attr, value } of attrs) {
yield invokeSetAttribute(browser, id, attr, value);
}
}
yield onUpdate;
if (Array.isArray(expected)) {
acc.QueryInterface(nsIAccessibleValue);
testValue(acc, ...expected);
} else {
is(acc.value, expected, `Correct value for ${prettyName(acc)}`);
}
}
}
);
|