diff --git a/lib/checks/media/frame-tested-after.js b/lib/checks/media/frame-tested-after.js new file mode 100644 index 0000000000..733ffe4a17 --- /dev/null +++ b/lib/checks/media/frame-tested-after.js @@ -0,0 +1,31 @@ +const joinStr = ' > '; + +function frameTestedAfter(results) { + const iframes = {}; + + return results.filter(result => { + const frameResult = + result.node.ancestry[result.node.ancestry.length - 1] !== 'html'; + + if (frameResult) { + const ancestry = result.node.ancestry.flat(Infinity).join(joinStr); + iframes[ancestry] = result; + return true; + } + + // remove the `html` from the path to get the iframe path + const ancestry = result.node.ancestry + .slice(0, result.node.ancestry.length - 1) + .flat(Infinity) + .join(joinStr); + + // pass for each iframe that has an html result + if (iframes[ancestry]) { + iframes[ancestry].result = true; + } + + return false; + }); +} + +export default frameTestedAfter; diff --git a/lib/checks/media/frame-tested-evaluate.js b/lib/checks/media/frame-tested-evaluate.js index fa6d43aaf0..263a420365 100644 --- a/lib/checks/media/frame-tested-evaluate.js +++ b/lib/checks/media/frame-tested-evaluate.js @@ -1,28 +1,6 @@ -import { respondable } from '../../core/utils'; - function frameTestedEvaluate(node, options) { - const resolve = this.async(); - const { isViolation, timeout } = Object.assign( - { isViolation: false, timeout: 500 }, - options - ); - - // give the frame .5s to respond to 'axe.ping', else log failed response - let timer = setTimeout(() => { - // This double timeout is important for allowing iframes to respond - // DO NOT REMOVE - timer = setTimeout(() => { - timer = null; - resolve(isViolation ? false : undefined); - }, 0); - }, timeout); - - respondable(node.contentWindow, 'axe.ping', null, undefined, () => { - if (timer !== null) { - clearTimeout(timer); - resolve(true); - } - }); + // assume iframe is not tested + return options.isViolation ? false : undefined; } export default frameTestedEvaluate; diff --git a/lib/checks/media/frame-tested.json b/lib/checks/media/frame-tested.json index d765e6f840..460f2832f7 100644 --- a/lib/checks/media/frame-tested.json +++ b/lib/checks/media/frame-tested.json @@ -1,6 +1,7 @@ { "id": "frame-tested", "evaluate": "frame-tested-evaluate", + "after": "frame-tested-after", "options": { "isViolation": false }, diff --git a/lib/core/base/metadata-function-map.js b/lib/core/base/metadata-function-map.js index 6d74804a50..fc8b490f82 100644 --- a/lib/core/base/metadata-function-map.js +++ b/lib/core/base/metadata-function-map.js @@ -127,6 +127,7 @@ import structuredDlitemsEvaluate from '../../checks/lists/structured-dlitems-eva // media import captionEvaluate from '../../checks/media/caption-evaluate'; import frameTestedEvaluate from '../../checks/media/frame-tested-evaluate'; +import frameTestedAfter from '../../checks/media/frame-tested-after'; import noAutoplayAudioEvaluate from '../../checks/media/no-autoplay-audio-evaluate'; // rule matches @@ -301,6 +302,7 @@ const metadataFunctionMap = { // media 'caption-evaluate': captionEvaluate, 'frame-tested-evaluate': frameTestedEvaluate, + 'frame-tested-after': frameTestedAfter, 'no-autoplay-audio-evaluate': noAutoplayAudioEvaluate, // rule matches diff --git a/lib/core/utils/pollyfills.js b/lib/core/utils/pollyfills.js index 5211f22f38..2afe6d6cd5 100644 --- a/lib/core/utils/pollyfills.js +++ b/lib/core/utils/pollyfills.js @@ -318,3 +318,30 @@ if (!String.prototype.includes) { } }; } + +// @see https://github.com/jonathantneal/array-flat-polyfill/blob/master/src/polyfill-flat.js +if (!Array.prototype.flat) { + Object.defineProperty(Array.prototype, 'flat', { + configurable: true, + value: function flat() { + var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]); + + return depth + ? Array.prototype.reduce.call( + this, + function(acc, cur) { + if (Array.isArray(cur)) { + acc.push.apply(acc, flat.call(cur, depth - 1)); + } else { + acc.push(cur); + } + + return acc; + }, + [] + ) + : Array.prototype.slice.call(this); + }, + writable: true + }); +} diff --git a/lib/rules/frame-tested.json b/lib/rules/frame-tested.json index b89241a873..e718a1bc21 100644 --- a/lib/rules/frame-tested.json +++ b/lib/rules/frame-tested.json @@ -1,6 +1,6 @@ { "id": "frame-tested", - "selector": "frame, iframe", + "selector": "html, frame, iframe", "tags": ["cat.structure", "review-item", "best-practice"], "metadata": { "description": "Ensures