-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: cron to check for relevant chromium changes (#11763)
- Loading branch information
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
third-party/chromium-synchronization/inspector-issueAdded-types-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
82
third-party/chromium-synchronization/installability-errors-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |