summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_formActionOrigin.html
blob: 0365d5369c9e491e71f59b6e2eae9b781f3152c4 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test that logins with non-matching formActionOrigin appear in autocomplete dropdown</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">
Login Manager test: logins with non-matching formActionOrigin appear in autocomplete dropdown

<template id="form1-template">
  <form id="form1">
    <input type="text" name="uname">
    <input type="password" name="pword">
  </form>
</template>

<script class="testbody" type="text/javascript">
  const formTemplate = document.getElementById("form1-template");

  add_setup(async () => {
    await setStoredLoginsDuringTest(
      [window.location.origin, "https://differentFormSubmitURL", null, "dfsu1", "dfsp1", "uname", "pword"]
    );
    listenForUnexpectedPopupShown();
  });

  add_named_task("form initially empty", async () => {
    const form = setContentForTask(formTemplate);
    const autofillResult = await formAutofillResult(form.id);
    is(autofillResult, "no_saved_logins", "form has not been filled due to no saved logins");
    is(form.uname.value, "", "username is empty");
    is(form.pword.value, "", "password is empty");
    const popupState = await getPopupState();
    is(popupState.open, false, "Check popup is initially closed");
  });

  /* For this testcase, the only login that exists for this origin
   * is one with a different formActionOrigin, so the login will appear
   * in the autocomplete popup.
   */
  add_named_task("menu shows logins for different form action origin", async () => {
    const form = setContentForTask(formTemplate);
    const autofillResult = await formAutofillResult(form.id);
    is(autofillResult, "no_saved_logins", "form has not been filled due to no saved logins");

    // Trigger autocomplete popup
    form.uname.focus();

    const autocompleteItems = await popupByArrowDown();

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

    const expectedMenuItems = ["dfsu1"];
    checkAutoCompleteResults(autocompleteItems, expectedMenuItems, window.location.host, "Check all menuitems are displayed correctly.");

    synthesizeKey("KEY_ArrowDown"); // first item

    // value shouldn't update just by selecting
    is(form.uname.value, "", "username is empty");
    is(form.pword.value, "", "password is empty");

    synthesizeKey("KEY_Enter");
    await untilAutocompletePopupClosed();
    is(form.uname.value, "dfsu1", "username is set");
    is(form.pword.value, "dfsp1", "password is set");
  });
</script>
</pre>
</body>
</html>