Skip to content

Commit

Permalink
feat(rule-matches): depreacte window-is-top-matches for is-intiator-m…
Browse files Browse the repository at this point in the history
…atches (#2531)
  • Loading branch information
straker authored Sep 28, 2020
1 parent e4edffc commit db2be93
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/core/base/metadata-function-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/bypass-matches.js
Original file line number Diff line number Diff line change
@@ -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]');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/document-title.json
Original file line number Diff line number Diff line change
@@ -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 <title> element",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-has-lang.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/is-initiator-matches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function isInitiatorMatches(node, virtualNode, context) {
return context.initiator;
}

export default isInitiatorMatches;
1 change: 1 addition & 0 deletions lib/rules/window-is-top-matches.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @deprecated
function windowIsTopMatches(node) {
return (
node.ownerDocument.defaultView.self === node.ownerDocument.defaultView.top
Expand Down
24 changes: 24 additions & 0 deletions test/rule-matches/is-initiator-matches.js
Original file line number Diff line number Diff line change
@@ -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 }));
});
});

0 comments on commit db2be93

Please sign in to comment.