Skip to content

Commit 2e03e74

Browse files
committedJul 24, 2020
chore: Tweaks to better match Firefox behavior and small fixes for recent flow typecheck errors
1 parent e666180 commit 2e03e74

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed
 

‎.flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[options]
66
module.system=node
7+
esproposal.optional_chaining=enable
78
log.file=./artifacts/flow.log
89

910
[ignore]

‎src/util/manifest.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ export function getManifestId(manifestData: ExtensionManifest): string | void {
9191
manifestData.applications,
9292
];
9393
for (const apps of manifestApps) {
94-
if (apps && apps.gecko && apps.gecko.id) {
94+
// If both bss and applicants contains a defined gecko property,
95+
// we prefer bss even if the id property isn't available.
96+
// This match what Firefox does in this particular scenario, see
97+
// https://searchfox.org/mozilla-central/rev/828f2319c0195d7f561ed35533aef6fe183e68e3/toolkit/mozapps/extensions/internal/XPIInstall.jsm#470-474,488
98+
if (apps?.gecko) {
9599
return apps.gecko.id;
96100
}
97101
}

‎tests/unit/test-cmd/test.sign.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ describe('sign', () => {
279279
apiSecret: stubs.signingConfig.apiSecret,
280280
apiUrlPrefix: stubs.signingConfig.apiUrlPrefix,
281281
downloadDir: artifactsDir,
282-
id: applications.gecko && applications.gecko.id,
282+
id: applications.gecko?.id,
283283
timeout: stubs.signingConfig.timeout,
284284
version: stubs.preValidatedManifest.version,
285285
xpiPath: stubs.buildResult.extensionPath,

‎tests/unit/test-extension-runners/test.firefox-desktop.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ describe('util/extension-runners/firefox-desktop', () => {
284284

285285
assert.equal(install.asProxy, true);
286286
assert.equal(install.manifestData.applications.gecko.id,
287-
manifestData.applications &&
288-
manifestData.applications.gecko &&
289-
manifestData.applications.gecko.id);
287+
manifestData.applications?.gecko?.id);
290288
assert.deepEqual(install.profile, fakeProfile);
291289
// This needs to be the source of the extension.
292290
assert.equal(install.extensionPath, sourceDir);

‎tests/unit/test-util/test.manifest.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe('util/manifest', () => {
213213
describe('getManifestId', () => {
214214
const id = 'basic-manifest@web-ext-test-suite';
215215

216-
['applications', 'browser_specific_settings'].forEach((key) => {
216+
['applications', 'browser_specific_settings'].forEach((key: string) => {
217217

218218
describe(`with ${key}`, () => {
219219

@@ -238,6 +238,35 @@ describe('util/manifest', () => {
238238

239239
});
240240

241+
describe('with both applications and browser_specific_settings', () => {
242+
const bssId = 'id@from-bss-prop';
243+
const appId = 'id@from-app-prop';
244+
245+
it('does prefer bss if it includes a gecko object', () => {
246+
assert.equal(getManifestId({
247+
...manifestWithoutApps,
248+
browser_specific_settings: {gecko: {id: bssId}},
249+
applications: {gecko: {id: appId}},
250+
}), bssId);
251+
252+
// This test that we are matching what Firefox does in this scenario.
253+
assert.equal(getManifestId({
254+
...manifestWithoutApps,
255+
browser_specific_settings: {gecko: {}},
256+
applications: {gecko: {id: appId}},
257+
}), undefined);
258+
});
259+
260+
it('does fallback to applications if bss.gecko is undefined', () => {
261+
assert.equal(getManifestId({
262+
...manifestWithoutApps,
263+
browser_specific_settings: {},
264+
applications: {gecko: {id: appId}},
265+
}), appId);
266+
});
267+
268+
});
269+
241270
describe('without applications and browser_specific_settings', () => {
242271

243272
it('returns undefined when ID is not specified', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.