Skip to content

Commit

Permalink
fix: Improve visibility of message to enable "Remote Debugging via US…
Browse files Browse the repository at this point in the history
…B" with web-ext run -t firefox-android (#2038)
  • Loading branch information
sonalprabhu authored Oct 9, 2020
1 parent 82c4250 commit 4ab3043
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
8 changes: 0 additions & 8 deletions src/extension-runners/firefox-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions src/util/adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 0 additions & 21 deletions tests/unit/test-extension-runners/test.firefox-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);

});

});
37 changes: 37 additions & 0 deletions tests/unit/test-util/test.adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 4ab3043

Please sign in to comment.