-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(region): contents in iframes should pass the region rule if the i…
…frame itself is in a region (#2949) * only run region rule on initiatior; iframe results will be on their own reports * add test * content in iframes that are in regions should be counted as within the region * add another nested iframe test * move match ancestry function to shared file * attempt to move things forward * working now * remove test that won't work because that logic is in the after method now * add unit tests for after method * test only result * match ancestry tests * passes * add comment * refactor * more refactor * add additional test
- Loading branch information
Showing
21 changed files
with
518 additions
and
36 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,31 @@ | ||
import { matchAncestry } from '../../core/utils'; | ||
|
||
function regionAfter(results) { | ||
const iframeResults = results.filter(r => r.data.isIframe); | ||
|
||
results.forEach(r => { | ||
// continue if the element passed the check or is not in a frame | ||
if (r.result || r.node.ancestry.length === 1) { | ||
return; | ||
} | ||
|
||
const frameAncestry = r.node.ancestry.slice(0, -1); | ||
for (const iframeResult of iframeResults) { | ||
// if the container frame passed the check, this element should also pass | ||
if (matchAncestry(frameAncestry, iframeResult.node.ancestry)) { | ||
r.result = iframeResult.result; | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
// iframe elements should always pass | ||
iframeResults.forEach(r => { | ||
if (!r.result) { | ||
r.result = true; | ||
} | ||
}); | ||
return results; | ||
} | ||
|
||
export default regionAfter; |
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
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
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,20 @@ | ||
/** | ||
* Check if two ancestries are identical | ||
*/ | ||
function matchAncestry(ancestryA, ancestryB) { | ||
if (ancestryA.length !== ancestryB.length) { | ||
return false; | ||
} | ||
return ancestryA.every((selectorA, index) => { | ||
const selectorB = ancestryB[index]; | ||
if (!Array.isArray(selectorA)) { | ||
return selectorA === selectorB; | ||
} | ||
if (selectorA.length !== selectorB.length) { | ||
return false; | ||
} | ||
return selectorA.every((str, index) => selectorB[index] === str); | ||
}); | ||
} | ||
|
||
export default matchAncestry; |
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,153 @@ | ||
describe('region-after', function() { | ||
'use strict'; | ||
|
||
var checkContext = axe.testUtils.MockCheckContext(); | ||
|
||
afterEach(function() { | ||
checkContext.reset(); | ||
}); | ||
|
||
it('should always pass iframes', function() { | ||
var results = checks.region.after([ | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe'] | ||
}, | ||
result: false | ||
}, | ||
{ | ||
data: { isIframe: false }, | ||
node: { | ||
ancestry: ['html > body > iframe', 'html > body > p'] | ||
}, | ||
result: false | ||
} | ||
]); | ||
assert.equal(results[0].result, true); | ||
assert.equal(results[1].result, false); | ||
}); | ||
|
||
it('should pass children of iframes if the iframe contained in it is in a region', function() { | ||
var results = checks.region.after([ | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe'] | ||
}, | ||
result: true | ||
}, | ||
{ | ||
data: { isIframe: false }, | ||
node: { | ||
ancestry: ['html > body > iframe', 'html > body > p'] | ||
}, | ||
result: false | ||
} | ||
]); | ||
|
||
assert.equal(results[0].result, true); | ||
assert.equal(results[1].result, true); | ||
}); | ||
|
||
it('should pass nested iframes', function() { | ||
var results = checks.region.after([ | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe'] | ||
}, | ||
result: false | ||
}, | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe', 'html > body > iframe'] | ||
}, | ||
result: false | ||
}, | ||
{ | ||
data: { isIframe: false }, | ||
node: { | ||
ancestry: [ | ||
'html > body > iframe', | ||
'html > body > iframe', | ||
'html > body > p' | ||
] | ||
}, | ||
result: false | ||
} | ||
]); | ||
|
||
assert.equal(results[0].result, true); | ||
assert.equal(results[1].result, true); | ||
assert.equal(results[2].result, false); | ||
}); | ||
|
||
it('should pass children of nested iframes if the nested iframe is in a region', function() { | ||
var results = checks.region.after([ | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe'] | ||
}, | ||
result: false | ||
}, | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe', 'html > body > iframe'] | ||
}, | ||
result: true | ||
}, | ||
{ | ||
data: { isIframe: false }, | ||
node: { | ||
ancestry: [ | ||
'html > body > iframe', | ||
'html > body > iframe', | ||
'html > body > p' | ||
] | ||
}, | ||
result: false | ||
} | ||
]); | ||
|
||
assert.equal(results[0].result, true); | ||
assert.equal(results[1].result, true); | ||
assert.equal(results[2].result, true); | ||
}); | ||
|
||
it('should pass content if a grandparent frame passes', function() { | ||
var results = checks.region.after([ | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe'] | ||
}, | ||
result: true | ||
}, | ||
{ | ||
data: { isIframe: true }, | ||
node: { | ||
ancestry: ['html > body > iframe', 'html > body > iframe'] | ||
}, | ||
result: false | ||
}, | ||
{ | ||
data: { isIframe: false }, | ||
node: { | ||
ancestry: [ | ||
'html > body > iframe', | ||
'html > body > iframe', | ||
'html > body > p' | ||
] | ||
}, | ||
result: false | ||
} | ||
]); | ||
assert.equal(results[0].result, true); | ||
assert.equal(results[1].result, true); | ||
assert.equal(results[2].result, true); | ||
}); | ||
}); |
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,60 @@ | ||
describe('axe.utils.matchAncestry', function() { | ||
'use strict'; | ||
var fixture = document.getElementById('fixture'); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should be a function', function() { | ||
assert.isFunction(axe.utils.matchAncestry); | ||
}); | ||
|
||
it('should match when ancestry is the same and one level', function() { | ||
var result = axe.utils.matchAncestry( | ||
['html > body > div:nth-child(1)'], | ||
['html > body > div:nth-child(1)'] | ||
); | ||
assert.isTrue(result); | ||
}); | ||
|
||
it('should not match when ancestry is different and one level', function() { | ||
var result = axe.utils.matchAncestry( | ||
['html > body > div:nth-child(3)'], | ||
['html > body > div:nth-child(1)'] | ||
); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('should not match when ancestries have different numbers of elements', function() { | ||
var result = axe.utils.matchAncestry( | ||
['iframe', 'html > body > div:nth-child(1)'], | ||
['html > body > div:nth-child(1)'] | ||
); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('should not match when first level is different and second level is the same', function() { | ||
var result = axe.utils.matchAncestry( | ||
['iframe', 'html > body > div:nth-child(1)'], | ||
['otherIframe', 'html > body > div:nth-child(1)'] | ||
); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('should not match when second level is different and first level is the same', function() { | ||
var result = axe.utils.matchAncestry( | ||
['iframe', 'html > body > div:nth-child(1)'], | ||
['iframe', 'html > body > div:nth-child(2)'] | ||
); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('should match when all levels are the same', function() { | ||
var result = axe.utils.matchAncestry( | ||
['iframe', 'iframe2', 'html > body > div:nth-child(1)'], | ||
['iframe', 'iframe2', 'html > body > div:nth-child(1)'] | ||
); | ||
assert.isTrue(result); | ||
}); | ||
}); |
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,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf8" /> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<p id="wrapper">Region content no region</p> | ||
</body> | ||
</html> |
Oops, something went wrong.