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 index f885794476fa..19b6bee97a27 100644 --- 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 @@ -75,10 +75,10 @@ add_setup(async () => { add_task(async function test_no_duplicates_autocomplete_autofill() { await promiseFormsProcessedInSameProcess(); await SimpleTest.promiseFocus(window); - let shownPromise = promiseACShown(); - checkLoginForm(uname, "exactUser1", pword, "exactPass1") - restoreForm(); - let results = await shownPromise; + let results = await popupBy(() => { + checkLoginForm(uname, "exactUser1", pword, "exactPass1") + restoreForm(); + }); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entires are selected upon opening"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form.html index 1d7d3425b5c1..e24736aa93ac 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form.html @@ -170,7 +170,7 @@ add_task(async function test_form1_menuitems() { await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -200,7 +200,7 @@ add_task(async function test_form1_first_entry() { await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -216,7 +216,7 @@ add_task(async function test_form1_first_entry() { add_task(async function test_form1_second_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second @@ -229,7 +229,7 @@ add_task(async function test_form1_second_entry() { add_task(async function test_form1_third_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second @@ -243,7 +243,7 @@ add_task(async function test_form1_third_entry() { add_task(async function test_form1_fourth_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second @@ -259,7 +259,7 @@ add_task(async function test_form1_wraparound_first_entry() { // Trigger autocomplete popup restoreForm(); await spinEventLoop(); // let focus happen - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second @@ -277,7 +277,7 @@ add_task(async function test_form1_wraparound_first_entry() { add_task(async function test_form1_wraparound_up_last_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowUp"); // footer synthesizeKey("KEY_ArrowUp"); // last (fourth) @@ -290,7 +290,7 @@ add_task(async function test_form1_wraparound_up_last_entry() { add_task(async function test_form1_wraparound_down_up_up() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // select first entry synthesizeKey("KEY_ArrowUp"); // selects nothing! @@ -304,7 +304,7 @@ add_task(async function test_form1_wraparound_down_up_up() { add_task(async function test_form1_wraparound_up_last() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); synthesizeKey("KEY_ArrowUp"); // deselects @@ -324,7 +324,7 @@ add_task(async function test_form1_wraparound_up_last() { add_task(async function test_form1_fill_username_without_autofill_right() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Set first entry w/o triggering autocomplete synthesizeKey("KEY_ArrowDown"); // first @@ -335,7 +335,7 @@ add_task(async function test_form1_fill_username_without_autofill_right() { add_task(async function test_form1_fill_username_without_autofill_left() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Set first entry w/o triggering autocomplete synthesizeKey("KEY_ArrowDown"); // first @@ -346,7 +346,7 @@ add_task(async function test_form1_fill_username_without_autofill_left() { add_task(async function test_form1_pageup_first() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry (page up) synthesizeKey("KEY_ArrowDown"); // first @@ -360,7 +360,7 @@ add_task(async function test_form1_pageup_first() { add_task(async function test_form1_pagedown_last() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); /* test 13 */ // Check last entry (page down) @@ -387,7 +387,7 @@ add_task(async function test_form1_untrusted_event() { add_task(async function test_form1_delete() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // XXX tried sending character "t" before/during dropdown to test // filtering, but had no luck. Seemed like the character was getting lost. @@ -418,7 +418,7 @@ add_task(async function test_form1_delete() { add_task(async function test_form1_first_after_deletion() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check the new first entry (of 3) synthesizeKey("KEY_ArrowDown"); @@ -430,7 +430,7 @@ add_task(async function test_form1_first_after_deletion() { add_task(async function test_form1_delete_second() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Delete the second entry (of 3), "testuser3" synthesizeKey("KEY_ArrowDown"); @@ -447,7 +447,7 @@ add_task(async function test_form1_delete_second() { add_task(async function test_form1_first_after_deletion2() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check the new first entry (of 2) synthesizeKey("KEY_ArrowDown"); @@ -459,7 +459,7 @@ add_task(async function test_form1_first_after_deletion2() { add_task(async function test_form1_delete_last() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); /* test 54 */ // Delete the last entry (of 2), "zzzuser4" @@ -478,7 +478,7 @@ add_task(async function test_form1_delete_last() { add_task(async function test_form1_first_after_3_deletions() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check the only remaining entry synthesizeKey("KEY_ArrowDown"); @@ -490,7 +490,7 @@ add_task(async function test_form1_first_after_3_deletions() { add_task(async function test_form1_check_only_entry_remaining() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); /* test 56 */ // Delete the only remaining entry, "testuser2" @@ -526,7 +526,7 @@ add_task(async function test_form2() { checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry synthesizeKey("KEY_ArrowDown"); @@ -549,7 +549,7 @@ add_task(async function test_form3() { pword = getFormElementByName(3, "pword"); checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry synthesizeKey("KEY_ArrowDown"); @@ -572,7 +572,7 @@ add_task(async function test_form4() { pword = getFormElementByName(4, "pword"); checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry synthesizeKey("KEY_ArrowDown"); @@ -595,7 +595,7 @@ add_task(async function test_form5() { pword = getFormElementByName(5, "pword"); checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry synthesizeKey("KEY_ArrowDown"); @@ -675,7 +675,7 @@ add_task(async function test_form7() { add_task(async function test_form7_2() { restoreForm(); - const autocompleteItems = await openAutocompletePopup();; + const autocompleteItems = await popupByArrowDown(); checkAutoCompleteResults(autocompleteItems, ["form7user1"], window.location.host, @@ -755,20 +755,16 @@ add_task(async function test_form9_filtering() { `, {fieldSelector: `input[name="uname"]`, fieldValue: ""}); // Turn our attention to form9 to test the dropdown - bug 497541 - let shownPromise = promiseACShown(); uname = getFormElementByName(9, "uname"); pword = getFormElementByName(9, "pword"); - uname.focus(); - let results = await shownPromise; + let results = await popupBy(() => uname.focus()); checkAutoCompleteResults(results, ["form9userAAB", "form9userAB"], window.location.host, "Check dropdown is showing all logins while field is blank"); synthesizeKey("KEY_Escape"); // Need to close the popup so we can get another popupshown after sending the string below. - shownPromise = promiseACShown(); - sendString("form9userAB"); - results = await shownPromise; + results = await popupBy(() => sendString("form9userAB")); checkAutoCompleteResults(results, ["form9userAB"], window.location.host, @@ -777,9 +773,7 @@ add_task(async function test_form9_filtering() { checkLoginForm(uname, "form9userAB", pword, ""); uname.focus(); synthesizeKey("KEY_ArrowLeft"); - shownPromise = promiseACShown(); - synthesizeKey("A", {shiftKey: true}); - results = await shownPromise; + results = await popupBy(() => synthesizeKey("A", {shiftKey: true})); checkLoginForm(uname, "form9userAAB", pword, ""); checkAutoCompleteResults(results, ["form9userAAB"], @@ -833,7 +827,7 @@ add_task(async function test_form11_formless() { pword = getFormElementByName(11, "pword"); restoreForm(); checkLoginForm(uname, "", pword, ""); - await openAutocompletePopup(); + await popupByArrowDown(); // Trigger autocomplete synthesizeKey("KEY_ArrowDown"); @@ -861,10 +855,10 @@ add_task(async function test_form11_open_on_trusted_focus() { resolve(); }); }); - const shownPromise = promiseACShown(); - synthesizeMouseAtCenter(uname, {}); - await firePrivEventPromise; - await shownPromise; + await popupBy(async () => { + synthesizeMouseAtCenter(uname, {}); + await firePrivEventPromise; + }); synthesizeKey("KEY_ArrowDown"); const processedPromise = promiseFormsProcessedInSameProcess(); synthesizeKey("KEY_Enter"); @@ -905,7 +899,7 @@ add_task(async function test_form12_recipes() { await promiseFormsProcessedInSameProcess(); restoreForm(); checkLoginForm(uname, "", pword, ""); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); checkLoginForm(uname, "", pword, ""); // value shouldn't update @@ -939,9 +933,7 @@ add_task(async function test_form13_stays_open_upon_empty_search() { checkLoginForm(uname, "prefilled", pword, "prefilled"); uname.scrollIntoView(); - let shownPromise = promiseACShown(); - synthesizeMouseAtCenter(uname, {}); - await shownPromise; + await popupBy(() => synthesizeMouseAtCenter(uname, {})); uname.select(); synthesizeKey("KEY_Delete"); @@ -955,9 +947,7 @@ add_task(async function test_form13_stays_open_upon_empty_search() { pword.select(); popupState = await getPopupState(); is(popupState.open, false, "Check popup closed since password field isn't empty"); - shownPromise = promiseACShown(); - synthesizeKey("KEY_Delete"); - await shownPromise; + await popupBy(() => synthesizeKey("KEY_Delete")); checkLoginForm(uname, "", pword, ""); // ensure the popup is closed for the next test @@ -982,7 +972,7 @@ add_task(async function test_form14_username_only() { pword = {value: ""}; checkLoginForm(uname, "prefilled", pword, ""); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry synthesizeKey("KEY_ArrowDown"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_formActionOrigin.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_formActionOrigin.html index 541f8391bdda..bbc57824b94c 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_formActionOrigin.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_formActionOrigin.html @@ -70,7 +70,7 @@ add_task(async function test_form1_menu_shows_logins_for_different_formActionOri await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_insecure.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_insecure.html index b06c4db587b3..8b6f90d68993 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_insecure.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_insecure.html @@ -142,7 +142,7 @@ add_task(async function test_form1_warning_entry() { await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -165,7 +165,7 @@ add_task(async function test_form1_first_entry() { await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -181,7 +181,7 @@ add_task(async function test_form1_first_entry() { add_task(async function test_form1_second_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning synthesizeKey("KEY_ArrowDown"); // first @@ -194,7 +194,7 @@ add_task(async function test_form1_second_entry() { add_task(async function test_form1_third_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning synthesizeKey("KEY_ArrowDown"); // first @@ -208,7 +208,7 @@ add_task(async function test_form1_third_entry() { add_task(async function test_form1_fourth_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning synthesizeKey("KEY_ArrowDown"); // first @@ -224,7 +224,7 @@ add_task(async function test_form1_wraparound_first_entry() { // Trigger autocomplete popup restoreForm(); await spinEventLoop(); // let focus happen - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning synthesizeKey("KEY_ArrowDown"); // first @@ -243,7 +243,7 @@ add_task(async function test_form1_wraparound_first_entry() { add_task(async function test_form1_wraparound_up_last_entry() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowUp"); // footer synthesizeKey("KEY_ArrowUp"); // last (fourth) @@ -255,7 +255,7 @@ add_task(async function test_form1_wraparound_up_last_entry() { add_task(async function test_form1_wraparound_down_up_up() { // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // select first entry synthesizeKey("KEY_ArrowUp"); // selects nothing! @@ -268,7 +268,7 @@ add_task(async function test_form1_wraparound_down_up_up() { add_task(async function test_form1_wraparound_up_last() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); synthesizeKey("KEY_ArrowUp"); // deselects @@ -288,7 +288,7 @@ add_task(async function test_form1_wraparound_up_last() { add_task(async function test_form1_fill_username_without_autofill_right() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Set first entry w/o triggering autocomplete synthesizeKey("KEY_ArrowDown"); // skip insecure warning @@ -300,7 +300,7 @@ add_task(async function test_form1_fill_username_without_autofill_right() { add_task(async function test_form1_fill_username_without_autofill_left() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Set first entry w/o triggering autocomplete synthesizeKey("KEY_ArrowDown"); // skip insecure warning @@ -311,7 +311,7 @@ add_task(async function test_form1_fill_username_without_autofill_left() { add_task(async function test_form1_pageup_first() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // Check first entry (page up) synthesizeKey("KEY_ArrowDown"); // first @@ -325,7 +325,7 @@ add_task(async function test_form1_pageup_first() { add_task(async function test_form1_pagedown_last() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // test 13 // Check last entry (page down) @@ -351,7 +351,7 @@ add_task(async function test_form1_untrusted_event() { add_task(async function test_form1_delete() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); // XXX tried sending character "t" before/during dropdown to test // filtering, but had no luck. Seemed like the character was getting lost. @@ -383,7 +383,7 @@ add_task(async function test_form1_delete() { add_task(async function test_form1_first_after_deletion() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check the new first entry (of 3) @@ -395,7 +395,7 @@ add_task(async function test_form1_first_after_deletion() { add_task(async function test_form1_delete_second() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Delete the second entry (of 3), "testuser3" @@ -414,7 +414,7 @@ add_task(async function test_form1_delete_second() { add_task(async function test_form1_first_after_deletion2() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check the new first entry (of 2) @@ -426,7 +426,7 @@ add_task(async function test_form1_first_after_deletion2() { add_task(async function test_form1_delete_last() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // test 54 @@ -448,7 +448,7 @@ add_task(async function test_form1_delete_last() { add_task(async function test_form1_first_after_3_deletions() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check the only remaining entry @@ -460,7 +460,7 @@ add_task(async function test_form1_first_after_3_deletions() { add_task(async function test_form1_check_only_entry_remaining() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // test 56 @@ -496,7 +496,7 @@ add_task(async function test_form2() { checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check first entry @@ -519,7 +519,7 @@ add_task(async function test_form3() { pword = getFormElementByName(3, "pword"); checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check first entry @@ -542,7 +542,7 @@ add_task(async function test_form4() { pword = getFormElementByName(4, "pword"); checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check first entry @@ -565,7 +565,7 @@ add_task(async function test_form5() { pword = getFormElementByName(5, "pword"); checkLoginForm(uname, "singleuser5", pword, "singlepass5"); restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check first entry @@ -644,7 +644,7 @@ add_task(async function test_form7() { add_task(async function test_form7_2() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning // Check first entry @@ -719,19 +719,17 @@ add_task(async function test_form9_filtering() { `, {fieldSelector: `input[name="uname"]`, fieldValue: ""}); // Turn our attention to form9 to test the dropdown - bug 497541 - let shownPromise = promiseACShown(); - uname = getFormElementByName(9, "uname"); - pword = getFormElementByName(9, "pword"); - uname.focus(); - let results = await shownPromise; + let results = await popupBy(() => { + uname = getFormElementByName(9, "uname"); + pword = getFormElementByName(9, "pword"); + uname.focus(); + }); checkAutoCompleteResults(results, ["This connection is not secure. Logins entered here could be compromised. Learn More", "form9userAAB", "form9userAB"], "mochi.test", "Check dropdown is showing all logins while field is blank"); synthesizeKey("KEY_Escape"); // Need to close the popup so we can get another popupshown after sending the string below. - shownPromise = promiseACShown(); - sendString("form9userAB"); - results = await shownPromise; + results = await popupBy(() => sendString("form9userAB")); checkAutoCompleteResults(results, ["This connection is not secure. Logins entered here could be compromised. Learn More", "form9userAB"], "mochi.test", @@ -740,9 +738,7 @@ add_task(async function test_form9_filtering() { checkLoginForm(uname, "form9userAB", pword, ""); uname.focus(); synthesizeKey("KEY_ArrowLeft"); - shownPromise = promiseACShown(); - synthesizeKey("A", {shiftKey: true}); - results = await shownPromise; + results = await popupBy(() => synthesizeKey("A", {shiftKey: true})); checkLoginForm(uname, "form9userAAB", pword, ""); checkAutoCompleteResults(results, @@ -765,7 +761,7 @@ add_task(async function test_form9_autocomplete_cache() { await storageChanged; uname.focus(); let promise2 = notifyMenuChanged(2); - let shownPromise = promiseACShown(); + let shownPromise = popupBy(); sendString("z"); let results = await promise2; await shownPromise; @@ -817,7 +813,7 @@ add_task(async function test_form11_recipes() { await promiseFormsProcessedInSameProcess(); restoreForm(); checkLoginForm(uname, "", pword, ""); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // skip insecure warning synthesizeKey("KEY_ArrowDown"); @@ -849,9 +845,9 @@ add_task(async function test_form12_formless() { uname = getFormElementByName(12, "uname"); pword = getFormElementByName(12, "pword"); - await openAutocompletePopup(uname); + await openPopupOn(uname); synthesizeKey("KEY_Escape"); // close the autocomplete popup - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let expectedMenuItems = ["This connection is not secure. Logins entered here could be compromised. Learn More", "testuser10"]; @@ -879,9 +875,7 @@ add_task(async function test_form13_stays_open_upon_empty_search() { checkLoginForm(uname, "prefilled", pword, "prefilled"); uname.scrollIntoView(); - let shownPromise = promiseACShown(); - synthesizeMouseAtCenter(uname, {}); - await shownPromise; + await popupBy(() => synthesizeMouseAtCenter(uname, {})); uname.select(); synthesizeKey("KEY_Delete"); @@ -895,9 +889,7 @@ add_task(async function test_form13_stays_open_upon_empty_search() { pword.select(); popupState = await getPopupState(); is(popupState.open, false, "Check popup closed since password field isn't empty"); - shownPromise = promiseACShown(); - synthesizeKey("KEY_Delete"); - await shownPromise; + await popupBy(() => synthesizeKey("KEY_Delete")); checkLoginForm(uname, "", pword, ""); }); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_related_realms.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_related_realms.html index dba17ce06f41..0178ed02bd28 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_related_realms.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_related_realms.html @@ -81,7 +81,7 @@ add_task(async function test_form1_initial_empty() { add_task(async function test_form_related_domain_menuitems() { await SimpleTest.promiseFocus(window); restoreForm(); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entires are selected upon opening"); @@ -107,7 +107,7 @@ add_task(async function test_form_related_domain_menuitems() { restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first item synthesizeKey("KEY_ArrowDown"); // second item diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_subdomain.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_subdomain.html index 0a6177d85a73..1cfd67a0a43f 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_subdomain.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_basic_form_subdomain.html @@ -94,7 +94,7 @@ add_task(async function test_form1_menu_shows_two_logins_same_usernames_for_diff await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -116,7 +116,7 @@ add_task(async function test_form1_menu_shows_two_logins_same_usernames_for_diff restoreForm(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first item synthesizeKey("KEY_ArrowDown"); // second item diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_hasBeenTypePassword.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_hasBeenTypePassword.html index fabfe038e60a..f67f302e87f1 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_hasBeenTypePassword.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_hasBeenTypePassword.html @@ -68,7 +68,7 @@ add_task(async function test_form1_password_to_type_text() { // Trigger autocomplete popup restoreForm(); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -90,7 +90,7 @@ add_task(async function test_form1_password_to_type_text() { info("Focusing the password field"); pword.focus(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // first item checkLoginForm(uname, "", pword, ""); // value shouldn't update just by selecting diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight.html index 49f1c11180a8..68dfe81f02cb 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight.html @@ -42,7 +42,7 @@ add_task(async function test_field_highlight_on_autocomplete() { let username = document.getElementById("uname"); let password = document.getElementById("pword"); - await openAutocompletePopup(username); + await openPopupOn(username); synthesizeKey("KEY_ArrowDown"); await synthesizeKey("KEY_Enter"); @@ -72,7 +72,7 @@ add_task(async function test_field_highlight_on_autocomplete() { password.value = ""; // Test password field autocomplete. - await openAutocompletePopup(password); + await openPopupOn(password); synthesizeKey("KEY_ArrowDown"); synthesizeKey("KEY_Enter"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_non_login.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_non_login.html index 2c3df90184b2..cabab173be28 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_non_login.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_non_login.html @@ -40,7 +40,7 @@ add_setup(async () => { add_task(async function test_field_highlight_on_pw_field_autocomplete_insecureWarning() { // Press enter on insecure warning and check. password.focus(); - await openAutocompletePopup(); + await popupByArrowDown(); synthesizeKey("KEY_ArrowDown"); // insecure warning synthesizeKey("KEY_Enter"); @@ -51,7 +51,7 @@ add_task(async function test_field_highlight_on_pw_field_autocomplete_insecureWa "Highlight is not applied to the username field if enter key is pressed on the insecure warning item"); // Press tab on insecure warning and check. - await openAutocompletePopup(password); + await openPopupOn(password); synthesizeKey("KEY_ArrowDown"); // insecure warning synthesizeKey("KEY_Tab"); @@ -71,7 +71,7 @@ function closeCurrentTab() { add_task(async function test_field_highlight_on_pw_field_autocomplete_footer() { // Press enter on the footer and check. - await openAutocompletePopup(password); + await openPopupOn(password); synthesizeKey("KEY_ArrowUp"); // footer synthesizeKey("KEY_Enter"); @@ -84,7 +84,7 @@ add_task(async function test_field_highlight_on_pw_field_autocomplete_footer() { closeCurrentTab(); // Press tab on the footer and check. - await openAutocompletePopup(password); + await openPopupOn(password); synthesizeKey("KEY_ArrowUp"); // footer synthesizeKey("KEY_Tab"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_username_only_form.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_username_only_form.html index 8a9e035ed2ba..b903fec6a876 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_username_only_form.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_highlight_username_only_form.html @@ -40,7 +40,7 @@ add_task(async function test_username_field_in_username_only_form_highlight_on_a // Test username autocomplete. const username = document.getElementById("uname"); - await openAutocompletePopup(username); + await openPopupOn(username); synthesizeKey("KEY_ArrowDown"); await synthesizeKey("KEY_Enter"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_downgrade.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_downgrade.html index e3d4b0fff0c5..f103fd64ca71 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_downgrade.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_downgrade.html @@ -94,7 +94,7 @@ add_task(async function test_autocomplete_https_downgrade() { await restoreForm(); let popupState = await getPopupState(); is(popupState.open, false, "Check popup is initially closed"); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); info("got results: " + autocompleteItems.join(", ")); popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html index c041e7fd5c4a..31059d7da5bd 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html @@ -80,7 +80,7 @@ add_task(async function test_empty_first_entry() { await restoreForm(); let popupState = await getPopupState(); is(popupState.open, false, "Check popup is initially closed"); - let autocompleteItems = await openAutocompletePopup(); + let autocompleteItems = await popupBy(); popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected"); checkAutoCompleteResults(autocompleteItems, ["name", "name1", "name2"], hostname, "initial"); @@ -97,7 +97,7 @@ add_task(async function test_empty_first_entry() { add_task(async function test_empty_second_entry() { await restoreForm(); - await openAutocompletePopup(); + await popupBy(); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second synthesizeKey("KEY_Enter"); @@ -107,19 +107,18 @@ add_task(async function test_empty_second_entry() { add_task(async function test_search() { await restoreForm(); - let shownPromise = promiseACShown(); + let results = await popupBy(async () => { + // We need to blur for the autocomplete controller to notice the forced value below. + await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { + let uname = this.content.document.getElementById("form-basic-username"); + uname.blur(); + uname.value = "name"; + uname.focus(); + }); - // We need to blur for the autocomplete controller to notice the forced value below. - await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { - let uname = this.content.document.getElementById("form-basic-username"); - uname.blur(); - uname.value = "name"; - uname.focus(); + sendChar("1"); + synthesizeKey("KEY_ArrowDown"); // open }); - - sendChar("1"); - synthesizeKey("KEY_ArrowDown"); // open - let results = await shownPromise; checkAutoCompleteResults(results, ["name1"], hostname, "check result deduping for 'name1'"); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_Enter"); @@ -132,7 +131,7 @@ add_task(async function test_search() { add_task(async function test_delete_first_entry() { await restoreForm(); - await openAutocompletePopup(); + await popupBy(); let index0Promise = notifySelectedIndex(0); synthesizeKey("KEY_ArrowDown"); @@ -157,7 +156,7 @@ add_task(async function test_delete_first_entry() { add_task(async function test_delete_duplicate_entry() { await restoreForm(); - await openAutocompletePopup(); + await popupBy(); let index0Promise = notifySelectedIndex(0); synthesizeKey("KEY_ArrowDown"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation.html index ff3ae2e7607b..ee79dfe5ed11 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation.html @@ -111,7 +111,7 @@ async function promiseACPopupClosed() { } async function showACPopup(formNumber, expectedACLabels) { - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); checkAutoCompleteResults(autocompleteItems, expectedACLabels, window.location.host, "Check all rows are correct"); } @@ -202,8 +202,7 @@ add_task(async function test_autofillAutocompletePassword_noGeneration() { checkForm(2, "", "pass1"); // No autocomplete results should appear for non-empty pw fields. - synthesizeKey("KEY_ArrowDown"); - await promiseNoUnexpectedPopupShown(); + await noPopupByArrowDown(); recreateTree(document.getElementById("form2")); }); @@ -277,8 +276,7 @@ add_task(async function test_autofillAutocompletePassword_withGeneration() { checkForm(formNumber, "", "pass1"); // No autocomplete results should appear for non-empty pw fields. - synthesizeKey("KEY_ArrowDown"); - await promiseNoUnexpectedPopupShown(); + await noPopupByArrowDown(); info("Removing all logins to test auto-saving of generated passwords"); await LoginManager.removeAllUserFacingLogins(); @@ -457,7 +455,7 @@ add_task(async function test_deleteAndReselectGeneratedPassword() { pword.select(); synthesizeKey("KEY_Backspace"); } - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupByArrowDown(); if (index < 0) { index = autocompleteItems.length + index; } diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html index c0b671942445..f92a4f934fa1 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html @@ -115,11 +115,11 @@ async function promiseACPopupClosed() { async function fillWithGeneratedPassword(input, expectedResults = ["Use a Securely Generated Password"]) { info("Opening the AC menu"); - const autocompleteItems = await openAutocompletePopup(input); - checkAutoCompleteResults(autocompleteItems, expectedResults, + const { items } = await openPopupOn(input); + checkAutoCompleteResults(items, expectedResults, window.location.host, "Check all rows are correct"); - for (let autocompleteItem of autocompleteItems) { + for (let autocompleteItem of items) { synthesizeKey("KEY_ArrowDown"); if (autocompleteItem == "Use a Securely Generated Password") { synthesizeKey("KEY_Enter"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_open.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_open.html index 61eafab0a589..2e2f79652454 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_open.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_open.html @@ -43,13 +43,10 @@ add_task(async function test_no_autofill() { }); add_task(async function test_two_logins() { - let shownPromise = promiseACShown(); - uname.focus(); - await shownPromise; + await popupBy(() => uname.focus()); - shownPromise = promiseACShown(); - synthesizeKey("KEY_Tab"); // popup on the password field should open upon focus - let results = await shownPromise; + // popup on the password field should open upon focus + let results = await popupBy(() => synthesizeKey("KEY_Tab")); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -69,7 +66,7 @@ add_task(async function test_two_logins() { add_task(async function test_zero_logins() { uname.focus(); - let shownPromise = promiseACShown().then(() => ok(false, "Should not have shown")); + let shownPromise = popupBy().then(() => ok(false, "Should not have shown")); // Popup on the password field should NOT automatically open upon focus when there are no saved logins. synthesizeKey("KEY_Tab"); // focus the password field SimpleTest.requestFlakyTimeout("Giving a chance for the unexpected popup to show"); @@ -83,7 +80,7 @@ add_task(async function test_zero_logins() { checkLoginForm(uname, "", pword, ""); info("arrow down should still open the popup"); - autocompleteItems = await openAutocompletePopup(); + autocompleteItems = await popupByArrowDown(); checkAutoCompleteResults(autocompleteItems, [], window.location.host, "Check only footer is displayed."); checkLoginForm(uname, "", pword, ""); }); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_sandboxed.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_sandboxed.html index 112027ecbc25..37b4df02501f 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_sandboxed.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_sandboxed.html @@ -59,7 +59,7 @@ add_task(async function test_no_autofill() { }); add_task(async function test_autocomplete_warning_no_logins() { - const autocompleteItems = await openAutocompletePopup(pword); + const { items } = await openPopupOn(pword); let popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); @@ -67,7 +67,7 @@ add_task(async function test_autocomplete_warning_no_logins() { let expectedMenuItems = [ "This connection is not secure. Logins entered here could be compromised. Learn More", ]; - checkAutoCompleteResults(autocompleteItems, expectedMenuItems, hostname, "Check all menuitems are displayed correctly."); + checkAutoCompleteResults(items, expectedMenuItems, hostname, "Check all menuitems are displayed correctly."); checkLoginForm(uname, "", pword, ""); }); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html index b246a576f2fb..4778ef63fff6 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html @@ -144,7 +144,7 @@ async function testResultOfTabInteractions(testData) { SpecialPowers.wrap(uname).setUserInput(""); info("Placing focus in the password field"); - const shownPromise = promiseACShown(); + const shownPromise = popupBy(); pword.focus(); await synthesizeKey("KEY_Tab", { shiftKey: true }); // blur pw, focus un await new Promise(resolve => SimpleTest.executeSoon(resolve)); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html b/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html index 5677a5964073..9c31fff5587e 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html @@ -85,11 +85,11 @@ add_task(async function test_reopened_after_edit_not_matching_saved() { await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { this.content.document.getElementById("form-basic-username").value = "nam"; }); - let shownPromise = promiseACShown(); - await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { - this.content.document.getElementById("form-basic-username").focus(); + await popupBy(async () => { + await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { + this.content.document.getElementById("form-basic-username").focus(); + }); }); - await shownPromise; await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { this.content.document.getElementById("form-basic-submit").focus(); }); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_basic_form_honor_autocomplete_off.html b/toolkit/components/passwordmgr/test/mochitest/test_basic_form_honor_autocomplete_off.html index 7cac3a36a66f..ccb991f2746a 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_basic_form_honor_autocomplete_off.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_basic_form_honor_autocomplete_off.html @@ -86,9 +86,7 @@ async function autoCompleteFieldsFromFirstMatch(form) { // trigger autocomplete from the username field await SimpleTest.promiseFocus(form.ownerGlobal); let uname = form.querySelector("[name='uname']"); - let shownPromise = promiseACShown(); - uname.focus(); - await shownPromise; + await popupBy(() => uname.focus()); let formFilled = promiseFormsProcessedInSameProcess(); await synthesizeKey("KEY_ArrowDown"); // open diff --git a/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html b/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html index a063ea0a874c..a162fcd3ab6d 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html @@ -59,10 +59,10 @@ add_task(async function test_empty_first_entry() { restoreForm(); let popupState = await getPopupState(); is(popupState.open, false, "Check popup is initially closed"); - const autocompleteItems = await openAutocompletePopup(); + const { items } = await openPopupOn(uname); popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected"); - checkAutoCompleteResults(autocompleteItems, ["name", "Name", "USER"], "example.com", "initial"); + checkAutoCompleteResults(items, ["name", "Name", "USER"], "example.com", "initial"); // Check first entry let index0Promise = notifySelectedIndex(0); @@ -76,7 +76,7 @@ add_task(async function test_empty_first_entry() { add_task(async function test_empty_second_entry() { restoreForm(); - await openAutocompletePopup(); + await openPopupOn(uname); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second synthesizeKey("KEY_Enter"); @@ -86,7 +86,7 @@ add_task(async function test_empty_second_entry() { add_task(async function test_empty_third_entry() { restoreForm(); - await openAutocompletePopup(); + await openPopupOn(uname); synthesizeKey("KEY_ArrowDown"); // first synthesizeKey("KEY_ArrowDown"); // second synthesizeKey("KEY_ArrowDown"); // third @@ -97,8 +97,7 @@ add_task(async function test_empty_third_entry() { add_task(async function test_preserve_matching_username_case() { restoreForm(); - uname.value = "user"; - await openAutocompletePopup(); + await openPopupOn(uname, { inputValue: "user" }); // Check that we don't clobber user-entered text when tabbing away // (even with no autocomplete entry selected) diff --git a/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html b/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html index b098447af838..8fcb9df6f6da 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html @@ -64,7 +64,7 @@ add_task(async function test_form1_warning_entry() { await SimpleTest.promiseFocus(window); // Trigger autocomplete popup restoreForm(); - await openAutocompletePopup(); + await popupBy(); let popupState = await getPopupState(); is(popupState.open, true, "Check popup is opened"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_munged_values.html b/toolkit/components/passwordmgr/test/mochitest/test_munged_values.html index 06f407172952..c14bef003b75 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_munged_values.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_munged_values.html @@ -266,7 +266,7 @@ add_task(async function test_no_autofill_munged_username_matching_password() { }); // we shouldn't get the save password doorhanger... - let popupShownPromise = promiseNoUnexpectedPopupShown(); + let popupShownPromise = noPopupBy(); // Check data sent via PasswordManager:onFormSubmit let processedPromise = getSubmitMessage(); @@ -329,7 +329,7 @@ add_task(async function test_autofill_munged_username_matching_password() { }); // we shouldn't get the save/update password doorhanger as it didn't change - let popupShownPromise = promiseNoUnexpectedPopupShown(); + let popupShownPromise = noPopupBy(); // Check data sent via PasswordManager:onFormSubmit let processedPromise = getSubmitMessage(); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html b/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html index 94dba51b9dda..2db691b1bf2e 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html @@ -107,7 +107,7 @@ async function userOpenAutocompleteOnForm1(autoFillInsecureForms) { ["signon.autofillForms.http", autoFillInsecureForms], ]}); await reinitializeForm(1); - const autocompleteItems = await openAutocompletePopup(); + const autocompleteItems = await popupBy(); const popupState = await getPopupState(); is(popupState.selectedIndex, -1, "Check no entries are selected upon opening"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_username_focus.html b/toolkit/components/passwordmgr/test/mochitest/test_username_focus.html index 3d9ccadabb22..cdd71d69ddc7 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_username_focus.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_username_focus.html @@ -113,44 +113,32 @@ add_setup(async () => { add_task(async function test_autofilled() { let usernameField = getFormElementByName("-autofilled", "uname"); info("Username and password already filled so don't show autocomplete"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); removeFocus(); usernameField.value = "testuser"; info("Focus when we don't have an exact match"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); add_task(async function test_autofilled_prefilled_un() { let usernameField = getFormElementByName("-autofilled-prefilled-un", "uname"); info("Username and password already filled so don't show autocomplete"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); removeFocus(); usernameField.value = "testuser"; info("Focus when we don't have an exact match"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); add_task(async function test_autofilled_focused_dynamic() { let usernameField = getFormElementByName("-autofilled-focused-dynamic", "uname"); let passwordField = getFormElementByName("-autofilled-focused-dynamic", "pword"); info("Username and password will be filled while username focused"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); info("triggering autofill"); - noPopupPromise = promiseNoUnexpectedPopupShown(); - passwordField.type = "password"; - await noPopupPromise; + await noPopupBy(() => passwordField.type = "password"); let popupState = await getPopupState(); is(popupState.open, false, "Check popup is closed"); @@ -158,9 +146,7 @@ add_task(async function test_autofilled_focused_dynamic() { removeFocus(); passwordField.value = "test"; info("Focus when we don't have an exact match"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); // Begin testing forms that have multiple saved logins @@ -168,66 +154,48 @@ add_task(async function test_autofilled_focused_dynamic() { add_task(async function test_multiple() { let usernameField = getFormElementByName("-multiple", "uname"); info("Fields not filled due to multiple so autocomplete upon focus"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); add_task(async function test_multiple_dynamic() { let usernameField = getFormElementByName("-multiple-dynamic", "uname"); let passwordField = getFormElementByName("-multiple-dynamic", "pword"); info("Fields not filled but username is focused upon marking so open"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); info("triggering _fillForm code"); - let shownPromise = promiseACShown(); - passwordField.type = "password"; - await shownPromise; + await popupBy(() => passwordField.type = "password"); }); add_task(async function test_multiple_prefilled_un1() { let usernameField = getFormElementByName("-multiple-prefilled-un1", "uname"); info("Username and password already filled so don't show autocomplete"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); removeFocus(); usernameField.value = "testuser"; info("Focus when we don't have an exact match"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); add_task(async function test_multiple_prefilled_un2() { let usernameField = getFormElementByName("-multiple-prefilled-un2", "uname"); info("Username and password already filled so don't show autocomplete"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); removeFocus(); usernameField.value = "testuser"; info("Focus when we don't have an exact match"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); add_task(async function test_multiple_prefilled_focused_dynamic() { let usernameField = getFormElementByName("-multiple-prefilled-focused-dynamic", "uname"); let passwordField = getFormElementByName("-multiple-prefilled-focused-dynamic", "pword"); info("Username and password will be filled while username focused"); - let noPopupPromise = promiseNoUnexpectedPopupShown(); - usernameField.focus(); - await noPopupPromise; + await noPopupBy(() => usernameField.focus()); info("triggering autofill"); - noPopupPromise = promiseNoUnexpectedPopupShown(); - passwordField.type = "password"; - await noPopupPromise; + await noPopupBy(() => passwordField.type = "password"); let popupState = await getPopupState(); is(popupState.open, false, "Check popup is closed"); @@ -235,9 +203,7 @@ add_task(async function test_multiple_prefilled_focused_dynamic() { removeFocus(); passwordField.value = "test"; info("Focus when we don't have an exact match"); - let shownPromise = promiseACShown(); - usernameField.focus(); - await shownPromise; + await popupBy(() => usernameField.focus()); }); diff --git a/toolkit/components/satchel/test/parent_utils.js b/toolkit/components/satchel/test/parent_utils.js index 2a47cc6ede73..2f07e11444e8 100644 --- a/toolkit/components/satchel/test/parent_utils.js +++ b/toolkit/components/satchel/test/parent_utils.js @@ -66,8 +66,8 @@ var ParentUtils = { ); }, - checkRowCount(expectedCount, expectedFirstValue = null) { - ContentTaskUtils.waitForCondition(() => { + async checkRowCount(expectedCount, expectedFirstValue = null) { + await ContentTaskUtils.waitForCondition(() => { // This may be called before gAutocompletePopup has initialised // which causes it to throw try { @@ -80,23 +80,17 @@ var ParentUtils = { } catch (e) { return false; } - }, "Waiting for row count change: " + expectedCount + " First value: " + expectedFirstValue).then( - () => { - let results = this.getMenuEntries(); - sendAsyncMessage("gotMenuChange", { results }); - } - ); + }, `Waiting for row count change to ${expectedCount}, first value: ${expectedFirstValue}.`); + return this.getMenuEntries(); }, - checkSelectedIndex(expectedIndex) { - ContentTaskUtils.waitForCondition(() => { - return ( + async checkSelectedIndex(expectedIndex) { + await ContentTaskUtils.waitForCondition( + () => gAutocompletePopup.popupOpen && - gAutocompletePopup.selectedIndex === expectedIndex - ); - }, "Checking selected index").then(() => { - sendAsyncMessage("gotSelectedIndex"); - }); + gAutocompletePopup.selectedIndex === expectedIndex, + "Checking selected index" + ); }, // Tests using this function need to flip pref for exceptional use of @@ -175,14 +169,13 @@ addMessageListener("countEntries", ({ name, value }) => { addMessageListener( "waitForMenuChange", - ({ expectedCount, expectedFirstValue }) => { - ParentUtils.checkRowCount(expectedCount, expectedFirstValue); - } + ({ expectedCount, expectedFirstValue }) => + ParentUtils.checkRowCount(expectedCount, expectedFirstValue) ); -addMessageListener("waitForSelectedIndex", ({ expectedIndex }) => { - ParentUtils.checkSelectedIndex(expectedIndex); -}); +addMessageListener("waitForSelectedIndex", ({ expectedIndex }) => + ParentUtils.checkSelectedIndex(expectedIndex) +); addMessageListener("waitForMenuEntryTest", ({ index, statement }) => { ParentUtils.testMenuEntry(index, statement); }); diff --git a/toolkit/components/satchel/test/satchel_common.js b/toolkit/components/satchel/test/satchel_common.js index a105013feb58..3b2d8c81efd9 100644 --- a/toolkit/components/satchel/test/satchel_common.js +++ b/toolkit/components/satchel/test/satchel_common.js @@ -136,36 +136,16 @@ function updateFormHistory(changes, then = null) { }); } -function notifyMenuChanged(expectedCount, expectedFirstValue, then = null) { - return new Promise(resolve => { - gChromeScript.sendAsyncMessage("waitForMenuChange", { - expectedCount, - expectedFirstValue, - }); - gChromeScript.addMessageListener("gotMenuChange", function changed({ - results, - }) { - gChromeScript.removeMessageListener("gotMenuChange", changed); - gLastAutoCompleteResults = results; - if (then) { - then(results); - } - resolve(results); - }); - }); +async function notifyMenuChanged(expectedCount, expectedFirstValue) { + gLastAutoCompleteResults = await gChromeScript.sendQuery( + "waitForMenuChange", + { expectedCount, expectedFirstValue } + ); + return gLastAutoCompleteResults; } -function notifySelectedIndex(expectedIndex, then = null) { - return new Promise(resolve => { - gChromeScript.sendAsyncMessage("waitForSelectedIndex", { expectedIndex }); - gChromeScript.addMessageListener("gotSelectedIndex", function changed() { - gChromeScript.removeMessageListener("gotSelectedIndex", changed); - if (then) { - then(); - } - resolve(); - }); - }); +function notifySelectedIndex(expectedIndex) { + return gChromeScript.sendQuery("waitForSelectedIndex", { expectedIndex }); } function testMenuEntry(index, statement) { @@ -202,55 +182,44 @@ function listenForUnexpectedPopupShown() { }; } -async function promiseNoUnexpectedPopupShown() { - gPopupShownExpected = false; - listenForUnexpectedPopupShown(); - SimpleTest.requestFlakyTimeout( - "Giving a chance for an unexpected popupshown to occur" - ); - await new Promise(resolve => setTimeout(resolve, 1000)); -} - -/** - * Resolve at the next popupshown event for the autocomplete popup - * - * @returns {Promise} with the results - */ -function promiseACShown() { +async function popupBy(triggerFn) { gPopupShownExpected = true; - return new Promise(resolve => { + const promise = new Promise(resolve => { gPopupShownListener = ({ results }) => { gPopupShownExpected = false; resolve(results); }; }); + if (triggerFn) { + triggerFn(); + } + return promise; } -async function popupAfterArrowDown() { - const promise = promiseACShown(); - synthesizeKey("KEY_Escape"); // in case popup is already open - synthesizeKey("KEY_ArrowDown"); - await promise; +async function noPopupBy(triggerFn) { + gPopupShownExpected = false; + listenForUnexpectedPopupShown(); + SimpleTest.requestFlakyTimeout( + "Giving a chance for an unexpected popupshown to occur" + ); + if (triggerFn) { + await triggerFn(); + } + await new Promise(resolve => setTimeout(resolve, 500)); } -async function noPopupAfterArrowDown() { - const promise = promiseNoUnexpectedPopupShown(); - synthesizeKey("KEY_Escape"); // in case popup is already open - synthesizeKey("KEY_ArrowDown"); - await promise; +async function popupByArrowDown() { + return popupBy(() => { + synthesizeKey("KEY_Escape"); // in case popup is already open + synthesizeKey("KEY_ArrowDown"); + }); } -/** - * Open autocomplete popup on a field (if it exists) and wait for it to be shown - * - * @param {HTMLInputElement} input - input field to open autocomplete popup on - * @returns {Promise} of autocomplete items shown - */ -function openAutocompletePopup(input) { - input?.focus(); - const promisePopupShown = promiseACShown(); - synthesizeKey("KEY_ArrowDown"); - return promisePopupShown; +async function noPopupByArrowDown() { + await noPopupBy(() => { + synthesizeKey("KEY_Escape"); // in case popup is already open + synthesizeKey("KEY_ArrowDown"); + }); } function checkACTelemetryEvent(actualEvent, input, augmentedExtra) { @@ -346,8 +315,8 @@ async function openPopupOn( : inputOrSelector; input.value = inputValue; input.focus(); - await (expectPopup ? popupAfterArrowDown() : noPopupAfterArrowDown()); - return input; + const items = await (expectPopup ? popupByArrowDown() : noPopupByArrowDown()); + return { input, items }; } satchelCommonSetup(); diff --git a/toolkit/components/satchel/test/test_bug_511615.html b/toolkit/components/satchel/test/test_bug_511615.html index 036aa1029e00..2d67c5468b00 100644 --- a/toolkit/components/satchel/test/test_bug_511615.html +++ b/toolkit/components/satchel/test/test_bug_511615.html @@ -20,8 +20,7 @@ Test for Form History Autocomplete Untrusted Events: Bug 511615 -
- -