-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allowed detection of given firefox APK #1338
Conversation
@rpl, could you please review this, and let me know if there's any questions or need any changes? |
src/util/adb.js
Outdated
line.startsWith('org.mozilla.fennec') || | ||
line.startsWith('org.mozilla.firefox') | ||
firefoxApk ? | ||
line.startsWith(firefoxApk) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use line === firefoxApk
instead of line.startsWith(firefoxApk)
.
In practice there is no difference because the list is filtered again in the end, but let's be more explicit that this an exact match is intended:
web-ext/src/extension-runners/firefox-android.js
Lines 340 to 367 in f9db35b
const packages = await adbUtils.discoverInstalledFirefoxAPKs( | |
selectedAdbDevice | |
); | |
if (packages.length === 0) { | |
throw new UsageError( | |
'No Firefox packages were found on the selected Android device'); | |
} | |
const pkgsListMsg = (pkgs) => { | |
return pkgs.map((pkg) => ` - ${ pkg}`).join('\n'); | |
}; | |
if (!firefoxApk) { | |
log.info(`\nPackages found:\n${pkgsListMsg(packages)}`); | |
if (packages.length > 1) { | |
throw new UsageError('Select one of the packages using --firefox-apk'); | |
} | |
// If only one APK has been found, select it even if it has not been | |
// specified explicitly on the comment line. | |
this.selectedFirefoxApk = packages[0]; | |
log.info(`Selected Firefox for Android APK: ${this.selectedFirefoxApk}`); | |
return; | |
} | |
const filteredPackages = packages.filter((line) => line === firefoxApk); |
tests/unit/test-util/test.adb.js
Outdated
}, | ||
adbkitUtil: { | ||
readAll: sinon.spy(() => { | ||
return Promise.resolve(new Buffer(fakeADBPackageList)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Buffer
constructor is deprecated. Please use Buffer.from(fakeADBPackageList)
instead.
tests/unit/test-util/test.adb.js
Outdated
}, | ||
adbkitUtil: { | ||
readAll: sinon.spy(() => { | ||
return Promise.resolve(new Buffer(fakeADBPackageList)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, use the Buffer.from
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @khaled-cliqz
Thanks, this looks like a reasonable change.
Follows some additional review comments (they are just some small tweaks that I would like to see applied before approving this PR for landing).
src/util/adb.js
Outdated
@@ -111,8 +112,12 @@ export default class ADBUtils { | |||
.map((line) => line.replace('package:', '').trim()) | |||
.filter((line) => { | |||
return ( | |||
line.startsWith('org.mozilla.fennec') || | |||
line.startsWith('org.mozilla.firefox') | |||
firefoxApk ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, do you mind to split this two conditions? just to enhance its readability a bit, something like:
// Look for an exact match if firefoxApk is defined.
if (firefoxApk) {
return line === firefoxApk;
}
// Match any package name that starts with the package name of a Firefox for Android browser.
return (line.startsWith('org.mozilla.fennec') || ...);
tests/unit/test-util/test.adb.js
Outdated
@@ -236,6 +238,52 @@ describe('utils/adb', () => { | |||
sinon.assert.calledOnce(adb.util.readAll); | |||
assert.deepEqual(packages, ['org.mozilla.fennec', 'org.mozilla.firefox']); | |||
}); | |||
|
|||
it('resolves only the given firefox APK', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that these two new test cases are both testing same "exact match" scenario, it doesn't seem that we actually need both (at least if I'm not missing something that makes these two tests actually different).
If we feel that we need to test explicitly this scenario on both "org.mozilla.fennec" and "com.some.firefox.fork", we could at least extract one of these test functions into an helper function which takes the package name as a parameter and then we can call it for both these package names in the same test case.
@khaled-cliqz how that sounds to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds correct, I'll just remove this one.
7c7c189
to
f796146
Compare
This commit is to allow extension development on custom forks of firefox for android, not just on firefox and fennec
@rpl, could you help me with figuring out why this PR is failing? |
@khaled-cliqz The failing test ( |
@khaled-cliqz yeah, that is an unrelated intermittent, I'm going to take another look on this PR asap (and don't worry about that failure, I'm already fighting against it separately from this review). |
Thank you, @khaled-cliqz! Your contribution has been added to our recognition wiki. Would you be interested in creating an account on mozillians.org? I'd be happy to vouch for you! |
Thanks, @caitmuenster! |
Yay! Your profile is vouched. Thanks again for the patch, @khaled-cliqz! Hope to see you around the project. :) |
This commit is to allow extension development on custom forks of
firefox for android, not just on firefox and fennec