From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../shell/test/browser_setDefaultBrowser.js | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 browser/components/shell/test/browser_setDefaultBrowser.js (limited to 'browser/components/shell/test/browser_setDefaultBrowser.js') diff --git a/browser/components/shell/test/browser_setDefaultBrowser.js b/browser/components/shell/test/browser_setDefaultBrowser.js new file mode 100644 index 0000000000..8a8b4d5913 --- /dev/null +++ b/browser/components/shell/test/browser_setDefaultBrowser.js @@ -0,0 +1,90 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +XPCOMUtils.defineLazyModuleGetters(this, { + ExperimentAPI: "resource://nimbus/ExperimentAPI.jsm", + ExperimentFakes: "resource://testing-common/NimbusTestUtils.jsm", + NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm", + sinon: "resource://testing-common/Sinon.jsm", +}); + +const userChoiceStub = sinon + .stub(ShellService, "setAsDefaultUserChoice") + .resolves(); +const setDefaultStub = sinon.stub(); +const shellStub = sinon + .stub(ShellService, "shellService") + .value({ setDefaultBrowser: setDefaultStub }); +registerCleanupFunction(() => { + userChoiceStub.restore(); + shellStub.restore(); + + ExperimentAPI._store._deleteForTests("shellService"); +}); + +let defaultUserChoice; +add_task(async function need_user_choice() { + ShellService.setDefaultBrowser(); + defaultUserChoice = userChoiceStub.called; + + Assert.ok( + defaultUserChoice !== undefined, + "Decided which default browser method to use" + ); + Assert.equal( + setDefaultStub.notCalled, + defaultUserChoice, + "Only one default behavior was used" + ); +}); + +add_task(async function remote_disable() { + if (defaultUserChoice === false) { + info("Default behavior already not user choice, so nothing to test"); + return; + } + + userChoiceStub.resetHistory(); + setDefaultStub.resetHistory(); + let doCleanup = await ExperimentFakes.enrollWithRollout({ + featureId: NimbusFeatures.shellService.featureId, + value: { + setDefaultBrowserUserChoice: false, + enabled: true, + }, + }); + + ShellService.setDefaultBrowser(); + + Assert.ok( + userChoiceStub.notCalled, + "Set default with user choice disabled via nimbus" + ); + Assert.ok(setDefaultStub.called, "Used plain set default insteead"); + + await doCleanup(); +}); + +add_task(async function restore_default() { + if (defaultUserChoice === undefined) { + info("No default user choice behavior set, so nothing to test"); + return; + } + + userChoiceStub.resetHistory(); + setDefaultStub.resetHistory(); + ExperimentAPI._store._deleteForTests("shellService"); + + ShellService.setDefaultBrowser(); + + Assert.equal( + userChoiceStub.called, + defaultUserChoice, + "Set default with user choice restored to original" + ); + Assert.equal( + setDefaultStub.notCalled, + defaultUserChoice, + "Plain set default behavior restored to original" + ); +}); -- cgit v1.2.3