"use strict"; const DEFAULT_TEST_DOC = `
`; const TESTCASES = [ { description: "Save address with trimmed address data", document: DEFAULT_TEST_DOC, targetElementId: "street-address", formValue: { "#street-address": "331 E. Evelyn Avenue ", "#country": "US", "#email": " ", "#tel": "1-650-903-0800", }, expected: [ { "street-address": "331 E. Evelyn Avenue", country: "US", email: "", tel: "+16509030800", }, ], }, ]; async function expectSavedAddresses(expectedAddresses) { const addresses = await getAddresses(); is( addresses.length, expectedAddresses.length, `${addresses.length} address in the storage` ); for (let i = 0; i < expectedAddresses.length; i++) { for (const [key, value] of Object.entries(expectedAddresses[i])) { is(addresses[i][key] ?? "", value, `field ${key} should be equal`); } } return addresses; } add_setup(async function () { await SpecialPowers.pushPrefEnv({ set: [ ["extensions.formautofill.addresses.enabled", true], ["extensions.formautofill.addresses.supported", "on"], ["extensions.formautofill.addresses.capture.enabled", true], ], }); }); add_task(async function test_address_capture_trimmed_data() { for (const TEST of TESTCASES) { info(`Test ${TEST.description}`); const onChanged = waitForStorageChangedEvents("add"); await BrowserTestUtils.withNewTab(EMPTY_URL, async function (browser) { await SpecialPowers.spawn(browser, [TEST.document], doc => { content.document.body.innerHTML = doc; }); await SimpleTest.promiseFocus(browser); const onPopupShown = waitForPopupShown(); await focusUpdateSubmitForm(browser, { focusSelector: `#${TEST.targetElementId}`, newValues: TEST.formValue, }); await onPopupShown; await clickDoorhangerButton(MAIN_BUTTON, 0); }); await onChanged; await expectSavedAddresses(TEST.expected); await removeAllRecords(); } });