summaryrefslogtreecommitdiffstats
path: root/browser/components/firefoxview/tests/browser/browser_sync_admin_disabled.js
blob: d2dc76974c037e2743e479ab7880596cd36399f3 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

var gSandbox;

add_setup(async function () {
  Services.prefs.lockPref("identity.fxaccounts.enabled");

  registerCleanupFunction(() => {
    gSandbox?.restore();
    Services.prefs.clearUserPref("services.sync.lastTabFetch");
    Services.prefs.unlockPref("identity.fxaccounts.enabled");
    Services.prefs.clearUserPref("identity.fxaccounts.enabled");
    // reset internal state so it doesn't affect the next tests
    TabsSetupFlowManager.resetInternalState();
  });

  // gSync.init() is called in a requestIdleCallback. Force its initialization.
  gSync.init();
});

add_task(async function test_sync_admin_disabled() {
  const sandbox = (gSandbox = sinon.createSandbox());
  sandbox.stub(UIState, "get").callsFake(() => {
    return {
      status: UIState.STATUS_NOT_CONFIGURED,
      syncEnabled: false,
    };
  });
  await withFirefoxView({}, async browser => {
    const { document } = browser.contentWindow;

    Services.obs.notifyObservers(null, UIState.ON_UPDATE);
    is(
      Services.prefs.getBoolPref("identity.fxaccounts.enabled"),
      true,
      "Expected identity.fxaccounts.enabled pref to be false"
    );

    is(
      Services.prefs.prefIsLocked("identity.fxaccounts.enabled"),
      true,
      "Expected identity.fxaccounts.enabled pref to be locked"
    );

    await waitForVisibleSetupStep(browser, {
      expectedVisible: "#tabpickup-steps-view0",
    });

    const errorStateHeader = document.querySelector(
      "#tabpickup-steps-view0-header"
    );

    await BrowserTestUtils.waitForMutationCondition(
      errorStateHeader,
      { childList: true },
      () => errorStateHeader.textContent.includes("disabled")
    );

    ok(
      errorStateHeader
        .getAttribute("data-l10n-id")
        .includes("fxa-admin-disabled"),
      "Correct message should show when fxa is disabled by an admin"
    );
  });
  Services.prefs.unlockPref("identity.fxaccounts.enabled");
});