diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_firefox.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_firefox.js')
-rw-r--r-- | toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_firefox.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_firefox.js b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_firefox.js new file mode 100644 index 0000000000..09714e6703 --- /dev/null +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_firefox.js @@ -0,0 +1,72 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const isWin = AppConstants.platform == "win"; +const isMac = AppConstants.platform == "macosx"; + +add_task(async function test_PIN_FIREFOX_TO_TASKBAR() { + const sandbox = sinon.createSandbox(); + let shell = { + async checkPinCurrentAppToTaskbarAsync() {}, + QueryInterface: () => shell, + get macDockSupport() { + return this; + }, + get shellService() { + return this; + }, + + ensureAppIsPinnedToDock: sandbox.stub(), + isCurrentAppPinnedToTaskbarAsync: sandbox.stub(), + pinCurrentAppToTaskbarAsync: sandbox.stub().resolves(undefined), + isAppInDock: false, + }; + + // Prefer the mocked implementation and fall back to the original version, + // which can call back into the mocked version (via this.shellService). + shell = new Proxy(shell, { + get(target, prop) { + return (prop in target ? target : ShellService)[prop]; + }, + }); + + const test = () => + SMATestUtils.executeAndValidateAction( + { type: "PIN_FIREFOX_TO_TASKBAR" }, + { + ownerGlobal: { + getShellService: () => shell, + }, + } + ); + + await test(); + + function check(count, message) { + Assert.equal( + shell.pinCurrentAppToTaskbarAsync.callCount, + count * isWin, + `pinCurrentAppToTaskbarAsync was ${message} by the action for windows` + ); + Assert.equal( + shell.ensureAppIsPinnedToDock.callCount, + count * isMac, + `ensureAppIsPinnedToDock was ${message} by the action for not windows` + ); + } + check(1, "called"); + + // Pretend the app is already pinned. + shell.isCurrentAppPinnedToTaskbarAsync.resolves(true); + shell.isAppInDock = true; + await test(); + check(1, "not called"); + + // Pretend the app became unpinned. + shell.isCurrentAppPinnedToTaskbarAsync.resolves(false); + shell.isAppInDock = false; + await test(); + check(2, "called again"); +}); |