From 7d20b04e9e2e7ac4b18a234614cb4be318fef789 Mon Sep 17 00:00:00 2001 From: Sonal Prabhu Date: Fri, 2 Oct 2020 15:15:53 +0530 Subject: [PATCH 01/10] Remote debugging message shown repeatedly --- src/extension-runners/firefox-android.js | 4 ++-- src/util/adb.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index aca3a10448..eec25c1b63 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -584,7 +584,7 @@ export class FirefoxAndroidExtensionRunner { try { const msg = ( `Waiting for ${selectedFirefoxApk} Remote Debugging Server...` + - '\nMake sure to enable "Remote Debugging via USB" ' + + '\n\nMake sure to enable "Remote Debugging via USB" ' + 'from Settings -> Developer Tools if it is not yet enabled.' ); @@ -593,7 +593,7 @@ export class FirefoxAndroidExtensionRunner { // Got a debugger socket file to connect. this.selectedRDPSocketFile = ( await adbUtils.discoverRDPUnixSocket( - selectedAdbDevice, selectedFirefoxApk, { + selectedAdbDevice, selectedFirefoxApk, msg, { maxDiscoveryTime: unixSocketDiscoveryMaxTime, retryInterval: unixSocketDiscoveryRetryInterval, } diff --git a/src/util/adb.js b/src/util/adb.js index 45a7c6efcf..f8be11668a 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -347,7 +347,7 @@ export default class ADBUtils { } async discoverRDPUnixSocket( - deviceId: string, apk: string, + deviceId: string, apk: string, msg: string, {maxDiscoveryTime, retryInterval}: DiscoveryParams = {} ): Promise { let rdpUnixSockets = []; @@ -355,6 +355,8 @@ export default class ADBUtils { const discoveryStartedAt = Date.now(); while (rdpUnixSockets.length === 0) { + log.info(`\n${msg}\n`); + if (this.userAbortDiscovery) { throw new UsageError( 'Exiting Firefox Remote Debugging socket discovery on user request' From 42a2098373d2c13237024d7960aa8cfbe0e65a29 Mon Sep 17 00:00:00 2001 From: Sonal Prabhu Date: Fri, 2 Oct 2020 15:41:58 +0530 Subject: [PATCH 02/10] Looped the error message with different color --- src/extension-runners/firefox-android.js | 2 +- src/util/adb.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index eec25c1b63..d08a2ca511 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -584,7 +584,7 @@ export class FirefoxAndroidExtensionRunner { try { const msg = ( `Waiting for ${selectedFirefoxApk} Remote Debugging Server...` + - '\n\nMake sure to enable "Remote Debugging via USB" ' + + '\nMake sure to enable "Remote Debugging via USB" ' + 'from Settings -> Developer Tools if it is not yet enabled.' ); diff --git a/src/util/adb.js b/src/util/adb.js index f8be11668a..806ed796d2 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -355,7 +355,7 @@ export default class ADBUtils { const discoveryStartedAt = Date.now(); while (rdpUnixSockets.length === 0) { - log.info(`\n${msg}\n`); + log.info(`\n\x1b[93m${msg}\x1b[39m\n`); if (this.userAbortDiscovery) { throw new UsageError( From 3b3dd589d78bf838b22f5d616627911e439bf8cc Mon Sep 17 00:00:00 2001 From: Sonal Prabhu Date: Fri, 2 Oct 2020 16:02:23 +0530 Subject: [PATCH 03/10] Removed trailing spaces --- src/util/adb.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/adb.js b/src/util/adb.js index 806ed796d2..dd3d5e8254 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -356,7 +356,6 @@ export default class ADBUtils { while (rdpUnixSockets.length === 0) { log.info(`\n\x1b[93m${msg}\x1b[39m\n`); - if (this.userAbortDiscovery) { throw new UsageError( 'Exiting Firefox Remote Debugging socket discovery on user request' From 702abc2ea22c1aaa436d2e4344de776e28a486a9 Mon Sep 17 00:00:00 2001 From: Sonal Prabhu Date: Fri, 2 Oct 2020 16:42:27 +0530 Subject: [PATCH 04/10] Corrected the errors --- src/extension-runners/firefox-android.js | 2 +- src/util/adb.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extension-runners/firefox-android.js b/src/extension-runners/firefox-android.js index d08a2ca511..aca3a10448 100644 --- a/src/extension-runners/firefox-android.js +++ b/src/extension-runners/firefox-android.js @@ -593,7 +593,7 @@ export class FirefoxAndroidExtensionRunner { // Got a debugger socket file to connect. this.selectedRDPSocketFile = ( await adbUtils.discoverRDPUnixSocket( - selectedAdbDevice, selectedFirefoxApk, msg, { + selectedAdbDevice, selectedFirefoxApk, { maxDiscoveryTime: unixSocketDiscoveryMaxTime, retryInterval: unixSocketDiscoveryRetryInterval, } diff --git a/src/util/adb.js b/src/util/adb.js index dd3d5e8254..4147fb2385 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -347,12 +347,17 @@ export default class ADBUtils { } async discoverRDPUnixSocket( - deviceId: string, apk: string, msg: string, + deviceId: string, apk: string, {maxDiscoveryTime, retryInterval}: DiscoveryParams = {} ): Promise { 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(`\n\x1b[93m${msg}\x1b[39m\n`); From 2ad9a9e4cbc1cea41bd2c09e11646edc2461b866 Mon Sep 17 00:00:00 2001 From: Sonal Prabhu Date: Fri, 2 Oct 2020 17:26:54 +0530 Subject: [PATCH 05/10] Removed yellow color from warning --- src/util/adb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/adb.js b/src/util/adb.js index 4147fb2385..0f481cf5e1 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -360,7 +360,7 @@ export default class ADBUtils { ); while (rdpUnixSockets.length === 0) { - log.info(`\n\x1b[93m${msg}\x1b[39m\n`); + log.info(`\n${msg}\n`); if (this.userAbortDiscovery) { throw new UsageError( 'Exiting Firefox Remote Debugging socket discovery on user request' From 5b785b029e27ddea5d433d9bf4135a30a28678d0 Mon Sep 17 00:00:00 2001 From: Sonal Prabhu Date: Thu, 8 Oct 2020 21:51:42 +0530 Subject: [PATCH 06/10] Added tests for enable Remote Debugging warning --- scripts/lib/flow.js | 2 +- tests/unit/test-util/test.adb.js | 42 +++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/scripts/lib/flow.js b/scripts/lib/flow.js index e7e31f136b..6a486efe05 100644 --- a/scripts/lib/flow.js +++ b/scripts/lib/flow.js @@ -4,7 +4,7 @@ exports.flowCheck = () => { if (process.env.TRAVIS_OS_NAME === 'windows') { console.log(`'flow check' task skipped because running on ${process.env.TRAVIS_OS_NAME}`); } else { - const res = spawnSync('flow', ['check'], {stdio: 'inherit'}); + const res = spawnSync('flow.cmd', ['check'], {stdio: 'inherit'}); if (res.error || res.status !== 0) { if (res.error) { console.error(res.error); diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index 39cc981581..36568f7cd7 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 @@ -1120,7 +1123,6 @@ describe('utils/adb', () => { await assert.isRejected( promise, 'Timeout while waiting for the Android Firefox Debugger Socket' ); - sinon.assert.called(adb.fakeADBClient.shell); sinon.assert.alwaysCalledWithMatch( adb.fakeADBClient.shell, @@ -1129,6 +1131,44 @@ describe('utils/adb', () => { ); }); + it('informs the user if remote debugging is not enabled', async () => { + const adb = getFakeADBKit({ + adbClient: { + shell: sinon.spy(() => Promise.resolve('')), + }, + adbkitUtil: { + readAll: sinon.spy(() => { + return Promise.resolve(Buffer.from('')); + }), + }, + }); + const adbUtils = new ADBUtils({adb}); + + const maxDiscoveryTime = 50; + const retryInterval = 10; + + consoleStream.stopCapturing(); + consoleStream.flushCapturedLogs(); + consoleStream.startCapturing(); + consoleStream.makeVerbose(); + + const promise = adbUtils.discoverRDPUnixSocket( + 'device1', 'org.mozilla.firefox_mybuild', { + maxDiscoveryTime, + retryInterval, + } + ); + const {capturedMessages} = consoleStream; + + assert.ok(capturedMessages.some( + (message) => ( + message.match('[debug]') && + message.match('Make sure to enable "Remote Debugging via USB') + ))); + await assert.isRejected(promise, WebExtError); + consoleStream.stopCapturing(); + }); + it('rejects a WebExtError if more than one RDP socket have been found', async () => { const adb = getFakeADBKit({ From dedb1260482668cd4921a4544580bbfc43fc9596 Mon Sep 17 00:00:00 2001 From: sonalprabhu <35455325+sonalprabhu@users.noreply.github.com> Date: Thu, 8 Oct 2020 22:15:47 +0530 Subject: [PATCH 07/10] Update flow.js --- scripts/lib/flow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lib/flow.js b/scripts/lib/flow.js index 6a486efe05..e7e31f136b 100644 --- a/scripts/lib/flow.js +++ b/scripts/lib/flow.js @@ -4,7 +4,7 @@ exports.flowCheck = () => { if (process.env.TRAVIS_OS_NAME === 'windows') { console.log(`'flow check' task skipped because running on ${process.env.TRAVIS_OS_NAME}`); } else { - const res = spawnSync('flow.cmd', ['check'], {stdio: 'inherit'}); + const res = spawnSync('flow', ['check'], {stdio: 'inherit'}); if (res.error || res.status !== 0) { if (res.error) { console.error(res.error); From 2e5c510ae0b4f369c29ab731bbb4a0e2d5ed4ac0 Mon Sep 17 00:00:00 2001 From: sonalprabhu <35455325+sonalprabhu@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:37:43 +0530 Subject: [PATCH 08/10] Update test.adb.js --- tests/unit/test-util/test.adb.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index 36568f7cd7..f4fccd2adc 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -1123,6 +1123,7 @@ describe('utils/adb', () => { await assert.isRejected( promise, 'Timeout while waiting for the Android Firefox Debugger Socket' ); + sinon.assert.called(adb.fakeADBClient.shell); sinon.assert.alwaysCalledWithMatch( adb.fakeADBClient.shell, From ae3653441c9a58e658f1887bb032ef043de9373a Mon Sep 17 00:00:00 2001 From: sonalprabhu <35455325+sonalprabhu@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:41:19 +0530 Subject: [PATCH 09/10] Update firefox-android.js --- src/extension-runners/firefox-android.js | 8 -------- 1 file changed, 8 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( From 2d5cc48859472effa36e91a90159a44b990b86a8 Mon Sep 17 00:00:00 2001 From: sonalprabhu <35455325+sonalprabhu@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:46:03 +0530 Subject: [PATCH 10/10] Update test.firefox-android.js --- .../test.firefox-android.js | 21 ------------------- 1 file changed, 21 deletions(-) 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(); - } - ); - }); });