summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_open.html
blob: e792aa19afc6c0a6c0d2aa5ea48d4198f4b33608 (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
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test password field autocomplete footer with and without logins</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>

<div id="content"></div>

<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Login Manager: Test password field autocomplete footer with and without logins **/

add_task(async function test_no_autofill() {
  await setStoredLoginsAsync(
    [location.origin, "", null, "user-1", "pass-1", "uname", "pword"],
    [location.origin, "", null, "user-2", "pass-2", "uname", "pword"]
  );
  const form = createLoginForm();
  await promiseFormsProcessedInSameProcess();

  // Make sure initial form is empty as autofill shouldn't happen in the sandboxed frame.
  checkLoginForm(form.uname, "", form.pword, "");
  let popupState = await getPopupState();
  is(popupState.open, false, "Check popup is initially closed");
});

add_task(async function test_two_logins() {
  await setStoredLoginsAsync(
    [location.origin, "", null, "user-1", "pass-1", "uname", "pword"],
    [location.origin, "", null, "user-2", "pass-2", "uname", "pword"]
  );
  const form = createLoginForm();
  await promiseFormsProcessedInSameProcess();

  await popupBy(() => form.uname.focus());

  // popup on the password field should open upon focus
  let results = await popupBy(() => synthesizeKey("KEY_Tab"));

  let popupState = await getPopupState();
  is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");

  let expectedMenuItems = [
    "user-1",
    "user-2",
  ];
  checkAutoCompleteResults(results, expectedMenuItems, window.location.host, "Check all menuitems are displayed correctly.");

  checkLoginForm(form.uname, "", form.pword, "");
});

add_task(async function test_zero_logins() {
  // no logins stored
  await setStoredLoginsAsync();
  const form = createLoginForm();
  await promiseFormsProcessedInSameProcess();

  form.uname.focus();

  let shownPromise = popupBy().then(() => ok(false, "Should not have shown"));
  // Popup on the password field should NOT automatically open upon focus when there are no saved logins.
  synthesizeKey("KEY_Tab"); // focus the password field
  SimpleTest.requestFlakyTimeout("Giving a chance for the unexpected popup to show");
  let autocompleteItems = await Promise.race([
    shownPromise,
    new Promise(resolve => setTimeout(resolve, 2000)), // Wait 2s for the popup to appear
  ]);

  let popupState = await getPopupState();
  is(popupState.open, false, "Check popup is still closed");

  checkLoginForm(form.uname, "", form.pword, "");
  info("arrow down should still open the popup");
  autocompleteItems = await popupByArrowDown();
  checkAutoCompleteResults(autocompleteItems, [], window.location.host, "Check only footer is displayed.");
  checkLoginForm(form.uname, "", form.pword, "");
});
</script>
</pre>
</body>
</html>