Skip to content

Commit

Permalink
add audit files, target-size
Browse files Browse the repository at this point in the history
  • Loading branch information
jazyan committed Jun 30, 2023
1 parent aed0992 commit 59729d6
Show file tree
Hide file tree
Showing 13 changed files with 466 additions and 143 deletions.
5 changes: 5 additions & 0 deletions cli/test/fixtures/a11y/a11y_tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ <h3>sub-sub-header</h3>
<tr><td>foo</td><td>foo</td><tr>
</table>
</section>
<p>target-size</p>
<section>
<button id="target-size-1">+</button>
<span role="button" tabindex="0" id="target-size-2">o</span>
</section>
<p>td-has-header</p>
<section>
<table id="td-has-header">
Expand Down
16 changes: 16 additions & 0 deletions cli/test/smokehouse/test-definitions/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,22 @@ const expectations = {
],
},
},
'target-size': {
score: null,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > span#target-size-2',
'snippet': '<span role="button" tabindex="0" id="target-size-2">',
'explanation': 'Fix any of the following:\n Target has insufficient size (8px by 18px, should be at least 24px by 24px)\n Target has insufficient offset from its closest neighbor (12px should be at least 24px)',
'nodeLabel': 'o',
},
},
],
},
},
'td-has-header': {
score: 0,
details: {
Expand Down
45 changes: 45 additions & 0 deletions core/audits/accessibility/empty-heading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensures that headings are not empty.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that checks if all heading elements have content. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: 'All heading elements contain content.',
/** Title of an accesibility audit that checks if all heading elements have content. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: 'Heading elements do not contain content.',
/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'A heading with no content or inaccessible text prevent screen reader users from ' +
'accessing information on the page\'s structure. ' +
'[Learn more about headings](https://dequeuniversity.com/rules/axe/4.7/empty-heading).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class EmptyHeading extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'empty-heading',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
requiredArtifacts: ['Accessibility'],
};
}
}

export default EmptyHeading;
export {UIStrings};
45 changes: 45 additions & 0 deletions core/audits/accessibility/identical-links-same-purpose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensures that identical links have the same purpose.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that checks if identical links have the same purpose. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: 'Identical links have the same purpose.',
/** Title of an accesibility audit that checks if identical links have the same purpose. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: 'Identical links do not have the same purpose.',
/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'Links with the same destination should have the same description, to help users ' +
'understand the link\'s purpose and decide whether to follow it. ' +
'[Learn more about identical links](https://dequeuniversity.com/rules/axe/4.7/identical-links-same-purpose).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class IdenticalLinksSamePurpose extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'identical-links-same-purpose',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
requiredArtifacts: ['Accessibility'],
};
}
}

export default IdenticalLinksSamePurpose;
export {UIStrings};
44 changes: 44 additions & 0 deletions core/audits/accessibility/landmark-one-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensures that the document has a main landmark.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that checks if the document has a main landmark. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: 'Document has a main landmark.',
/** Title of an accesibility audit that checks if the document has a main landmark. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: 'Document does not have a main landmark.',
/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'One main landmark helps screen reader users navigate a web page. ' +
'[Learn more about landmarks](https://dequeuniversity.com/rules/axe/4.7/landmark-one-main).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class LandmarkOneMain extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'landmark-one-main',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
requiredArtifacts: ['Accessibility'],
};
}
}

export default LandmarkOneMain;
export {UIStrings};
45 changes: 45 additions & 0 deletions core/audits/accessibility/target-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensures that touch targets have sufficient size and spacing.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that checks if all touch targets have sufficient size and spacing. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: 'Touch targets have sufficient size and spacing.',
/** Title of an accesibility audit that checks if all touch targets have sufficient size and spacing. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: 'Touch targets do not have sufficient size or spacing.',
/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'Touch targets with sufficient size and spacing help users who may have ' +
'difficulty targeting small controls activate the targets. ' +
'[Learn more about touch targets](https://dequeuniversity.com/rules/axe/4.7/target-size).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class TargetSize extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'target-size',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
scoreDisplayMode: AxeAudit.SCORING_MODES.INFORMATIVE,
requiredArtifacts: ['Accessibility'],
};
}
}

export default TargetSize;
export {UIStrings};
2 changes: 2 additions & 0 deletions core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const defaultConfig = {
'accessibility/select-name',
'accessibility/tabindex',
'accessibility/table-fake-caption',
'accessibility/target-size',
'accessibility/td-has-header',
'accessibility/td-headers-attr',
'accessibility/th-has-data-cells',
Expand Down Expand Up @@ -575,6 +576,7 @@ const defaultConfig = {
{id: 'empty-heading', weight: 0, group: 'hidden'},
{id: 'identical-links-same-purpose', weight: 0, group: 'hidden'},
{id: 'landmark-one-main', weight: 0, group: 'hidden'},
{id: 'target-size', weight: 0, group: 'hidden'},
],
},
'best-practices': {
Expand Down
1 change: 1 addition & 0 deletions core/gather/gatherers/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async function runA11yChecks() {
'svg-img-alt': {enabled: false},
'tabindex': {enabled: true},
'table-fake-caption': {enabled: true},
'target-size': {enabled: true},
'td-has-header': {enabled: true},
},
});
Expand Down
Loading

0 comments on commit 59729d6

Please sign in to comment.