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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test interaction between autocomplete and focus on username 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="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="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>
<script>
let pwmgrCommonScript = runInParent(SimpleTest.getTestFileURL("pwmgr_common.js"));
let readyPromise = registerRunTests();
let chromeScript = runInParent(function chromeSetup() {
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
let pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
let login1A = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
let login1B = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
let login2A = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
let login2B = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
let login2C = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
login1A.init("http://mochi.test:8888", "http://username-focus-1", null,
"testuser1A", "testpass1A", "", "");
login2A.init("http://mochi.test:8888", "http://username-focus-2", null,
"testuser2A", "testpass2A", "", "");
login2B.init("http://mochi.test:8888", "http://username-focus-2", null,
"testuser2B", "testpass2B", "", "");
pwmgr.addLogin(login1A);
pwmgr.addLogin(login2A);
pwmgr.addLogin(login2B);
});
</script>
<p id="display"></p>
<div id="content">
<!-- first 3 forms have a matching user+pass login -->
<!-- user+pass form. -->
<form id="form-autofilled" action="http://username-focus-1">
<input type="text" name="uname">
<input type="password" name="pword">
<button type="submit" name="submit">Submit</button>
</form>
<!-- user+pass form, username prefilled -->
<form id="form-autofilled-prefilled-un" action="http://username-focus-1">
<input type="text" name="uname" value="testuser1A">
<input type="password" name="pword">
<button type="submit">Submit</button>
</form>
<!-- user+pass form. -->
<form id="form-autofilled-focused-dynamic" action="http://username-focus-1">
<input type="text" name="uname">
<input type="not-yet-password" name="pword">
<button type="submit">Submit</button>
</form>
<!-- next 5 forms have matching user+pass (2x) logins -->
<!-- user+pass form. -->
<form id="form-multiple" action="http://username-focus-2">
<input type="text" name="uname">
<input type="password" name="pword">
<button type="submit">Submit</button>
</form>
<!-- user+pass form dynamic with existing focus -->
<form id="form-multiple-dynamic" action="http://username-focus-2">
<input type="text" name="uname">
<input type="not-yet-password" name="pword">
<button type="submit">Submit</button>
</form>
<!-- user+pass form, username prefilled -->
<form id="form-multiple-prefilled-un1" action="http://username-focus-2">
<input type="text" name="uname" value="testuser2A">
<input type="password" name="pword">
<button type="submit">Submit</button>
</form>
<!-- user+pass form, different username prefilled -->
<form id="form-multiple-prefilled-un2" action="http://username-focus-2">
<input type="text" name="uname" value="testuser2B">
<input type="password" name="pword">
<button type="submit">Submit</button>
</form>
<!-- user+pass form, username prefilled with existing focus -->
<form id="form-multiple-prefilled-focused-dynamic" action="http://username-focus-2">
<input type="text" name="uname" value="testuser2B">
<input type="not-yet-password" name="pword">
<button type="submit">Submit</button>
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
function removeFocus() {
$_("-autofilled", "submit").focus();
}
add_task(function* setup() {
yield SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", false],
]});
ok(readyPromise, "check promise is available");
yield readyPromise;
});
add_task(function* test_autofilled() {
let usernameField = $_("-autofilled", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
removeFocus();
usernameField.value = "testuser";
info("Focus when we don't have an exact match");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
add_task(function* test_autofilled_prefilled_un() {
let usernameField = $_("-autofilled-prefilled-un", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
removeFocus();
usernameField.value = "testuser";
info("Focus when we don't have an exact match");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
add_task(function* test_autofilled_focused_dynamic() {
let usernameField = $_("-autofilled-focused-dynamic", "uname");
let passwordField = $_("-autofilled-focused-dynamic", "pword");
info("Username and password will be filled while username focused");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
info("triggering autofill");
noPopupPromise = promiseNoUnexpectedPopupShown();
passwordField.type = "password";
yield noPopupPromise;
let popupState = yield getPopupState();
is(popupState.open, false, "Check popup is closed");
removeFocus();
passwordField.value = "test";
info("Focus when we don't have an exact match");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
// Begin testing forms that have multiple saved logins
add_task(function* test_multiple() {
let usernameField = $_("-multiple", "uname");
info("Fields not filled due to multiple so autocomplete upon focus");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
add_task(function* test_multiple_dynamic() {
let usernameField = $_("-multiple-dynamic", "uname");
let passwordField = $_("-multiple-dynamic", "pword");
info("Fields not filled but username is focused upon marking so open");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
info("triggering _fillForm code");
let shownPromise = promiseACShown();
passwordField.type = "password";
yield shownPromise;
});
add_task(function* test_multiple_prefilled_un1() {
let usernameField = $_("-multiple-prefilled-un1", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
removeFocus();
usernameField.value = "testuser";
info("Focus when we don't have an exact match");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
add_task(function* test_multiple_prefilled_un2() {
let usernameField = $_("-multiple-prefilled-un2", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
removeFocus();
usernameField.value = "testuser";
info("Focus when we don't have an exact match");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
add_task(function* test_multiple_prefilled_focused_dynamic() {
let usernameField = $_("-multiple-prefilled-focused-dynamic", "uname");
let passwordField = $_("-multiple-prefilled-focused-dynamic", "pword");
info("Username and password will be filled while username focused");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
yield noPopupPromise;
info("triggering autofill");
noPopupPromise = promiseNoUnexpectedPopupShown();
passwordField.type = "password";
yield noPopupPromise;
let popupState = yield getPopupState();
is(popupState.open, false, "Check popup is closed");
removeFocus();
passwordField.value = "test";
info("Focus when we don't have an exact match");
shownPromise = promiseACShown();
usernameField.focus();
yield shownPromise;
});
add_task(function* cleanup() {
removeFocus();
});
</script>
</pre>
</body>
</html>
|