From 69e64cedcf69f1fbe101b435d057b532caae3b53 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Fri, 17 Jul 2020 12:33:41 -0600 Subject: [PATCH 1/2] tests: add serial tests for button-name, input-button-name, aria-toggle-field-name, and aria-input-field-name --- .../virtual-rules/aria-input-field-name.js | 126 +++++++++++++ .../virtual-rules/aria-toggle-field-name.js | 176 ++++++++++++++++++ test/integration/virtual-rules/button-name.js | 156 ++++++++++++++++ test/integration/virtual-rules/index.html | 4 + .../virtual-rules/input-button-name.js | 167 +++++++++++++++++ test/integration/virtual-rules/object-alt.js | 2 +- 6 files changed, 630 insertions(+), 1 deletion(-) create mode 100644 test/integration/virtual-rules/aria-input-field-name.js create mode 100644 test/integration/virtual-rules/aria-toggle-field-name.js create mode 100644 test/integration/virtual-rules/button-name.js create mode 100644 test/integration/virtual-rules/input-button-name.js diff --git a/test/integration/virtual-rules/aria-input-field-name.js b/test/integration/virtual-rules/aria-input-field-name.js new file mode 100644 index 0000000000..e5fd5f544f --- /dev/null +++ b/test/integration/virtual-rules/aria-input-field-name.js @@ -0,0 +1,126 @@ +describe('aria-input-field-name', function() { + it('should pass for aria-label', function() { + var results = axe.runVirtualRule('aria-input-field-name', { + nodeName: 'div', + attributes: { + role: 'combobox', + 'aria-label': 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete for aria-labelledby', function() { + var results = axe.runVirtualRule('aria-input-field-name', { + nodeName: 'div', + attributes: { + role: 'listbox', + 'aria-labelledby': 'foobar' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should pass for title', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'searchbox', + title: 'foobar' + } + }); + // children are required since titleText comes after subtree text + // in accessible name calculation + node.children = []; + + var results = axe.runVirtualRule('aria-input-field-name', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label contains only whitespace', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'spinbutton', + 'aria-label': ' \t \n ' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-input-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'textbox', + 'aria-label': '' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-input-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when title is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'combobox', + title: '' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-input-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete if has explicit and implicit label', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'listbox', + 'aria-label': 'name' + } + }); + var parent = new axe.SerialVirtualNode({ + nodeName: 'label' + }); + var child = new axe.SerialVirtualNode({ + nodeName: '#text', + nodeType: 3, + nodeValue: 'first name' + }); + node.parent = parent; + node.children = []; + parent.children = [child, node]; + + var results = axe.runVirtualRule('aria-input-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); +}); diff --git a/test/integration/virtual-rules/aria-toggle-field-name.js b/test/integration/virtual-rules/aria-toggle-field-name.js new file mode 100644 index 0000000000..cd890a4fc7 --- /dev/null +++ b/test/integration/virtual-rules/aria-toggle-field-name.js @@ -0,0 +1,176 @@ +describe('aria-toggle-field-name', function() { + it('should pass for aria-label', function() { + var results = axe.runVirtualRule('aria-toggle-field-name', { + nodeName: 'div', + attributes: { + role: 'menuitemcheckbox', + 'aria-label': 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete for aria-labelledby', function() { + var results = axe.runVirtualRule('aria-toggle-field-name', { + nodeName: 'div', + attributes: { + role: 'menuitemradio', + 'aria-labelledby': 'foobar' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should pass for title', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'checkbox', + title: 'foobar' + } + }); + // children are required since titleText comes after subtree text + // in accessible name calculation + node.children = []; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for visible text content', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'radio' + } + }); + var child = new axe.SerialVirtualNode({ + nodeName: '#text', + nodeType: 3, + nodeValue: 'foobar' + }); + node.children = [child]; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete when children are missing', function() { + var results = axe.runVirtualRule('aria-toggle-field-name', { + nodeName: 'div', + attributes: { + role: 'switch' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should fail children contain no visible text', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'menuitemcheckbox' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label contains only whitespace', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'menuitemcheckbox', + 'aria-label': ' \t \n ' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'menuitemcheckbox', + 'aria-label': '' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when title is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'menuitemcheckbox', + title: '' + } + }); + node.children = []; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete if has explicit and implicit label', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'div', + attributes: { + role: 'menuitemcheckbox', + 'aria-label': 'name' + } + }); + var parent = new axe.SerialVirtualNode({ + nodeName: 'label' + }); + var child = new axe.SerialVirtualNode({ + nodeName: '#text', + nodeType: 3, + nodeValue: 'first name' + }); + node.parent = parent; + node.children = []; + parent.children = [child, node]; + + var results = axe.runVirtualRule('aria-toggle-field-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); +}); diff --git a/test/integration/virtual-rules/button-name.js b/test/integration/virtual-rules/button-name.js new file mode 100644 index 0000000000..ede4f4b4d5 --- /dev/null +++ b/test/integration/virtual-rules/button-name.js @@ -0,0 +1,156 @@ +describe('button-name', function() { + it('should pass for aria-label', function() { + var results = axe.runVirtualRule('button-name', { + nodeName: 'button', + attributes: { + 'aria-label': 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete for aria-labelledby', function() { + var results = axe.runVirtualRule('button-name', { + nodeName: 'button', + attributes: { + 'aria-labelledby': 'foobar' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should pass for title', function() { + var results = axe.runVirtualRule('button-name', { + nodeName: 'button', + attributes: { + title: 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for role=presentation', function() { + var results = axe.runVirtualRule('button-name', { + nodeName: 'button', + attributes: { + role: 'presentation' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for role=none', function() { + var results = axe.runVirtualRule('button-name', { + nodeName: 'button', + attributes: { + role: 'none' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for visible text content', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'button' + }); + var child = new axe.SerialVirtualNode({ + nodeName: '#text', + nodeType: 3, + nodeValue: 'foobar' + }); + node.children = [child]; + + var results = axe.runVirtualRule('button-name', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete when alt and children are missing', function() { + var results = axe.runVirtualRule('button-name', { + nodeName: 'button', + attributes: {} + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should fail children contain no visible text', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'button' + }); + node.children = []; + + var results = axe.runVirtualRule('button-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when alt contains only whitespace', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'button', + attributes: { + alt: ' \t \n ' + } + }); + node.children = []; + + var results = axe.runVirtualRule('button-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'button', + attributes: { + alt: '' + } + }); + node.children = []; + + var results = axe.runVirtualRule('button-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when title is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'button', + attributes: { + title: '' + } + }); + node.children = []; + + var results = axe.runVirtualRule('button-name', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); +}); diff --git a/test/integration/virtual-rules/index.html b/test/integration/virtual-rules/index.html index f4907ddc1b..2271a81462 100644 --- a/test/integration/virtual-rules/index.html +++ b/test/integration/virtual-rules/index.html @@ -26,6 +26,10 @@ + + + + diff --git a/test/integration/virtual-rules/input-button-name.js b/test/integration/virtual-rules/input-button-name.js new file mode 100644 index 0000000000..889c4938a5 --- /dev/null +++ b/test/integration/virtual-rules/input-button-name.js @@ -0,0 +1,167 @@ +describe('input-button-name', function() { + it('should pass for type=submit without value', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'submit' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for value', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + value: 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for aria-label', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + 'aria-label': 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete for aria-labelledby', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + 'aria-labelledby': 'foobar' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should pass for title', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + title: 'foobar' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for role=presentation', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + role: 'presentation' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for role=none', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + role: 'none' + } + }); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when no other attributes are passed', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when value is empty', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + value: '' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when alt contains only whitespace', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + alt: ' \t \n ' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label is empty', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + 'aria-label': '' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when title is empty', function() { + var results = axe.runVirtualRule('input-button-name', { + nodeName: 'input', + attributes: { + type: 'button', + title: '' + } + }); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); +}); diff --git a/test/integration/virtual-rules/object-alt.js b/test/integration/virtual-rules/object-alt.js index 5782c85c55..f6f53a28eb 100644 --- a/test/integration/virtual-rules/object-alt.js +++ b/test/integration/virtual-rules/object-alt.js @@ -126,7 +126,7 @@ describe('object-alt', function() { var node = new axe.SerialVirtualNode({ nodeName: 'object', attributes: { - alt: '' + 'aria-label': '' } }); node.children = []; From f7534c761cfbd0a45a66fe284f25f1a8c02310f7 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Fri, 17 Jul 2020 13:01:02 -0600 Subject: [PATCH 2/2] add area-alt --- test/integration/virtual-rules/area-alt.js | 152 +++++++++++++++++++++ test/integration/virtual-rules/index.html | 1 + 2 files changed, 153 insertions(+) create mode 100644 test/integration/virtual-rules/area-alt.js diff --git a/test/integration/virtual-rules/area-alt.js b/test/integration/virtual-rules/area-alt.js new file mode 100644 index 0000000000..ad5841aa5a --- /dev/null +++ b/test/integration/virtual-rules/area-alt.js @@ -0,0 +1,152 @@ +describe('area-alt', function() { + it('should pass for aria-label', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + 'aria-label': 'foobar' + } + }); + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should incomplete for aria-labelledby', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + 'aria-labelledby': 'foobar' + } + }); + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 1); + }); + + it('should pass for alt', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + alt: 'foobar' + } + }); + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should pass for title', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + title: 'foobar' + } + }); + // children are required since titleText comes after subtree text + // in accessible name calculation + child.children = []; + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 1); + assert.lengthOf(results.violations, 0); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when alt contains only whitespace', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + alt: ' \t \n ' + } + }); + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when aria-label is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + 'aria-label': '' + } + }); + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); + + it('should fail when title is empty', function() { + var node = new axe.SerialVirtualNode({ + nodeName: 'map' + }); + var child = new axe.SerialVirtualNode({ + nodeName: 'area', + attributes: { + href: 'foobar', + title: '' + } + }); + child.children = []; + child.parent = node; + node.children = [child]; + + var results = axe.runVirtualRule('area-alt', node); + + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 1); + assert.lengthOf(results.incomplete, 0); + }); +}); diff --git a/test/integration/virtual-rules/index.html b/test/integration/virtual-rules/index.html index 2271a81462..b59f993a17 100644 --- a/test/integration/virtual-rules/index.html +++ b/test/integration/virtual-rules/index.html @@ -30,6 +30,7 @@ +