summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html
blob: 8fcb9df6f6da0e9cfd25eec963de6c54e09991a4 (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
91
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test basic login, contextual inscure password warning without saved 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>
Login Manager test: contextual inscure password warning without saved logins

<script>
let chromeScript = runChecksAfterCommonInit();
</script>
<p id="display"></p>

<!-- we presumably can't hide the content for this test. -->
<div id="content">

  <form id="form1" action="http://autocomplete:8888/formtest.js" onsubmit="return false;">
    <input  type="text"       name="uname">
    <input  type="password"   name="pword">
    <button type="submit">Submit</button>
  </form>

</div>

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

/** Test for Login Manager: contextual insecure password warning without saved logins. **/

let uname = getFormElementByName(1, "uname");
let pword = getFormElementByName(1, "pword");

// Restore the form to the default state.
function restoreForm() {
  uname.value = "";
  pword.value = "";
  uname.focus();
}

function spinEventLoop() {
  return Promise.resolve();
}

add_setup(async () => {
  listenForUnexpectedPopupShown();
});

add_task(async function test_form1_initial_empty() {
  await SimpleTest.promiseFocus(window);

  // Make sure initial form is empty.
  checkLoginForm(uname, "", pword, "");
  let popupState = await getPopupState();
  is(popupState.open, false, "Check popup is initially closed");
});

add_task(async function test_form1_warning_entry() {
  await SimpleTest.promiseFocus(window);
  // Trigger autocomplete popup
  restoreForm();
  await popupBy();

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

  let acEvents = await getTelemetryEvents({ process: "parent", filterProps: TelemetryFilterPropsAC, clear: true });
  is(acEvents.length, 1, "One autocomplete event");
  checkACTelemetryEvent(acEvents[0], uname, {
    "hadPrevious": "0",
    "insecureWarning": "1",
    "loginsFooter": "1"
  });

  synthesizeKey("KEY_ArrowDown"); // select insecure warning
  checkLoginForm(uname, "", pword, ""); // value shouldn't update just by selecting
  synthesizeKey("KEY_Enter");
  await spinEventLoop(); // let focus happen
  checkLoginForm(uname, "", pword, "");
});

</script>
</pre>
</body>
</html>