diff --git a/cli/test/fixtures/dobetterweb/dbw_tester.html b/cli/test/fixtures/dobetterweb/dbw_tester.html index dcdbfef37470..93301e328f5a 100644 --- a/cli/test/fixtures/dobetterweb/dbw_tester.html +++ b/cli/test/fixtures/dobetterweb/dbw_tester.html @@ -242,16 +242,6 @@
- This is a link in a text block. - This is a link in a text block. - This is a link in a text block. - This is a link in a text block. - This is a link in a text block. -
- - - diff --git a/cli/test/smokehouse/core-tests.js b/cli/test/smokehouse/core-tests.js index 0dbffbeb8a1c..9d4ae94ebc26 100644 --- a/cli/test/smokehouse/core-tests.js +++ b/cli/test/smokehouse/core-tests.js @@ -61,7 +61,6 @@ import screenshot from './test-definitions/screenshot.js'; import seoFailing from './test-definitions/seo-failing.js'; import seoPassing from './test-definitions/seo-passing.js'; import seoStatus403 from './test-definitions/seo-status-403.js'; -import seoTapTargets from './test-definitions/seo-tap-targets.js'; import serviceWorkerReloaded from './test-definitions/service-worker-reloaded.js'; import shiftAttribution from './test-definitions/shift-attribution.js'; import sourceMaps from './test-definitions/source-maps.js'; @@ -126,7 +125,6 @@ const smokeTests = [ seoFailing, seoPassing, seoStatus403, - seoTapTargets, serviceWorkerReloaded, shiftAttribution, sourceMaps, diff --git a/cli/test/smokehouse/test-definitions/dobetterweb.js b/cli/test/smokehouse/test-definitions/dobetterweb.js index 5547b0768805..10cc01da3425 100644 --- a/cli/test/smokehouse/test-definitions/dobetterweb.js +++ b/cli/test/smokehouse/test-definitions/dobetterweb.js @@ -442,7 +442,7 @@ const expectations = { }, 'dom-size': { score: 1, - numericValue: 154, + numericValue: 151, details: { items: [ { @@ -450,7 +450,7 @@ const expectations = { value: { type: 'numeric', granularity: 1, - value: 154, + value: 151, }, }, { diff --git a/cli/test/smokehouse/test-definitions/seo-tap-targets.js b/cli/test/smokehouse/test-definitions/seo-tap-targets.js deleted file mode 100644 index f37c193c72c4..000000000000 --- a/cli/test/smokehouse/test-definitions/seo-tap-targets.js +++ /dev/null @@ -1,210 +0,0 @@ -/** - * @license - * Copyright 2017 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -const BASE_URL = 'http://localhost:10200/seo/'; - -/** @type {LH.Config} */ -const config = { - extends: 'lighthouse:default', - settings: { - onlyCategories: ['seo'], - }, -}; - -const expectedGatheredTapTargets = [ - { - node: { - snippet: /large-link-at-bottom-of-page/, - }, - }, - { - node: { - snippet: /visible-target/, - }, - }, - { - node: { - snippet: /target-with-client-rect-outside-scroll-container/, - }, - }, - { - node: { - snippet: /link-containing-large-inline-block-element/, - }, - }, - { - node: { - snippet: /link-next-to-link-containing-large-inline-block-element/, - }, - }, - { - node: { - snippet: /tap-target-containing-other-tap-targets/, - }, - }, - { - node: { - snippet: /child-client-rect-hidden-by-overflow-hidden/, - }, - }, - { - node: { - snippet: /tap-target-next-to-child-client-rect-hidden-by-overflow-hidden/, - }, - }, - { - node: { - snippet: /child-client-rect-overlapping-other-target/, - }, - shouldFail: true, - }, - { - node: { - snippet: /tap-target-overlapped-by-other-targets-position-absolute-child-rect/, - }, - shouldFail: true, - }, - { - node: { - snippet: /position-absolute-tap-target-fully-contained-in-other-target/, - }, - }, - { - node: { - snippet: /tap-target-fully-containing-position-absolute-target/, - }, - }, - { - node: { - snippet: /too-small-failing-tap-target/, - }, - shouldFail: true, - }, - { - node: { - snippet: /large-enough-tap-target-next-to-too-small-tap-target/, - }, - }, - { - node: { - snippet: /zero-width-tap-target-with-overflowing-child-content/, - }, - shouldFail: true, - }, - { - node: { - snippet: /passing-tap-target-next-to-zero-width-target/, - }, - }, - { - node: { - snippet: /links-with-same-link-target-1/, - }, - }, - { - node: { - snippet: /links-with-same-link-target-2/, - }, - }, -]; - -/** - * @type {Smokehouse.ExpectedRunnerResult} - * Expected Lighthouse audit values for a site exercising tap targets. - */ -const expectations = { - lhr: { - finalDisplayedUrl: BASE_URL + 'seo-tap-targets.html', - requestedUrl: BASE_URL + 'seo-tap-targets.html', - audits: { - 'tap-targets': { - score: (() => { - const totalTapTargets = expectedGatheredTapTargets.length; - const passingTapTargets = expectedGatheredTapTargets.filter(t => !t.shouldFail).length; - const SCORE_FACTOR = 0.89; - return Math.round(passingTapTargets / totalTapTargets * SCORE_FACTOR * 100) / 100; - })(), - details: { - items: [ - { - 'tapTarget': { - 'type': 'node', - /* eslint-disable max-len */ - 'snippet': '', - 'path': '2,HTML,1,BODY,14,DIV,0,A', - 'selector': 'body > div > a', - 'nodeLabel': 'zero width target', - }, - 'overlappingTarget': { - 'type': 'node', - /* eslint-disable max-len */ - 'snippet': '', - 'path': '2,HTML,1,BODY,14,DIV,1,A', - 'selector': 'body > div > a', - 'nodeLabel': 'passing target', - }, - 'tapTargetScore': 864, - 'overlappingTargetScore': 720, - 'overlapScoreRatio': 0.8333333333333334, - 'size': '110x18', - 'width': 110, - 'height': 18, - }, - { - 'tapTarget': { - 'type': 'node', - 'path': '2,HTML,1,BODY,10,DIV,0,DIV,1,A', - 'selector': 'body > div > div > a', - 'nodeLabel': 'too small target', - }, - 'overlappingTarget': { - 'type': 'node', - 'path': '2,HTML,1,BODY,10,DIV,0,DIV,2,A', - 'selector': 'body > div > div > a', - 'nodeLabel': 'big enough target', - }, - 'tapTargetScore': 1440, - 'overlappingTargetScore': 432, - 'overlapScoreRatio': 0.3, - 'size': '100x30', - 'width': 100, - 'height': 30, - }, - { - 'tapTarget': { - 'type': 'node', - 'path': '2,HTML,1,BODY,3,DIV,24,A', - 'selector': 'body > div > a', - 'nodeLabel': 'left', - }, - 'overlappingTarget': { - 'type': 'node', - 'path': '2,HTML,1,BODY,3,DIV,25,A', - 'selector': 'body > div > a', - 'nodeLabel': 'right', - }, - 'tapTargetScore': 1920, - 'overlappingTargetScore': 560, - 'overlapScoreRatio': 0.2916666666666667, - 'size': '40x40', - 'width': 40, - 'height': 40, - }, - ], - }, - }, - }, - }, - artifacts: { - TapTargets: expectedGatheredTapTargets.map(({node}) => ({node})), - }, -}; - -export default { - id: 'seo-tap-targets', - expectations, - config, -}; diff --git a/core/audits/seo/tap-targets.js b/core/audits/seo/tap-targets.js deleted file mode 100644 index 5458db00e539..000000000000 --- a/core/audits/seo/tap-targets.js +++ /dev/null @@ -1,352 +0,0 @@ -/** - * @license - * Copyright 2018 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview Checks that links, buttons, etc. are sufficiently large and that there's - * no other tap target that's too close so that the user might accidentally tap on. - */ - -import {Audit} from '../audit.js'; -import {ViewportMeta} from '../../computed/viewport-meta.js'; -import { - rectsTouchOrOverlap, - getRectOverlapArea, - getRectAtCenter, - allRectsContainedWithinEachOther, - getLargestRect, - getBoundingRectWithPadding, -} from '../../lib/rect-helpers.js'; -import {getTappableRectsFromClientRects} from '../../lib/tappable-rects.js'; -import * as i18n from '../../lib/i18n/i18n.js'; - -const UIStrings = { - /** Title of a Lighthouse audit that provides detail on whether tap targets (like buttons and links) on a page are big enough so they can easily be tapped on a mobile device. This descriptive title is shown when tap targets are easy to tap on. */ - title: 'Tap targets are sized appropriately', - /** Descriptive title of a Lighthouse audit that provides detail on whether tap targets (like buttons and links) on a page are big enough so they can easily be tapped on a mobile device. This descriptive title is shown when tap targets are not easy to tap on. */ - failureTitle: 'Tap targets are not sized appropriately', - /** Description of a Lighthouse audit that tells the user why buttons and links need to be big enough and what 'big enough' means. 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: 'Interactive elements like buttons and links should be large enough (48x48px), or have enough space around them, to be easy enough to tap without overlapping onto other elements. [Learn more about tap targets](https://developer.chrome.com/docs/lighthouse/seo/tap-targets/).', - /** Label of a table column that identifies tap targets (like buttons and links) that have failed the audit and aren't easy to tap on. */ - tapTargetHeader: 'Tap Target', - /** Label of a table column that identifies a tap target (like a link or button) that overlaps with another tap target. */ - overlappingTargetHeader: 'Overlapping Target', - /** Explanatory message stating that there was a failure in an audit caused by the viewport meta tag not being optimized for mobile screens, which caused tap targets like buttons and links to be too small to tap on. */ - /* eslint-disable-next-line max-len */ - explanationViewportMetaNotOptimized: 'Tap targets are too small because there\'s no viewport meta tag optimized for mobile screens', - /** Explanatory message stating that a certain percentage of the tap targets (like buttons and links) on the page are of an appropriately large size. */ - displayValue: '{decimalProportion, number, percent} appropriately sized tap targets', -}; - -const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings); - -const FINGER_SIZE_PX = 48; -// Ratio of the finger area tapping on an unintended element -// to the finger area tapping on the intended element -const MAX_ACCEPTABLE_OVERLAP_SCORE_RATIO = 0.25; - -/** - * Returns a tap target augmented with a bounding rect for quick overlapping - * rejections. Rect contains all the client rects, padded to half FINGER_SIZE_PX. - * @param {LH.Artifacts.TapTarget[]} targets - * @return {BoundedTapTarget[]} - */ -function getBoundedTapTargets(targets) { - return targets.map(tapTarget => { - return { - tapTarget, - paddedBoundsRect: getBoundingRectWithPadding(tapTarget.clientRects, FINGER_SIZE_PX), - }; - }); -} - -/** - * @param {LH.Artifacts.Rect} cr - */ -function clientRectBelowMinimumSize(cr) { - return cr.width < FINGER_SIZE_PX || cr.height < FINGER_SIZE_PX; -} - -/** - * A target is "too small" if none of its clientRects are at least the size of a finger. - * @param {BoundedTapTarget[]} targets - * @return {BoundedTapTarget[]} - */ -function getTooSmallTargets(targets) { - return targets.filter(target => { - return target.tapTarget.clientRects.every(clientRectBelowMinimumSize); - }); -} - -/** - * @param {BoundedTapTarget[]} tooSmallTargets - * @param {BoundedTapTarget[]} allTargets - * @return {TapTargetOverlapFailure[]} - */ -function getAllOverlapFailures(tooSmallTargets, allTargets) { - /** @type {TapTargetOverlapFailure[]} */ - const failures = []; - - tooSmallTargets.forEach(target => { - // Convert client rects to unique tappable areas from a user's perspective - const tappableRects = getTappableRectsFromClientRects(target.tapTarget.clientRects); - - for (const maybeOverlappingTarget of allTargets) { - if (maybeOverlappingTarget === target) { - // Checking the same target with itself, skip. - continue; - } - - if (!rectsTouchOrOverlap(target.paddedBoundsRect, maybeOverlappingTarget.paddedBoundsRect)) { - // Bounding boxes (padded with half FINGER_SIZE_PX) don't overlap, skip. - continue; - } - - if (target.tapTarget.href === maybeOverlappingTarget.tapTarget.href) { - const isHttpOrHttpsLink = /https?:\/\//.test(target.tapTarget.href); - if (isHttpOrHttpsLink) { - // No overlap because same target action, skip. - continue; - } - } - - const maybeOverlappingRects = maybeOverlappingTarget.tapTarget.clientRects; - if (allRectsContainedWithinEachOther(tappableRects, maybeOverlappingRects)) { - // If one tap target is fully contained within the other that's - // probably intentional (e.g. an item with a delete button inside). - // We'll miss some problems because of this, but that's better - // than falsely reporting a failure. - continue; - } - - const rectFailure = getOverlapFailureForTargetPair(tappableRects, maybeOverlappingRects); - if (rectFailure) { - failures.push({ - ...rectFailure, - tapTarget: target.tapTarget, - overlappingTarget: maybeOverlappingTarget.tapTarget, - }); - } - } - }); - - return failures; -} - -/** - * @param {LH.Artifacts.Rect[]} tappableRects - * @param {LH.Artifacts.Rect[]} maybeOverlappingRects - * @return {ClientRectOverlapFailure | null} - */ -function getOverlapFailureForTargetPair(tappableRects, maybeOverlappingRects) { - /** @type ClientRectOverlapFailure | null */ - let greatestFailure = null; - - for (const targetCR of tappableRects) { - const fingerRect = getRectAtCenter(targetCR, FINGER_SIZE_PX); - // Score indicates how much of the finger area overlaps each target when the user - // taps on the center of targetCR - const tapTargetScore = getRectOverlapArea(fingerRect, targetCR); - - for (const maybeOverlappingCR of maybeOverlappingRects) { - const overlappingTargetScore = getRectOverlapArea(fingerRect, maybeOverlappingCR); - - const overlapScoreRatio = overlappingTargetScore / tapTargetScore; - if (overlapScoreRatio < MAX_ACCEPTABLE_OVERLAP_SCORE_RATIO) { - // low score means it's clear that the user tried to tap on the targetCR, - // rather than the other tap target client rect - continue; - } - - // only update our state if this was the biggest failure we've seen for this pair - if (!greatestFailure || overlapScoreRatio > greatestFailure.overlapScoreRatio) { - greatestFailure = { - overlapScoreRatio, - tapTargetScore, - overlappingTargetScore, - }; - } - } - } - return greatestFailure; -} - -/** - * Only report one failure if two targets overlap each other - * @param {TapTargetOverlapFailure[]} overlapFailures - * @return {TapTargetOverlapFailure[]} - */ -function mergeSymmetricFailures(overlapFailures) { - /** @type TapTargetOverlapFailure[] */ - const failuresAfterMerging = []; - - overlapFailures.forEach((failure, overlapFailureIndex) => { - const symmetricFailure = overlapFailures.find(f => - f.tapTarget === failure.overlappingTarget && - f.overlappingTarget === failure.tapTarget - ); - - if (!symmetricFailure) { - failuresAfterMerging.push(failure); - return; - } - - const {overlapScoreRatio: failureOSR} = failure; - const {overlapScoreRatio: symmetricOSR} = symmetricFailure; - // Push if: - // - the current failure has a higher OSR - // - OSRs are the same, and the current failure comes before its symmetric partner in the list - // Otherwise do nothing and let the symmetric partner be pushed later. - if (failureOSR > symmetricOSR || ( - failureOSR === symmetricOSR && - overlapFailureIndex < overlapFailures.indexOf(symmetricFailure) - )) { - failuresAfterMerging.push(failure); - } - }); - - return failuresAfterMerging; -} - -/** - * @param {TapTargetOverlapFailure[]} overlapFailures - * @return {TapTargetTableItem[]} - */ -function getTableItems(overlapFailures) { - const tableItems = overlapFailures.map(failure => { - const largestCR = getLargestRect(failure.tapTarget.clientRects); - const width = Math.floor(largestCR.width); - const height = Math.floor(largestCR.height); - const size = width + 'x' + height; - return { - tapTarget: Audit.makeNodeItem(failure.tapTarget.node), - overlappingTarget: Audit.makeNodeItem(failure.overlappingTarget.node), - tapTargetScore: failure.tapTargetScore, - overlappingTargetScore: failure.overlappingTargetScore, - overlapScoreRatio: failure.overlapScoreRatio, - size, - width, - height, - }; - }); - - tableItems.sort((a, b) => { - return b.overlapScoreRatio - a.overlapScoreRatio; - }); - - return tableItems; -} - -class TapTargets extends Audit { - /** - * @return {LH.Audit.Meta} - */ - static get meta() { - return { - id: 'tap-targets', - title: str_(UIStrings.title), - failureTitle: str_(UIStrings.failureTitle), - description: str_(UIStrings.description), - requiredArtifacts: ['MetaElements', 'TapTargets'], - }; - } - - /** - * @param {LH.Artifacts} artifacts - * @param {LH.Audit.Context} context - * @return {Promise