summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/unit/test_addressComponent_email.js
blob: 2c4b07a542973c2e71c30098b5e842415c0c13be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 };
  });
});