diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/extensions/formautofill/test/unit/head_addressComponent.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/extensions/formautofill/test/unit/head_addressComponent.js')
-rw-r--r-- | browser/extensions/formautofill/test/unit/head_addressComponent.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/browser/extensions/formautofill/test/unit/head_addressComponent.js b/browser/extensions/formautofill/test/unit/head_addressComponent.js new file mode 100644 index 0000000000..6ed7d52d7e --- /dev/null +++ b/browser/extensions/formautofill/test/unit/head_addressComponent.js @@ -0,0 +1,75 @@ +"use strict"; + +/* exported BOTH_EMPTY, A_IS_EMPTY, B_IS_EMPTY, A_CONTAINS_B, B_CONTAINS_A, SIMILAR, SAME, DIFFERENT, runIsValidTest, runCompareTest */ + +const { AddressComparison, AddressComponent } = ChromeUtils.importESModule( + "resource://gre/modules/shared/AddressComponent.sys.mjs" +); + +const { FormAutofill } = ChromeUtils.importESModule( + "resource://autofill/FormAutofill.sys.mjs" +); + +const BOTH_EMPTY = AddressComparison.BOTH_EMPTY; +const A_IS_EMPTY = AddressComparison.A_IS_EMPTY; +const B_IS_EMPTY = AddressComparison.B_IS_EMPTY; +const A_CONTAINS_B = AddressComparison.A_CONTAINS_B; +const B_CONTAINS_A = AddressComparison.B_CONTAINS_A; +const SIMILAR = AddressComparison.SIMILAR; +const SAME = AddressComparison.SAME; +const DIFFERENT = AddressComparison.DIFFERENT; + +function runIsValidTest(tests, fieldName, funcSetupRecord) { + for (const test of tests) { + if (!Array.isArray(test)) { + FormAutofill.DEFAULT_REGION = test.region; + info(`Change region to ${JSON.stringify(test.region)}`); + continue; + } + + const [testValue, expected] = test; + const record = funcSetupRecord(testValue); + + const field = new AddressComponent(record, { + ignoreInvalid: false, + }).getField(fieldName); + const result = field.isValid(); + Assert.equal( + result, + expected, + `Expect isValid returns ${expected} for ${testValue}` + ); + } + FormAutofill.DEFAULT_REGION = null; +} + +function runCompareTest(tests, fieldName, funcSetupRecord) { + for (const test of tests) { + if (!Array.isArray(test)) { + info(`change region to ${JSON.stringify(test.region)}`); + FormAutofill.DEFAULT_REGION = test.region; + continue; + } + + const [v1, v2, expected] = test; + const r1 = funcSetupRecord(v1); + const f1 = new AddressComponent(r1, { ignoreInvalid: false }).getField( + fieldName + ); + + const r2 = funcSetupRecord(v2); + const f2 = new AddressComponent(r2, { ignoreInvalid: false }).getField( + fieldName + ); + + const result = AddressComparison.compare(f1, f2); + const resultString = AddressComparison.resultToString(result); + const expectedString = AddressComparison.resultToString(expected); + Assert.equal( + result, + expected, + `Expect ${expectedString} when comparing "${v1}" & "${v2}", got ${resultString}` + ); + } + FormAutofill.DEFAULT_REGION = null; +} |