From 4ab30431ed717bea564d9e9a8abc4278d20b8121 Mon Sep 17 00:00:00 2001 From: sonalprabhu <35455325+sonalprabhu@users.noreply.github.com> Date: Fri, 9 Oct 2020 17:36:12 +0530 Subject: [PATCH] fix: Improve visibility of message to enable "Remote Debugging via USB" with web-ext run -t firefox-android (#2038) --- src/extension-runners/firefox-android.js | 8 ---- src/util/adb.js | 6 +++ .../test.firefox-android.js | 21 ----------- tests/unit/test-util/test.adb.js | 37 +++++++++++++++++++ 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index aca3a10448..d4e5170c6e 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -582,14 +582,6 @@ export class FirefoxAndroidExtensionRunner { } try { - const msg = ( - `Waiting for ${selectedFirefoxApk} Remote Debugging Server...` + - '\nMake sure to enable "Remote Debugging via USB" ' + - 'from Settings -> Developer Tools if it is not yet enabled.' - ); - - log.info(`\n${msg}\n`); - // Got a debugger socket file to connect. this.selectedRDPSocketFile = ( await adbUtils.discoverRDPUnixSocket( diff --git a/src/util/adb.js b/src/util/adb.js index 725c100685..c61c041acc 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -353,8 +353,14 @@ export default class ADBUtils { let rdpUnixSockets = []; const discoveryStartedAt = Date.now(); + const msg = ( + `Waiting for ${apk} Remote Debugging Server...` + + '\nMake sure to enable "Remote Debugging via USB" ' + + 'from Settings -> Developer Tools if it is not yet enabled.' + ); while (rdpUnixSockets.length === 0) { + log.info(msg); if (this.userAbortDiscovery) { throw new UsageError( 'Exiting Firefox Remote Debugging socket discovery on user request' diff --git a/tests/unit/test-extension-runners/test.firefox-android.js b/tests/unit/test-extension-runners/test.firefox-android.js index 58e0c55805..74512da4fb 100644 --- a/tests/unit/test-extension-runners/test.firefox-android.js +++ b/tests/unit/test-extension-runners/test.firefox-android.js @@ -1029,27 +1029,6 @@ describe('util/extension-runners/firefox-android', () => { consoleStream.stopCapturing(); }); - it( - 'does tell user to enable Remote Debugging when running Fenix', - async () => { - const {params, fakeADBUtils} = prepareSelectedDeviceAndAPKParams(); - params.firefoxApk = 'org.mozilla.fenix.nightly'; - fakeADBUtils.getAndroidVersionNumber = async () => 23; - - consoleStream.startCapturing(); - const runner = new FirefoxAndroidExtensionRunner(params); - await runner.run(); - - assert.match( - consoleStream.capturedMessages.join('\n'), - /Make sure to enable "Remote Debugging via USB"/ - ); - - consoleStream.flushCapturedLogs(); - consoleStream.stopCapturing(); - } - ); - }); }); diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index 39cc981581..939937ff38 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -14,6 +14,9 @@ import ADBUtils, { ARTIFACTS_DIR_PREFIX, DEVICE_DIR_BASE, } from '../../../src/util/adb'; +import { + consoleStream, // instance is imported to inspect logged messages +} from '../../../src/util/logger'; const fakeADBPackageList = ` package:org.mozilla.fennec @@ -1129,6 +1132,40 @@ describe('utils/adb', () => { ); }); + it('reminds the user to enable remote_debugging', async () => { + const adb = getFakeADBKit({ + adbClient: { + shell: sinon.spy(() => Promise.resolve('')), + }, + adbkitUtil: { + readAll: sinon.spy(() => { + return Promise.resolve(Buffer.from('')); + }), + }, + }); + const adbUtils = new ADBUtils({adb}); + + consoleStream.flushCapturedLogs(); + consoleStream.makeVerbose(); + consoleStream.startCapturing(); + + const promise = adbUtils.discoverRDPUnixSocket( + 'device1', 'org.mozilla.firefox_mybuild', { + maxDiscoveryTime: 50, retryInterval: 10, + } + ); + await assert.isRejected(promise, WebExtError); + + const {capturedMessages} = consoleStream; + const foundMessage = capturedMessages.find((message) => + message.includes('Make sure to enable "Remote Debugging via USB')); + + consoleStream.stopCapturing(); + + assert.ok(foundMessage); + assert.ok(foundMessage && foundMessage.includes('[info]')); + }); + it('rejects a WebExtError if more than one RDP socket have been found', async () => { const adb = getFakeADBKit({