From ca31d1f487161bf0193039e1f6dcdad2fb0c99b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Fern=C3=A1ndez=20Aldana?= Date: Mon, 10 Oct 2022 15:25:43 +0200 Subject: [PATCH 1/3] fix: Ctrl+C now works in firefox-android target when using run with --no-reload --- src/extension-runners/firefox-android.js | 2 ++ .../test.firefox-android.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index fec64e0f42..b1e009e77c 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -598,6 +598,8 @@ export class FirefoxAndroidExtensionRunner { } finally { if (isTTY(stdin)) { stdin.removeListener('keypress', handleCtrlC); + // Restore mode so Ctrl-C can be used to kill the process. + setRawMode(stdin, false); } } diff --git a/tests/unit/test-extension-runners/test.firefox-android.js b/tests/unit/test-extension-runners/test.firefox-android.js index 8b5f061756..5d0ea57516 100644 --- a/tests/unit/test-extension-runners/test.firefox-android.js +++ b/tests/unit/test-extension-runners/test.firefox-android.js @@ -1025,5 +1025,22 @@ describe('util/extension-runners/firefox-android', () => { }); }); + it('Stdin raw mode is set to false before setupForward', + async () => { + const { + params, fakeADBUtils, + } = prepareSelectedDeviceAndAPKParams(); + + fakeADBUtils.setupForward = sinon.spy(async () => { + fakeStdin.emit('keypress', 'c', {name: 'c', ctrl: true}); + }); + + const fakeStdin = sinon.spy(createFakeStdin()); + params.stdin = fakeStdin; + + const runnerInstance = new FirefoxAndroidExtensionRunner(params); + await runnerInstance.run(); + assert.deepEqual(fakeStdin.setRawMode.lastCall.args, [false]); + }); }); From 8fb99d4c6672dbaf9a59f3a13d1f95cf8be9d751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Fern=C3=A1ndez=20Aldana?= Date: Mon, 10 Oct 2022 20:17:47 +0200 Subject: [PATCH 2/3] fix: Ctrl+C now works in firefox-android target while awaiting to start activity --- src/extension-runners/firefox-android.js | 47 ++++++++++++++----- src/util/adb.js | 30 +++++++++++- .../test.firefox-android.js | 42 +++++++++++++++++ tests/unit/test-util/test.adb.js | 27 +++++++++++ 4 files changed, 134 insertions(+), 12 deletions(-) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index b1e009e77c..562c857a18 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -145,6 +145,13 @@ export class FirefoxAndroidExtensionRunner { // push the profile preferences to the remote profile dir. await this.adbPrepareProfileDir(); + const stdin = this.params.stdin || process.stdin; + + if (isTTY(stdin)) { + readline.emitKeypressEvents(stdin); + setRawMode(stdin, true); + } + // NOTE: running Firefox for Android on the Android Emulator can be // pretty slow, we can run the following 3 steps in parallel to speed up // it a bit. @@ -164,6 +171,11 @@ export class FirefoxAndroidExtensionRunner { this.adbDiscoveryAndForwardRDPUnixSocket(), ]); + if (isTTY(stdin)) { + // Restore mode so Ctrl-C can be used to kill the process. + setRawMode(stdin, false); + } + // Connect to RDP socket on the local tcp server, install all the pushed extension // and keep track of the built and installed extension by extension sourceDir. await this.rdpInstallExtensions(); @@ -499,12 +511,30 @@ export class FirefoxAndroidExtensionRunner { log.debug(`Using profile ${deviceProfileDir} (ignored by Fenix)`); - await adbUtils.startFirefoxAPK( - selectedAdbDevice, - selectedFirefoxApk, - firefoxApkComponent, - deviceProfileDir, - ); + const stdin = this.params.stdin || process.stdin; + + const handleCtrlC = (str, key) => { + if (key.ctrl && key.name === 'c') { + adbUtils.setUserAbortStartActivity(true); + } + }; + + if (isTTY(stdin)) { + stdin.on('keypress', handleCtrlC); + } + + try { + await adbUtils.startFirefoxAPK( + selectedAdbDevice, + selectedFirefoxApk, + firefoxApkComponent, + deviceProfileDir, + ); + } finally { + if (isTTY(stdin)) { + stdin.removeListener('keypress', handleCtrlC); + } + } } async buildAndPushExtension(sourceDir: string) { @@ -579,9 +609,6 @@ export class FirefoxAndroidExtensionRunner { // TODO: use noInput property to decide if we should // disable direct keypress handling. if (isTTY(stdin)) { - readline.emitKeypressEvents(stdin); - setRawMode(stdin, true); - stdin.on('keypress', handleCtrlC); } @@ -598,8 +625,6 @@ export class FirefoxAndroidExtensionRunner { } finally { if (isTTY(stdin)) { stdin.removeListener('keypress', handleCtrlC); - // Restore mode so Ctrl-C can be used to kill the process. - setRawMode(stdin, false); } } diff --git a/src/util/adb.js b/src/util/adb.js index 7e64006612..a252287d71 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -60,6 +60,10 @@ export default class ADBUtils { // while it is still executing. userAbortDiscovery: boolean; + // Toggled when the user wants to abort the Start Activity loop + // while it is still executing. + userAbortStartActivity: boolean; + constructor(params: ADBUtilsParams) { this.params = params; @@ -81,6 +85,7 @@ export default class ADBUtils { this.artifactsDirMap = new Map(); this.userAbortDiscovery = false; + this.userAbortStartActivity = false; } runShellCommand( @@ -343,20 +348,43 @@ export default class ADBUtils { // the following to: `${apk}/${apk}.${apkComponent}` const component = `${apk}/${apkComponent}`; - await wrapADBCall(async () => { + let exception; + wrapADBCall(async () => { await adbClient.getDevice(deviceId).startActivity({ wait: true, action: 'android.activity.MAIN', component, extras, }); + }).then(() => { + exception = null; + }).catch((err) => { + exception = err; }); + + // Wait for the activity to be started. + while (exception === undefined) { + if (this.userAbortStartActivity) { + throw new UsageError( + 'Exiting Firefox Start Activity on user request' + ); + } + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + + if (exception) { + throw exception; + } } setUserAbortDiscovery(value: boolean) { this.userAbortDiscovery = value; } + setUserAbortStartActivity(value: boolean) { + this.userAbortStartActivity = value; + } + async discoverRDPUnixSocket( deviceId: string, apk: string, {maxDiscoveryTime, retryInterval}: DiscoveryParams = {} diff --git a/tests/unit/test-extension-runners/test.firefox-android.js b/tests/unit/test-extension-runners/test.firefox-android.js index 5d0ea57516..8a0373b53f 100644 --- a/tests/unit/test-extension-runners/test.firefox-android.js +++ b/tests/unit/test-extension-runners/test.firefox-android.js @@ -132,6 +132,7 @@ function prepareSelectedDeviceAndAPKParams( clearArtifactsDir: sinon.spy(() => Promise.resolve()), detectOrRemoveOldArtifacts: sinon.spy(() => Promise.resolve(true)), setUserAbortDiscovery: sinon.spy(() => {}), + setUserAbortStartActivity: sinon.spy(() => {}), ensureRequiredAPKRuntimePermissions: sinon.spy(() => Promise.resolve()), ...adbOverrides, }; @@ -786,6 +787,47 @@ describe('util/extension-runners/firefox-android', () => { ); }); + it('allows user to exit while waiting to start activity', + async () => { + const { + params, fakeADBUtils, + } = prepareSelectedDeviceAndAPKParams(); + + fakeADBUtils.startFirefoxAPK = sinon.spy(async () => { + fakeStdin.emit('keypress', 'c', {name: 'c', ctrl: true}); + + sinon.assert.calledOnce(fakeADBUtils.setUserAbortStartActivity); + sinon.assert.calledWith( + fakeADBUtils.setUserAbortStartActivity + ); + + // Reject the expected error, if all the assertion passes. + throw new UsageError('fake user exit'); + }); + + const fakeStdin = createFakeStdin(); + + params.stdin = fakeStdin; + + let actualError; + + try { + const runnerInstance = new FirefoxAndroidExtensionRunner(params); + await runnerInstance.run(); + } catch (error) { + actualError = error; + } finally { + fakeStdin.emit('keypress', 'c', {name: 'c', ctrl: true}); + } + + assert.instanceOf(actualError, UsageError); + assert.match( + actualError && actualError.message, + /fake user exit/ + ); + }); + + it('rejects on Android Firefox Debugger discovery timeouts', async () => { const { diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index 45c6d88131..e96777ce7c 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -1097,6 +1097,33 @@ describe('utils/adb', () => { } ); }); + + it('rejects an UsageError on setUserAbortStartActivity call', async () => { + const adb = getFakeADBKit({ + adbDevice: { + startActivity: sinon.spy(() => Promise.resolve()), + }, + adbkitUtil: { + readAll: sinon.spy(() => Promise.resolve(Buffer.from('\n'))), + }, + }); + const adbUtils = new ADBUtils({adb}); + + adbUtils.setUserAbortStartActivity(true); + + const promise = adbUtils.startFirefoxAPK( + 'device1', + 'org.mozilla.firefox_mybuild', + undefined, // firefoxApkComponent/* + '/fake/custom/profile/path' + ); + + await assert.isRejected(promise, UsageError); + await assert.isRejected( + promise, + 'Exiting Firefox Start Activity on user request' + ); + }); }); describe('discoverRDPUnixSocket', () => { From 7dd22e7f0ceef53f883be849482bf8e532139862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Fern=C3=A1ndez=20Aldana?= Date: Fri, 28 Oct 2022 20:15:36 +0200 Subject: [PATCH 3/3] Prettier format --- src/extension-runners/firefox-android.js | 235 ++++++++---------- src/util/adb.js | 16 +- .../test.firefox-android.js | 25 +- tests/unit/test-util/test.adb.js | 2 +- 4 files changed, 126 insertions(+), 152 deletions(-) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index 562c857a18..9ca556938b 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -8,11 +8,9 @@ import path from 'path'; import readline from 'readline'; -import {withTempDir} from '../util/temp-dir.js'; +import { withTempDir } from '../util/temp-dir.js'; import DefaultADBUtils from '../util/adb.js'; -import { - showDesktopNotification as defaultDesktopNotifications, -} from '../util/desktop-notifier.js'; +import { showDesktopNotification as defaultDesktopNotifications } from '../util/desktop-notifier.js'; import { MultiExtensionsReloadError, UsageError, @@ -23,22 +21,15 @@ import { connectWithMaxRetries as defaultFirefoxConnector, findFreeTcpPort, } from '../firefox/remote.js'; -import {createLogger} from '../util/logger.js'; -import {isTTY, setRawMode} from '../util/stdin.js'; +import { createLogger } from '../util/logger.js'; +import { isTTY, setRawMode } from '../util/stdin.js'; import type { ExtensionRunnerParams, ExtensionRunnerReloadResult, } from './base'; -import type { - FirefoxPreferences, -} from '../firefox/preferences'; -import type { - FirefoxRDPResponseAddon, - RemoteFirefox, -} from '../firefox/remote'; -import type { - ExtensionBuildResult, -} from '../cmd/build'; +import type { FirefoxPreferences } from '../firefox/preferences'; +import type { FirefoxRDPResponseAddon, RemoteFirefox } from '../firefox/remote'; +import type { ExtensionBuildResult } from '../cmd/build'; const log = createLogger(import.meta.url); @@ -132,7 +123,9 @@ export class FirefoxAndroidExtensionRunner { } = this.params; this.adbUtils = new ADBUtils({ - adbBin, adbHost, adbPort, + adbBin, + adbHost, + adbPort, }); await this.adbDevicesDiscoveryAndSelect(); @@ -198,7 +191,7 @@ export class FirefoxAndroidExtensionRunner { const runnerName = this.getName(); const reloadErrors = new Map(); - for (const {sourceDir} of this.params.extensions) { + for (const { sourceDir } of this.params.extensions) { const [res] = await this.reloadExtensionBySourceDir(sourceDir); if (res.reloadError instanceof Error) { reloadErrors.set(sourceDir, res.reloadError); @@ -206,13 +199,15 @@ export class FirefoxAndroidExtensionRunner { } if (reloadErrors.size > 0) { - return [{ - runnerName, - reloadError: new MultiExtensionsReloadError(reloadErrors), - }]; + return [ + { + runnerName, + reloadError: new MultiExtensionsReloadError(reloadErrors), + }, + ]; } - return [{runnerName}]; + return [{ runnerName }]; } /** @@ -226,28 +221,32 @@ export class FirefoxAndroidExtensionRunner { const addonId = this.reloadableExtensions.get(extensionSourceDir); if (!addonId) { - return [{ - sourceDir: extensionSourceDir, - reloadError: new WebExtError( - 'Extension not reloadable: ' + - `no addonId has been mapped to "${extensionSourceDir}"` - ), - runnerName, - }]; + return [ + { + sourceDir: extensionSourceDir, + reloadError: new WebExtError( + 'Extension not reloadable: ' + + `no addonId has been mapped to "${extensionSourceDir}"` + ), + runnerName, + }, + ]; } try { await this.buildAndPushExtension(extensionSourceDir); await this.remoteFirefox.reloadAddon(addonId); } catch (error) { - return [{ - sourceDir: extensionSourceDir, - reloadError: error, - runnerName, - }]; + return [ + { + sourceDir: extensionSourceDir, + reloadError: error, + runnerName, + }, + ]; } - return [{runnerName, sourceDir: extensionSourceDir}]; + return [{ runnerName, sourceDir: extensionSourceDir }]; } /** @@ -263,11 +262,7 @@ export class FirefoxAndroidExtensionRunner { * Exits the runner, by closing the managed Firefox instance. */ async exit(): Promise { - const { - adbUtils, - selectedAdbDevice, - selectedArtifactsDir, - } = this; + const { adbUtils, selectedAdbDevice, selectedArtifactsDir } = this; this.exiting = true; @@ -299,16 +294,14 @@ export class FirefoxAndroidExtensionRunner { printIgnoredParamsWarnings() { Object.keys(ignoredParams).forEach((ignoredParam) => { if (this.params[ignoredParam]) { - log.warn( - getIgnoredParamsWarningsMessage(ignoredParams[ignoredParam]) - ); + log.warn(getIgnoredParamsWarningsMessage(ignoredParams[ignoredParam])); } }); } async adbDevicesDiscoveryAndSelect() { - const {adbUtils} = this; - const {adbDevice} = this.params; + const { adbUtils } = this; + const { adbDevice } = this.params; let devices = []; log.debug('Listing android devices'); @@ -317,7 +310,7 @@ export class FirefoxAndroidExtensionRunner { if (devices.length === 0) { throw new UsageError( 'No Android device found through ADB. ' + - 'Make sure the device is connected and USB debugging is enabled.' + 'Make sure the device is connected and USB debugging is enabled.' ); } @@ -325,7 +318,8 @@ export class FirefoxAndroidExtensionRunner { const devicesMsg = devices.map((dev) => ` - ${dev}`).join('\n'); log.info(`\nAndroid devices found:\n${devicesMsg}`); throw new UsageError( - 'Select an android device using --android-device='); + 'Select an android device using --android-device=' + ); } const foundDevices = devices.filter((device) => { @@ -335,7 +329,8 @@ export class FirefoxAndroidExtensionRunner { if (foundDevices.length === 0) { const devicesMsg = JSON.stringify(devices); throw new UsageError( - `Android device ${adbDevice} was not found in list: ${devicesMsg}`); + `Android device ${adbDevice} was not found in list: ${devicesMsg}` + ); } this.selectedAdbDevice = foundDevices[0]; @@ -346,9 +341,7 @@ export class FirefoxAndroidExtensionRunner { const { adbUtils, selectedAdbDevice, - params: { - firefoxApk, - }, + params: { firefoxApk }, } = this; // Discovery and select a Firefox for Android version. const packages = await adbUtils.discoverInstalledFirefoxAPKs( @@ -358,11 +351,12 @@ export class FirefoxAndroidExtensionRunner { if (packages.length === 0) { throw new UsageError( - 'No Firefox packages were found on the selected Android device'); + 'No Firefox packages were found on the selected Android device' + ); } const pkgsListMsg = (pkgs) => { - return pkgs.map((pkg) => ` - ${ pkg}`).join('\n'); + return pkgs.map((pkg) => ` - ${pkg}`).join('\n'); }; if (!firefoxApk) { @@ -393,22 +387,14 @@ export class FirefoxAndroidExtensionRunner { } async adbForceStopSelectedPackage() { - const { - adbUtils, - selectedAdbDevice, - selectedFirefoxApk, - } = this; + const { adbUtils, selectedAdbDevice, selectedFirefoxApk } = this; log.info(`Stopping existing instances of ${selectedFirefoxApk}...`); await adbUtils.amForceStopAPK(selectedAdbDevice, selectedFirefoxApk); } async adbCheckRuntimePermissions() { - const { - adbUtils, - selectedAdbDevice, - selectedFirefoxApk, - } = this; + const { adbUtils, selectedAdbDevice, selectedFirefoxApk } = this; log.debug(`Discovering Android version for ${selectedAdbDevice}...`); @@ -426,17 +412,19 @@ export class FirefoxAndroidExtensionRunner { return; } - log.debug('Checking read/write permissions needed for web-ext' + - `on ${selectedFirefoxApk}...`); + log.debug( + 'Checking read/write permissions needed for web-ext' + + `on ${selectedFirefoxApk}...` + ); // Runtime permissions needed to Firefox to be able to access the // xpi file uploaded to the android device or emulator. - const requiredPermissions = [ - 'android.permission.READ_EXTERNAL_STORAGE', - ]; + const requiredPermissions = ['android.permission.READ_EXTERNAL_STORAGE']; await adbUtils.ensureRequiredAPKRuntimePermissions( - selectedAdbDevice, selectedFirefoxApk, requiredPermissions + selectedAdbDevice, + selectedFirefoxApk, + requiredPermissions ); } @@ -445,11 +433,7 @@ export class FirefoxAndroidExtensionRunner { adbUtils, selectedAdbDevice, selectedFirefoxApk, - params: { - customPrefs, - firefoxApp, - adbRemoveOldArtifacts, - }, + params: { customPrefs, firefoxApp, adbRemoveOldArtifacts }, } = this; // Create the preferences file and the Fennec temporary profile. log.debug(`Preparing a temporary profile for ${selectedFirefoxApk}...`); @@ -462,17 +446,20 @@ export class FirefoxAndroidExtensionRunner { // Check if there are any artifacts dirs from previous runs and // automatically remove them if adbRemoteOldArtifacts is true. const foundOldArtifacts = await adbUtils.detectOrRemoveOldArtifacts( - selectedAdbDevice, adbRemoveOldArtifacts + selectedAdbDevice, + adbRemoveOldArtifacts ); if (foundOldArtifacts) { if (adbRemoveOldArtifacts) { - log.info('Old web-ext artifacts have been found and removed ' + - `from ${selectedAdbDevice} device`); + log.info( + 'Old web-ext artifacts have been found and removed ' + + `from ${selectedAdbDevice} device` + ); } else { log.warn( `Old artifacts directories have been found on ${selectedAdbDevice} ` + - 'device. Use --adb-remove-old-artifacts to remove them automatically.' + 'device. Use --adb-remove-old-artifacts to remove them automatically.' ); } } @@ -486,11 +473,15 @@ export class FirefoxAndroidExtensionRunner { const deviceProfileDir = this.getDeviceProfileDir(); await adbUtils.runShellCommand(selectedAdbDevice, [ - 'mkdir', '-p', deviceProfileDir, + 'mkdir', + '-p', + deviceProfileDir, ]); - await adbUtils.pushFile(selectedAdbDevice, - path.join(profile.profileDir, 'user.js'), - `${deviceProfileDir}/user.js`); + await adbUtils.pushFile( + selectedAdbDevice, + path.join(profile.profileDir, 'user.js'), + `${deviceProfileDir}/user.js` + ); log.debug(`Created temporary profile at ${deviceProfileDir}.`); } @@ -500,9 +491,7 @@ export class FirefoxAndroidExtensionRunner { adbUtils, selectedFirefoxApk, selectedAdbDevice, - params: { - firefoxApkComponent, - }, + params: { firefoxApkComponent }, } = this; const deviceProfileDir = this.getDeviceProfileDir(); @@ -528,7 +517,7 @@ export class FirefoxAndroidExtensionRunner { selectedAdbDevice, selectedFirefoxApk, firefoxApkComponent, - deviceProfileDir, + deviceProfileDir ); } finally { if (isTTY(stdin)) { @@ -542,13 +531,11 @@ export class FirefoxAndroidExtensionRunner { adbUtils, selectedAdbDevice, selectedArtifactsDir, - params: { - buildSourceDir, - }, + params: { buildSourceDir }, } = this; await withTempDir(async (tmpDir) => { - const {extensionPath} = await buildSourceDir(sourceDir, tmpDir.path()); + const { extensionPath } = await buildSourceDir(sourceDir, tmpDir.path()); const extFileName = path.basename(extensionPath, '.zip'); @@ -561,7 +548,9 @@ export class FirefoxAndroidExtensionRunner { log.debug(`Uploading ${extFileName} on the android device`); await adbUtils.pushFile( - selectedAdbDevice, extensionPath, adbExtensionPath + selectedAdbDevice, + extensionPath, + adbExtensionPath ); log.debug(`Upload completed: ${adbExtensionPath}`); @@ -571,7 +560,7 @@ export class FirefoxAndroidExtensionRunner { } async buildAndPushExtensions() { - for (const {sourceDir} of this.params.extensions) { + for (const { sourceDir } of this.params.extensions) { await this.buildAndPushExtension(sourceDir); } } @@ -581,20 +570,14 @@ export class FirefoxAndroidExtensionRunner { adbUtils, selectedAdbDevice, selectedFirefoxApk, - params: { - adbDiscoveryTimeout, - }, + params: { adbDiscoveryTimeout }, } = this; const stdin = this.params.stdin || process.stdin; - const { - unixSocketDiscoveryRetryInterval, - } = FirefoxAndroidExtensionRunner; + const { unixSocketDiscoveryRetryInterval } = FirefoxAndroidExtensionRunner; - let { - unixSocketDiscoveryMaxTime, - } = FirefoxAndroidExtensionRunner; + let { unixSocketDiscoveryMaxTime } = FirefoxAndroidExtensionRunner; if (typeof adbDiscoveryTimeout === 'number') { unixSocketDiscoveryMaxTime = adbDiscoveryTimeout; @@ -614,13 +597,13 @@ export class FirefoxAndroidExtensionRunner { try { // Got a debugger socket file to connect. - this.selectedRDPSocketFile = ( - await adbUtils.discoverRDPUnixSocket( - selectedAdbDevice, selectedFirefoxApk, { - maxDiscoveryTime: unixSocketDiscoveryMaxTime, - retryInterval: unixSocketDiscoveryRetryInterval, - } - ) + this.selectedRDPSocketFile = await adbUtils.discoverRDPUnixSocket( + selectedAdbDevice, + selectedFirefoxApk, + { + maxDiscoveryTime: unixSocketDiscoveryMaxTime, + retryInterval: unixSocketDiscoveryRetryInterval, + } ); } finally { if (isTTY(stdin)) { @@ -636,8 +619,8 @@ export class FirefoxAndroidExtensionRunner { // to connect the Firefox DevTools to the Firefox for Android instance). log.info(`You can connect to this Android device on TCP port ${tcpPort}`); - const forwardSocketSpec = this.selectedRDPSocketFile.startsWith('@') ? - `localabstract:${this.selectedRDPSocketFile.substr(1)}` + const forwardSocketSpec = this.selectedRDPSocketFile.startsWith('@') + ? `localabstract:${this.selectedRDPSocketFile.substr(1)}` : `localfilesystem:${this.selectedRDPSocketFile}`; await adbUtils.setupForward( @@ -652,15 +635,12 @@ export class FirefoxAndroidExtensionRunner { async rdpInstallExtensions() { const { selectedTCPPort, - params: { - extensions, - firefoxClient, - }, + params: { extensions, firefoxClient }, } = this; - const remoteFirefox = this.remoteFirefox = await firefoxClient({ + const remoteFirefox = (this.remoteFirefox = await firefoxClient({ port: selectedTCPPort, - }); + })); // Exit and cleanup the extension runner if the connection to the // remote Firefox for Android instance has been closed. @@ -673,10 +653,8 @@ export class FirefoxAndroidExtensionRunner { // Install all the temporary addons. for (const extension of extensions) { - const {sourceDir} = extension; - const adbExtensionPath = this.adbExtensionsPathBySourceDir.get( - sourceDir - ); + const { sourceDir } = extension; + const adbExtensionPath = this.adbExtensionsPathBySourceDir.get(sourceDir); if (!adbExtensionPath) { throw new WebExtError( @@ -684,17 +662,16 @@ export class FirefoxAndroidExtensionRunner { ); } - const addonId = await ( - remoteFirefox.installTemporaryAddon(adbExtensionPath) - .then((installResult: FirefoxRDPResponseAddon) => { - return installResult.addon.id; - }) - ); + const addonId = await remoteFirefox + .installTemporaryAddon(adbExtensionPath) + .then((installResult: FirefoxRDPResponseAddon) => { + return installResult.addon.id; + }); if (!addonId) { throw new WebExtError( 'Received an empty addonId from ' + - `remoteFirefox.installTemporaryAddon("${adbExtensionPath}")` + `remoteFirefox.installTemporaryAddon("${adbExtensionPath}")` ); } diff --git a/src/util/adb.js b/src/util/adb.js index 20b7f14efe..1ecffebbee 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -364,18 +364,18 @@ export default class ADBUtils { component, extras, }); - }).then(() => { - exception = null; - }).catch((err) => { - exception = err; - }); + }) + .then(() => { + exception = null; + }) + .catch((err) => { + exception = err; + }); // Wait for the activity to be started. while (exception === undefined) { if (this.userAbortStartActivity) { - throw new UsageError( - 'Exiting Firefox Start Activity on user request' - ); + throw new UsageError('Exiting Firefox Start Activity on user request'); } await new Promise((resolve) => setTimeout(resolve, 1000)); } diff --git a/tests/unit/test-extension-runners/test.firefox-android.js b/tests/unit/test-extension-runners/test.firefox-android.js index 62fd1fa0ab..7b7c81b7cf 100644 --- a/tests/unit/test-extension-runners/test.firefox-android.js +++ b/tests/unit/test-extension-runners/test.firefox-android.js @@ -990,22 +990,19 @@ describe('util/extension-runners/firefox-android', () => { consoleStream.stopCapturing(); }); }); - it('Stdin raw mode is set to false before setupForward', - async () => { - const { - params, fakeADBUtils, - } = prepareSelectedDeviceAndAPKParams(); + it('Stdin raw mode is set to false before setupForward', async () => { + const { params, fakeADBUtils } = prepareSelectedDeviceAndAPKParams(); - fakeADBUtils.setupForward = sinon.spy(async () => { - fakeStdin.emit('keypress', 'c', {name: 'c', ctrl: true}); - }); + fakeADBUtils.setupForward = sinon.spy(async () => { + fakeStdin.emit('keypress', 'c', { name: 'c', ctrl: true }); + }); - const fakeStdin = sinon.spy(createFakeStdin()); - params.stdin = fakeStdin; + const fakeStdin = sinon.spy(createFakeStdin()); + params.stdin = fakeStdin; - const runnerInstance = new FirefoxAndroidExtensionRunner(params); - await runnerInstance.run(); + const runnerInstance = new FirefoxAndroidExtensionRunner(params); + await runnerInstance.run(); - assert.deepEqual(fakeStdin.setRawMode.lastCall.args, [false]); - }); + assert.deepEqual(fakeStdin.setRawMode.lastCall.args, [false]); + }); }); diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index fdb97cb0fb..a538576526 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -1146,7 +1146,7 @@ describe('utils/adb', () => { readAll: sinon.spy(() => Promise.resolve(Buffer.from('\n'))), }, }); - const adbUtils = new ADBUtils({adb}); + const adbUtils = new ADBUtils({ adb }); adbUtils.setUserAbortStartActivity(true);