--- a/browser/extensions/formautofill/test/unit/test_createRecords.js
+++ b/browser/extensions/formautofill/test/unit/test_createRecords.js
@@ -21,81 +21,84 @@ const TESTCASES = [
"given-name": "John",
"organization": "*".repeat(200),
"address-level1": "*".repeat(201),
"country": "US",
"cc-number": "1111222233334444",
"cc-name": "*".repeat(201),
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "*".repeat(200),
"address-level1": "",
"country": "US",
- },
- creditCard: {
+ }],
+ creditCard: [{
"cc-number": "1111222233334444",
"cc-name": "",
- },
+ }],
},
},
{
description: "Don't create address record if filled data is less than 3",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="country" autocomplete="country">
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
},
expectedRecord: {
- address: undefined,
+ address: [],
+ creditCard: [],
},
},
{
description: "\"country\" using @autocomplete shouldn't be identified aggressively",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="country" autocomplete="country">
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
- },
+ }],
+ creditCard: [],
},
},
{
description: "\"country\" using heuristics should be identified aggressively",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="country" name="country">
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "Mozilla",
"country": "US",
- },
+ }],
+ creditCard: [],
},
},
{
description: "\"tel\" related fields should be concatenated",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="tel-country-code" autocomplete="tel-country-code">
@@ -103,21 +106,22 @@ const TESTCASES = [
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
"tel-country-code": "+1",
"tel-national": "1234567890",
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "Mozilla",
"tel": "+11234567890",
- },
+ }],
+ creditCard: [],
},
},
{
description: "\"tel\" should be removed if it's too short",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="country" autocomplete="country">
@@ -125,22 +129,23 @@ const TESTCASES = [
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
"tel": "1234",
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
"tel": "",
- },
+ }],
+ creditCard: [],
},
},
{
description: "\"tel\" should be removed if it's too long",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="country" autocomplete="country">
@@ -148,22 +153,23 @@ const TESTCASES = [
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
"tel": "1234567890123456",
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
"tel": "",
- },
+ }],
+ creditCard: [],
},
},
{
description: "\"tel\" should be removed if it contains invalid characters",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="organization" autocomplete="organization">
<input id="country" autocomplete="country">
@@ -171,38 +177,40 @@ const TESTCASES = [
</form>`,
formValue: {
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
"tel": "12345###!!!",
},
expectedRecord: {
- address: {
+ address: [{
"given-name": "John",
"organization": "Mozilla",
"country": "United States",
"tel": "",
- },
+ }],
+ creditCard: [],
},
},
{
description: "All name related fields should be counted as 1 field only.",
document: `<form>
<input id="given-name" autocomplete="given-name">
<input id="family-name" autocomplete="family-name">
<input id="organization" autocomplete="organization">
</form>`,
formValue: {
"given-name": "John",
"family-name": "Doe",
"organization": "Mozilla",
},
expectedRecord: {
- address: undefined,
+ address: [],
+ creditCard: [],
},
},
{
description: "All telephone related fields should be counted as 1 field only.",
document: `<form>
<input id="tel-country-code" autocomplete="tel-country-code">
<input id="tel-area-code" autocomplete="tel-area-code">
<input id="tel-local" autocomplete="tel-local">
@@ -210,83 +218,158 @@ const TESTCASES = [
</form>`,
formValue: {
"tel-country-code": "+1",
"tel-area-code": "123",
"tel-local": "4567890",
"organization": "Mozilla",
},
expectedRecord: {
- address: undefined,
+ address: [],
+ creditCard: [],
},
},
{
description: "A credit card form with the value of cc-number, cc-exp, and cc-name.",
document: `<form>
<input id="cc-number" autocomplete="cc-number">
<input id="cc-name" autocomplete="cc-name">
<input id="cc-exp" autocomplete="cc-exp">
</form>`,
formValue: {
"cc-number": "4444000022220000",
"cc-name": "Foo Bar",
"cc-exp": "2022-06",
},
expectedRecord: {
- creditCard: {
+ address: [],
+ creditCard: [{
"cc-number": "4444000022220000",
"cc-name": "Foo Bar",
"cc-exp": "2022-06",
- },
+ }],
},
},
{
description: "A credit card form with cc-number value only.",
document: `<form>
<input id="cc-number" autocomplete="cc-number">
</form>`,
formValue: {
"cc-number": "4444000022220000",
},
expectedRecord: {
- creditCard: {
+ address: [],
+ creditCard: [{
"cc-number": "4444000022220000",
- },
+ }],
},
},
{
description: "A credit card form must have cc-number value.",
document: `<form>
<input id="cc-number" autocomplete="cc-number">
<input id="cc-name" autocomplete="cc-name">
<input id="cc-exp" autocomplete="cc-exp">
</form>`,
formValue: {
"cc-number": "",
"cc-name": "Foo Bar",
"cc-exp": "2022-06",
},
expectedRecord: {
- creditCard: undefined,
+ address: [],
+ creditCard: [],
},
},
{
description: "A credit card form must have cc-number field.",
document: `<form>
<input id="cc-name" autocomplete="cc-name">
<input id="cc-exp" autocomplete="cc-exp">
</form>`,
formValue: {
"cc-name": "Foo Bar",
"cc-exp": "2022-06",
},
expectedRecord: {
- creditCard: undefined,
+ address: [],
+ creditCard: [],
},
},
+ {
+ description: "A form with multiple sections",
+ document: `<form>
+ <input id="given-name" autocomplete="given-name">
+ <input id="organization" autocomplete="organization">
+ <input id="country" autocomplete="country">
+
+ <input id="given-name-shipping" autocomplete="shipping given-name">
+ <input id="family-name-shipping" autocomplete="shipping family-name">
+ <input id="organization-shipping" autocomplete="shipping organization">
+ <input id="country-shipping" autocomplete="shipping country">
+
+ <input id="given-name-billing" autocomplete="billing given-name">
+ <input id="organization-billing" autocomplete="billing organization">
+ <input id="country-billing" autocomplete="billing country">
+
+ <input id="cc-number-section-one" autocomplete="section-one cc-number">
+ <input id="cc-name-section-one" autocomplete="section-one cc-name">
+
+ <input id="cc-number-section-two" autocomplete="section-two cc-number">
+ <input id="cc-name-section-two" autocomplete="section-two cc-name">
+ <input id="cc-exp-section-two" autocomplete="section-two cc-exp">
+ </form>`,
+ formValue: {
+ "given-name": "Bar",
+ "organization": "Foo",
+ "country": "US",
+
+ "given-name-shipping": "John",
+ "family-name-shipping": "Doe",
+ "organization-shipping": "Mozilla",
+ "country-shipping": "US",
+
+ "given-name-billing": "Foo",
+ "organization-billing": "Bar",
+ "country-billing": "US",
+
+ "cc-number-section-one": "4444000022220000",
+ "cc-name-section-one": "John",
+
+ "cc-number-section-two": "4444000022221111",
+ "cc-name-section-two": "Foo Bar",
+ "cc-exp-section-two": "2026-26",
+ },
+ expectedRecord: {
+ address: [{
+ "given-name": "Bar",
+ "organization": "Foo",
+ "country": "US",
+ }, {
+ "given-name": "John",
+ "family-name": "Doe",
+ "organization": "Mozilla",
+ "country": "US",
+ }, {
+ "given-name": "Foo",
+ "organization": "Bar",
+ "country": "US",
+ }],
+ creditCard: [{
+ "cc-number": "4444000022220000",
+ "cc-name": "John",
+ }, {
+ "cc-number": "4444000022221111",
+ "cc-name": "Foo Bar",
+ "cc-exp": "2026-26",
+ }],
+ },
+ },
+
];
for (let testcase of TESTCASES) {
add_task(async function() {
do_print("Starting testcase: " + testcase.description);
let doc = MockDocument.createTestDocument("http://localhost:8080/test/", testcase.document);
let form = doc.querySelector("form");
@@ -296,17 +379,14 @@ for (let testcase of TESTCASES) {
handler.collectFormFields();
for (let id in testcase.formValue) {
doc.getElementById(id).value = testcase.formValue[id];
}
let record = handler.createRecords();
- for (let type in testcase.expectedRecord) {
- if (!testcase.expectedRecord[type]) {
- do_check_eq(record[type], undefined);
- } else {
- Assert.deepEqual(record[type].record, testcase.expectedRecord[type]);
- }
+ let expectedRecord = testcase.expectedRecord;
+ for (let type in record) {
+ Assert.deepEqual(record[type].map(secRecord => secRecord.record), expectedRecord[type]);
}
});
}
--- a/browser/extensions/formautofill/test/unit/test_onFormSubmitted.js
+++ b/browser/extensions/formautofill/test/unit/test_onFormSubmitted.js
@@ -57,52 +57,54 @@ const TESTCASES = [
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "",
"address-level2": "",
"country": "USA",
"email": "",
"tel": "1-650-903-0800",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Trigger credit card saving",
formValue: {
"cc-name": "John Doe",
"cc-number": "1234567812345678",
"cc-exp-month": 12,
"cc-exp-year": 2000,
},
expectedResult: {
formSubmission: true,
records: {
- creditCard: {
+ address: [],
+ creditCard: [{
guid: null,
record: {
"cc-name": "John Doe",
"cc-number": "1234567812345678",
"cc-exp-month": 12,
"cc-exp-year": 2000,
},
untouchedFields: [],
- },
+ }],
},
},
},
{
description: "Trigger address and credit card saving",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
@@ -110,381 +112,394 @@ const TESTCASES = [
"cc-name": "John Doe",
"cc-number": "1234567812345678",
"cc-exp-month": 12,
"cc-exp-year": 2000,
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "",
"address-level2": "",
"country": "USA",
"email": "",
"tel": "1-650-903-0800",
},
untouchedFields: [],
- },
- creditCard: {
+ }],
+ creditCard: [{
guid: null,
record: {
"cc-name": "John Doe",
"cc-number": "1234567812345678",
"cc-exp-month": 12,
"cc-exp-year": 2000,
},
untouchedFields: [],
- },
+ }],
},
},
},
{
description: "Profile saved with trimmed string",
formValue: {
"street-addr": "331 E. Evelyn Avenue ",
"country": "USA",
"tel": " 1-650-903-0800",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "",
"address-level2": "",
"country": "USA",
"email": "",
"tel": "1-650-903-0800",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Eliminate the field that is empty after trimmed",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
"email": " ",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "",
"address-level2": "",
"country": "USA",
"email": "",
"tel": "1-650-903-0800",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Save state with regular select option",
formValue: {
"address-level1": "CA",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"address-level1": "CA",
"address-level2": "",
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"email": "",
"tel": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Save state with lowercase value",
formValue: {
"address-level1": "ca",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"address-level1": "CA",
"address-level2": "",
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"email": "",
"tel": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Save state with a country code prefixed to the label",
formValue: {
"address-level1": "AR",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"address-level1": "AR",
"address-level2": "",
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"email": "",
"tel": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Save state with a country code prefixed to the value",
formValue: {
"address-level1": "US-CA",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"address-level1": "CA",
"address-level2": "",
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"email": "",
"tel": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Save state with a country code prefixed to the value and label",
formValue: {
"address-level1": "US-AZ",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"address-level1": "AZ",
"address-level2": "",
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"email": "",
"tel": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Should save select label instead when failed to abbreviate the value",
formValue: {
"address-level1": "Ariz",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"address-level1": "Arizonac",
"address-level2": "",
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"email": "",
"tel": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Shouldn't save select with multiple selections",
formValue: {
"address-level1": ["AL", "AK", "AP"],
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "",
"address-level2": "",
"country": "USA",
"tel": "1-650-903-0800",
"email": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Shouldn't save select with empty value",
formValue: {
"address-level1": "",
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "",
"address-level2": "",
"country": "USA",
"tel": "1-650-903-0800",
"email": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Shouldn't save tel whose length is too short",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"address-level1": "CA",
"country": "US",
"tel": "1234",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "CA",
"address-level2": "",
"country": "US",
"tel": "",
"email": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Shouldn't save tel whose length is too long",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"address-level1": "CA",
"country": "US",
"tel": "1234567890123456",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "CA",
"address-level2": "",
"country": "US",
"tel": "",
"email": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
{
description: "Shouldn't save tel which contains invalid characters",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"address-level1": "CA",
"country": "US",
"tel": "12345###!!",
},
expectedResult: {
formSubmission: true,
records: {
- address: {
+ address: [{
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"address-level1": "CA",
"address-level2": "",
"country": "US",
"tel": "",
"email": "",
},
untouchedFields: [],
- },
+ }],
+ creditCard: [],
},
},
},
];
add_task(async function handle_earlyformsubmit_event() {
do_print("Starting testcase: Test an invalid form element");
let fakeForm = MOCK_DOC.createElement("form");
sinon.spy(FormAutofillContent, "_onFormSubmit");
- do_check_eq(FormAutofillContent.notify(fakeForm), true);
- do_check_eq(FormAutofillContent._onFormSubmit.called, false);
+ Assert.equal(FormAutofillContent.notify(fakeForm), true);
+ Assert.equal(FormAutofillContent._onFormSubmit.called, false);
FormAutofillContent._onFormSubmit.restore();
});
add_task(async function autofill_disabled() {
let form = MOCK_DOC.getElementById("form1");
form.reset();
let testcase = {
@@ -503,43 +518,43 @@ add_task(async function autofill_disable
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.notify(form);
- do_check_eq(FormAutofillContent._onFormSubmit.called, false);
+ Assert.equal(FormAutofillContent._onFormSubmit.called, false);
FormAutofillContent._onFormSubmit.reset();
// "_onFormSubmit" should be called as usual.
Services.prefs.clearUserPref("extensions.formautofill.addresses.enabled");
Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
FormAutofillContent.notify(form);
- do_check_eq(FormAutofillContent._onFormSubmit.called, true);
- do_check_neq(FormAutofillContent._onFormSubmit.args[0][0].address, undefined);
- do_check_neq(FormAutofillContent._onFormSubmit.args[0][0].creditCard, undefined);
+ Assert.equal(FormAutofillContent._onFormSubmit.called, true);
+ Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
+ Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
FormAutofillContent._onFormSubmit.reset();
// "address" should be empty if "addresses" pref is disabled.
Services.prefs.setBoolPref("extensions.formautofill.addresses.enabled", false);
FormAutofillContent.notify(form);
- do_check_eq(FormAutofillContent._onFormSubmit.called, true);
- do_check_eq(FormAutofillContent._onFormSubmit.args[0][0].address, undefined);
- do_check_neq(FormAutofillContent._onFormSubmit.args[0][0].creditCard, undefined);
+ Assert.equal(FormAutofillContent._onFormSubmit.called, true);
+ Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
+ Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
FormAutofillContent._onFormSubmit.reset();
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.notify(form);
- do_check_eq(FormAutofillContent._onFormSubmit.called, true);
- do_check_neq(FormAutofillContent._onFormSubmit.args[0][0].address, undefined);
- do_check_eq(FormAutofillContent._onFormSubmit.args[0][0].creditCard, undefined);
+ Assert.deepEqual(FormAutofillContent._onFormSubmit.called, true);
+ Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
+ Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
FormAutofillContent._onFormSubmit.reset();
Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
FormAutofillContent._onFormSubmit.restore();
});
TESTCASES.forEach(testcase => {
add_task(async function check_records_saving_is_called_correctly() {
@@ -561,17 +576,17 @@ TESTCASES.forEach(testcase => {
}
}
sinon.stub(FormAutofillContent, "_onFormSubmit");
let element = MOCK_DOC.getElementById(TARGET_ELEMENT_ID);
FormAutofillContent.identifyAutofillFields(element);
FormAutofillContent.notify(form);
- do_check_eq(FormAutofillContent._onFormSubmit.called,
+ Assert.equal(FormAutofillContent._onFormSubmit.called,
testcase.expectedResult.formSubmission);
if (FormAutofillContent._onFormSubmit.called) {
Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0],
testcase.expectedResult.records);
}
FormAutofillContent._onFormSubmit.restore();
});
});