Skip to content

Commit

Permalink
feat(aria-allowed-attr): report violations for non-global ARIA attrib…
Browse files Browse the repository at this point in the history
…utes on elements without a role (#3102)

* feat(aria-allowed-attr): report violations for non-global ARIA attributes on elements without a role

* fix tests

* remove wrong test
  • Loading branch information
straker authored Aug 3, 2021
1 parent 99dbb99 commit 87cfc0b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/checks/aria/aria-allowed-attr-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function ariaAllowedAttrEvaluate(node, options, virtualNode) {
allowed = uniqueArray(options[role].concat(allowed));
}

if (role && allowed) {
if (allowed) {
for (let i = 0; i < attrs.length; i++) {
const attrName = attrs[i];
if (validateAttr(attrName) && !allowed.includes(attrName)) {
Expand Down
17 changes: 15 additions & 2 deletions test/checks/aria/allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('aria-allowed-attr', function() {
assert.deepEqual(checkContext._data, ['aria-selected="true"']);
});

it('should return true if there is no role', function() {
it('should return true for global attributes if there is no role', function() {
var vNode = queryFixture(
'<div id="target" tabindex="1" aria-selected="true" aria-checked="true"></div>'
'<div id="target" tabindex="1" aria-busy="true" aria-owns="foo"></div>'
);

assert.isTrue(
Expand All @@ -59,6 +59,19 @@ describe('aria-allowed-attr', function() {
assert.isNull(checkContext._data);
});

it('should return false for non-global attributes if there is no role', function() {
var vNode = queryFixture(
'<div id="target" tabindex="1" aria-selected="true" aria-owns="foo"></div>'
);

assert.isFalse(
axe.testUtils
.getCheckEvaluate('aria-allowed-attr')
.call(checkContext, null, null, vNode)
);
assert.deepEqual(checkContext._data, ['aria-selected="true"']);
});

it('should not report on invalid attributes', function() {
var vNode = queryFixture(
'<div role="dialog" id="target" tabindex="1" aria-cats="true"></div>'
Expand Down
6 changes: 6 additions & 0 deletions test/integration/rules/aria-allowed-attr/failures.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@
<kbd aria-label="value" id="fail27"></kbd>
<abbr aria-label="value" id="fail28"></abbr>
<custom-elm aria-label="value" id="fail29"></custom-elm>
<audio
src="/test/assets/moon-speech.mp3"
controls
aria-orientation="horizontal"
id="fail30"
></audio>
3 changes: 2 additions & 1 deletion test/integration/rules/aria-allowed-attr/failures.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
["#fail26"],
["#fail27"],
["#fail28"],
["#fail29"]
["#fail29"],
["#fail30"]
]
}
17 changes: 15 additions & 2 deletions test/integration/virtual-rules/aria-allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe('aria-allowed-attr virtual-rule', function() {
assert.lengthOf(results.incomplete, 0);
});

it('should pass for element with no role', function() {
it('should pass for global attributes and element with no role', function() {
var results = axe.runVirtualRule('aria-allowed-attr', {
nodeName: 'div',
attributes: {
'aria-checked': true
'aria-busy': true
}
});

Expand All @@ -55,6 +55,19 @@ describe('aria-allowed-attr virtual-rule', function() {
assert.lengthOf(results.incomplete, 0);
});

it('should fail for non-global attributes and element with no role', function() {
var results = axe.runVirtualRule('aria-allowed-attr', {
nodeName: 'div',
attributes: {
'aria-checked': true
}
});

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.incomplete, 0);
});

it('should fail for unallowed attributes', function() {
var results = axe.runVirtualRule('aria-allowed-attr', {
nodeName: 'div',
Expand Down
13 changes: 0 additions & 13 deletions test/integration/virtual-rules/aria-allowed-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ describe('aria-allowed-role virtual-rule', function() {
assert.lengthOf(results.incomplete, 0);
});

it('should pass for element with no role', function() {
var results = axe.runVirtualRule('aria-allowed-attr', {
nodeName: 'div',
attributes: {
'aria-checked': true
}
});

assert.lengthOf(results.passes, 1);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 0);
});

it('should fail for unallowed role', function() {
var results = axe.runVirtualRule('aria-allowed-role', {
nodeName: 'dd',
Expand Down

0 comments on commit 87cfc0b

Please sign in to comment.