From f3bfb3ce89396fa580b5dd5172025c595c884607 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Tue, 13 Apr 2021 10:51:58 -0700 Subject: [PATCH] tests: cron to check for relevant chromium changes (#11763) --- .../{check-md-links.yml => cron-weekly.yml} | 14 ++++ jest.config.js | 1 + .../inspector-issueAdded-types-test.js | 60 ++++++++++++++ .../installability-errors-test.js | 82 +++++++++++++++++++ 4 files changed, 157 insertions(+) rename .github/workflows/{check-md-links.yml => cron-weekly.yml} (71%) create mode 100644 third-party/chromium-synchronization/inspector-issueAdded-types-test.js create mode 100644 third-party/chromium-synchronization/installability-errors-test.js diff --git a/.github/workflows/check-md-links.yml b/.github/workflows/cron-weekly.yml similarity index 71% rename from .github/workflows/check-md-links.yml rename to .github/workflows/cron-weekly.yml index ccdbfeb2bc84..0d9bc0f0633f 100644 --- a/.github/workflows/check-md-links.yml +++ b/.github/workflows/cron-weekly.yml @@ -24,3 +24,17 @@ jobs: use-verbose-mode: 'yes' config-file: '.github/workflows/markdown.links.config.json' max-depth: 0 + + up-to-date-with-chromium: + runs-on: ubuntu-latest + + steps: + - name: git clone + uses: actions/checkout@v2 + - name: Use Node.js 12.x + uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: yarn --frozen-lockfile + + - run: yarn jest --testMatch="**/third-party/chromium-synchronization/*-test.js" diff --git a/jest.config.js b/jest.config.js index 5ced6597d8a3..868eb0ba6f95 100644 --- a/jest.config.js +++ b/jest.config.js @@ -27,6 +27,7 @@ module.exports = { '**/lighthouse-treemap/**/*-test-pptr.js', '**/lighthouse-viewer/**/*-test.js', '**/lighthouse-viewer/**/*-test-pptr.js', + '**/third-party/**/*-test.js', '**/clients/test/**/*-test.js', '**/docs/**/*.test.js', ], diff --git a/third-party/chromium-synchronization/inspector-issueAdded-types-test.js b/third-party/chromium-synchronization/inspector-issueAdded-types-test.js new file mode 100644 index 000000000000..cf0d247e5671 --- /dev/null +++ b/third-party/chromium-synchronization/inspector-issueAdded-types-test.js @@ -0,0 +1,60 @@ +/** + * @license Copyright 2020 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. + */ +'use strict'; + +const fs = require('fs'); +const fetch = require('node-fetch'); + +const inspectorIssuesGathererPath = __dirname + + '/../../lighthouse-core/gather/gatherers/inspector-issues.js'; +const inspectorIssuesGathererSource = fs.readFileSync(inspectorIssuesGathererPath, 'utf-8'); + +/* eslint-env jest */ + +describe('issueAdded types', () => { + /** @type {Array} */ + let inspectorIssueDetailsTypes; + + beforeAll(async () => { + const browserProtocolUrl = + 'https://raw.githubusercontent.com/ChromeDevTools/devtools-protocol/master/json/browser_protocol.json'; + const json = await fetch(browserProtocolUrl).then(r => r.json()); + + inspectorIssueDetailsTypes = json.domains + .find(d => d.domain === 'Audits').types + .find(t => t.id === 'InspectorIssueDetails').properties + .map(t => t.name) + .sort(); + }); + + it('should notify us if something changed', () => { + expect(inspectorIssueDetailsTypes).toMatchInlineSnapshot(` + Array [ + "blockedByResponseIssueDetails", + "contentSecurityPolicyIssueDetails", + "heavyAdIssueDetails", + "mixedContentIssueDetails", + "sameSiteCookieIssueDetails", + "sharedArrayBufferTransferIssueDetails", + ] + `); + }); + + it('are each handled explicitly in the gatherer', () => { + // Regex relies on the typecasts + const sourceTypeMatches = inspectorIssuesGathererSource.matchAll( + /LH\.Crdp\.Audits\.(.*?Details)>/g + ); + + const sourceTypeMatchIds = [...sourceTypeMatches] + .map(match => match[1]) + // mapping TS type casing (TitleCase) to protocol types (camelCase) + .map(id => `${id.slice(0, 1).toLowerCase()}${id.slice(1)}`) + .sort(); + + expect(sourceTypeMatchIds).toMatchObject(inspectorIssueDetailsTypes); + }); +}); diff --git a/third-party/chromium-synchronization/installability-errors-test.js b/third-party/chromium-synchronization/installability-errors-test.js new file mode 100644 index 000000000000..4bbc1a5315e3 --- /dev/null +++ b/third-party/chromium-synchronization/installability-errors-test.js @@ -0,0 +1,82 @@ +/** + * @license Copyright 2020 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. + */ +'use strict'; + +const fetch = require('node-fetch'); + +const InstallableManifestAudit = require('../../lighthouse-core/audits/installable-manifest.js'); + +/* eslint-env jest */ + +describe('installabilityErrors', () => { + let chromiumErrorIds; + + beforeAll(async () => { + const installableLoggingGitTilesUrl = + 'https://chromium.googlesource.com/chromium/src/+/master/components/webapps/installable/installable_logging.cc?format=TEXT'; + const resp = await fetch(installableLoggingGitTilesUrl); + if (!resp.ok) { + throw new Error(`Chromium source fetch failed: ${resp.status} ${resp.statusText}`); + } + const base64 = await resp.text(); + const buff = Buffer.from(base64, 'base64'); + const text = buff.toString('utf-8'); + + // Apply some *beautiful* regexes to parse the C++ of https://chromium.googlesource.com/chromium/src/+/master/chrome/browser/installable/installable_logging.cc + const handledErrorConsts = [...text.matchAll(/error_id = (k.*?);/g)].map(([_, match]) => match); + const errorConstsToIdsCode = [...text.matchAll(/static const char k.*?Id\[\](.|\n)*?;/g)].map( + ([match]) => match.replace(/\n/, '') + ); + const errorConstsToIds = errorConstsToIdsCode.map(txt => [ + txt.match(/char (k.*?)\[/)[1], + txt.match(/ "(.*?)"/)[1], + ]); + const errorConstsToIdsDict = Object.fromEntries(errorConstsToIds); + + chromiumErrorIds = handledErrorConsts.map(varName => { + if (!errorConstsToIdsDict[varName]) throw new Error(`Error const (${varName}) not found!`); + return errorConstsToIdsDict[varName]; + }).sort(); + }); + + it('should notify us if something changed', () => { + expect(chromiumErrorIds).toMatchInlineSnapshot(` + Array [ + "already-installed", + "cannot-download-icon", + "ids-do-not-match", + "in-incognito", + "manifest-display-not-supported", + "manifest-display-override-not-supported", + "manifest-empty", + "manifest-location-changed", + "manifest-missing-name-or-short-name", + "manifest-missing-suitable-icon", + "no-acceptable-icon", + "no-icon-available", + "no-id-specified", + "no-manifest", + "no-matching-service-worker", + "no-url-for-service-worker", + "not-from-secure-origin", + "not-offline-capable", + "platform-not-supported-on-android", + "prefer-related-applications", + "prefer-related-applications-only-beta-stable", + "start-url-not-valid", + "url-not-supported-for-webapk", + "warn-not-offline-capable", + ] + `); + }); + + it('are each handled explicitly in the gatherer', () => { + const errorStrings = Object.keys(InstallableManifestAudit.UIStrings) + .filter(key => chromiumErrorIds.includes(key)) + .sort(); + expect(errorStrings).toEqual(chromiumErrorIds); + }); +});