Skip to content

Commit 29317f5

Browse files
author
Ryan Safaeian
committed
Bug 1789298 - Make removeValueAt and isRemovableAt return false for LoginAutoCompleteResult and remove associated tests. r=issammani
Differential Revision: https://phabricator.services.mozilla.com/D210223
1 parent a39846b commit 29317f5

6 files changed

+11
-341
lines changed

toolkit/components/passwordmgr/LoginAutoComplete.sys.mjs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,21 +452,12 @@ export class LoginAutoCompleteResult {
452452
return this.getValueAt(index);
453453
}
454454

455-
isRemovableAt(index) {
456-
this.#throwOnBadIndex(index);
457-
return true;
455+
isRemovableAt(_index) {
456+
return false;
458457
}
459458

460-
removeValueAt(index) {
461-
this.#throwOnBadIndex(index);
462-
463-
let [removedItem] = this.#rows.splice(index, 1);
464-
465-
if (this.defaultIndex > this.#rows.length) {
466-
this.defaultIndex--;
467-
}
468-
469-
removedItem.removeFromStorage();
459+
removeValueAt(_index) {
460+
return false;
470461
}
471462
}
472463

toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form.html

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@
297297
is(form.pword.value, "", "password is empty");
298298
});
299299

300-
add_named_task("delete", async () => {
300+
add_named_task("do not delete last", async () => {
301301
await setStoredLoginsDuringTask(
302302
[location.origin, "https://autocomplete:8888", null, "user-1", "pass-1", "uname", "pword"],
303303
[location.origin, "https://autocomplete:8888", null, "user-2", "pass-2", "uname", "pword"],
@@ -309,91 +309,24 @@
309309
form.uname.focus();
310310
await popupByArrowDown();
311311

312-
// XXX tried sending character "t" before/during dropdown to test
313-
// filtering, but had no luck. Seemed like the character was getting lost.
314-
// Setting uname.value didn't seem to work either. This works with a human
315-
// driver, so I'm not sure what's up.
316-
317-
// Delete the first entry (of 3), "user-1"
312+
// Try and fail to delete the last entry (of 3), "user-3"
318313
synthesizeKey("KEY_ArrowDown");
319-
const numLoginsBeforeDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
320-
is(numLoginsBeforeDeletion, 3, "Correct number of logins before deleting one");
321-
322-
const countChangedPromise = notifyMenuChanged(3);
323-
const deletionPromise = promiseStorageChanged(["removeLogin"]);
324-
// On OS X, shift-backspace and shift-delete work, just delete does not.
325-
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
326-
synthesizeKey("KEY_Delete", {shiftKey: true});
327-
await deletionPromise;
328-
329-
is(form.uname.value, "", "username is empty");
330-
is(form.pword.value, "", "password is empty");
331-
const numLoginsAfterDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
332-
is(numLoginsAfterDeletion, 2, "Correct number of logins after deleting one");
333-
await countChangedPromise;
334-
synthesizeKey("KEY_Enter");
335-
await untilAutocompletePopupClosed();
336-
is(form.uname.value, "user-2", "username is set");
337-
is(form.pword.value, "pass-2", "password is set");
338-
});
339-
340-
add_named_task("delete second", async () => {
341-
await setStoredLoginsDuringTask(
342-
[location.origin, "https://autocomplete:8888", null, "user-1", "pass-1", "uname", "pword"],
343-
[location.origin, "https://autocomplete:8888", null, "user-2", "pass-2", "uname", "pword"],
344-
[location.origin, "https://autocomplete:8888", null, "user-3", "pass-3", "uname", "pword"]
345-
);
346-
const form = setContentForTask(formTemplate);
347-
const autofillResult = await formAutofillResult(form.id);
348-
is(autofillResult, "multiple_logins", "form has not been filled due to multiple logins");
349-
form.uname.focus();
350-
await popupByArrowDown();
351-
352-
// Delete the second entry (of 3), "user-2"
353314
synthesizeKey("KEY_ArrowDown");
354315
synthesizeKey("KEY_ArrowDown");
316+
const numLoginsBeforeDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
317+
is(numLoginsBeforeDeletion, 3, "Correct number of logins before trying to delete one using an autocomplete form");
318+
// Pressing the delete key shouldn't remove a login.
355319
synthesizeKey("KEY_Delete", {shiftKey: true});
356320
is(form.uname.value, "", "username is empty");
357321
is(form.pword.value, "", "password is empty");
358-
const numLoginsAfterDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
359-
is(numLoginsAfterDeletion, 2, "Correct number of logins after deleting one");
322+
const numLoginsAfterAttemptedDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
323+
is(numLoginsAfterAttemptedDeletion, 3, "Correct number of logins after trying to delete one using an autocomplete form");
360324
synthesizeKey("KEY_Enter");
361325
await untilAutocompletePopupClosed();
362326
is(form.uname.value, "user-3", "username is set");
363327
is(form.pword.value, "pass-3", "password is set");
364328
});
365329

366-
add_named_task("delete last", async () => {
367-
await setStoredLoginsDuringTask(
368-
[location.origin, "https://autocomplete:8888", null, "user-1", "pass-1", "uname", "pword"],
369-
[location.origin, "https://autocomplete:8888", null, "user-2", "pass-2", "uname", "pword"],
370-
[location.origin, "https://autocomplete:8888", null, "user-3", "pass-3", "uname", "pword"]
371-
);
372-
const form = setContentForTask(formTemplate);
373-
const autofillResult = await formAutofillResult(form.id);
374-
is(autofillResult, "multiple_logins", "form has not been filled due to multiple logins");
375-
form.uname.focus();
376-
await popupByArrowDown();
377-
378-
/* test 54 */
379-
// Delete the last entry (of 3), "user-3"
380-
synthesizeKey("KEY_ArrowDown");
381-
synthesizeKey("KEY_ArrowDown");
382-
synthesizeKey("KEY_ArrowDown");
383-
const numLoginsBeforeDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
384-
is(numLoginsBeforeDeletion, 3, "Correct number of logins before deleting one");
385-
synthesizeKey("KEY_Delete", {shiftKey: true});
386-
is(form.uname.value, "", "username is empty");
387-
is(form.pword.value, "", "password is empty");
388-
const numLoginsAfterDeletion = await LoginManager.countLogins(location.origin, "https://autocomplete:8888", null);
389-
is(numLoginsAfterDeletion, 2, "Correct number of logins after deleting one");
390-
synthesizeKey("KEY_ArrowDown");
391-
synthesizeKey("KEY_Enter");
392-
await untilAutocompletePopupClosed();
393-
is(form.uname.value, "user-1", "username is set");
394-
is(form.pword.value, "pass-1", "password is set");
395-
});
396-
397330
// Tests for single-user forms for ignoring autocomplete=off */
398331

399332
add_named_task("default", async () => {

toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_insecure.html

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -299,108 +299,6 @@
299299
is(form.pword.value, "", "password is empty");
300300
});
301301

302-
add_named_task("delete", async () => {
303-
await setStoredLoginsDuringTask(
304-
[location.origin, "http://autocomplete:8888", null, "user-1", "pass-1", "uname", "pword"],
305-
[location.origin, "http://autocomplete:8888", null, "user-2", "pass-2", "uname", "pword"],
306-
[location.origin, "http://autocomplete:8888", null, "user-3", "pass-3", "uname", "pword"]
307-
);
308-
const form = setContentForTask(formTemplate);
309-
const autofillResult = await formAutofillResult(form.id);
310-
is(autofillResult, "multiple_logins", "form has not been filled due to multiple logins");
311-
form.uname.focus();
312-
await popupByArrowDown();
313-
314-
// XXX tried sending character "t" before/during dropdown to test
315-
// filtering, but had no luck. Seemed like the character was getting lost.
316-
// Setting uname.value didn't seem to work either. This works with a human
317-
// driver, so I'm not sure what's up.
318-
319-
// Delete the first entry (of 3), "user-1"
320-
synthesizeKey("KEY_ArrowDown"); // skip insecure warning
321-
synthesizeKey("KEY_ArrowDown");
322-
const numLoginsBeforeDeletion = await LoginManager.countLogins(location.origin, "http://autocomplete:8888", null);
323-
is(numLoginsBeforeDeletion, 3, "Correct number of logins before deleting one");
324-
325-
const countChangedPromise = notifyMenuChanged(4);
326-
const deletionPromise = promiseStorageChanged(["removeLogin"]);
327-
// On OS X, shift-backspace and shift-delete work, just delete does not.
328-
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
329-
synthesizeKey("KEY_Delete", {shiftKey: true});
330-
await deletionPromise;
331-
332-
is(form.uname.value, "", "username is empty");
333-
is(form.pword.value, "", "password is empty");
334-
const numLoginsAfterDeletion = await LoginManager.countLogins(location.origin, "http://autocomplete:8888", null);
335-
is(numLoginsAfterDeletion, 2, "Correct number of logins after deleting one");
336-
await countChangedPromise;
337-
synthesizeKey("KEY_Enter");
338-
await untilAutocompletePopupClosed();
339-
is(form.uname.value, "user-2", "username is set");
340-
is(form.pword.value, "pass-2", "password is set");
341-
});
342-
343-
add_named_task("delete second", async () => {
344-
await setStoredLoginsDuringTask(
345-
[location.origin, "http://autocomplete:8888", null, "user-1", "pass-1", "uname", "pword"],
346-
[location.origin, "http://autocomplete:8888", null, "user-2", "pass-2", "uname", "pword"],
347-
[location.origin, "http://autocomplete:8888", null, "user-3", "pass-3", "uname", "pword"]
348-
);
349-
const form = setContentForTask(formTemplate);
350-
const autofillResult = await formAutofillResult(form.id);
351-
is(autofillResult, "multiple_logins", "form has not been filled due to multiple logins");
352-
form.uname.focus();
353-
await popupByArrowDown();
354-
355-
synthesizeKey("KEY_ArrowDown"); // skip insecure warning
356-
// Delete the second entry (of 3), "user-2"
357-
synthesizeKey("KEY_ArrowDown");
358-
synthesizeKey("KEY_ArrowDown");
359-
synthesizeKey("KEY_Delete", {shiftKey: true});
360-
is(form.uname.value, "", "username is empty");
361-
is(form.pword.value, "", "password is empty");
362-
const numLoginsAfterDeletion = await LoginManager.countLogins(location.origin, "http://autocomplete:8888", null);
363-
is(numLoginsAfterDeletion, 2, "Correct number of logins after deleting one");
364-
synthesizeKey("KEY_Enter");
365-
await untilAutocompletePopupClosed();
366-
is(form.uname.value, "user-3", "username is set");
367-
is(form.pword.value, "pass-3", "password is set");
368-
});
369-
370-
add_named_task("delete last", async () => {
371-
await setStoredLoginsDuringTask(
372-
[location.origin, "http://autocomplete:8888", null, "user-1", "pass-1", "uname", "pword"],
373-
[location.origin, "http://autocomplete:8888", null, "user-2", "pass-2", "uname", "pword"],
374-
[location.origin, "http://autocomplete:8888", null, "user-3", "pass-3", "uname", "pword"]
375-
);
376-
const form = setContentForTask(formTemplate);
377-
const autofillResult = await formAutofillResult(form.id);
378-
is(autofillResult, "multiple_logins", "form has not been filled due to multiple logins");
379-
form.uname.focus();
380-
await popupByArrowDown();
381-
382-
/* test 54 */
383-
synthesizeKey("KEY_ArrowDown"); // skip insecure warning
384-
// Delete the last entry (of 3), "user-3"
385-
synthesizeKey("KEY_ArrowDown");
386-
synthesizeKey("KEY_ArrowDown");
387-
synthesizeKey("KEY_ArrowDown");
388-
const numLoginsBeforeDeletion = await LoginManager.countLogins(location.origin, "http://autocomplete:8888", null);
389-
is(numLoginsBeforeDeletion, 3, "Correct number of logins before deleting one");
390-
synthesizeKey("KEY_Delete", {shiftKey: true});
391-
is(form.uname.value, "", "username is empty");
392-
is(form.pword.value, "", "password is empty");
393-
const numLoginsAfterDeletion = await LoginManager.countLogins(location.origin, "http://autocomplete:8888", null);
394-
is(numLoginsAfterDeletion, 2, "Correct number of logins after deleting one");
395-
synthesizeKey("KEY_ArrowDown"); // skip insecure warning
396-
synthesizeKey("KEY_ArrowDown");
397-
synthesizeKey("KEY_Enter");
398-
await untilAutocompletePopupClosed();
399-
is(form.uname.value, "user-1", "username is set");
400-
is(form.pword.value, "pass-1", "password is set");
401-
});
402-
403-
404302
// Tests for single-user forms for ignoring autocomplete=off
405303

406304
add_named_task("default", async () => {

toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -127,65 +127,6 @@
127127
let popupState = await getPopupState();
128128
is(popupState.open, false, "Check popup is now closed");
129129
});
130-
131-
add_task(async function test_delete_first_entry() {
132-
await restoreForm();
133-
await popupBy();
134-
135-
let index0Promise = notifySelectedIndex(0);
136-
synthesizeKey("KEY_ArrowDown");
137-
await index0Promise;
138-
139-
let deletionPromise = promiseStorageChanged(["removeLogin"]);
140-
// On OS X, shift-backspace and shift-delete work, just delete does not.
141-
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
142-
synthesizeKey("KEY_Delete", {shiftKey: true});
143-
await deletionPromise;
144-
await checkLoginFormInFrame(getIframeBrowsingContext(window, 0), "form-basic-username", "", "form-basic-password", "");
145-
146-
let results = await notifyMenuChanged(3, "name1");
147-
148-
checkAutoCompleteResults(results.labels, ["name1", "name2"], hostname, "two logins should remain after deleting the first");
149-
150-
let popupState = await getPopupState();
151-
is(popupState.open, true, "Check popup stays open after deleting");
152-
synthesizeKey("KEY_Escape");
153-
popupState = await getPopupState();
154-
is(popupState.open, false, "Check popup closed upon ESC");
155-
});
156-
157-
add_task(async function test_delete_duplicate_entry() {
158-
await restoreForm();
159-
await popupBy();
160-
161-
let index0Promise = notifySelectedIndex(0);
162-
synthesizeKey("KEY_ArrowDown");
163-
await index0Promise;
164-
165-
let deletionPromise = promiseStorageChanged(["removeLogin"]);
166-
// On OS X, shift-backspace and shift-delete work, just delete does not.
167-
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
168-
synthesizeKey("KEY_Delete", {shiftKey: true});
169-
await deletionPromise;
170-
await checkLoginFormInFrame(getIframeBrowsingContext(window, 0), "form-basic-username", "", "form-basic-password", "");
171-
172-
is(await LoginManager.countLogins(originNonSecure, originNonSecure, null), 1,
173-
"Check that the HTTP login remains");
174-
is(await LoginManager.countLogins(originSecure, originSecure, null), 0,
175-
"Check that the HTTPS login was deleted");
176-
177-
// Two menu items should remain as the HTTPS login should have been deleted but
178-
// the HTTP would remain.
179-
let results = await notifyMenuChanged(2, "name2");
180-
181-
checkAutoCompleteResults(results.labels, ["name2"], hostname, "one login should remain after deleting the HTTPS name1");
182-
let popupState = await getPopupState();
183-
is(popupState.open, true, "Check popup stays open after deleting");
184-
synthesizeKey("KEY_Escape");
185-
popupState = await getPopupState();
186-
is(popupState.open, false, "Check popup closed upon ESC");
187-
});
188-
189130
</script>
190131
</pre>
191132
</body>

0 commit comments

Comments
 (0)