From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/unit/test_addressComponent_email.js | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 browser/extensions/formautofill/test/unit/test_addressComponent_email.js (limited to 'browser/extensions/formautofill/test/unit/test_addressComponent_email.js') diff --git a/browser/extensions/formautofill/test/unit/test_addressComponent_email.js b/browser/extensions/formautofill/test/unit/test_addressComponent_email.js new file mode 100644 index 0000000000..2c4b07a542 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_addressComponent_email.js @@ -0,0 +1,74 @@ +"use strict"; + +// TODO: +// https://help.xmatters.com/ondemand/trial/valid_email_format.htm what is the allow characters??? +const VALID_TESTS = [ + // Is Valid Test + // [email1, expected] + ["john.doe@mozilla.org", true], + + ["", false], // empty + ["@mozilla.org", false], // without username + ["john.doe@", false], // without domain + ["john.doe@-mozilla.org", false], // domain starts with '-' + ["john.doe@mozilla.org-", false], // domain ends with '-' + ["john.doe@mozilla.-com.au", false], // sub-domain starts with '-' + ["john.doe@mozilla.com-.au", false], // sub-domain ends with '-' + + ["john-doe@mozilla.org", true], // dash (ok) + + // Special characters check + ["john.!#$%&'*+-/=?^_`{|}~doe@gmail.com", true], + + ["john.doe@work@mozilla.org", false], + ["äbc@mail.com", false], + + ["john.doe@" + "a".repeat(63) + ".org", true], + ["john.doe@" + "a".repeat(64) + ".org", false], + + // The following are commented out since we're using a more relax email + // validation algorithm now. + /* + ["-john.doe@mozilla.org", false], // username starts with '-' + [".john.doe@mozilla.org", false], // username starts with '.' + ["john.doe-@mozilla.org", true], // username ends with '-' ??? + ["john.doe.@mozilla.org", true], // username ends with '.' ??? + ["john.doe@-mozilla.org", true], // domain starts with '.' ??? + ["john..doe@mozilla.org", false], // consecutive period + ["john.-doe@mozilla.org", false], // period + dash + ["john-.doe@mozilla.org", false], // dash + period + ["john.doe@school.123", false], + ["peter-parker@spiderman", false], + + ["a".repeat(64) + "@mydomain.com", true], // length of username + ["b".repeat(65) + "@mydomain.com", false], +*/ +]; + +const COMPARE_TESTS = [ + // Same + ["test@mozilla.org", "test@mozilla.org", SAME], + ["john.doe@example.com", "jOhn.doE@example.com", SAME], + ["jan@gmail.com", "JAN@gmail.com", SAME], + + // Different + ["jan@gmail.com", "jan1@gmail.com", DIFFERENT], + ["jan@gmail.com", "jan@gmail.com.au", DIFFERENT], + ["john#smith@gmail.com", "johnsmith@gmail.com", DIFFERENT], +]; + +const TEST_FIELD_NAME = "Email"; + +add_setup(async () => {}); + +add_task(async function test_isValid() { + runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => { + return { email: value }; + }); +}); + +add_task(async function test_compare() { + runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => { + return { email: value }; + }); +}); -- cgit v1.2.3