Skip to content

Commit

Permalink
Merge pull request #733 from dequelabs/axe-3-checks
Browse files Browse the repository at this point in the history
Update remaining checks to support Shadow DOM
  • Loading branch information
dylanb authored Feb 19, 2018
2 parents 5d99c73 + 0e48413 commit 3aaacea
Show file tree
Hide file tree
Showing 44 changed files with 312 additions and 458 deletions.
2 changes: 1 addition & 1 deletion lib/checks/keyboard/focusable-no-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ var tabIndex = node.getAttribute('tabindex'),
if (!inFocusOrder) {
return false;
}
return !axe.commons.text.accessibleText(node);
return !axe.commons.text.accessibleTextVirtual(virtualNode);
2 changes: 1 addition & 1 deletion lib/checks/label/implicit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var label = axe.commons.dom.findUpVirtual(virtualNode, 'label');
if (label) {
return !!axe.commons.text.accessibleText(label);
return !!axe.commons.text.accessibleTextVirtual(label);
}
return false;
2 changes: 1 addition & 1 deletion lib/checks/navigation/header-present.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return !!node.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
return !!axe.utils.querySelectorAll(virtualNode, 'h1, h2, h3, h4, h5, h6, [role="heading"]')[0];
3 changes: 2 additions & 1 deletion lib/checks/navigation/internal-link-present.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
return !!node.querySelector('a[href^="#"]');
const links = axe.utils.querySelectorAll(virtualNode, 'a[href]');
return links.some(vLink => vLink.actualNode.getAttribute('href')[0] === '#');
2 changes: 1 addition & 1 deletion lib/checks/shared/button-has-visible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let role = node.getAttribute('role');
let label;

if (nodeName === 'BUTTON' || (role === 'button' && nodeName !== 'INPUT')) {
label = axe.commons.text.accessibleText(node);
label = axe.commons.text.accessibleTextVirtual(virtualNode);
this.data(label);

return !!label;
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/shared/has-visible-text.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return axe.commons.text.accessibleText(node).length > 0;
return axe.commons.text.accessibleTextVirtual(virtualNode).length > 0;
1 change: 1 addition & 0 deletions lib/checks/tables/same-caption-summary.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// passing node.caption to accessibleText instead of using the logic in accessibleTextVirtual on virtualNode
return !!(node.summary && node.caption) && node.summary === axe.commons.text.accessibleText(node.caption);
20 changes: 2 additions & 18 deletions test/checks/aria/allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ describe('aria-allowed-attr', function () {
'use strict';

var fixture = document.getElementById('fixture');

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

it('should detect incorrectly used attributes', function () {
Expand All @@ -25,8 +19,6 @@ describe('aria-allowed-attr', function () {

assert.isFalse(checks['aria-allowed-attr'].evaluate.call(checkContext, node));
assert.deepEqual(checkContext._data, ['aria-selected="true"']);


});

it('should not report on required attributes', function () {
Expand All @@ -38,8 +30,6 @@ describe('aria-allowed-attr', function () {
fixture.appendChild(node);

assert.isTrue(checks['aria-allowed-attr'].evaluate.call(checkContext, node));


});

it('should detect incorrectly used attributes - implicit role', function () {
Expand All @@ -52,8 +42,6 @@ describe('aria-allowed-attr', function () {

assert.isFalse(checks['aria-allowed-attr'].evaluate.call(checkContext, node));
assert.deepEqual(checkContext._data, ['aria-selected="true"']);


});

it('should return true if there is no role', function () {
Expand All @@ -66,8 +54,6 @@ describe('aria-allowed-attr', function () {

assert.isTrue(checks['aria-allowed-attr'].evaluate.call(checkContext, node));
assert.isNull(checkContext._data);


});

it('should determine attribute validity by calling axe.commons.aria.allowedAttr', function () {
Expand Down Expand Up @@ -103,8 +89,6 @@ describe('aria-allowed-attr', function () {

assert.isTrue(checks['aria-allowed-attr'].evaluate.call(checkContext, node));
assert.isNull(checkContext._data);


});

it('should not report on allowed attributes', function () {
Expand Down
10 changes: 2 additions & 8 deletions test/checks/aria/aria-hidden-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ describe('aria-hidden', function () {
'use strict';

var node = document.getElementsByTagName('body')[0];

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
checkContext._data = null;
checkContext.reset();
node.removeAttribute('aria-hidden');
});

Expand Down
24 changes: 22 additions & 2 deletions test/checks/aria/errormessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ describe('aria-errormessage', function () {
'use strict';

var fixture = document.getElementById('fixture');

var shadowSupported = axe.testUtils.shadowSupport.v1;
var shadowCheckSetup = axe.testUtils.shadowCheckSetup;
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

it('should return false if aria-errormessage value is invalid', function () {
Expand Down Expand Up @@ -46,4 +47,23 @@ describe('aria-errormessage', function () {
target.setAttribute('aria-describedby', 'plain');
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target));
});

(shadowSupported ? it : xit)
('should return false if aria-errormessage value crosses shadow boundary', function () {
var params = shadowCheckSetup(
'<div id="target" aria-errormessage="live"></div>',
'<div id="live" aria-live="assertive"></div>'
);
assert.isFalse(checks['aria-errormessage'].evaluate.apply(checkContext, params));
});

(shadowSupported ? it : xit)
('should return true if aria-errormessage and value are inside shadow dom', function () {
var params = shadowCheckSetup(
'<div></div>',
'<div id="target" aria-errormessage="live"</div>' +
'<div id="live" aria-live="assertive"></div>'
);
assert.isTrue(checks['aria-errormessage'].evaluate.apply(checkContext, params));
});
});
10 changes: 2 additions & 8 deletions test/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ describe('aria-required-attr', function () {
'use strict';

var fixture = document.getElementById('fixture');

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

it('should detect missing attributes', function () {
Expand Down
11 changes: 2 additions & 9 deletions test/checks/aria/required-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ describe('aria-required-children', function () {

var fixture = document.getElementById('fixture');
var shadowSupported = axe.testUtils.shadowSupport.v1;

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};

var checkContext = axe.testUtils.MockCheckContext();
var checkSetup = axe.testUtils.checkSetup;

afterEach(function () {
fixture.innerHTML = '';
axe._tree = undefined;
checkContext._data = null;
checkContext.reset();
});

it('should detect missing sole required child', function () {
Expand Down
11 changes: 2 additions & 9 deletions test/checks/aria/required-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ describe('aria-required-parent', function () {

var fixture = document.getElementById('fixture');
var shadowSupported = axe.testUtils.shadowSupport.v1;

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};

var checkContext = axe.testUtils.MockCheckContext();
var checkSetup = axe.testUtils.checkSetup;

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
axe._tree = undefined;
});

Expand Down
10 changes: 2 additions & 8 deletions test/checks/aria/valid-attr-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ describe('aria-valid-attr-value', function () {
'use strict';

var fixture = document.getElementById('fixture');

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

it('should not check the validity of attribute names', function () {
Expand Down
10 changes: 2 additions & 8 deletions test/checks/aria/valid-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ describe('aria-valid-attr', function () {
'use strict';

var fixture = document.getElementById('fixture');

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

it('should return false if any invalid ARIA attributes are found', function () {
Expand Down
15 changes: 2 additions & 13 deletions test/checks/color/color-contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@ describe('color-contrast', function () {
var fixtureSetup = axe.testUtils.fixtureSetup;
var shadowSupported = axe.testUtils.shadowSupport.v1;
var shadowCheckSetup = axe.testUtils.shadowCheckSetup;

var checkContext = {
_relatedNodes: [],
_data: null,
data: function (d) {
this._data = d;
},
relatedNodes: function (rn) {
this._relatedNodes = rn;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._relatedNodes = [];
checkContext._data = null;
checkContext.reset();
axe._tree = undefined;
});

Expand Down
14 changes: 2 additions & 12 deletions test/checks/color/link-in-text-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ describe('link-in-text-block', function () {
var shadowSupport = axe.testUtils.shadowSupport;
var styleElm;

var checkContext = {
_relatedNodes: [],
_data: null,
data: function (d) {
this._data = d;
},
relatedNodes: function (rn) {
this._relatedNodes = rn;
}
};
var checkContext = axe.testUtils.MockCheckContext();

before(function () {
styleElm = document.createElement('style');
Expand All @@ -33,8 +24,7 @@ describe('link-in-text-block', function () {
afterEach(function () {
fixture.innerHTML = '';
styleElm.innerHTML = '';
checkContext._relatedNodes = [];
checkContext._data = null;
checkContext.reset();
});

after(function () {
Expand Down
12 changes: 2 additions & 10 deletions test/checks/forms/fieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ describe('fieldset', function () {
var shadowSupport = axe.testUtils.shadowSupport.v1;
var fixtureSetup = axe.testUtils.fixtureSetup;

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
},
relatedNodes: function (nodes) {
this._relatedNodes = Array.isArray(nodes) ? nodes : [nodes];
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

function tests(type) {
Expand Down
9 changes: 2 additions & 7 deletions test/checks/forms/group-labelledby.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ describe('group-labelledby', function () {
var fixtureSetup = axe.testUtils.fixtureSetup;
var shadowSupport = axe.testUtils.shadowSupport.v1;

var checkContext = {
_data: null,
data: function (d) {
this._data = d;
}
};
var checkContext = axe.testUtils.MockCheckContext();

beforeEach(function () {
axe._tree = undefined;
});

afterEach(function () {
fixture.innerHTML = '';
checkContext._data = null;
checkContext.reset();
});

function tests(type) {
Expand Down
15 changes: 2 additions & 13 deletions test/checks/keyboard/accesskeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@ describe('accesskeys', function () {

var fixture = document.getElementById('fixture');


var checkContext = {
_relatedNodes: [],
_data: null,
data: function (d) {
this._data = d;
},
relatedNodes: function (rn) {
this._relatedNodes = rn;
}
};
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function () {
fixture.innerHTML = '';
checkContext._relatedNodes = [];
checkContext._data = null;
checkContext.reset();
});

it('should return true and record accesskey', function () {
Expand Down
Loading

0 comments on commit 3aaacea

Please sign in to comment.