summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_doorhanger_not_shown.js
blob: 0056b8372708768624ce47da9b91d7edc977d779 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
"use strict";

const DEFAULT_TEST_DOC = `<form id="form">
  <input id="street-addr" autocomplete="street-address">
  <select id="address-level1" autocomplete="address-level1">
    <option value=""></option>
    <option value="AL">Alabama</option>
    <option value="AK">Alaska</option>
    <option value="AP">Armed Forces Pacific</option>

    <option value="ca">california</option>
    <option value="AR">US-Arkansas</option>
    <option value="US-CA">California</option>
    <option value="CA">California</option>
    <option value="US-AZ">US_Arizona</option>
    <option value="Ariz">Arizonac</option>
  </select>
  <input id="city" autocomplete="address-level2">
  <input id="country" autocomplete="country">
  <input id="email" autocomplete="email">
  <input id="tel" autocomplete="tel">
  <input id="cc-name" autocomplete="cc-name">
  <input id="cc-number" autocomplete="cc-number">
  <input id="cc-exp-month" autocomplete="cc-exp-month">
  <input id="cc-exp-year" autocomplete="cc-exp-year">
  <select id="cc-type">
    <option value="">Select</option>
    <option value="visa">Visa</option>
    <option value="mastercard">Master Card</option>
    <option value="amex">American Express</option>
  </select>
  <input id="submit" type="submit">
</form>`;

const TESTCASES = [
  {
    description: "Should not trigger credit card saving if number is empty",
    document: DEFAULT_TEST_DOC,
    targetElementId: "cc-name",
    formValue: {
      "#cc-name": "John Doe",
      "#cc-exp-month": 12,
      "#cc-exp-year": 2000,
    },
  },
  {
    description:
      "Should not trigger credit card saving if there is more than one cc-number field but less than four fields",
    document: `<form id="form">
                <input id="cc-type" autocomplete="cc-type">
                <input id="cc-name" autocomplete="cc-name">
                <input id="cc-number1" maxlength="4">
                <input id="cc-number2" maxlength="4">
                <input id="cc-number3" maxlength="4">
                <input id="cc-exp-month" autocomplete="cc-exp-month">
                <input id="cc-exp-year" autocomplete="cc-exp-year">
                <input id="submit" type="submit">
              </form>
    `,
    targetElementId: "cc-name",
    formValue: {
      "#cc-name": "John Doe",
      "#cc-number1": "3714",
      "#cc-number2": "4963",
      "#cc-number3": "5398",
      "#cc-exp-month": 12,
      "#cc-exp-year": 2000,
      "#cc-type": "amex",
    },
  },
];

add_task(async function test_save_doorhanger_not_shown() {
  for (const TEST of TESTCASES) {
    info(`Test ${TEST.description}`);

    await BrowserTestUtils.withNewTab(EMPTY_URL, async function (browser) {
      await SpecialPowers.spawn(browser, [TEST.document], doc => {
        content.document.body.innerHTML = doc;
      });

      await SimpleTest.promiseFocus(browser);

      await focusUpdateSubmitForm(browser, {
        focusSelector: `#${TEST.targetElementId}`,
        newValues: TEST.formValue,
      });

      await ensureNoDoorhanger();
    });
  }
});