Skip to content

Commit 289f623

Browse files
authored
fix: Do not require media captions / descriptions (#1075)
Do not require media captions / descriptions Closes #816 ## Reviewer checks **Required fields, to be filled out by PR reviewer(s)** - [x] Follows the commit message policy, appropriate for next version - [x] Has documentation updated, a DU ticket, or requires no documentation change - [x] Includes new tests, or was unnecessary - [x] Code is reviewed for security by: @JKODU
1 parent 01536dd commit 289f623

File tree

11 files changed

+54
-50
lines changed

11 files changed

+54
-50
lines changed

build/tasks/validate.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ function hasUniqueId() {
2727
};
2828
}
2929

30+
function hasMultipleOutcomes(messages) {
31+
const keys = Object.keys(messages);
32+
if (keys.length < 2) {
33+
return false;
34+
}
35+
36+
return keys.every(key => {
37+
switch (key) {
38+
case 'pass':
39+
case 'fail':
40+
return typeof messages[key] === 'string';
41+
42+
case 'incomplete':
43+
return ['string', 'object'].includes(typeof messages[key]);
44+
45+
default:
46+
return false;
47+
}
48+
});
49+
}
50+
3051
function createSchemas() {
3152
var schemas = {};
3253

@@ -84,15 +105,9 @@ function createSchemas() {
84105
messages: {
85106
required: true,
86107
type: 'object',
87-
properties: {
88-
fail: {
89-
required: true,
90-
type: 'string'
91-
},
92-
pass: {
93-
required: true,
94-
type: 'string'
95-
}
108+
conform: hasMultipleOutcomes,
109+
messages: {
110+
conform: 'Must have at least two valid messages'
96111
}
97112
},
98113
impact: {

lib/checks/media/caption.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
var tracks = axe.utils.querySelectorAll(virtualNode, 'track');
1+
const tracks = axe.utils.querySelectorAll(virtualNode, 'track');
2+
const hasCaptions = tracks.some(
3+
({ actualNode }) =>
4+
(actualNode.getAttribute('kind') || '').toLowerCase() === 'captions'
5+
);
26

3-
if (tracks.length) {
4-
// return false if any track has kind === 'caption'
5-
return !tracks.some(
6-
({ actualNode }) =>
7-
(actualNode.getAttribute('kind') || '').toLowerCase() === 'captions'
8-
);
9-
}
10-
// Undefined if there are no tracks - media may be decorative
11-
return undefined;
7+
// Undefined if there are no tracks - media may use another caption method
8+
return hasCaptions ? false : undefined;

lib/checks/media/caption.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"impact": "critical",
66
"messages": {
77
"pass": "The multimedia element has a captions track",
8-
"fail": "The multimedia element does not have a captions track",
9-
"incomplete": "A captions track for this element could not be found"
8+
"incomplete": "Check that captions is available for the element"
109
}
1110
}
1211
}

lib/checks/media/description.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
var tracks = axe.utils.querySelectorAll(virtualNode, 'track');
1+
const tracks = axe.utils.querySelectorAll(virtualNode, 'track');
2+
const hasDescriptions = tracks.some(
3+
({ actualNode }) =>
4+
(actualNode.getAttribute('kind') || '').toLowerCase() === 'descriptions'
5+
);
26

3-
if (tracks.length) {
4-
// return false if any track has kind === 'description'
5-
var out = !tracks.some(
6-
({ actualNode }) =>
7-
(actualNode.getAttribute('kind') || '').toLowerCase() === 'descriptions'
8-
);
9-
return out;
10-
}
11-
// Undefined if there are no tracks - media may be decorative
12-
return undefined;
7+
// Undefined if there are no tracks - media may have another description method
8+
return hasDescriptions ? false : undefined;

lib/checks/media/description.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"impact": "critical",
66
"messages": {
77
"pass": "The multimedia element has an audio description track",
8-
"fail": "The multimedia element does not have an audio description track",
9-
"incomplete": "An audio description track for this element could not be found"
8+
"incomplete": "Check that audio description is available for the element"
109
}
1110
}
1211
}

test/checks/media/caption.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ describe('caption', function() {
1414
assert.isUndefined(checks.caption.evaluate.apply(null, checkArgs));
1515
});
1616

17-
it('should fail if there is no kind=captions attribute', function() {
17+
it('should return undefined if there is no kind=captions attribute', function() {
1818
var checkArgs = checkSetup(
1919
'<audio><track kind=descriptions></audio>',
2020
'audio'
2121
);
22-
assert.isTrue(checks.caption.evaluate.apply(null, checkArgs));
22+
assert.isUndefined(checks.caption.evaluate.apply(null, checkArgs));
2323
});
2424

25-
it('should fail if there is no kind attribute', function() {
25+
it('should return undefined if there is no kind attribute', function() {
2626
var checkArgs = checkSetup('<video><track></video>', 'video');
27-
assert.isTrue(checks.description.evaluate.apply(null, checkArgs));
27+
assert.isUndefined(checks.description.evaluate.apply(null, checkArgs));
2828
});
2929

3030
it('should pass if there is a kind=captions attribute', function() {
@@ -36,12 +36,12 @@ describe('caption', function() {
3636
'should get track from composed tree',
3737
function() {
3838
var node = document.createElement('div');
39-
node.innerHTML = '<track kind=descriptions>';
39+
node.innerHTML = '<track kind=captions>';
4040
var shadow = node.attachShadow({ mode: 'open' });
4141
shadow.innerHTML = '<audio><slot></slot></audio>';
4242

4343
var checkArgs = checkSetup(node, {}, 'audio');
44-
assert.isTrue(checks.caption.evaluate.apply(null, checkArgs));
44+
assert.isFalse(checks.caption.evaluate.apply(null, checkArgs));
4545
}
4646
);
4747
});

test/checks/media/description.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ describe('description', function() {
1313
assert.isUndefined(checks.description.evaluate.apply(null, checkArgs));
1414
});
1515

16-
it('should fail if there is no kind=captions attribute', function() {
16+
it('should return undefined if there is no kind=captions attribute', function() {
1717
var checkArgs = checkSetup('<video><track kind=captions></video>', 'video');
18-
assert.isTrue(checks.description.evaluate.apply(null, checkArgs));
18+
assert.isUndefined(checks.description.evaluate.apply(null, checkArgs));
1919
});
2020

21-
it('should fail if there is no kind attribute', function() {
21+
it('should return undefined if there is no kind attribute', function() {
2222
var checkArgs = checkSetup('<video><track></video>', 'video');
23-
assert.isTrue(checks.description.evaluate.apply(null, checkArgs));
23+
assert.isUndefined(checks.description.evaluate.apply(null, checkArgs));
2424
});
2525

2626
it('should pass if there is a kind=descriptions attribute', function() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<video id="incomplete1"></video>
2-
<video id="fail1"><track kind="descriptions"></video>
2+
<video id="incomplete2"><track kind="descriptions"></video>
33
<video id="pass1"><track kind="captions"></video>
44
<video id="pass2"><track kind="descriptions"><track kind="captions"></video>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"description": "video-caption test",
33
"rule": "video-caption",
4-
"incomplete": [["#incomplete1"]],
5-
"violations": [["#fail1"]],
4+
"incomplete": [["#incomplete1"], ["#incomplete2"]],
65
"passes": [["#pass1"], ["#pass2"]]
76
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
<video id="incomplete1"></video>
3-
<video id="fail1"><track kind="captions"></video>
3+
<video id="incomplete2"><track kind="captions"></video>
44
<video id="pass1"><track kind="descriptions"></video>
55
<video id="pass2"><track kind="descriptions"><track kind="captions"></video>

0 commit comments

Comments
 (0)