summaryrefslogtreecommitdiffstats
path: root/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_pin_private_firefox.js
blob: 90880edd27e84777067840970199d1908973b8ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_PIN_PRIVATE_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 (Object.hasOwn(target, prop) ? target : ShellService)[prop];
    },
  });

  const test = () =>
    SMATestUtils.executeAndValidateAction(
      {
        type: "PIN_FIREFOX_TO_TASKBAR",
        data: {
          privatePin: true,
        },
      },
      {
        ownerGlobal: {
          getShellService: () => shell,
        },
      }
    );

  await test();

  function check(count, message, arg) {
    Assert.equal(
      shell.pinCurrentAppToTaskbarAsync.callCount,
      count,
      `pinCurrentAppToTaskbarAsync was ${message} by the action for windows`
    );
    if (arg) {
      Assert.equal(
        shell.pinCurrentAppToTaskbarAsync.calledWith(arg),
        true,
        `pinCurrentAppToTaskbarAsync was ${message} with the arg: ${JSON.stringify(
          arg
        )}`
      );
    }
  }
  check(1, "called", true);

  // 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", true);
});