-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve generated selectors for namespaced elements in XHTML (#582
) * feat(utils): add function `isXHTML` to test if a document node is XHTML * test(utils): add a test for `axe.utils.isXHTML` on an XHTML document * fix(getSelector): improve selectors for namespaced elements - by default, ensure the nodename is escaped - for XHTML documents, only use the local name Replaces #566 Closes #563 * test(getSelector): add a test for `axe.utils.getSelector` on a namespaced XHTML element
- Loading branch information
1 parent
e67a913
commit dbe63eb
Showing
8 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
/** | ||
* Determines if a document node is XHTML | ||
* @method isXHTML | ||
* @memberof axe.utils | ||
* @instance | ||
* @param {Node} doc a document node | ||
* @return {Boolean} | ||
*/ | ||
axe.utils.isXHTML = function (doc) { | ||
'use strict'; | ||
if (!doc.createElement) { | ||
return false; | ||
} | ||
return doc.createElement('A').localName === 'A'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe('axe.utils.isXHTML', function () { | ||
'use strict'; | ||
|
||
it('should be a function', function () { | ||
assert.isFunction(axe.utils.isXHTML); | ||
}); | ||
|
||
it('should return true on any document that is XHTML', function () { | ||
var doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null); | ||
assert.isTrue(axe.utils.isXHTML(doc)); | ||
}); | ||
|
||
it('should return false on any document that is HTML', function () { | ||
var doc = document.implementation.createHTMLDocument('Monkeys'); | ||
assert.isFalse(axe.utils.isXHTML(doc)); | ||
}); | ||
|
||
it('should return false on any document that is HTML - fixture', function () { | ||
assert.isFalse(axe.utils.isXHTML(document)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
describe('axe.utils.getSelector', function () { | ||
'use strict'; | ||
it('should work on namespaced elements', function () { | ||
var fixture = document.querySelector('#fixture'); | ||
var node = fixture.firstElementChild; | ||
var sel = axe.utils.getSelector(node); | ||
var result = document.querySelectorAll(sel); | ||
assert.lengthOf(result, 1); | ||
assert.equal(result[0], node); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>axe.utils.getSelector test</title> | ||
<meta charset="utf-8"/> | ||
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" /> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="fixture"> | ||
<m:math xmlns:m="http://www.w3.org/1998/Math/MathML"></m:math> | ||
</div> | ||
<div id="mocha"></div> | ||
<script src="get-selector.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
describe('axe.utils.isXHTML', function () { | ||
'use strict'; | ||
|
||
it('should return true on any document that is XHTML', function () { | ||
assert.isTrue(axe.utils.isXHTML(document)); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>axe.utils.isXHTML test</title> | ||
<meta charset="utf-8"/> | ||
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" /> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="fixture"> | ||
</div> | ||
<div id="mocha"></div> | ||
<script src="is-xhtml.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |