From 87cfc0b4f4d998a88a2d534438e4f2ccf9427a86 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Tue, 3 Aug 2021 09:14:18 -0600 Subject: [PATCH] feat(aria-allowed-attr): report violations for non-global ARIA attributes 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 --- lib/checks/aria/aria-allowed-attr-evaluate.js | 2 +- test/checks/aria/allowed-attr.js | 17 +++++++++++++++-- .../rules/aria-allowed-attr/failures.html | 6 ++++++ .../rules/aria-allowed-attr/failures.json | 3 ++- .../virtual-rules/aria-allowed-attr.js | 17 +++++++++++++++-- .../virtual-rules/aria-allowed-role.js | 13 ------------- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/checks/aria/aria-allowed-attr-evaluate.js b/lib/checks/aria/aria-allowed-attr-evaluate.js index 59da14c22a..19775a9528 100644 --- a/lib/checks/aria/aria-allowed-attr-evaluate.js +++ b/lib/checks/aria/aria-allowed-attr-evaluate.js @@ -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)) { diff --git a/test/checks/aria/allowed-attr.js b/test/checks/aria/allowed-attr.js index cbba61b843..e63e64bbb9 100644 --- a/test/checks/aria/allowed-attr.js +++ b/test/checks/aria/allowed-attr.js @@ -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( - '
' + '
' ); assert.isTrue( @@ -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( + '
' + ); + + 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( '' diff --git a/test/integration/rules/aria-allowed-attr/failures.html b/test/integration/rules/aria-allowed-attr/failures.html index f4839431e7..0f77954a3f 100644 --- a/test/integration/rules/aria-allowed-attr/failures.html +++ b/test/integration/rules/aria-allowed-attr/failures.html @@ -28,3 +28,9 @@ + diff --git a/test/integration/rules/aria-allowed-attr/failures.json b/test/integration/rules/aria-allowed-attr/failures.json index 6b48f87d29..bbc6f0a214 100644 --- a/test/integration/rules/aria-allowed-attr/failures.json +++ b/test/integration/rules/aria-allowed-attr/failures.json @@ -30,6 +30,7 @@ ["#fail26"], ["#fail27"], ["#fail28"], - ["#fail29"] + ["#fail29"], + ["#fail30"] ] } diff --git a/test/integration/virtual-rules/aria-allowed-attr.js b/test/integration/virtual-rules/aria-allowed-attr.js index dab04984fb..d25619137d 100644 --- a/test/integration/virtual-rules/aria-allowed-attr.js +++ b/test/integration/virtual-rules/aria-allowed-attr.js @@ -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 } }); @@ -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', diff --git a/test/integration/virtual-rules/aria-allowed-role.js b/test/integration/virtual-rules/aria-allowed-role.js index 8d2fcdd947..9b579e56e3 100644 --- a/test/integration/virtual-rules/aria-allowed-role.js +++ b/test/integration/virtual-rules/aria-allowed-role.js @@ -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',