File: test_autocomplete_tab_between_fields.html

package info (click to toggle)
thunderbird 1%3A91.13.0-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,953,400 kB
  • sloc: cpp: 6,084,049; javascript: 4,790,441; ansic: 3,341,496; python: 862,958; asm: 366,542; xml: 204,277; java: 152,477; sh: 111,436; makefile: 21,388; perl: 15,312; yacc: 4,583; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; awk: 564; sql: 453; php: 436; lisp: 432; ruby: 99; sed: 69; csh: 45
file content (203 lines) | stat: -rw-r--r-- 6,819 bytes parent folder | download | duplicates (4)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test autocomplete behavior when tabbing between form fields</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="pwmgr_common.js"></script>
  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script>
let nsLoginInfo = SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
                                                                           SpecialPowers.Ci.nsILoginInfo,
                                                                           "init");
let readyPromise = registerRunTests(1);
</script>
<p id="display"></p>

<!-- we presumably can't hide the content for this test. -->
<div id="content">
  <form id="form1" action="https://autofill" 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">
const { TestUtils } = SpecialPowers.Cu.import("resource://testing-common/TestUtils.jsm");

async function prepareLogins(logins = []) {
  await LoginManager.removeAllUserFacingLogins();

  for (let login of logins) {
    let storageAddPromise = promiseStorageChanged(["addLogin"]);
    await LoginManager.addLogin(login);
    await storageAddPromise;
  }
  let count = (await LoginManager.getAllLogins()).length;
  is(count, logins.length, "All logins were added");
}

let origin = window.location.origin;
const availableLogins = {
  "exampleUser1": new nsLoginInfo(origin, "https://autofill", null,
                              "user1", "pass1", "uname", "pword"),
  "subdomainUser1": new nsLoginInfo("https://sub." + window.location.host,
                              "https://autofill", null,
                              "user1", "pass1", "uname", "pword"),
  "emptyUsername": new nsLoginInfo(origin, "https://autofill", null,
                              "", "pass2", "uname", "pword"),
}

const tests = [
  {
    name: "single_login_exact_origin_no_inputs",
    logins: ["exampleUser1"],
    expectedAutofillUsername: "user1",
    expectedAutofillPassword: "pass1",
    expectedACLabels: ["user1"],
    typeUsername: null,
    expectedTabbedUsername: "",
    expectedTabbedPassword: "",
  },
  {
    name: "single_login_exact_origin_initial_letter",
    logins: ["exampleUser1"],
    expectedAutofillUsername: "user1",
    expectedAutofillPassword: "pass1",
    expectedACLabels: ["user1"],
    typeUsername: "u",
    expectedTabbedUsername: "u",
    expectedTabbedPassword: "",
  },
  {
    name: "single_login_exact_origin_type_username",
    logins: ["exampleUser1"],
    expectedAutofillUsername: "user1",
    expectedAutofillPassword: "pass1",
    expectedACLabels: ["user1"],
    typeUsername: "user1",
    expectedTabbedUsername: "user1",
    expectedTabbedPassword: "pass1",
  },
  {
    name: "single_login_subdomain_no_inputs",
    logins: ["subdomainUser1"],
    expectedAutofillUsername: "",
    expectedAutofillPassword: "",
    expectedACLabels: ["user1"],
    typeUsername: null,
    expectedTabbedUsername: "",
    expectedTabbedPassword: "",
  },
  {
    name: "single_login_subdomain_type_username",
    logins: ["subdomainUser1"],
    expectedAutofillUsername: "",
    expectedAutofillPassword: "",
    expectedACLabels: ["user1"],
    typeUsername: "user1",
    expectedTabbedUsername: "user1",
    expectedTabbedPassword: "",
  },
  {
    name: "two_logins_one_with_empty_username",
    logins: ["exampleUser1", "emptyUsername"],
    expectedAutofillUsername: "user1",
    expectedAutofillPassword: "pass1",
    expectedACLabels: ["user1"],
    typeUsername: "",
    expectedTabbedUsername: "",
    expectedTabbedPassword: "",
  },
];

add_task(async function setup() {
  await SpecialPowers.pushPrefEnv({"set": [["signon.includeOtherSubdomainsInLookup", true]]});
  ok(readyPromise, "check promise is available");
  await readyPromise;
});

async function testResultOfTabInteractions(testData) {
  await SimpleTest.promiseFocus(window);
  let logins = testData.logins.map(name => availableLogins[name]);
  await prepareLogins(logins);

  info("recreating form");
  let processed = promiseFormsProcessedInSameProcess();
  recreateTree(document.getElementById("form1"));
  info("waiting for form processed");
  await processed;
  // check autofill results
  checkForm(1, testData.expectedAutofillUsername, testData.expectedAutofillPassword);
  let pword = $_(1, "pword");
  let uname = $_(1, "uname");

  SpecialPowers.wrap(pword).setUserInput("");
  SpecialPowers.wrap(uname).setUserInput("");

  info("Placing focus in the password field");
  const shownPromise = promiseACShown();
  pword.focus();
  await synthesizeKey("KEY_Tab", { shiftKey: true }); // blur pw, focus un
  await new Promise(resolve => SimpleTest.executeSoon(resolve));

  // moving focus shouldn't change anything
  checkForm(1, "", "");

  await synthesizeKey("KEY_ArrowDown");
  info("waiting for AC results");
  let results = await shownPromise;
  info("checking results");
  checkAutoCompleteResults(results, testData.expectedACLabels,
                           window.location.host, "Check all rows are correct");

  if (testData.typeUsername) {
    await sendString(testData.typeUsername);
  }

  // don't select anything from the AC menu
  await synthesizeKey("KEY_Escape");
  await TestUtils.waitForCondition(async () => {
    let popupState = await getPopupState();
    return !popupState.open;
  }, "AutoComplete popup should have closed");

  await synthesizeKey("KEY_Tab");
  // Filling password is performed asynchronously.  So, let's wait the value
  // change instead of just waiting next event loop.
  if (testData.expectedTabbedPassword === "") {
    await new Promise(resolve => SimpleTest.executeSoon(resolve));
  } else {
    await TestUtils.waitForCondition(() => {
      return pword.value === testData.expectedTabbedPassword;
    }, "Password field should be filled");
  }

  ok($_(1, "pword").matches("input:focus"), "pword field is focused");
  checkForm(1, testData.expectedTabbedUsername, testData.expectedTabbedPassword);

  recreateTree(document.getElementById("form1"));
  await promiseFormsProcessedInSameProcess();
  // tidy up by closing any open AC popup
  await synthesizeKey("KEY_Escape");
}

for (let testData of tests) {
  let tmp = {
    async [testData.name]() {
      await testResultOfTabInteractions(testData);
    },
  };
  add_task(tmp[testData.name]);
}

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