diff --git a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js index d38c96cbdfc4..79762803d8d5 100644 --- a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js +++ b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js @@ -142,6 +142,26 @@ function checkUnmodifiedForm(formNum) { } } +/** + * @param {Function} [aFilterFn = undefined] Function to filter out irrelevant submissions. + * @return {Promise} resolving when a relevant form submission was processed. + */ +function getSubmitMessage(aFilterFn = undefined) { + info("getSubmitMessage"); + return new Promise((resolve, reject) => { + PWMGR_COMMON_PARENT.addMessageListener("formSubmissionProcessed", function processed(...args) { + if (aFilterFn && !aFilterFn(...args)) { + // This submission isn't the one we're waiting for. + return; + } + + info("got formSubmissionProcessed"); + PWMGR_COMMON_PARENT.removeMessageListener("formSubmissionProcessed", processed); + resolve(...args); + }); + }); +} + function registerRunTests() { return new Promise(resolve => { function onDOMContentLoaded() { diff --git a/toolkit/components/passwordmgr/test/mochitest/test_formless_submit.html b/toolkit/components/passwordmgr/test/mochitest/test_formless_submit.html index 9a8d01ee8c9a..b064d83a5ff0 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_formless_submit.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_formless_submit.html @@ -129,17 +129,6 @@ const TESTCASES = [ }, ]; -function getSubmitMessage() { - info("getSubmitMessage"); - return new Promise((resolve, reject) => { - PWMGR_COMMON_PARENT.addMessageListener("formSubmissionProcessed", function processed(...args) { - info("got formSubmissionProcessed"); - PWMGR_COMMON_PARENT.removeMessageListener("formSubmissionProcessed", processed); - resolve(...args); - }); - }); -} - add_task(async function test() { let count = 0; let loginFrame = document.getElementById("loginFrame"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_formless_submit_navigation.html b/toolkit/components/passwordmgr/test/mochitest/test_formless_submit_navigation.html index 63f282835f26..b838b1eddf1e 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_formless_submit_navigation.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_formless_submit_navigation.html @@ -138,26 +138,6 @@ const TESTCASES = [ }, ]; -/** - * @param {Function} [aFilterFn = undefined] Function to filter out irrelevant submissions. - * @return {Promise} resolving when a relevant form submission was processed. - */ -function getSubmitMessage(aFilterFn = undefined) { - info("getSubmitMessage"); - return new Promise((resolve, reject) => { - PWMGR_COMMON_PARENT.addMessageListener("formSubmissionProcessed", function processed(...args) { - if (aFilterFn && !aFilterFn(...args)) { - // This submission isn't the one we're waiting for. - return; - } - - info("got formSubmissionProcessed"); - PWMGR_COMMON_PARENT.removeMessageListener("formSubmissionProcessed", processed); - resolve(...args); - }); - }); -} - function filterFormSubmissions(data) { return data.newPasswordField.value != "ignore-form-submission"; } diff --git a/toolkit/components/passwordmgr/test/mochitest/test_munged_username.html b/toolkit/components/passwordmgr/test/mochitest/test_munged_username.html index 4c18a4ed6991..3fe42dfa8143 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_munged_username.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_munged_username.html @@ -129,20 +129,6 @@ const TESTCASES = [ }, ]; -/** - * @return {Promise} resolving when form submission was processed. - */ -function getSubmitMessage() { - info("getSubmitMessage"); - return new Promise((resolve, reject) => { - PWMGR_COMMON_PARENT.addMessageListener("formSubmissionProcessed", function processed(...args) { - info("got formSubmissionProcessed"); - PWMGR_COMMON_PARENT.removeMessageListener("formSubmissionProcessed", processed); - resolve(...args); - }); - }); -} - add_task(async function test_new_logins() { for (let tc of TESTCASES) { info("Starting testcase: " + JSON.stringify(tc)); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_one_doorhanger_per_un_pw.html b/toolkit/components/passwordmgr/test/mochitest/test_one_doorhanger_per_un_pw.html index 6ffa5110b7cd..fdd6d3a6adff 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_one_doorhanger_per_un_pw.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_one_doorhanger_per_un_pw.html @@ -12,17 +12,6 @@
diff --git a/toolkit/components/passwordmgr/test/mochitest/test_onsubmit_value_change.html b/toolkit/components/passwordmgr/test/mochitest/test_onsubmit_value_change.html index 1904366e62e0..3d52e330bd19 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_onsubmit_value_change.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_onsubmit_value_change.html @@ -12,17 +12,6 @@ Login Manager test: input value change right after onsubmit event diff --git a/toolkit/components/passwordmgr/test/mochitest/test_password_length.html b/toolkit/components/passwordmgr/test/mochitest/test_password_length.html index 90a82e3b1074..9a92a85bd865 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_password_length.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_password_length.html @@ -77,19 +77,6 @@ const TESTCASES = [ }, ]; -/** - * @return {Promise} resolving when form submission was processed. - */ -function getSubmitMessage() { - return new Promise((resolve, reject) => { - PWMGR_COMMON_PARENT.addMessageListener("formSubmissionProcessed", function processed(...args) { - info("got formSubmissionProcessed"); - PWMGR_COMMON_PARENT.removeMessageListener("formSubmissionProcessed", processed); - resolve(...args); - }); - }); -} - add_task(async function test_password_lengths() { for (let tc of TESTCASES) { info("Starting testcase: " + tc.testName + ", " + JSON.stringify([tc.pword1, tc.pword2]));