test_addressComponent_email.js (2444B)
1 "use strict"; 2 3 // TODO: 4 // https://help.xmatters.com/ondemand/trial/valid_email_format.htm what is the allow characters??? 5 const VALID_TESTS = [ 6 // Is Valid Test 7 // [email1, expected] 8 ["john.doe@mozilla.org", true], 9 10 ["@mozilla.org", false], // without username 11 ["john.doe@", false], // without domain 12 ["john.doe@-mozilla.org", false], // domain starts with '-' 13 ["john.doe@mozilla.org-", false], // domain ends with '-' 14 ["john.doe@mozilla.-com.au", false], // sub-domain starts with '-' 15 ["john.doe@mozilla.com-.au", false], // sub-domain ends with '-' 16 17 ["john-doe@mozilla.org", true], // dash (ok) 18 19 // Special characters check 20 ["john.!#$%&'*+-/=?^_`{|}~doe@gmail.com", true], 21 22 ["john.doe@work@mozilla.org", false], 23 ["äbc@mail.com", false], 24 25 ["john.doe@" + "a".repeat(63) + ".org", true], 26 ["john.doe@" + "a".repeat(64) + ".org", false], 27 28 // The following are commented out since we're using a more relax email 29 // validation algorithm now. 30 /* 31 ["-john.doe@mozilla.org", false], // username starts with '-' 32 [".john.doe@mozilla.org", false], // username starts with '.' 33 ["john.doe-@mozilla.org", true], // username ends with '-' ??? 34 ["john.doe.@mozilla.org", true], // username ends with '.' ??? 35 ["john.doe@-mozilla.org", true], // domain starts with '.' ??? 36 ["john..doe@mozilla.org", false], // consecutive period 37 ["john.-doe@mozilla.org", false], // period + dash 38 ["john-.doe@mozilla.org", false], // dash + period 39 ["john.doe@school.123", false], 40 ["peter-parker@spiderman", false], 41 42 ["a".repeat(64) + "@mydomain.com", true], // length of username 43 ["b".repeat(65) + "@mydomain.com", false], 44 */ 45 ]; 46 47 const COMPARE_TESTS = [ 48 // Same 49 ["test@mozilla.org", "test@mozilla.org", SAME], 50 ["john.doe@example.com", "jOhn.doE@example.com", SAME], 51 ["jan@gmail.com", "JAN@gmail.com", SAME], 52 53 // Different 54 ["jan@gmail.com", "jan1@gmail.com", DIFFERENT], 55 ["jan@gmail.com", "jan@gmail.com.au", DIFFERENT], 56 ["john#smith@gmail.com", "johnsmith@gmail.com", DIFFERENT], 57 ]; 58 59 const TEST_FIELD_NAME = "email"; 60 61 add_setup(async () => {}); 62 63 add_task(async function test_isValid() { 64 runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => { 65 return { email: value }; 66 }); 67 }); 68 69 add_task(async function test_compare() { 70 runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => { 71 return { email: value }; 72 }); 73 });