Skip to content

Commit

Permalink
fix: Exclude iframe for html-has-lang rule (Issue 1424) (#1430)
Browse files Browse the repository at this point in the history
Exclude `iframe` elements for SC311 rule `html-has-lang`.

Note: `context` integration tests had to be updated to not use `html-has-lang`.

Closes issue: #1424

## Reviewer checks

**Required fields, to be filled out by PR reviewer(s)**
- [x] Follows the commit message policy, appropriate for next version
- [x] Has documentation updated, a DU ticket, or requires no documentation change
- [x] Includes new tests, or was unnecessary
- [x] Code is reviewed for security by: @WilcoFiers
  • Loading branch information
jeeyyy authored and WilcoFiers committed Apr 15, 2019
1 parent 8b34dc6 commit 98b5ed2
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 62 deletions.
4 changes: 2 additions & 2 deletions lib/core/utils/get-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ function getThreeLeastCommonFeatures(elm, selectorData) {
return a.species !== b.species && a.species === 'class'
? -1
: a.species === b.species
? 0
: 1;
? 0
: 1;
});
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/rules/html-has-lang.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "html-has-lang",
"selector": "html",
"matches": "window-is-top.js",
"tags": ["cat.language", "wcag2a", "wcag311"],
"metadata": {
"description": "Ensures every HTML document has a lang attribute",
Expand Down
3 changes: 2 additions & 1 deletion test/integration/full/context/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('context test', function() {
'use strict';

var config = { runOnly: { type: 'rule', values: ['html-has-lang'] } };
var config = { runOnly: { type: 'rule', values: ['html-lang-valid'] } };
var shadowSupported = axe.testUtils.shadowSupport.v1;

before(function(done) {
Expand Down Expand Up @@ -321,6 +321,7 @@ describe('context test', function() {
});
});
});

describe('direct include', function() {
it('should find the frames given a context object', function(done) {
axe.run({ include: [['#myframe']] }, config, function(err, results) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/full/context/frames/level1.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html id="level1">
<html id="level1" lang="@(#$*">
<head>
<meta charset="utf8">
<script src="/axe.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/full/context/frames/level2-a.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html id="level2-a">
<html id="level2-a" lang="!@£">
<head>
<meta charset="utf8">
<script src="/axe.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/full/context/frames/level2-b.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html id="level2-b">
<html id="level2-b" xml:lang="$%^">
<head>
<meta charset="utf8">
<script src="/axe.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<html lang="klingon" id="pass1">
<html id="fail1">

<head>
<title>html-has-lang test</title>
<meta charset="utf8">
Expand All @@ -16,10 +17,17 @@
var assert = chai.assert;
</script>
</head>

<body>
<!--
Note:
This rule does not include `iframe` uses matches "window-is-top.js"
-->

<iframe id="frame1" src="frames/level1.html"></iframe>
<div id="mocha"></div>
<script src="html-has-lang.js"></script>
<script src="html-has-lang-fail.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>

</html>
37 changes: 37 additions & 0 deletions test/integration/full/html-has-lang/html-has-lang-fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Note:
* This rule does not include `iframe` uses matches "window-is-top.js"
*/
describe('html-has-lang fail test', function() {
'use strict';

var results;
before(function(done) {
axe.testUtils.awaitNestedLoad(function() {
axe.run(
{ runOnly: { type: 'rule', values: ['html-has-lang'] } },
function(err, r) {
assert.isNull(err);
results = r;
done();
}
);
});
});

describe('violations', function() {
it('should find 1 violations', function() {
assert.lengthOf(results.violations, 1);
});

it('should find #fail1', function() {
assert.deepEqual(results.violations[0].nodes[0].target, ['#fail1']);
});
});

describe('passes', function() {
it('should find 0 passes', function() {
assert.lengthOf(results.passes, 0);
});
});
});
32 changes: 32 additions & 0 deletions test/integration/full/html-has-lang/html-has-lang-pass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<html lang="klingon" id="pass1">

<head>
<title>html-has-lang test</title>
<meta charset="utf8">
<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 src="/test/testutils.js"></script>
<script>
mocha.setup({
timeout: 10000,
ui: 'bdd'
});
var assert = chai.assert;
</script>
</head>

<body>
<!--
Note:
This rule excludes `iframe`, uses matches "window-is-top.js"
-->
<iframe id="frame1" src="frames/level1.html"></iframe>
<div id="mocha"></div>
<script src="html-has-lang-pass.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>

</html>
36 changes: 36 additions & 0 deletions test/integration/full/html-has-lang/html-has-lang-pass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Note:
* This rule does not include `iframe` uses matches "window-is-top.js"
*/
describe('html-has-lang pass test', function() {
'use strict';
var results;
before(function(done) {
axe.testUtils.awaitNestedLoad(function() {
axe.run(
{ runOnly: { type: 'rule', values: ['html-has-lang'] } },
function(err, r) {
assert.isNull(err);
results = r;
done();
}
);
});
});

describe('violations', function() {
it('should find 0 violations', function() {
assert.lengthOf(results.violations, 0);
});
});

describe('passes', function() {
it('should find 1', function() {
assert.lengthOf(results.passes[0].nodes, 1);
});

it('should find #pass1', function() {
assert.deepEqual(results.passes[0].nodes[0].target, ['#pass1']);
});
});
});
53 changes: 0 additions & 53 deletions test/integration/full/html-has-lang/html-has-lang.js

This file was deleted.

0 comments on commit 98b5ed2

Please sign in to comment.