Loading browser/components/shell/ShellService.sys.mjs +2 −2 Original line number Diff line number Diff line Loading @@ -304,7 +304,7 @@ let ShellServiceInternal = { arguments: exeArgs, }); telemetryResult = "ErrOther"; this._handleWDBAResult(exeProcess); await this._handleWDBAResult(exeProcess); telemetryResult = "Success"; } catch (ex) { if (ex instanceof WDBAError) { Loading Loading @@ -342,7 +342,7 @@ let ShellServiceInternal = { ], }); telemetryResult = "ErrOther"; this._handleWDBAResult(exeProcess); await this._handleWDBAResult(exeProcess); telemetryResult = "Success"; } catch (ex) { if (ex instanceof WDBAError) { Loading browser/components/shell/test/browser_setDefaultBrowser.js +56 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,24 @@ ChromeUtils.defineESModuleGetters(this, { sinon: "resource://testing-common/Sinon.sys.mjs", }); const _handleWDBAResultStub = sinon .stub(ShellService, "_handleWDBAResult") .callsFake(async () => { throw new Error("from _handleWDBAResultStub"); }); const _callExternalDefaultBrowserAgentStub = sinon .stub(ShellService, "_callExternalDefaultBrowserAgent") .callsFake(async () => ({ async wait() { return { exitCode: 0 }; }, })); const _userChoiceImpossibleTelemetryResultStub = sinon .stub(ShellService, "_userChoiceImpossibleTelemetryResult") .callsFake(() => null); const userChoiceStub = sinon .stub(ShellService, "setAsDefaultUserChoice") .resolves(); Loading @@ -15,7 +33,11 @@ const setDefaultStub = sinon.stub(); const shellStub = sinon .stub(ShellService, "shellService") .value({ setDefaultBrowser: setDefaultStub }); registerCleanupFunction(() => { _handleWDBAResultStub.restore(); _callExternalDefaultBrowserAgentStub.restore(); _userChoiceImpossibleTelemetryResultStub.restore(); userChoiceStub.restore(); shellStub.restore(); Loading Loading @@ -88,3 +110,37 @@ add_task(async function restore_default() { "Plain set default behavior restored to original" ); }); add_task(async function ensure_fallback() { if (AppConstants.platform != "win") { info("Nothing to test on non-Windows"); return; } let userChoicePromise = Promise.resolve(); userChoiceStub.callsFake(function (...args) { return (userChoicePromise = userChoiceStub.wrappedMethod.apply(this, args)); }); userChoiceStub.resetHistory(); setDefaultStub.resetHistory(); let doCleanup = await ExperimentFakes.enrollWithRollout({ featureId: NimbusFeatures.shellService.featureId, value: { setDefaultBrowserUserChoice: true, setDefaultPDFHandler: false, enabled: true, }, }); ShellService.setDefaultBrowser(); Assert.ok(userChoiceStub.called, "Set default with user choice called"); let thrown = false; await userChoicePromise.catch(() => (thrown = true)); Assert.ok(thrown, "Set default with user choice threw an error"); Assert.ok(setDefaultStub.called, "Fallbacked to plain set default"); await doCleanup(); }); Loading
browser/components/shell/ShellService.sys.mjs +2 −2 Original line number Diff line number Diff line Loading @@ -304,7 +304,7 @@ let ShellServiceInternal = { arguments: exeArgs, }); telemetryResult = "ErrOther"; this._handleWDBAResult(exeProcess); await this._handleWDBAResult(exeProcess); telemetryResult = "Success"; } catch (ex) { if (ex instanceof WDBAError) { Loading Loading @@ -342,7 +342,7 @@ let ShellServiceInternal = { ], }); telemetryResult = "ErrOther"; this._handleWDBAResult(exeProcess); await this._handleWDBAResult(exeProcess); telemetryResult = "Success"; } catch (ex) { if (ex instanceof WDBAError) { Loading
browser/components/shell/test/browser_setDefaultBrowser.js +56 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,24 @@ ChromeUtils.defineESModuleGetters(this, { sinon: "resource://testing-common/Sinon.sys.mjs", }); const _handleWDBAResultStub = sinon .stub(ShellService, "_handleWDBAResult") .callsFake(async () => { throw new Error("from _handleWDBAResultStub"); }); const _callExternalDefaultBrowserAgentStub = sinon .stub(ShellService, "_callExternalDefaultBrowserAgent") .callsFake(async () => ({ async wait() { return { exitCode: 0 }; }, })); const _userChoiceImpossibleTelemetryResultStub = sinon .stub(ShellService, "_userChoiceImpossibleTelemetryResult") .callsFake(() => null); const userChoiceStub = sinon .stub(ShellService, "setAsDefaultUserChoice") .resolves(); Loading @@ -15,7 +33,11 @@ const setDefaultStub = sinon.stub(); const shellStub = sinon .stub(ShellService, "shellService") .value({ setDefaultBrowser: setDefaultStub }); registerCleanupFunction(() => { _handleWDBAResultStub.restore(); _callExternalDefaultBrowserAgentStub.restore(); _userChoiceImpossibleTelemetryResultStub.restore(); userChoiceStub.restore(); shellStub.restore(); Loading Loading @@ -88,3 +110,37 @@ add_task(async function restore_default() { "Plain set default behavior restored to original" ); }); add_task(async function ensure_fallback() { if (AppConstants.platform != "win") { info("Nothing to test on non-Windows"); return; } let userChoicePromise = Promise.resolve(); userChoiceStub.callsFake(function (...args) { return (userChoicePromise = userChoiceStub.wrappedMethod.apply(this, args)); }); userChoiceStub.resetHistory(); setDefaultStub.resetHistory(); let doCleanup = await ExperimentFakes.enrollWithRollout({ featureId: NimbusFeatures.shellService.featureId, value: { setDefaultBrowserUserChoice: true, setDefaultPDFHandler: false, enabled: true, }, }); ShellService.setDefaultBrowser(); Assert.ok(userChoiceStub.called, "Set default with user choice called"); let thrown = false; await userChoicePromise.catch(() => (thrown = true)); Assert.ok(thrown, "Set default with user choice threw an error"); Assert.ok(setDefaultStub.called, "Fallbacked to plain set default"); await doCleanup(); });