Skip to content

Commit

Permalink
fix: host dependency validation (#6227)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Apr 20, 2021
1 parent f9af4c3 commit 9cd89ae
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 21 deletions.
34 changes: 34 additions & 0 deletions packages/installation-tests/installation-tests.sh
Expand Up @@ -42,6 +42,8 @@ function copy_test_scripts {
cp "${SCRIPTS_PATH}/inspector-custom-executable.js" .
cp "${SCRIPTS_PATH}/sanity.js" .
cp "${SCRIPTS_PATH}/screencast.js" .
cp "${SCRIPTS_PATH}/validate-dependencies.js" .
cp "${SCRIPTS_PATH}/validate-dependencies-skip-executable-path.js" .
cp "${SCRIPTS_PATH}/esm.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .
Expand All @@ -64,6 +66,8 @@ function run_tests {
test_playwright_chromium_should_work
test_playwright_webkit_should_work
test_playwright_firefox_should_work
test_playwright_validate_dependencies
test_playwright_validate_dependencies_skip_executable_path
test_playwright_global_installation
test_playwright_global_installation_cross_package
test_playwright_electron_should_work
Expand Down Expand Up @@ -359,6 +363,36 @@ function test_playwright_firefox_should_work {
echo "${FUNCNAME[0]} success"
}

function test_playwright_validate_dependencies {
initialize_test "${FUNCNAME[0]}"

npm install ${PLAYWRIGHT_TGZ}
copy_test_scripts

OUTPUT="$(node validate-dependencies.js)"
if [[ "${OUTPUT}" != *"PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"* ]]; then
echo "ERROR: validateDependencies was not called"
exit 1
fi

echo "${FUNCNAME[0]} success"
}

function test_playwright_validate_dependencies_skip_executable_path {
initialize_test "${FUNCNAME[0]}"

npm install ${PLAYWRIGHT_TGZ}
copy_test_scripts

OUTPUT="$(node validate-dependencies-skip-executable-path.js)"
if [[ "${OUTPUT}" == *"PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"* ]]; then
echo "ERROR: validateDependencies was called"
exit 1
fi

echo "${FUNCNAME[0]} success"
}

function test_playwright_electron_should_work {
initialize_test "${FUNCNAME[0]}"

Expand Down
@@ -0,0 +1,10 @@
const playwright = require('playwright');

process.env.PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = 1;

(async () => {
const browser = await playwright.chromium.launch({
executablePath: playwright.chromium.executablePath()
});
await browser.close();
})();
8 changes: 8 additions & 0 deletions packages/installation-tests/validate-dependencies.js
@@ -0,0 +1,8 @@
const playwright = require('playwright');

process.env.PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = 1;

(async () => {
const browser = await playwright.chromium.launch();
await browser.close();
})();
2 changes: 1 addition & 1 deletion src/install/installer.ts
Expand Up @@ -74,7 +74,7 @@ async function validateCache(linksDir: string, browserNames: BrowserName[]) {
linkTarget = (await fsReadFileAsync(linkPath)).toString();
const linkRegistry = new Registry(linkTarget);
for (const browserName of allBrowserNames) {
if (!linkRegistry.shouldRetain(browserName))
if (!linkRegistry.isSupportedBrowser(browserName))
continue;
const usedBrowserPath = linkRegistry.browserDirectory(browserName);
const browserRevision = linkRegistry.revision(browserName);
Expand Down
7 changes: 4 additions & 3 deletions src/server/browserType.ts
Expand Up @@ -178,10 +178,11 @@ export abstract class BrowserType extends SdkObject {
throw new Error(errorMessageLines.join('\n'));
}

if (!executable) {
// Only validate dependencies for bundled browsers.
// Only validate dependencies for downloadable browsers.
if (!executablePath && !options.channel)
await validateHostRequirements(this._registry, this._name);
}
else if (!executablePath && options.channel && this._registry.isSupportedBrowser(options.channel))
await validateHostRequirements(this._registry, options.channel as registry.BrowserName);

let wsEndpointCallback: ((wsEndpoint: string) => void) | undefined;
const wsEndpoint = options.useWebSocket ? new Promise<string>(f => wsEndpointCallback = f) : undefined;
Expand Down
37 changes: 20 additions & 17 deletions src/utils/registry.ts
Expand Up @@ -292,21 +292,25 @@ export class Registry {

linuxLddDirectories(browserName: BrowserName): string[] {
const browserDirectory = this.browserDirectory(browserName);
if (browserName === 'chromium')
return [path.join(browserDirectory, 'chrome-linux')];
if (browserName === 'firefox')
return [path.join(browserDirectory, 'firefox')];
if (browserName === 'webkit') {
return [
path.join(browserDirectory, 'minibrowser-gtk'),
path.join(browserDirectory, 'minibrowser-gtk', 'bin'),
path.join(browserDirectory, 'minibrowser-gtk', 'lib'),
path.join(browserDirectory, 'minibrowser-wpe'),
path.join(browserDirectory, 'minibrowser-wpe', 'bin'),
path.join(browserDirectory, 'minibrowser-wpe', 'lib'),
];
switch (browserName) {
case 'chromium':
return [path.join(browserDirectory, 'chrome-linux')];
case 'webkit':
case 'webkit-technology-preview':
return [
path.join(browserDirectory, 'minibrowser-gtk'),
path.join(browserDirectory, 'minibrowser-gtk', 'bin'),
path.join(browserDirectory, 'minibrowser-gtk', 'lib'),
path.join(browserDirectory, 'minibrowser-wpe'),
path.join(browserDirectory, 'minibrowser-wpe', 'bin'),
path.join(browserDirectory, 'minibrowser-wpe', 'lib'),
];
case 'firefox':
case 'firefox-stable':
return [path.join(browserDirectory, 'firefox')];
default:
return [];
}
return [];
}

windowsExeAndDllDirectories(browserName: BrowserName): string[] {
Expand Down Expand Up @@ -345,14 +349,13 @@ export class Registry {
return util.format(urlTemplate, downloadHost, browser.revision);
}

shouldRetain(browserName: BrowserName): boolean {
isSupportedBrowser(browserName: string): boolean {
// We retain browsers if they are found in the descriptor.
// Note, however, that there are older versions out in the wild that rely on
// the "download" field in the browser descriptor and use its value
// to retain and download browsers.
// As of v1.10, we decided to abandon "download" field.
const browser = this._descriptors.find(browser => browser.name === browserName);
return !!browser;
return this._descriptors.some(browser => browser.name === browserName);
}

installByDefault(): BrowserName[] {
Expand Down

0 comments on commit 9cd89ae

Please sign in to comment.