summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_form_history_fallback.js
blob: 6a198e021a5f1aac561b54d6092eacb56ba34359 (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
const { FormHistoryTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/FormHistoryTestUtils.sys.mjs"
);

const usernameFieldName = "user";

async function cleanup() {
  Services.prefs.clearUserPref("signon.rememberSignons");
  Services.logins.removeAllLogins();
  await FormHistoryTestUtils.clear(usernameFieldName);
}

add_setup(async function () {
  await cleanup();
});

add_task(
  async function test_username_not_saved_in_form_history_when_password_manager_enabled() {
    Services.prefs.setBoolPref("signon.rememberSignons", true);

    const storageChangedPromise = TestUtils.topicObserved(
      "passwordmgr-storage-changed",
      (_, data) => data == "addLogin"
    );

    await testSubmittingLoginFormHTTP(
      "subtst_notifications_1.html",
      async () => {
        const notif = await getCaptureDoorhangerThatMayOpen("password-save");
        await clickDoorhangerButton(notif, REMEMBER_BUTTON);
      }
    );

    await storageChangedPromise;

    const loginEntries = (await Services.logins.getAllLogins()).length;
    const historyEntries = await FormHistoryTestUtils.count(usernameFieldName);

    Assert.equal(
      loginEntries,
      1,
      "Username should be saved in password manager"
    );

    Assert.equal(
      historyEntries,
      0,
      "Username should not be saved in form history"
    );
    await cleanup();
  }
);

add_task(
  async function test_username_saved_in_form_history_when_password_manager_disabled() {
    Services.prefs.setBoolPref("signon.rememberSignons", false);

    await testSubmittingLoginFormHTTP("subtst_notifications_1.html");

    const loginEntries = (await Services.logins.getAllLogins()).length;
    const historyEntries = await FormHistoryTestUtils.count(usernameFieldName);

    Assert.equal(
      loginEntries,
      0,
      "Username should not be saved in password manager"
    );

    Assert.equal(historyEntries, 1, "Username should be saved in form history");
    await cleanup();
  }
);