testaro 60.12.0 → 60.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/UPGRADES.md +2 -0
- package/package.json +1 -1
- package/procs/doTestAct.js +1 -1
- package/procs/testaro.js +107 -6
- package/run.js +1 -1
- package/testaro/adbID.js +1 -3
- package/testaro/altScheme.js +1 -3
- package/testaro/captionLoc.js +1 -3
- package/testaro/datalistRef.js +1 -1
- package/testaro/embAc.js +1 -1
- package/testaro/focAndOp.js +1 -3
- package/testaro/focInd.js +1 -3
- package/testaro/focVis.js +23 -35
- package/testaro/hover-draft0.js +110 -0
- package/testaro/hover-draft1.js +185 -0
- package/testaro/hover-draft2.js +183 -0
- package/testaro/hover-draft3.js +143 -0
- package/testaro/hover-orig.js +109 -0
- package/testaro/hover.js +66 -58
- package/testaro/lineHeight.js +1 -3
- package/testaro/miniText.js +1 -1
- package/tests/testaro.js +18 -11
package/UPGRADES.md
CHANGED
|
@@ -3305,3 +3305,5 @@ In a run by the Kilotest server on the [home page of the Open Source Collective]
|
|
|
3305
3305
|
All of the tests with elapsed times longer than 2 seconds were not yet refactored. Some of the refactored tests applied `checkVisibility` to all `body` descendant elements.
|
|
3306
3306
|
|
|
3307
3307
|
Credit for the speed improvement in refactored tests is apparently owed to the encapsulation of the entire test logic in a browser function, versus the repeated element-by-element execution of the same logic in Node.js with Playwright methods.
|
|
3308
|
+
|
|
3309
|
+
Evidence for this hypothesis is provided by the change in elapsed time after refactoring of the `focOp` and `opFoc` tests. These two tests consumed 18 seconds before the refactoring. The refactoring combined them into a single `focAndOp` test with functionality equivalent to both original tests. The refactored test on the same target consumed 2 seconds, even though it reported and itemized 223 violations.
|
package/package.json
CHANGED
package/procs/doTestAct.js
CHANGED
|
@@ -43,7 +43,7 @@ const tmpDir = os.tmpdir();
|
|
|
43
43
|
|
|
44
44
|
// FUNCTIONS
|
|
45
45
|
|
|
46
|
-
// Performs the tests of
|
|
46
|
+
// Performs the tests of an act.
|
|
47
47
|
const doTestAct = async actIndex => {
|
|
48
48
|
const reportPath = `${tmpDir}/report.json`;
|
|
49
49
|
// Get the report from the temporary directory.
|
package/procs/testaro.js
CHANGED
|
@@ -90,7 +90,7 @@ const getRuleResult = exports.getRuleResult = async (
|
|
|
90
90
|
// If itemization is required:
|
|
91
91
|
if (withItems) {
|
|
92
92
|
// Get the bounding box of the element.
|
|
93
|
-
const {tagName,id, location, excerpt} = elData;
|
|
93
|
+
const {tagName, id, location, excerpt} = elData;
|
|
94
94
|
const box = location.type === 'box' ? location.spec : await boxOf(loc);
|
|
95
95
|
// Add a standard instance to the result.
|
|
96
96
|
standardInstances.push({
|
|
@@ -169,7 +169,7 @@ exports.doTest = async (
|
|
|
169
169
|
getBadWhatString
|
|
170
170
|
) => {
|
|
171
171
|
// Return totals and standard instances for the rule.
|
|
172
|
-
return await page.evaluate(args => {
|
|
172
|
+
return await page.evaluate(async args => {
|
|
173
173
|
const [
|
|
174
174
|
withItems,
|
|
175
175
|
ruleID,
|
|
@@ -186,8 +186,8 @@ exports.doTest = async (
|
|
|
186
186
|
// Get a violation function.
|
|
187
187
|
const getBadWhat = eval(`(${getBadWhatString})`);
|
|
188
188
|
// For each candidate:
|
|
189
|
-
|
|
190
|
-
const violationWhat = getBadWhat(
|
|
189
|
+
for (const candidate of candidates) {
|
|
190
|
+
const violationWhat = await getBadWhat(candidate);
|
|
191
191
|
// If it violates the rule:
|
|
192
192
|
if (violationWhat) {
|
|
193
193
|
// Increment the violation count.
|
|
@@ -205,11 +205,11 @@ exports.doTest = async (
|
|
|
205
205
|
}
|
|
206
206
|
// Add an instance to the instances.
|
|
207
207
|
instances.push(
|
|
208
|
-
window.getInstance(
|
|
208
|
+
window.getInstance(candidate, ruleID, ruleWhat, 1, ruleSeverity)
|
|
209
209
|
);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
}
|
|
212
|
+
}
|
|
213
213
|
// If there are any violations and itemization is not required:
|
|
214
214
|
if (violationCount && ! withItems) {
|
|
215
215
|
// Add a summary instance to the instances.
|
|
@@ -233,3 +233,104 @@ exports.doTest = async (
|
|
|
233
233
|
]
|
|
234
234
|
);
|
|
235
235
|
};
|
|
236
|
+
// Returns a result from a basic test.
|
|
237
|
+
exports.getBasicResult = async (
|
|
238
|
+
page, withItems, ruleID, ordinalSeverity, summaryTagName, whats, data, violations
|
|
239
|
+
) => {
|
|
240
|
+
// If the test was prevented:
|
|
241
|
+
if (data.prevented) {
|
|
242
|
+
// Return this.
|
|
243
|
+
return {
|
|
244
|
+
data,
|
|
245
|
+
totals: [0, 0, 0, 0],
|
|
246
|
+
standardInstances: []
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
// Otherwise, i.e. if the test was not prevented:
|
|
250
|
+
const totals = [0, 0, 0, 0];
|
|
251
|
+
totals[ordinalSeverity] = violations.length;
|
|
252
|
+
const standardInstances = [];
|
|
253
|
+
// If itemization is required:
|
|
254
|
+
if (withItems) {
|
|
255
|
+
// For each violation:
|
|
256
|
+
for (const violation of violations) {
|
|
257
|
+
const {loc, what} = violation;
|
|
258
|
+
const elData = await getLocatorData(loc);
|
|
259
|
+
// Get the bounding box of the element.
|
|
260
|
+
const {tagName, id, location, excerpt} = elData;
|
|
261
|
+
const box = location.type === 'box' ? location.spec : await boxOf(loc);
|
|
262
|
+
// Add a standard instance to the instances.
|
|
263
|
+
standardInstances.push({
|
|
264
|
+
ruleID,
|
|
265
|
+
what,
|
|
266
|
+
ordinalSeverity,
|
|
267
|
+
tagName,
|
|
268
|
+
id,
|
|
269
|
+
location,
|
|
270
|
+
excerpt,
|
|
271
|
+
boxID: boxToString(box),
|
|
272
|
+
pathID: tagName === 'HTML' ? '/html' : await xPath(loc)
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// Otherwise, i.e. if itemization is not required:
|
|
277
|
+
else {
|
|
278
|
+
// Add a summary instance to the instances.
|
|
279
|
+
standardInstances.push({
|
|
280
|
+
ruleID,
|
|
281
|
+
what: whats,
|
|
282
|
+
ordinalSeverity,
|
|
283
|
+
summaryTagName,
|
|
284
|
+
id: '',
|
|
285
|
+
location: {},
|
|
286
|
+
excerpt: '',
|
|
287
|
+
boxID: '',
|
|
288
|
+
pathID: ''
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
// Return the result.
|
|
292
|
+
return {
|
|
293
|
+
data,
|
|
294
|
+
totals,
|
|
295
|
+
standardInstances
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
// Returns an awaited change in a visible element count.
|
|
299
|
+
exports.getVisibleCountChange = async (
|
|
300
|
+
rootLoc, elementCount0, timeLimit = 400, settleInterval = 75
|
|
301
|
+
) => {
|
|
302
|
+
const startTime = Date.now();
|
|
303
|
+
let timeout;
|
|
304
|
+
let settleChecker;
|
|
305
|
+
let elementCount1 = elementCount0;
|
|
306
|
+
// Set a time limit on the change.
|
|
307
|
+
const timeoutPromise = new Promise(resolve => {
|
|
308
|
+
timeout = setTimeout(() => {
|
|
309
|
+
clearInterval(settleChecker);
|
|
310
|
+
resolve();
|
|
311
|
+
}, timeLimit);
|
|
312
|
+
});
|
|
313
|
+
// Until the time limit expires, periodically:
|
|
314
|
+
const settlePromise = new Promise(resolve => {
|
|
315
|
+
settleChecker = setInterval(async () => {
|
|
316
|
+
const visiblesLoc = await rootLoc.locator('*:visible');
|
|
317
|
+
// Get the count.
|
|
318
|
+
elementCount1 = await visiblesLoc.count();
|
|
319
|
+
// If the count has changed:
|
|
320
|
+
if (elementCount1 !== elementCount0) {
|
|
321
|
+
// Stop.
|
|
322
|
+
clearTimeout(timeout);
|
|
323
|
+
clearInterval(settleChecker);
|
|
324
|
+
resolve();
|
|
325
|
+
}
|
|
326
|
+
}, settleInterval);
|
|
327
|
+
});
|
|
328
|
+
// When a change occurs or the time limit expires:
|
|
329
|
+
await Promise.race([timeoutPromise, settlePromise]);
|
|
330
|
+
const elapsedTime = Math.round(Date.now() - startTime);
|
|
331
|
+
// Return the change.
|
|
332
|
+
return {
|
|
333
|
+
change: elementCount1 - elementCount0,
|
|
334
|
+
elapsedTime
|
|
335
|
+
};
|
|
336
|
+
};
|
package/run.js
CHANGED
|
@@ -98,7 +98,7 @@ const timeLimits = {
|
|
|
98
98
|
alfa: 20,
|
|
99
99
|
ed11y: 30,
|
|
100
100
|
ibm: 30,
|
|
101
|
-
testaro:
|
|
101
|
+
testaro: 200 + Math.round(6 * waits / 1000)
|
|
102
102
|
};
|
|
103
103
|
// Timeout multiplier.
|
|
104
104
|
const timeoutMultiplier = Number.parseFloat(process.env.TIMEOUT_MULTIPLIER) || 1;
|
package/testaro/adbID.js
CHANGED
|
@@ -40,7 +40,6 @@ const {doTest} = require('../procs/testaro');
|
|
|
40
40
|
|
|
41
41
|
// Runs the test and returns the result.
|
|
42
42
|
exports.reporter = async (page, withItems) => {
|
|
43
|
-
// Define a violation function for execution in the browser.
|
|
44
43
|
const getBadWhat = element => {
|
|
45
44
|
// Get the IDs in the aria-describedby attribute of the element.
|
|
46
45
|
const IDs = element.getAttribute('aria-describedby').trim().split(/\s+/).filter(Boolean);
|
|
@@ -74,8 +73,7 @@ exports.reporter = async (page, withItems) => {
|
|
|
74
73
|
}
|
|
75
74
|
};
|
|
76
75
|
const whats = 'Elements have aria-describedby attributes with missing or invalid id values';
|
|
77
|
-
|
|
78
|
-
return doTest(
|
|
76
|
+
return await doTest(
|
|
79
77
|
page, withItems, 'adbID', '[aria-describedby]', whats, 3, null, getBadWhat.toString()
|
|
80
78
|
);
|
|
81
79
|
};
|
package/testaro/altScheme.js
CHANGED
|
@@ -37,7 +37,6 @@ const {doTest} = require('../procs/testaro');
|
|
|
37
37
|
|
|
38
38
|
// Runs the test and returns the result.
|
|
39
39
|
exports.reporter = async (page, withItems) => {
|
|
40
|
-
// Define a violation function for execution in the browser.
|
|
41
40
|
const getBadWhat = element => {
|
|
42
41
|
// Get the value of the alt attribute of the element.
|
|
43
42
|
const alt = (element.getAttribute('alt') || '').trim();
|
|
@@ -56,8 +55,7 @@ exports.reporter = async (page, withItems) => {
|
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
57
|
const whats = 'img elements have alt attributes with URL or filename values';
|
|
59
|
-
|
|
60
|
-
return doTest(
|
|
58
|
+
return await doTest(
|
|
61
59
|
page, withItems, 'altScheme', 'img[alt]', whats, 1, 'IMG', getBadWhat.toString()
|
|
62
60
|
);
|
|
63
61
|
};
|
package/testaro/captionLoc.js
CHANGED
|
@@ -36,7 +36,6 @@ const {doTest} = require('../procs/testaro');
|
|
|
36
36
|
// FUNCTIONS
|
|
37
37
|
|
|
38
38
|
exports.reporter = async (page, withItems) => {
|
|
39
|
-
// Define a violation function for execution in the browser.
|
|
40
39
|
const getBadWhat = element => {
|
|
41
40
|
const parent = element.parentElement;
|
|
42
41
|
// If the element is not the first child of a table element:
|
|
@@ -46,8 +45,7 @@ exports.reporter = async (page, withItems) => {
|
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
const whats = 'caption elements are not the first children of table elements';
|
|
49
|
-
|
|
50
|
-
return doTest(
|
|
48
|
+
return await doTest(
|
|
51
49
|
page, withItems, 'captionLoc', 'caption', whats, 3, 'CAPTION', getBadWhat.toString()
|
|
52
50
|
);
|
|
53
51
|
};
|
package/testaro/datalistRef.js
CHANGED
|
@@ -61,7 +61,7 @@ exports.reporter = async (page, withItems) => {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
const whats = 'list attributes of input elements are empty or IDs of no or non-datalist elements';
|
|
64
|
-
return doTest(
|
|
64
|
+
return await doTest(
|
|
65
65
|
page, withItems, 'datalistRef', 'input[list]', whats, 3, 'INPUT', getBadWhat.toString()
|
|
66
66
|
);
|
|
67
67
|
};
|
package/testaro/embAc.js
CHANGED
|
@@ -48,5 +48,5 @@ exports.reporter = async (page, withItems) => {
|
|
|
48
48
|
.map(tag => `a ${tag}, button ${tag}`)
|
|
49
49
|
.join(', ');
|
|
50
50
|
const whats = 'interactive elements are embedded in links or buttons';
|
|
51
|
-
return doTest(page, withItems, 'embAc', selector, whats, 2, null, getBadWhat.toString());
|
|
51
|
+
return await doTest(page, withItems, 'embAc', selector, whats, 2, null, getBadWhat.toString());
|
|
52
52
|
};
|
package/testaro/focAndOp.js
CHANGED
|
@@ -45,7 +45,6 @@ const {doTest} = require('../procs/testaro');
|
|
|
45
45
|
|
|
46
46
|
// Runs the test and returns the result.
|
|
47
47
|
exports.reporter = async (page, withItems) => {
|
|
48
|
-
// Define a violation function for execution in the browser.
|
|
49
48
|
const getBadWhat = element => {
|
|
50
49
|
// Get whether the element is visible.
|
|
51
50
|
const isVisible = element.checkVisibility({
|
|
@@ -139,8 +138,7 @@ exports.reporter = async (page, withItems) => {
|
|
|
139
138
|
}
|
|
140
139
|
};
|
|
141
140
|
const whats = 'Elements are Tab-focusable but not operable or vice versa';
|
|
142
|
-
|
|
143
|
-
return doTest(
|
|
141
|
+
return await doTest(
|
|
144
142
|
page, withItems, 'focAndOp', 'body *', whats, 2, null, getBadWhat.toString()
|
|
145
143
|
);
|
|
146
144
|
};
|
package/testaro/focInd.js
CHANGED
|
@@ -50,7 +50,6 @@ const {doTest} = require('../procs/testaro');
|
|
|
50
50
|
|
|
51
51
|
// Runs the test and returns the result.
|
|
52
52
|
exports.reporter = async (page, withItems) => {
|
|
53
|
-
// Define a violation function for execution in the browser.
|
|
54
53
|
const getBadWhat = element => {
|
|
55
54
|
// Get whether the element is visible.
|
|
56
55
|
const isVisible = element.checkVisibility({
|
|
@@ -108,8 +107,7 @@ exports.reporter = async (page, withItems) => {
|
|
|
108
107
|
}
|
|
109
108
|
};
|
|
110
109
|
const whats = 'Elements fail to have standard focus indicators';
|
|
111
|
-
|
|
112
|
-
return doTest(
|
|
110
|
+
return await doTest(
|
|
113
111
|
page, withItems, 'focInd', 'body *', whats, 1, null, getBadWhat.toString()
|
|
114
112
|
);
|
|
115
113
|
};
|
package/testaro/focVis.js
CHANGED
|
@@ -29,45 +29,33 @@
|
|
|
29
29
|
This test reports links that are at least partly off the display when focused.
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// IMPORTS
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
const {init, getRuleResult} = require('../procs/testaro');
|
|
34
|
+
const {doTest} = require('../procs/testaro');
|
|
36
35
|
|
|
37
|
-
//
|
|
36
|
+
// FUNCTIONS
|
|
38
37
|
|
|
39
|
-
// Runs the test and returns the result.
|
|
40
38
|
exports.reporter = async (page, withItems) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
param = 'above and to the left of';
|
|
39
|
+
const getBadWhat = element => {
|
|
40
|
+
const isVisible = element.checkVisibility({
|
|
41
|
+
contentVisibilityAuto: true,
|
|
42
|
+
opacityProperty: true,
|
|
43
|
+
visibilityProperty: true
|
|
44
|
+
});
|
|
45
|
+
// If the element is visible:
|
|
46
|
+
if (isVisible) {
|
|
47
|
+
// Focus it.
|
|
48
|
+
element.focus();
|
|
49
|
+
const box = element.getBoundingClientRect();
|
|
50
|
+
// If it violates the rule:
|
|
51
|
+
if (box.x < 0 || box.y < 0) {
|
|
52
|
+
// Return a violation description.
|
|
53
|
+
return 'Upper left corner of the element is above or to the left of the display';
|
|
57
54
|
}
|
|
58
|
-
else if (isBad[0]) {
|
|
59
|
-
param = 'to the left of';
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
param = 'above';
|
|
63
|
-
}
|
|
64
|
-
all.locs.push([loc, param]);
|
|
65
55
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
'
|
|
70
|
-
|
|
71
|
-
];
|
|
72
|
-
return await getRuleResult(withItems, all, 'focVis', whats, 2);
|
|
56
|
+
};
|
|
57
|
+
const whats = 'Visible links are above or to the left of the display';
|
|
58
|
+
return await doTest(
|
|
59
|
+
page, withItems, 'focVis', 'a', whats, 2, 'A', getBadWhat.toString()
|
|
60
|
+
);
|
|
73
61
|
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
© 2021–2024 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
|
+
© 2025 Jonathan Robert Pool. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
hover
|
|
28
|
+
This test reports unexpected impacts of hovering. The elements that are subjected to hovering
|
|
29
|
+
(called “triggers”) include all the elements that have ARIA attributes associated with control
|
|
30
|
+
over the visibility of other elements and all the elements that have onmouseenter or
|
|
31
|
+
onmouseover attributes, as well as a sample of all visible elements in the body. If hovering over
|
|
32
|
+
an element results in an increase or decrease in the total count of visible elements in the body,
|
|
33
|
+
the rule is considered violated.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// IMPORTS
|
|
37
|
+
|
|
38
|
+
const {doTest} = require('../procs/testaro');
|
|
39
|
+
|
|
40
|
+
// FUNCTIONS
|
|
41
|
+
|
|
42
|
+
exports.reporter = async (page, withItems) => {
|
|
43
|
+
const getBadWhat = element => {
|
|
44
|
+
let violationDescription;
|
|
45
|
+
const hoverEvent = new MouseEvent('mouseover', {
|
|
46
|
+
bubbles: true,
|
|
47
|
+
cancelable: true,
|
|
48
|
+
view: window
|
|
49
|
+
});
|
|
50
|
+
let timer;
|
|
51
|
+
// Create a mutation observer.
|
|
52
|
+
const observer = new MutationObserver(mutations => {
|
|
53
|
+
// When any mutation occurs in any other element(s):
|
|
54
|
+
const otherMutatedRecords = mutations.filter(
|
|
55
|
+
record => record.target !== element && record.target.getAttribute('role') !== 'tooltip'
|
|
56
|
+
);
|
|
57
|
+
// Update the count of mutated elements and the violation description.
|
|
58
|
+
const impactCount = otherMutatedRecords.length;
|
|
59
|
+
const impactWhat = impactCount === 1 ? '1 other element1' : `${impactCount} other elements`;
|
|
60
|
+
violationDescription = `Hovering over the element adds, removes, or changes ${impactWhat}`;
|
|
61
|
+
// Stop the observer.
|
|
62
|
+
observer.disconnect();
|
|
63
|
+
// Clear the timer.
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
});
|
|
66
|
+
// Ensure that the mouse is in the home position.
|
|
67
|
+
document.body.dispatchEvent(hoverEvent);
|
|
68
|
+
// Start observing.
|
|
69
|
+
observer.observe(document.body, {
|
|
70
|
+
attributes: true,
|
|
71
|
+
subtree: true,
|
|
72
|
+
childList: true
|
|
73
|
+
});
|
|
74
|
+
// Start hovering over the element.
|
|
75
|
+
element.dispatchEvent(hoverEvent);
|
|
76
|
+
// In case no other elements were mutated within 200ms, stop the observer.
|
|
77
|
+
timer = setTimeout(() => {
|
|
78
|
+
observer.disconnect();
|
|
79
|
+
}, 200);
|
|
80
|
+
// If any other elements were mutated within 200ms:
|
|
81
|
+
if (violationDescription) {
|
|
82
|
+
// Return the violation description.
|
|
83
|
+
return violationDescription;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const selector = [
|
|
87
|
+
'[aria-controls]',
|
|
88
|
+
'[aria-expanded]',
|
|
89
|
+
'[aria-haspopup]',
|
|
90
|
+
'[onmouseenter]',
|
|
91
|
+
'[onmouseover]',
|
|
92
|
+
'[onmouseenter]',
|
|
93
|
+
'[onmouseover]',
|
|
94
|
+
'[role="menu"]',
|
|
95
|
+
'[role="menubar"]',
|
|
96
|
+
'[role="menuitem"]',
|
|
97
|
+
'[data-tooltip]',
|
|
98
|
+
'[data-popover]',
|
|
99
|
+
'[data-hover]',
|
|
100
|
+
'[data-menu]',
|
|
101
|
+
'[data-dropdown]',
|
|
102
|
+
'[role="tab"]',
|
|
103
|
+
'[role="combobox"]',
|
|
104
|
+
'li'
|
|
105
|
+
].join(', ');
|
|
106
|
+
const whats = 'Hovering over elements adds, removes, or changes other elements';
|
|
107
|
+
return await doTest(
|
|
108
|
+
page, withItems, 'hover', selector, whats, 0, '', getBadWhat.toString()
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
© 2021–2024 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
|
+
© 2025 Jonathan Robert Pool. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
hover
|
|
28
|
+
This test reports unexpected impacts of hovering. The elements that are subjected to hovering
|
|
29
|
+
(called “triggers”) include all the elements that have ARIA attributes associated with control
|
|
30
|
+
over the visibility of other elements and all the elements that have onmouseenter or
|
|
31
|
+
onmouseover attributes, as well as a sample of all visible elements in the body. If hovering over
|
|
32
|
+
an element results in an increase or decrease in the total count of visible elements in the body,
|
|
33
|
+
the rule is considered violated.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// IMPORTS
|
|
37
|
+
|
|
38
|
+
const {doTest} = require('../procs/testaro');
|
|
39
|
+
|
|
40
|
+
// FUNCTIONS
|
|
41
|
+
|
|
42
|
+
exports.reporter = async (page, withItems) => {
|
|
43
|
+
const getBadWhat = async element => {
|
|
44
|
+
const isVisible = element.checkVisibility({
|
|
45
|
+
contentVisibilityAuto: true,
|
|
46
|
+
opacityProperty: true,
|
|
47
|
+
visibilityProperty: true
|
|
48
|
+
});
|
|
49
|
+
// If the element is visible and is not a tooltip:
|
|
50
|
+
if (isVisible && element.getAttribute('role') !== 'tooltip') {
|
|
51
|
+
let timer;
|
|
52
|
+
let observer;
|
|
53
|
+
const options = {
|
|
54
|
+
bubbles: true,
|
|
55
|
+
cancelable: true,
|
|
56
|
+
view: window
|
|
57
|
+
};
|
|
58
|
+
const hoverEvents = [
|
|
59
|
+
new MouseEvent('mouseover', options),
|
|
60
|
+
new MouseEvent('mousemove', options),
|
|
61
|
+
new PointerEvent('pointerover', options),
|
|
62
|
+
new PointerEvent('pointermove', options)
|
|
63
|
+
];
|
|
64
|
+
const {__lastHoveredElement} = window;
|
|
65
|
+
// Exit the prior hover location, if any.
|
|
66
|
+
if (__lastHoveredElement) {
|
|
67
|
+
[
|
|
68
|
+
[MouseEvent, 'mouseout', true],
|
|
69
|
+
[MouseEvent, 'mouseleave', false],
|
|
70
|
+
[PointerEvent, 'pointerout', true],
|
|
71
|
+
[PointerEvent, 'pointerleave', false]
|
|
72
|
+
].forEach(([event, type, bubbles]) => {
|
|
73
|
+
__lastHoveredElement.dispatchEvent(new event(type, {bubbles}));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Allow time for handlers of these events to complete execution.
|
|
77
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
78
|
+
// Check whether the visibility of the element was due solely to the prior hovering.
|
|
79
|
+
const isStillVisible = element.checkVisibility({
|
|
80
|
+
contentVisibilityAuto: true,
|
|
81
|
+
opacityProperty: true,
|
|
82
|
+
visibilityProperty: true
|
|
83
|
+
});
|
|
84
|
+
// If so:
|
|
85
|
+
if (isStillVisible) {
|
|
86
|
+
const observationStart = Date.now();
|
|
87
|
+
// Execute a Promise that resolves when a mutation is observed.
|
|
88
|
+
const mutationPromise = new Promise(resolve => {
|
|
89
|
+
// When mutations are observed:
|
|
90
|
+
observer = new MutationObserver(mutationRecords => {
|
|
91
|
+
const otherMutationRecords = mutationRecords.filter(record => {
|
|
92
|
+
const {target, type} = record;
|
|
93
|
+
return type !== 'childList'
|
|
94
|
+
&& target !== element
|
|
95
|
+
&& target.getAttribute('role') !== 'tooltip';
|
|
96
|
+
});
|
|
97
|
+
// If any are reportable:
|
|
98
|
+
if (otherMutationRecords.length) {
|
|
99
|
+
// Get a non-duplicative set of their types and XPaths.
|
|
100
|
+
const impacts = new Set();
|
|
101
|
+
otherMutationRecords.forEach(record => {
|
|
102
|
+
const {attributeName, target, type} = record;
|
|
103
|
+
const xPath = getXPath(target);
|
|
104
|
+
const attributeSuffix = attributeName ? `:${attributeName}` : '';
|
|
105
|
+
const textStart = target.textContent?.slice(0, 20).trim().replace(/\s+/g, ' ') || '';
|
|
106
|
+
impacts.add(`${type}${attributeSuffix}@${xPath} (“${textStart}”)`);
|
|
107
|
+
});
|
|
108
|
+
const impactTime = Math.round(Date.now() - observationStart);
|
|
109
|
+
// Create a violation description with the elapsed time and the mutation details.
|
|
110
|
+
const violationWhat = `Hovering over the element makes these changes after ${impactTime}ms: ${Array.from(impacts).join(', ')}`;
|
|
111
|
+
// Clear the timer.
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
// Stop the observer.
|
|
114
|
+
observer.disconnect();
|
|
115
|
+
// Resolve the Promise with the violation description.
|
|
116
|
+
resolve(violationWhat);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
let observationRoot = element.parentElement.parentElement;
|
|
120
|
+
const rootTagName = observationRoot.tagName;
|
|
121
|
+
if (['MAIN', 'BODY'].includes(rootTagName)) {
|
|
122
|
+
observationRoot = element.parentElement;
|
|
123
|
+
}
|
|
124
|
+
// Start observing.
|
|
125
|
+
observer.observe(observationRoot, {
|
|
126
|
+
attributes: true,
|
|
127
|
+
attributeFilter: ['style', 'class', 'hidden', 'aria-hidden', 'disabled', 'open'],
|
|
128
|
+
subtree: true,
|
|
129
|
+
childList: true
|
|
130
|
+
});
|
|
131
|
+
// Start hovering over the element.
|
|
132
|
+
hoverEvents.forEach(event => {
|
|
133
|
+
element.dispatchEvent(event);
|
|
134
|
+
});
|
|
135
|
+
// Record the element for future mouseout events.
|
|
136
|
+
window.__lastHoveredElement = element;
|
|
137
|
+
});
|
|
138
|
+
// Execute a Promise that resolves when a time limit expires.
|
|
139
|
+
const timeoutPromise = new Promise(resolve => {
|
|
140
|
+
// If no mutation is observed before the time limit:
|
|
141
|
+
timer = setTimeout(() => {
|
|
142
|
+
// Stop the observer.
|
|
143
|
+
observer.disconnect();
|
|
144
|
+
// Resolve the Promise with an empty string.
|
|
145
|
+
resolve('');
|
|
146
|
+
}, 400);
|
|
147
|
+
});
|
|
148
|
+
// Get the violation description or timeout report.
|
|
149
|
+
const violationWhat = await Promise.race([mutationPromise, timeoutPromise]);
|
|
150
|
+
// If any mutations occurred before the time limit:
|
|
151
|
+
if (violationWhat) {
|
|
152
|
+
// Return the violation description.
|
|
153
|
+
return violationWhat;
|
|
154
|
+
}
|
|
155
|
+
//XXX Temp
|
|
156
|
+
return 'No mutations';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const selector = [
|
|
161
|
+
'[aria-controls]',
|
|
162
|
+
'[aria-expanded]',
|
|
163
|
+
'[aria-haspopup]',
|
|
164
|
+
'[onmouseenter]',
|
|
165
|
+
'[onmouseover]',
|
|
166
|
+
'[onmouseenter]',
|
|
167
|
+
'[onmouseover]',
|
|
168
|
+
'[role="menu"]',
|
|
169
|
+
'[role="menubar"]',
|
|
170
|
+
'[role="menuitem"]',
|
|
171
|
+
'[data-tooltip]',
|
|
172
|
+
'[data-popover]',
|
|
173
|
+
'[data-hover]',
|
|
174
|
+
'[data-menu]',
|
|
175
|
+
'[data-dropdown]',
|
|
176
|
+
'[role="tab"]',
|
|
177
|
+
'[role="combobox"]',
|
|
178
|
+
'a',
|
|
179
|
+
'button'
|
|
180
|
+
].join(', ');
|
|
181
|
+
const whats = 'Hovering over elements adds, removes, or changes other elements';
|
|
182
|
+
return await doTest(
|
|
183
|
+
page, withItems, 'hover', selector, whats, 0, '', getBadWhat.toString()
|
|
184
|
+
);
|
|
185
|
+
};
|