Bug 1823194 - Declutter toolkit/components/satchel/test/satchel_common.js API r=credential-management-reviewers,dimi

Differential Revision: https://phabricator.services.mozilla.com/D172931
This commit is contained in:
Sergey Galich 2023-03-20 15:31:21 +00:00
parent 754503b035
commit c831cb5d87
44 changed files with 391 additions and 647 deletions

View File

@ -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");

View File

@ -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() {
</form>`, {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");

View File

@ -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");

View File

@ -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() {
</form>`, {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, "");
});
</script>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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;
}

View File

@ -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");

View File

@ -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, "");
});

View File

@ -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, "");
});

View File

@ -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));

View File

@ -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();
});

View File

@ -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

View File

@ -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)

View File

@ -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");

View File

@ -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();

View File

@ -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");

View File

@ -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());
});
</script>
</pre>

View File

@ -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);
});

View File

@ -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();

View File

@ -20,8 +20,7 @@ Test for Form History Autocomplete Untrusted Events: Bug 511615
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<script>
/**
* Indicates the time to wait before checking that the state of the autocomplete
* popup, including whether it is open, has not changed in response to events.
@ -37,55 +36,33 @@ Test for Form History Autocomplete Untrusted Events: Bug 511615
*/
const POPUP_RESPONSE_WAIT_TIME_MS = 200;
SimpleTest.requestFlakyTimeout("Must ensure that an event does not happen.");
/**
* Checks that the popup does not open in response to the given function.
*
* @param {Function} triggerFn - function that triggers an event
* @returns {Promise}
*/
function expectPopupDoesNotOpen(triggerFn) {
const popupShown = promiseACShown();
triggerFn();
return Promise.race([
popupShown.then(() => Promise.reject("Popup opened unexpectedly.")),
new Promise(resolve => setTimeout(resolve, POPUP_RESPONSE_WAIT_TIME_MS)),
]);
}
/**
* Checks that the selected index in the popup still matches the given value.
*
* @param {number} expectedIndex
* @returns {Promise}
*/
function checkSelectedIndexAfterResponseTime(expectedIndex) {
return new Promise(resolve => {
async function checkSelectedIndexAfterResponseTime(expectedIndex) {
const popupState = await new Promise(resolve => {
setTimeout(() => getPopupState(resolve), POPUP_RESPONSE_WAIT_TIME_MS);
}).then(popupState => {
is(popupState.open, true, "Popup should still be open.");
is(popupState.selectedIndex, expectedIndex, "Selected index should match.");
});
is(popupState.open, true, "Popup should still be open.");
is(popupState.selectedIndex, expectedIndex, "Selected index should match.");
}
const input = getFormElementByName(1, "field1");
const input = document.querySelector("#form1 > input");
function doKeyUnprivileged(key) {
let keyName = "DOM_VK_" + key.toUpperCase();
const keyName = "DOM_VK_" + key.toUpperCase();
let keycode, charcode, alwaysval;
if (key.length == 1) {
keycode = 0;
charcode = key.charCodeAt(0);
alwaysval = charcode;
[keycode, charcode, alwaysval] = [0, key.charCodeAt(0), charcode];
} else {
keycode = KeyEvent[keyName];
[keycode, charcode, alwaysval] = [KeyEvent[keyName], 0, keycode];
if (!keycode) {
throw new Error("invalid keyname in test");
}
charcode = 0;
alwaysval = keycode;
}
const dnEvent = new KeyboardEvent("keydown", {
@ -161,13 +138,11 @@ add_task(async function test_untrusted_events_ignored() {
]) {
// We must wait for the entire timeout for each individual test, because the
// next event in the list might prevent the popup from opening.
await expectPopupDoesNotOpen(triggerFn);
await noPopupBy(triggerFn);
}
// A privileged key press will actually open the popup.
const promisePopupShown = promiseACShown();
synthesizeKey("KEY_ArrowDown");
await promisePopupShown;
await openPopupOn(input);
// The selected autocomplete item should not change from untrusted events.
for (let triggerFn of [
@ -179,7 +154,7 @@ add_task(async function test_untrusted_events_ignored() {
}
// A privileged key press will actually change the selected index.
const indexChanged = new Promise(resolve => notifySelectedIndex(0, resolve));
const indexChanged = notifySelectedIndex(0);
synthesizeKey("KEY_ArrowDown");
await indexChanged;
@ -198,10 +173,7 @@ add_task(async function test_untrusted_events_ignored() {
await checkSelectedIndexAfterResponseTime(0);
is(input.value, "", "The selected item should not have been used.");
}
input.blur(); // Close popup
});
</script>
</pre>
</body>
</html>

View File

@ -48,8 +48,7 @@ Form History Layout test: form field autocomplete: Bug 787624
</div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<script>
add_setup(async () => {
await updateFormHistory([
{ op: "remove" },
@ -59,22 +58,16 @@ add_setup(async () => {
});
add_task(async function test_popup_not_move_input() {
const input = getFormElementByName(1, "field1");
const input = document.querySelector("#form1 > input");
const rect = input.getBoundingClientRect();
input.focus();
const promisePopupShown = promiseACShown();
synthesizeKey("KEY_ArrowDown");
await promisePopupShown;
await openPopupOn(input);
const newRect = input.getBoundingClientRect();
is(newRect.left, rect.left,
"autocomplete popup does not disturb the input position");
is(newRect.top, rect.top,
"autocomplete popup does not disturb the input position");
isDeeply(
[newRect.left, newRect.top],
[rect.left, rect.top],
"popup does not disturb the input position");
});
</script>
</pre>
</body>
</html>

View File

@ -13,8 +13,7 @@
<button type="submit">Submit</button>
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<script>
add_setup(async () => {
const count = await countEntries(null, null);
@ -58,6 +57,5 @@ add_task(async function captureLimit() {
});
</script>
</pre>
</body>
</html>

View File

@ -21,22 +21,16 @@
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
const { TestUtils } = SpecialPowers.ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);
const input = document.getElementById("input");
<script>
add_task(async function test_dropdown_shown_when_type_attribute_changed() {
const input = document.getElementById("input");
input.addEventListener("click", () => input.setAttribute("type", "text"));
is(input.type, "button", "Input type is initially button.");
synthesizeMouseAtCenter(input, {button: input, type: "mousedown"}, window);
synthesizeMouseAtCenter(input, {button: input, type: "mouseup"}, window);
synthesizeMouseAtCenter(input, { button: input, type: "mousedown" }, window);
synthesizeMouseAtCenter(input, { button: input, type: "mouseup" }, window);
await SimpleTest.promiseWaitForCondition(() => input.type === "text", "Input type changed to text.");
@ -45,18 +39,15 @@ add_task(async function test_dropdown_shown_when_type_attribute_changed() {
// We decided to refer fixing this to a later bug, This is tracked in Bug 1788698.
// ok(input.matches(":focus-visible"), "Outer focus ring is shown.");
// We should wait until the next tick/frame, otherwise the popup is not shown.
await TestUtils.waitForTick();
const promisePopupShown = promiseACShown();
synthesizeKey("KEY_ArrowDown");
await promisePopupShown;
await openPopupOn(input);
isDeeply(getMenuEntries(), ["Mozilla", "Firefox", "Thunderbird"], "Datalist shown after changing input type from button to text.");
isDeeply(
getMenuEntries(),
["Mozilla", "Firefox", "Thunderbird"],
"Datalist shown after changing input type from button to text.");
input.removeEventListener("click", () => input.setAttribute("type", "text"));
});
</script>
</pre>
</body>
</html>

View File

@ -12,11 +12,8 @@
<option value="ab1">
<option value="ab2">
</datalist>
<pre id="test">
<script class="testbody">
<script>
const { TestUtils } = SpecialPowers.Cu.import("resource://testing-common/TestUtils.jsm");
const input = document.querySelector("input");
const datalist = document.querySelector("datalist");
const DATALIST_DATA = {
"a": ["a1", "a2", "ab1", "ab2"],
@ -25,16 +22,12 @@ const DATALIST_DATA = {
"abcd": ["abcd1", "abcd2", "abcde1", "abcde2", "abcde3"]
};
var resolvePopupShownListener;
registerPopupShownListener(() => resolvePopupShownListener());
function waitPopup() {
return new Promise(resolve => { resolvePopupShownListener = resolve; });
}
add_task(async function() {
const input = document.querySelector("input");
const datalist = document.querySelector("datalist");
async function inputHandler() {
let options = DATALIST_DATA[input.value] || [];
const options = DATALIST_DATA[input.value] || [];
await TestUtils.waitForTick();
@ -42,8 +35,8 @@ add_task(async function() {
datalist.firstChild.remove();
}
for (let option of options) {
let element = document.createElement("option");
for (const option of options) {
const element = document.createElement("option");
element.setAttribute("value", option);
datalist.appendChild(element);
}
@ -58,9 +51,7 @@ add_task(async function() {
synthesizeKey("b");
synthesizeKey("c");
is(input.value, "abc", "<input>'s value has to be abc for initial data");
synthesizeKey("KEY_ArrowDown");
await waitPopup();
await notifyMenuChanged(4);
let values = getMenuEntries();
is(values.length, 4, "expected count of datalist popup");
for (let i = 0; i < values.length; i++) {
@ -86,5 +77,4 @@ add_task(async function() {
input.removeEventListener("input", inputHandler);
});
</script>
</pre>
</html>

View File

@ -17,20 +17,17 @@
<option value="Secomundo"></option>
</datalist>
<script>
function oneTick() {
return new Promise(resolve => SimpleTest.executeSoon(resolve));
}
add_task(async function readonly() {
let input = await openPopupOn("input", { expectPopup: false });
const { input } = await openPopupOn("input", { expectPopup: false });
ok(input.readOnly, "Input should be readonly");
input.removeAttribute("readonly");
await oneTick();
await new Promise(resolve => SimpleTest.executeSoon(resolve));
// AttributeChanged takes control of the input again off a runnable...
ok(!input.readOnly, "Input should not be readonly");
is(document.activeElement, input, "Should still be focused");
input = await openPopupOn("input");
await openPopupOn(input);
assertAutocompleteItems("First", "Second", "Secomundo");
assertValueAfterKeys(
input,

View File

@ -29,7 +29,7 @@ host.attachShadow({ mode: "open" }).innerHTML = `
`;
add_task(async function fill_in_shadow() {
const input = await openPopupOn(host.shadowRoot.querySelector("input"));
const { input } = await openPopupOn(host.shadowRoot.querySelector("input"));
assertAutocompleteItems("First", "Second", "Secomundo");
assertValueAfterKeys(
input,
@ -38,7 +38,7 @@ add_task(async function fill_in_shadow() {
});
add_task(async function filter_and_fill_in_shadow() {
const input = await openPopupOn(host.shadowRoot.querySelector("input"));
const { input } = await openPopupOn(host.shadowRoot.querySelector("input"));
sendString("Sec");
await notifyMenuChanged(2);
assertAutocompleteItems("Second", "Secomundo");

View File

@ -36,7 +36,7 @@ add_setup(async () => {
});
add_task(async function datalist_with_caching() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertAutocompleteItems("Sec", "First", "Second", "Secomundo");
assertValueAfterKeys(
input,
@ -45,7 +45,7 @@ add_task(async function datalist_with_caching() {
});
add_task(async function filtering_datalist_with_caching() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
sendString("Sec");
await notifyMenuChanged(3);
assertAutocompleteItems("Sec", "Second", "Secomundo");

View File

@ -188,7 +188,7 @@ add_setup(async () => {
});
add_task(async function use_1st_item() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertAutocompleteItems("value1", "value2", "value3", "value4");
assertValueAfterKeys(input, "KEY_ArrowDown", "");
@ -196,7 +196,7 @@ add_task(async function use_1st_item() {
});
add_task(async function use_2nd_item() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -204,7 +204,7 @@ add_task(async function use_2nd_item() {
});
add_task(async function use_3rd_item() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -212,7 +212,7 @@ add_task(async function use_3rd_item() {
});
add_task(async function use_4th_item() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -220,7 +220,7 @@ add_task(async function use_4th_item() {
});
add_task(async function use_1st_item_wrap_around() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown",
@ -229,7 +229,7 @@ add_task(async function use_1st_item_wrap_around() {
});
add_task(async function use_last_item_via_arrow_up() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowUp", "KEY_Enter"],
@ -237,7 +237,7 @@ add_task(async function use_last_item_via_arrow_up() {
});
add_task(async function use_last_item_via_arrow_up_from_selected_1st() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowUp", "KEY_ArrowUp", "KEY_Enter"],
@ -245,7 +245,7 @@ add_task(async function use_last_item_via_arrow_up_from_selected_1st() {
});
add_task(async function test9() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowUp", "KEY_ArrowUp", "KEY_ArrowUp", "KEY_ArrowUp",
@ -254,7 +254,7 @@ add_task(async function test9() {
});
add_task(async function select_1st_item_without_autocomplete() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowRight"],
@ -262,7 +262,7 @@ add_task(async function select_1st_item_without_autocomplete() {
});
add_task(async function set_first_item_without_autocomplete() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowLeft"],
@ -270,7 +270,7 @@ add_task(async function set_first_item_without_autocomplete() {
});
add_task(async function use_1st_item_with_page_up() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_PageUp", "KEY_Enter"],
@ -278,7 +278,7 @@ add_task(async function use_1st_item_with_page_up() {
});
add_task(async function use_last_item_with_page_down() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_PageDown", "KEY_Enter"],
@ -288,7 +288,7 @@ add_task(async function use_last_item_with_page_down() {
add_task(async function delete_1st_item() {
assertAutocompleteItems("value1", "value2", "value3", "value4");
const input = await openPopupOn("#form1 input", { inputValue: "value" });
const { input } = await openPopupOn("#form1 > input", { inputValue: "value" });
synthesizeKey("KEY_ArrowDown");
// Tests that on OS X shift-backspace didn't delete the last character
@ -304,7 +304,7 @@ add_task(async function delete_1st_item() {
});
add_task(async function use_1st_item_of_3() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -312,7 +312,7 @@ add_task(async function use_1st_item_of_3() {
});
add_task(async function delete_2nd_item() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_ArrowDown");
deleteSelectedAutocompleteItem();
@ -324,7 +324,7 @@ add_task(async function delete_2nd_item() {
});
add_task(async function use_1st_item_of_2() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -332,7 +332,7 @@ add_task(async function use_1st_item_of_2() {
});
add_task(async function delete_last_item_of_2() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_ArrowDown");
deleteSelectedAutocompleteItem();
@ -344,7 +344,7 @@ add_task(async function delete_last_item_of_2() {
});
add_task(async function use_1st_item_of_1() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -352,7 +352,7 @@ add_task(async function use_1st_item_of_1() {
});
add_task(async function delete_only_item() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
synthesizeKey("KEY_ArrowDown");
deleteSelectedAutocompleteItem();
await notifyMenuChanged(0);
@ -361,7 +361,7 @@ add_task(async function delete_only_item() {
});
add_task(async function form2_fills() {
const input = await openPopupOn("#form2 input");
const { input } = await openPopupOn("#form2 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -383,7 +383,7 @@ add_task(async function form3_autocomplete_off() {
resolve();
}, false);
});
const input = await openPopupOn("#form3 input", { expectPopup: false });
const { input } = await openPopupOn("#form3 > input", { expectPopup: false });
await scroll;
// Ensure there's no autocomplete dropdown (autocomplete=off is present)
assertValueAfterKeys(
@ -393,7 +393,7 @@ add_task(async function form3_autocomplete_off() {
});
add_task(async function form4_autocomplete_off() {
const input = await openPopupOn("#form4 input", { expectPopup: false });
const { input } = await openPopupOn("#form4 > input", { expectPopup: false });
await notifyMenuChanged(0);
// Ensure there's no autocomplete dropdown (autocomplete=off is present)
@ -404,7 +404,7 @@ add_task(async function form4_autocomplete_off() {
});
add_task(async function filtering_form5() {
const input = await openPopupOn("#form5 input");
const { input } = await openPopupOn("#form5 > input");
sendChar("a");
await notifyMenuChanged(5);
assertAutocompleteItems("a", "aa", "aaz", "aa\xe6", "az");
@ -448,7 +448,7 @@ add_task(async function filtering_form5() {
});
add_task(async function filtering_form6_part1() {
await openPopupOn("#form6 input");
await openPopupOn("#form6 > input");
sendChar("a");
await notifyMenuChanged(3);
@ -464,7 +464,7 @@ add_task(async function filtering_form6_part1() {
});
add_task(async function filtering_form6_part2() {
await openPopupOn("#form6 input");
await openPopupOn("#form6 > input");
sendChar("b");
await notifyMenuChanged(1, "bc d\xe6");
assertAutocompleteItems("bc d\xe6");
@ -490,27 +490,27 @@ add_task(async function filtering_form6_part2() {
});
add_task(async function input_maxLength() {
let input = await openPopupOn("#form7 input");
let { input } = await openPopupOn("#form7 > input");
await notifyMenuChanged(4);
assertAutocompleteItems("1", "12", "123", "1234");
input.maxLength = 4;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
await notifyMenuChanged(4);
assertAutocompleteItems("1", "12", "123", "1234");
input.maxLength = 3;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
await notifyMenuChanged(3);
assertAutocompleteItems("1", "12", "123");
input.maxLength = 2;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
await notifyMenuChanged(2);
assertAutocompleteItems("1", "12");
input.maxLength = 1;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
await notifyMenuChanged(1);
assertAutocompleteItems("1");
@ -524,21 +524,21 @@ add_task(async function input_maxLength() {
});
add_task(async function input_maxLength_with_character_typed() {
let input = await openPopupOn("#form7 input");
let { input } = await openPopupOn("#form7 > input");
sendChar("1");
await notifyMenuChanged(4);
assertAutocompleteItems("1", "12", "123", "1234");
input.maxLength = 3;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
assertAutocompleteItems("1", "12", "123");
input.maxLength = 2;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
assertAutocompleteItems("1", "12");
input.maxLength = 1;
input = await openPopupOn("#form7 input");
input = (await openPopupOn("#form7 > input")).input;
assertAutocompleteItems("1");
input.maxLength = 0;
@ -550,14 +550,14 @@ add_task(async function input_maxLength_with_character_typed() {
for (const formId of ["form8", "form9", "form10", "form11"]) {
add_named_task(formId, async () => {
const input = await openPopupOn(`#${formId} input`);
const { input } = await openPopupOn(`#${formId} > input`);
assertAutocompleteItems("value");
assertValueAfterKeys(input, ["KEY_ArrowDown", "KEY_Enter"], "value");
});
}
add_task(async function form12() {
const input = await openPopupOn("#form12 input");
const { input } = await openPopupOn("#form12 > input");
assertAutocompleteItems("42");
assertValueAfterKeys(
input,
@ -566,7 +566,7 @@ add_task(async function form12() {
});
add_task(async function form14() {
const input = await openPopupOn("#form14 input", { expectPopup: false });
const { input } = await openPopupOn("#form14 > input", { expectPopup: false });
await notifyMenuChanged(0);
// type=date with it's own control frame does not have a dropdown menu
assertAutocompleteItems();
@ -574,7 +574,7 @@ add_task(async function form14() {
});
add_task(async function form15() {
const input = await openPopupOn("#form15 input", { expectPopup: false });
const { input } = await openPopupOn("#form15 > input", { expectPopup: false });
await notifyMenuChanged(0);
// type=time with it's own control frame does not have a dropdown menu
assertAutocompleteItems();
@ -582,7 +582,7 @@ add_task(async function form15() {
});
add_task(async function form16() {
const input = await openPopupOn("#form16 input", { expectPopup: false });
const { input } = await openPopupOn("#form16 > input", { expectPopup: false });
await notifyMenuChanged(0);
// type=range does not have a dropdown menu
assertAutocompleteItems();
@ -591,7 +591,7 @@ add_task(async function form16() {
});
add_task(async function form17() {
const input = await openPopupOn("#form17 input", { expectPopup: false });
const { input } = await openPopupOn("#form17 > input", { expectPopup: false });
await notifyMenuChanged(0);
// type=color does not have a dropdown menu
assertAutocompleteItems();
@ -600,7 +600,7 @@ add_task(async function form17() {
});
add_task(async function form18() {
const input = await openPopupOn("#form18 input");
const { input } = await openPopupOn("#form18 > input");
assertAutocompleteItems("2016-08");
assertValueAfterKeys(
input,
@ -609,7 +609,7 @@ add_task(async function form18() {
});
add_task(async function form19() {
const input = await openPopupOn("#form19 input");
const { input } = await openPopupOn("#form19 > input");
assertAutocompleteItems("2016-W32");
assertValueAfterKeys(
input,
@ -618,7 +618,7 @@ add_task(async function form19() {
});
add_task(async function form20() {
const input = await openPopupOn("#form20 input", { expectPopup: false });
const { input } = await openPopupOn("#form20 > input", { expectPopup: false });
await notifyMenuChanged(0);
// type=datetime-local with it's own control frame does not have a dropdown menu
assertAutocompleteItems();
@ -627,7 +627,7 @@ add_task(async function form20() {
add_task(async function input_event_fired() {
await addEntry("field1", "value1");
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
let beforeInputFired = false;
input.addEventListener("beforeinput", (e) => {
@ -667,7 +667,7 @@ add_task(async function input_event_fired() {
});
add_task(async function cancelling_beforeinput_cancels_autocompletion() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
await SpecialPowers.pushPrefEnv({
set: [["dom.input_event.allow_to_cancel_set_user_input", true]],
});
@ -686,7 +686,7 @@ add_task(async function cancelling_beforeinput_cancels_autocompletion() {
});
add_task(async function no_autocomplete_for_searchbar_history() {
await openPopupOn("#form13 input", { expectPopup: false });
await openPopupOn("#form13 > input", { expectPopup: false });
await notifyMenuChanged(0);
assertAutocompleteItems();
});

View File

@ -32,7 +32,7 @@ add_setup(async () => {
});
add_task(async function input_events() {
const input = await openPopupOn("input[name=field1]");
const { input } = await openPopupOn("input[name=field1]");
synthesizeKey("KEY_Escape");
let inputFired = false;
@ -48,7 +48,7 @@ add_task(async function input_events() {
});
add_task(async function input_events_for_valid_selection() {
const input = await openPopupOn("input[name=field1]");
const { input } = await openPopupOn("input[name=field1]");
let inputFired = false;
input.addEventListener("input", e => {
@ -63,7 +63,7 @@ add_task(async function input_events_for_valid_selection() {
});
add_task(async function input_events_for_invalid_selection() {
const input = await openPopupOn("input[name=field1]");
const { input } = await openPopupOn("input[name=field1]");
let inputFired = false;
input.addEventListener("input", e => {

View File

@ -83,12 +83,12 @@ add_setup(async () => {
});
add_task(async function no_changes_when_opening_popup(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(input, [], "");
});
add_task(async function use_1st_entry() {
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertAutocompleteItems("historyvalue", "PASS1", "PASS2", "final");
assertValueAfterKeys(
input,
@ -97,7 +97,7 @@ add_task(async function use_1st_entry() {
});
add_task(async function use_2nd_entry(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -105,7 +105,7 @@ add_task(async function use_2nd_entry(){
});
add_task(async function use_3rd_entry(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -113,7 +113,7 @@ add_task(async function use_3rd_entry(){
});
add_task(async function use_4th_entry(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -121,7 +121,7 @@ add_task(async function use_4th_entry(){
});
add_task(async function delete_1st_entry(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertValueAfterKeys(input, "KEY_ArrowDown", "");
deleteSelectedAutocompleteItem();
await notifyMenuChanged(3);
@ -129,13 +129,13 @@ add_task(async function delete_1st_entry(){
});
add_task(async function can_use_next_item_after_deletion(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
assertAutocompleteItems("PASS1", "PASS2", "final");
assertValueAfterKeys(input, ["KEY_ArrowDown", "KEY_Enter"], "Google");
});
add_task(async function autocomplete_on_datalist_with_cached_results(){
const input = await openPopupOn("#form1 input");
const { input } = await openPopupOn("#form1 > input");
sendString("PAS");
await notifyMenuChanged(2);
sendString("S1");
@ -147,7 +147,7 @@ add_task(async function autocomplete_on_datalist_with_cached_results(){
});
add_task(async function fills_with_autocomplete_off_on_form(){
const input = await openPopupOn("#form4 input");
const { input } = await openPopupOn("#form4 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -156,7 +156,7 @@ add_task(async function fills_with_autocomplete_off_on_form(){
});
add_task(async function use_1st_entry_with_autocomplete_off_on_form(){
const input = await openPopupOn("#form4 input");
const { input } = await openPopupOn("#form4 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -164,7 +164,7 @@ add_task(async function use_1st_entry_with_autocomplete_off_on_form(){
});
add_task(async function use_2nd_entry_with_autocomplete_off_on_form(){
const input = await openPopupOn("#form4 input");
const { input } = await openPopupOn("#form4 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -172,7 +172,7 @@ add_task(async function use_2nd_entry_with_autocomplete_off_on_form(){
});
add_task(async function use_3rd_entry_with_autocomplete_off_on_form(){
const input = await openPopupOn("#form4 input");
const { input } = await openPopupOn("#form4 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -180,7 +180,7 @@ add_task(async function use_3rd_entry_with_autocomplete_off_on_form(){
});
add_task(async function fills_with_autocomplete_off_on_input(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -189,7 +189,7 @@ add_task(async function fills_with_autocomplete_off_on_input(){
});
add_task(async function use_1st_entry_with_autocomplete_off_on_input(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -197,7 +197,7 @@ add_task(async function use_1st_entry_with_autocomplete_off_on_input(){
});
add_task(async function use_2nd_entry_with_autocomplete_off_on_input(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -205,7 +205,7 @@ add_task(async function use_2nd_entry_with_autocomplete_off_on_input(){
});
add_task(async function use_3rd_entry_with_autocomplete_off_on_input(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_ArrowDown", "KEY_ArrowDown", "KEY_Enter"],
@ -218,7 +218,7 @@ add_task(async function remove_item_from_datalist(){
//
// Removing the second element while on the first then going down and
// push enter. Value should be one from the third suggesion.
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
synthesizeKey("KEY_ArrowDown");
const datalist = document.getElementById("suggest");
const toRemove = datalist.children[1];
@ -234,7 +234,7 @@ add_task(async function remove_item_from_datalist(){
});
add_task(async function add_item_to_datalist(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
const datalist = document.getElementById("suggest");
// Adding an attribute after the first one while on the first then going
@ -256,10 +256,10 @@ add_task(async function change_datalist_option_value(){
await notifyMenuChanged(0);
// Change the first element value attribute.
let prevValue = datalist.children[0].value;
const prevValue = datalist.children[0].value;
datalist.children[0].value = "foo";
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
assertValueAfterKeys(
input,
["KEY_ArrowDown", "KEY_Enter"],
@ -274,7 +274,7 @@ add_task(async function change_datalist_option_text_content(){
const prevValue = datalist.children[0].getAttribute("value");
datalist.children[0].removeAttribute("value");
datalist.children[0].textContent = "foobar";
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
assertValueAfterKeys(
input,
@ -286,7 +286,7 @@ add_task(async function change_datalist_option_text_content(){
});
add_task(async function filters_with_1st_letter(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
sendString("f");
assertValueAfterKeys(
input,
@ -295,7 +295,7 @@ add_task(async function filters_with_1st_letter(){
});
add_task(async function filters_with_letter_in_the_middle(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
sendString("in");
assertValueAfterKeys(
input,
@ -304,7 +304,7 @@ add_task(async function filters_with_letter_in_the_middle(){
});
add_task(async function no_filtering_when_mozNoFilter(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
input.setAttribute("mozNoFilter", "true");
sendString("f");
await notifyMenuChanged(3);
@ -316,7 +316,7 @@ add_task(async function no_filtering_when_mozNoFilter(){
});
add_task(async function input_events(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
let beforeInputFired = false;
input.addEventListener("beforeinput", (event) => {
@ -352,7 +352,7 @@ add_task(async function input_events(){
});
add_task(async function cancelled_beforeinput_event(){
const input = await openPopupOn("#form3 input");
const { input } = await openPopupOn("#form3 > input");
await SpecialPowers.pushPrefEnv({
set: [["dom.input_event.allow_to_cancel_set_user_input", true]],
});
@ -371,7 +371,7 @@ add_task(async function cancelled_beforeinput_event(){
});
add_task(async function attempt_to_delete_datalist_entries(){
const input = await openPopupOn("#form5 input");
const { input } = await openPopupOn("#form5 > input");
assertAutocompleteItems("history1", "history2", "PASS1", "PASS2", "final");
assertValueAfterKeys(
@ -405,7 +405,7 @@ for (const input of document
async () => {
input.focus();
is(document.activeElement, input, "Input is focused.");
await (expectPopup ? popupAfterArrowDown() : noPopupAfterArrowDown());
await (expectPopup ? popupByArrowDown() : noPopupByArrowDown());
}
);
}

View File

@ -263,8 +263,7 @@
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<script>
/* eslint-disable complexity */
const ccNumbers = {
@ -352,11 +351,7 @@ async function checkSubmitSaves(formNumber, inputName, interactiveValue, savedVa
is(historyEntriesCount, 1, form.getAttribute("purpose"));
}
// This will prevent endless loop of tests
for (const form of document.forms) {
/* eslint-disable-next-line mozilla/balanced-listeners */
form.addEventListener("submit", e => e.preventDefault());
}
preventSubmitOnForms();
add_setup(async () => {
await updateFormHistory([
@ -403,7 +398,7 @@ add_task(async function form7_does_not_save() {
add_task(async function form8_does_not_save() {
// Form 8 has an input with no name or input attribute.
let input = SpecialPowers.wrap(document.getElementById("form8").elements[0]);
const input = SpecialPowers.wrap(document.getElementById("form8").elements[0]);
is(input.type, "text", "checking we got unidentified input");
input.setUserInput("dontSaveThis");
await checkSubmitDoesNotSave(8);
@ -443,7 +438,7 @@ add_task(async function form13_does_not_save() {
});
add_task(async function form14_does_not_save() {
let input = SpecialPowers.wrap(document.getElementById("form14").elements[0]);
const input = SpecialPowers.wrap(document.getElementById("form14").elements[0]);
input.type = "password";
input.setUserInput("dontSaveThis");
// Set it back to type=text to simulate a password visibility toggle.
@ -599,6 +594,5 @@ add_task(async function form109_saves() {
});
</script>
</pre>
</body>
</html>

View File

@ -12,7 +12,7 @@
<!-- normal, basic form -->
<form id="form1" onsubmit="return false;">
<input list="suggest" type="text" name="field1" id="field1">
<input list="suggest" type="text" name="field1" id="field1">
<button type="submit">Submit</button>
<datalist id="suggest">
<option value="Mozilla">
@ -23,46 +23,33 @@
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
const input = document.getElementById("field1");
<script>
add_setup(async () => {
await new Promise(resolve => updateFormHistory([
await updateFormHistory([
{ op: "add", fieldname: "field1", value: "Mozilla" },
{ op: "add", fieldname: "field1", value: "Firefox" },
{ op: "add", fieldname: "field1", value: "Relay" },
], resolve));
]);
});
add_task(async function test_all_entries_are_unique_and_ordered() {
await triggerAutofillAndCheckEntriesValue("",["Relay", "Mozilla", "Firefox", "Relay is awesome"]);
await triggerAutofillAndCheckEntriesValue("",["Relay", "Mozilla", "Firefox", "Relay is awesome"]);
});
add_task(async function test_duplicate_entries_are_shown_once() {
await triggerAutofillAndCheckEntriesValue("f", ["Firefox"]);
await triggerAutofillAndCheckEntriesValue("f", ["Firefox"]);
});
add_task(async function test_non_duplicate_entries_are_shown_once() {
await triggerAutofillAndCheckEntriesValue("rel",["Relay", "Relay is awesome"]);
await triggerAutofillAndCheckEntriesValue("rel",["Relay", "Relay is awesome"]);
});
async function triggerAutofillAndCheckEntriesValue(inputValue, expectedValues) {
SpecialPowers.wrap(input).setUserInput(inputValue);
input.focus();
const promisePopupShown = promiseACShown();
synthesizeKey("KEY_ArrowDown");
await promisePopupShown;
await openPopupOn("#form1 > input", { inputValue });
isDeeply(getMenuEntries(), expectedValues, "Matching deduplicated autocomplete list entries with expected values.");
input.blur(); // Close popup
}
</script>
</pre>
</body>
</html>

View File

@ -35,7 +35,7 @@ add_setup(async () => {
add_task(async function datalist_with_caching() {
const kSetUserInputCancelable = SpecialPowers.getBoolPref("dom.input_event.allow_to_cancel_set_user_input");
const input = await openPopupOn("input[name=field1]");
const { input } = await openPopupOn("input[name=field1]");
synthesizeKey("KEY_Escape");
let beforeInputFired = false;
@ -60,7 +60,7 @@ add_task(async function datalist_with_caching() {
ok(beforeInputFired, "'beforeinput' event fired at typing 'e'");
ok(inputFired, "'input' event fired at typing 'e'");
await promiseACShown();
await notifyMenuChanged(2);
inputFired = false;
beforeInputFired = false;
input.addEventListener("beforeinput", e => {
@ -91,7 +91,7 @@ add_task(async function datalist_with_caching() {
inputFired = false;
beforeInputFired = false;
synthesizeKey("KEY_Backspace");
await promiseACShown();
await notifyMenuChanged(2);
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_ArrowDown");
input.addEventListener("beforeinput", e => {

View File

@ -32,39 +32,7 @@
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/**
* Indicates the time to wait before checking that the state of the autocomplete
* popup, including whether it is open, has not changed in response to events.
*
* Manual testing on a fast machine revealed that 80ms was still unreliable,
* while 100ms detected a simulated failure reliably. Unfortunately, this means
* that to take into account slower machines we should use a larger value.
*
* Note that if a machine takes more than this time to show the popup, this
* would not cause a failure, conversely the machine would not be able to detect
* whether the test should have failed. In other words, this use of timeouts is
* never expected to cause intermittent failures with test automation.
*/
const POPUP_RESPONSE_WAIT_TIME_MS = 200;
SimpleTest.requestFlakyTimeout("Must ensure that an event does not happen.");
/**
* Checks that the popup does not open in response to the given function.
*
* @param {Function} triggerFn - function that triggers an event
* @returns {Promise}
*/
function expectPopupDoesNotOpen(triggerFn) {
const popupShown = promiseACShown();
triggerFn();
return Promise.race([
popupShown.then(() => Promise.reject("Popup opened unexpectedly.")),
new Promise(resolve => setTimeout(resolve, POPUP_RESPONSE_WAIT_TIME_MS)),
]);
}
<script>
add_setup(async () => {
await SpecialPowers.pushPrefEnv({set: [["signon.rememberSignons", false]]});
@ -72,10 +40,10 @@ add_setup(async () => {
is(window.location.protocol, "https:", "This test must run on HTTPS");
// Now that rememberSignons is false, create the password fields.
getFormElementByName(1, "field1").type = "password";
getFormElementByName(2, "field1").type = "password";
document.querySelector("#form1 > input").type = "password";
document.querySelector("#form2 > input").type = "password";
await new Promise(resolve => updateFormHistory([
await updateFormHistory([
{ op: "remove" },
{ op: "add", fieldname: "field1", value: "value1" },
{ op: "add", fieldname: "field1", value: "value2" },
@ -86,11 +54,11 @@ add_setup(async () => {
{ op: "add", fieldname: "field1", value: "value7" },
{ op: "add", fieldname: "field1", value: "value8" },
{ op: "add", fieldname: "field1", value: "value9" },
], resolve));
]);
});
add_task(async function test_secure_noFormHistoryOrWarning() {
const input = getFormElementByName(1, "field1");
const input = document.querySelector("#form1 input");
// The autocomplete popup should not open under any circumstances on
// type=password with password manager disabled.
@ -103,30 +71,19 @@ add_task(async function test_secure_noFormHistoryOrWarning() {
() => sendString("v "),
() => synthesizeKey("KEY_Backspace"),
]) {
ok(true, "Testing: " + triggerFn.toString());
info("Testing: " + triggerFn.toString());
// We must wait for the entire timeout for each individual test, because the
// next event in the list might prevent the popup from opening.
await expectPopupDoesNotOpen(triggerFn);
await noPopupBy(triggerFn);
}
input.blur();
});
add_task(async function test_insecure_focusWarning() {
// Form 2 has an insecure action so should show the warning even if password manager is disabled.
const input = getFormElementByName(2, "field1");
input.focus();
const promisePopupShown = promiseACShown();
synthesizeKey("KEY_ArrowDown");
await promisePopupShown;
await openPopupOn("#form2 > input");
ok(getMenuEntries()[0].includes("Logins entered here could be compromised"),
"Check warning is first");
input.blur(); // Close popup.
});
</script>
</pre>
</body>
</html>

View File

@ -20,8 +20,7 @@ Test for Popup Direction
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<script>
add_setup(async () => {
await updateFormHistory([
@ -32,22 +31,14 @@ add_setup(async () => {
});
add_task(async function test_popup_direction() {
let input = getFormElementByName(1, "field1");
for (let direction of ["ltr", "rtl"]) {
for (const direction of ["ltr", "rtl"]) {
document.getElementById("content").style.direction = direction;
await openAutocompletePopup(input);
let popupState = await getPopupState();
await openPopupOn("#form1 > input");
const popupState = await getPopupState();
is(popupState.direction, direction, "Direction should match.");
// Close the popup.
input.blur();
}
});
</script>
</pre>
</body>
</html>

View File

@ -19,11 +19,7 @@ Form History test: Test for events while the form history popup is open
</form>
</div>
<pre id="test">
<script class="testbody">
var form = document.getElementById("form1");
var input = getFormElementByName(1, "field1");
var expectedValue = "value1";
<script>
add_setup(async () => {
await updateFormHistory([
@ -32,43 +28,37 @@ add_setup(async () => {
]);
});
function handleEnter(evt) {
if (evt.keyCode != KeyEvent.DOM_VK_RETURN) {
return;
}
info("RETURN received for phase: " + evt.eventPhase);
if (input.value == expectedValue) {
ok(true, "RETURN should be received when the popup is closed");
is(input.value, expectedValue, "Check input value when enter is pressed the 2nd time");
info("form should submit with the default handler");
} else {
ok(false, "RETURN keypress shouldn't have been received when a popup item is selected");
}
}
add_task(async function popupEnterEvent() {
const form = document.querySelector("#form1");
const input = form.querySelector("input");
const expectedValue = "value1";
function handleEnter(e) {
if (e.keyCode != KeyEvent.DOM_VK_RETURN) {
return;
}
info("RETURN received for phase: " + e.eventPhase);
if (input.value == expectedValue) {
ok(true, "RETURN should be received when the popup is closed");
is(input.value, expectedValue, "Check input value when enter is pressed the 2nd time");
info("form should submit with the default handler");
} else {
ok(false, "RETURN keypress shouldn't have been received when a popup item is selected");
}
}
const submitTested = new Promise(resolve => {
SpecialPowers.addSystemEventListener(input, "keypress", handleEnter, true);
form.addEventListener("submit", evt => {
evt.preventDefault();
form.addEventListener("submit", e => {
e.preventDefault();
is(input.value, expectedValue, "Check input value in the submit handler");
SpecialPowers.removeSystemEventListener(input, "keypress", handleEnter, true);
resolve();
}, { once: true });
});
const autocompleteShown = promiseACShown();
// Focus the input before adjusting.value so that the caret goes to the end
// (since OS X doesn't show the dropdown otherwise).
input.focus();
input.value = "value";
input.focus();
synthesizeKey("KEY_ArrowDown");
await autocompleteShown;
await openPopupOn(input, { inputValue: "value" });
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter"); // select the first entry in the popup
synthesizeKey("KEY_Enter"); // try to submit the form with the filled value
@ -76,6 +66,5 @@ add_task(async function popupEnterEvent() {
});
</script>
</pre>
</body>
</html>

View File

@ -19,12 +19,7 @@ Form History test: Test for keydown handler submitting the form
</form>
</div>
<pre id="test">
<script class="testbody">
var form = document.getElementById("form1");
var input = getFormElementByName(1, "field1");
var expectedValue = "value1";
var beforeInputFired = false;
<script>
add_setup(async () => {
await updateFormHistory([
@ -34,6 +29,10 @@ add_setup(async () => {
});
add_task(async function submitOnKeydownEnter() {
const form = document.querySelector("#form1");
const input = form.querySelector("input");
const expectedValue = "value1";
let beforeInputFired = false;
const submitTested = new Promise(resolve => {
function handleBeforeInput(aEvent) {
@ -56,23 +55,18 @@ add_task(async function submitOnKeydownEnter() {
'getTargetRanges() of "beforeinput" event should return empty array');
}
function handleInput(aEvent) {
function handleInput(e) {
info("Input");
ok(beforeInputFired, '"beforeinput" event should have been fired');
is(input.value, expectedValue, "Check input value");
ok(aEvent instanceof InputEvent,
ok(e instanceof InputEvent,
'"input" event should be dispatched with InputEvent interface');
is(aEvent.cancelable, false,
'"input" event should be never cancelable');
is(aEvent.bubbles, true,
'"input" event should always bubble');
is(aEvent.inputType, "insertReplacementText",
'inputType of "input" event should be "insertReplacementText"');
is(aEvent.data, expectedValue,
`data of "input" event should be "${expectedValue}"`);
is(aEvent.dataTransfer, null,
'dataTransfer of "input" event should be null');
is(aEvent.getTargetRanges().length, 0,
is(e.cancelable, false, '"input" event should be never cancelable');
is(e.bubbles, true, '"input" event should always bubble');
is(e.inputType, "insertReplacementText", 'inputType of "input" event');
is(e.data, expectedValue, "data of input event");
is(e.dataTransfer, null, 'dataTransfer of "input" event');
is(e.getTargetRanges().length, 0,
'getTargetRanges() of "input" event should return empty array');
removeEventListeners();
resolve();
@ -101,16 +95,7 @@ add_task(async function submitOnKeydownEnter() {
}, { once: true });
});
const autocompleteShown = promiseACShown();
// Focus the input before adjusting.value so that the caret goes to the end
// (since OS X doesn't show the dropdown otherwise).
input.focus();
input.value = "value";
input.focus();
synthesizeKey("KEY_ArrowDown");
await autocompleteShown;
await openPopupOn(input, { inputValue: "value" });
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter"); // select the first entry in the popup
@ -119,6 +104,5 @@ add_task(async function submitOnKeydownEnter() {
});
</script>
</pre>
</body>
</html>