summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_subdomain.html
blob: 685c2044c855aa84382873361fd3f2bf6dda3b0f (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test that logins with non-exact match origin appear in autocomplete dropdown</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" 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: logins with non-exact match origin appear in autocomplete dropdown
<p id="display"></p>

<!-- we presumably can't hide the content for this test. -->
<div id="content"></div>
<pre id="test">
<script class="testbody" type="text/javascript">
const setupScript = runInParent(function setup() {
  addMessageListener("getDateString", () => {
    const dateAndTimeFormatter = new Services.intl.DateTimeFormat(undefined, { dateStyle: "medium" });
    return dateAndTimeFormatter.format(new Date());
  });
});

add_setup(async () => {
  const origin = window.location.origin;
  const lastDot = origin.lastIndexOf(".");
  const suffix = origin.slice(lastDot);

  const baseHost = "http://example" + suffix;
  const baseSecureHost = "https://example" + suffix;
  const oldHost = "http://old.example" + suffix;
  const oldSecureHost = "https://old.example" + suffix;
  const newHost = "https://new.example" + suffix;

  await addLoginsInParent(
    // The first two logins should never be visible on https: versions of
    // *.example.com since the login is for http: and an https: login exists for this username.
    [oldHost, oldSecureHost, null, "dsdu1", "dsdp1new", "uname", "pword"],
    [baseHost, baseSecureHost, null, "dsdu1", "dsdp1", "uname", "pword"],
    [oldSecureHost, oldSecureHost, null, "dsdu1", "dsdp1", "uname", "pword"],
    [baseSecureHost, baseSecureHost, null, "dsdu1", "dsdp1", "uname", "pword"],
    [newHost, newHost, null, "dsdu1", "dsdp1prime", "uname", "pword"]
  );

  await SpecialPowers.pushPrefEnv({
    set: [
      ["signon.includeOtherSubdomainsInLookup", true],
    ],
  });
  listenForUnexpectedPopupShown();
});

add_task(async function test_form1_initial_empty() {
  const form = createLoginForm({
    action: "https://otherexample.com/formtest.js"
  });

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

/* For this testcase, there exists two logins for this origin
 * on different subdomains but with different passwords. Both logins
 * should appear in the autocomplete popup.
 */
add_task(async function test_form1_menu_shows_two_logins_same_usernames_for_different_subdomain() {
  const form = createLoginForm({
    action: "https://otherexample.com/formtest.js"
  });

  // 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");

  // The logins are added "today" and since they are duplicates, the date that they were last
  // changed will be appended.
  const dateString = await setupScript.sendQuery("getDateString");
  const username = `dsdu1 (${dateString})`;

  checkAutoCompleteResults(autocompleteItems, [username, username], window.location.host, "Check all menuitems are displayed correctly.");

  synthesizeKey("KEY_ArrowDown"); // first item
  checkLoginForm(form.uname, "", form.pword, ""); // value shouldn't update just by selecting

  synthesizeKey("KEY_Enter");
  await promiseFormsProcessedInSameProcess();
  is(form.pword.value, "dsdp1", "password should match the login that was selected");
  checkLoginForm(form.uname, "dsdu1", form.pword, "dsdp1");

  form.uname.value = "";
  form.pword.value = "";
  form.uname.focus();

  await popupByArrowDown();

  synthesizeKey("KEY_ArrowDown"); // first item
  synthesizeKey("KEY_ArrowDown"); // second item
  checkLoginForm(form.uname, "", form.pword, ""); // value shouldn't update just by selecting

  synthesizeKey("KEY_Enter");
  await promiseFormsProcessedInSameProcess();
  is(form.pword.value, "dsdp1prime", "Password should match the login that was selected");
  checkLoginForm(form.uname, "dsdu1", form.pword, "dsdp1prime");
});
</script>
</pre>
</body>
</html>