summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /browser/extensions/formautofill/test/unit
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/extensions/formautofill/test/unit')
-rw-r--r--browser/extensions/formautofill/test/unit/head.js18
-rw-r--r--browser/extensions/formautofill/test/unit/test_autofillFormFields.js35
-rw-r--r--browser/extensions/formautofill/test/unit/test_getFormInputDetails.js18
-rw-r--r--browser/extensions/formautofill/test/unit/test_markAsAutofillField.js32
-rw-r--r--browser/extensions/formautofill/test/unit/test_onFormSubmitted.js712
-rw-r--r--browser/extensions/formautofill/test/unit/test_phoneNumber.js4
-rw-r--r--browser/extensions/formautofill/test/unit/test_previewFormFields.js2
-rw-r--r--browser/extensions/formautofill/test/unit/test_storage_tombstones.js8
-rw-r--r--browser/extensions/formautofill/test/unit/xpcshell.toml6
9 files changed, 65 insertions, 770 deletions
diff --git a/browser/extensions/formautofill/test/unit/head.js b/browser/extensions/formautofill/test/unit/head.js
index 2448c7efff..efb9a65c19 100644
--- a/browser/extensions/formautofill/test/unit/head.js
+++ b/browser/extensions/formautofill/test/unit/head.js
@@ -71,24 +71,6 @@ region-name-tw = Taiwan
L10nRegistry.getInstance().registerSources([mockSource]);
}
-/**
- * Mock the return value of Services.focus.elementIsFocusable
- * since a field's focusability can't be tested in a unit test.
- */
-(function ignoreAFieldsFocusability() {
- let stub = sinon.stub(Services, "focus").get(() => {
- return {
- elementIsFocusable() {
- return true;
- },
- };
- });
-
- registerCleanupFunction(() => {
- stub.restore();
- });
-})();
-
do_get_profile();
const EXTENSION_ID = "formautofill@mozilla.org";
diff --git a/browser/extensions/formautofill/test/unit/test_autofillFormFields.js b/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
index 49ffb0083a..be6b142195 100644
--- a/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
@@ -423,6 +423,39 @@ const TESTCASES = [
},
{
description:
+ "Form with hidden input and visible input that share the same autocomplete attribute",
+ document: `<form>
+ <input id="hidden-cc" autocomplete="cc-number" hidden>
+ <input id="hidden-cc-2" autocomplete="cc-number" style="display:none">
+ <input id="visible-cc" autocomplete="cc-number">
+ <input id="hidden-name" autocomplete="cc-name" hidden>
+ <input id="hidden-name-2" autocomplete="cc-name" style="display:none">
+ <input id="visible-name" autocomplete="cc-name">
+ <input id="cc-exp-month" autocomplete="cc-exp-month">
+ <input id="cc-exp-year" autocomplete="cc-exp-year">
+ </form>`,
+ focusedInputId: "visible-cc",
+ profileData: {
+ guid: "123",
+ "cc-number": "4111111111111111",
+ "cc-name": "test name",
+ "cc-exp-month": 6,
+ "cc-exp-year": 25,
+ },
+ expectedResult: {
+ guid: "123",
+ "visible-cc": "4111111111111111",
+ "visible-name": "test name",
+ "cc-exp-month": "06",
+ "cc-exp-year": "25",
+ "hidden-cc": "4111111111111111",
+ "hidden-cc-2": "4111111111111111",
+ "hidden-name": "test name",
+ "hidden-name-2": "test name",
+ },
+ },
+ {
+ description:
"Fill credit card fields in a form where the value property is being used as a placeholder for cardholder name",
document: `<form>
<input id="cc-number" autocomplete="cc-number">
@@ -862,7 +895,7 @@ function do_test(testcases, testFn) {
// Replace the internal decrypt method with OSKeyStore API,
// but don't pass the reauth parameter to avoid triggering
// reauth login dialog in these tests.
- let decryptHelper = async (cipherText, reauth) => {
+ let decryptHelper = async (cipherText, _reauth) => {
return OSKeyStore.decrypt(cipherText, false);
};
handler.collectFormFields();
diff --git a/browser/extensions/formautofill/test/unit/test_getFormInputDetails.js b/browser/extensions/formautofill/test/unit/test_getFormInputDetails.js
index 18bd18b74a..cfcae8935d 100644
--- a/browser/extensions/formautofill/test/unit/test_getFormInputDetails.js
+++ b/browser/extensions/formautofill/test/unit/test_getFormInputDetails.js
@@ -1,11 +1,8 @@
"use strict";
-var FormAutofillContent;
-add_task(async function () {
- ({ FormAutofillContent } = ChromeUtils.importESModule(
- "resource://autofill/FormAutofillContent.sys.mjs"
- ));
-});
+const { FormStateManager } = ChromeUtils.importESModule(
+ "resource://gre/modules/shared/FormStateManager.sys.mjs"
+);
const TESTCASES = [
{
@@ -168,15 +165,16 @@ TESTCASES.forEach(testcase => {
for (let i in testcase.targetInput) {
let input = doc.getElementById(testcase.targetInput[i]);
- FormAutofillContent.identifyAutofillFields(input);
- FormAutofillContent.updateActiveInput(input);
+ const fsm = new FormStateManager();
+ fsm.updateActiveInput(input);
+ fsm.identifyAutofillFields(input);
// Put the input element reference to `element` to make sure the result of
// `activeFieldDetail` contains the same input element.
testcase.expectedResult[i].input.elementWeakRef = new WeakRef(input);
inputDetailAssertion(
- FormAutofillContent.activeFieldDetail,
+ fsm.activeFieldDetail,
testcase.expectedResult[i].input
);
@@ -193,7 +191,7 @@ TESTCASES.forEach(testcase => {
formDetail.elementWeakRef = new WeakRef(doc.querySelector(queryString));
}
- FormAutofillContent.activeFormDetails.forEach((detail, index) => {
+ fsm.activeFormDetails.forEach((detail, index) => {
inputDetailAssertion(detail, formDetails[index]);
});
}
diff --git a/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js b/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js
index 72960fcaf2..a170ff59a9 100644
--- a/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js
+++ b/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js
@@ -1,5 +1,9 @@
"use strict";
+const { FormStateManager } = ChromeUtils.importESModule(
+ "resource://gre/modules/shared/FormStateManager.sys.mjs"
+);
+
const TESTCASES = [
{
description: "Form containing 8 fields with autocomplete attribute.",
@@ -158,19 +162,6 @@ const TESTCASES = [
},
];
-let markedFieldId = [];
-
-var FormAutofillContent;
-add_setup(async () => {
- ({ FormAutofillContent } = ChromeUtils.importESModule(
- "resource://autofill/FormAutofillContent.sys.mjs"
- ));
-
- FormAutofillContent._markAsAutofillField = function (field) {
- markedFieldId.push(field.id);
- };
-});
-
TESTCASES.forEach(testcase => {
add_task(async function () {
info("Starting testcase: " + testcase.description);
@@ -179,17 +170,20 @@ TESTCASES.forEach(testcase => {
testcase.prefs.forEach(pref => SetPref(pref[0], pref[1]));
}
- markedFieldId = [];
-
- let doc = MockDocument.createTestDocument(
+ const doc = MockDocument.createTestDocument(
"http://localhost:8080/test/",
testcase.document
);
- let element = doc.getElementById(testcase.targetElementId);
- FormAutofillContent.identifyAutofillFields(element);
+ const element = doc.getElementById(testcase.targetElementId);
+
+ const fsm = new FormStateManager();
+ fsm.updateActiveInput(element);
+
+ const identifiedFields = fsm.identifyAutofillFields(element);
+ const identifiedFieldIds = identifiedFields.map(x => x.element.id);
Assert.deepEqual(
- markedFieldId,
+ identifiedFieldIds,
testcase.expectedResult,
"Check the fields were marked correctly."
);
diff --git a/browser/extensions/formautofill/test/unit/test_onFormSubmitted.js b/browser/extensions/formautofill/test/unit/test_onFormSubmitted.js
deleted file mode 100644
index 484112cc86..0000000000
--- a/browser/extensions/formautofill/test/unit/test_onFormSubmitted.js
+++ /dev/null
@@ -1,712 +0,0 @@
-"use strict";
-
-var FormAutofillContent;
-add_setup(async () => {
- ({ FormAutofillContent } = ChromeUtils.importESModule(
- "resource://autofill/FormAutofillContent.sys.mjs"
- ));
-});
-
-const DEFAULT_TEST_DOC = `<form id="form1">
- <input id="street-addr" autocomplete="street-address">
- <select id="address-level1" autocomplete="address-level1">
- <option value=""></option>
- <option value="AL">Alabama</option>
- <option value="AK">Alaska</option>
- <option value="AP">Armed Forces Pacific</option>
-
- <option value="ca">california</option>
- <option value="AR">US-Arkansas</option>
- <option value="US-CA">California</option>
- <option value="CA">California</option>
- <option value="US-AZ">US_Arizona</option>
- <option value="Ariz">Arizonac</option>
- </select>
- <input id="city" autocomplete="address-level2">
- <input id="country" autocomplete="country">
- <input id="email" autocomplete="email">
- <input id="tel" autocomplete="tel">
- <input id="cc-name" autocomplete="cc-name">
- <input id="cc-number" autocomplete="cc-number">
- <input id="cc-exp-month" autocomplete="cc-exp-month">
- <input id="cc-exp-year" autocomplete="cc-exp-year">
- <select id="cc-type">
- <option value="">Select</option>
- <option value="visa">Visa</option>
- <option value="mastercard">Master Card</option>
- <option value="amex">American Express</option>
- </select>
- <input id="submit" type="submit">
- </form>`;
-const TARGET_ELEMENT_ID = "street-addr";
-
-const TESTCASES = [
- {
- description:
- "Should not trigger address saving if the number of fields is less than 3",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "street-addr": "331 E. Evelyn Avenue",
- tel: "1-650-903-0800",
- },
- expectedResult: {
- formSubmission: false,
- },
- },
- {
- description: "Should not trigger credit card saving if number is empty",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "cc-name": "John Doe",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- },
- expectedResult: {
- formSubmission: false,
- },
- },
- {
- description:
- "Should not trigger credit card saving if there is more than one cc-number field but less than four fields",
- document: `<form id="form1">
- <input id="cc-type" autocomplete="cc-type">
- <input id="cc-name" autocomplete="cc-name">
- <input id="cc-number1" maxlength="4">
- <input id="cc-number2" maxlength="4">
- <input id="cc-number3" maxlength="4">
- <input id="cc-exp-month" autocomplete="cc-exp-month">
- <input id="cc-exp-year" autocomplete="cc-exp-year">
- <input id="submit" type="submit">
- </form>
- `,
- targetElementId: "cc-name",
- formValue: {
- "cc-name": "John Doe",
- "cc-number1": "3714",
- "cc-number2": "4963",
- "cc-number3": "5398",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "amex",
- },
- expectedResult: {
- formSubmission: false,
- },
- },
- {
- description: "Trigger address saving",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- tel: "1-650-903-0800",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "street-address": "331 E. Evelyn Avenue",
- "address-level1": "",
- "address-level2": "",
- country: "US",
- email: "",
- tel: "1-650-903-0800",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Trigger credit card saving",
- document: DEFAULT_TEST_DOC,
- targetElementId: "cc-type",
- formValue: {
- "cc-name": "John Doe",
- "cc-number": "5105105105105100",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "amex",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [],
- creditCard: [
- {
- guid: null,
- record: {
- "cc-name": "John Doe",
- "cc-number": "5105105105105100",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "amex",
- },
- untouchedFields: [],
- },
- ],
- },
- },
- },
- {
- description: "Trigger credit card saving using multiple cc-number fields",
- document: `<form id="form1">
- <input id="cc-type" autocomplete="cc-type">
- <input id="cc-name" autocomplete="cc-name">
- <input id="cc-number1" maxlength="4">
- <input id="cc-number2" maxlength="4">
- <input id="cc-number3" maxlength="4">
- <input id="cc-number4" maxlength="4">
- <input id="cc-exp-month" autocomplete="cc-exp-month">
- <input id="cc-exp-year" autocomplete="cc-exp-year">
- <input id="submit" type="submit">
- </form>`,
- targetElementId: "cc-type",
- formValue: {
- "cc-name": "John Doe",
- "cc-number1": "3714",
- "cc-number2": "4963",
- "cc-number3": "5398",
- "cc-number4": "431",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "amex",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [],
- creditCard: [
- {
- guid: null,
- record: {
- "cc-name": "John Doe",
- "cc-number": "371449635398431",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "amex",
- },
- untouchedFields: [],
- },
- ],
- },
- },
- },
- {
- description: "Trigger address and credit card saving",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- tel: "1-650-903-0800",
- "cc-name": "John Doe",
- "cc-number": "5105105105105100",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "visa",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "street-address": "331 E. Evelyn Avenue",
- "address-level1": "",
- "address-level2": "",
- country: "US",
- email: "",
- tel: "1-650-903-0800",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [
- {
- guid: null,
- record: {
- "cc-name": "John Doe",
- "cc-number": "5105105105105100",
- "cc-exp-month": 12,
- "cc-exp-year": 2000,
- "cc-type": "visa",
- },
- untouchedFields: [],
- },
- ],
- },
- },
- },
- {
- description: "Profile saved with trimmed string",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "street-addr": "331 E. Evelyn Avenue ",
- country: "US",
- tel: " 1-650-903-0800",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "street-address": "331 E. Evelyn Avenue",
- "address-level1": "",
- "address-level2": "",
- country: "US",
- email: "",
- tel: "1-650-903-0800",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Eliminate the field that is empty after trimmed",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- email: " ",
- tel: "1-650-903-0800",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "street-address": "331 E. Evelyn Avenue",
- "address-level1": "",
- "address-level2": "",
- country: "US",
- email: "",
- tel: "1-650-903-0800",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Save state with regular select option",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "CA",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "address-level1": "CA",
- "address-level2": "",
- "street-address": "331 E. Evelyn Avenue",
- country: "US",
- email: "",
- tel: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Save state with lowercase value",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "ca",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "address-level1": "CA",
- "address-level2": "",
- "street-address": "331 E. Evelyn Avenue",
- country: "US",
- email: "",
- tel: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Save state with a country code prefixed to the label",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "AR",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "address-level1": "AR",
- "address-level2": "",
- "street-address": "331 E. Evelyn Avenue",
- country: "US",
- email: "",
- tel: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Save state with a country code prefixed to the value",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "US-CA",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "address-level1": "CA",
- "address-level2": "",
- "street-address": "331 E. Evelyn Avenue",
- country: "US",
- email: "",
- tel: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description:
- "Save state with a country code prefixed to the value and label",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "US-AZ",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "address-level1": "AZ",
- "address-level2": "",
- "street-address": "331 E. Evelyn Avenue",
- country: "US",
- email: "",
- tel: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description:
- "Should save select label instead when failed to abbreviate the value",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "Ariz",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "address-level1": "Arizonac",
- "address-level2": "",
- "street-address": "331 E. Evelyn Avenue",
- country: "US",
- email: "",
- tel: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Shouldn't save select with multiple selections",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": ["AL", "AK", "AP"],
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- tel: "1-650-903-0800",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "street-address": "331 E. Evelyn Avenue",
- "address-level1": "",
- "address-level2": "",
- country: "US",
- tel: "1-650-903-0800",
- email: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
- {
- description: "Shouldn't save select with empty value",
- document: DEFAULT_TEST_DOC,
- targetElementId: TARGET_ELEMENT_ID,
- formValue: {
- "address-level1": "",
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- tel: "1-650-903-0800",
- },
- expectedResult: {
- formSubmission: true,
- records: {
- address: [
- {
- guid: null,
- record: {
- "street-address": "331 E. Evelyn Avenue",
- "address-level1": "",
- "address-level2": "",
- country: "US",
- tel: "1-650-903-0800",
- email: "",
- },
- untouchedFields: [],
- },
- ],
- creditCard: [],
- },
- },
- },
-];
-
-add_task(async function handle_invalid_form() {
- info("Starting testcase: Test an invalid form element");
- let doc = MockDocument.createTestDocument(
- "http://localhost:8080/test",
- DEFAULT_TEST_DOC
- );
- let fakeForm = doc.createElement("form");
- sinon.spy(FormAutofillContent, "_onFormSubmit");
-
- FormAutofillContent.formSubmitted(fakeForm, undefined, null);
- Assert.equal(FormAutofillContent._onFormSubmit.called, false);
- FormAutofillContent._onFormSubmit.restore();
-});
-
-add_task(async function autofill_disabled() {
- let doc = MockDocument.createTestDocument(
- "http://localhost:8080/test",
- DEFAULT_TEST_DOC
- );
- let form = doc.getElementById("form1");
- form.reset();
-
- let testcase = {
- "street-addr": "331 E. Evelyn Avenue",
- country: "US",
- tel: "+16509030800",
- "cc-number": "1111222233334444",
- };
- for (let key in testcase) {
- let input = doc.getElementById(key);
- input.value = testcase[key];
- }
-
- let element = doc.getElementById(TARGET_ELEMENT_ID);
- FormAutofillContent.identifyAutofillFields(element);
-
- sinon.stub(FormAutofillContent, "_onFormSubmit");
-
- // "_onFormSubmit" shouldn't be called if both "addresses" and "creditCards"
- // are disabled.
- Services.prefs.setBoolPref(
- "extensions.formautofill.addresses.enabled",
- false
- );
- Services.prefs.setBoolPref(
- "extensions.formautofill.creditCards.enabled",
- false
- );
- FormAutofillContent.formSubmitted(form, undefined, null);
- Assert.equal(FormAutofillContent._onFormSubmit.called, false);
- FormAutofillContent._onFormSubmit.resetHistory();
-
- // "_onFormSubmit" should be called as usual.
- Services.prefs.clearUserPref("extensions.formautofill.addresses.enabled");
- Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
-
- Services.prefs.setBoolPref(
- "extensions.formautofill.creditCards.enabled",
- true
- );
-
- FormAutofillContent.formSubmitted(form, undefined, null);
- Assert.equal(FormAutofillContent._onFormSubmit.called, true);
- Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
- Assert.notDeepEqual(
- FormAutofillContent._onFormSubmit.args[0][0].creditCard,
- []
- );
- FormAutofillContent._onFormSubmit.resetHistory();
-
- // "address" should be empty if "addresses" pref is disabled.
- Services.prefs.setBoolPref(
- "extensions.formautofill.addresses.enabled",
- false
- );
- FormAutofillContent.formSubmitted(form, undefined, null);
- Assert.equal(FormAutofillContent._onFormSubmit.called, true);
- Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
- Assert.notDeepEqual(
- FormAutofillContent._onFormSubmit.args[0][0].creditCard,
- []
- );
- FormAutofillContent._onFormSubmit.resetHistory();
- Services.prefs.clearUserPref("extensions.formautofill.addresses.enabled");
-
- // "creditCard" should be empty if "creditCards" pref is disabled.
- Services.prefs.setBoolPref(
- "extensions.formautofill.creditCards.enabled",
- false
- );
- FormAutofillContent.formSubmitted(form, undefined, null);
- Assert.deepEqual(FormAutofillContent._onFormSubmit.called, true);
- Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
- Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
- FormAutofillContent._onFormSubmit.resetHistory();
- Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
-
- FormAutofillContent._onFormSubmit.restore();
-});
-
-TESTCASES.forEach(testcase => {
- add_task(async function check_records_saving_is_called_correctly() {
- info("Starting testcase: " + testcase.description);
-
- Services.prefs.setBoolPref(
- "extensions.formautofill.creditCards.enabled",
- true
- );
- let doc = MockDocument.createTestDocument(
- "http://localhost:8080/test/",
- testcase.document
- );
- let form = doc.getElementById("form1");
- form.reset();
- for (let key in testcase.formValue) {
- let input = doc.getElementById(key);
- let value = testcase.formValue[key];
- if (ChromeUtils.getClassName(input) === "HTMLSelectElement" && value) {
- input.multiple = Array.isArray(value);
- [...input.options].forEach(option => {
- option.selected = value.includes(option.value);
- });
- } else {
- input.value = testcase.formValue[key];
- }
- }
- sinon.stub(FormAutofillContent, "_onFormSubmit");
-
- let element = doc.getElementById(testcase.targetElementId);
- FormAutofillContent.identifyAutofillFields(element);
- FormAutofillContent.formSubmitted(form, undefined, null);
-
- Assert.equal(
- FormAutofillContent._onFormSubmit.called,
- testcase.expectedResult.formSubmission,
- "Check expected onFormSubmit.called"
- );
- if (FormAutofillContent._onFormSubmit.called) {
- for (let ccRecord of FormAutofillContent._onFormSubmit.args[0][0]
- .creditCard) {
- delete ccRecord.flowId;
- }
- for (let addrRecord of FormAutofillContent._onFormSubmit.args[0][0]
- .address) {
- delete addrRecord.flowId;
- }
-
- Assert.deepEqual(
- FormAutofillContent._onFormSubmit.args[0][0],
- testcase.expectedResult.records
- );
- }
- FormAutofillContent._onFormSubmit.restore();
- Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
- });
-});
diff --git a/browser/extensions/formautofill/test/unit/test_phoneNumber.js b/browser/extensions/formautofill/test/unit/test_phoneNumber.js
index 1c1d67e166..133e54f6d7 100644
--- a/browser/extensions/formautofill/test/unit/test_phoneNumber.js
+++ b/browser/extensions/formautofill/test/unit/test_phoneNumber.js
@@ -7,10 +7,10 @@
var PhoneNumber, PhoneNumberNormalizer;
add_setup(async () => {
({ PhoneNumber } = ChromeUtils.importESModule(
- "resource://autofill/phonenumberutils/PhoneNumber.sys.mjs"
+ "resource://gre/modules/shared/PhoneNumber.sys.mjs"
));
({ PhoneNumberNormalizer } = ChromeUtils.importESModule(
- "resource://autofill/phonenumberutils/PhoneNumberNormalizer.sys.mjs"
+ "resource://gre/modules/shared/PhoneNumberNormalizer.sys.mjs"
));
});
diff --git a/browser/extensions/formautofill/test/unit/test_previewFormFields.js b/browser/extensions/formautofill/test/unit/test_previewFormFields.js
index 1b1a01860d..b5ca7e5dfc 100644
--- a/browser/extensions/formautofill/test/unit/test_previewFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_previewFormFields.js
@@ -152,7 +152,7 @@ function run_tests(testcases) {
// Replace the internal decrypt method with OSKeyStore API,
// but don't pass the reauth parameter to avoid triggering
// reauth login dialog in these tests.
- let decryptHelper = async (cipherText, reauth) => {
+ let decryptHelper = async (cipherText, _reauth) => {
return OSKeyStore.decrypt(cipherText, false);
};
handler.collectFormFields();
diff --git a/browser/extensions/formautofill/test/unit/test_storage_tombstones.js b/browser/extensions/formautofill/test/unit/test_storage_tombstones.js
index 584dac8043..d0365d8f11 100644
--- a/browser/extensions/formautofill/test/unit/test_storage_tombstones.js
+++ b/browser/extensions/formautofill/test/unit/test_storage_tombstones.js
@@ -109,7 +109,7 @@ add_storage_task(async function test_simple_synctombstone(storage, record) {
do_check_tombstone_record(tombstoneInDisk);
});
-add_storage_task(async function test_add_tombstone(storage, record) {
+add_storage_task(async function test_add_tombstone(storage, _record) {
info("Should be able to add a new tombstone");
let guid = await storage.add({ guid: "test-guid-1", deleted: true });
@@ -136,7 +136,7 @@ add_storage_task(async function test_add_tombstone(storage, record) {
add_storage_task(async function test_add_tombstone_without_guid(
storage,
- record
+ _record
) {
info("Should not be able to add a new tombstone without specifying the guid");
await Assert.rejects(storage.add({ deleted: true }), /Record missing GUID/);
@@ -164,7 +164,7 @@ add_storage_task(async function test_add_tombstone_existing_guid(
);
});
-add_storage_task(async function test_update_tombstone(storage, record) {
+add_storage_task(async function test_update_tombstone(storage, _record) {
info("Updating a tombstone should fail");
let guid = await storage.add({ guid: "test-guid-1", deleted: true });
await Assert.rejects(storage.update(guid, {}), /No matching record./);
@@ -172,7 +172,7 @@ add_storage_task(async function test_update_tombstone(storage, record) {
add_storage_task(async function test_remove_existing_tombstone(
storage,
- record
+ _record
) {
info("Removing a record that's already a tombstone should be a no-op");
let guid = await storage.add({
diff --git a/browser/extensions/formautofill/test/unit/xpcshell.toml b/browser/extensions/formautofill/test/unit/xpcshell.toml
index f63ac60e58..dccc27fa63 100644
--- a/browser/extensions/formautofill/test/unit/xpcshell.toml
+++ b/browser/extensions/formautofill/test/unit/xpcshell.toml
@@ -6,6 +6,9 @@ skip-if = [
firefox-appdir = "browser"
head = "head.js"
support-files = ["../fixtures/**"]
+prefs = [
+ "extensions.formautofill.test.ignoreVisibilityCheck=true",
+]
["test_activeStatus.js"]
@@ -98,9 +101,6 @@ skip-if = ["tsan"] # Times out, bug 1612707
["test_nameUtils.js"]
-["test_onFormSubmitted.js"]
-skip-if = ["tsan"] # Times out, bug 1612707
-
["test_parseAddressFormat.js"]
["test_parseStreetAddress.js"]