Skip to content

Commit c083c07

Browse files
authored
feat: Support for android build variants without requiring a fully qualified value in the --apk-component flag (#1941)
* feat: Support for android build variants without requiring a fully qualified value in the `--apk-component` flag * package-identifiers.js imported as packageIdentifiers, updated logic to support full and shortened apkComponents, added org.mozilla.fenix.nightly test * Modified browser prepend logic * Added “if apk is identical to the package” OR condition, and updated the respective test.adb case * Added 3 tests for adb.js
1 parent 05dd260 commit c083c07

File tree

3 files changed

+173
-8
lines changed

3 files changed

+173
-8
lines changed

src/firefox/package-identifiers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* @flow */
2+
3+
export default [
4+
'org.mozilla.fennec',
5+
'org.mozilla.fenix',
6+
'org.mozilla.geckoview_example',
7+
'org.mozilla.geckoview',
8+
'org.mozilla.firefox',
9+
'org.mozilla.reference.browser',
10+
];

src/util/adb.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
WebExtError,
88
} from '../errors';
99
import {createLogger} from '../util/logger';
10+
import packageIdentifiers from '../firefox/package-identifiers';
1011

1112
export const DEVICE_DIR_BASE = '/sdcard/';
1213
export const ARTIFACTS_DIR_PREFIX = 'web-ext-artifacts-';
@@ -119,13 +120,13 @@ export default class ADBUtils {
119120
return line === firefoxApk;
120121
}
121122
// Match any package name that starts with the package name of a Firefox for Android browser.
122-
return (
123-
line.startsWith('org.mozilla.fennec') ||
124-
line.startsWith('org.mozilla.fenix') ||
125-
line.startsWith('org.mozilla.geckoview') ||
126-
line.startsWith('org.mozilla.firefox') ||
127-
line.startsWith('org.mozilla.reference.browser')
128-
);
123+
for (const browser of packageIdentifiers) {
124+
if (line.startsWith(browser)) {
125+
return true;
126+
}
127+
}
128+
129+
return false;
129130
});
130131
}
131132

@@ -315,6 +316,18 @@ export default class ADBUtils {
315316
} else if (!apkComponent.includes('.')) {
316317
apkComponent = `.${apkComponent}`;
317318
}
319+
320+
// if `apk` is a browser package or the `apk` has a
321+
// browser package prefix: prepend the package identifier
322+
// before `apkComponent`
323+
if (apkComponent.startsWith('.')) {
324+
for (const browser of packageIdentifiers) {
325+
if (apk === browser || apk.startsWith(`${browser}.`)) {
326+
apkComponent = browser + apkComponent;
327+
}
328+
}
329+
}
330+
318331
// if `apkComponent` starts with a '.', then adb will expand
319332
// the following to: `${apk}/${apk}.${apkComponent}`
320333
const component = `${apk}/${apkComponent}`;

tests/unit/test-util/test.adb.js

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ describe('utils/adb', () => {
851851
sinon.assert.calledWithMatch(
852852
adb.fakeADBClient.startActivity, 'device1', {
853853
action: 'android.activity.MAIN',
854-
component: 'org.mozilla.geckoview_example/.GeckoViewActivity',
854+
component: 'org.mozilla.geckoview_example' +
855+
'/org.mozilla.geckoview_example.GeckoViewActivity',
855856
extras: [{
856857
key: 'args',
857858
value: '-profile /fake/custom/profile/path',
@@ -895,6 +896,147 @@ describe('utils/adb', () => {
895896
}
896897
);
897898
});
899+
900+
it('starts a given APK component on fenix.nightly', async () => {
901+
const adb = getFakeADBKit({
902+
adbClient: {
903+
startActivity: sinon.spy(() => Promise.resolve()),
904+
},
905+
adbkitUtil: {
906+
readAll: sinon.spy(() => Promise.resolve(Buffer.from('\n'))),
907+
},
908+
});
909+
const adbUtils = new ADBUtils({adb});
910+
911+
const promise = adbUtils.startFirefoxAPK(
912+
'device1',
913+
'org.mozilla.fenix.nightly',
914+
'HomeActivity', // firefoxApkComponent
915+
'/fake/custom/profile/path',
916+
);
917+
918+
await assert.isFulfilled(promise);
919+
920+
sinon.assert.calledOnce(adb.fakeADBClient.startActivity);
921+
sinon.assert.calledWithMatch(
922+
adb.fakeADBClient.startActivity, 'device1', {
923+
action: 'android.activity.MAIN',
924+
component: 'org.mozilla.fenix.nightly/' +
925+
'org.mozilla.fenix.HomeActivity',
926+
extras: [{
927+
key: 'args',
928+
value: '-profile /fake/custom/profile/path',
929+
}],
930+
wait: true,
931+
}
932+
);
933+
});
934+
935+
it('starts without specifying an APK component', async () => {
936+
const adb = getFakeADBKit({
937+
adbClient: {
938+
startActivity: sinon.spy(() => Promise.resolve()),
939+
},
940+
adbkitUtil: {
941+
readAll: sinon.spy(() => Promise.resolve(Buffer.from('\n'))),
942+
},
943+
});
944+
const adbUtils = new ADBUtils({adb});
945+
946+
const promise = adbUtils.startFirefoxAPK(
947+
'device1',
948+
'org.mozilla.geckoview_example',
949+
undefined, // firefoxApkComponent
950+
'/fake/custom/profile/path',
951+
);
952+
953+
await assert.isFulfilled(promise);
954+
955+
sinon.assert.calledOnce(adb.fakeADBClient.startActivity);
956+
sinon.assert.calledWithMatch(
957+
adb.fakeADBClient.startActivity, 'device1', {
958+
action: 'android.activity.MAIN',
959+
component: 'org.mozilla.geckoview_example/' +
960+
'org.mozilla.geckoview_example.App',
961+
extras: [{
962+
key: 'args',
963+
value: '-profile /fake/custom/profile/path',
964+
}],
965+
wait: true,
966+
}
967+
);
968+
});
969+
970+
it('starts a fully-qualified APK component on the build-variant: ' +
971+
'fenix.nightly', async () => {
972+
const adb = getFakeADBKit({
973+
adbClient: {
974+
startActivity: sinon.spy(() => Promise.resolve()),
975+
},
976+
adbkitUtil: {
977+
readAll: sinon.spy(() => Promise.resolve(Buffer.from('\n'))),
978+
},
979+
});
980+
const adbUtils = new ADBUtils({adb});
981+
982+
const promise = adbUtils.startFirefoxAPK(
983+
'device1',
984+
'org.mozilla.fenix.nightly',
985+
'org.mozilla.fenix.HomeActivity', // firefoxApkComponent
986+
'/fake/custom/profile/path',
987+
);
988+
989+
await assert.isFulfilled(promise);
990+
991+
sinon.assert.calledOnce(adb.fakeADBClient.startActivity);
992+
sinon.assert.calledWithMatch(
993+
adb.fakeADBClient.startActivity, 'device1', {
994+
action: 'android.activity.MAIN',
995+
component: 'org.mozilla.fenix.nightly/' +
996+
'org.mozilla.fenix.HomeActivity',
997+
extras: [{
998+
key: 'args',
999+
value: '-profile /fake/custom/profile/path',
1000+
}],
1001+
wait: true,
1002+
}
1003+
);
1004+
});
1005+
1006+
it('starts a given APK component that begins with a period', async () => {
1007+
const adb = getFakeADBKit({
1008+
adbClient: {
1009+
startActivity: sinon.spy(() => Promise.resolve()),
1010+
},
1011+
adbkitUtil: {
1012+
readAll: sinon.spy(() => Promise.resolve(Buffer.from('\n'))),
1013+
},
1014+
});
1015+
const adbUtils = new ADBUtils({adb});
1016+
1017+
const promise = adbUtils.startFirefoxAPK(
1018+
'device1',
1019+
'org.mozilla.fenix.nightly',
1020+
'.HomeActivity', // firefoxApkComponent
1021+
'/fake/custom/profile/path',
1022+
);
1023+
1024+
await assert.isFulfilled(promise);
1025+
1026+
sinon.assert.calledOnce(adb.fakeADBClient.startActivity);
1027+
sinon.assert.calledWithMatch(
1028+
adb.fakeADBClient.startActivity, 'device1', {
1029+
action: 'android.activity.MAIN',
1030+
component: 'org.mozilla.fenix.nightly/' +
1031+
'org.mozilla.fenix.HomeActivity',
1032+
extras: [{
1033+
key: 'args',
1034+
value: '-profile /fake/custom/profile/path',
1035+
}],
1036+
wait: true,
1037+
}
1038+
);
1039+
});
8981040
});
8991041

9001042
describe('discoverRDPUnixSocket', () => {

0 commit comments

Comments
 (0)