Skip to content

Commit

Permalink
tests: cron to check for relevant chromium changes (#11763)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Apr 13, 2021
1 parent ba53daf commit f3bfb3c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -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<LH.Crdp.Audits.InspectorIssueDetails>} */
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);
});
});
82 changes: 82 additions & 0 deletions third-party/chromium-synchronization/installability-errors-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit f3bfb3c

Please sign in to comment.