summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/heuristics/browser_section_validation_address.js
blob: 2e9cf42ab0b4eb631b0e550658601a776992c80e (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
75
76
77
78
79
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

/* global add_heuristic_tests */

"use strict";

add_heuristic_tests([
  {
    description: `An address section is valid when it only contains more than three fields`,
    fixtureData: `
        <html><body>
            <input id="street-address" autocomplete="street-address">
            <input id="postal-code" autocomplete="postal-code">
            <input id="email" autocomplete="email">
        </body></html>
      `,
    expectedResult: [
      {
        default: {
          reason: "autocomplete",
        },
        fields: [
          { fieldName: "street-address" },
          { fieldName: "postal-code" },
          { fieldName: "email" },
        ],
      },
    ],
  },
  {
    description: `An address section is invalid when it contains less than threee fields`,
    fixtureData: `
        <html><body>
            <input id="postal-code" autocomplete="postal-code">
            <input id="email" autocomplete="email">

            <input id="postal-code" autocomplete="postal-code">
        </body></html>
      `,
    expectedResult: [
      {
        description: "A section with two fields",
        invalid: true,
        fields: [
          { fieldName: "postal-code", reason: "autocomplete" },
          { fieldName: "email", reason: "autocomplete" },
        ],
      },
      {
        description: "A section with one field",
        invalid: true,
        fields: [{ fieldName: "postal-code", reason: "autocomplete" }],
      },
    ],
  },
  {
    description: `Address section validation only counts the number of different address field name in the section`,
    fixtureData: `
        <html><body>
            <input id="postal-code" autocomplete="postal-code">
            <input id="email" autocomplete="email">
            <input id="email" autocomplete="email">
        </body></html>
      `,
    expectedResult: [
      {
        description:
          "A section with three fields but has duplicated email fields",
        invalid: true,
        fields: [
          { fieldName: "postal-code", reason: "autocomplete" },
          { fieldName: "email", reason: "autocomplete" },
          { fieldName: "email", reason: "autocomplete" },
        ],
      },
    ],
  },
]);