tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_getAdaptedProfiles.js (48168B)


      1 /*
      2 * Test for form auto fill content helper fill all inputs function.
      3 */
      4 
      5 "use strict";
      6 
      7 const DEFAULT_ADDRESS_RECORD = {
      8  guid: "123",
      9  "street-address": "2 Harrison St\nline2\nline3",
     10  "address-line1": "2 Harrison St",
     11  "address-line2": "line2",
     12  "address-line3": "line3",
     13  "address-level1": "CA",
     14  country: "US",
     15  tel: "+19876543210",
     16  "tel-national": "9876543210",
     17 };
     18 
     19 const ADDRESS_RECORD_2 = {
     20  guid: "address2",
     21  "given-name": "John",
     22  "additional-name": "Middle",
     23  "family-name": "Doe",
     24  "postal-code": "940012345",
     25 };
     26 
     27 const DEFAULT_CREDITCARD_RECORD = {
     28  guid: "123",
     29  "cc-exp-month": 1,
     30  "cc-exp-year": 2025,
     31  "cc-exp": "2025-01",
     32 };
     33 
     34 const DEFAULT_EXPECTED_CREDITCARD_RECORD = {
     35  guid: "123",
     36  "cc-exp-month": 1,
     37  "cc-exp-year": 2025,
     38  "cc-exp": "01/2025",
     39 };
     40 
     41 const getCCExpMonthFormatted = () => {
     42  return DEFAULT_CREDITCARD_RECORD["cc-exp-month"].toString().padStart(2, "0");
     43 };
     44 
     45 const getCCExpYearFormatted = () => {
     46  return DEFAULT_CREDITCARD_RECORD["cc-exp-year"].toString().substring(2);
     47 };
     48 
     49 // Bug 1767130: If a form has separate inputs for expiry month and year,
     50 // we will always transform month into MM
     51 const DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY = {
     52  ...DEFAULT_CREDITCARD_RECORD,
     53  "cc-exp-month-formatted": getCCExpMonthFormatted(),
     54 };
     55 
     56 const TESTCASES = [
     57  {
     58    description: "Address form with street-address",
     59    document: `<form>
     60               <input autocomplete="given-name">
     61               <input autocomplete="family-name">
     62               <input id="street-addr" autocomplete="street-address">
     63               </form>`,
     64    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
     65    expectedResult: [
     66      {
     67        guid: "123",
     68        "street-address": "2 Harrison St line2 line3",
     69        "-moz-street-address-one-line": "2 Harrison St line2 line3",
     70        "address-line1": "2 Harrison St",
     71        "address-line2": "line2",
     72        "address-line3": "line3",
     73        "address-level1": "CA",
     74        country: "US",
     75        tel: "+19876543210",
     76        "tel-national": "9876543210",
     77      },
     78    ],
     79  },
     80  {
     81    description: "Address form with street-address, address-line[1, 2, 3]",
     82    document: `<form>
     83               <input id="street-addr" autocomplete="street-address">
     84               <input id="line1" autocomplete="address-line1">
     85               <input id="line2" autocomplete="address-line2">
     86               <input id="line3" autocomplete="address-line3">
     87               </form>`,
     88    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
     89    expectedResult: [
     90      {
     91        guid: "123",
     92        "street-address": "2 Harrison St line2 line3",
     93        "-moz-street-address-one-line": "2 Harrison St line2 line3",
     94        "address-line1": "2 Harrison St",
     95        "address-line2": "line2",
     96        "address-line3": "line3",
     97        "address-level1": "CA",
     98        country: "US",
     99        tel: "+19876543210",
    100        "tel-national": "9876543210",
    101      },
    102    ],
    103  },
    104  {
    105    description: "Address form with street-address, address-line1",
    106    document: `<form>
    107               <input autocomplete="given-name">
    108               <input id="street-addr" autocomplete="street-address">
    109               <input id="line1" autocomplete="address-line1">
    110               </form>`,
    111    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    112    expectedResult: [
    113      {
    114        guid: "123",
    115        "street-address": "2 Harrison St line2 line3",
    116        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    117        "address-line1": "2 Harrison St line2 line3",
    118        "address-line2": "line2",
    119        "address-line3": "line3",
    120        "address-level1": "CA",
    121        country: "US",
    122        tel: "+19876543210",
    123        "tel-national": "9876543210",
    124      },
    125    ],
    126  },
    127  {
    128    description: "Address form with street-address, address-line[1, 2]",
    129    document: `<form>
    130               <input id="street-addr" autocomplete="street-address">
    131               <input id="line1" autocomplete="address-line1">
    132               <input id="line2" autocomplete="address-line2">
    133               </form>`,
    134    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    135    expectedResult: [
    136      {
    137        guid: "123",
    138        "street-address": "2 Harrison St line2 line3",
    139        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    140        "address-line1": "2 Harrison St",
    141        "address-line2": "line2 line3",
    142        "address-line3": "line3",
    143        "address-level1": "CA",
    144        country: "US",
    145        tel: "+19876543210",
    146        "tel-national": "9876543210",
    147      },
    148    ],
    149  },
    150  {
    151    description:
    152      "Address form with street-address, address-line[1, 3]" +
    153      ", determined by autocomplete attr",
    154    document: `<form>
    155               <input id="street-addr" autocomplete="street-address">
    156               <input id="line1" autocomplete="address-line1">
    157               <input id="line3" autocomplete="address-line3">
    158               </form>`,
    159    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    160    expectedResult: [
    161      {
    162        guid: "123",
    163        "street-address": "2 Harrison St line2 line3",
    164        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    165        // Since the form is missing address-line2 field, the value of
    166        // address-line1 should contain line2 value as well.
    167        "address-line1": "2 Harrison St line2",
    168        "address-line2": "line2",
    169        "address-line3": "line3",
    170        "address-level1": "CA",
    171        country: "US",
    172        tel: "+19876543210",
    173        "tel-national": "9876543210",
    174      },
    175    ],
    176  },
    177  {
    178    description:
    179      "Address form with street-address, address-line[1, 3]" +
    180      ", determined by heuristics",
    181    document: `<form>
    182               <input id="street-address">
    183               <input id="address-line1">
    184               <input id="address-line3">
    185               </form>`,
    186    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    187    expectedResult: [
    188      {
    189        guid: "123",
    190        "street-address": "2 Harrison St\nline2\nline3",
    191        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    192        // Since the form is missing address-line2 field, the value of
    193        // address-line1 should contain line2 value as well.
    194        "address-line1": "2 Harrison St",
    195        "address-line2": "line2",
    196        "address-line3": "line3",
    197        "address-level1": "CA",
    198        country: "US",
    199        tel: "+19876543210",
    200        "tel-national": "9876543210",
    201      },
    202    ],
    203  },
    204  {
    205    description: "Address form with exact matching options in select",
    206    document: `<form>
    207               <input autocomplete="given-name">
    208               <select autocomplete="address-level1">
    209                 <option id="option-address-level1-XX" value="XX">Dummy</option>
    210                 <option id="option-address-level1-CA" value="CA">California</option>
    211               </select>
    212               <select autocomplete="country">
    213                 <option id="option-country-XX" value="XX">Dummy</option>
    214                 <option id="option-country-US" value="US">United States</option>
    215               </select>
    216               </form>`,
    217    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    218    expectedResult: [
    219      {
    220        guid: "123",
    221        "street-address": "2 Harrison St\nline2\nline3",
    222        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    223        "address-line1": "2 Harrison St",
    224        "address-line2": "line2",
    225        "address-line3": "line3",
    226        "address-level1": "CA",
    227        country: "US",
    228        tel: "+19876543210",
    229        "tel-national": "9876543210",
    230      },
    231    ],
    232    expectedOptionElements: [
    233      {
    234        "address-level1": "option-address-level1-CA",
    235        country: "option-country-US",
    236      },
    237    ],
    238  },
    239  {
    240    description: "Address form with inexact matching options in select",
    241    document: `<form>
    242               <input autocomplete="given-name">
    243               <select autocomplete="address-level1">
    244                 <option id="option-address-level1-XX" value="XX">Dummy</option>
    245                 <option id="option-address-level1-OO" value="OO">California</option>
    246               </select>
    247               <select autocomplete="country">
    248                 <option id="option-country-XX" value="XX">Dummy</option>
    249                 <option id="option-country-OO" value="OO">United States</option>
    250               </select>
    251               </form>`,
    252    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    253    expectedResult: [
    254      {
    255        guid: "123",
    256        "street-address": "2 Harrison St\nline2\nline3",
    257        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    258        "address-line1": "2 Harrison St",
    259        "address-line2": "line2",
    260        "address-line3": "line3",
    261        "address-level1": "CA",
    262        country: "US",
    263        tel: "+19876543210",
    264        "tel-national": "9876543210",
    265      },
    266    ],
    267    expectedOptionElements: [
    268      {
    269        "address-level1": "option-address-level1-OO",
    270        country: "option-country-OO",
    271      },
    272    ],
    273  },
    274  {
    275    description: "Address form with value-omitted options in select",
    276    document: `<form>
    277               <input autocomplete="given-name">
    278               <select autocomplete="address-level1">
    279                 <option id="option-address-level1-1" value="">Dummy</option>
    280                 <option id="option-address-level1-2" value="">California</option>
    281               </select>
    282               <select autocomplete="country">
    283                 <option id="option-country-1" value="">Dummy</option>
    284                 <option id="option-country-2" value="">United States</option>
    285               </select>
    286               </form>`,
    287    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    288    expectedResult: [
    289      {
    290        guid: "123",
    291        "street-address": "2 Harrison St\nline2\nline3",
    292        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    293        "address-line1": "2 Harrison St",
    294        "address-line2": "line2",
    295        "address-line3": "line3",
    296        "address-level1": "CA",
    297        country: "US",
    298        tel: "+19876543210",
    299        "tel-national": "9876543210",
    300      },
    301    ],
    302    expectedOptionElements: [
    303      {
    304        "address-level1": "option-address-level1-2",
    305        country: "option-country-2",
    306      },
    307    ],
    308  },
    309  {
    310    description: "Address form with options with the same value in select ",
    311    document: `<form>
    312               <input autocomplete="given-name">
    313               <select autocomplete="address-level1">
    314                 <option id="option-address-level1-same1" value="same">Dummy</option>
    315                 <option id="option-address-level1-same2" value="same">California</option>
    316               </select>
    317               <select autocomplete="country">
    318                 <option id="option-country-same1" value="sametoo">Dummy</option>
    319                 <option id="option-country-same2" value="sametoo">United States</option>
    320               </select>
    321               </form>`,
    322    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    323    expectedResult: [
    324      {
    325        guid: "123",
    326        "street-address": "2 Harrison St\nline2\nline3",
    327        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    328        "address-line1": "2 Harrison St",
    329        "address-line2": "line2",
    330        "address-line3": "line3",
    331        "address-level1": "CA",
    332        country: "US",
    333        tel: "+19876543210",
    334        "tel-national": "9876543210",
    335      },
    336    ],
    337    expectedOptionElements: [
    338      {
    339        "address-level1": "option-address-level1-same2",
    340        country: "option-country-same2",
    341      },
    342    ],
    343  },
    344  {
    345    description:
    346      "Change the tel value of a profile to tel-national for a field without pattern and maxlength.",
    347    document: `<form>
    348               <input id="telephone">
    349               <input id="line1" autocomplete="address-line1">
    350               <input id="line2" autocomplete="address-line2">
    351               </form>`,
    352    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    353    expectedResult: [
    354      {
    355        guid: "123",
    356        "street-address": "2 Harrison St\nline2\nline3",
    357        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    358        "address-line1": "2 Harrison St",
    359        "address-line2": "line2 line3",
    360        "address-line3": "line3",
    361        "address-level1": "CA",
    362        country: "US",
    363        tel: "9876543210",
    364        "tel-national": "9876543210",
    365      },
    366    ],
    367  },
    368  {
    369    description:
    370      'Do not change the profile for an autocomplete="tel" field without patern and maxlength.',
    371    document: `<form>
    372               <input id="tel" autocomplete="tel">
    373               <input id="line1" autocomplete="address-line1">
    374               <input id="line2" autocomplete="address-line2">
    375               </form>`,
    376    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    377    expectedResult: [
    378      {
    379        guid: "123",
    380        "street-address": "2 Harrison St\nline2\nline3",
    381        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    382        "address-line1": "2 Harrison St",
    383        "address-line2": "line2 line3",
    384        "address-line3": "line3",
    385        "address-level1": "CA",
    386        country: "US",
    387        tel: "+19876543210",
    388        "tel-national": "9876543210",
    389      },
    390    ],
    391  },
    392  {
    393    description:
    394      'autocomplete="tel" field with `maxlength` can be filled with `tel` value.',
    395    document: `<form>
    396               <input id="telephone" autocomplete="tel" maxlength="12">
    397               <input id="line1" autocomplete="address-line1">
    398               <input id="line2" autocomplete="address-line2">
    399               </form>`,
    400    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    401    expectedResult: [
    402      {
    403        guid: "123",
    404        "street-address": "2 Harrison St\nline2\nline3",
    405        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    406        "address-line1": "2 Harrison St",
    407        "address-line2": "line2 line3",
    408        "address-line3": "line3",
    409        "address-level1": "CA",
    410        country: "US",
    411        tel: "+19876543210",
    412        "tel-national": "9876543210",
    413      },
    414    ],
    415  },
    416  {
    417    description:
    418      "Still fill `tel-national` in a `tel` field with `maxlength` can be filled with `tel` value.",
    419    document: `<form>
    420               <input id="telephone" maxlength="12">
    421               <input id="line1" autocomplete="address-line1">
    422               <input id="line2" autocomplete="address-line2">
    423               </form>`,
    424    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    425    expectedResult: [
    426      {
    427        guid: "123",
    428        "street-address": "2 Harrison St\nline2\nline3",
    429        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    430        "address-line1": "2 Harrison St",
    431        "address-line2": "line2 line3",
    432        "address-line3": "line3",
    433        "address-level1": "CA",
    434        country: "US",
    435        tel: "9876543210",
    436        "tel-national": "9876543210",
    437      },
    438    ],
    439  },
    440  {
    441    description:
    442      "`tel` field with `maxlength` can be filled with `tel-national` value.",
    443    document: `<form>
    444               <input id="telephone" maxlength="10">
    445               <input id="line1" autocomplete="address-line1">
    446               <input id="line2" autocomplete="address-line2">
    447               </form>`,
    448    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    449    expectedResult: [
    450      {
    451        guid: "123",
    452        "street-address": "2 Harrison St\nline2\nline3",
    453        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    454        "address-line1": "2 Harrison St",
    455        "address-line2": "line2 line3",
    456        "address-line3": "line3",
    457        "address-level1": "CA",
    458        country: "US",
    459        tel: "9876543210",
    460        "tel-national": "9876543210",
    461      },
    462    ],
    463  },
    464  {
    465    description:
    466      "`tel` field with `pattern` attr can be filled with `tel` value.",
    467    document: `<form>
    468               <input id="telephone" pattern="[+][0-9]+">
    469               <input id="line1" autocomplete="address-line1">
    470               <input id="line2" autocomplete="address-line2">
    471               </form>`,
    472    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    473    expectedResult: [
    474      {
    475        guid: "123",
    476        "street-address": "2 Harrison St\nline2\nline3",
    477        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    478        "address-line1": "2 Harrison St",
    479        "address-line2": "line2 line3",
    480        "address-line3": "line3",
    481        "address-level1": "CA",
    482        country: "US",
    483        tel: "+19876543210",
    484        "tel-national": "9876543210",
    485      },
    486    ],
    487  },
    488  {
    489    description:
    490      "Change the tel value of a profile to tel-national one when the pattern is matched.",
    491    document: `<form>
    492               <input id="telephone" pattern="\d*">
    493               <input id="line1" autocomplete="address-line1">
    494               <input id="line2" autocomplete="address-line2">
    495               </form>`,
    496    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    497    expectedResult: [
    498      {
    499        guid: "123",
    500        "street-address": "2 Harrison St\nline2\nline3",
    501        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    502        "address-line1": "2 Harrison St",
    503        "address-line2": "line2 line3",
    504        "address-line3": "line3",
    505        "address-level1": "CA",
    506        country: "US",
    507        tel: "9876543210",
    508        "tel-national": "9876543210",
    509      },
    510    ],
    511  },
    512  {
    513    description: 'Matching pattern when a field is with autocomplete="tel".',
    514    document: `<form>
    515               <input id="tel" autocomplete="tel" pattern="[0-9]+">
    516               <input id="line1" autocomplete="address-line1">
    517               <input id="line2" autocomplete="address-line2">
    518               </form>`,
    519    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    520    expectedResult: [
    521      {
    522        guid: "123",
    523        "street-address": "2 Harrison St\nline2\nline3",
    524        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    525        "address-line1": "2 Harrison St",
    526        "address-line2": "line2 line3",
    527        "address-line3": "line3",
    528        "address-level1": "CA",
    529        country: "US",
    530        tel: "9876543210",
    531        "tel-national": "9876543210",
    532      },
    533    ],
    534  },
    535  {
    536    description:
    537      "Checking maxlength of tel field first when a field is with maxlength.",
    538    document: `<form>
    539               <input id="tel" autocomplete="tel" maxlength="10">
    540               <input id="line1" autocomplete="address-line1">
    541               <input id="line2" autocomplete="address-line2">
    542               </form>`,
    543    profileData: [{ ...DEFAULT_ADDRESS_RECORD }],
    544    expectedResult: [
    545      {
    546        guid: "123",
    547        "street-address": "2 Harrison St\nline2\nline3",
    548        "-moz-street-address-one-line": "2 Harrison St line2 line3",
    549        "address-line1": "2 Harrison St",
    550        "address-line2": "line2 line3",
    551        "address-line3": "line3",
    552        "address-level1": "CA",
    553        country: "US",
    554        tel: "9876543210",
    555        "tel-national": "9876543210",
    556      },
    557    ],
    558  },
    559  {
    560    description: "Address form with maxlength restriction",
    561    document: `<form>
    562               <input autocomplete="given-name" maxlength="1">
    563               <input autocomplete="additional-name" maxlength="1">
    564               <input autocomplete="family-name" maxlength="1">
    565               <input autocomplete="postal-code" maxlength="5">
    566               </form>`,
    567    profileData: [{ ...ADDRESS_RECORD_2 }],
    568    expectedResult: [
    569      {
    570        guid: "address2",
    571        "given-name": "J",
    572        "additional-name": "M",
    573        "family-name": "D",
    574        "postal-code": "94001",
    575      },
    576    ],
    577  },
    578  {
    579    description:
    580      "Address form with the special cases of the maxlength restriction",
    581    document: `<form>
    582               <input autocomplete="given-name" maxlength="-1">
    583               <input autocomplete="additional-name" maxlength="0">
    584               <input autocomplete="family-name" maxlength="1">
    585               </form>`,
    586    profileData: [{ ...ADDRESS_RECORD_2 }],
    587    expectedResult: [
    588      {
    589        guid: "address2",
    590        "given-name": "John",
    591        "family-name": "D",
    592        "postal-code": "940012345",
    593      },
    594    ],
    595  },
    596  {
    597    description:
    598      "Credit card form with separate fields for expiration month and year",
    599    document: `<form>
    600                <input autocomplete="cc-number">
    601                <input autocomplete="cc-exp-month">
    602                <input autocomplete="cc-exp-year">
    603              </form`,
    604    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    605    expectedResult: [{ ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY }],
    606  },
    607  {
    608    description:
    609      "Credit Card form with matching options of cc-exp-year and cc-exp-month",
    610    document: `<form>
    611               <input autocomplete="cc-number">
    612               <select autocomplete="cc-exp-month">
    613                 <option id="option-cc-exp-month-01" value="1">01</option>
    614                 <option id="option-cc-exp-month-02" value="2">02</option>
    615                 <option id="option-cc-exp-month-03" value="3">03</option>
    616                 <option id="option-cc-exp-month-04" value="4">04</option>
    617                 <option id="option-cc-exp-month-05" value="5">05</option>
    618                 <option id="option-cc-exp-month-06" value="6">06</option>
    619                 <option id="option-cc-exp-month-07" value="7">07</option>
    620                 <option id="option-cc-exp-month-08" value="8">08</option>
    621                 <option id="option-cc-exp-month-09" value="9">09</option>
    622                 <option id="option-cc-exp-month-10" value="10">10</option>
    623                 <option id="option-cc-exp-month-11" value="11">11</option>
    624                 <option id="option-cc-exp-month-12" value="12">12</option>
    625               </select>
    626               <select autocomplete="cc-exp-year">
    627                 <option id="option-cc-exp-year-17" value="2017">17</option>
    628                 <option id="option-cc-exp-year-18" value="2018">18</option>
    629                 <option id="option-cc-exp-year-19" value="2019">19</option>
    630                 <option id="option-cc-exp-year-20" value="2020">20</option>
    631                 <option id="option-cc-exp-year-21" value="2021">21</option>
    632                 <option id="option-cc-exp-year-22" value="2022">22</option>
    633                 <option id="option-cc-exp-year-23" value="2023">23</option>
    634                 <option id="option-cc-exp-year-24" value="2024">24</option>
    635                 <option id="option-cc-exp-year-25" value="2025">25</option>
    636                 <option id="option-cc-exp-year-26" value="2026">26</option>
    637                 <option id="option-cc-exp-year-27" value="2027">27</option>
    638                 <option id="option-cc-exp-year-28" value="2028">28</option>
    639               </select>
    640               </form>`,
    641    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    642    expectedResult: [DEFAULT_CREDITCARD_RECORD],
    643    expectedOptionElements: [
    644      {
    645        "cc-exp-month": "option-cc-exp-month-01",
    646        "cc-exp-year": "option-cc-exp-year-25",
    647      },
    648    ],
    649  },
    650  {
    651    description: "Credit Card form with matching options which contain labels",
    652    document: `<form>
    653               <input autocomplete="cc-number">
    654               <select autocomplete="cc-exp-month">
    655                 <option value="" selected="selected">Month</option>
    656                 <option label="01 - January" id="option-cc-exp-month-01" value="object:17">dummy</option>
    657                 <option label="02 - February" id="option-cc-exp-month-02" value="object:18">dummy</option>
    658                 <option label="03 - March" id="option-cc-exp-month-03" value="object:19">dummy</option>
    659                 <option label="04 - April" id="option-cc-exp-month-04" value="object:20">dummy</option>
    660                 <option label="05 - May" id="option-cc-exp-month-05" value="object:21">dummy</option>
    661                 <option label="06 - June" id="option-cc-exp-month-06" value="object:22">dummy</option>
    662                 <option label="07 - July" id="option-cc-exp-month-07" value="object:23">dummy</option>
    663                 <option label="08 - August" id="option-cc-exp-month-08" value="object:24">dummy</option>
    664                 <option label="09 - September" id="option-cc-exp-month-09" value="object:25">dummy</option>
    665                 <option label="10 - October" id="option-cc-exp-month-10" value="object:26">dummy</option>
    666                 <option label="11 - November" id="option-cc-exp-month-11" value="object:27">dummy</option>
    667                 <option label="12 - December" id="option-cc-exp-month-12" value="object:28">dummy</option>
    668               </select>
    669               <select autocomplete="cc-exp-year">
    670                 <option value="" selected="selected">Year</option>
    671                 <option label="2017" id="option-cc-exp-year-17" value="object:29">dummy</option>
    672                 <option label="2018" id="option-cc-exp-year-18" value="object:30">dummy</option>
    673                 <option label="2019" id="option-cc-exp-year-19" value="object:31">dummy</option>
    674                 <option label="2020" id="option-cc-exp-year-20" value="object:32">dummy</option>
    675                 <option label="2021" id="option-cc-exp-year-21" value="object:33">dummy</option>
    676                 <option label="2022" id="option-cc-exp-year-22" value="object:34">dummy</option>
    677                 <option label="2023" id="option-cc-exp-year-23" value="object:35">dummy</option>
    678                 <option label="2024" id="option-cc-exp-year-24" value="object:36">dummy</option>
    679                 <option label="2025" id="option-cc-exp-year-25" value="object:37">dummy</option>
    680                 <option label="2026" id="option-cc-exp-year-26" value="object:38">dummy</option>
    681                 <option label="2027" id="option-cc-exp-year-27" value="object:39">dummy</option>
    682                 <option label="2028" id="option-cc-exp-year-28" value="object:40">dummy</option>
    683                 <option label="2029" id="option-cc-exp-year-29" value="object:41">dummy</option>
    684                 <option label="2030" id="option-cc-exp-year-30" value="object:42">dummy</option>
    685                 <option label="2031" id="option-cc-exp-year-31" value="object:43">dummy</option>
    686                 <option label="2032" id="option-cc-exp-year-32" value="object:44">dummy</option>
    687                 <option label="2033" id="option-cc-exp-year-33" value="object:45">dummy</option>
    688                 <option label="2034" id="option-cc-exp-year-34" value="object:46">dummy</option>
    689                 <option label="2035" id="option-cc-exp-year-35" value="object:47">dummy</option>
    690               </select>
    691               </form>`,
    692    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    693    expectedResult: [DEFAULT_CREDITCARD_RECORD],
    694    expectedOptionElements: [
    695      {
    696        "cc-exp-month": "option-cc-exp-month-01",
    697        "cc-exp-year": "option-cc-exp-year-25",
    698      },
    699    ],
    700  },
    701  {
    702    description: "Compound cc-exp: {MON1}/{YEAR2}",
    703    document: `<form>
    704               <input autocomplete="cc-number">
    705               <select autocomplete="cc-exp">
    706                 <option value="3/17">3/17</option>
    707                 <option value="1/25" id="selected-cc-exp">1/25</option>
    708               </select></form>`,
    709    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    710    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    711    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    712  },
    713  {
    714    description: "Compound cc-exp: {MON1}/{YEAR4}",
    715    document: `<form>
    716               <input autocomplete="cc-number">
    717               <select autocomplete="cc-exp">
    718                 <option value="3/2017">3/2017</option>
    719                 <option value="1/2025" id="selected-cc-exp">1/2025</option>
    720               </select></form>`,
    721    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    722    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    723    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    724  },
    725  {
    726    description: "Compound cc-exp: {MON2}/{YEAR2}",
    727    document: `<form>
    728               <input autocomplete="cc-number">
    729               <select autocomplete="cc-exp">
    730                 <option value="03/17">03/17</option>
    731                 <option value="01/25" id="selected-cc-exp">01/25</option>
    732               </select></form>`,
    733    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    734    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    735    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    736  },
    737  {
    738    description: "Compound cc-exp: {MON2}/{YEAR4}",
    739    document: `<form>
    740               <input autocomplete="cc-number">
    741               <select autocomplete="cc-exp">
    742                 <option value="03/2017">03/2017</option>
    743                 <option value="01/2025" id="selected-cc-exp">01/2025</option>
    744               </select></form>`,
    745    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    746    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    747    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    748  },
    749  {
    750    description: "Compound cc-exp: {MON1}-{YEAR2}",
    751    document: `<form>
    752               <input autocomplete="cc-number">
    753               <select autocomplete="cc-exp">
    754                 <option value="3-17">3-17</option>
    755                 <option value="1-25" id="selected-cc-exp">1-25</option>
    756               </select></form>`,
    757    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    758    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    759    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    760  },
    761  {
    762    description: "Compound cc-exp: {MON1}-{YEAR4}",
    763    document: `<form>
    764               <input autocomplete="cc-number">
    765               <select autocomplete="cc-exp">
    766                 <option value="3-2017">3-2017</option>
    767                 <option value="1-2025" id="selected-cc-exp">1-2025</option>
    768               </select></form>`,
    769    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    770    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    771    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    772  },
    773  {
    774    description: "Compound cc-exp: {MON2}-{YEAR2}",
    775    document: `<form>
    776               <input autocomplete="cc-number">
    777               <select autocomplete="cc-exp">
    778                 <option value="03-17">03-17</option>
    779                 <option value="01-25" id="selected-cc-exp">01-25</option>
    780               </select></form>`,
    781    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    782    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    783    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    784  },
    785  {
    786    description: "Compound cc-exp: {MON2}-{YEAR4}",
    787    document: `<form>
    788               <input autocomplete="cc-number">
    789               <select autocomplete="cc-exp">
    790                 <option value="03-2017">03-2017</option>
    791                 <option value="01-2025" id="selected-cc-exp">01-2025</option>
    792               </select></form>`,
    793    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    794    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    795    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    796  },
    797  {
    798    description: "Compound cc-exp: {YEAR2}-{MON2}",
    799    document: `<form>
    800               <input autocomplete="cc-number">
    801               <select autocomplete="cc-exp">
    802                 <option value="17-03">17-03</option>
    803                 <option value="25-01" id="selected-cc-exp">25-01</option>
    804               </select></form>`,
    805    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    806    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    807    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    808  },
    809  {
    810    description: "Compound cc-exp: {YEAR4}-{MON2}",
    811    document: `<form>
    812               <input autocomplete="cc-number">
    813               <select autocomplete="cc-exp">
    814                 <option value="2017-03">2017-03</option>
    815                 <option value="2025-01" id="selected-cc-exp">2025-01</option>
    816               </select></form>`,
    817    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    818    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    819    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    820  },
    821  {
    822    description: "Compound cc-exp: {YEAR4}/{MON2}",
    823    document: `<form>
    824               <input autocomplete="cc-number">
    825               <select autocomplete="cc-exp">
    826                 <option value="2017/3">2017/3</option>
    827                 <option value="2025/1" id="selected-cc-exp">2025/1</option>
    828               </select></form>`,
    829    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    830    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    831    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    832  },
    833  {
    834    description: "Compound cc-exp: {MON2}{YEAR2}",
    835    document: `<form>
    836               <input autocomplete="cc-number">
    837               <select autocomplete="cc-exp">
    838                 <option value="0317">0317</option>
    839                 <option value="0125" id="selected-cc-exp">0125</option>
    840               </select></form>`,
    841    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    842    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    843    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    844  },
    845  {
    846    description: "Compound cc-exp: {YEAR2}{MON2}",
    847    document: `<form>
    848               <input autocomplete="cc-number">
    849               <select autocomplete="cc-exp">
    850                 <option value="1703">1703</option>
    851                 <option value="2501" id="selected-cc-exp">2501</option>
    852               </select></form>`,
    853    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
    854    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
    855    expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }],
    856  },
    857  {
    858    description: "Fill a cc-exp without cc-exp-month value in the profile",
    859    document: `<form>
    860               <input autocomplete="cc-number">
    861               <select autocomplete="cc-exp">
    862                 <option value="03/17">03/17</option>
    863                 <option value="01/25">01/25</option>
    864               </select></form>`,
    865    profileData: [
    866      {
    867        guid: "123",
    868        "cc-exp-year": 2025,
    869      },
    870    ],
    871    expectedResult: [
    872      {
    873        guid: "123",
    874        "cc-exp-year": 2025,
    875      },
    876    ],
    877    expectedOptionElements: [],
    878  },
    879  {
    880    description: "Fill a cc-exp without cc-exp-year value in the profile",
    881    document: `<form>
    882               <input autocomplete="cc-number">
    883               <select autocomplete="cc-exp">
    884                 <option value="03/17">03/17</option>
    885                 <option value="01/25">01/25</option>
    886               </select></form>`,
    887    profileData: [
    888      {
    889        guid: "123",
    890        "cc-exp-month": 1,
    891      },
    892    ],
    893    expectedResult: [
    894      {
    895        guid: "123",
    896        "cc-exp-month": 1,
    897      },
    898    ],
    899    expectedOptionElements: [],
    900  },
    901  {
    902    description: "Fill a cc-exp* without cc-exp-month value in the profile",
    903    document: `<form>
    904               <input autocomplete="cc-number">
    905               <select autocomplete="cc-exp-month">
    906                 <option value="03">03</option>
    907                 <option value="01">01</option>
    908               </select>
    909               <select autocomplete="cc-exp-year">
    910                 <option value="17">2017</option>
    911                 <option value="25">2025</option>
    912               </select>
    913               </form>`,
    914    profileData: [
    915      {
    916        guid: "123",
    917        "cc-exp-year": 2025,
    918      },
    919    ],
    920    expectedResult: [
    921      {
    922        guid: "123",
    923        "cc-exp-year": 2025,
    924      },
    925    ],
    926    expectedOptionElements: [],
    927  },
    928  {
    929    description: "Fill a cc-exp* without cc-exp-year value in the profile",
    930    document: `<form>
    931               <input autocomplete="cc-number">
    932               <select autocomplete="cc-exp-month">
    933                 <option value="03">03</option>
    934                 <option value="01">01</option>
    935               </select>
    936               <select autocomplete="cc-exp-year">
    937                 <option value="17">2017</option>
    938                 <option value="25">2025</option>
    939               </select>
    940               </form>`,
    941    profileData: [
    942      {
    943        guid: "123",
    944        "cc-exp-month": 1,
    945      },
    946    ],
    947    expectedResult: [
    948      {
    949        guid: "123",
    950        "cc-exp-month": 1,
    951      },
    952    ],
    953    expectedOptionElements: [],
    954  },
    955  {
    956    description:
    957      "Fill a cc-exp field using label (MM - RR) as expiry string placeholder",
    958    document: `<form>
    959                <input autocomplete="cc-number">
    960                <input id="cc-exp" autocomplete="cc-exp">
    961                <label for="cc-exp">MM/RR</label>
    962              </form>
    963              `,
    964    profileData: [DEFAULT_CREDITCARD_RECORD],
    965    expectedResult: [
    966      { ...DEFAULT_EXPECTED_CREDITCARD_RECORD, "cc-exp": "01/25" },
    967    ],
    968  },
    969  {
    970    description:
    971      "Fill a cc-exp field using adjacent label (MM/YY) as expiry string placeholder",
    972    document: `<form>
    973                <input autocomplete="cc-number">
    974                <label>Expiry (MM/YY)</label>
    975                <input autocomplete="cc-exp">
    976              </form>
    977              `,
    978    profileData: [DEFAULT_CREDITCARD_RECORD],
    979    expectedResult: [
    980      { ...DEFAULT_EXPECTED_CREDITCARD_RECORD, "cc-exp": "01/25" },
    981    ],
    982  },
    983  {
    984    description:
    985      "Fill a cc-exp field using adjacent label (MM - YY) as expiry string placeholder",
    986    document: `<form>
    987                <input autocomplete="cc-number">
    988                <label>Expiry (MM - YY)</label>
    989                <input autocomplete="cc-exp">
    990              </form>
    991              `,
    992    profileData: [DEFAULT_CREDITCARD_RECORD],
    993    expectedResult: [
    994      { ...DEFAULT_EXPECTED_CREDITCARD_RECORD, "cc-exp": "01-25" },
    995    ],
    996  },
    997  {
    998    description: "Fill a cc-exp field correctly while ignoring unrelated label",
    999    document: `<form>
   1000                <label>Credit card number label</label>
   1001                <input autocomplete="cc-number">
   1002                <input autocomplete="cc-exp">
   1003              </form>
   1004              `,
   1005    profileData: [DEFAULT_CREDITCARD_RECORD],
   1006    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
   1007  },
   1008  {
   1009    description: "Fill a cc-exp without placeholder on the cc-exp field",
   1010    document: `<form><input autocomplete="cc-number">
   1011               <input autocomplete="cc-exp"></form>`,
   1012    profileData: [DEFAULT_CREDITCARD_RECORD],
   1013    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
   1014  },
   1015  {
   1016    description:
   1017      "Fill a cc-exp with whitespace placeholder on the cc-exp field",
   1018    document: `<form><input autocomplete="cc-number">
   1019               <input autocomplete="cc-exp" placeholder=" "></form>`,
   1020    profileData: [DEFAULT_CREDITCARD_RECORD],
   1021    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
   1022  },
   1023  {
   1024    description: "Use placeholder to adjust cc-exp format [mm/yy].",
   1025    document: `<form><input autocomplete="cc-number">
   1026               <input placeholder="mm/yy" autocomplete="cc-exp"></form>`,
   1027    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1028    expectedResult: [
   1029      {
   1030        ...DEFAULT_CREDITCARD_RECORD,
   1031        "cc-exp": "01/25",
   1032      },
   1033    ],
   1034  },
   1035  {
   1036    description: "Use placeholder to adjust cc-exp format [mm / yy].",
   1037    document: `<form><input autocomplete="cc-number">
   1038               <input placeholder="mm / yy" autocomplete="cc-exp"></form>`,
   1039    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1040    expectedResult: [
   1041      {
   1042        ...DEFAULT_CREDITCARD_RECORD,
   1043        "cc-exp": "01/25",
   1044      },
   1045    ],
   1046  },
   1047  {
   1048    description: "Use placeholder to adjust cc-exp format [MM / YY].",
   1049    document: `<form><input autocomplete="cc-number">
   1050               <input placeholder="MM / YY" autocomplete="cc-exp"></form>`,
   1051    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1052    expectedResult: [
   1053      {
   1054        ...DEFAULT_CREDITCARD_RECORD,
   1055        "cc-exp": "01/25",
   1056      },
   1057    ],
   1058  },
   1059  {
   1060    description: "Use placeholder to adjust cc-exp format [mm / yyyy].",
   1061    document: `<form><input autocomplete="cc-number">
   1062               <input placeholder="mm / yyyy" autocomplete="cc-exp"></form>`,
   1063    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1064    expectedResult: [
   1065      {
   1066        ...DEFAULT_CREDITCARD_RECORD,
   1067        "cc-exp": "01/2025",
   1068      },
   1069    ],
   1070  },
   1071  {
   1072    description: "Use placeholder to adjust cc-exp format [mm - yyyy].",
   1073    document: `<form><input autocomplete="cc-number">
   1074               <input placeholder="mm - yyyy" autocomplete="cc-exp"></form>`,
   1075    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1076    expectedResult: [
   1077      {
   1078        ...DEFAULT_CREDITCARD_RECORD,
   1079        "cc-exp": "01-2025",
   1080      },
   1081    ],
   1082  },
   1083  {
   1084    description: "Use placeholder to adjust cc-exp format [yyyy-mm].",
   1085    document: `<form><input autocomplete="cc-number">
   1086               <input placeholder="yyyy-mm" autocomplete="cc-exp"></form>`,
   1087    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1088    expectedResult: [
   1089      {
   1090        ...DEFAULT_CREDITCARD_RECORD,
   1091        "cc-exp": "2025-01",
   1092      },
   1093    ],
   1094  },
   1095  {
   1096    description: "Use placeholder to adjust cc-exp format [mmm yyyy].",
   1097    document: `<form><input autocomplete="cc-number">
   1098               <input placeholder="mmm yyyy" autocomplete="cc-exp"></form>`,
   1099    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1100    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
   1101  },
   1102  {
   1103    description: "Use placeholder to adjust cc-exp format [mm foo yyyy].",
   1104    document: `<form><input autocomplete="cc-number">
   1105               <input placeholder="mm foo yyyy" autocomplete="cc-exp"></form>`,
   1106    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1107    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
   1108  },
   1109  {
   1110    description: "Use placeholder to adjust cc-exp format [mm - - yyyy].",
   1111    document: `<form><input autocomplete="cc-number">
   1112               <input placeholder="mm - - yyyy" autocomplete="cc-exp"></form>`,
   1113    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1114    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD],
   1115  },
   1116  {
   1117    description: "Use placeholder to adjust cc-exp-month field [mm].",
   1118    document: `<form>
   1119                <input autocomplete="cc-number">
   1120                <input autocomplete="cc-exp-month" placeholder="MM">
   1121                <input autocomplete="cc-exp-year">
   1122               </form>`,
   1123    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1124    expectedResult: [
   1125      {
   1126        ...DEFAULT_CREDITCARD_RECORD,
   1127        "cc-exp-month-formatted": getCCExpMonthFormatted(),
   1128      },
   1129    ],
   1130  },
   1131  {
   1132    description: "Use placeholder to adjust cc-exp-year field [yy].",
   1133    document: `<form>
   1134                <input autocomplete="cc-number">
   1135                <input autocomplete="cc-exp-month">
   1136                <input autocomplete="cc-exp-year" placeholder="YY">
   1137               </form>`,
   1138    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1139    expectedResult: [
   1140      {
   1141        ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY,
   1142        "cc-exp-year-formatted": getCCExpYearFormatted(),
   1143      },
   1144    ],
   1145  },
   1146  {
   1147    description: "Test maxlength=2 on numeric fields.",
   1148    document: `<form>
   1149                 <input autocomplete="cc-number">
   1150                 <input autocomplete="cc-exp-month" maxlength="2">
   1151                 <input autocomplete="cc-exp-year" maxlength="2">
   1152               </form>`,
   1153    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1154    expectedResult: [
   1155      {
   1156        ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY,
   1157        "cc-exp-year": 25,
   1158      },
   1159    ],
   1160  },
   1161  {
   1162    description: "Test maxlength=4 on numeric fields.",
   1163    document: `<form>
   1164                 <input autocomplete="cc-number">
   1165                 <input autocomplete="cc-exp-month" maxlength="4">
   1166                 <input autocomplete="cc-exp-year" maxlength="4">
   1167               </form>`,
   1168    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1169    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY],
   1170  },
   1171  // Bug 1687679: The default value of an expiration month, when filled in an input element,
   1172  // is a two character length string. Because of this, testing a maxlength of 1 is invalid.
   1173  {
   1174    description: "Test maxlength=1 on numeric fields.",
   1175    document: `<form>
   1176                 <input autocomplete="cc-number">
   1177                 <input autocomplete="cc-exp-month" maxlength="1">
   1178                 <input autocomplete="cc-exp-year" maxlength="1">
   1179               </form>`,
   1180    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1181    expectedResult: [
   1182      {
   1183        ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY,
   1184        "cc-exp-year": 5,
   1185        "cc-exp-month": 1,
   1186      },
   1187    ],
   1188  },
   1189  {
   1190    description: "Test maxlength=0 on numeric fields.",
   1191    document: `<form>
   1192                 <input autocomplete="cc-number">
   1193                 <input autocomplete="cc-exp-month" maxlength="0">
   1194                 <input autocomplete="cc-exp-year" maxlength="0">
   1195               </form>`,
   1196    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1197    expectedResult: [
   1198      {
   1199        guid: DEFAULT_CREDITCARD_RECORD.guid,
   1200        "cc-exp": DEFAULT_CREDITCARD_RECORD["cc-exp"],
   1201      },
   1202    ],
   1203  },
   1204  {
   1205    // It appears that negative values do not get propagated.
   1206    description: "Test maxlength=-2 on numeric fields.",
   1207    document: `<form>
   1208                 <input autocomplete="cc-number">
   1209                 <input autocomplete="cc-exp-month" maxlength="-2">
   1210                 <input autocomplete="cc-exp-year" maxlength="-2">
   1211               </form>`,
   1212    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1213    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY],
   1214  },
   1215  {
   1216    description: "Test maxlength=10 on numeric fields.",
   1217    document: `<form>
   1218                 <input autocomplete="cc-number">
   1219                 <input autocomplete="cc-exp-month" maxlength="10">
   1220                 <input autocomplete="cc-exp-year" maxlength="10">
   1221               </form>`,
   1222    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1223    expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY],
   1224  },
   1225  {
   1226    description: "Test (special case) maxlength=5 on cc-exp field.",
   1227    document: `<form>
   1228                 <input autocomplete="cc-number">
   1229                 <input autocomplete="cc-exp" maxlength="5">
   1230               </form>`,
   1231    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1232    expectedResult: [
   1233      {
   1234        ...DEFAULT_CREDITCARD_RECORD,
   1235        "cc-exp": "01/25",
   1236      },
   1237    ],
   1238  },
   1239  {
   1240    description: "Test (special case) maxlength=4 on cc-exp field.",
   1241    document: `<form>
   1242                 <input autocomplete="cc-number">
   1243                 <input autocomplete="cc-exp" maxlength="4">
   1244               </form>`,
   1245    profileData: [{ ...DEFAULT_CREDITCARD_RECORD }],
   1246    expectedResult: [
   1247      {
   1248        ...DEFAULT_CREDITCARD_RECORD,
   1249        "cc-exp": "0125",
   1250      },
   1251    ],
   1252  },
   1253 ];
   1254 
   1255 for (let testcase of TESTCASES) {
   1256  add_task(async function () {
   1257    info("Starting testcase: " + testcase.description);
   1258 
   1259    let doc = MockDocument.createTestDocument(
   1260      "http://localhost:8080/test/",
   1261      testcase.document
   1262    );
   1263    let form = doc.querySelector("form");
   1264    let formLike = FormLikeFactory.createFromForm(form);
   1265    let handler = new FormAutofillHandler(formLike);
   1266 
   1267    const fieldDetails = FormAutofillHandler.collectFormFieldDetails(
   1268      handler.form
   1269    );
   1270 
   1271    // TODO: This test should be a browser test instead
   1272    FormAutofillHeuristics.parseAndUpdateFieldNamesParent(fieldDetails);
   1273    handler.setIdentifiedFieldDetails(fieldDetails);
   1274 
   1275    let adaptedRecords = handler.getAdaptedProfiles(testcase.profileData);
   1276    adaptedRecords.forEach(record => delete record._original);
   1277    Assert.deepEqual(adaptedRecords, testcase.expectedResult);
   1278 
   1279    if (testcase.expectedOptionElements) {
   1280      testcase.expectedOptionElements.forEach((expectedOptionElement, i) => {
   1281        for (let field in expectedOptionElement) {
   1282          let select = form.querySelector(`[autocomplete=${field}]`);
   1283          let expectedOption = doc.getElementById(expectedOptionElement[field]);
   1284          Assert.notEqual(expectedOption, null);
   1285 
   1286          let targetOption =
   1287            handler.matchSelectOptions(
   1288              { element: select, fieldName: field },
   1289              testcase.profileData[i]
   1290            ) ?? null;
   1291          Assert.notEqual(targetOption, null);
   1292 
   1293          Assert.equal(targetOption, expectedOption);
   1294        }
   1295      });
   1296    }
   1297  });
   1298 }