summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/mochitest/formautofill_common.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/extensions/formautofill/test/mochitest/formautofill_common.js')
-rw-r--r--browser/extensions/formautofill/test/mochitest/formautofill_common.js45
1 files changed, 37 insertions, 8 deletions
diff --git a/browser/extensions/formautofill/test/mochitest/formautofill_common.js b/browser/extensions/formautofill/test/mochitest/formautofill_common.js
index 6cdf9ca86b..dab2d58b4a 100644
--- a/browser/extensions/formautofill/test/mochitest/formautofill_common.js
+++ b/browser/extensions/formautofill/test/mochitest/formautofill_common.js
@@ -2,6 +2,10 @@
/* import-globals-from ../../../../../testing/mochitest/tests/SimpleTest/EventUtils.js */
/* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */
/* eslint-disable no-unused-vars */
+// Despite a use of `spawnChrome` and thus ChromeUtils, we can't use isInstance
+// here as it gets used in plain mochitests which don't have the ChromeOnly
+// APIs for it.
+/* eslint-disable mozilla/use-isInstance */
"use strict";
@@ -14,6 +18,10 @@ const { FormAutofillUtils } = SpecialPowers.ChromeUtils.importESModule(
"resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
);
+const { OSKeyStore } = SpecialPowers.ChromeUtils.importESModule(
+ "resource://gre/modules/OSKeyStore.sys.mjs"
+);
+
async function sleep(ms = 500, reason = "Intentionally wait for UI ready") {
SimpleTest.requestFlakyTimeout(reason);
await new Promise(resolve => setTimeout(resolve, ms));
@@ -80,8 +88,9 @@ function clickOnElement(selector) {
SimpleTest.executeSoon(() => element.click());
}
-// The equivalent helper function to getAdaptedProfiles in FormAutofillHandler.jsm that
-// transforms the given profile to expected filled profile.
+// The equivalent helper function to getAdaptedProfiles in
+// FormAutofillSection.sys.mjs that transforms the given profile to expected
+// filled profile.
function _getAdaptedProfile(profile) {
const adaptedProfile = Object.assign({}, profile);
@@ -270,12 +279,18 @@ async function onStorageChanged(type) {
});
}
-function checkMenuEntries(expectedValues, isFormAutofillResult = true) {
+function makeAddressLabel({ primary, secondary, status }) {
+ return JSON.stringify({
+ primary,
+ secondary,
+ status,
+ ariaLabel: primary + " " + secondary + " " + status,
+ });
+}
+
+function checkMenuEntries(expectedValues, extraRows = 1) {
let actualValues = getMenuEntries();
- // Expect one more item would appear at the bottom as the footer if the result is from form autofill.
- let expectedLength = isFormAutofillResult
- ? expectedValues.length + 1
- : expectedValues.length;
+ let expectedLength = expectedValues.length + extraRows;
is(actualValues.length, expectedLength, " Checking length of expected menu");
for (let i = 0; i < expectedValues.length; i++) {
@@ -346,7 +361,21 @@ async function canTestOSKeyStoreLogin() {
}
async function waitForOSKeyStoreLogin(login = false) {
- await invokeAsyncChromeTask("FormAutofillTest:OSKeyStoreLogin", { login });
+ // Need to fetch this from the parent in order for it to be correct.
+ let isOSAuthEnabled = await SpecialPowers.spawnChrome([], () => {
+ // Need to re-import this because we're running in the parent.
+ // eslint-disable-next-line no-shadow
+ const { FormAutofillUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
+ );
+
+ return FormAutofillUtils.getOSAuthEnabled(
+ FormAutofillUtils.AUTOFILL_CREDITCARDS_REAUTH_PREF
+ );
+ });
+ if (isOSAuthEnabled) {
+ await invokeAsyncChromeTask("FormAutofillTest:OSKeyStoreLogin", { login });
+ }
}
function patchRecordCCNumber(record) {