From 85b66058fa0d14d0b693cf5b6d8d07f8384bf94f Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Sat, 4 May 2019 17:17:43 -0700 Subject: [PATCH 01/15] add ios-pwa audit to pwa category. --- lighthouse-core/audits/ios-pwa-icon.js | 54 ++++++++++++++++++++++++ lighthouse-core/config/default-config.js | 2 + 2 files changed, 56 insertions(+) create mode 100644 lighthouse-core/audits/ios-pwa-icon.js diff --git a/lighthouse-core/audits/ios-pwa-icon.js b/lighthouse-core/audits/ios-pwa-icon.js new file mode 100644 index 000000000000..defd17762177 --- /dev/null +++ b/lighthouse-core/audits/ios-pwa-icon.js @@ -0,0 +1,54 @@ +/** + * @license Copyright 2019 Google Inc. 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. + */ +'use strict'; + +const Audit = require('./audit'); + +/** + * @fileoverview + * Audits if the page's web app has a valid icon for iOS installability. + */ + +class IosPwaIcon extends Audit { + /** + * @return {LH.Audit.Meta} + */ + static get meta() { + return { + id: 'ios-pwa-icon', + title: 'Web app has a valid iOS PWA icon', + // title: 'Web app manifest meets the installability requirements', + failureTitle: 'Web app does not have a valid iOS PWA icon', + description: 'In order to be installable as an iOS PWA, ' + + 'web apps must have a valid iOS icon.', + requiredArtifacts: ['LinkElements'], + }; + } + + /** + * @param {LH.Artifacts} artifacts + * @param {LH.Audit.Context} _ + * @return {Promise} + */ + static audit(artifacts, _) { + const appleTouchIcons = artifacts.LinkElements.filter(el => el.rel === 'apple-touch-icon'); + + // Audit passes if an `apple-touch-icon` exists. + const passed = appleTouchIcons.length !== 0; + + let explanation; + if (!passed) { + explanation = 'No Apple touch icon link found.'; + } + + return { + score: passed ? 1 : 0, + explanation, + }; + } +} + +module.exports = IosPwaIcon; diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index 9184e54928f1..ffc3e3cbaf2b 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -179,6 +179,7 @@ const defaultConfig = { 'critical-request-chains', 'redirects', 'installable-manifest', + 'ios-pwa-icon', 'splash-screen', 'themed-omnibox', 'content-width', @@ -516,6 +517,7 @@ const defaultConfig = { {id: 'is-on-https', weight: 2, group: 'pwa-installable'}, {id: 'service-worker', weight: 1, group: 'pwa-installable'}, {id: 'installable-manifest', weight: 2, group: 'pwa-installable'}, + {id: 'ios-pwa-icon', weight: 1, group: 'pwa-installable'}, // PWA Optimized {id: 'redirects-http', weight: 2, group: 'pwa-optimized'}, {id: 'splash-screen', weight: 1, group: 'pwa-optimized'}, From 560dbe7fb687aba7853ec1803f3a89e018e6dfb4 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Sat, 4 May 2019 18:14:16 -0700 Subject: [PATCH 02/15] nits --- lighthouse-core/audits/ios-pwa-icon.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lighthouse-core/audits/ios-pwa-icon.js b/lighthouse-core/audits/ios-pwa-icon.js index defd17762177..a3c0bd3853ac 100644 --- a/lighthouse-core/audits/ios-pwa-icon.js +++ b/lighthouse-core/audits/ios-pwa-icon.js @@ -8,8 +8,7 @@ const Audit = require('./audit'); /** - * @fileoverview - * Audits if the page's web app has a valid icon for iOS installability. + * @fileoverview Audits if a page's web app has a valid icon for iOS installability. */ class IosPwaIcon extends Audit { @@ -19,11 +18,11 @@ class IosPwaIcon extends Audit { static get meta() { return { id: 'ios-pwa-icon', - title: 'Web app has a valid iOS PWA icon', - // title: 'Web app manifest meets the installability requirements', - failureTitle: 'Web app does not have a valid iOS PWA icon', - description: 'In order to be installable as an iOS PWA, ' - + 'web apps must have a valid iOS icon.', + title: 'Web app has a valid iOS touch icon', + failureTitle: 'Web app does not have a valid iOS touch icon', + description: 'In order to be installable as an iOS PWA ' + + 'web apps must have a valid apple-touch-icon. ' + + '[Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).', requiredArtifacts: ['LinkElements'], }; } @@ -31,7 +30,7 @@ class IosPwaIcon extends Audit { /** * @param {LH.Artifacts} artifacts * @param {LH.Audit.Context} _ - * @return {Promise} + * @return {LH.Audit.Product} */ static audit(artifacts, _) { const appleTouchIcons = artifacts.LinkElements.filter(el => el.rel === 'apple-touch-icon'); @@ -41,7 +40,7 @@ class IosPwaIcon extends Audit { let explanation; if (!passed) { - explanation = 'No Apple touch icon link found.'; + explanation = 'No `apple-touch-icon` link found.'; } return { From 00a9235818ee3c3d695182ae8dad543be38721f8 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Sat, 4 May 2019 18:30:25 -0700 Subject: [PATCH 03/15] added tests, updated sample json --- .../test/audits/ios-pwa-icon-test.js | 36 +++++++++++++++++++ lighthouse-core/test/results/sample_v2.json | 21 ++++++++++- proto/sample_v2_round_trip.json | 27 +++++++++++--- 3 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 lighthouse-core/test/audits/ios-pwa-icon-test.js diff --git a/lighthouse-core/test/audits/ios-pwa-icon-test.js b/lighthouse-core/test/audits/ios-pwa-icon-test.js new file mode 100644 index 000000000000..ca2021632503 --- /dev/null +++ b/lighthouse-core/test/audits/ios-pwa-icon-test.js @@ -0,0 +1,36 @@ +/** + * @license Copyright 2016 Google Inc. 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. + */ +'use strict'; + +const IosPwaIcon = require('../../audits/ios-pwa-icon.js'); + +/* eslint-env jest */ + +describe('PWA: ios-pwa-icon audit', () => { + it(`fails when apple-touch-icon is not present`, async () => { + const artifacts = { + LinkElements: [], + }; + + const context = {settings: {}, computedCache: new Map()}; + const {score, explanation} = IosPwaIcon.audit(artifacts, context); + + expect(score).toBe(0); + expect(explanation).toBe('No `apple-touch-icon` link found.'); + }); + + it(`passes when apple-touch-icon is on page`, async () => { + const artifacts = { + LinkElements: [{rel: 'apple-touch-icon', href: 'https://example.com/touch-icon.png'}], + }; + + const context = {settings: {}, computedCache: new Map()}; + const {score, explanation} = IosPwaIcon.audit(artifacts, context); + + expect(score).toBe(1); + expect(explanation).toBeUndefined(); + }); +}); diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index c045c7cddc02..cf2e19cb151d 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -476,6 +476,14 @@ ] } }, + "ios-pwa-icon": { + "id": "ios-pwa-icon", + "title": "Web app does not have a valid iOS touch icon", + "description": "In order to be installable as an iOS PWA web apps must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", + "score": 0, + "scoreDisplayMode": "binary", + "explanation": "No `apple-touch-icon` link found." + }, "splash-screen": { "id": "splash-screen", "title": "Is not configured for a custom splash screen", @@ -3660,6 +3668,11 @@ "weight": 2, "group": "pwa-installable" }, + { + "id": "ios-pwa-icon", + "weight": 1, + "group": "pwa-installable" + }, { "id": "redirects-http", "weight": 2, @@ -3704,7 +3717,7 @@ } ], "id": "pwa", - "score": 0.42 + "score": 0.41 } }, "categoryGroups": { @@ -4073,6 +4086,12 @@ "duration": 100, "entryType": "measure" }, + { + "startTime": 0, + "name": "lh:audit:ios-pwa-icon", + "duration": 100, + "entryType": "measure" + }, { "startTime": 0, "name": "lh:audit:splash-screen", diff --git a/proto/sample_v2_round_trip.json b/proto/sample_v2_round_trip.json index d9f5ba95c53b..045a0112e3c0 100644 --- a/proto/sample_v2_round_trip.json +++ b/proto/sample_v2_round_trip.json @@ -1040,6 +1040,14 @@ "scoreDisplayMode": "manual", "title": "Interactive elements indicate their purpose and state" }, + "ios-pwa-icon": { + "description": "In order to be installable as an iOS PWA web apps must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", + "explanation": "No `apple-touch-icon` link found.", + "id": "ios-pwa-icon", + "score": 0.0, + "scoreDisplayMode": "binary", + "title": "Web app does not have a valid iOS touch icon" + }, "is-crawlable": { "description": "Search engines are unable to include your pages in search results if they don't have permission to crawl them. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/indexing).", "details": { @@ -1100,7 +1108,7 @@ "name": "WordPress" } ], - "summary": {}, + "summary": null, "type": "table" }, "id": "js-libraries", @@ -1227,7 +1235,7 @@ "details": { "headings": [], "items": [], - "summary": {}, + "summary": null, "type": "table" }, "id": "link-text", @@ -1883,7 +1891,7 @@ "vulnCount": 2.0 } ], - "summary": {}, + "summary": null, "type": "table" }, "displayValue": "2 vulnerabilities detected", @@ -3521,6 +3529,11 @@ "id": "installable-manifest", "weight": 2.0 }, + { + "group": "pwa-installable", + "id": "ios-pwa-icon", + "weight": 1.0 + }, { "group": "pwa-optimized", "id": "redirects-http", @@ -3567,7 +3580,7 @@ "description": "These checks validate the aspects of a Progressive Web App. [Learn more](https://developers.google.com/web/progressive-web-apps/checklist).", "id": "pwa", "manualDescription": "These checks are required by the baseline [PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist) but are not automatically checked by Lighthouse. They do not affect your score but it's important that you verify them manually.", - "score": 0.42, + "score": 0.41, "title": "Progressive Web App" }, "seo": { @@ -4076,6 +4089,12 @@ "name": "lh:computed:ManifestValues", "startTime": 0.0 }, + { + "duration": 100.0, + "entryType": "measure", + "name": "lh:audit:ios-pwa-icon", + "startTime": 0.0 + }, { "duration": 100.0, "entryType": "measure", From e43efc6c9026c2dddda4b121fd88dc28ec680793 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Sat, 4 May 2019 21:05:52 -0700 Subject: [PATCH 04/15] update tests, i18n audit. --- .../test/cli/__snapshots__/index-test.js.snap | 8 +++++ lighthouse-core/audits/ios-pwa-icon.js | 35 ++++++++++++++----- lighthouse-core/lib/i18n/en-US.json | 16 +++++++++ .../test/audits/ios-pwa-icon-test.js | 16 +++++++-- .../html/renderer/category-renderer-test.js | 4 +-- lighthouse-core/test/results/sample_v2.json | 15 ++++++-- proto/sample_v2_round_trip.json | 6 ++-- 7 files changed, 81 insertions(+), 19 deletions(-) diff --git a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap index d1e45ec5d810..ea19819b1d63 100644 --- a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap +++ b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap @@ -69,6 +69,9 @@ Object { Object { "path": "installable-manifest", }, + Object { + "path": "ios-pwa-icon", + }, Object { "path": "splash-screen", }, @@ -893,6 +896,11 @@ Object { "id": "installable-manifest", "weight": 2, }, + Object { + "group": "pwa-installable", + "id": "ios-pwa-icon", + "weight": 1, + }, Object { "group": "pwa-optimized", "id": "redirects-http", diff --git a/lighthouse-core/audits/ios-pwa-icon.js b/lighthouse-core/audits/ios-pwa-icon.js index a3c0bd3853ac..bc4148fed619 100644 --- a/lighthouse-core/audits/ios-pwa-icon.js +++ b/lighthouse-core/audits/ios-pwa-icon.js @@ -5,12 +5,29 @@ */ 'use strict'; -const Audit = require('./audit'); +const Audit = require('./audit.js'); +const i18n = require('../lib/i18n/i18n.js'); /** - * @fileoverview Audits if a page's web app has a valid icon for iOS installability. + * @fileoverview Audits if a page's web app has an icon link for iOS installability. */ +const UIStrings = { + /** Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page contains a valid iOS touch icon. "iOS" is the name of the Apple operating system and should not be translated. */ + title: 'Site a valid iOS touch icon', + /** Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page does not contain a valid iOS touch icon. "iOS" is the name of the Apple operating system and should not be translated. */ + failureTitle: 'Site does not have a valid iOS touch icon', + /** Description of a Lighthouse audit that tells the user what having a valid apple-touch-icon does. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */ + description: + 'In order to be installable as an iOS PWA ' + + 'sites must have a valid apple-touch-icon. ' + + '[Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).', + /** Explanatory message stating that there was a failure in an audit caused by the page having an invalid apple-touch-icon link. `apple-touch-icon` is a HTML tag value and should not be translated. */ + explanation: 'No valid `apple-touch-icon` link found.', +}; + +const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); + class IosPwaIcon extends Audit { /** * @return {LH.Audit.Meta} @@ -18,11 +35,9 @@ class IosPwaIcon extends Audit { static get meta() { return { id: 'ios-pwa-icon', - title: 'Web app has a valid iOS touch icon', - failureTitle: 'Web app does not have a valid iOS touch icon', - description: 'In order to be installable as an iOS PWA ' - + 'web apps must have a valid apple-touch-icon. ' - + '[Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).', + title: str_(UIStrings.title), + failureTitle: str_(UIStrings.failureTitle), + description: str_(UIStrings.description), requiredArtifacts: ['LinkElements'], }; } @@ -33,14 +48,15 @@ class IosPwaIcon extends Audit { * @return {LH.Audit.Product} */ static audit(artifacts, _) { - const appleTouchIcons = artifacts.LinkElements.filter(el => el.rel === 'apple-touch-icon'); + const appleTouchIcons = artifacts.LinkElements.filter( + el => el.rel === 'apple-touch-icon' && el.href !== undefined); // Audit passes if an `apple-touch-icon` exists. const passed = appleTouchIcons.length !== 0; let explanation; if (!passed) { - explanation = 'No `apple-touch-icon` link found.'; + explanation = str_(UIStrings.explanation); } return { @@ -51,3 +67,4 @@ class IosPwaIcon extends Audit { } module.exports = IosPwaIcon; +module.exports.UIStrings = UIStrings; diff --git a/lighthouse-core/lib/i18n/en-US.json b/lighthouse-core/lib/i18n/en-US.json index e40e4f0483bd..056459e43673 100644 --- a/lighthouse-core/lib/i18n/en-US.json +++ b/lighthouse-core/lib/i18n/en-US.json @@ -635,6 +635,22 @@ "message": "All text remains visible during webfont loads", "description": "Title of a diagnostic audit that provides detail on if all the text on a webpage was visible while the page was loading its webfonts. This descriptive title is shown to users when the amount is acceptable and no user action is required." }, + "lighthouse-core/audits/ios-pwa-icon.js | description": { + "message": "In order to be installable as an iOS PWA sites must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", + "description": "Description of a Lighthouse audit that tells the user what having a valid apple-touch-icon does. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation." + }, + "lighthouse-core/audits/ios-pwa-icon.js | explanation": { + "message": "No valid `apple-touch-icon` link found.", + "description": "Explanatory message stating that there was a failure in an audit caused by the page having an invalid apple-touch-icon link. `apple-touch-icon` is a HTML tag value and should not be translated." + }, + "lighthouse-core/audits/ios-pwa-icon.js | failureTitle": { + "message": "Site does not have a valid iOS touch icon", + "description": "Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page does not contain a valid iOS touch icon. \"iOS\" is the name of the Apple operating system and should not be translated." + }, + "lighthouse-core/audits/ios-pwa-icon.js | title": { + "message": "Site a valid iOS touch icon", + "description": "Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page contains a valid iOS touch icon. \"iOS\" is the name of the Apple operating system and should not be translated." + }, "lighthouse-core/audits/load-fast-enough-for-pwa.js | description": { "message": "A fast page load over a cellular network ensures a good mobile user experience. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/fast-3g).", "description": "Description of a Lighthouse audit that tells the user *why* they need to load fast enough on mobile networks. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation." diff --git a/lighthouse-core/test/audits/ios-pwa-icon-test.js b/lighthouse-core/test/audits/ios-pwa-icon-test.js index ca2021632503..febe6787a286 100644 --- a/lighthouse-core/test/audits/ios-pwa-icon-test.js +++ b/lighthouse-core/test/audits/ios-pwa-icon-test.js @@ -1,5 +1,5 @@ /** - * @license Copyright 2016 Google Inc. All Rights Reserved. + * @license Copyright 2019 Google Inc. 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. */ @@ -19,7 +19,19 @@ describe('PWA: ios-pwa-icon audit', () => { const {score, explanation} = IosPwaIcon.audit(artifacts, context); expect(score).toBe(0); - expect(explanation).toBe('No `apple-touch-icon` link found.'); + expect(explanation).toBeDisplayString('No valid `apple-touch-icon` link found.'); + }); + + it(`fails when apple-touch-icon does not have an href`, async () => { + const artifacts = { + LinkElements: [{rel: 'apple-touch-icon'}], + }; + + const context = {settings: {}, computedCache: new Map()}; + const {score, explanation} = IosPwaIcon.audit(artifacts, context); + + expect(score).toBe(0); + expect(explanation).toBeDisplayString('No valid `apple-touch-icon` link found.'); }); it(`passes when apple-touch-icon is on page`, async () => { diff --git a/lighthouse-core/test/report/html/renderer/category-renderer-test.js b/lighthouse-core/test/report/html/renderer/category-renderer-test.js index 8e691f5a5862..b18f27521c78 100644 --- a/lighthouse-core/test/report/html/renderer/category-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/category-renderer-test.js @@ -366,7 +366,7 @@ describe('CategoryRenderer', () => { const manualAudits = elem.querySelectorAll('.lh-clump--manual .lh-audit'); assert.equal(passedAudits.length, 2); - assert.equal(failedAudits.length, 8); + assert.equal(failedAudits.length, 9); assert.equal(warningAudits.length, 2); assert.equal(manualAudits.length, 3); }); @@ -380,7 +380,7 @@ describe('CategoryRenderer', () => { const failedAudits = elem.querySelectorAll('.lh-clump--failed .lh-audit'); assert.equal(passedAudits.length, 0); - assert.equal(failedAudits.length, 12); + assert.equal(failedAudits.length, 13); }); it('expands warning audit group', () => { diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index cf2e19cb151d..67153a614003 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -478,11 +478,11 @@ }, "ios-pwa-icon": { "id": "ios-pwa-icon", - "title": "Web app does not have a valid iOS touch icon", - "description": "In order to be installable as an iOS PWA web apps must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", + "title": "Site does not have a valid iOS touch icon", + "description": "In order to be installable as an iOS PWA sites must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", "score": 0, "scoreDisplayMode": "binary", - "explanation": "No `apple-touch-icon` link found." + "explanation": "No valid `apple-touch-icon` link found." }, "splash-screen": { "id": "splash-screen", @@ -4930,6 +4930,15 @@ "lighthouse-core/audits/redirects.js | description": [ "audits.redirects.description" ], + "lighthouse-core/audits/ios-pwa-icon.js | failureTitle": [ + "audits[ios-pwa-icon].title" + ], + "lighthouse-core/audits/ios-pwa-icon.js | description": [ + "audits[ios-pwa-icon].description" + ], + "lighthouse-core/audits/ios-pwa-icon.js | explanation": [ + "audits[ios-pwa-icon].explanation" + ], "lighthouse-core/audits/mainthread-work-breakdown.js | title": [ "audits[mainthread-work-breakdown].title" ], diff --git a/proto/sample_v2_round_trip.json b/proto/sample_v2_round_trip.json index 045a0112e3c0..fe108d4920a4 100644 --- a/proto/sample_v2_round_trip.json +++ b/proto/sample_v2_round_trip.json @@ -1041,12 +1041,12 @@ "title": "Interactive elements indicate their purpose and state" }, "ios-pwa-icon": { - "description": "In order to be installable as an iOS PWA web apps must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", - "explanation": "No `apple-touch-icon` link found.", + "description": "In order to be installable as an iOS PWA sites must have a valid apple-touch-icon. [Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).", + "explanation": "No valid `apple-touch-icon` link found.", "id": "ios-pwa-icon", "score": 0.0, "scoreDisplayMode": "binary", - "title": "Web app does not have a valid iOS touch icon" + "title": "Site does not have a valid iOS touch icon" }, "is-crawlable": { "description": "Search engines are unable to include your pages in search results if they don't have permission to crawl them. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/indexing).", From 5239b85b044cc5d194e0728fb0650c08b764acb4 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Sun, 5 May 2019 16:56:42 -0700 Subject: [PATCH 05/15] renamed files, updated a lot of things. testing next. --- .../{ios-pwa-icon.js => apple-touch-icon.js} | 56 +++++++++++++------ lighthouse-core/config/default-config.js | 4 +- lighthouse-core/lib/i18n/en-US.json | 36 ++++++------ ...-icon-test.js => apple-touch-icon-test.js} | 4 +- lighthouse-core/test/results/sample_v2.json | 33 +++++------ proto/sample_v2_round_trip.json | 28 +++++----- 6 files changed, 92 insertions(+), 69 deletions(-) rename lighthouse-core/audits/{ios-pwa-icon.js => apple-touch-icon.js} (53%) rename lighthouse-core/test/audits/{ios-pwa-icon-test.js => apple-touch-icon-test.js} (94%) diff --git a/lighthouse-core/audits/ios-pwa-icon.js b/lighthouse-core/audits/apple-touch-icon.js similarity index 53% rename from lighthouse-core/audits/ios-pwa-icon.js rename to lighthouse-core/audits/apple-touch-icon.js index bc4148fed619..db9d8d99067b 100644 --- a/lighthouse-core/audits/ios-pwa-icon.js +++ b/lighthouse-core/audits/apple-touch-icon.js @@ -6,6 +6,7 @@ 'use strict'; const Audit = require('./audit.js'); +const URL = require('../lib/url-shim'); const i18n = require('../lib/i18n/i18n.js'); /** @@ -13,17 +14,19 @@ const i18n = require('../lib/i18n/i18n.js'); */ const UIStrings = { - /** Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page contains a valid iOS touch icon. "iOS" is the name of the Apple operating system and should not be translated. */ - title: 'Site a valid iOS touch icon', - /** Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page does not contain a valid iOS touch icon. "iOS" is the name of the Apple operating system and should not be translated. */ - failureTitle: 'Site does not have a valid iOS touch icon', + /** Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page contains a valid iOS touch icon. */ + title: 'Provides a valid apple-touch-icon', + /** Title of a Lighthouse audit that tells the user that their site contains a vaild touch icon. This descriptive title is shown when the page does not contain a valid iOS touch icon. */ + failureTitle: 'Does not provide a valid apple-touch-icon', /** Description of a Lighthouse audit that tells the user what having a valid apple-touch-icon does. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */ - description: - 'In order to be installable as an iOS PWA ' + - 'sites must have a valid apple-touch-icon. ' + - '[Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).', - /** Explanatory message stating that there was a failure in an audit caused by the page having an invalid apple-touch-icon link. `apple-touch-icon` is a HTML tag value and should not be translated. */ - explanation: 'No valid `apple-touch-icon` link found.', + description: 'In order to have a custom icon on iOS once ' + + 'installed, a site must have a valid apple-touch-icon. ' + + '[Learn More](https://developers.google.com/web/fundamentals/design-and-ux/browser-customization/).', + /** Warning that HTML attribute `apple-touch-icon-precomposed` should not be used in favor of `apple-touch-icon`. "apple-touch-icon-precomposed" and "apple-touch-icon" are HTML attributes and should not be translated. */ + precomposedWarning: '`apple-touch-icon-precomposed` is out of date, ' + + '`apple-touch-icon` is preferred.', + /** Explanatory message stating that there was a failure in an audit caused by the page's `apple-touch-icon` having an invalide `href` attribute. `apple-touch-icon` and `href` are HTML tag values and should not be translated. */ + explanation: '`apple-touch-icon`\'s `href` attribute is not valid', }; const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); @@ -34,7 +37,7 @@ class IosPwaIcon extends Audit { */ static get meta() { return { - id: 'ios-pwa-icon', + id: 'apple-touch-icon', title: str_(UIStrings.title), failureTitle: str_(UIStrings.failureTitle), description: str_(UIStrings.description), @@ -44,23 +47,42 @@ class IosPwaIcon extends Audit { /** * @param {LH.Artifacts} artifacts - * @param {LH.Audit.Context} _ * @return {LH.Audit.Product} */ - static audit(artifacts, _) { + static audit(artifacts) { + let explanation; const appleTouchIcons = artifacts.LinkElements.filter( - el => el.rel === 'apple-touch-icon' && el.href !== undefined); + el => { + if (el.rel !== 'apple-touch-icon' && el.rel !== 'apple-touch-icon-precomposed' + || !el.href) { + return false; + } + // Check that the href is valid + try { + new URL(el.href); + return true; + } catch (e) {} + // Check if the href needs the base url to be valid + try { + new URL(el.href, artifacts.URL.finalUrl); + return true; + } catch (e) { + explanation = str_(UIStrings.explanation); + return false; + } + }); // Audit passes if an `apple-touch-icon` exists. const passed = appleTouchIcons.length !== 0; - let explanation; - if (!passed) { - explanation = str_(UIStrings.explanation); + const warnings = []; + if (appleTouchIcons.filter(el => el.rel === 'apple-touch-icon-precomposed').length !== 0) { + warnings.push(str_(UIStrings.precomposedWarning)); } return { score: passed ? 1 : 0, + warnings, explanation, }; } diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index ffc3e3cbaf2b..42672983cf19 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -179,7 +179,7 @@ const defaultConfig = { 'critical-request-chains', 'redirects', 'installable-manifest', - 'ios-pwa-icon', + 'apple-touch-icon', 'splash-screen', 'themed-omnibox', 'content-width', @@ -517,7 +517,6 @@ const defaultConfig = { {id: 'is-on-https', weight: 2, group: 'pwa-installable'}, {id: 'service-worker', weight: 1, group: 'pwa-installable'}, {id: 'installable-manifest', weight: 2, group: 'pwa-installable'}, - {id: 'ios-pwa-icon', weight: 1, group: 'pwa-installable'}, // PWA Optimized {id: 'redirects-http', weight: 2, group: 'pwa-optimized'}, {id: 'splash-screen', weight: 1, group: 'pwa-optimized'}, @@ -525,6 +524,7 @@ const defaultConfig = { {id: 'content-width', weight: 1, group: 'pwa-optimized'}, {id: 'viewport', weight: 2, group: 'pwa-optimized'}, {id: 'without-javascript', weight: 1, group: 'pwa-optimized'}, + {id: 'apple-touch-icon', weight: 1, group: 'pwa-optimized'}, // Manual audits {id: 'pwa-cross-browser', weight: 0}, {id: 'pwa-page-transitions', weight: 0}, diff --git a/lighthouse-core/lib/i18n/en-US.json b/lighthouse-core/lib/i18n/en-US.json index 056459e43673..a87bc37f2414 100644 --- a/lighthouse-core/lib/i18n/en-US.json +++ b/lighthouse-core/lib/i18n/en-US.json @@ -423,6 +423,26 @@ "message": "`