summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_basic_form_honor_autocomplete_off.html
blob: 42214485c8149cf2199de301b94d3826ec93d944 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test login autofill autocomplete when signon.autofillForms.autocompleteOff is false</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: autofilling when autocomplete=off
<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">
/** Test for Login Manager: multiple login autocomplete. **/

// Check for expected username/password in form.
function checkFormValues(form, expectedUsername, expectedPassword) {
  let uname = form.querySelector("[name='uname']");
  let pword = form.querySelector("[name='pword']");
  is(uname.value, expectedUsername, `Checking ${form.id} username is: ${expectedUsername}`);
  is(pword.value, expectedPassword, `Checking ${form.id} password is: ${expectedPassword}`);
}

async function autoCompleteFieldsFromFirstMatch(form) {
  // trigger autocomplete from the username field
  await SimpleTest.promiseFocus(form.ownerGlobal);
  let uname = form.querySelector("[name='uname']");
  await popupBy(() => uname.focus());

  let formFilled = promiseFormsProcessedInSameProcess();
  await synthesizeKey("KEY_ArrowDown"); // open
  await synthesizeKey("KEY_Enter");
  await formFilled;
  await Promise.resolve();
}

add_setup(async () => {
  // Set the pref before the document loads.
  SpecialPowers.setBoolPref("signon.autofillForms.autocompleteOff", false);
  SimpleTest.registerCleanupFunction(() => {
    SpecialPowers.clearUserPref("signon.autofillForms.autocompleteOff");
  });

  await setStoredLoginsAsync(
    [window.location.origin, "https://autocomplete", null, "singleuser", "singlepass", "uname", "pword"]
  );
  listenForUnexpectedPopupShown();
});

/* Tests for autofill of single-user forms for when we honor autocomplete=off on password fields */
add_task(async function honor_password_autocomplete_off() {
  const form = createLoginForm({
    action: "https://autocomplete",
    password: {
      autocomplete: "off"
    }
  });
  await promiseFormsProcessedInSameProcess();
  await SimpleTest.promiseFocus(window);
  // With the pref toggled off, and with autocomplete=off on the password field,
  // we expect not to have autofilled this form
  checkFormValues(form, "", "");
  // ..but it should autocomplete just fine
  await autoCompleteFieldsFromFirstMatch(form);
  checkFormValues(form, "singleuser", "singlepass");
});

add_task(async function honor_username_autocomplete_off() {
  const form = createLoginForm({
    action: "https://autocomplete",
    username: {
      autocomplete: "off"
    }
  });
  await promiseFormsProcessedInSameProcess();
  await SimpleTest.promiseFocus(window);
  // With the pref toggled off, and with autocomplete=off on the username field,
  // we expect to have autofilled this form
  checkFormValues(form, "singleuser", "singlepass");
});

add_task(async function honor_form_autocomplete_off() {
  const form = createLoginForm({
    action: "https://autocomplete",
    autocomplete: "off"
  });
  await promiseFormsProcessedInSameProcess();
  await SimpleTest.promiseFocus(window);
  // With the pref toggled off, and with autocomplete=off on the form,
  // we expect to have autofilled this form
  checkFormValues(form, "singleuser", "singlepass");
});

add_task(async function honor_username_and_password_autocomplete_off() {
  const form = createLoginForm({
    action: "https://autocomplete",
    username: {
      autocomplete: "off"
    },
    password: {
      autocomplete: "off"
    }
  });
  await promiseFormsProcessedInSameProcess();
  await SimpleTest.promiseFocus(window);
  // With the pref toggled off, and autocomplete=off on the username and password field,
  // we expect not to have autofilled this form
  checkFormValues(form, "", "");
  // ..but it should autocomplete just fine
  await autoCompleteFieldsFromFirstMatch(form);
  checkFormValues(form, "singleuser", "singlepass");
});

add_task(async function reference_form() {
  const form = createLoginForm({
    action: "https://autocomplete"
  });
  await promiseFormsProcessedInSameProcess();
  await SimpleTest.promiseFocus(window);
  // (this is a control, w/o autocomplete=off, to ensure the login
  // that was being suppressed would have been filled in otherwise)
  checkFormValues(form, "singleuser", "singlepass");
});

add_task(async function honor_username_autocomplete_off_without_password() {
  const form = createLoginForm({
    action: "https://autocomplete",
    username: {
      id: "username",
      autocomplete: "off"
    },
    password: false
  });
  await promiseFormsProcessedInSameProcess();
  await SimpleTest.promiseFocus(window);
  // With the pref toggled off, and with autocomplete=off on the username field
  // in a username-only form, we expect to have autofilled this form
  is(form.uname.value, "singleuser", `Checking form6 username is: singleuser`);
});
</script>
</pre>
</body>
</html>