diff options
Diffstat (limited to 'toolkit/components/passwordmgr/test/mochitest/test_autocomplete_autofill_related_realms_no_dupes.html')
-rw-r--r-- | toolkit/components/passwordmgr/test/mochitest/test_autocomplete_autofill_related_realms_no_dupes.html | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_autofill_related_realms_no_dupes.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_autofill_related_realms_no_dupes.html new file mode 100644 index 0000000000..243ea9f052 --- /dev/null +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_autofill_related_realms_no_dupes.html @@ -0,0 +1,92 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test no duplicate logins using autofill/autocomplete with related realms</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" href="/tests/SimpleTest/test.css"/> +</head> +<body> +Login Manager test: no duplicate logins when using autofill and autocomplete with related realms +<p id="display"></p> +<div id="content"></div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Login Manager: related realms autofill/autocomplete. **/ + +function restoreForm(form) { + form.uname.value = ""; + form.pword.value = ""; + form.uname.focus(); +} + +function sendFakeAutocompleteEvent(element) { + const acEvent = document.createEvent("HTMLEvents"); + acEvent.initEvent("DOMAutoComplete", true, false); + element.dispatchEvent(acEvent); +} + +function spinEventLoop() { + return Promise.resolve(); +} + +async function promiseACPopupClosed() { + return SimpleTest.promiseWaitForCondition(async () => { + const popupState = await getPopupState(); + return !popupState.open; + }, "Wait for AC popup to be closed"); +} + +add_setup(async () => { + await addLoginsInParent( + // Simple related domain relationship where example.com and other-example.com are in the related domains list + ["https://other-example.com", "https://other-example.com", null, "relatedUser1", "relatedPass1", "uname", "pword"], + + // Example.com and example.co.uk are related, so sub.example.co.uk should appear on example.com's autocomplete dropdown + // The intent is to cover the ebay.com/ebay.co.uk and all other country TLD cases + // where the sign in page is actually signin.ebay.com/signin.ebay.co.uk but credentials could have manually been entered + // for ebay.com/ebay.co.uk or automatically stored as signin.ebay.com/sigin.ebay.co.uk + ["https://sub.example.co.uk", "https://sub.example.co.uk", null, "subUser1", "subPass1", "uname", "pword"], + + // Ensures there are no duplicates for the exact domain that the user is on + ["https://example.com", "https://example.com", null, "exactUser1", "exactPass1", "uname", "pword"], + ["https://www.example.com", "https://www.example.com", null, "exactWWWUser1", "exactWWWPass1", "uname", "pword"], + ); + listenForUnexpectedPopupShown(); +}); + +add_task(async function test_no_duplicates_autocomplete_autofill() { + const form = createLoginForm({ + action: "https://www.example.com" + }); + + await promiseFormsProcessedInSameProcess(); + await SimpleTest.promiseFocus(window); + const results = await popupBy(() => { + checkLoginForm(form.uname, "exactUser1", form.pword, "exactPass1") + restoreForm(form); + }); + + const popupState = await getPopupState(); + is(popupState.selectedIndex, -1, "Check no entires are selected upon opening"); + const expectedMenuItems = ["exactUser1", "exactWWWUser1", "relatedUser1", "subUser1"]; + checkAutoCompleteResults(results, expectedMenuItems, window.location.host, "Check all menuitems are displayed correctly"); + + const acEvents = await getTelemetryEvents({ process: "parent", filterProps: TelemetryFilterPropsAC, clear: true }); + is(acEvents.length, 1, "One autocomplete event"); + checkACTelemetryEvent(acEvents[0], form.uname, { + "hadPrevious": "0", + "login": expectedMenuItems.length + "", + "loginsFooter": "1" + }); + restoreForm(form); + synthesizeKey("KEY_Escape"); +}); +</script> +</pre> +</body> +</html> |