1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 const { LoginTestUtils } = ChromeUtils.importESModule(
5 "resource://testing-common/LoginTestUtils.sys.mjs"
8 async function tearDown(sandbox) {
10 Services.prefs.clearUserPref("services.sync.lastTabFetch");
13 function setupMocks() {
14 const sandbox = (gSandbox = setupRecentDeviceListMocks());
18 add_setup(async function () {
19 registerCleanupFunction(async () => {
20 // reset internal state so it doesn't affect the next tests
21 TabsSetupFlowManager.resetInternalState();
22 LoginTestUtils.primaryPassword.disable();
23 await tearDown(gSandbox);
25 await SpecialPowers.pushPrefEnv({
26 set: [["services.sync.username", "username@example.com"]],
30 add_task(async function test_primary_password_locked() {
31 LoginTestUtils.primaryPassword.enable();
32 const sandbox = setupMocks();
34 await withFirefoxView({}, async browser => {
35 sandbox.stub(TabsSetupFlowManager, "syncTabs").resolves(null);
36 const syncedTabsMock = sandbox.stub(SyncedTabs, "getRecentTabs");
37 syncedTabsMock.resolves(getMockTabData(syncedTabsData1));
39 const { document } = browser.contentWindow;
40 Services.obs.notifyObservers(null, UIState.ON_UPDATE);
42 info("waiting for the error setup step to be visible");
43 await waitForVisibleSetupStep(browser, {
44 expectedVisible: "#tabpickup-steps-view0",
47 const errorStateHeader = document.querySelector(
48 "#tabpickup-steps-view0-header"
50 await BrowserTestUtils.waitForMutationCondition(
53 () => errorStateHeader.textContent.includes("Enter your Primary Password")
57 errorStateHeader.getAttribute("data-l10n-id").includes("password-locked"),
58 "Correct error message is shown"
61 const errorLink = document.querySelector("#error-state-link");
63 errorLink && BrowserTestUtils.is_visible(errorLink),
64 "Error link is visible"
67 errorLink.getAttribute("data-l10n-id").includes("password-locked-link"),
68 "Correct link text is shown"
71 const primaryButton = document.querySelector("#error-state-button");
73 primaryButton && BrowserTestUtils.is_visible(primaryButton),
74 "Error primary button is visible"
77 const clearErrorStub = sandbox.stub(
81 info("Setup state:" + TabsSetupFlowManager.currentSetupState.name);
83 info("clicking the error panel button");
84 primaryButton.click();
86 clearErrorStub.called,
87 "tryToClearError was called when the try-again button was clicked"
89 TabsSetupFlowManager.tryToClearError.restore();
91 info("Clearing the primary password");
92 LoginTestUtils.primaryPassword.disable();
94 !TabsSetupFlowManager.isPrimaryPasswordLocked,
95 "primary password is unlocked"
98 info("notifying of the primary-password unlock");
99 const clearErrorSpy = sandbox.spy(TabsSetupFlowManager, "tryToClearError");
100 // we stubbed out sync, so pretend it ran.
101 info("notifying of sync:finish");
102 Services.obs.notifyObservers(null, "weave:service:sync:finish");
104 const setupContainer = document.querySelector(".sync-setup-container");
105 // wait until the setup container gets hidden before checking if the tabs container is visible
106 // as it may not exist until then
107 let setupHiddenPromise = BrowserTestUtils.waitForMutationCondition(
110 attributeFilter: ["hidden"],
113 return BrowserTestUtils.is_hidden(setupContainer);
117 Services.obs.notifyObservers(null, "passwordmgr-crypto-login");
118 await setupHiddenPromise;
120 clearErrorSpy.called,
121 "tryToClearError was called when the primary-password unlock notification was received"
123 // We expect the waiting state until we get a sync update/finished
124 info("Setup state:" + TabsSetupFlowManager.currentSetupState.name);
126 ok(TabsSetupFlowManager.waitingForTabs, "Now waiting for tabs");
129 .querySelector("#tabpickup-tabs-container")
130 .classList.contains("loading"),
131 "Synced tabs container has loading class"
134 info("notifying of sync:finish");
135 Services.obs.notifyObservers(null, "weave:service:sync:finish");
136 await TestUtils.waitForTick();
139 .querySelector("#tabpickup-tabs-container")
140 .classList.contains("loading"),
141 "Synced tabs isn't loading any more"
144 await tearDown(sandbox);