Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dpub): upgrade to DPUB 1.1 and report deprecated roles #3280

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 56 additions & 56 deletions doc/rule-descriptions.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions lib/checks/aria/deprecatedrole-evaluate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import standards from '../../standards';
import { getRole } from '../../commons/aria';

/**
* Check that an elements semantic role is deprecated.
*
* Deprecated roles are taken from the `ariaRoles` standards object from the roles `deprecated` property.
*
* @memberof checks
* @return {Boolean} True if the elements semantic role is deprecated. False otherwise.
*/
export default function deprecatedroleEvaluate(node, options, virtualNode) {
const role = getRole(virtualNode, { dpub: true });
straker marked this conversation as resolved.
Show resolved Hide resolved
const roleDefinition = standards.ariaRoles[role];
if (!roleDefinition?.deprecated) {
return false;
}

this.data(role);
return true;
}
11 changes: 11 additions & 0 deletions lib/checks/aria/deprecatedrole.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "deprecatedrole",
"evaluate": "deprecatedrole-evaluate",
"metadata": {
"impact": "minor",
straker marked this conversation as resolved.
Show resolved Hide resolved
"messages": {
"pass": "ARIA role is deprecated",
WilcoFiers marked this conversation as resolved.
Show resolved Hide resolved
"fail": "The role used deprecated: ${data.values}"
WilcoFiers marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
2 changes: 2 additions & 0 deletions lib/core/base/metadata-function-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ariaRoledescriptionEvaluate from '../../checks/aria/aria-roledescription-
import ariaUnsupportedAttrEvaluate from '../../checks/aria/aria-unsupported-attr-evaluate';
import ariaValidAttrEvaluate from '../../checks/aria/aria-valid-attr-evaluate';
import ariaValidAttrValueEvaluate from '../../checks/aria/aria-valid-attr-value-evaluate';
import deprecatedroleEvaluate from '../../checks/aria/deprecatedrole-evaluate';
import fallbackroleEvaluate from '../../checks/aria/fallbackrole-evaluate';
import hasGlobalAriaAttributeEvaluate from '../../checks/aria/has-global-aria-attribute-evaluate';
import hasImplicitChromiumRoleMatches from '../../rules/has-implicit-chromium-role-matches';
Expand Down Expand Up @@ -191,6 +192,7 @@ const metadataFunctionMap = {
'aria-unsupported-attr-evaluate': ariaUnsupportedAttrEvaluate,
'aria-valid-attr-evaluate': ariaValidAttrEvaluate,
'aria-valid-attr-value-evaluate': ariaValidAttrValueEvaluate,
'deprecatedrole-evaluate': deprecatedroleEvaluate,
'fallbackrole-evaluate': fallbackroleEvaluate,
'has-global-aria-attribute-evaluate': hasGlobalAriaAttributeEvaluate,
'has-implicit-chromium-role-matches': hasImplicitChromiumRoleMatches,
Expand Down
8 changes: 7 additions & 1 deletion lib/rules/aria-roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
},
"all": [],
"any": [],
"none": ["fallbackrole", "invalidrole", "abstractrole", "unsupportedrole"]
"none": [
"fallbackrole",
"invalidrole",
"abstractrole",
"unsupportedrole",
"deprecatedrole"
]
}
11 changes: 4 additions & 7 deletions lib/standards/dpub-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ const dpubRoles = {
},
'doc-biblioentry': {
type: 'listitem',
requiredContext: ['doc-bibliography'],
allowedAttrs: [
'aria-expanded',
'aria-level',
'aria-posinset',
'aria-setsize'
],
superclassRole: ['listitem']
superclassRole: ['listitem'],
deprecated: true
},
'doc-bibliography': {
type: 'landmark',
requiredOwned: ['doc-biblioentry'],
allowedAttrs: ['aria-expanded'],
superclassRole: ['landmark']
},
Expand Down Expand Up @@ -86,7 +85,6 @@ const dpubRoles = {
},
'doc-endnote': {
type: 'listitem',
requiredContext: ['doc-endnotes'],
allowedAttrs: [
'aria-expanded',
'aria-level',
Expand All @@ -97,9 +95,9 @@ const dpubRoles = {
},
'doc-endnotes': {
type: 'landmark',
requiredOwned: ['doc-endnote'],
allowedAttrs: ['aria-expanded'],
superclassRole: ['landmark']
superclassRole: ['landmark'],
deprecated: true
},
'doc-epigraph': {
type: 'section',
Expand Down Expand Up @@ -133,7 +131,6 @@ const dpubRoles = {
},
'doc-glossary': {
type: 'landmark',
requiredOwned: ['definition', 'term'],
allowedAttrs: ['aria-expanded'],
superclassRole: ['landmark']
},
Expand Down
58 changes: 58 additions & 0 deletions test/checks/aria/deprecatedrole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
describe('deprecatedrole', function() {
'use strict';

var checkContext = axe.testUtils.MockCheckContext();
var checkSetup = axe.testUtils.checkSetup;
var checkEvaluate = axe.testUtils.getCheckEvaluate('deprecatedrole');
afterEach(function () {
checkContext.reset();
})

it('should return true if applied to a deprecated role', function() {
axe.configure({
standards: {
ariaRoles: {
melon: {
type: 'widget',
deprecated: true
}
}
}
});
var params = checkSetup('<div id="target" role="melon">Contents</div>');
assert.isTrue(checkEvaluate.apply(checkContext, params));
assert.deepEqual(checkContext._data, 'melon');
});

it('should return true if applied to a deprecated DPUB role', function() {
axe.configure({
standards: {
ariaRoles: {
'doc-fizzbuzz': {
type: 'widget',
deprecated: true
}
}
}
});
var params = checkSetup('<div id="target" role="doc-fizzbuzz">Contents</div>');
assert.isTrue(checkEvaluate.apply(checkContext, params));
assert.deepEqual(checkContext._data, 'doc-fizzbuzz');
});

it('should return false if applied to a non-deprecated role', function() {
var params = checkSetup('<div id="target" role="button">Contents</div>');
assert.isFalse(checkEvaluate.apply(checkContext, params));
assert.isNull(checkContext._data);

var params = checkSetup('<button id="target">Contents</button>');
assert.isFalse(checkEvaluate.apply(checkContext, params));
assert.isNull(checkContext._data);
});

it('should return false if applied to an invalid role', function() {
var params = checkSetup('<input id="target" role="foo">');
assert.isFalse(checkEvaluate.apply(checkContext, params));
assert.isNull(checkContext._data);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<div role="tree" id="incomplete6"></div>
<div role="treegrid" id="incomplete7"></div>
<div role="rowgroup" id="incomplete8"></div>
<div role="doc-bibliography" id="incomplete9"></div>
<div role="doc-endnotes" id="incomplete10"></div>
<div role="listbox" id="incomplete11">
<div role="listbox" id="incomplete9">
<div></div>
</div>
<div role="list" id="fail6">
Expand Down Expand Up @@ -68,3 +66,6 @@
<div role="option">option</div>
</div>
</div>

<div role="doc-bibliography" id="inapplicable1"></div>
<div role="doc-endnotes" id="inapplicable2"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
["#incomplete6"],
["#incomplete7"],
["#incomplete8"],
["#incomplete9"],
["#incomplete10"],
["#incomplete11"]
["#incomplete9"]
]
}
5 changes: 3 additions & 2 deletions test/integration/rules/aria-roles/aria-roles.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<div role="doc-afterword" id="pass72">ok</div>
<div role="doc-appendix" id="pass73">ok</div>
<div role="doc-backlink" id="pass74">ok</div>
<div role="doc-biblioentry" id="pass75">ok</div>
<div role="doc-bibliography" id="pass76">ok</div>
<div role="doc-biblioref" id="pass77">ok</div>
<div role="doc-chapter" id="pass78">ok</div>
Expand All @@ -83,7 +82,6 @@
<div role="doc-credits" id="pass83">ok</div>
<div role="doc-dedication" id="pass84">ok</div>
<div role="doc-endnote" id="pass85">ok</div>
<div role="doc-endnotes" id="pass86">ok</div>
<div role="doc-epigraph" id="pass87">ok</div>
<div role="doc-epilogue" id="pass88">ok</div>
<div role="doc-errata" id="pass89">ok</div>
Expand Down Expand Up @@ -134,6 +132,9 @@
<!-- unsupported roles -->
<!-- fallback roles -->
<div role="button alert" id="fail14">fail</div>
<!-- deprecated roles-->
<div role="doc-biblioentry" id="fail15">fail</div>
<div role="doc-endnotes" id="fail16">fail</div>
</div>

<!-- inapplicable -->
Expand Down
6 changes: 3 additions & 3 deletions test/integration/rules/aria-roles/aria-roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
["#fail11"],
["#fail12"],
["#fail13"],
["#fail14"]
["#fail14"],
["#fail15"],
["#fail16"]
],
"passes": [
["#pass1"],
Expand Down Expand Up @@ -91,7 +93,6 @@
["#pass72"],
["#pass73"],
["#pass74"],
["#pass75"],
["#pass76"],
["#pass77"],
["#pass78"],
Expand All @@ -102,7 +103,6 @@
["#pass83"],
["#pass84"],
["#pass85"],
["#pass86"],
["#pass87"],
["#pass88"],
["#pass89"],
Expand Down