Skip to content

Commit

Permalink
feat(dpub): upgrade to DPUB 1.1 and report deprecated roles (#3280)
Browse files Browse the repository at this point in the history
* feat(dpub): upgrade to DPUB 1.1 and report deprecated roles

* Apply suggestions from code review

Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>

* Handle fallback roles

Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
  • Loading branch information
WilcoFiers and straker authored Nov 15, 2021
1 parent ce4dfaf commit 034a846
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 75 deletions.
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, fallback: true });
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",
"messages": {
"pass": "ARIA role is not deprecated",
"fail": "The role used is deprecated: ${data.values}"
}
}
}
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
93 changes: 93 additions & 0 deletions test/checks/aria/deprecatedrole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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();
axe.reset();
})

it('returns 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('returns 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('returns 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('returns 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);
});

describe('with fallback roles', function () {
it('returns true if the deprecated role is the first valid role', function () {
axe.configure({
standards: {
ariaRoles: {
melon: {
type: 'widget',
deprecated: true
}
}
}
});
var params = checkSetup('<div id="target" role="foo widget melon button">Contents</div>');
assert.isTrue(checkEvaluate.apply(checkContext, params));
assert.deepEqual(checkContext._data, 'melon');
})

it('returns false if the deprecated role is not the first valid role', function () {
axe.configure({
standards: {
ariaRoles: {
melon: {
type: 'widget',
deprecated: true
}
}
}
});
var params = checkSetup('<div id="target" role="button melon widget">Contents</div>');
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

0 comments on commit 034a846

Please sign in to comment.