From db2be93d07dda488f9d5ca66d193709eb41bf8cd Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Mon, 28 Sep 2020 09:14:55 -0600 Subject: [PATCH] feat(rule-matches): depreacte window-is-top-matches for is-intiator-matches (#2531) --- lib/core/base/metadata-function-map.js | 2 ++ lib/rules/bypass-matches.js | 6 +++--- lib/rules/document-title.json | 2 +- lib/rules/html-has-lang.json | 2 +- lib/rules/is-initiator-matches.js | 5 +++++ lib/rules/window-is-top-matches.js | 1 + test/rule-matches/is-initiator-matches.js | 24 +++++++++++++++++++++++ 7 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 lib/rules/is-initiator-matches.js create mode 100644 test/rule-matches/is-initiator-matches.js diff --git a/lib/core/base/metadata-function-map.js b/lib/core/base/metadata-function-map.js index f80a570d22..3196646263 100644 --- a/lib/core/base/metadata-function-map.js +++ b/lib/core/base/metadata-function-map.js @@ -145,6 +145,7 @@ import headingMatches from '../../rules/heading-matches'; import htmlNamespaceMatches from '../../rules/html-namespace-matches'; import identicalLinksSamePurposeMatches from '../../rules/identical-links-same-purpose-matches'; import insertedIntoFocusOrderMatches from '../../rules/inserted-into-focus-order-matches'; +import isInitiatorMatches from '../../rules/is-initiator-matches'; import labelContentNameMismatchMatches from '../../rules/label-content-name-mismatch-matches'; import labelMatches from '../../rules/label-matches'; import landmarkHasBodyContextMatches from '../../rules/landmark-has-body-context-matches'; @@ -310,6 +311,7 @@ const metadataFunctionMap = { 'html-namespace-matches': htmlNamespaceMatches, 'identical-links-same-purpose-matches': identicalLinksSamePurposeMatches, 'inserted-into-focus-order-matches': insertedIntoFocusOrderMatches, + 'is-initiator-matches': isInitiatorMatches, 'label-content-name-mismatch-matches': labelContentNameMismatchMatches, 'label-matches': labelMatches, 'landmark-has-body-context-matches': landmarkHasBodyContextMatches, diff --git a/lib/rules/bypass-matches.js b/lib/rules/bypass-matches.js index 91d22f8165..f6fd2b2440 100644 --- a/lib/rules/bypass-matches.js +++ b/lib/rules/bypass-matches.js @@ -1,8 +1,8 @@ -import windowIsTopMatches from './window-is-top-matches'; +import isInitiatorMatches from './is-initiator-matches'; -function bypassMatches(node) { +function bypassMatches(node, virtualNode, context) { // the top level window should have an anchor - if (windowIsTopMatches(node)) { + if (isInitiatorMatches(node, virtualNode, context)) { return !!node.querySelector('a[href]'); } diff --git a/lib/rules/document-title.json b/lib/rules/document-title.json index 2aba304b6b..ceaa155fea 100644 --- a/lib/rules/document-title.json +++ b/lib/rules/document-title.json @@ -1,7 +1,7 @@ { "id": "document-title", "selector": "html", - "matches": "window-is-top-matches", + "matches": "is-initiator-matches", "tags": ["cat.text-alternatives", "wcag2a", "wcag242", "ACT"], "metadata": { "description": "Ensures each HTML document contains a non-empty element", diff --git a/lib/rules/html-has-lang.json b/lib/rules/html-has-lang.json index 0fd137af85..f0315bda68 100644 --- a/lib/rules/html-has-lang.json +++ b/lib/rules/html-has-lang.json @@ -1,7 +1,7 @@ { "id": "html-has-lang", "selector": "html", - "matches": "window-is-top-matches", + "matches": "is-initiator-matches", "tags": ["cat.language", "wcag2a", "wcag311", "ACT"], "metadata": { "description": "Ensures every HTML document has a lang attribute", diff --git a/lib/rules/is-initiator-matches.js b/lib/rules/is-initiator-matches.js new file mode 100644 index 0000000000..2caa44f133 --- /dev/null +++ b/lib/rules/is-initiator-matches.js @@ -0,0 +1,5 @@ +function isInitiatorMatches(node, virtualNode, context) { + return context.initiator; +} + +export default isInitiatorMatches; diff --git a/lib/rules/window-is-top-matches.js b/lib/rules/window-is-top-matches.js index b84d6727d2..bebf17a153 100644 --- a/lib/rules/window-is-top-matches.js +++ b/lib/rules/window-is-top-matches.js @@ -1,3 +1,4 @@ +// @deprecated function windowIsTopMatches(node) { return ( node.ownerDocument.defaultView.self === node.ownerDocument.defaultView.top diff --git a/test/rule-matches/is-initiator-matches.js b/test/rule-matches/is-initiator-matches.js new file mode 100644 index 0000000000..59c7df3f6c --- /dev/null +++ b/test/rule-matches/is-initiator-matches.js @@ -0,0 +1,24 @@ +describe('is-initiator-matches', function() { + 'use strict'; + + var rule; + + beforeEach(function() { + rule = axe._audit.rules.find(function(rule) { + return rule.id === 'html-has-lang'; + }); + }); + + afterEach(function() { + var fixture = document.getElementById('fixture'); + fixture.innerHTML = ''; + }); + + it('should return true if the context is the initiator', function() { + assert.isTrue(rule.matches(null, null, { initiator: true })); + }); + + it('should return false if the context is not the initiator', function() { + assert.isFalse(rule.matches(null, null, { initiator: false })); + }); +});