summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_heuristics_cc_type.js
blob: e3f12096c2c0e52ee47f258bd15ae105b1d51505 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_PROFILE = {
  "cc-name": "John Doe",
  "cc-number": "4111111111111111",
  // "cc-type" should be remove from proile after fixing Bug 1834768.
  "cc-type": "visa",
  "cc-exp-month": 4,
  "cc-exp-year": new Date().getFullYear(),
};

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.formautofill.creditCards.supported", "on"],
      ["extensions.formautofill.creditCards.enabled", true],
    ],
  });
});

add_autofill_heuristic_tests([
  {
    description:
      "cc-type select does not have any information in labels or attributes",
    fixtureData: `
    <form>
      <input id="cc-number" autocomplete="cc-number">
      <input id="cc-name" autocomplete="cc-name">
      <select id="test">
        <option value="" selected="">0</option>
        <option value="VISA">1</option>
        <option value="MasterCard">2</option>
        <option value="DINERS">3</option>
        <option value="Discover">4</option>
     </select>
    </form>
    <form>
      <input id="cc-number" autocomplete="cc-number">
      <input id="cc-name" autocomplete="cc-name">
      <select id="test">
        <option value="0" selected="">Card Type</option>
        <option value="1">Visa</option>
        <option value="2">MasterCard</option>
        <option value="3">Diners Club International</option>
        <option value="4">Discover</option>
     </select>
    </form>`,
    profile: TEST_PROFILE,
    expectedResult: [
      {
        description: "cc-type option.value has the hint",
        default: {
          reason: "autocomplete",
        },
        fields: [
          { fieldName: "cc-number", autofill: TEST_PROFILE["cc-number"] },
          { fieldName: "cc-name", autofill: TEST_PROFILE["cc-name"] },
          { fieldName: "cc-type", reason: "regex-heuristic", autofill: "VISA" },
        ],
      },
      {
        description: "cc-type option.text has the hint",
        default: {
          reason: "autocomplete",
        },
        fields: [
          { fieldName: "cc-number", autofill: TEST_PROFILE["cc-number"] },
          { fieldName: "cc-name", autofill: TEST_PROFILE["cc-name"] },
          { fieldName: "cc-type", reason: "regex-heuristic", autofill: "1" },
        ],
      },
    ],
  },
]);